Define the WormRailManager class which handles trains. More...
Public Member Functions | |
constructor | WormRailManager () |
Create an instance of WormRailManager and initialize our variables. | |
function | UpdateRailType () |
Updates the current rail type of the AI based on the maximum number of cargoes transportable. | |
function | BuildRailway () |
Main function for building a railway which decides all the details. | |
function | RegisterRoute (route_data, station_data, vehtype, group, train_length) |
Register the new route into the database. | |
function | CheckRoutes () |
Checks all routes. | |
function | GetOptimalTrainLength (route) |
Get the optimal train length for this route. | |
function | GetMinMaxTrainLength (vehicles) |
Get the minimum and maximum length of trains in the supplied list of vehicles. | |
function | CheckDefaultGroup () |
Checks ungrouped vehicles. | |
function | CheckAddTrainToGroup (route, vehicle_count, first_vehicle) |
Check if we should add another train to the specified group. | |
function | SelectAndAddTrain (route) |
Select optimal wagon and train engine for the specified route and buy it if possible. | |
function | AddVehicle (route, mainvehicle, engine, wagon) |
Adds a new vehicle to an existing route. | |
function | ReplaceVehicle (vehicle) |
Replaces an old vehicle with a newer model if it is already in the depot. | |
function | HandleVehicleInDepot (vehicle) |
Handle a vehicle that is stopped in depot for selling, replacement or attaching wagons. | |
function | CheckTrainProfits () |
Check train profits and send unprofitable ones to depot to be sold. | |
function | SendTrainToDepotForSelling (vehicle) |
Check train profits and send unprofitable ones to depot to be sold. | |
function | SaveData (table) |
Save all data that WormRailManager needs in table. | |
function | LoadData (table, worm_save_version) |
Load all data that WormRailManager from the table. | |
function | AfterLoading () |
Do any necessary processing after a savegame has been loaded. |
Static Public Member Functions | |
static function | SetGroupName (group, crg, stasrc) |
Set the name of a vehicle group. | |
static function | IsRectangleWithinTownInfluence (tile, town_id, width, height) |
Checks whether a given rectangle is within the influence of a given town. | |
static function | SetRailType () |
Sets the current rail type of the AI based on the maximum number of cargoes transportable. |
Public Attributes | |
routes = null | |
An array containing all our routes. | |
groups = null | |
The list of vehicle groups. | |
serviced = null | |
Industry/town - cargo pairs already serviced. | |
railbridges = null | |
The list of rail bridges. | |
engine_blacklist = null | |
The blacklist of train engines. | |
buildingstage = null | |
The current building stage. | |
lastroute = null | |
The date the last route was built. | |
removelist = null | |
An array used to continue rail removal and electrification. | |
todepotlist = null | |
A list of vehicles heading for the depot. | |
route_without_trains = -1 | |
Group number or -1 of unfinished route that needs trains added. | |
last_route = null | |
route info table of last completed route. Needed if we still need to buy trains for this route. |
Static Public Attributes | |
static | BS_NOTHING = 0 |
Building stages, needed to recover a savegame. | |
static | BS_BUILDING = 1 |
static | BS_REMOVING = 2 |
static | BS_ELECTRIFYING = 3 |
static | TD_SELL = 1 |
Reasons to send a vehicle to a depot. | |
static | TD_REPLACE = 2 |
static | TD_ATTACH_WAGONS = 3 |
Define the WormRailManager class which handles trains.
|
inline |
Create an instance of WormRailManager and initialize our variables.
function WormRailManager::AddVehicle | ( | route | , |
mainvehicle | , | ||
engine | , | ||
wagon | |||
) |
Adds a new vehicle to an existing route.
route | The route to which the new vehicle will be added. |
mainvehicle | An already existing vehicle on the route to share orders with. |
engine | The EngineID of the new vehicle. In case of trains it is the EngineID of the locomotive. |
wagon | The EngineID of the train wagons. |
function WormRailManager::AfterLoading | ( | ) |
Do any necessary processing after a savegame has been loaded.
Currently recomputes the values for the _optimal_train_lengths list.
function WormRailManager::BuildRailway | ( | ) |
function WormRailManager::CheckAddTrainToGroup | ( | route | , |
vehicle_count | , | ||
first_vehicle | |||
) |
Check if we should add another train to the specified group.
route | The route info table. |
vehicle_count | The current number of vehicles in this group. |
first_vehicle | The first vehicle in this group. |
function WormRailManager::CheckDefaultGroup | ( | ) |
Checks ungrouped vehicles.
Under normal conditions all vehicles should be grouped.
function WormRailManager::CheckRoutes | ( | ) |
Checks all routes.
Empty routes are removed, new vehicles are added if needed, old vehicles are replaced, vehicles are restarted if sitting in the depot for no reason, rails are electrified, short trains are lengthened.
Only remove route if we're not waiting for trains to be added
see above replacement if (vehicles.Count() == 1 && route.maxvehicles == 2 && (!AIVehicle.IsStoppedInDepot(vehicles.Begin()))) { if (AIVehicle.GetProfitThisYear(vehicles.Begin()) <= 0) continue; if (AIStation.GetCargoWaiting(route.stasrc, route.crg) > 150) { local railtype = AIRail.GetCurrentRailType(); AIRail.SetCurrentRailType(route.railtype); local wagon = WormRailBuilder.ChooseWagon(route.crg, engine_blacklist); if (wagon == null) { AIRail.SetCurrentRailType(railtype); return false; } local platform = WormRailBuilder.GetRailStationPlatformLength(route.stasrc); local engine = WormRailBuilder.ChooseTrainEngine(route.crg, AIMap.DistanceManhattan(AIStation.GetLocation(route.stasrc), AIStation.GetLocation(route.stadst)), wagon, platform * 2 - 1, engine_blacklist); if (engine == null) { AIRail.SetCurrentRailType(railtype); return false; }
Check if we can afford it if (WormMoney.GetMaxBankBalance() > (WormMoney.GetMinimumCashNeeded() + AIEngine.GetPrice(engine) + 4 * AIEngine.GetPrice(wagon))) { if (WormRailManager.AddVehicle(route, vehicles.Begin(), engine, wagon)) { AILog.Info("Added train to route: " + AIStation.GetName(route.stasrc) + " - " + AIStation.GetName(route.stadst)); } } AIRail.SetCurrentRailType(railtype); } }
function WormRailManager::CheckTrainProfits | ( | ) |
Check train profits and send unprofitable ones to depot to be sold.
function WormRailManager::GetMinMaxTrainLength | ( | vehicles | ) |
Get the minimum and maximum length of trains in the supplied list of vehicles.
vehicles | AIVehicleList containing the vehicles. |
function WormRailManager::GetOptimalTrainLength | ( | route | ) |
Get the optimal train length for this route.
route | The route info. |
function WormRailManager::HandleVehicleInDepot | ( | vehicle | ) |
Handle a vehicle that is stopped in depot for selling, replacement or attaching wagons.
vehicle | The vehicle stopped in depot. |
|
static |
Checks whether a given rectangle is within the influence of a given town.
tile | The topmost tile of the rectangle. |
town_id | The TownID of the town to be checked. |
width | The width of the rectangle. |
height | The height of the rectangle. |
function WormRailManager::LoadData | ( | table | , |
worm_save_version | |||
) |
Load all data that WormRailManager from the table.
table | The table that has all the data. |
worm_save_version | WormAI save data version. |
function WormRailManager::RegisterRoute | ( | route_data | , |
station_data | , | ||
vehtype | , | ||
group | , | ||
train_length | |||
) |
Register the new route into the database.
route_data | A WormRoute class object containing info about the route. |
station_data | A WormStation class object containing info about the station. |
vehtype | The type of vehicle using this route. Currently always VT_RAIL. |
group | The vehicle group for the vehicles using this route. |
train_length | The train_length we start with measure in 1/16th of a tile. |
function WormRailManager::ReplaceVehicle | ( | vehicle | ) |
Replaces an old vehicle with a newer model if it is already in the depot.
vehicle | The vehicle to be replaced. |
function WormRailManager::SaveData | ( | table | ) |
Save all data that WormRailManager needs in table.
table | The table to store the data in. |
\xrefitem todo 49.
function WormRailManager::SelectAndAddTrain | ( | route | ) |
Select optimal wagon and train engine for the specified route and buy it if possible.
route | The route info table. |
function WormRailManager::SendTrainToDepotForSelling | ( | vehicle | ) |
Check train profits and send unprofitable ones to depot to be sold.
vehicle | The vehicle that should be sent to depot to be sold. |
|
static |
Set the name of a vehicle group.
group | The GroupID of the group. |
crg | The cargo transported. |
stasrc | The source station. |
|
static |
Sets the current rail type of the AI based on the maximum number of cargoes transportable.
|
static |
Building stages, needed to recover a savegame.
|
static |
Reasons to send a vehicle to a depot.