Hello,
As the title says can an AI detect if a specific scenario has been loaded?
In the "dream about OpenTTD 2.0" thread the idea came up to create a tutorial AI using a breakpoint.
I am willing to give it a go but I am still learning so things might advance slowly.
As Zuu pointed out to me it is possible to make the AI wait for the removal of a sign before continuing.
I am looking at making a sort of head to head map where the AI shows the basic steps to get to the game going on one side of the map, then the newcomer to OpenTTD can experiment on the other side and remove the breakpoint to get the next lesson. Maybe I could even place multiple breakpoint-signs, something in the lines of: Remove this sign to start lesson 1, remove this sign to start lesson two, ...
As of today, yay for me, I am able to make my AI choose between normal behaviour (road building) and saying this is the tutorial branch depending on the configuration setting but I think it would be cooler if my AI reacted to the name of the scenario that is loaded.
So the question is, is this possible at all?
Another question I have is if it is possible to change the configuration settings ingame?
I tried but the game did not allow me to do so. Maybe I did something wrong?
It would be nice if when the lessons are over to swith to normal behaviour and continue a bit on the same map, this would allow the player to look back on the tutorials while getting used to eg. signal placement.
Thank you in advance for the help.
Can AI detect savegame name?
Moderator: OpenTTD Developers
Can AI detect savegame name?
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.
Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.
Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
Re: Can AI detect savegame name?
Nice to see that you are giving this idea a try.
I can't find any information regarding getting the name of the current save/scenario neither do I remember seeing anything like this nor it being discussed. An a bit complicated method would be to make a function that makes a signature from the current map and prints it to the logs. Then you store these signatures to see if the map is a known map. You could for example take the height / slope / clearness etc. of a bunch of tiles and add that together in some way to create a signature number. Its not fool prof, but neither is using file name.
If you want to make it so that a user can change a setting in-game then use the AICONFIG_INGAME flag when you set up the settings in your info.nut. If you instead want to make it so that the AI can change the setting in game, then I don't think that is possible. To get a setting you use AIController.GetSetting and since there is no AIController.SetSetting I don't think it is possible.
I can't find any information regarding getting the name of the current save/scenario neither do I remember seeing anything like this nor it being discussed. An a bit complicated method would be to make a function that makes a signature from the current map and prints it to the logs. Then you store these signatures to see if the map is a known map. You could for example take the height / slope / clearness etc. of a bunch of tiles and add that together in some way to create a signature number. Its not fool prof, but neither is using file name.
If you want to make it so that a user can change a setting in-game then use the AICONFIG_INGAME flag when you set up the settings in your info.nut. If you instead want to make it so that the AI can change the setting in game, then I don't think that is possible. To get a setting you use AIController.GetSetting and since there is no AIController.SetSetting I don't think it is possible.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: Can AI detect savegame name?
Zuu to the rescue. 
Anyway back on topic.
Like you say, one can change the savegame/scenario name as one wishes, so that may not be such a good idea even if it was possible.
I also think letting the AI change configuration settings is a bad idea, only the player should be able to do that IMHO.
Dilemma, dilemma, hmmm ....
So the three options that remain are:
- Including a breakpoint sign that is already there before the AI is loaded. Would that work?
- Making a signature of the map in some way. Maybe have the four borders at level 15 descending to level 0 in one slope? Surely nobody will ever make such a scenario and I do not see the landscape generator produce it neither.
- Doing like everybody does and make the player adjust the AI settings before startup in order to start the tutorial, and continue its normal behaviour upon removal of YAB (yet another breakpoint) or changes the ingame settings. I think the removal of YAB is better because a tutorial AI would be aimed at newbies to OpenTTD.
Option four:
- A combination of all three previous options so the tutorial part never starts on a map it is not supposed to "teach" to make it foolproof for newbies?
I did not get to learning how to use breakpoints yet, but I will get there eventually. I need to experiment a bit more.
Thank you for the link Zuu.
/Me goes experimenting.
ps:
Maybe I should change the topic's title and use this thread for collecting ideas on how to create a tutorial AI and what it should teach?
EDIT: Ingame changing of settings fixed.

I think it will be fun while I am learning myself how to program an AI. I once started making a JavaScript/HTML site (unpublished and unfinished) while I was learning the basics of JavaScript and OOP. It was fun while it lasted. It is almost ten years now that I am telling myself to finish it. I could have a long time ago but due to a crashed disk, I lost a part of it (spelling and debugging) and there is always something else I want to do first, I lost my drive to continue a little bit. I sometimes do continue but not for long unfortunately.Zuu wrote:Nice to see that you are giving this idea a try.
Anyway back on topic.
Making a signature from the map properties sound a bit overcomplicated but sounds like a good solution.Many useful things ...
Like you say, one can change the savegame/scenario name as one wishes, so that may not be such a good idea even if it was possible.
I also think letting the AI change configuration settings is a bad idea, only the player should be able to do that IMHO.
Dilemma, dilemma, hmmm ....
So the three options that remain are:
- Including a breakpoint sign that is already there before the AI is loaded. Would that work?
- Making a signature of the map in some way. Maybe have the four borders at level 15 descending to level 0 in one slope? Surely nobody will ever make such a scenario and I do not see the landscape generator produce it neither.
- Doing like everybody does and make the player adjust the AI settings before startup in order to start the tutorial, and continue its normal behaviour upon removal of YAB (yet another breakpoint) or changes the ingame settings. I think the removal of YAB is better because a tutorial AI would be aimed at newbies to OpenTTD.
Option four:
- A combination of all three previous options so the tutorial part never starts on a map it is not supposed to "teach" to make it foolproof for newbies?
I did not get to learning how to use breakpoints yet, but I will get there eventually. I need to experiment a bit more.

Thank you for the link Zuu.
/Me goes experimenting.
ps:
Maybe I should change the topic's title and use this thread for collecting ideas on how to create a tutorial AI and what it should teach?
EDIT: Ingame changing of settings fixed.
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.
Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.
Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
Re: Can AI detect savegame name?
The AI can only read signs that it own itself. If scenarios can be saves with existing infrastructure for some players, then you probably can do that either by using a bootstrap routine in your AI or using the cheat dialog to get in control of the AI company and place signs for it.
Using signs is probably the best. Newbies will not know how to open up the AI debug window. If scenarios work the same as save games then the location which you are at when you save will be viewed when someone starts the scenario (same upper left location of screen). Perhaps place your breakpoint signs so that all or at least the ones with the instructions are visible in 640x480.
The first task in your tutorial will have to be learning about removal of signs. Just keep in mid that if the player is on his/her own company they can't ctrl+click on the AI signs to remove them.
Using signs is probably the best. Newbies will not know how to open up the AI debug window. If scenarios work the same as save games then the location which you are at when you save will be viewed when someone starts the scenario (same upper left location of screen). Perhaps place your breakpoint signs so that all or at least the ones with the instructions are visible in 640x480.
The first task in your tutorial will have to be learning about removal of signs. Just keep in mid that if the player is on his/her own company they can't ctrl+click on the AI signs to remove them.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: Can AI detect savegame name?
True. But you can edit them. By doing so, you take ownership. And then you can delete itZuu wrote:The first task in your tutorial will have to be learning about removal of signs. Just keep in mid that if the player is on his/her own company they can't ctrl+click on the AI signs to remove them.

OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: Can AI detect savegame name?
Yes you can. You can even click on them and then hit the delete button on the edit window. It is just a tiny bit less convenient than ctrl clicking.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Who is online
Users browsing this forum: No registered users and 7 guests