(svn r15860) -Add: AIRoad::GetRoadVehicleTypeForCargo() to tell whether a certain cargo needs a bus- or a truckstop.

This commit is contained in:
frosch 2009-03-26 19:45:45 +00:00
parent 6f15901769
commit 779a9f4e24
5 changed files with 32 additions and 0 deletions

View File

@ -329,6 +329,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));
} }
} }

View File

@ -824,6 +824,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 +835,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 +846,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 +857,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 +868,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 +879,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 +890,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 +901,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 +912,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 +923,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 +934,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 +945,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 +956,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 +967,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 +978,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 +989,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

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");