1
0
Fork 0

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

- Feature: Watermark crash.sav and do not generate crash information if a loaded crash.sav causes a crash so the real crash report does not get overwritten (r15893)
- Feature: Add autoclean_novehicles setting which will, when autoclean_companies is true, remove any company with no vehicles and no active client after autoclean_novehicles-months (r15848)
- Add: [NoAI] AIIndustryType::IsBuiltOnWater(), HasHeliport() and HasDock(). Just like AIIndustry (r15901)
- Add: [NoAI] AIBridge::GetBridgeID() so AIs can get the type of bridge that are already build (r15875)
- Add: [NoAI] AIRoad::GetRoadVehicleTypeForCargo() to tell whether a certain cargo needs a bus- or a truckstop (r15860)
release/0.7
rubidium 2009-03-30 23:22:13 +00:00
parent 76b2e1c5ab
commit 1595413545
21 changed files with 219 additions and 3 deletions

View File

@ -256,12 +256,15 @@ function Regression::Bridge()
print(" Valid Bridges: " + j); print(" Valid Bridges: " + j);
print(" IsBridgeTile(): " + AIBridge.IsBridgeTile(33160)); print(" IsBridgeTile(): " + AIBridge.IsBridgeTile(33160));
print(" GetBridgeID(): " + AIBridge.GetBridgeID(33160));
print(" RemoveBridge(): " + AIBridge.RemoveBridge(33155)); print(" RemoveBridge(): " + AIBridge.RemoveBridge(33155));
print(" GetLastErrorString(): " + AIError.GetLastErrorString()); print(" GetLastErrorString(): " + AIError.GetLastErrorString());
print(" GetOtherBridgeEnd(): " + AIBridge.GetOtherBridgeEnd(33160)); print(" GetOtherBridgeEnd(): " + AIBridge.GetOtherBridgeEnd(33160));
print(" BuildBridge(): " + AIBridge.BuildBridge(AIVehicle.VT_ROAD, 5, 33160, 33155)); print(" BuildBridge(): " + AIBridge.BuildBridge(AIVehicle.VT_ROAD, 5, 33160, 33155));
print(" IsBridgeTile(): " + AIBridge.IsBridgeTile(33160)); print(" IsBridgeTile(): " + AIBridge.IsBridgeTile(33160));
print(" GetBridgeID(): " + AIBridge.GetBridgeID(33160));
print(" IsBridgeTile(): " + AIBridge.IsBridgeTile(33155)); print(" IsBridgeTile(): " + AIBridge.IsBridgeTile(33155));
print(" GetBridgeID(): " + AIBridge.GetBridgeID(33155));
print(" GetOtherBridgeEnd(): " + AIBridge.GetOtherBridgeEnd(33160)); print(" GetOtherBridgeEnd(): " + AIBridge.GetOtherBridgeEnd(33160));
print(" BuildBridge(): " + AIBridge.BuildBridge(AIVehicle.VT_ROAD, 5, 33160, 33155)); print(" BuildBridge(): " + AIBridge.BuildBridge(AIVehicle.VT_ROAD, 5, 33160, 33155));
print(" GetLastErrorString(): " + AIError.GetLastErrorString()); print(" GetLastErrorString(): " + AIError.GetLastErrorString());
@ -329,6 +332,7 @@ function Regression::Cargo()
print(" GetCargoIncome(10, 10): " + AICargo.GetCargoIncome(i, 10, 10)); print(" GetCargoIncome(10, 10): " + AICargo.GetCargoIncome(i, 10, 10));
print(" GetCargoIncome(100, 10): " + AICargo.GetCargoIncome(i, 100, 10)); print(" GetCargoIncome(100, 10): " + AICargo.GetCargoIncome(i, 100, 10));
print(" GetCargoIncome(10, 100): " + AICargo.GetCargoIncome(i, 10, 100)); print(" GetCargoIncome(10, 100): " + AICargo.GetCargoIncome(i, 10, 100));
print(" GetRoadVehicleTypeForCargo(): " + AIRoad.GetRoadVehicleTypeForCargo(i));
} }
} }
@ -631,6 +635,9 @@ function Regression::IndustryTypeList()
print(" GetName(): " + AIIndustryType.GetName(i)); print(" GetName(): " + AIIndustryType.GetName(i));
print(" CanBuildIndustry(): " + AIIndustryType.CanBuildIndustry(i)); print(" CanBuildIndustry(): " + AIIndustryType.CanBuildIndustry(i));
print(" CanProspectIndustry(): " + AIIndustryType.CanProspectIndustry(i)); print(" CanProspectIndustry(): " + AIIndustryType.CanProspectIndustry(i));
print(" IsBuiltOnWater(): " + AIIndustryType.IsBuiltOnWater(i));
print(" HasHeliport(): " + AIIndustryType.HasHeliport(i));
print(" HasDock(): " + AIIndustryType.HasDock(i));
} }
} }

View File

