Add AI to player company

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
Xycor
Engineer
Engineer
Posts: 29
Joined: 17 Mar 2014 01:28

Add AI to player company

Post by Xycor »

My goal here is play on the same team as my kids with my AI assistant so I don't have to establish routes constantly.

I thought I could save a game in single-player and load it in multi-player, but that doesn't seem to work. The player is always company #1 after load. Not saving the player's company # in single-player is a pain for debugging since I have to manually switch it back every load.

Is the only option to start building my own personal OpenTTD binary? I'm hoping to avoid that job.

It seems better to have an official method of flagging the use of script assistance multi-player games if players want to avoid them instead of having players compiling their own binaries.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Add AI to player company

Post by planetmaker »

cheat yourself into the AI's company.

On grounds of fairness between different players, players and AIs in the same company won't be supported differently than by the cheat method.
R2dical
Traffic Manager
Traffic Manager
Posts: 163
Joined: 18 Mar 2013 22:22

Re: Add AI to player company

Post by R2dical »

Why not implement your AI as a GS? Then you don't need to cheat, be playing on the same company or have the empty Player 1 company after you switch :) AFAIK this will work seamlessly in MP too.
Xycor
Engineer
Engineer
Posts: 29
Joined: 17 Mar 2014 01:28

Re: Add AI to player company

Post by Xycor »

Ah... Thanks! I didn't realize the GS system existed with the same functionality as the AI.

I've tried the cheat method but it doesn't seem to work in multi-player for me.

Is a gamescript able to call an AI library or do I have to sacrifice that to make multiplayer with the kids a reality? Originally I was planning on making my AI available as a library so I could experiment with a more traditional AI without breaking the routing component.

All of the functions I use for the AI seem present in the GS namespace. Maybe I can get away with a macro rename between AI* and GS*...
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Add AI to player company

Post by Zuu »

Xycor wrote:All of the functions I use for the AI seem present in the GS namespace. Maybe I can get away with a macro rename between AI* and GS*...
A subset of the AI API is available in the GS API, which in turn got some APIs not in the AI API. However, if all you need is available in the GS API then you are set.

An important difference is that GS doesn't automatically execute commands for a specific company. Instead you have to control this by creating a GSCompanyMode class instance. For the time that this instance is in scope/alive, API calls that you make will be executed as the company given in the GSCompanyMode constructor. It is worth to note that some GS APIs will not work when there is a GSCompanyMode in scope. So while a first idea may be to just stick a GSCompanyMode(0) to always be in scope, it is more flexible to create the company mode instance near the API calls so that you don't cut away the ability to for example display a news message with some text.

Read here for more info about developing your own Game Script:
http://wiki.openttd.org/Game_script#Wri ... ame_script
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Xycor
Engineer
Engineer
Posts: 29
Joined: 17 Mar 2014 01:28

Re: Add AI to player company

Post by Xycor »

Bummer... looks like the GS system won't work for me because it cannot alter the orders of the vehicles.

GS is also missing a GSGroup namespace, but that I could workaround

So I guess I am back to modifying the source?
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Semrush [Bot] and 22 guests