(svn r17294) -Add [NoAI]: AITown::GetLastMonthTransportedPercentage and AIIndustry::GetLastMonthTransportedPercentage

pull/155/head
smatz 15 years ago
parent 15242b3ac8
commit e126e1e9c6

@ -25,6 +25,8 @@
* \li AISubsidy::GetSourceIndex
* \li AISubsidy::GetDestinationType
* \li AISubsidy::GetDestinationIndex
* \li AITown::GetLastMonthTransportedPercentage
* \li AIIndustry::GetLastMonthTransportedPercentage
*
* API removals:
* \li AIOrder::ChangeOrder

@ -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;

@ -84,6 +84,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.

@ -32,6 +32,7 @@ void SQAIIndustry_Register(Squirrel *engine) {
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");

@ -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));

@ -175,6 +175,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.

@ -65,6 +65,7 @@ void SQAITown_Register(Squirrel *engine) {
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");

Loading…
Cancel
Save