@ -743,12 +743,15 @@
GetMinLength(): -1 GetMinLength(): -1
Valid Bridges: 10 Valid Bridges: 10
IsBridgeTile(): false IsBridgeTile(): false
GetBridgeID(): -1
RemoveBridge(): false RemoveBridge(): false
GetLastErrorString(): ERR_PRECONDITION_FAILED GetLastErrorString(): ERR_PRECONDITION_FAILED
GetOtherBridgeEnd(): -1 GetOtherBridgeEnd(): -1
BuildBridge(): true BuildBridge(): true
IsBridgeTile(): true IsBridgeTile(): true
GetBridgeID(): 5
IsBridgeTile(): true IsBridgeTile(): true
GetBridgeID(): 5
GetOtherBridgeEnd(): 33155 GetOtherBridgeEnd(): 33155
BuildBridge(): false BuildBridge(): false
GetLastErrorString(): ERR_ALREADY_BUILT GetLastErrorString(): ERR_ALREADY_BUILT
@ -824,6 +827,7 @@
GetCargoIncome(10, 10): -1 GetCargoIncome(10, 10): -1
GetCargoIncome(100, 10): -1 GetCargoIncome(100, 10): -1
GetCargoIncome(10, 100): -1 GetCargoIncome(10, 100): -1
GetRoadVehicleTypeForCargo(): 1
Cargo 0 Cargo 0
IsValidCargo(): true IsValidCargo(): true
GetCargoLabel(): 'PASS' GetCargoLabel(): 'PASS'
@ -834,6 +838,7 @@
GetCargoIncome(10, 10): 3 GetCargoIncome(10, 10): 3
GetCargoIncome(100, 10): 39 GetCargoIncome(100, 10): 39
GetCargoIncome(10, 100): 3 GetCargoIncome(10, 100): 3
GetRoadVehicleTypeForCargo(): 0
Cargo 1 Cargo 1
IsValidCargo(): true IsValidCargo(): true
GetCargoLabel(): 'COAL' GetCargoLabel(): 'COAL'
@ -844,6 +849,7 @@
GetCargoIncome(10, 10): 7 GetCargoIncome(10, 10): 7
GetCargoIncome(100, 10): 75 GetCargoIncome(100, 10): 75
GetCargoIncome(10, 100): 6 GetCargoIncome(10, 100): 6
GetRoadVehicleTypeForCargo(): 1
Cargo 2 Cargo 2
IsValidCargo(): true IsValidCargo(): true
GetCargoLabel(): 'MAIL' GetCargoLabel(): 'MAIL'
@ -854,6 +860,7 @@
GetCargoIncome(10, 10): 5 GetCargoIncome(10, 10): 5
GetCargoIncome(100, 10): 58 GetCargoIncome(100, 10): 58
GetCargoIncome(10, 100): 5 GetCargoIncome(10, 100): 5
GetRoadVehicleTypeForCargo(): 1
Cargo 3 Cargo 3
IsValidCargo(): true IsValidCargo(): true
GetCargoLabel(): 'OIL_' GetCargoLabel(): 'OIL_'
@ -864,6 +871,7 @@
GetCargoIncome(10, 10): 5 GetCargoIncome(10, 10): 5
GetCargoIncome(100, 10): 56 GetCargoIncome(100, 10): 56
GetCargoIncome(10, 100): 5 GetCargoIncome(10, 100): 5
GetRoadVehicleTypeForCargo(): 1
Cargo 4 Cargo 4
IsValidCargo(): true IsValidCargo(): true
GetCargoLabel(): 'LVST' GetCargoLabel(): 'LVST'
@ -874,6 +882,7 @@
GetCargoIncome(10, 10): 5 GetCargoIncome(10, 10): 5
GetCargoIncome(100, 10): 55 GetCargoIncome(100, 10): 55
GetCargoIncome(10, 100): 4 GetCargoIncome(10, 100): 4
GetRoadVehicleTypeForCargo(): 1
Cargo 5 Cargo 5
IsValidCargo(): true IsValidCargo(): true
GetCargoLabel(): 'GOOD' GetCargoLabel(): 'GOOD'
@ -884,6 +893,7 @@
GetCargoIncome(10, 10): 7 GetCargoIncome(10, 10): 7
GetCargoIncome(100, 10): 78 GetCargoIncome(100, 10): 78
GetCargoIncome(10, 100): 6 GetCargoIncome(10, 100): 6
GetRoadVehicleTypeForCargo(): 1
Cargo 6 Cargo 6
IsValidCargo(): true IsValidCargo(): true
GetCargoLabel(): 'GRAI' GetCargoLabel(): 'GRAI'
@ -894,6 +904,7 @@
GetCargoIncome(10, 10): 6 GetCargoIncome(10, 10): 6
GetCargoIncome(100, 10): 60 GetCargoIncome(100, 10): 60
GetCargoIncome(10, 100): 5 GetCargoIncome(10, 100): 5
GetRoadVehicleTypeForCargo(): 1
Cargo 7 Cargo 7
IsValidCargo(): true IsValidCargo(): true
GetCargoLabel(): 'WOOD' GetCargoLabel(): 'WOOD'
@ -904,6 +915,7 @@
GetCargoIncome(10, 10): 6 GetCargoIncome(10, 10): 6
GetCargoIncome(100, 10): 63 GetCargoIncome(100, 10): 63
GetCargoIncome(10, 100): 5 GetCargoIncome(10, 100): 5
GetRoadVehicleTypeForCargo(): 1
Cargo 8 Cargo 8
IsValidCargo(): true IsValidCargo(): true
GetCargoLabel(): 'IORE' GetCargoLabel(): 'IORE'
@ -914,6 +926,7 @@
GetCargoIncome(10, 10): 6 GetCargoIncome(10, 10): 6
GetCargoIncome(100, 10): 65 GetCargoIncome(100, 10): 65
GetCargoIncome(10, 100): 5 GetCargoIncome(10, 100): 5
GetRoadVehicleTypeForCargo(): 1
Cargo 9 Cargo 9
IsValidCargo(): true IsValidCargo(): true
GetCargoLabel(): 'STEL' GetCargoLabel(): 'STEL'
@ -924,6 +937,7 @@
GetCargoIncome(10, 10): 7 GetCargoIncome(10, 10): 7
GetCargoIncome(100, 10): 72 GetCargoIncome(100, 10): 72
GetCargoIncome(10, 100): 6 GetCargoIncome(10, 100): 6
GetRoadVehicleTypeForCargo(): 1
Cargo 10 Cargo 10
IsValidCargo(): true IsValidCargo(): true
GetCargoLabel(): 'VALU' GetCargoLabel(): 'VALU'
@ -934,6 +948,7 @@
GetCargoIncome(10, 10): 9 GetCargoIncome(10, 10): 9
GetCargoIncome(100, 10): 94 GetCargoIncome(100, 10): 94
GetCargoIncome(10, 100): 7 GetCargoIncome(10, 100): 7
GetRoadVehicleTypeForCargo(): 1
Cargo 11 Cargo 11
IsValidCargo(): false IsValidCargo(): false
GetCargoLabel(): '(null : 0x00000000)' GetCargoLabel(): '(null : 0x00000000)'
@ -944,6 +959,7 @@
GetCargoIncome(10, 10): -1 GetCargoIncome(10, 10): -1
GetCargoIncome(100, 10): -1 GetCargoIncome(100, 10): -1
GetCargoIncome(10, 100): -1 GetCargoIncome(10, 100): -1
GetRoadVehicleTypeForCargo(): 1
Cargo 12 Cargo 12
IsValidCargo(): false IsValidCargo(): false
GetCargoLabel(): '(null : 0x00000000)' GetCargoLabel(): '(null : 0x00000000)'
@ -954,6 +970,7 @@
GetCargoIncome(10, 10): -1 GetCargoIncome(10, 10): -1
GetCargoIncome(100, 10): -1 GetCargoIncome(100, 10): -1
GetCargoIncome(10, 100): -1 GetCargoIncome(10, 100): -1
GetRoadVehicleTypeForCargo(): 1
Cargo 13 Cargo 13
IsValidCargo(): false IsValidCargo(): false
GetCargoLabel(): '(null : 0x00000000)' GetCargoLabel(): '(null : 0x00000000)'
@ -964,6 +981,7 @@
GetCargoIncome(10, 10): -1 GetCargoIncome(10, 10): -1
GetCargoIncome(100, 10): -1 GetCargoIncome(100, 10): -1
GetCargoIncome(10, 100): -1 GetCargoIncome(10, 100): -1
GetRoadVehicleTypeForCargo(): 1
Cargo 14 Cargo 14
IsValidCargo(): false IsValidCargo(): false
GetCargoLabel(): '(null : 0x00000000)' GetCargoLabel(): '(null : 0x00000000)'
@ -974,6 +992,7 @@
GetCargoIncome(10, 10): -1 GetCargoIncome(10, 10): -1
GetCargoIncome(100, 10): -1 GetCargoIncome(100, 10): -1
GetCargoIncome(10, 100): -1 GetCargoIncome(10, 100): -1
GetRoadVehicleTypeForCargo(): 1
--CargoList-- --CargoList--
Count(): 11 Count(): 11
@ -6907,6 +6926,9 @@
GetName(): Farm GetName(): Farm
CanBuildIndustry(): false CanBuildIndustry(): false
CanProspectIndustry(): false CanProspectIndustry(): false
IsBuiltOnWater(): false
HasHeliport(): false
HasDock(): false
Id: 5 Id: 5
IsRawIndustry(): true IsRawIndustry(): true
ProductionCanIncrease(): true ProductionCanIncrease(): true
@ -6914,6 +6936,9 @@
GetName(): Oil Rig GetName(): Oil Rig
CanBuildIndustry(): false CanBuildIndustry(): false
CanProspectIndustry(): false CanProspectIndustry(): false
IsBuiltOnWater(): true
HasHeliport(): true
HasDock(): true
Id: 12 Id: 12
IsRawIndustry(): false IsRawIndustry(): false
ProductionCanIncrease(): true ProductionCanIncrease(): true
@ -6921,6 +6946,9 @@
GetName(): Bank GetName(): Bank
CanBuildIndustry(): true CanBuildIndustry(): true
CanProspectIndustry(): false CanProspectIndustry(): false
IsBuiltOnWater(): false
HasHeliport(): false
HasDock(): false
Id: 11 Id: 11
IsRawIndustry(): true IsRawIndustry(): true
ProductionCanIncrease(): false ProductionCanIncrease(): false
@ -6928,6 +6956,9 @@
GetName(): Oil Wells GetName(): Oil Wells
CanBuildIndustry(): false CanBuildIndustry(): false
CanProspectIndustry(): false CanProspectIndustry(): false
IsBuiltOnWater(): false
HasHeliport(): false
HasDock(): false
Id: 1 Id: 1
IsRawIndustry(): false IsRawIndustry(): false
ProductionCanIncrease(): true ProductionCanIncrease(): true
@ -6935,6 +6966,9 @@
GetName(): Power Station GetName(): Power Station
CanBuildIndustry(): true CanBuildIndustry(): true
CanProspectIndustry(): false CanProspectIndustry(): false
IsBuiltOnWater(): false
HasHeliport(): false
HasDock(): false
Id: 3 Id: 3
IsRawIndustry(): true IsRawIndustry(): true
ProductionCanIncrease(): true ProductionCanIncrease(): true
@ -6942,6 +6976,9 @@
GetName(): Forest GetName(): Forest
CanBuildIndustry(): false CanBuildIndustry(): false
CanProspectIndustry(): false CanProspectIndustry(): false
IsBuiltOnWater(): false
HasHeliport(): false
HasDock(): false
Id: 2 Id: 2
IsRawIndustry(): false IsRawIndustry(): false
ProductionCanIncrease(): true ProductionCanIncrease(): true
@ -6949,6 +6986,9 @@
GetName(): Sawmill GetName(): Sawmill
CanBuildIndustry(): true CanBuildIndustry(): true
CanProspectIndustry(): false CanProspectIndustry(): false
IsBuiltOnWater(): false
HasHeliport(): false
HasDock(): false
Id: 18 Id: 18
IsRawIndustry(): true IsRawIndustry(): true
ProductionCanIncrease(): true ProductionCanIncrease(): true
@ -6956,6 +6996,9 @@
GetName(): Iron Ore Mine GetName(): Iron Ore Mine
CanBuildIndustry(): false CanBuildIndustry(): false
CanProspectIndustry(): false CanProspectIndustry(): false
IsBuiltOnWater(): false
HasHeliport(): false
HasDock(): false
Id: 0 Id: 0
IsRawIndustry(): true IsRawIndustry(): true
ProductionCanIncrease(): true ProductionCanIncrease(): true
@ -6963,6 +7006,9 @@
GetName(): Coal Mine GetName(): Coal Mine
CanBuildIndustry(): false CanBuildIndustry(): false
CanProspectIndustry(): false CanProspectIndustry(): false
IsBuiltOnWater(): false
HasHeliport(): false
HasDock(): false
Id: 8 Id: 8
IsRawIndustry(): false IsRawIndustry(): false
ProductionCanIncrease(): true ProductionCanIncrease(): true
@ -6970,6 +7016,9 @@
GetName(): Steel Mill GetName(): Steel Mill
CanBuildIndustry(): true CanBuildIndustry(): true
CanProspectIndustry(): false CanProspectIndustry(): false
IsBuiltOnWater(): false
HasHeliport(): false
HasDock(): false
Id: 4 Id: 4
IsRawIndustry(): false IsRawIndustry(): false
ProductionCanIncrease(): true ProductionCanIncrease(): true
@ -6977,6 +7026,9 @@
GetName(): Oil Refinery GetName(): Oil Refinery
CanBuildIndustry(): true CanBuildIndustry(): true
CanProspectIndustry(): false CanProspectIndustry(): false
IsBuiltOnWater(): false
HasHeliport(): false
HasDock(): false
Id: 6 Id: 6
IsRawIndustry(): false IsRawIndustry(): false
ProductionCanIncrease(): true ProductionCanIncrease(): true
@ -6984,6 +7036,9 @@
GetName(): Factory GetName(): Factory
CanBuildIndustry(): true CanBuildIndustry(): true
CanProspectIndustry(): false CanProspectIndustry(): false
IsBuiltOnWater(): false
HasHeliport(): false
HasDock(): false
--Map-- --Map--
GetMapSize(): 65536 GetMapSize(): 65536

View File

@ -23,6 +23,12 @@
return ::IsBridgeTile(tile); return ::IsBridgeTile(tile);
} }
/* static */ BridgeID AIBridge::GetBridgeID(TileIndex tile)
{
if (!IsBridgeTile(tile)) return -1;
return (BridgeID)::GetBridgeType(tile);
}
static void _DoCommandReturnBuildBridge2(class AIInstance *instance) static void _DoCommandReturnBuildBridge2(class AIInstance *instance)
{ {
if (!AIBridge::_BuildBridgeRoad2()) { if (!AIBridge::_BuildBridgeRoad2()) {

View File

@ -51,6 +51,14 @@ public:
*/ */
static bool IsBridgeTile(TileIndex tile); static bool IsBridgeTile(TileIndex tile);
/**
* Get the BridgeID of a bridge at a given tile.
* @param tile The tile to get the BridgeID from.
* @pre IsBridgeTile(tile).
* @return The BridgeID from the bridge at tile 'tile'.
*/
static BridgeID GetBridgeID(TileIndex tile);
/** /**
* Get the name of a bridge. * Get the name of a bridge.
* @param bridge_id The bridge to get the name of. * @param bridge_id The bridge to get the name of.

View File

@ -36,6 +36,7 @@ void SQAIBridge_Register(Squirrel *engine) {
SQAIBridge.DefSQStaticMethod(engine, &AIBridge::IsValidBridge, "IsValidBridge", 2, ".i"); SQAIBridge.DefSQStaticMethod(engine, &AIBridge::IsValidBridge, "IsValidBridge", 2, ".i");
SQAIBridge.DefSQStaticMethod(engine, &AIBridge::IsBridgeTile, "IsBridgeTile", 2, ".i"); SQAIBridge.DefSQStaticMethod(engine, &AIBridge::IsBridgeTile, "IsBridgeTile", 2, ".i");
SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetBridgeID, "GetBridgeID", 2, ".i");
SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetName, "GetName", 2, ".i"); SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetName, "GetName", 2, ".i");
SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetMaxSpeed, "GetMaxSpeed", 2, ".i"); SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetMaxSpeed, "GetMaxSpeed", 2, ".i");
SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetPrice, "GetPrice", 3, ".ii"); SQAIBridge.DefSQStaticMethod(engine, &AIBridge::GetPrice, "GetPrice", 3, ".ii");

View File

@ -18,7 +18,7 @@ public:
* The classes of cargo (from newgrf_cargo.h). * The classes of cargo (from newgrf_cargo.h).
*/ */
enum CargoClass { enum CargoClass {
CC_PASSENGERS = 1 << 0, //!< Passengers CC_PASSENGERS = 1 << 0, //!< Passengers. Cargos of this class appear at bus stops. Cargos not of this class appear at truck stops.
CC_MAIL = 1 << 1, //!< Mail CC_MAIL = 1 << 1, //!< Mail
CC_EXPRESS = 1 << 2, //!< Express cargo (Goods, Food, Candy, but also possible for passengers) CC_EXPRESS = 1 << 2, //!< Express cargo (Goods, Food, Candy, but also possible for passengers)
CC_ARMOURED = 1 << 3, //!< Armoured cargo (Valuables, Gold, Diamonds) CC_ARMOURED = 1 << 3, //!< Armoured cargo (Valuables, Gold, Diamonds)
@ -52,6 +52,7 @@ public:
/** /**
* Gets the string representation of the cargo label. * Gets the string representation of the cargo label.
* @param cargo_type The cargo to get the string representation of. * @param cargo_type The cargo to get the string representation of.
* @pre AICargo::IsValidCargo(cargo_type).
* @return The cargo label. * @return The cargo label.
* @note Never use this to check if it is a certain cargo. NewGRF can * @note Never use this to check if it is a certain cargo. NewGRF can
* redefine all of the names. * redefine all of the names.
@ -60,7 +61,10 @@ public:
/** /**
* Checks whether the give cargo is a freight or not. * Checks whether the give cargo is a freight or not.
* This defines whether the "freight train weight multiplier" will apply to
* trains transporting this cargo.
* @param cargo_type The cargo to check on. * @param cargo_type The cargo to check on.
* @pre AICargo::IsValidCargo(cargo_type).
* @return True if and only if the cargo is freight. * @return True if and only if the cargo is freight.
*/ */
static bool IsFreight(CargoID cargo_type); static bool IsFreight(CargoID cargo_type);
@ -68,6 +72,7 @@ public:
/** /**
* Check if this cargo is in the requested cargo class. * Check if this cargo is in the requested cargo class.
* @param cargo_type The cargo to check on. * @param cargo_type The cargo to check on.
* @pre AICargo::IsValidCargo(cargo_type).
* @param cargo_class The class to check for. * @param cargo_class The class to check for.
* @return True if and only if the cargo is in the cargo class. * @return True if and only if the cargo is in the cargo class.
*/ */
@ -76,6 +81,7 @@ public:
/** /**
* Get the effect this cargo has on a town. * Get the effect this cargo has on a town.
* @param cargo_type The cargo to check on. * @param cargo_type The cargo to check on.
* @pre AICargo::IsValidCargo(cargo_type).
* @return The effect this cargo has on a town, or TE_NONE if it has no effect. * @return The effect this cargo has on a town, or TE_NONE if it has no effect.
*/ */
static TownEffect GetTownEffect(CargoID cargo_type); static TownEffect GetTownEffect(CargoID cargo_type);
@ -84,6 +90,7 @@ public:
* Get the income for transporting a piece of cargo over the * Get the income for transporting a piece of cargo over the
* given distance within the specified time. * given distance within the specified time.
* @param cargo_type The cargo to transport. * @param cargo_type The cargo to transport.
* @pre AICargo::IsValidCargo(cargo_type).
* @param distance The distance the cargo travels from begin to end. * @param distance The distance the cargo travels from begin to end.
* @param days_in_transit Amount of (game) days the cargo is in transit. The max value of this variable is 637. Any value higher returns the same as 637 would. * @param days_in_transit Amount of (game) days the cargo is in transit. The max value of this variable is 637. Any value higher returns the same as 637 would.
* @return The amount of money that would be earned by this trip. * @return The amount of money that would be earned by this trip.

View File

@ -111,3 +111,24 @@
uint32 seed = ::InteractiveRandom(); uint32 seed = ::InteractiveRandom();
return AIObject::DoCommand(0, industry_type, seed, CMD_BUILD_INDUSTRY); return AIObject::DoCommand(0, industry_type, seed, CMD_BUILD_INDUSTRY);
} }
/* static */ bool AIIndustryType::IsBuiltOnWater(IndustryType industry_type)
{
if (!IsValidIndustryType(industry_type)) return false;
return (::GetIndustrySpec(industry_type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0;
}
/* static */ bool AIIndustryType::HasHeliport(IndustryType industry_type)
{
if (!IsValidIndustryType(industry_type)) return false;
return (::GetIndustrySpec(industry_type)->behaviour & INDUSTRYBEH_AI_AIRSHIP_ROUTES) != 0;
}
/* static */ bool AIIndustryType::HasDock(IndustryType industry_type)
{
if (!IsValidIndustryType(industry_type)) return false;
return (::GetIndustrySpec(industry_type)->behaviour & INDUSTRYBEH_AI_AIRSHIP_ROUTES) != 0;
}

View File

@ -113,6 +113,30 @@ public:
* @note If true is returned the money is paid, whether a new industry was build or not. * @note If true is returned the money is paid, whether a new industry was build or not.
*/ */
static bool ProspectIndustry(IndustryType industry_type); static bool ProspectIndustry(IndustryType industry_type);
/**
* Is this type of industry built on water.
* @param industry_type The type of the industry.
* @pre IsValidIndustryType(industry_type).
* @return True when this type is built on water.
*/
static bool IsBuiltOnWater(IndustryType industry_type);
/**
* Does this type of industry have a heliport?
* @param industry_type The type of the industry.
* @pre IsValidIndustryType(industry_type).
* @return True when this type has a heliport.
*/
static bool HasHeliport(IndustryType industry_type);
/**
* Does this type of industry have a dock?
* @param industry_type The type of the industry.
* @pre IsValidIndustryType(industry_type).
* @return True when this type has a dock.
*/
static bool HasDock(IndustryType industry_type);
}; };
#endif /* AI_INDUSTRYTYPE_HPP */ #endif /* AI_INDUSTRYTYPE_HPP */

View File

@ -28,6 +28,9 @@ void SQAIIndustryType_Register(Squirrel *engine) {
SQAIIndustryType.DefSQStaticMethod(engine, &AIIndustryType::CanProspectIndustry, "CanProspectIndustry", 2, ".i"); SQAIIndustryType.DefSQStaticMethod(engine, &AIIndustryType::CanProspectIndustry, "CanProspectIndustry", 2, ".i");
SQAIIndustryType.DefSQStaticMethod(engine, &AIIndustryType::BuildIndustry, "BuildIndustry", 3, ".ii"); SQAIIndustryType.DefSQStaticMethod(engine, &AIIndustryType::BuildIndustry, "BuildIndustry", 3, ".ii");
SQAIIndustryType.DefSQStaticMethod(engine, &AIIndustryType::ProspectIndustry, "ProspectIndustry", 2, ".i"); SQAIIndustryType.DefSQStaticMethod(engine, &AIIndustryType::ProspectIndustry, "ProspectIndustry", 2, ".i");
SQAIIndustryType.DefSQStaticMethod(engine, &AIIndustryType::IsBuiltOnWater, "IsBuiltOnWater", 2, ".i");
SQAIIndustryType.DefSQStaticMethod(engine, &AIIndustryType::HasHeliport, "HasHeliport", 2, ".i");
SQAIIndustryType.DefSQStaticMethod(engine, &AIIndustryType::HasDock, "HasDock", 2, ".i");
SQAIIndustryType.PostRegister(engine); SQAIIndustryType.PostRegister(engine);
} }

View File

@ -5,12 +5,18 @@
#include "ai_road.hpp" #include "ai_road.hpp"
#include "ai_map.hpp" #include "ai_map.hpp"
#include "ai_station.hpp" #include "ai_station.hpp"
#include "ai_cargo.hpp"
#include "../../station_map.h" #include "../../station_map.h"
#include "../../command_type.h" #include "../../command_type.h"
#include "../../settings_type.h" #include "../../settings_type.h"
#include "../../company_func.h" #include "../../company_func.h"
#include "../../script/squirrel_helper_type.hpp" #include "../../script/squirrel_helper_type.hpp"
/* static */ AIRoad::RoadVehicleType AIRoad::GetRoadVehicleTypeForCargo(CargoID cargo_type)
{
return AICargo::HasCargoClass(cargo_type, AICargo::CC_PASSENGERS) ? ROADVEHTYPE_BUS : ROADVEHTYPE_TRUCK;
}
/* static */ bool AIRoad::IsRoadTile(TileIndex tile) /* static */ bool AIRoad::IsRoadTile(TileIndex tile)
{ {
if (!::IsValidTile(tile)) return false; if (!::IsValidTile(tile)) return false;

View File

@ -56,6 +56,14 @@ public:
ROADVEHTYPE_TRUCK, //!< Build objects useable for trucks and cargo trams ROADVEHTYPE_TRUCK, //!< Build objects useable for trucks and cargo trams
}; };
/**
* Determines whether a busstop or a truckstop is needed to transport a certain cargo.
* @param cargo_type The cargo to test.
* @pre AICargo::IsValidCargo(cargo_type).
* @return The road vehicle type needed to transport the cargo.
*/
static RoadVehicleType GetRoadVehicleTypeForCargo(CargoID cargo_type);
/** /**
* Checks whether the given tile is actually a tile with road that can be * Checks whether the given tile is actually a tile with road that can be
* used to traverse a tile. This excludes road depots and 'normal' road * used to traverse a tile. This excludes road depots and 'normal' road

View File

@ -46,6 +46,7 @@ void SQAIRoad_Register(Squirrel *engine) {
AIError::RegisterErrorMapString(AIRoad::ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD, "ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD"); AIError::RegisterErrorMapString(AIRoad::ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD, "ERR_ROAD_CANNOT_BUILD_ON_TOWN_ROAD");
AIError::RegisterErrorMapString(AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS, "ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS"); AIError::RegisterErrorMapString(AIRoad::ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS, "ERR_ROAD_ONE_WAY_ROADS_CANNOT_HAVE_JUNCTIONS");
SQAIRoad.DefSQStaticMethod(engine, &AIRoad::GetRoadVehicleTypeForCargo, "GetRoadVehicleTypeForCargo", 2, ".i");
SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsRoadTile, "IsRoadTile", 2, ".i"); SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsRoadTile, "IsRoadTile", 2, ".i");
SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsRoadDepotTile, "IsRoadDepotTile", 2, ".i"); SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsRoadDepotTile, "IsRoadDepotTile", 2, ".i");
SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsRoadStationTile, "IsRoadStationTile", 2, ".i"); SQAIRoad.DefSQStaticMethod(engine, &AIRoad::IsRoadStationTile, "IsRoadStationTile", 2, ".i");

View File

@ -135,6 +135,7 @@ static const char *la_text[] = {
"cheat was used", "cheat was used",
"settings changed", "settings changed",
"GRF bug triggered", "GRF bug triggered",
"emergency savegame",
}; };
assert_compile(lengthof(la_text) == GLAT_END); assert_compile(lengthof(la_text) == GLAT_END);
@ -249,6 +250,9 @@ void GamelogPrint(GamelogPrintProc *proc)
PrintGrfFilename(buf, lc->grfbug.grfid); PrintGrfFilename(buf, lc->grfbug.grfid);
break; break;
} }
case GLCT_EMERGENCY:
break;
} }
proc(buf); proc(buf);
@ -317,6 +321,31 @@ static LoggedChange *GamelogChange(GamelogChangeType ct)
} }
/** Logs a emergency savegame
*/
void GamelogEmergency()
{
assert(_gamelog_action_type == GLAT_EMERGENCY);
GamelogChange(GLCT_EMERGENCY);
}
/** Finds out if current game is a loaded emergency savegame.
*/
bool GamelogTestEmergency()
{
const LoggedChange *emergency = NULL;
const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
for (const LoggedAction *la = _gamelog_action; la != laend; la++) {
const LoggedChange *lcend = &la->change[la->changes];
for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
if (lc->ct == GLCT_EMERGENCY) emergency = lc;
}
}
return (emergency != NULL);
}
/** Logs a change in game revision /** Logs a change in game revision
* @param revision new revision string * @param revision new revision string
*/ */

View File

@ -14,6 +14,7 @@ enum GamelogActionType {
GLAT_CHEAT, ///< Cheat was used GLAT_CHEAT, ///< Cheat was used
GLAT_SETTING, ///< Setting changed GLAT_SETTING, ///< Setting changed
GLAT_GRFBUG, ///< GRF bug was triggered GLAT_GRFBUG, ///< GRF bug was triggered
GLAT_EMERGENCY, ///< Emergency savegame
GLAT_END, ///< So we know how many GLATs are there GLAT_END, ///< So we know how many GLATs are there
GLAT_NONE = 0xFF, ///< No logging active; in savegames, end of list GLAT_NONE = 0xFF, ///< No logging active; in savegames, end of list
}; };
@ -29,6 +30,9 @@ void GamelogPrint(GamelogPrintProc *proc); // needed for WIN32 / WINCE crash.log
void GamelogPrintDebug(int level); void GamelogPrintDebug(int level);
void GamelogPrintConsole(); void GamelogPrintConsole();
void GamelogEmergency();
bool GamelogTestEmergency();
void GamelogRevision(); void GamelogRevision();
void GamelogMode(); void GamelogMode();
void GamelogOldver(); void GamelogOldver();

View File

@ -19,6 +19,7 @@ enum GamelogChangeType {
GLCT_GRFPARAM, ///< GRF parameter changed GLCT_GRFPARAM, ///< GRF parameter changed
GLCT_GRFMOVE, ///< GRF order changed GLCT_GRFMOVE, ///< GRF order changed
GLCT_GRFBUG, ///< GRF bug triggered GLCT_GRFBUG, ///< GRF bug triggered
GLCT_EMERGENCY, ///< Emergency savegame
GLCT_END, ///< So we know how many GLCTs are there GLCT_END, ///< So we know how many GLCTs are there
GLCT_NONE = 0xFF, ///< In savegames, end of list GLCT_NONE = 0xFF, ///< In savegames, end of list
}; };

View File

@ -1418,6 +1418,7 @@ static void NetworkAutoCleanCompanies()
const NetworkClientInfo *ci; const NetworkClientInfo *ci;
const Company *c; const Company *c;
bool clients_in_company[MAX_COMPANIES]; bool clients_in_company[MAX_COMPANIES];
int vehicles_in_company[MAX_COMPANIES];
if (!_settings_client.network.autoclean_companies) return; if (!_settings_client.network.autoclean_companies) return;
@ -1433,6 +1434,16 @@ static void NetworkAutoCleanCompanies()
if (IsValidCompanyID(ci->client_playas)) clients_in_company[ci->client_playas] = true; if (IsValidCompanyID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
} }
if (_settings_client.network.autoclean_novehicles != 0) {
memset(vehicles_in_company, 0, sizeof(vehicles_in_company));
const Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (!IsValidCompanyID(v->owner) || !v->IsPrimaryVehicle()) continue;
vehicles_in_company[v->owner]++;
}
}
/* Go through all the comapnies */ /* Go through all the comapnies */
FOR_ALL_COMPANIES(c) { FOR_ALL_COMPANIES(c) {
/* Skip the non-active once */ /* Skip the non-active once */
@ -1446,7 +1457,7 @@ static void NetworkAutoCleanCompanies()
if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && StrEmpty(_network_company_states[c->index].password)) { if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && StrEmpty(_network_company_states[c->index].password)) {
/* Shut the company down */ /* Shut the company down */
DoCommandP(0, 2, c->index, CMD_COMPANY_CTRL); DoCommandP(0, 2, c->index, CMD_COMPANY_CTRL);
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d", c->index + 1); IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no password", c->index + 1);
} }
/* Is the company empty for autoclean_protected-months, and there is a protection? */ /* Is the company empty for autoclean_protected-months, and there is a protection? */
if (_settings_client.network.autoclean_protected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_protected && !StrEmpty(_network_company_states[c->index].password)) { if (_settings_client.network.autoclean_protected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_protected && !StrEmpty(_network_company_states[c->index].password)) {
@ -1456,6 +1467,12 @@ static void NetworkAutoCleanCompanies()
_network_company_states[c->index].months_empty = 0; _network_company_states[c->index].months_empty = 0;
NetworkServerUpdateCompanyPassworded(c->index, false); NetworkServerUpdateCompanyPassworded(c->index, false);
} }
/* Is the company empty for autoclean_novehicles-months, and has no vehicles? */
if (_settings_client.network.autoclean_novehicles != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_novehicles && vehicles_in_company[c->index] == 0) {
/* Shut the company down */
DoCommandP(0, 2, c->index, CMD_COMPANY_CTRL);
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no vehicles", c->index + 1);
}
} else { } else {
/* It is not empty, reset the date */ /* It is not empty, reset the date */
_network_company_states[c->index].months_empty = 0; _network_company_states[c->index].months_empty = 0;

View File

@ -76,6 +76,10 @@ static const SaveLoad _glog_grfbug_desc[] = {
SLE_END() SLE_END()
}; };
static const SaveLoad _glog_emergency_desc[] = {
SLE_END()
};
static const SaveLoad *_glog_desc[] = { static const SaveLoad *_glog_desc[] = {
_glog_mode_desc, _glog_mode_desc,
_glog_revision_desc, _glog_revision_desc,
@ -87,6 +91,7 @@ static const SaveLoad *_glog_desc[] = {
_glog_grfparam_desc, _glog_grfparam_desc,
_glog_grfmove_desc, _glog_grfmove_desc,
_glog_grfbug_desc, _glog_grfbug_desc,
_glog_emergency_desc,
}; };
assert_compile(lengthof(_glog_desc) == GLCT_END); assert_compile(lengthof(_glog_desc) == GLCT_END);

View File

@ -40,7 +40,7 @@
#include "saveload_internal.h" #include "saveload_internal.h"
extern const uint16 SAVEGAME_VERSION = 115; extern const uint16 SAVEGAME_VERSION = 116;
SavegameType _savegame_type; ///< type of savegame we are loading SavegameType _savegame_type; ///< type of savegame we are loading

View File

@ -1567,6 +1567,7 @@ const SettingDesc _settings[] = {
SDTC_BOOL(network.autoclean_companies, S, NO, false, STR_NULL, NULL), SDTC_BOOL(network.autoclean_companies, S, NO, false, STR_NULL, NULL),
SDTC_VAR(network.autoclean_unprotected, SLE_UINT8, S,D0|NO, 12, 0, 240, 0, STR_NULL, NULL), SDTC_VAR(network.autoclean_unprotected, SLE_UINT8, S,D0|NO, 12, 0, 240, 0, STR_NULL, NULL),
SDTC_VAR(network.autoclean_protected, SLE_UINT8, S,D0|NO, 36, 0, 240, 0, STR_NULL, NULL), SDTC_VAR(network.autoclean_protected, SLE_UINT8, S,D0|NO, 36, 0, 240, 0, STR_NULL, NULL),
SDTC_VAR(network.autoclean_novehicles, SLE_UINT8, S,D0|NO, 0, 0, 240, 0, STR_NULL, NULL),
SDTC_VAR(network.max_companies, SLE_UINT8, S, NO, 8, 1,MAX_COMPANIES,0, STR_NULL, UpdateClientConfigValues), SDTC_VAR(network.max_companies, SLE_UINT8, S, NO, 8, 1,MAX_COMPANIES,0, STR_NULL, UpdateClientConfigValues),
SDTC_VAR(network.max_clients, SLE_UINT8, S, NO, 16, 2, MAX_CLIENTS, 0, STR_NULL, NULL), SDTC_VAR(network.max_clients, SLE_UINT8, S, NO, 16, 2, MAX_CLIENTS, 0, STR_NULL, NULL),
SDTC_VAR(network.max_spectators, SLE_UINT8, S, NO, 8, 0, MAX_CLIENTS, 0, STR_NULL, UpdateClientConfigValues), SDTC_VAR(network.max_spectators, SLE_UINT8, S, NO, 8, 0, MAX_CLIENTS, 0, STR_NULL, UpdateClientConfigValues),

View File

@ -126,6 +126,7 @@ struct NetworkSettings {
bool autoclean_companies; ///< automatically remove companies that are not in use bool autoclean_companies; ///< automatically remove companies that are not in use
uint8 autoclean_unprotected; ///< remove passwordless companies after this many months uint8 autoclean_unprotected; ///< remove passwordless companies after this many months
uint8 autoclean_protected; ///< remove the password from passworded companies after this many months uint8 autoclean_protected; ///< remove the password from passworded companies after this many months
uint8 autoclean_novehicles; ///< remove companies with no vehicles after this many months
uint8 max_companies; ///< maximum amount of companies uint8 max_companies; ///< maximum amount of companies
uint8 max_clients; ///< maximum amount of clients uint8 max_clients; ///< maximum amount of clients
uint8 max_spectators; ///< maximum amount of spectators uint8 max_spectators; ///< maximum amount of spectators

View File

@ -234,8 +234,15 @@ static const TCHAR _save_succeeded[] =
_T("Be aware that critical parts of the internal game state may have become ") _T("Be aware that critical parts of the internal game state may have become ")
_T("corrupted. The saved game is not guaranteed to work."); _T("corrupted. The saved game is not guaranteed to work.");
static const TCHAR _emergency_crash[] =
_T("A serious fault condition occured in the game. The game will shut down.\n")
_T("As you loaded an emergency savegame no crash information will be generated.\n");
static bool EmergencySave() static bool EmergencySave()
{ {
GamelogStartAction(GLAT_EMERGENCY);
GamelogEmergency();
GamelogStopAction();
SaveOrLoad("crash.sav", SL_SAVE, BASE_DIR); SaveOrLoad("crash.sav", SL_SAVE, BASE_DIR);
return true; return true;
} }
@ -471,6 +478,10 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
static bool had_exception = false; static bool had_exception = false;
if (had_exception) ExitProcess(0); if (had_exception) ExitProcess(0);
if (GamelogTestEmergency()) {
MessageBox(NULL, _emergency_crash, _T("Fatal Application Failure"), MB_ICONERROR);
ExitProcess(0);
}
had_exception = true; had_exception = true;
_ident = GetTickCount(); // something pretty unique _ident = GetTickCount(); // something pretty unique