Page 1 of 1

HeliFerry - helicopters & ferries AI

Posted: 23 Oct 2016 21:49
by mjm
Hi everyone,
I'd like to show you a simple AI, I've been working on for the past few days. It operates 2 types of vehicles which need the simplest infrastructure:
  • Helicopters - AI follows the old trick I always used in the past when playing with my siblings: demolish 1 tile directly in the city center, build a heliport there and connect it with the nearest city.
  • Ferries - I found A*-based pathfinders really slow when working with larger water distances, so I wrote my own 2. One follows a straight line, the other one follows the coast.
Features include:
  • autoreplacing vehicle model when the new, better model appears
  • selling unprofitable vehicles
  • autoreplacing old vehicles with new ones
AI starts building heliports when helidepot becomes available. You can use multiple instances of this AI on the same map. I tested it only with the standard GRF and it did OK even with only ferries available.

Download: https://github.com/mmuszkow/HeliFerry/a ... master.zip
The code is available on my github: https://github.com/mmuszkow/HeliFerry

Re: HeliFerry - helicopters & ferries AI

Posted: 12 Dec 2016 20:27
by piratescooby
Why does the AI build Heliports on the roads ? It has done this at 50 towns in this game , can be a annoying having to build roads around them .

Re: HeliFerry - helicopters & ferries AI

Posted: 12 Dec 2016 20:45
by Translink
Seems interesting, how do I install it into the game?

Re: HeliFerry - helicopters & ferries AI

Posted: 12 Dec 2016 22:05
by piratescooby
Either from the first post or check online content from the title screen or https://bananas.openttd.org/en/ai/.

Re: HeliFerry - helicopters & ferries AI

Posted: 13 Dec 2016 05:48
by Alberth
piratescooby wrote:Why does the AI build Heliports on the roads ? It has done this at 50 towns in this game , can be a annoying having to build roads around them .
You have magic bulldozer enabled?

Re: HeliFerry - helicopters & ferries AI

Posted: 13 Dec 2016 06:30
by piratescooby
Magic on , this is the first time the AI has chose to do this ,also building service stations on the peaks of mountains , bought the company out to see what it would do .Built a Heliport next to another one , very strange .

Re: HeliFerry - helicopters & ferries AI

Posted: 13 Dec 2016 06:44
by Alberth
piratescooby wrote:Magic on , this is the first time the AI has chose to do this ,also building service stations on the peaks of mountains , bought the company out to see what it would do .Built a Heliport next to another one , very strange .
What do you mean, "very strange"?

Switching on magic bulldozer enables removal of anything, for everybody.
You can remove anything, but any other entity, such as AIs or town authorities can do that too.

Looking for an empty spot in the middle of a town is hopeless anyway, so likely it just tries to remove random tiles or so until it works.
With magic bulldozer any tile will work. Very convenient!

Re: HeliFerry - helicopters & ferries AI

Posted: 13 Dec 2016 11:22
by piratescooby
I just find it strange that a AI will build on a road tile and not an empty ground tile , just booted up a rnd game and let the AI run , mostly flat ground ,100% airports built in the towns on road tiles .Surely the coding could be changed so the AI does not do this sort of behaviour .

Re: HeliFerry - helicopters & ferries AI

Posted: 13 Dec 2016 11:51
by Alberth
It's probably the center city tile which is tried first.

Of course it can be changed. On the other hand, it's a valid play style in your game.

Would you stop building in a certain way if another company is bothered by it, but the rules allow it?

Re: HeliFerry - helicopters & ferries AI

Posted: 13 Dec 2016 12:26
by piratescooby
Getting used to it , just switch to other company ,demolish a block or two of buildings and build a road around .Not so bad at the coast ,seem to build along the route of the road .

Re: HeliFerry - helicopters & ferries AI

Posted: 13 Dec 2016 22:14
by mjm
piratescooby wrote:Why does the AI build Heliports on the roads ? It has done this at 50 towns in this game , can be a annoying having to build roads around them .
Cause it can, even without the magic bulldozer cheat and hostile town council attitude to area restructuring. To be precise, AI demolishes tile in the exact city center and builds there a heliport, in many cases this happens to be a road tile. I was happy with that cause:
- demolishing road doesn't cause the city population to decrease, demolishing building does
- it breaks the road AIs who don't react to the road network change for their existing routes

On the other hand, for a human player such behavior can be indeed annoying. I updated the .zip from the first post, to omit roads when demolishing space for heliport. It's not on bananas yet (and I'm not sure if I will include that change in "stable" version).
piratescooby wrote:also building service stations on the peaks of mountains
Are there any disadvantages of that? Helidepots are used only to build, upgrade or replace old vehicles (which happens ~once/20-25 years).
piratescooby wrote:Built a Heliport next to another one , very strange
Not really, you have 2 AIs which use the exact same strategy. Both of these heliports will have great passengers "production".

Re: HeliFerry - helicopters & ferries AI

Posted: 14 Dec 2016 04:52
by piratescooby
Thanks for the update , enjoy watching the Zeps landing in the center of town ,going to set up with VTOLs grf in the next game ,a Martian scenario , should be fun .

Re: HeliFerry - helicopters & ferries AI

Posted: 23 Dec 2016 07:37
by HGus
mjm wrote:To be precise, AI demolishes tile in the exact city center and builds there a heliport, in many cases this happens to be a road tile.
From the beginning, cities are build around a road tile in the center, no matters what algorithm you choose (original, improved, 2x2 or 3x3). So demolishing exactly that tile will always break the network for small towns, mostly at beginning of game when most towns still don't have more than a crossroad, or in islands. It would be gently if you change that behaviour, or at least add a new setting to the script.

