Secondary production API for 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
zetrax
Engineer
Engineer
Posts: 4
Joined: 09 Nov 2014 10:04

Secondary production API for AI

Post by zetrax »

Hi

I have trouble getting the last month production from secondary industries (are they called this?, industries that only produce when they are delivered cargo) like steel mill, toy factory etc.

When I try to use AIIndustry.GetLastMonthProduction() from these industries, they only produce cargo for a very short time (until next month) and then go back to 0. When polling with the AI
it can often take quite some time (months) to scan all industries, so it is a matter of luck when it discover a secondary industry that is producing.

are the any way to see the yearly production or lastNDaysProduction, or do I need to simulate a background job that keep scanning industries and add them up in an array for the AI to have better
chance of noticing them?

Best regards
Kim
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: Secondary production API for AI

Post by krinn »

Handling such industries is really more problematic than you think :
If you aren't using yourself the industry, and the player decide to stop any production (by no more feeding the industry, or the player collapse, or the player send raw material to another industry), the production will just stopped.
So your AI will need to handle that : should we just remove some vehicles to adapt ourselves to new production value, should we close it and sell everything...
The only "reliable" way to use those industries would be use them yourself, just the make sure the production will remain high.

So if you cannot catch any production value within a month for an industry like that, you just better don't care, the production is too low or unstable and your AI will have a too hard time using it and will drain your money instead of making some.
zetrax
Engineer
Engineer
Posts: 4
Joined: 09 Nov 2014 10:04

Re: Secondary production API for AI

Post by zetrax »

When you get tired of playing the game yourself, you need to invent an AI to play the game for you. The game can never stop once started :-). So my goal is to play around with an AI to build a network transporting goods with trains, playing alone.... *YAWN* how boring is that? *YAWN*

I have been thinking the same thought as you, if the production isn't stable then why bother. But then my stupid AI only wants to build coal lines to power plants until exhausted and I want to try to get it more focused on delivering the full cargo chain.

Also the value of the route is harder to calculate if you only see production spikes, then that wont be very true once the route is build.

Maybe there is a library which calculate more steady production from industry?
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: Secondary production API for AI

Post by Alberth »

Can't it recognize primary industries that cause production at secondary industries?
That's how I usually play, I start at the first step in the production chain, once I have that going, I make a next step, knowing that I am sending input to one particular secondary industry.

Of course we tend to do it one step bigger before starting to build anything, not only do we select a primary industry at the map to use, we also find a matching destination industry, and if that is a secondary industry, we check where a tertiary industry is relative to the secondary one, since we want to deliver there eventually.
Being a retired OpenTTD developer does not mean I know what I am doing.
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: Secondary production API for AI

Post by krinn »

zetrax wrote:I have been thinking the same thought as you, if the production isn't stable then why bother. But then my stupid AI only wants to build coal lines to power plants until exhausted and I want to try to get it more focused on delivering the full cargo chain.

Also the value of the route is harder to calculate if you only see production spikes, then that wont be very true once the route is build.
I never said your AI shouldn't handle secondary industries, just said you shouldn't care about one that out of your scope, as it get really hard to handle them (player using them can any time decide to bug you by stopping dropping stuff there)
But for the one you handle yourself, you can hint your AI to re-use them as a kinda more secure in the chain.
For my AI i have some rating for an industry, if an industry produce good only if someone deliver it something, i increase the rating of that industry if my AI have another task that deliver stuff to that industry, so my AI hint itself that it work with it, and the production may have less trouble.
As example :
someone deliver 100 iron to Blahsteel, that produce 10 steel then -> rate it 10
my AI deliver 50 iron to beurpsteel, that produce 5 steel then -> rate is 5+50 (bonus) = 55, my AI think using beurpsteel is more worth than Blahsteel.
(But still if that someone start delivering blahsteel a lot, blahsteel may have a rating my AI think it might be worth to try it even we aren't doing it ourselves).

As you see, not impossible, but it complicate things more.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 58 guests