(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction() noai
authorglx
Fri, 06 Jun 2008 00:44:23 +0000
branchnoai
changeset 10840 fd5945ab9ea6
parent 10831 f7e17819358b
child 10841 a8942f5f7e3b
(svn r13391) [NoAI] -Add: added AITown.GetNumHouses(), AITown.GetLastMonthProduction(), AITown.GetLastMonthTransported() and AITown.GetMaxProduction()
src/ai/api/ai_town.cpp
src/ai/api/ai_town.hpp
src/ai/api/ai_town.hpp.sq
--- a/src/ai/api/ai_town.cpp	Wed Jun 04 22:57:17 2008 +0000
+++ b/src/ai/api/ai_town.cpp	Fri Jun 06 00:44:23 2008 +0000
@@ -4,6 +4,7 @@
 
 #include "ai_town.hpp"
 #include "ai_map.hpp"
+#include "ai_cargo.hpp"
 #include "../../openttd.h"
 #include "../../town.h"
 #include "../../strings_func.h"
@@ -44,6 +45,13 @@
 	return t->population;
 }
 
+/* static */ int32 AITown::GetNumHouses(TownID town_id)
+{
+	if (!IsValidTown(town_id)) return -1;
+	const Town *t = ::GetTown(town_id);
+	return t->num_houses;
+}
+
 /* static */ TileIndex AITown::GetLocation(TownID town_id)
 {
 	if (!IsValidTown(town_id)) return INVALID_TILE;
@@ -51,6 +59,48 @@
 	return t->xy;
 }
 
+/* static */ int32 AITown::GetLastMonthProduction(TownID town_id, CargoID cargo_id)
+{
+	if (!IsValidTown(town_id)) return -1;
+	if (!AICargo::IsValidCargo(cargo_id)) return -1;
+
+	const Town *t = ::GetTown(town_id);
+
+	switch(AICargo::GetTownEffect(cargo_id)) {
+		case AICargo::TE_PASSENGERS: return t->act_pass;
+		case AICargo::TE_MAIL:       return t->act_mail;
+		default: return -1;
+	}
+}
+
+/* static */ int32 AITown::GetLastMonthTransported(TownID town_id, CargoID cargo_id)
+{
+	if (!IsValidTown(town_id)) return -1;
+	if (!AICargo::IsValidCargo(cargo_id)) return -1;
+
+	const Town *t = ::GetTown(town_id);
+
+	switch(AICargo::GetTownEffect(cargo_id)) {
+		case AICargo::TE_PASSENGERS: return t->pct_pass_transported;
+		case AICargo::TE_MAIL:       return t->pct_mail_transported;
+		default: return -1;
+	}
+}
+
+/* static */ int32 AITown::GetMaxProduction(TownID town_id, CargoID cargo_id)
+{
+	if (!IsValidTown(town_id)) return -1;
+	if (!AICargo::IsValidCargo(cargo_id)) return -1;
+
+	const Town *t = ::GetTown(town_id);
+
+	switch(AICargo::GetTownEffect(cargo_id)) {
+		case AICargo::TE_PASSENGERS: return t->max_pass;
+		case AICargo::TE_MAIL:       return t->max_mail;
+		default: return -1;
+	}
+}
+
 /* static */ int32 AITown::GetDistanceManhattanToTile(TownID town_id, TileIndex tile)
 {
 	return AIMap::DistanceManhattan(tile, GetLocation(town_id));
--- a/src/ai/api/ai_town.hpp	Wed Jun 04 22:57:17 2008 +0000
+++ b/src/ai/api/ai_town.hpp	Fri Jun 06 00:44:23 2008 +0000
@@ -46,7 +46,7 @@
 
 	/**
 	 * Gets the number of inhabitants in the town.
-	 * @param town_id The town to get the name of.
+	 * @param town_id The town to get the population of.
 	 * @pre IsValidTown(town_id).
 	 * @return The number of inhabitants.
 	 * @post Return value is always non-negative.
@@ -54,6 +54,15 @@
 	static int32 GetPopulation(TownID town_id);
 
 	/**
+	 * Gets the number of houses in the town.
+	 * @param town_id The town to get the number of houses of.
+	 * @pre IsValidTown(town_id).
+	 * @return The number of houses.
+	 * @post Return value is always non-negative.
+	 */
+	static int32 GetNumHouses(TownID town_id);
+
+	/**
 	 * Gets the location of the town.
 	 * @param town_id The location of the town.
 	 * @pre IsValidTown(town_id).
@@ -62,6 +71,42 @@
 	static TileIndex GetLocation(TownID town_id);
 
 	/**
+	 * Get the total last month's production of the given cargo at a town.
+	 * @param town_id The index of the town.
+	 * @param cargo_id The index of the cargo.
+	 * @pre IsValidTown(town_id).
+	 * @pre AICargo::IsValidCargo(cargo_id).
+	 * @pre AICargo::GetTownEffect(cargo_id) == TE_PASSENGERS || AICargo::GetTownEffect(cargo_id) == TE_MAIL.
+	 * @return The last month's production of the given cargo for this town.
+	 * @post Return value is always non-negative.
+	 */
+	static int32 GetLastMonthProduction(TownID town_id, CargoID cargo_id);
+
+	/**
+	 * Get the total amount of cargo transported from a town last month.
+	 * @param town_id The index of the industry.
+	 * @param cargo_id The index of the cargo.
+	 * @pre IsValidTown(town_id).
+	 * @pre AICargo::IsValidCargo(cargo_id).
+	 * @pre AICargo::GetTownEffect(cargo_id) == TE_PASSENGERS || AICargo::GetTownEffect(cargo_id) == TE_MAIL.
+	 * @return The amount of given cargo transported from this town last month.
+	 * @post Return value is always non-negative.
+	 */
+	static int32 GetLastMonthTransported(TownID town_id, CargoID cargo_id);
+
+	/**
+	 * Get the maximum production of the given cargo at a town.
+	 * @param town_id The index of the town.
+	 * @param cargo_id The index of the cargo.
+	 * @pre IsValidTown(town_id).
+	 * @pre AICargo::IsValidCargo(cargo_id).
+	 * @pre AICargo::GetTownEffect(cargo_id) == TE_PASSENGERS || AICargo::GetTownEffect(cargo_id) == TE_MAIL.
+	 * @return The maximum production of the given cargo for this town.
+	 * @post Return value is always non-negative.
+	 */
+	static int32 GetMaxProduction(TownID town_id, CargoID cargo_id);
+
+	/**
 	 * Get the manhattan distance from the tile to the AITown::GetLocation()
 	 *  of the town.
 	 * @param town_id The town to get the distance to.
--- a/src/ai/api/ai_town.hpp.sq	Wed Jun 04 22:57:17 2008 +0000
+++ b/src/ai/api/ai_town.hpp.sq	Fri Jun 06 00:44:23 2008 +0000
@@ -23,7 +23,11 @@
 	SQAITown.DefSQStaticMethod(engine, &AITown::IsValidTown,                "IsValidTown",                2, "xi");
 	SQAITown.DefSQStaticMethod(engine, &AITown::GetName,                    "GetName",                    2, "xi");
 	SQAITown.DefSQStaticMethod(engine, &AITown::GetPopulation,              "GetPopulation",              2, "xi");
+	SQAITown.DefSQStaticMethod(engine, &AITown::GetNumHouses,               "GetNumHouses",               2, "xi");
 	SQAITown.DefSQStaticMethod(engine, &AITown::GetLocation,                "GetLocation",                2, "xi");
+	SQAITown.DefSQStaticMethod(engine, &AITown::GetLastMonthProduction,     "GetLastMonthProduction",     3, "xii");
+	SQAITown.DefSQStaticMethod(engine, &AITown::GetLastMonthTransported,    "GetLastMonthTransported",    3, "xii");
+	SQAITown.DefSQStaticMethod(engine, &AITown::GetMaxProduction,           "GetMaxProduction",           3, "xii");
 	SQAITown.DefSQStaticMethod(engine, &AITown::GetDistanceManhattanToTile, "GetDistanceManhattanToTile", 3, "xii");
 	SQAITown.DefSQStaticMethod(engine, &AITown::GetDistanceSquareToTile,    "GetDistanceSquareToTile",    3, "xii");
 	SQAITown.DefSQStaticMethod(engine, &AITown::IsWithinTownInfluence,      "IsWithinTownInfluence",      3, "xii");