ShipAI

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

ShipAI

Post by mjm » 21 Nov 2016 11:46

AI that operates only ships (both freight and PAX), it's heavily based on HeliFerry AI and shouldn't be played with it together.

It supports:
- autoreplacing vehicle model when the new, better model appears
- selling unprofitable vehicles
- autoreplacing old vehicles with new ones

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

lucj@n
Engineer
Engineer
Posts: 10
Joined: 21 Jul 2008 16:11
Location: Polska/Poland

Re: ShipAI

Post by lucj@n » 04 Jun 2017 15:19

Hi. Is this normal for this AI to place so many buoys?
And another thing, have a look at this screenshot: http://imgur.com/W7hbh5q . This yellow line is the route ship takes. It's really unefficient.

I like this AI and it's really great that ships are used to transport a lot of different cargos but my map full of islands was extremely cluttered with buoys after few years. And those poor ships which wasted a lot of time going along the coast when it was 5x closer to cut the way like on the screenshot above.

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

Re: ShipAI

Post by mjm » 09 Jun 2017 14:25

lucj@n wrote:Is this normal for this AI to place so many buoys?
Yes, boys are placed every 25 tiles. This is made to avoid ships getting lost and to improve the pathfinder performance ( see: viewtopic.php?t=75339 ).
lucj@n wrote:And another thing, have a look at this screenshot: http://imgur.com/W7hbh5q . This yellow line is the route ship takes. It's really unefficient.
The 2 pathfinders used by the AI (straight line, coast) were chosen because of their speed. The price for that, in case of the coast pathfinder, is that it sometimes gives sub-optimal routes.

lucj@n
Engineer
Engineer
Posts: 10
Joined: 21 Jul 2008 16:11
Location: Polska/Poland

Re: ShipAI

Post by lucj@n » 12 Jun 2017 13:46

mjm wrote:...
ok, that makes sense.
Dzięki.

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

Re: ShipAI

Post by mjm » 09 Aug 2017 12:20

Update, v4 (available on bananas)

The biggest change is that ShipAI can now use canals for the freight cargo.
In order to use canals, AI needs to have it enabled in settings and 2x max loan in it's budget.
The max canal length is limited to 50 tiles and no aqueducts or inner-locks are used to reduce the costs.

There are also few minor changes regarding the main AI logic (improved maintenance time, more expensive cargo first) and performance.

Wormnest
Engineer
Engineer
Posts: 95
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: ShipAI

Post by Wormnest » 27 Nov 2017 10:57

Crash of ShipAI version 4 right after starting because using a valuator inside a valuator on the latest versions of OpenTTD are time limited.
This is without any NewGRF, 1024x1024 map.

PS. It might be useful to upgrade your API compatibility to a newer version than 0.7. That would give you access to newer API functions.
Attachments
Unnamed, Jan 23rd, 1955.png
Crash log ShipAI v4.
(291.99 KiB) Not downloaded yet

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

Re: ShipAI

Post by xarick » 26 Feb 2018 19:05

cpu evaluator crash

Code: Select all

