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

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)
 Register the new route into the database.
function CheckRoutes ()
 Checks all routes.
function CheckDefaultGroup ()
 Checks ungrouped vehicles.
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.

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
 List used to continue rail removal and electrification.
 todepotlist = null
 A list of vehicles heading for the depot.

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

Detailed Description

Define the WormRailManager class which handles trains.

Constructor & Destructor Documentation

constructor WormRailManager::WormRailManager ( )
inline

Create an instance of WormRailManager and initialize our variables.

Member Function Documentation

function WormRailManager::AddVehicle ( route  ,
mainvehicle  ,
engine  ,
wagon   
)

Adds a new vehicle to an existing route.

Parameters
routeThe route to which the new vehicle will be added.
mainvehicleAn already existing vehicle on the route to share orders with.
engineThe EngineID of the new vehicle. In case of trains it is the EngineID of the locomotive.
wagonThe EngineID of the train wagons.
Returns
True if the action succeeded.
function WormRailManager::BuildRailway ( )

Main function for building a railway which decides all the details.

Todo:
replace number by a definied constant or variable depending on date and other factors
Todo:
If building trains fails because of lack of money we should try again after a little wait... BuildAndStartTrains should return a status code instead of True/False [OK, NOMONEY, BADTRAIN, ...]
Todo:
check first if we are below max no. of trains...
Todo:
if we're short on money we should'nt try but wait longer before trying again.
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.

Todo:
if vehicle count = 0 because we didn't have enough money to buy trains then
Todo:
we should (try to) add trains or wait until we have more money
Todo:
Maybe add a status to routes like [nomoneyfortrains, unprofitable, ...]
function WormRailManager::CheckTrainProfits ( )

Check train profits and send unprofitable ones to depot to be sold.

Todo:
possible duplicate code with profit checking in air manager. Maybe combine in 1 function?
Todo:
When maintenance costs are on we should set low profit limit too at least the yearly costs.
Todo:
When maintenance costs are on we should set low profit limit too at least the yearly costs.
Todo:
Don't sell all trans from the same route all at once, try selling 1 per year?
function WormRailManager::HandleVehicleInDepot ( vehicle  )

Handle a vehicle that is stopped in depot for selling, replacement or attaching wagons.

Parameters
vehicleThe vehicle stopped in depot.
function WormRailManager::IsRectangleWithinTownInfluence ( tile  ,
town_id  ,
width  ,
height   
)
static

Checks whether a given rectangle is within the influence of a given town.

Parameters
tileThe topmost tile of the rectangle.
town_idThe TownID of the town to be checked.
widthThe width of the rectangle.
heightThe height of the rectangle.
Returns
True if the rectangle is within the influence of the town.
Todo:
Needs to be moved to a different unit. (Town?)
Note
Taken from SimpleAI.
function WormRailManager::RegisterRoute ( route_data  ,
station_data  ,
vehtype  ,
group   
)

Register the new route into the database.

Parameters
route_dataA WormRoute class object containing info about the route.
station_dataA WormStation class object containing info about the station.
vehtypeThe type of vehicle using this route. Currently always VT_RAIL.
groupThe vehicle group for the vehicles using this route.
Returns
The new route registered.
Todo:
Also save IsSubsidy, ...
function WormRailManager::ReplaceVehicle ( vehicle  )

Replaces an old vehicle with a newer model if it is already in the depot.

Parameters
vehicleThe vehicle to be replaced.
function WormRailManager::SendTrainToDepotForSelling ( vehicle  )

Check train profits and send unprofitable ones to depot to be sold.

Parameters
vehicleThe vehicle that should be sent to depot to be sold.
function WormRailManager::SetGroupName ( group  ,
crg  ,
stasrc   
)
static

Set the name of a vehicle group.

Parameters
groupThe GroupID of the group.
crgThe cargo transported.
stasrcThe source station.
Note
Taken from SimpleAI.
Todo:
Move to a different unit, should be accessible from other managers too.
function WormRailManager::SetRailType ( )
static

Sets the current rail type of the AI based on the maximum number of cargoes transportable.

Returns
The new railtype that has been set.
Todo:
Possible better evaluation what rail type is the most profitable.

Member Data Documentation

WormRailManager::BS_NOTHING = 0
static

Building stages, needed to recover a savegame.

WormRailManager::TD_SELL = 1
static

Reasons to send a vehicle to a depot.


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