(svn r17305) [0.7] -Backport from trunk:

-Fix: [NoAI] AITown::GetLastMonthTransported didn't work as documented at all, make it return what AITown::GetLastMonthProduction did
-Change: [NoAI] AITown::GetLastMonthProduction now returns the same value as AITown::GetMaxProduction
-Add: [NoAI] AITown::GetLastMonthTransportedPercentage and AIIndustry::GetLastMonthTransportedPercentage
This commit is contained in:
smatz 2009-08-29 11:18:03 +00:00
parent 47ae295ee1
commit 36497b584e
6 changed files with 88 additions and 45 deletions

View File

@ -91,6 +91,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 = ::GetIndustry(industry_id);
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
if (i->produced_cargo[j] == cargo_id) return i->last_month_pct_transported[j] * 100 >> 8;
}
return -1;
}
/* static */ TileIndex AIIndustry::GetLocation(IndustryID industry_id)
{
if (!IsValidIndustry(industry_id)) return INVALID_TILE;

View File

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

View File

@ -17,23 +17,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);
}

View File

@ -65,8 +65,8 @@
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;
case AICargo::TE_PASSENGERS: return t->max_pass;
case AICargo::TE_MAIL: return t->max_mail;
default: return -1;
}
}
@ -79,22 +79,27 @@
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;
case AICargo::TE_PASSENGERS: return t->act_pass;
case AICargo::TE_MAIL: return t->act_mail;
default: return -1;
}
}
/* static */ int32 AITown::GetMaxProduction(TownID town_id, CargoID cargo_id)
{
return AITown::GetLastMonthProduction(town_id, cargo_id);
}
/* 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 = ::GetTown(town_id);
switch(AICargo::GetTownEffect(cargo_id)) {
case AICargo::TE_PASSENGERS: return t->max_pass;
case AICargo::TE_MAIL: return t->max_mail;
switch (AICargo::GetTownEffect(cargo_id)) {
case AICargo::TE_PASSENGERS: return t->pct_pass_transported * 100 >> 8;
case AICargo::TE_MAIL: return t->pct_mail_transported * 100 >> 8;
default: return -1;
}
}

View File

@ -180,6 +180,18 @@ public:
*/
static int32 GetMaxProduction(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.

View File

@ -49,27 +49,28 @@ 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::GetMaxProduction, "GetMaxProduction", 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::GetMaxProduction, "GetMaxProduction", 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);
}