HeliFerry - helicopters & ferries AI

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
mjm
Engineer
Engineer
Posts: 9
Joined: 23 Oct 2016 21:37

HeliFerry - helicopters & ferries AI

Post by mjm » 23 Oct 2016 21:49

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

User avatar
piratescooby
Transport Coordinator
Transport Coordinator
Posts: 311
Joined: 21 Nov 2014 12:39
Location: The Granite City.

Re: HeliFerry - helicopters & ferries AI

Post by piratescooby » 12 Dec 2016 20:27

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 .
Attachments
Antarctica Railways, 03-09-1980.png
(1.07 MiB) Not downloaded yet

Translink
Traffic Manager
Traffic Manager
Posts: 231
Joined: 20 Oct 2015 19:05

Re: HeliFerry - helicopters & ferries AI

Post by Translink » 12 Dec 2016 20:45

Seems interesting, how do I install it into the game?

User avatar
piratescooby
Transport Coordinator
Transport Coordinator
Posts: 311
Joined: 21 Nov 2014 12:39
Location: The Granite City.

Re: HeliFerry - helicopters & ferries AI

Post by piratescooby » 12 Dec 2016 22:05

Either from the first post or check online content from the title screen or https://bananas.openttd.org/en/ai/.

Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4741
Joined: 09 Sep 2007 05:03
Location: home

Re: HeliFerry - helicopters & ferries AI

Post by Alberth » 13 Dec 2016 05:48

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?
Being a OpenTTD developer does not mean I know what I am doing.
Also, other OpenTTD developers may have different opinions.

User avatar
piratescooby
Transport Coordinator
Transport Coordinator
Posts: 311
Joined: 21 Nov 2014 12:39
Location: The Granite City.

Re: HeliFerry - helicopters & ferries AI

Post by piratescooby » 13 Dec 2016 06:30

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 .
Attachments
Antarctica Railways, 09-09-1986.png
(1.46 MiB) Not downloaded yet

Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4741
Joined: 09 Sep 2007 05:03
Location: home

Re: HeliFerry - helicopters & ferries AI

Post by Alberth » 13 Dec 2016 06:44

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!
Being a OpenTTD developer does not mean I know what I am doing.
Also, other OpenTTD developers may have different opinions.

User avatar
piratescooby
Transport Coordinator
Transport Coordinator
Posts: 311
Joined: 21 Nov 2014 12:39
Location: The Granite City.

Re: HeliFerry - helicopters & ferries AI

Post by piratescooby » 13 Dec 2016 11:22

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 .

Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4741
Joined: 09 Sep 2007 05:03
Location: home

Re: HeliFerry - helicopters & ferries AI

Post by Alberth » 13 Dec 2016 11:51

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?
Being a OpenTTD developer does not mean I know what I am doing.
Also, other OpenTTD developers may have different opinions.

User avatar
piratescooby
Transport Coordinator
Transport Coordinator
Posts: 311
Joined: 21 Nov 2014 12:39
Location: The Granite City.

Re: HeliFerry - helicopters & ferries AI

Post by piratescooby » 13 Dec 2016 12:26

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 .

mjm
Engineer
Engineer
Posts: 9
Joined: 23 Oct 2016 21:37

Re: HeliFerry - helicopters & ferries AI

Post by mjm » 13 Dec 2016 22:14

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".

User avatar
piratescooby
Transport Coordinator
Transport Coordinator
Posts: 311
Joined: 21 Nov 2014 12:39
Location: The Granite City.

Re: HeliFerry - helicopters & ferries AI

Post by piratescooby » 14 Dec 2016 04:52

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 .

HGus
Engineer
Engineer
Posts: 95
Joined: 12 May 2013 22:28
Location: Argentina

Re: HeliFerry - helicopters & ferries AI

Post by HGus » 23 Dec 2016 07:37

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.

User avatar
supermop
Tycoon
Tycoon
Posts: 1045
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: HeliFerry - helicopters & ferries AI

Post by supermop » 23 Dec 2016 18:00

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.

xarick
Transport Coordinator
Transport Coordinator
Posts: 269
Joined: 26 Feb 2015 00:52

Re: HeliFerry - helicopters & ferries AI

Post by xarick » 25 Feb 2018 01:09

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.
Attachments
HeliFerry, 1st Sep 1988.sav
(2.51 MiB) Downloaded 65 times
Formerly known as Samu

xarick
Transport Coordinator
Transport Coordinator
Posts: 269
Joined: 26 Feb 2015 00:52

Re: HeliFerry - helicopters & ferries AI

Post by xarick » 26 Feb 2018 16:36

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
Attachments
HeliFerry, 1st Feb 1950.sav
(1.02 MiB) Downloaded 60 times
Formerly known as Samu

mjm
Engineer
Engineer
Posts: 9
Joined: 23 Oct 2016 21:37

Re: HeliFerry - helicopters & ferries AI

Post by mjm » 07 Mar 2018 23:27

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.

xarick
Transport Coordinator
Transport Coordinator
Posts: 269
Joined: 26 Feb 2015 00:52

Re: HeliFerry - helicopters & ferries AI

Post by xarick » 04 Dec 2018 02:18

Ship 4 of HeliFerry was ordered to go to a nearest ship depot, but it became lost.
Attachments
Sem nome, 22 Mar 1974.sav
(86.71 KiB) Downloaded 43 times
Formerly known as Samu

mjm
Engineer
Engineer
Posts: 9
Joined: 23 Oct 2016 21:37

Re: HeliFerry - helicopters & ferries AI

Post by mjm » 06 Nov 2019 15:10

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.

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest