Define the main class of our AI WormAI. More...
Public Member Functions | |
function | GetAuthor () |
function | GetName () |
function | GetShortName () |
function | GetDescription () |
function | GetVersion () |
function | GetDate () |
function | MinVersionToLoad () |
function | CreateInstance () |
function | GetAPIVersion () |
function | GetURL () |
function | GetSettings () |
constructor | WormAI () |
Create an instance of WormAI. | |
Implementation of base class functions | |
function | Start () |
Start the main loop of WormAI. | |
function | Save () |
Save all data that WormAI uses. | |
function | Load (version, data) |
Load previously saved information. | |
Utility functions | |
function | decToHex (number) |
Convert a number to its hexadecimal string representation. | |
function | WriteTile (tile) |
Writes a tile as a hexadecimal number. | |
function | GetAircraftTypeAsText (airplane_id) |
Returns aircraft type as text. | |
function | GetAgeString (AgeInDays) |
Rough year/month age estimation string where year = 365 days and month = 30 days. | |
function | SafeAddRectangle (list, tile, radius) |
Add a rectangular area to an AITileList containing tiles that are within /radius/ tiles from the center tile, taking the edges of the map into account. | |
Debugging output functions | |
function | DebugListTownsUsed () |
List of towns used and stations near those towns. | |
function | DebugListTowns (towns_list) |
List all towns in the supplied list. | |
function | DebugListRoutes () |
List all routes: per route all stations and all vehicles on that route with relevant info. | |
function | DebugListRoute (route) |
List all route info in the supplied list. | |
function | DebugListRouteInfo () |
List all our air routes. | |
function | DebugListVehiclesSentToDepot () |
List all vehicles that were sent to depot to be sold. | |
function | DebugVehicleInfo (veh) |
Show info about the specified vehicle. | |
Money related functions | |
function | HasMoney (money) |
Check if we have enough money (via loan and on bank). | |
function | GetMoney (money) |
Get the amount of money requested, loan if needed. | |
Airport handling functions | |
function | RemoveAirport (tile) |
Remove airport at specified tile. | |
function | GetOptimalAvailableAirportType () |
Get the optimal type of airport that is available. | |
function | GetAiportTileOtherEndOfRoute (town_id, station_tile) |
Get tile of airport at the other end of the route. | |
function | UpdateAirportTileInfo (town_idx, station_id, old_tile) |
Update the airport station tile info in our lists after upgrading airport. | |
function | ReplaceAirportTileInfo (old_town_idx, old_tile, new_tile, other_end_of_route_tile) |
Replace the airport town and station tile info in our lists and update orders. | |
function | CheckForAirportsNeedingToBeUpgraded () |
Checks all airports to see if they should be upgraded. | |
function | BuildAirportRoute () |
Build an airport route. | |
function | FindSuitableAirportSpot (airport_type, center_tile) |
Find a suitable spot for an airport, walking all towns hoping to find one. | |
function | SellAirports (airport_1_tile, airport_2_tile) |
Sells the airports at tile_1 and tile_2. | |
Order handling | |
function | IsTownFirstOrder (town_id) |
Check whether the airport at a certain town is used as the first order of a route. | |
function | ReplaceOrders (veh, is_first_order, breakdowns, station_tile) |
Replace orders of a vehicle, either the first station or last station is replaced. | |
function | InsertGotoStationOrder (veh, order_pos, station_tile) |
Insert go to station order for airport at station_tile. | |
function | InsertMaintenanceOrder (veh, order_pos, station_tile) |
Insert Maintenance order for airport at station_tile. | |
function | ReplaceGotoStationOrder (veh, order_pos, station_tile) |
Replace go to station order for airport at station_tile. | |
Aircraft handling | |
function | GetMaximumDistance (engine) |
Get the maximum distance this aircraft can safely fly without landing. | |
function | BuildAircraft (tile_1, tile_2, start_tile) |
Build an aircraft with orders from tile_1 to tile_2. | |
function | SendAllVehiclesOfStationToDepot (station_id, sell_reason) |
Send all vehicles belonging to a station to depot for selling. | |
function | SendToDepotForSelling (vehicle, sell_reason) |
Send a vehicle to depot to be sold when it arrives. | |
function | RemoveVehicleFromLists (vehicle) |
Remove a vehicle from our route lists and to depot list. | |
function | SellVehicleInDepot (vehicle) |
Sell the vehicle provided it's in depot. | |
function | SellVehiclesInDepot () |
Sell all vehicles in depot that are marked to be sold. | |
function | CanBuildAircraft () |
Checks if we can build an aircraft and if not outputs a string with the reason. | |
Task related functions | |
function | ManageVehicleRenewal (age_limit) |
Check all vehicles for being old or needing upgrading to a newer type. | |
function | CheckAirportsWithoutVehicles () |
Check for airports that don't have any vehicles anymore and delete them. | |
function | ManageAirRoutes () |
Manage air routes: | |
function | HandleEvents () |
Callback that handles events. | |
function | EvaluateAircraft () |
Task that evaluates all available aircraft for how suited they are for our purposes. | |
General functions | |
function | GetTownFromStationTile (st_tile) |
Get Town id in our towns_used list based on tile of station built near it. | |
function | IsValidStationFromTile (st_tile) |
Determine if a station is valid based on the station tile. | |
function | IsValidFirstStation (veh) |
Determine if the first station of the route of a vehicle is valid. | |
function | IsValidLastStation (veh) |
Determine if the last station of the route of a vehicle is valid. | |
Valuator functions | |
function | GetCostFactor (engine, costfactor_list) |
Valuator function to get the cost factor of an aircraft. | |
Initialization functions | |
function | InitSettings () |
InitSettings initializes a number of required variables based on the game settings of our AI. | |
function | Welcome () |
Welcome says hello to the user and prints out the current AI gamesettings. |
Public Attributes | |
name = null | |
towns_used = null | |
town id, airport station tile | |
route_1 = null | |
vehicle id, station_tile of first station in an order | |
route_2 = null | |
vehicle id, station_tile of last station in an order | |
distance_of_route = {} | |
vehicle id, distance between first/last order stations | |
vehicle_to_depot = {} | |
vehicle id, boolean always true currently | |
ai_speed_factor = 1 | |
speed factor for our ai actions (1=fast..3=slow) | |
delay_build_airport_route = 0 | |
passenger_cargo_id = -1 | |
loaded_from_save = false | |
engine_usefulness = null | |
acceptance_limit = 0 | |
Starting limit for passenger acceptance for airport finding. | |
aircraft_disabled_shown = 0 | |
Has the aircraft disabled in game settings message been shown (1) or not (0). | |
aircraft_max0_shown = 0 | |
Has the max aircraft is 0 in game settings message been shown. |
Define the main class of our AI WormAI.
|
inline |
Create an instance of WormAI.
function WormAI::BuildAircraft | ( | tile_1 | , |
tile_2 | , | ||
start_tile | |||
) |
Build an aircraft with orders from tile_1 to tile_2.
The best available aircraft will be bought.
tile_1 | Airport tile that should be used as the first order. |
tile_2 | Airport tile that should be used as the last order. |
start_tile | The Airport tile where the airplane should start. If this is 0 then it will start at tile_1. To let it start at tile_2 use the same value as tile_2. |
function WormAI::BuildAirportRoute | ( | ) |
Build an airport route.
Find 2 cities that are big enough and try to build airport in both cities. Then we can build an aircraft and try to make some money. We limit our amount of airports to max aircraft / AIRPORT_LIMIT_FACTOR * 2. (2 airports for a route, and AIRPORT_LIMIT_FACTOR planes per route)
function WormAI::CanBuildAircraft | ( | ) |
Checks if we can build an aircraft and if not outputs a string with the reason.
function WormAI::CheckForAirportsNeedingToBeUpgraded | ( | ) |
Checks all airports to see if they should be upgraded.
If they can it tries to upgrade the airport. If it fails after removing the old airport it will first try to replace it with another airport at another spot. If that also fails it will send the aircraft on the now crippled route to depot to be sold. After all aircraft are sold the remaining airport will be sold too.
function WormAI::DebugListRoute | ( | route | ) |
List all route info in the supplied list.
function WormAI::DebugListRouteInfo | ( | ) |
List all our air routes.
function WormAI::DebugListRoutes | ( | ) |
List all routes: per route all stations and all vehicles on that route with relevant info.
function WormAI::DebugListTowns | ( | towns_list | ) |
List all towns in the supplied list.
function WormAI::DebugListTownsUsed | ( | ) |
List of towns used and stations near those towns.
function WormAI::DebugListVehiclesSentToDepot | ( | ) |
List all vehicles that were sent to depot to be sold.
function WormAI::DebugVehicleInfo | ( | veh | ) |
Show info about the specified vehicle.
It's start and end town and distance between them.
veh | = Vehicle id |
function WormAI::decToHex | ( | number | ) |
Convert a number to its hexadecimal string representation.
number | The number to convert. |
function WormAI::EvaluateAircraft | ( | ) |
Task that evaluates all available aircraft for how suited they are for our purposes.
The suitedness values for aircraft which we can use are saved in engine_usefulness.
function WormAI::FindSuitableAirportSpot | ( | airport_type | , |
center_tile | |||
) |
Find a suitable spot for an airport, walking all towns hoping to find one.
When a town is used, it is marked as such and not re-used.
airport_type | The type of airport we want to build. |
center_tile | The tile around which we will search for a spot for the airport. |
function WormAI::GetAgeString | ( | AgeInDays | ) |
Rough year/month age estimation string where year = 365 days and month = 30 days.
AgeInDays | The age in days. |
function WormAI::GetAiportTileOtherEndOfRoute | ( | town_id | , |
station_tile | |||
) |
Get tile of airport at the other end of the route.
town_id | Town id of town at this end of route. |
station_tile | tile of station at this end of route. |
function WormAI::GetAircraftTypeAsText | ( | airplane_id | ) |
Returns aircraft type as text.
airplane_id | The id of the airplane |
function WormAI::GetCostFactor | ( | engine | , |
costfactor_list | |||
) |
Valuator function to get the cost factor of an aircraft.
engine | The engine id of the aircraft. |
costfactor_list | The list (usually engine_usefulness) that holds the cost factors. |
function WormAI::GetMaximumDistance | ( | engine | ) |
Get the maximum distance this aircraft can safely fly without landing.
engine | The engine id for which we want to know the maximum distance. |
function WormAI::GetMoney | ( | money | ) |
Get the amount of money requested, loan if needed.
money | The amount of money we need. |
function WormAI::GetOptimalAvailableAirportType | ( | ) |
Get the optimal type of airport that is available.
function WormAI::GetTownFromStationTile | ( | st_tile | ) |
Get Town id in our towns_used list based on tile of station built near it.
function WormAI::HandleEvents | ( | ) |
Callback that handles events.
Currently only AIEvent.ET_VEHICLE_CRASHED is handled.
function WormAI::HasMoney | ( | money | ) |
Check if we have enough money (via loan and on bank).
money | The amount of money we need. |
function WormAI::InsertGotoStationOrder | ( | veh | , |
order_pos | , | ||
station_tile | |||
) |
Insert go to station order for airport at station_tile.
veh | Vehicle to set the order for. |
order_pos | Position in the order list where order should be inserted. |
station_tile | Tile for the Airport of the to be inserted order. |
function WormAI::InsertMaintenanceOrder | ( | veh | , |
order_pos | , | ||
station_tile | |||
) |
Insert Maintenance order for airport at station_tile.
veh | Vehicle to set the order for |
order_pos | Position in the order list where order should be inserted |
station_tile | Tile for the Airport (not the hangar) of the order to be inserted. |
function WormAI::IsTownFirstOrder | ( | town_id | ) |
Check whether the airport at a certain town is used as the first order of a route.
town_id | The id of the town to check if it's the first order. |
function WormAI::IsValidFirstStation | ( | veh | ) |
Determine if the first station of the route of a vehicle is valid.
veh | Vehicle to determine the validity of the station for. |
function WormAI::IsValidLastStation | ( | veh | ) |
Determine if the last station of the route of a vehicle is valid.
veh | Vehicle to determine the validity of the station for. |
function WormAI::IsValidStationFromTile | ( | st_tile | ) |
Determine if a station is valid based on the station tile.
st_tile | The tile of the station. |
function WormAI::Load | ( | version | , |
data | |||
) |
Load previously saved information.
version | Which version of our AI saved the information. |
data | The data that was saved. |
function WormAI::ManageAirRoutes | ( | ) |
function WormAI::ManageVehicleRenewal | ( | age_limit | ) |
Check all vehicles for being old or needing upgrading to a newer type.
It will send all vehicles that are non optimal to depot for selling.
age_limit | The days left age limit below which we send to depot for selling. |
function WormAI::RemoveAirport | ( | tile | ) |
Remove airport at specified tile.
If removing fails then give a warning.
tile | The tile of the airport that should be removed. |
function WormAI::RemoveVehicleFromLists | ( | vehicle | ) |
Remove a vehicle from our route lists and to depot list.
vehicle | The vehicle id that should be removed from the lists. |
function WormAI::ReplaceAirportTileInfo | ( | old_town_idx | , |
old_tile | , | ||
new_tile | , | ||
other_end_of_route_tile | |||
) |
Replace the airport town and station tile info in our lists and update orders.
old_town_idx | Index into towns_used list of town/station being replaced |
old_tile | The old tile for the airport being replaced. |
new_tile | The tile of the new airport. |
other_end_of_route_tile | Tile of other end of route (needed to access vehicles of route) |
function WormAI::ReplaceGotoStationOrder | ( | veh | , |
order_pos | , | ||
station_tile | |||
) |
Replace go to station order for airport at station_tile.
veh | Vehicle to set the order for. |
order_pos | Position in the order list where order should be inserted. |
station_tile | Tile for the Airport of the new to be inserted order. |
function WormAI::ReplaceOrders | ( | veh | , |
is_first_order | , | ||
breakdowns | , | ||
station_tile | |||
) |
Replace orders of a vehicle, either the first station or last station is replaced.
veh | Vehicle to replace the orders for. |
is_first_order | Whether to replace the orders for the first or last station. |
breakdowns | Whether breakdowns are on; if they are on we will add maintenance orders. |
station_tile | Tile of station for the new order. |
function WormAI::SafeAddRectangle | ( | list | , |
tile | , | ||
radius | |||
) |
Add a rectangular area to an AITileList containing tiles that are within /radius/ tiles from the center tile, taking the edges of the map into account.
list | The AITileList in which the valid tiles will be returned. |
tile | The center tile. |
radius | The radius of tiles. |
function WormAI::Save | ( | ) |
Save all data that WormAI uses.
function WormAI::SellAirports | ( | airport_1_tile | , |
airport_2_tile | |||
) |
Sells the airports at tile_1 and tile_2.
Removes towns from towns_used list too.
airport_1_tile | The tile of the first airport to remove |
airport_2_tile | The tile of the other airport to remove |
function WormAI::SellVehicleInDepot | ( | vehicle | ) |
Sell the vehicle provided it's in depot.
If it's not yet in depot it will fail silently.
vehicle | The id of the vehicle that should be sold. |
function WormAI::SendAllVehiclesOfStationToDepot | ( | station_id | , |
sell_reason | |||
) |
Send all vehicles belonging to a station to depot for selling.
station_id | The id of the station. |
sell_reason | The reason for selling. Valid reasons are VEH_OLD_AGE, VEH_LOW_PROFIT, VEH_STATION_REMOVAL |
function WormAI::SendToDepotForSelling | ( | vehicle | , |
sell_reason | |||
) |
Send a vehicle to depot to be sold when it arrives.
vehicle | The vehicle id of the vehicle to be sold. |
sell_reason | The reason for selling. Valid reasons are VEH_OLD_AGE, VEH_LOW_PROFIT, VEH_STATION_REMOVAL |
function WormAI::UpdateAirportTileInfo | ( | town_idx | , |
station_id | , | ||
old_tile | |||
) |
Update the airport station tile info in our lists after upgrading airport.
Expects a valid station_id.
town_idx | Index into towns_used list. |
station_id | Id of the Airport station that got upgraded. |
old_tile | The old tile for the airport before upgrading. |
function WormAI::WriteTile | ( | tile | ) |
Writes a tile as a hexadecimal number.
tile | The tile to convert. |