Good work. Thank you.

Re: HeliFerry - helicopters & ferries AI

Posted: 23 Dec 2016 18:00
by supermop
HGus wrote:
mjm wrote:To be precise, AI demolishes tile in the exact city center and builds there a heliport, in many cases this happens to be a road tile.
From the beginning, cities are build around a road tile in the center, no matters what algorithm you choose (original, improved, 2x2 or 3x3). So demolishing exactly that tile will always break the network for small towns, mostly at beginning of game when most towns still don't have more than a crossroad, or in islands. It would be gently if you change that behaviour, or at least add a new setting to the script.

Good work. Thank you.
Furthermore, towns grow from the center tile road - if this road tile is missing, the town cannot grow at all, so will generally shrink over time.

Re: HeliFerry - helicopters & ferries AI

Posted: 25 Feb 2018 01:09
by xarick
I'm taking HeliFerry into an aircraft only competition. It builds profitable routes, but it's always working too close to the loan limit, triggering bankrupt warnings on month transitions.

The attached savegame provided is the last month it was alive. Next month it banktupts.

Re: HeliFerry - helicopters & ferries AI

Posted: 26 Feb 2018 16:36
by xarick
Testing only ships, it crashed immediately on start. cpu evaluator

Code: Select all

dbg: [script] [0] [I] 0.7 API compatibility in effect:
dbg: [script] [0] [I]  - AITown::GetLastMonthProduction's behaviour has slightly changed.
dbg: [script] [0] [I]  - AISubsidy::GetDestination returns STATION_INVALID for awarded subsidies.
dbg: [script] [0] [I]  - AISubsidy::GetSource returns STATION_INVALID for awarded subsidies.
dbg: [script] [0] [S] Your script made an error: excessive CPU usage in valuator function
dbg: [script] [0] [S] 
dbg: [script] [0] [S] *FUNCTION [GetCoastTilesCloseToCity()] heliferry-3\ferry.nut line [85]
dbg: [script] [0] [S] *FUNCTION [GetCoastTileClosestToCity()] heliferry-3\ferry.nut line [98]
dbg: [script] [0] [S] *FUNCTION [Valuate()] NATIVE line [-1]
dbg: [script] [0] [S] *FUNCTION [BuildFerryRoutes()] heliferry-3\ferry.nut line [337]
dbg: [script] [0] [S] *FUNCTION [Start()] heliferry-3\main.nut line [42]
dbg: [script] [0] [S] 
dbg: [script] [0] [S] [tiles] INSTANCE
dbg: [script] [0] [S] [city] 770170
dbg: [script] [0] [S] [cargo_id] 0
dbg: [script] [0] [S] [range] 20
dbg: [script] [0] [S] [town] 186
dbg: [script] [0] [S] [this] TABLE
dbg: [script] [0] [S] [cargo_id] 0
dbg: [script] [0] [S] [range] 20
dbg: [script] [0] [S] [town] 186
dbg: [script] [0] [S] [this] TABLE
dbg: [script] [0] [S] [towns] INSTANCE
dbg: [script] [0] [S] [ferries_built] 0
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [new_helis] 0
dbg: [script] [0] [S] [passengers_cargo] 0
dbg: [script] [0] [S] [loan_limit] 500000
dbg: [script] [0] [S] [maintenance] INSTANCE
dbg: [script] [0] [S] [ferry] INSTANCE
dbg: [script] [0] [S] [heli] INSTANCE
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] Your script made an error: excessive CPU usage in valuator function
dbg: [script] [0] [S] 
dbg: [script] [0] [S] *FUNCTION [BuildFerryRoutes()] heliferry-3\ferry.nut line [337]
dbg: [script] [0] [S] *FUNCTION [Start()] heliferry-3\main.nut line [42]
dbg: [script] [0] [S] 
dbg: [script] [0] [S] [towns] INSTANCE
dbg: [script] [0] [S] [ferries_built] 0
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [new_helis] 0
dbg: [script] [0] [S] [passengers_cargo] 0
dbg: [script] [0] [S] [loan_limit] 500000
dbg: [script] [0] [S] [maintenance] INSTANCE
dbg: [script] [0] [S] [ferry] INSTANCE
dbg: [script] [0] [S] [heli] INSTANCE
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] The script died unexpectedly.
One of the running scripts crashed. Please report this to the script author with a screenshot of the AI/Game Script Debug Window

Re: HeliFerry - helicopters & ferries AI

Posted: 07 Mar 2018 23:27
by mjm
Looking through the changelog, I think this "fix" from 1.7.0
- Fix: [Script] Kill scripts, when a non-suspendable valuator call takes way too long [FS#6473] (r27594)
causes that. The valuator it crashes on is a simple check if a tile is a coast tile. HeliFerry (and also ShipAI) relies heavily on valuators to improve performance for the water-related algorithms, so there are probably many more places in the code I'd need to debug & rewrite. I don't have the time for that now, so the only solution is to disable the use of ferries in the AI settings.

Re: HeliFerry - helicopters & ferries AI

Posted: 04 Dec 2018 02:18
by xarick
Ship 4 of HeliFerry was ordered to go to a nearest ship depot, but it became lost.

Re: HeliFerry - helicopters & ferries AI

Posted: 06 Nov 2019 15:10
by mjm
After almost 2 years, I finally fixed the valuator timeout error which was crashing the AI, v4 is available on Bananas (the built-in updater).

My future support for this AI will be limited to fixing critical bugs only. HeliFerry is not super-competitive, it has some minor bugs (like operating too close to the money limit, problems with servicing etc), but overall it does Ok on the default settings and it remains profitable.