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, station_data)
 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, route, station_data)
 Build a double (two-lane) rail station at a town or an industry.
function CanBuildDoubleRailStation (tile, direction, 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, recursiondepth)
 Retry building a rail track after it was interrupted.
function BuildPassingLaneSection (near_source, station_data)
 Build a passing lane section between the current source and destination.
function CanBuildPassingLaneSection (centre, direction, reverse)
 Determine whether a passing lane section can be built at a given position.
function BuildAndStartTrains (number, length, engine, wagon, ordervehicle, group, route_data, 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.

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::BuildAndStartTrains ( number  ,
length  ,
engine  ,
wagon  ,
ordervehicle  ,
group  ,
route_data  ,
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.
route_dataInfo about the route. Used here is Cargo.
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  ,
route  ,
station_data   
)

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.
routeA WormRoute class object containing info about the route.
station_dataA WormStation class object containing info about the station.
Returns
True if the construction succeeded.
Todo:
RemoveRailLine
function WormRailBuilder::BuildPassingLaneSection ( near_source  ,
station_data   
)

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)
station_dataA WormStation class object with info about the stations between which rail is being built.
Returns
True if the construction succeeded.
Todo:
RemoveRailLine
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  ,
station_data   
)

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. (2 or 3)
routeA WormRoute class object containing info about the route.
station_dataA WormStation class object containing info about the station.
Returns
True if the construction succeeded.
Todo:
RemoveRailLine
function WormRailBuilder::CanBuildDoubleRailStation ( tile  ,
direction  ,
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.
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.
function WormRailBuilder::CanBuildPassingLaneSection ( centre  ,
direction  ,
reverse   
)

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.
Returns
True if a passing lane section can be built.
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. (2 or 3)
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::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. The 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::RetryRail ( prevprev  ,
pp1  ,
pp2  ,
pp3  ,
head1  ,
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. The 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.
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: