Can't find "a piece of code that queues all your commands in a big list"

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
Stefmachine
Engineer
Engineer
Posts: 6
Joined: 13 Sep 2021 14:05

Can't find "a piece of code that queues all your commands in a big list"

Post by Stefmachine »

The AI doc talks about "[...] a piece of code that queues all your commands in a big list and starts executing them on request all at once. Now if one fails, where it didn't before, it rolls everything back.".
Found in the last paragraph here: https://wiki.openttd.org/en/Development ... s#now-what

Any idea what this is referring to?
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5601
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Can't find "a piece of code that queues all your commands in a big list"

Post by PikkaBird »

I think the intended meaning of that paragraph is "it might be a good idea to write such a thing as part of your AI".
Stefmachine
Engineer
Engineer
Posts: 6
Joined: 13 Sep 2021 14:05

Re: Can't find "a piece of code that queues all your commands in a big list"

Post by Stefmachine »

Oh. I was hoping to save some time.

Then, if you or anyone happens to know the existence of a script/class/library doing something like that, feel free to post it here.

Thank you
User avatar
jfs
Tycoon
Tycoon
Posts: 1750
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: Can't find "a piece of code that queues all your commands in a big list"

Post by jfs »

Here's a framework for you:

Code: Select all

while (commandList.len() > 0) {
  ExecuteCommand(commandList[0]);
  commandList.remove(0);
}
The hard part is not really going over a list of stuff in first-in-first-out fashion, it's what to put in the list so you get the appropriate granularity, how you want to handle unexpected changes to the world that make the planned commands impossible or pointless, and when/how often you want to check for game events too.
Most of that isn't something I think is suited for putting into a framework or library, because they are part of the things that make your AI have personality.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 5 guests