WormAIDev  Worm SELF_VERSION
 All Classes Files Functions Variables Pages
Public Member Functions | Static Public Member Functions | List of all members
WormRailBuilder Class Reference

Define the WormRailBuilder class which handles trains. More...

Public Member Functions

function GetTilesAroundTown (town_id, width, height)
 Get a TileList around a town.
function BuildSingleRailStation (is_source, platform_length, route_data, station_data, rail_manager)
 Build a single (one-lane) rail station at a town or an industry.
function CanBuildSingleRailStation (tile, direction, platform_length, station_data)
 Check whether a single rail station can be built at the given position.
function BuildDoubleRailStation (is_source, platform_length, route_data, station_data, rail_manager)
 Build a double (two-lane) rail station at a town or an industry.
function CanBuildDoubleRailStation (tile, direction, platform_length, station_data)
 Determine whether a double rail station can be built at a given place.
function BuildRail (head1, head2, railbridges)
 Build a rail line between two given points.
function InternalBuildRail (head1, head2, railbridges, recursiondepth)
 Build a rail line between two given points.
function RetryRail (prevprev, pp1, pp2, pp3, head1, railbridges, recursiondepth)
 Retry building a rail track after it was interrupted.
function BuildPassingLaneSection (near_source, train_length, station_data, rail_manager)
 Build a passing lane section between the current source and destination.
function CanBuildPassingLaneSection (centre, direction, reverse, train_length)
 Determine whether a passing lane section can be built at a given position.
function BuildAndStartTrains (number, length, engine, wagon, ordervehicle, group, cargo, station_data, engineblacklist)
 Build and start trains for the current route.
function MailWagonWorkaround (mailwagon, firstwagon, trainengine, crg)
 A workaround for refitting the mail wagon separately.
function RemoveRailLine (start_tile, rail_manager)
 Remove a continuous segment of rail track starting from a single point.
function AreRailTilesConnected (tilefrom, tileto)
 Determine whether two tiles are connected with rail directly.
function DeleteRailStation (sta, rail_manager)
 Delete a rail station together with the rail line.
function ElectrifyRail (start_tile, rail_manager)
 Upgrade a segment of normal rail to electrified rail from a given starting point.
function GetRailStationPlatformLength (sta)
 Get the platform length of a station.
function AttachMoreWagons (vehicle, rail_manager)
 Attach more wagons to a train after it has been sent to the depot.

Static Public Member Functions

static function ChooseWagon (cargo, blacklist)
 Choose a rail wagon for the given cargo.
static function ChooseTrainEngine (cargo, distance, wagon, num_wagons, blacklist)
 Choose a train locomotive.
static function TrainEngineValuator (engine, weight, max_speed, money)
 A valuator function for scoring train locomotives.

Detailed Description

Define the WormRailBuilder class which handles trains.

Member Function Documentation

function WormRailBuilder::AreRailTilesConnected ( tilefrom  ,
tileto   
)

Determine whether two tiles are connected with rail directly.

Parameters
tilefromThe first tile to check.
tiletoThe second tile to check.
Returns
True if the two tiles are connected.
function WormRailBuilder::AttachMoreWagons ( vehicle  ,
rail_manager   
)

Attach more wagons to a train after it has been sent to the depot.

Parameters
vehicleThe VehicleID of the train.
rail_managerThe WormRailManager class object.
function WormRailBuilder::BuildAndStartTrains ( number  ,
length  ,
engine  ,
wagon  ,
ordervehicle  ,
group  ,
cargo  ,
station_data  ,
engineblacklist   
)

Build and start trains for the current route.

Parameters
numberThe number of trains to be built.
lengthThe number of wagons to be attached to the train.
engineThe EngineID of the locomotive.
wagonThe EngineID of the wagons.
ordervehicleThe vehicle to share orders with. Null, if there is no such vehicle.
groupThe vehicle group this train should be part of.
cargoThe cargo to transport.
station_dataA WormStation class object with info about the stations between which rail is being built.
engineblacklistThe blacklist of engines to which bad engines will be added.
Returns
True if at least one train was built.
function WormRailBuilder::BuildDoubleRailStation ( is_source  ,
platform_length  ,
route_data  ,
station_data  ,
rail_manager   
)

