(svn r23298) -Add: track statistics of all incoming and outgoing goods. Incoming based on TownEffect, outgoing based on CargoType (based on patch by Terkhen)

This commit is contained in:
truebrain
2011-11-23 16:05:19 +00:00
parent 4e09cde649
commit 229e572663
19 changed files with 202 additions and 142 deletions

View File

@@ -20,6 +20,11 @@
return (cargo_type < NUM_CARGO && ::CargoSpec::Get(cargo_type)->IsValid());
}
/* static */ bool AICargo::IsValidTownEffect(TownEffect towneffect_type)
{
return (towneffect_type >= TE_BEGIN && towneffect_type < TE_END);
}
/* static */ char *AICargo::GetCargoLabel(CargoID cargo_type)
{
if (!IsValidCargo(cargo_type)) return NULL;

View File

@@ -62,6 +62,13 @@ public:
*/
static bool IsValidCargo(CargoID cargo_type);
/**
* Checks whether the given town effect type is valid.
* @param towneffect_type The town effect to check.
* @return True if and only if the town effect type is valid.
*/
static bool IsValidTownEffect(TownEffect towneffect_type);
/**
* Gets the string representation of the cargo label.
* @param cargo_type The cargo to get the string representation of.

View File

@@ -55,12 +55,13 @@ void SQAICargo_Register(Squirrel *engine)
SQAICargo.DefSQConst(engine, AICargo::CT_AUTO_REFIT, "CT_AUTO_REFIT");
SQAICargo.DefSQConst(engine, AICargo::CT_NO_REFIT, "CT_NO_REFIT");
SQAICargo.DefSQStaticMethod(engine, &AICargo::IsValidCargo, "IsValidCargo", 2, ".i");
SQAICargo.DefSQStaticMethod(engine, &AICargo::GetCargoLabel, "GetCargoLabel", 2, ".i");
SQAICargo.DefSQStaticMethod(engine, &AICargo::IsFreight, "IsFreight", 2, ".i");
SQAICargo.DefSQStaticMethod(engine, &AICargo::HasCargoClass, "HasCargoClass", 3, ".ii");
SQAICargo.DefSQStaticMethod(engine, &AICargo::GetTownEffect, "GetTownEffect", 2, ".i");
SQAICargo.DefSQStaticMethod(engine, &AICargo::GetCargoIncome, "GetCargoIncome", 4, ".iii");
SQAICargo.DefSQStaticMethod(engine, &AICargo::IsValidCargo, "IsValidCargo", 2, ".i");
SQAICargo.DefSQStaticMethod(engine, &AICargo::IsValidTownEffect, "IsValidTownEffect", 2, ".i");
SQAICargo.DefSQStaticMethod(engine, &AICargo::GetCargoLabel, "GetCargoLabel", 2, ".i");
SQAICargo.DefSQStaticMethod(engine, &AICargo::IsFreight, "IsFreight", 2, ".i");
SQAICargo.DefSQStaticMethod(engine, &AICargo::HasCargoClass, "HasCargoClass", 3, ".ii");
SQAICargo.DefSQStaticMethod(engine, &AICargo::GetTownEffect, "GetTownEffect", 2, ".i");
SQAICargo.DefSQStaticMethod(engine, &AICargo::GetCargoIncome, "GetCargoIncome", 4, ".iii");
SQAICargo.PostRegister(engine);
}

View File

@@ -23,6 +23,7 @@
*
* \li AICargo::CT_AUTO_REFIT
* \li AICargo::CT_NO_REFIT
* \li AICargo::IsValidTownEffect
* \li AICargoList_StationAccepting
* \li AICompany::GetQuarterlyIncome
* \li AICompany::GetQuarterlyExpenses
@@ -34,12 +35,25 @@
* \li AIOrder::GetOrderRefit
* \li AIOrder::IsRefitOrder
* \li AIOrder::SetOrderRefit
* \li AITown::GetLastMonthReceived
* \li AITown::GetTownAuthority
* \li AIVehicle::ERR_VEHICLE_TOO_LONG in case vehicle length limit is reached
*
* API renames:
* \li AITown::GetLastMonthTransported to AITown::GetLastMonthSupplied to better
* reflect what it does
*
* API removals:
* \li AICompany::GetCompanyValue, use AICompany::GetQuarterlyCompanyValue instead.
*
* Other changes:
* \li AITown::GetLastMonthProduction no longer has prerequisites based on town
* effects.
* \li AITown::GetLastMonthTransported no longer has prerequisites based on
* town effects.
* \li AITown::GetLastMonthTransportedPercentage no longer has prerequisites
* based on town effects.
*
* \b 1.1.2
*
* No changes

View File

@@ -70,25 +70,17 @@
const Town *t = ::Town::Get(town_id);
switch (AICargo::GetTownEffect(cargo_id)) {
case AICargo::TE_PASSENGERS: return t->pass.old_max;
case AICargo::TE_MAIL: return t->mail.old_max;
default: return -1;
}
return t->supplied[cargo_id].old_max;
}
/* static */ int32 AITown::GetLastMonthTransported(TownID town_id, CargoID cargo_id)
/* static */ int32 AITown::GetLastMonthSupplied(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 t->pass.old_act;
case AICargo::TE_MAIL: return t->mail.old_act;
default: return -1;
}
return t->supplied[cargo_id].old_act;
}
/* static */ int32 AITown::GetLastMonthTransportedPercentage(TownID town_id, CargoID cargo_id)
@@ -97,12 +89,17 @@
if (!AICargo::IsValidCargo(cargo_id)) return -1;
const Town *t = ::Town::Get(town_id);
return ::ToPercent8(t->GetPercentTransported(cargo_id));
}
switch (AICargo::GetTownEffect(cargo_id)) {
case AICargo::TE_PASSENGERS: return ::ToPercent8(t->GetPercentPassTransported());
case AICargo::TE_MAIL: return ::ToPercent8(t->GetPercentMailTransported());
default: return -1;
}
/* static */ int32 AITown::GetLastMonthReceived(TownID town_id, AICargo::TownEffect towneffect_id)
{
if (!IsValidTown(town_id)) return -1;
if (!AICargo::IsValidTownEffect(towneffect_id)) return -1;
const Town *t = ::Town::Get(town_id);
return t->received[towneffect_id].old_act;
}
/* static */ int32 AITown::GetDistanceManhattanToTile(TownID town_id, TileIndex tile)

