--- a/bin/ai/regression/regression.nut Wed Jun 04 22:34:45 2008 +0000
+++ b/bin/ai/regression/regression.nut Wed Jun 04 22:57:17 2008 +0000
@@ -175,6 +175,7 @@
print(" GetCargoLabel(): '" + AICargo.GetCargoLabel(i)+ "'");
print(" IsFreight(): " + AICargo.IsFreight(i));
print(" HasCargoClass(): " + AICargo.HasCargoClass(i, AICargo.CC_PASSENGERS));
+ print(" GetTownEffect(): " + AICargo.GetTownEffect(i));
print(" GetCargoIncome(0, 0): " + AICargo.GetCargoIncome(i, 0, 0));
print(" GetCargoIncome(10, 10): " + AICargo.GetCargoIncome(i, 10, 10));
print(" GetCargoIncome(100, 10): " + AICargo.GetCargoIncome(i, 100, 10));
--- a/bin/ai/regression/regression.txt Wed Jun 04 22:34:45 2008 +0000
+++ b/bin/ai/regression/regression.txt Wed Jun 04 22:57:17 2008 +0000
@@ -657,6 +657,7 @@
GetCargoLabel(): '(null : 0x00000000)'
IsFreight(): false
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): -1
GetCargoIncome(10, 10): -1
GetCargoIncome(100, 10): -1
@@ -666,6 +667,7 @@
GetCargoLabel(): 'PASS'
IsFreight(): false
HasCargoClass(): true
+ GetTownEffect(): 1
GetCargoIncome(0, 0): 0
GetCargoIncome(10, 10): 3
GetCargoIncome(100, 10): 37
@@ -675,6 +677,7 @@
GetCargoLabel(): 'COAL'
IsFreight(): true
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): 0
GetCargoIncome(10, 10): 7
GetCargoIncome(100, 10): 71
@@ -684,6 +687,7 @@
GetCargoLabel(): 'MAIL'
IsFreight(): false
HasCargoClass(): false
+ GetTownEffect(): 2
GetCargoIncome(0, 0): 0
GetCargoIncome(10, 10): 5
GetCargoIncome(100, 10): 55
@@ -693,6 +697,7 @@
GetCargoLabel(): 'OIL_'
IsFreight(): true
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): 0
GetCargoIncome(10, 10): 5
GetCargoIncome(100, 10): 53
@@ -702,6 +707,7 @@
GetCargoLabel(): 'LVST'
IsFreight(): true
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): 0
GetCargoIncome(10, 10): 5
GetCargoIncome(100, 10): 51
@@ -711,6 +717,7 @@
GetCargoLabel(): 'GOOD'
IsFreight(): true
HasCargoClass(): false
+ GetTownEffect(): 3
GetCargoIncome(0, 0): 0
GetCargoIncome(10, 10): 7
GetCargoIncome(100, 10): 73
@@ -720,6 +727,7 @@
GetCargoLabel(): 'GRAI'
IsFreight(): true
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): 0
GetCargoIncome(10, 10): 5
GetCargoIncome(100, 10): 56
@@ -729,6 +737,7 @@
GetCargoLabel(): 'WOOD'
IsFreight(): true
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): 0
GetCargoIncome(10, 10): 6
GetCargoIncome(100, 10): 60
@@ -738,6 +747,7 @@
GetCargoLabel(): 'IORE'
IsFreight(): true
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): 0
GetCargoIncome(10, 10): 6
GetCargoIncome(100, 10): 62
@@ -747,6 +757,7 @@
GetCargoLabel(): 'STEL'
IsFreight(): true
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): 0
GetCargoIncome(10, 10): 6
GetCargoIncome(100, 10): 68
@@ -756,6 +767,7 @@
GetCargoLabel(): 'VALU'
IsFreight(): true
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): 0
GetCargoIncome(10, 10): 8
GetCargoIncome(100, 10): 88
@@ -765,6 +777,7 @@
GetCargoLabel(): '(null : 0x00000000)'
IsFreight(): false
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): -1
GetCargoIncome(10, 10): -1
GetCargoIncome(100, 10): -1
@@ -774,6 +787,7 @@
GetCargoLabel(): '(null : 0x00000000)'
IsFreight(): false
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): -1
GetCargoIncome(10, 10): -1
GetCargoIncome(100, 10): -1
@@ -783,6 +797,7 @@
GetCargoLabel(): '(null : 0x00000000)'
IsFreight(): false
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): -1
GetCargoIncome(10, 10): -1
GetCargoIncome(100, 10): -1
@@ -792,6 +807,7 @@
GetCargoLabel(): '(null : 0x00000000)'
IsFreight(): false
HasCargoClass(): false
+ GetTownEffect(): 0
GetCargoIncome(0, 0): -1
GetCargoIncome(10, 10): -1
GetCargoIncome(100, 10): -1
--- a/src/ai/api/ai_cargo.cpp Wed Jun 04 22:34:45 2008 +0000
+++ b/src/ai/api/ai_cargo.cpp Wed Jun 04 22:57:17 2008 +0000
@@ -43,6 +43,13 @@
return ::IsCargoInClass(cargo_type, (::CargoClass)cargo_class);
}
+/* static */ AICargo::TownEffect AICargo::GetTownEffect(CargoID cargo_type)
+{
+ if (!IsValidCargo(cargo_type)) return TE_NONE;
+
+ return (AICargo::TownEffect)GetCargo(cargo_type)->town_effect;
+}
+
/* static */ Money AICargo::GetCargoIncome(CargoID cargo_type, uint32 distance, uint32 days_in_transit)
{
if (!IsValidCargo(cargo_type)) return -1;
--- a/src/ai/api/ai_cargo.hpp Wed Jun 04 22:34:45 2008 +0000
+++ b/src/ai/api/ai_cargo.hpp Wed Jun 04 22:57:17 2008 +0000
@@ -31,6 +31,18 @@
};
/**
+ * The effects a cargo can have on a town.
+ */
+ enum TownEffect {
+ TE_NONE = 0, ///< This cargo has no effect on a town
+ TE_PASSENGERS = 1, ///< This cargo supplies passengers to a town
+ TE_MAIL = 2, ///< This cargo supplies mail to a town
+ TE_GOODS = 3, ///< This cargo supplies goods to a town
+ TE_WATER = 4, ///< This cargo supplies water to a town
+ TE_FOOD = 5, ///< This cargo supplies food to a town
+ };
+
+ /**
* Checks whether the given cargo type is valid.
* @param cargo_type The cargo to check.
* @return True if and only if the cargo type is valid.
@@ -62,6 +74,13 @@
static bool HasCargoClass(CargoID cargo_type, CargoClass cargo_class);
/**
+ * Get the effect this cargo has on a town.
+ * @param cargo_type The cargo to check on.
+ * @return The effect this cargo has on a town, or TE_NONE if it has no effect.
+ */
+ static TownEffect GetTownEffect(CargoID cargo_type);
+
+ /**
* Get the income for transporting a piece of cargo over the
* given distance within the specified time.
* @param cargo_type The cargo to transport.
--- a/src/ai/api/ai_cargo.hpp.sq Wed Jun 04 22:34:45 2008 +0000
+++ b/src/ai/api/ai_cargo.hpp.sq Wed Jun 04 22:57:17 2008 +0000
@@ -7,6 +7,8 @@
/* Allow enums to be used as Squirrel parameters */
template <> AICargo::CargoClass GetParam(ForceType<AICargo::CargoClass>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AICargo::CargoClass)tmp; }
template <> int Return<AICargo::CargoClass>(HSQUIRRELVM vm, AICargo::CargoClass res) { sq_pushinteger(vm, (int32)res); return 1; }
+ template <> AICargo::TownEffect GetParam(ForceType<AICargo::TownEffect>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AICargo::TownEffect)tmp; }
+ template <> int Return<AICargo::TownEffect>(HSQUIRRELVM vm, AICargo::TownEffect res) { sq_pushinteger(vm, (int32)res); return 1; }
/* Allow AICargo to be used as Squirrel parameter */
template <> AICargo *GetParam(ForceType<AICargo *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AICargo *)instance; }
@@ -31,12 +33,19 @@
SQAICargo.DefSQConst(engine, AICargo::CC_REFRIGERATED, "CC_REFRIGERATED");
SQAICargo.DefSQConst(engine, AICargo::CC_HAZARDOUS, "CC_HAZARDOUS");
SQAICargo.DefSQConst(engine, AICargo::CC_COVERED, "CC_COVERED");
+ SQAICargo.DefSQConst(engine, AICargo::TE_NONE, "TE_NONE");
+ SQAICargo.DefSQConst(engine, AICargo::TE_PASSENGERS, "TE_PASSENGERS");
+ SQAICargo.DefSQConst(engine, AICargo::TE_MAIL, "TE_MAIL");
+ SQAICargo.DefSQConst(engine, AICargo::TE_GOODS, "TE_GOODS");
+ SQAICargo.DefSQConst(engine, AICargo::TE_WATER, "TE_WATER");
+ SQAICargo.DefSQConst(engine, AICargo::TE_FOOD, "TE_FOOD");
SQAICargo.DefSQStaticMethod(engine, &AICargo::GetClassName, "GetClassName", 1, "x");
SQAICargo.DefSQStaticMethod(engine, &AICargo::IsValidCargo, "IsValidCargo", 2, "xi");
SQAICargo.DefSQStaticMethod(engine, &AICargo::GetCargoLabel, "GetCargoLabel", 2, "xi");
SQAICargo.DefSQStaticMethod(engine, &AICargo::IsFreight, "IsFreight", 2, "xi");
SQAICargo.DefSQStaticMethod(engine, &AICargo::HasCargoClass, "HasCargoClass", 3, "xii");
+ SQAICargo.DefSQStaticMethod(engine, &AICargo::GetTownEffect, "GetTownEffect", 2, "xi");
SQAICargo.DefSQStaticMethod(engine, &AICargo::GetCargoIncome, "GetCargoIncome", 4, "xiii");
SQAICargo.PostRegister(engine);