dbg: [script] [0] [I] Building LVST ship between Trudingville Farm(producer) and Gronfingley Factory(acceptor)
dbg: [script] [0] [E] Failed to build dock: ERR_AREA_NOT_CLEAR
dbg: [script] [0] [I] Building LVST ship between Keston Farm(producer) and Grenningpool Falls Factory(acceptor)
dbg: [script] [0] [I] Building LVST ship between Quarnbury Farm(producer) and Nindham Factory(acceptor)
dbg: [script] [0] [I] Building LVST ship between Hunnway Farm(producer) and Hunnway Factory(acceptor)
dbg: [script] [0] [I] Building LVST ship between Nuntborough Farm(producer) and Drundworth Factory(acceptor)
dbg: [script] [0] [I] Building LVST ship between Barningpool Farm(producer) and Fruham Factory(acceptor)
dbg: [script] [0] [I] Building LVST ship between Wrondingville Farm(producer) and Garfinghill Factory(acceptor)
dbg: [script] [0] [S] Your script made an error: excessive CPU usage in valuator function
dbg: [script] [0] [S] 
dbg: [script] [0] [S] *FUNCTION [GetCargoAcceptingCoastTiles()] shipai-4\town.nut line [20]
dbg: [script] [0] [S] *FUNCTION [_val_TownCanHaveDock()] shipai-4\town.nut line [43]
dbg: [script] [0] [S] *FUNCTION [Valuate()] NATIVE line [-1]
dbg: [script] [0] [S] *FUNCTION [GetTownsThatCanHaveDock()] shipai-4\freight.nut line [27]
dbg: [script] [0] [S] *FUNCTION [BuildTownFreightRoutes()] shipai-4\freight.nut line [55]
dbg: [script] [0] [S] *FUNCTION [Start()] shipai-4\main.nut line [30]
dbg: [script] [0] [S] 
dbg: [script] [0] [S] [tiles] INSTANCE
dbg: [script] [0] [S] [cargo] 5
dbg: [script] [0] [S] [range] 20
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [cargo] 5
dbg: [script] [0] [S] [range] 20
dbg: [script] [0] [S] [town_id] 51
dbg: [script] [0] [S] [this] TABLE
dbg: [script] [0] [S] [towns] INSTANCE
dbg: [script] [0] [S] [cargo] 5
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [producers] INSTANCE
dbg: [script] [0] [S] [min_capacity] 160
dbg: [script] [0] [S] [cargo] 5
dbg: [script] [0] [S] [cargos] INSTANCE
dbg: [script] [0] [S] [ships_built] 0
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [new_freights] 302
dbg: [script] [0] [S] [ferry] INSTANCE
dbg: [script] [0] [S] [freight] 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 [GetTownsThatCanHaveDock()] shipai-4\freight.nut line [27]
dbg: [script] [0] [S] *FUNCTION [BuildTownFreightRoutes()] shipai-4\freight.nut line [55]
dbg: [script] [0] [S] *FUNCTION [Start()] shipai-4\main.nut line [30]
dbg: [script] [0] [S] 
dbg: [script] [0] [S] [towns] INSTANCE
dbg: [script] [0] [S] [cargo] 5
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [producers] INSTANCE
dbg: [script] [0] [S] [min_capacity] 160
dbg: [script] [0] [S] [cargo] 5
dbg: [script] [0] [S] [cargos] INSTANCE
dbg: [script] [0] [S] [ships_built] 0
dbg: [script] [0] [S] [this] INSTANCE
dbg: [script] [0] [S] [new_freights] 302
dbg: [script] [0] [S] [ferry] INSTANCE
dbg: [script] [0] [S] [freight] 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
ShipAI, 1st Jan 1957.sav
(1.17 MiB) Downloaded 98 times
Formerly known as Samu

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

Re: ShipAI

Post by mjm » 07 Mar 2018 22:48

Please check the new version (v5) from https://github.com/mmuszkow/ShipAI/archive/master.zip
I've splitted the problems AI was lagging on into smaller chunks and now the operations should take short enough not to raise the "excessive CPU usage in valuator". If everything is Ok, I'll put it on bananas shortly.
PS. It might be useful to upgrade your API compatibility to a newer version than 0.7. That would give you access to newer API functions.
I always use the doc for trunk version and functions from there. I never lacked any. Is there any other point in increasing the min compatibile version?

edit: v5 was put on bananas.

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

Re: ShipAI

Post by xarick » 30 Apr 2019 16:50

Excessive cpu usage in valuator function
Attachments
Unnamed, 1941-10-17.sav
(605.88 KiB) Downloaded 37 times
Unnamed, 1943-04-12.png
(484.76 KiB) Not downloaded yet
Formerly known as Samu

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: ShipAI

Post by Zuu » 02 May 2019 07:24

mjm wrote:Quote:
PS. It might be useful to upgrade your API compatibility to a newer version than 0.7. That would give you access to newer API functions.
I always use the doc for trunk version and functions from there. I never lacked any. Is there any other point in increasing the min compatibile version?
Min compatible version is where you declare the minimum OpenTTD version required to run your AI. If you use APIs from later versions than your min compatible version in ways that would crash the AI in older versions of OpenTTD, you should raise it to properly declare what OpenTTD version is required to run your AI.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

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

Re: ShipAI

Post by xarick » 01 Oct 2019 17:29

Your ships never service. There are ships with 255 breakdowns.
Vehicles don't automatically service if you have a go to depot order in your order list. You have such order, but it's through the condition that they're old it's executed. Makes it so that during most of its life it never visits a depot for service.
Attachments
Unnamed, 2085-12-08.png
(249.86 KiB) Not downloaded yet
Unnamed, 2086-03-17.sav
(5.1 MiB) Downloaded 13 times
Formerly known as Samu

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

Re: ShipAI

Post by mjm » 30 Oct 2019 20:58

Version 7 is available on Bananas (built-in updater). The problem with servicing has been fixed, other improvements:
- pathfinding was completely reworked
- vehicles now share orders
- HQ building and trees planting was added

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests