summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-08-27 13:50:07 +0000
committersmatz <smatz@openttd.org>2009-08-27 13:50:07 +0000
commit713f5d44ce5328c785f172f7cf798407e6d78fcd (patch)
treeda8a764a78fd23592a27e441595380c9ee2d2022 /src
parent072ce4bb17dcb02e8e832f46e4fcadfd7c4be944 (diff)
downloadopenttd-713f5d44ce5328c785f172f7cf798407e6d78fcd.tar.xz
(svn r17294) -Add [NoAI]: AITown::GetLastMonthTransportedPercentage and AIIndustry::GetLastMonthTransportedPercentage
Diffstat (limited to 'src')
-rw-r--r--src/ai/api/ai_changelog.hpp2
-rw-r--r--src/ai/api/ai_industry.cpp14
-rw-r--r--src/ai/api/ai_industry.hpp10
-rw-r--r--src/ai/api/ai_industry.hpp.sq35
-rw-r--r--src/ai/api/ai_town.cpp14
-rw-r--r--src/ai/api/ai_town.hpp12
-rw-r--r--src/ai/api/ai_town.hpp.sq41
7 files changed, 91 insertions, 37 deletions
diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp
index d3511422c..c1c9e44be 100644
--- a/src/ai/api/ai_changelog.hpp
+++ b/src/ai/api/ai_changelog.hpp
@@ -25,6 +25,8 @@
* \li AISubsidy::GetSourceIndex
* \li AISubsidy::GetDestinationType
* \li AISubsidy::GetDestinationIndex
+ * \li AITown::GetLastMonthTransportedPercentage
+ * \li AIIndustry::GetLastMonthTransportedPercentage
*
* API removals:
* \li AIOrder::ChangeOrder
diff --git a/src/ai/api/ai_industry.cpp b/src/ai/api/ai_industry.cpp
index 3870a216b..2002374e6 100644
--- a/src/ai/api/ai_industry.cpp
+++ b/src/ai/api/ai_industry.cpp
@@ -98,6 +98,20 @@
return -1;
}
+/* static */ int32 AIIndustry::GetLastMonthTransportedPercentage(IndustryID industry_id, CargoID cargo_id)
+{
+ if (!IsValidIndustry(industry_id)) return -1;
+ if (!AICargo::IsValidCargo(cargo_id)) return -1;
+
+ const Industry *i = ::Industry::Get(industry_id);
+
+ for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
+ if (i->produced_cargo[j] == cargo_id) return ::ToPercent8(i->last_month_pct_transported[j]);
+ }
+
+ return -1;
+}
+
/* static */ TileIndex AIIndustry::GetLocation(IndustryID industry_id)
{
if (!IsValidIndustry(industry_id)) return INVALID_TILE;
diff --git a/src/ai/api/ai_industry.hpp b/src/ai/api/ai_industry.hpp
index ec74b690e..cbaa9f407 100644
--- a/src/ai/api/ai_industry.hpp
+++ b/src/ai/api/ai_industry.hpp
@@ -85,6 +85,16 @@ public:
static int32 GetLastMonthTransported(IndustryID industry_id, CargoID cargo_id);
/**
+ * Get the percentage of cargo transported from an industry last month.
+ * @param industry_id The index of the industry.
+ * @param cargo_id The index of the cargo.
+ * @pre IsValidIndustry(industry_id).
+ * @pre AICargo::IsValidCargo(cargo_id).
+ * @return The percentage of given cargo transported from this industry last month.
+ */
+ static int32 GetLastMonthTransportedPercentage(IndustryID industry_id, CargoID cargo_id);
+
+ /**
* Gets the location of the industry.
* @param industry_id The index of the industry.
* @pre IsValidIndustry(industry_id).
diff --git a/src/ai/api/ai_industry.hpp.sq b/src/ai/api/ai_industry.hpp.sq
index f9470d420..2eb8e129e 100644
--- a/src/ai/api/ai_industry.hpp.sq
+++ b/src/ai/api/ai_industry.hpp.sq
@@ -25,23 +25,24 @@ void SQAIIndustry_Register(Squirrel *engine) {
SQAIIndustry.PreRegister(engine);
SQAIIndustry.AddConstructor<void (AIIndustry::*)(), 1>(engine, "x");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetIndustryCount, "GetIndustryCount", 1, ".");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsValidIndustry, "IsValidIndustry", 2, ".i");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetName, "GetName", 2, ".i");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsCargoAccepted, "IsCargoAccepted", 3, ".ii");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetStockpiledCargo, "GetStockpiledCargo", 3, ".ii");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLastMonthProduction, "GetLastMonthProduction", 3, ".ii");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLastMonthTransported, "GetLastMonthTransported", 3, ".ii");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLocation, "GetLocation", 2, ".i");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetAmountOfStationsAround, "GetAmountOfStationsAround", 2, ".i");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetDistanceManhattanToTile, "GetDistanceManhattanToTile", 3, ".ii");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetDistanceSquareToTile, "GetDistanceSquareToTile", 3, ".ii");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsBuiltOnWater, "IsBuiltOnWater", 2, ".i");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::HasHeliport, "HasHeliport", 2, ".i");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetHeliportLocation, "GetHeliportLocation", 2, ".i");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::HasDock, "HasDock", 2, ".i");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetDockLocation, "GetDockLocation", 2, ".i");
- SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetIndustryType, "GetIndustryType", 2, ".i");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetIndustryCount, "GetIndustryCount", 1, ".");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsValidIndustry, "IsValidIndustry", 2, ".i");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetName, "GetName", 2, ".i");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsCargoAccepted, "IsCargoAccepted", 3, ".ii");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetStockpiledCargo, "GetStockpiledCargo", 3, ".ii");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLastMonthProduction, "GetLastMonthProduction", 3, ".ii");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLastMonthTransported, "GetLastMonthTransported", 3, ".ii");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLastMonthTransportedPercentage, "GetLastMonthTransportedPercentage", 3, ".ii");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetLocation, "GetLocation", 2, ".i");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetAmountOfStationsAround, "GetAmountOfStationsAround", 2, ".i");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetDistanceManhattanToTile, "GetDistanceManhattanToTile", 3, ".ii");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetDistanceSquareToTile, "GetDistanceSquareToTile", 3, ".ii");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsBuiltOnWater, "IsBuiltOnWater", 2, ".i");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::HasHeliport, "HasHeliport", 2, ".i");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetHeliportLocation, "GetHeliportLocation", 2, ".i");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::HasDock, "HasDock", 2, ".i");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetDockLocation, "GetDockLocation", 2, ".i");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetIndustryType, "GetIndustryType", 2, ".i");
SQAIIndustry.PostRegister(engine);
}
diff --git a/src/ai/api/ai_town.cpp b/src/ai/api/ai_town.cpp
index 72f068f09..78144b998 100644
--- a/src/ai/api/ai_town.cpp
+++ b/src/ai/api/ai_town.cpp
@@ -92,6 +92,20 @@
}
}
+/* static */ int32 AITown::GetLastMonthTransportedPercentage(TownID town_id, CargoID cargo_id)
+{
+ if (!IsValidTown(town_id)) return -1;
+ if (!AICargo::IsValidCargo(cargo_id)) return -1;
+
+ const Town *t = ::Town::Get(town_id);
+
+ switch (AICargo::GetTownEffect(cargo_id)) {
+ case AICargo::TE_PASSENGERS: return ::ToPercent8(t->pct_pass_transported);
+ case AICargo::TE_MAIL: return ::ToPercent8(t->pct_mail_transported);
+ default: return -1;
+ }
+}
+
/* static */ int32 AITown::GetDistanceManhattanToTile(TownID town_id, TileIndex tile)
{
return AIMap::DistanceManhattan(tile, GetLocation(town_id));
diff --git a/src/ai/api/ai_town.hpp b/src/ai/api/ai_town.hpp
index dca8a36e9..d59dd9261 100644
--- a/src/ai/api/ai_town.hpp
+++ b/src/ai/api/ai_town.hpp
@@ -176,6 +176,18 @@ public:
static int32 GetLastMonthTransported(TownID town_id, CargoID cargo_id);
/**
+ * Get the percentage of transported 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 percentage of given cargo transported from this town last month.
+ * @post Return value is always non-negative.
+ */
+ static int32 GetLastMonthTransportedPercentage(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.
diff --git a/src/ai/api/ai_town.hpp.sq b/src/ai/api/ai_town.hpp.sq
index bb10e8fba..924de2b9b 100644
--- a/src/ai/api/ai_town.hpp.sq
+++ b/src/ai/api/ai_town.hpp.sq
@@ -57,26 +57,27 @@ void SQAITown_Register(Squirrel *engine) {
SQAITown.DefSQConst(engine, AITown::ROAD_LAYOUT_3x3, "ROAD_LAYOUT_3x3");
SQAITown.DefSQConst(engine, AITown::ROAD_LAYOUT_INVALID, "ROAD_LAYOUT_INVALID");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetTownCount, "GetTownCount", 1, ".");
- SQAITown.DefSQStaticMethod(engine, &AITown::IsValidTown, "IsValidTown", 2, ".i");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetName, "GetName", 2, ".i");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetPopulation, "GetPopulation", 2, ".i");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetHouseCount, "GetHouseCount", 2, ".i");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetLocation, "GetLocation", 2, ".i");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetLastMonthProduction, "GetLastMonthProduction", 3, ".ii");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetLastMonthTransported, "GetLastMonthTransported", 3, ".ii");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetDistanceManhattanToTile, "GetDistanceManhattanToTile", 3, ".ii");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetDistanceSquareToTile, "GetDistanceSquareToTile", 3, ".ii");
- SQAITown.DefSQStaticMethod(engine, &AITown::IsWithinTownInfluence, "IsWithinTownInfluence", 3, ".ii");
- SQAITown.DefSQStaticMethod(engine, &AITown::HasStatue, "HasStatue", 2, ".i");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetRoadReworkDuration, "GetRoadReworkDuration", 2, ".i");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetExclusiveRightsCompany, "GetExclusiveRightsCompany", 2, ".i");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetExclusiveRightsDuration, "GetExclusiveRightsDuration", 2, ".i");
- SQAITown.DefSQStaticMethod(engine, &AITown::IsActionAvailable, "IsActionAvailable", 3, ".ii");
- SQAITown.DefSQStaticMethod(engine, &AITown::PerformTownAction, "PerformTownAction", 3, ".ii");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetRating, "GetRating", 3, ".ii");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetAllowedNoise, "GetAllowedNoise", 2, ".i");
- SQAITown.DefSQStaticMethod(engine, &AITown::GetRoadLayout, "GetRoadLayout", 2, ".i");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetTownCount, "GetTownCount", 1, ".");
+ SQAITown.DefSQStaticMethod(engine, &AITown::IsValidTown, "IsValidTown", 2, ".i");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetName, "GetName", 2, ".i");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetPopulation, "GetPopulation", 2, ".i");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetHouseCount, "GetHouseCount", 2, ".i");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetLocation, "GetLocation", 2, ".i");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetLastMonthProduction, "GetLastMonthProduction", 3, ".ii");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetLastMonthTransported, "GetLastMonthTransported", 3, ".ii");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetLastMonthTransportedPercentage, "GetLastMonthTransportedPercentage", 3, ".ii");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetDistanceManhattanToTile, "GetDistanceManhattanToTile", 3, ".ii");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetDistanceSquareToTile, "GetDistanceSquareToTile", 3, ".ii");
+ SQAITown.DefSQStaticMethod(engine, &AITown::IsWithinTownInfluence, "IsWithinTownInfluence", 3, ".ii");
+ SQAITown.DefSQStaticMethod(engine, &AITown::HasStatue, "HasStatue", 2, ".i");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetRoadReworkDuration, "GetRoadReworkDuration", 2, ".i");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetExclusiveRightsCompany, "GetExclusiveRightsCompany", 2, ".i");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetExclusiveRightsDuration, "GetExclusiveRightsDuration", 2, ".i");
+ SQAITown.DefSQStaticMethod(engine, &AITown::IsActionAvailable, "IsActionAvailable", 3, ".ii");
+ SQAITown.DefSQStaticMethod(engine, &AITown::PerformTownAction, "PerformTownAction", 3, ".ii");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetRating, "GetRating", 3, ".ii");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetAllowedNoise, "GetAllowedNoise", 2, ".i");
+ SQAITown.DefSQStaticMethod(engine, &AITown::GetRoadLayout, "GetRoadLayout", 2, ".i");
SQAITown.PostRegister(engine);
}