View File

@@ -12,6 +12,7 @@
#ifndef AI_TOWN_HPP
#define AI_TOWN_HPP
#include "ai_cargo.hpp"
#include "ai_company.hpp"
/**
@@ -154,23 +155,21 @@ public:
* @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.
* Get the total amount of cargo supplied from a town last month.
* @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 amount of given cargo transported from this town last month.
* @return The amount of cargo supplied for transport from this town last month.
* @post Return value is always non-negative.
*/
static int32 GetLastMonthTransported(TownID town_id, CargoID cargo_id);
static int32 GetLastMonthSupplied(TownID town_id, CargoID cargo_id);
/**
* Get the percentage of transported production of the given cargo at a town.
@@ -178,12 +177,22 @@ public:
* @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 total amount of cargo effects received by a town last month.
* @param town_id The index of the town.
* @param towneffect_id The index of the cargo.
* @pre IsValidTown(town_id).
* @pre AICargo::IsValidTownEffect(cargo_id).
* @return The amount of cargo received by this town last month for this cargo effect.
* @post Return value is always non-negative.
*/
static int32 GetLastMonthReceived(TownID town_id, AICargo::TownEffect towneffect_id);
/**
* Get the manhattan distance from the tile to the AITown::GetLocation()
* of the town.

View File

@@ -67,8 +67,9 @@ void SQAITown_Register(Squirrel *engine)
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::GetLastMonthSupplied, "GetLastMonthSupplied", 3, ".ii");
SQAITown.DefSQStaticMethod(engine, &AITown::GetLastMonthTransportedPercentage, "GetLastMonthTransportedPercentage", 3, ".ii");
SQAITown.DefSQStaticMethod(engine, &AITown::GetLastMonthReceived, "GetLastMonthReceived", 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");