Multiple instance issue with PlannerAI P.S. Hello Forums!
Moderator: OpenTTD Developers
Multiple instance issue with PlannerAI P.S. Hello Forums!
Hi all,
First of all let me introduce myself, I have been a long time player of TT (I have been playing Transport Tycoon since It came out when I was 2 years old!) and I have been occasionally looking through these forums since around ~2008 . OTTD is a fantastic improvement to what is already probably one of the top games of all time. So hats off to the developers and all you content creators. I have recently started working as transport planner which has inspired me to get back into OTTD and try and write an AI.
So please welcome PlannerAI (very early alpha, please ignore the debug signs...):
Currently it is just a humble bus only AI with new GRF support which does point to point connections out of large cities. I have written a custom valuator that gets the highest profit vehicle option taking into account distance, speed and running cost (including purchase cost spread over a vehicles lifetime). Although I say it myself it does seem to pick good options from eGRVTS. While this AI is far from complete one issue that has me totally stumped is I can't seem to start a second instance of the AI even though I have taken the code from the wiki that gives new instances a different name. Help would be appreciated thanks.
First of all let me introduce myself, I have been a long time player of TT (I have been playing Transport Tycoon since It came out when I was 2 years old!) and I have been occasionally looking through these forums since around ~2008 . OTTD is a fantastic improvement to what is already probably one of the top games of all time. So hats off to the developers and all you content creators. I have recently started working as transport planner which has inspired me to get back into OTTD and try and write an AI.
So please welcome PlannerAI (very early alpha, please ignore the debug signs...):
Currently it is just a humble bus only AI with new GRF support which does point to point connections out of large cities. I have written a custom valuator that gets the highest profit vehicle option taking into account distance, speed and running cost (including purchase cost spread over a vehicles lifetime). Although I say it myself it does seem to pick good options from eGRVTS. While this AI is far from complete one issue that has me totally stumped is I can't seem to start a second instance of the AI even though I have taken the code from the wiki that gives new instances a different name. Help would be appreciated thanks.
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
Re: Multiple instance issue with PlannerAI P.S. Hello Forums
You don't need a different name to start multiple instances.
For testing purposes just open the console and use "startai <ainame>" to start another instance, with <ainame> being the name from your info.nut.
For testing purposes just open the console and use "startai <ainame>" to start another instance, with <ainame> being the name from your info.nut.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Re: Multiple instance issue with PlannerAI P.S. Hello Forums
Sorry perhaps I should elaborate. When I use the console to start a second instance as you suggest, the company forms but the script does not run, no debug log appears, the company name does not change (the first thing the script does). it basically appears that while the company exists the ai is totally inactive.frosch wrote:You don't need a different name to start multiple instances.
For testing purposes just open the console and use "startai <ainame>" to start another instance, with <ainame> being the name from your info.nut.
I'm guessing the fault lies with my ai rather than OTTD
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
Re: Multiple instance issue with PlannerAI P.S. Hello Forums
If you guess that it has problems related to naming, insert some AILog.Info calls in that code so you can track what is happening. Insert a very early log in Start() to verify for yourself that your AI starts.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: Multiple instance issue with PlannerAI P.S. Hello Forums
while (!AICompany.SetName("MyNewAI #" + i));
Re: Multiple instance issue with PlannerAI P.S. Hello Forums
I threw in a ton of log messages and found the script worked up to the to the first company setname function before freezing, its perfectly happy as long as you don't attempt to set the name as the same as the existing one. I am now using the companyID to ensure that all instances have a unique company name, and everything works happilyZuu wrote:If you guess that it has problems related to naming, insert some AILog.Info calls in that code so you can track what is happening. Insert a very early log in Start() to verify for yourself that your AI starts.
Code: Select all
AICompany.SetName("Planner Co"+ AICompany.ResolveCompanyID( AICompany.COMPANY_SELF ));
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
Re: Multiple instance issue with PlannerAI P.S. Hello Forums
Krinn did point out the problem in his post above though he didn't explain why it is a problem.
Basically, stick to the rule to not put a semicolon after if, while and for statements and you will be good. (Yes there are a few cases when a semicolon after while may be valid, but you will not miss anything by sticking to the rule to not place it there until you know the language better)
The while statement will loop the next statement until the condition is met. With a semicolon you run an empty statement instead of the block below that you think it will run.
Basically, stick to the rule to not put a semicolon after if, while and for statements and you will be good. (Yes there are a few cases when a semicolon after while may be valid, but you will not miss anything by sticking to the rule to not place it there until you know the language better)
The while statement will loop the next statement until the condition is met. With a semicolon you run an empty statement instead of the block below that you think it will run.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: Multiple instance issue with PlannerAI P.S. Hello Forums
Zuu wrote:Krinn did point out the problem in his post above though he didn't explain why it is a problem.
Basically, stick to the rule to not put a semicolon after if, while and for statements and you will be good. (Yes there are a few cases when a semicolon after while may be valid, but you will not miss anything by sticking to the rule to not place it there until you know the language better)
The while statement will loop the next statement until the condition is met. With a semicolon you run an empty statement instead of the block below that you think it will run.
derp thanks for the explanation.
Another issue I've come across is the GetProduction function for returning passenger production doesn't seem to correlate at all with how many passengers are actually generated, I found stations on a tile with 11 production with hundreds of passengers a month, then a production 14 tile in another town which only produces ~30 passengers. What value does production actually correspond to?
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
Re: Multiple instance issue with PlannerAI P.S. Hello Forums
If you want info on some API usage, it would help if you actually gives us the real function name.
Re: Multiple instance issue with PlannerAI P.S. Hello Forums
Sorry its how the AITile.GetProduction function works in the context of:krinn wrote:If you want info on some API usage, it would help if you actually gives us the real function name.
Code: Select all
AITile.GetCargoProduction( choice , passengerID , 1 , 1 , AIStation.GetCoverageRadius( AIStation.STATION_BUS_STOP ))
I print this value onto a sign, but have spotted that production doesn't always seem to correlate with the passengers produced at the station, this seems to be the case where the station is build in-between smaller houses. Is it the case that small houses have the same production value as a tower but produces less passengers?
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
Re: Multiple instance issue with PlannerAI P.S. Hello Forums
The returned value of GetCargoProduction means about nothing. It is the number of tiles that could *potentially* produce *some* amount. Huge houses and small houses count the same, just like industry tiles count the same, even when the industry is producing nothing due to missing supplies.
Anyway, scripts have the same information as human players. A human player cannot know how much a station will receive, nor does OTTD itself know. For industries all you can do is finding the nearby Industry instances and ask them about the production last month (just like humans). For houses I am not aware of a useful method, other than counting tiles and then making some assumption from experience.
Anyway, scripts have the same information as human players. A human player cannot know how much a station will receive, nor does OTTD itself know. For industries all you can do is finding the nearby Industry instances and ask them about the production last month (just like humans). For houses I am not aware of a useful method, other than counting tiles and then making some assumption from experience.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Re: Multiple instance issue with PlannerAI P.S. Hello Forums
Thanks Frosch that's useful info I guess I can apply some factor that rewards being closer to the centre of town over number of houses.
I'm glad that the api gives the ai the same powers as a human in that it's both not cheaty and easier to write script. However a human can not only see house size but also query tiles to get building names. Does the ai have a function to get that?
Ps just had a brain wave the larger buildings tend to have higher goods acceptance could use that to try and build a clearer picture of a town for the ai.
I'm glad that the api gives the ai the same powers as a human in that it's both not cheaty and easier to write script. However a human can not only see house size but also query tiles to get building names. Does the ai have a function to get that?
Ps just had a brain wave the larger buildings tend to have higher goods acceptance could use that to try and build a clearer picture of a town for the ai.
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
Who is online
Users browsing this forum: Google [Bot] and 30 guests