Miscellaneous suggestions/New AI and Airport
From OpenTTD
This article has been requested for deletion.
Reason: use forums for suggestions not wiki
Requester: Not Supplied
If you have suggestions for new features, post them to the forum, where developers and other players will voice their opinions on your idea. Only post them under requested features if you have first started a forum thread, and definitely don't create a separate page unless it's under your user page.
Stuff about AI airport ;)
Suggested algorithm by Stumo (probably needs work, and possibly computationally intensive)
Airport AI Code Proposal.
If the AI is searching for potential airport sites, then the following code ranks them. The highest rated airport(s) should be built, subject to being over a minimum rating. We'll probably need to play around with different ratings weightings to get something sensible. One way to do this might be start different AIs with different weightings, randomly allocated, see which air routes they decide on on a given map and then pick the more sensible ones. Kind of an evolutionary style AI weighting.
- Find some possible towns for airports. Pick all over MIN_AIRPORT_POP
- Reject all towns where this AI already has an airport.
- Reject all towns which already have too many airports.
- Reject all towns which have a town owned airport, should such a thing ever exist.
- For each possible town, find the best airport location. Look at all squares 1 unit out from the town, then 2 units, then 3... For each square, work out the amount of passengers, mail and goods that would be accepted for an airport (i.e. the numbers from the Land Area information), including those from any stations the AI already has that would be adjacent. Do not include squares that would have to be bulldozed to build that airport.Keep going out in rings until you have a complete ring which doesn't accept mail (potentially on a map with very few gaps between towns, this'd mean iterating over the entire map. Possibly have a fixed limit here, MAX_AIRPORT_TOWN_DISTANCE, say 20 squares)
- Discard sites which are ajacent to a competitors station.
- Discard sites that would require demolishing more than MAX_BUILDINGS_TO_DEMOLISH buildings.
- Discard sites that would require demolishing one of your own statations, or train track.
- Discard sites that would require demolishing roads you use for your trucks/busses.
- Discard sites where it is not possible to make the land level enough for the airport.
- For each of these possible sites, perform the following calculation:
SITE_WEIGHTING = PASS_WEIGHTING * (Total Passengers accepted) +MAIL_WEIGHTING * (Total Mail Accepted) +GOODS_WEIGHTING* (Total Goods Accepted) +BUS_STN_BONUS if adjacent to an existing bus station +TRAIN_STN_BONUS if adjacent to an existing train station. +LORRY_STN_BONUS if adjacent to an existing lorry station +DOCK_BONUS if adjacent to a dock (Unlikely to happen often) +BANK_BONUS if the airport would accept valubles (diamonds/gold in non-temperate?) - Now we have a best site for each town, and a weighting for it. Discard all those that are below MIN_AIRPORT_WEIGHTING.
- If the AI already owns airports, go to 15. Otherwise go to 14
- Order sites by SITE_WEIGHTING and build the first 2 (or more?) that are over MIN_AIRPORT_ROUTE_DISTANCE apart. (Now go to 16)
- Multiply each SITE_WEIGHTING by log(1+{number of AI owned airports distance>MIN_AIRPORT_ROUTE_DISTANCE apart}). This will be 0 if there aren't any airports sufficiently far away. Build an airport at the site with the new highest site rating.
- You will now have (at least) 2 airports. Time to choose which planes to put on which routes.
- If an airport has not got any planes flying to it at the moment, build a plane there and set it to full load there, then fly to an airport at least MIN_AIRPORT_ROUTE_DISTANCE away (choose randomly). (If you've just built the first 2 airports, do this at both)
- If any airport currently has 1.5 times as many passengers as needed to fill a plane, build a plane and send it between there and the airport with the most passengers waiting that is MIN_AIRPORT_ROUTE_DISTANCE away.
- If an airplane recieves <1/4 loadings on 3 succesive trips to an airport, add another airport into the schedule that is MIN_AIRPORT_ROUTE_DISTANCE away from the orders it would be adjacent too, if possible. Choose the one with the most passengers waiting.
Note-at most one instance of 18 or 19 should be done each month, to avoid all planes suddenly switching at the same time. You could either choose the most deserving case, or randomly, or some combination of the 2.
The weightings don't need to be constants, they could be functions of (whatever). E.g. MIN_AIRPORT_ROUTE_DISTANCE could increase once jets are available; TRAIN_STN_BONUS could be dependent on the size and/or rating of the train station.
If there are 2 seperate AI stations at present, both of which would be adjacent to the airport if built, then merge them and change vehicle orders when appropriate.
- Note: Also limit to a maximum number of airplanes per airport, depending on airport size.