Build a double (two-lane) rail station at a town or an industry.

Builder class variables used: crg, src, dst, srcplace, dstplace, srcistown, dstistown, statile, deptile, stafront, depfront, frontfront, front1, front2, lane2, morefront Builder class variables set: stasrc, stadst, homedepot

Parameters
is_sourceTrue if we are building the source station.
platform_lengthThe length of the proposed station's platform.
route_dataA WormRoute class object containing info about the route.
station_dataA WormStation class object containing info about the station.
rail_managerThe WormRailManager class object.
Returns
True if the construction succeeded.
Todo:
Shouldn't 1, 1 be enough then?
Todo:
Shouldn't 1, 1 be enough here?
function WormRailBuilder::BuildPassingLaneSection ( near_source  ,
train_length  ,
station_data  ,
rail_manager   
)

Build a passing lane section between the current source and destination.

Builder class variables used: stasrc, stadst

Parameters
near_sourceTrue if we're building the first passing lane section. (the one closer to the source station)
train_lengthThe maximum train length in tiles that should fit (should be at least 3).
station_dataA WormStation class object with info about the stations between which rail is being built.
rail_managerThe WormRailManager class object.
Returns
True if the construction succeeded.
function WormRailBuilder::BuildRail ( head1  ,
head2  ,
railbridges   
)

Build a rail line between two given points.

Parameters
head1The starting points of the rail line.
head2The ending points of the rail line.
railbridgesThe list of railbridges. If we need to build a bridge it will be added to this list.
Returns
True if the construction succeeded.
function WormRailBuilder::BuildSingleRailStation ( is_source  ,
platform_length  ,
route_data  ,
station_data  ,
rail_manager   
)

Build a single (one-lane) rail station at a town or an industry.

Builder class variables used: crg, src, dst, srcplace, dstplace, srcistown, dstistown, statile, stafront, depfront, frontfront, statop, stationdir Builder class variables set: stasrc, stadst, homedepot

Parameters
is_sourceTrue if we are building the source station.
platform_lengthThe length of the new station's platform.
route_dataA WormRoute class object containing info about the route.
station_dataA WormStation class object containing info about the station.
rail_managerThe WormRailManager class object.
Returns
True if the construction succeeded.
function WormRailBuilder::CanBuildDoubleRailStation ( tile  ,
direction  ,
platform_length  ,
station_data   
)

Determine whether a double rail station can be built at a given place.

Builder class variables set: statile, deptile, stafront, depfront, front1, front2, lane2, frontfront, morefront, statop, stabottom

Parameters
tileThe tile to be checked.
directionThe direction of the proposed station.
platform_lengthThe length of the proposed station's platform.
station_dataWormStation class object where the build info will be store (should be non null when called).
Returns
Ture if a double rail station can be built at the given position.
Todo:
Why is this different in CanBuildSingleRailStation?
Todo:
Why is this different in CanBuildSingleRailStation?
function WormRailBuilder::CanBuildPassingLaneSection ( centre  ,
direction  ,
reverse  ,
train_length   
)

Determine whether a passing lane section can be built at a given position.

Parameters
centreThe centre tile of the proposed passing lane section.
directionThe direction of the proposed passing lane section.
reverseTrue if we are trying to build a flipped passing lane section.
train_lengthThe maximum train length in tiles that should fit (should be at least 3).
Returns
True if a passing lane section can be built.
Todo:
The connection start and finish tile need to be at the same height, needs to be checked too!
Todo:
The connection start and finish tile need to be at the same height, needs to be checked too!
function WormRailBuilder::CanBuildSingleRailStation ( tile  ,
direction  ,
platform_length  ,
station_data   
)

Check whether a single rail station can be built at the given position.

Builder class variables set: statop, stabotton, statile, stafront, depfront, frontfront

Parameters
tileThe tile to be checked.
directionThe direction of the proposed station.
platform_lengthThe length of the proposed station's platform.
station_dataWormStation class object where the build info will be store (should be non null when called).
Returns
True if a single rail station can be built at the given position.
function WormRailBuilder::ChooseTrainEngine ( cargo  ,
distance  ,
wagon  ,
num_wagons  ,
blacklist   
)
static

Choose a train locomotive.

Parameters
cargoThe cargo to carry.
distanceThe distance to be traveled.
wagonThe EngineID of the wagons to be pulled.
num_wagonsThe number of wagons to be pulled.
blacklistA list of engines that cannot be used.
Returns
The EngineID of the chosen locomotive, null if no suitable locomotive was found.
function WormRailBuilder::ChooseWagon ( cargo  ,
blacklist   
)
static

Choose a rail wagon for the given cargo.

Parameters
cargoThe cargo which will be transported by te wagon.
Returns
The EngineID of the chosen wagon, null if no suitable wagon was found.
function WormRailBuilder::DeleteRailStation ( sta  ,
rail_manager   
)

Delete a rail station together with the rail line.

Builder class variables used and set:

Parameters
staThe StationID of the station to be deleted.
rail_managerThe WormRailManager class object.
function WormRailBuilder::ElectrifyRail ( start_tile  ,
rail_manager   
)

Upgrade a segment of normal rail to electrified rail from a given starting point.

Tiles which are reachable by a train from a given starting point are electrified, including stations and depots. This function is not static.

Parameters
start_tileThe starting point from which rails are electrified.
rail_managerThe WormRailManager class object.
function WormRailBuilder::GetRailStationPlatformLength ( sta  )

Get the platform length of a station.

Parameters
staThe StationID of the station.
Returns
The length of the station's platform in tiles.
function WormRailBuilder::GetTilesAroundTown ( town_id  ,
width  ,
height   
)

Get a TileList around a town.

Parameters
town_idThe TownID of the given town.
widthThe width of the proposed station.
heightThe height of the proposed station.
Returns
A TileList containing tiles around a town.
function WormRailBuilder::InternalBuildRail ( head1  ,
head2  ,
railbridges  ,
recursiondepth   
)

Build a rail line between two given points.

Parameters
head1The starting points of the rail line.
head2The ending points of the rail line.
railbridgesThe list of railbridges. If we need to build a bridge it will be added to this list.
recursiondepthThe recursion depth used to catch infinite recursions.
Returns
True if the construction succeeded.
function WormRailBuilder::MailWagonWorkaround ( mailwagon  ,
firstwagon  ,
trainengine  ,
crg   
)

A workaround for refitting the mail wagon separately.

Parameters
mailwagonThe mail wagon to be refitted.
firstwagonThe wagon to which the mail wagon is attached.
trainengineThe locomotive of the train, used to move the wagons.
crgThe cargo which the mail wagon will be refitted to.
function WormRailBuilder::RemoveRailLine ( start_tile  ,
rail_manager   
)

Remove a continuous segment of rail track starting from a single point.

This includes depots and stations, in all directions and braches. Basically the function deletes all rail tiles which are reachable by a train from the starting point. This function is not static.

Parameters
start_tileThe starting point of the rail.
rail_managerThe WormRailManager class object.
function WormRailBuilder::RetryRail ( prevprev  ,
pp1  ,
pp2  ,
pp3  ,
head1  ,
railbridges  ,
recursiondepth   
)

Retry building a rail track after it was interrupted.

The last three pieces of track are removed, and then pathfinding is restarted from the other end.

Parameters
prevprevThe last successfully built piece of track.
pp1The piece of track before prevprev.
pp2The piece of track before pp1.
pp3The piece of track before pp2. It is not removed.
head1The other end to be connected.
railbridgesThe list of railbridges. If we need to build a bridge it will be added to this list.
recursiondepthThe recursion depth used to catch infinite recursions.
Returns
True if the construction succeeded.
function WormRailBuilder::TrainEngineValuator ( engine  ,
weight  ,
max_speed  ,
money   
)
static

A valuator function for scoring train locomotives.

Parameters
engineThe engine to be scored.
weightThe weight to be pulled.
max_speedThe maximum speed allowed.
moneyThe amount of money the company has.
Returns
The score of the engine.
Todo:
the money parameter seems not to be used.

The documentation for this class was generated from the following file: