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

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
smatz 15 years ago
parent 072ce4bb17
commit 713f5d44ce

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

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

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

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

Loading…
Cancel
Save