TownCars AI
Moderator: OpenTTD Developers
TownCars AI
Hello,
Let me present TownCars, which is an AI that builds road vehicles that drive around randomly in towns.
In the AI settings there are a few options for defining which road vehicles it should built. The default settings are compatible with the Generic Cars GRF.
I have not tested with any other car GRFs, but for the AI to be able to distinguish them from buses, they need to either have free price, free running cost or zero capacity. And you need to in the AI settings specify which property that is zero in your GRF. It is also possible to make it only build road vehicles that carry passengers.
If you want this AI to stay alive for long time, you will have to use the cheat dialog to change player to the AI and give it some money for it to keep alive. Depends on the GRF of course, what costs it has to pay per year for the road vehicles.
From version 5 of this AI, it should no longer be selected as a random AI by OpenTTD, so in order to use it one must explicitly select it in the AI Settings. I believe this is the behaviour that most users want.
Dependencies
TownCars 5 requires SuperLib version 6 in order to function. If you download the AI via the in-game content downloader you will get this library automatically.
Let me present TownCars, which is an AI that builds road vehicles that drive around randomly in towns.
In the AI settings there are a few options for defining which road vehicles it should built. The default settings are compatible with the Generic Cars GRF.
I have not tested with any other car GRFs, but for the AI to be able to distinguish them from buses, they need to either have free price, free running cost or zero capacity. And you need to in the AI settings specify which property that is zero in your GRF. It is also possible to make it only build road vehicles that carry passengers.
If you want this AI to stay alive for long time, you will have to use the cheat dialog to change player to the AI and give it some money for it to keep alive. Depends on the GRF of course, what costs it has to pay per year for the road vehicles.
From version 5 of this AI, it should no longer be selected as a random AI by OpenTTD, so in order to use it one must explicitly select it in the AI Settings. I believe this is the behaviour that most users want.
Dependencies
TownCars 5 requires SuperLib version 6 in order to function. If you download the AI via the in-game content downloader you will get this library automatically.
- Attachments
-
- TownCars-5.tar
- (18 KiB) Downloaded 2323 times
Last edited by Zuu on 25 Mar 2011 23:00, edited 1 time in total.
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: TownCars AI
Wow, nice to see this actually implemented 
Zuu, what about the idea, to give the AI a simple money maker (maybe also via an option), e.g to build one long-distance air route with a few planes (maybe 10) in order to make money and pay for the cars?

Zuu, what about the idea, to give the AI a simple money maker (maybe also via an option), e.g to build one long-distance air route with a few planes (maybe 10) in order to make money and pay for the cars?
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: TownCars AI
Now that's a fun idea 

Re: TownCars AI
I totally agree with this AI.
Does he take city size into account ? I mean, dos he build more cars for bigger towns ?

Does he take city size into account ? I mean, dos he build more cars for bigger towns ?
Re: TownCars AI
No, it doesn't. But it starts building in the biggest town. So that the biggest towns get populated with cars first.Hypolite wrote:I totally agree with this AI.![]()
Does he take city size into account ? I mean, dos he build more cars for bigger towns ?
That was an idea I had, but didn't implement it right now.planetmaker wrote:Zuu, what about the idea, to give the AI a simple money maker (maybe also via an option), e.g to build one long-distance air route with a few planes (maybe 10) in order to make money and pay for the cars?
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: TownCars AI
Maybe you could make it place 2-3 bus stops randomly in the city? It would make it some money, but the cities would start to grow..
I'll test the AI when I get home.
I'll test the AI when I get home.

Re: TownCars AI
Nice. 
What about intercity traffic?

What about intercity traffic?

Re: TownCars AI
Way to go Zuu, I like the out of the box thinking you're applying here and in PAX. Mad props to you!

I think that is pretty much handled by not giving cars order they will simply drive around taking any road available. So if an other company builds a road which links cities I think it will go there as well.PikkaBird wrote:Nice.
What about intercity traffic?
Re: TownCars AI
Not originally my idea with town cars, as this has been suggested for ages. But I was the first one to implement it. Or rather copy and paste parts of PAXLink and then link it together with a new main-loop. Fix bugs, add settings and fine tune.Morloth wrote:Way to go Zuu, I like the out of the box thinking you're applying here and in PAX. Mad props to you!


On bananas there is an update, that fixes the bug I mentioned in the PAXLink thread with depots/stations built wrongly next to sloping road with wrong slope direction. This was due to a return of an API function was treated as a boolean where it really was an integer with four possible values.
I couldn't resist to try 15 TownCars AIs, and found another issue, that if the AI failed to build the road bit it did still built the depot, resulting in an unconnected depot (for AIs you need do build the road before, as it is not built automatically as for players). Now it keeps trying as long as the error is "vehicle in the way". Same for building the depot, it will keep trying as long as the error is "vehicle in the way". However when removing the road stump after the depot is removed has always been retrying until it succeeds.
Oh, and naming has been changed so it now names the company #2, #3, .. when the name TownCars fails.
- Attachments
-
- TownCars-v3.tar
- (24.5 KiB) Downloaded 993 times
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: TownCars AI
I like that proposal, though (possibly in addition to a max number of cars per town): Clearly one would expect more traffic in the bigger town - maybe a factor as a setting with something like population / 100 as default and a max vehicle limit of 25 / town?Zuu wrote:No, it doesn't. But it starts building in the biggest town. So that the biggest towns get populated with cars first.Hypolite wrote: Does he take city size into account ? I mean, dos he build more cars for bigger towns ?
In any case it's great for the looks


EDIT: Another thing which just popped my mind: it might be a bad idea to remove the depots, if vehicle_breakdowns = 1 - e.g. the cars will start to break down constantly, if they have not even a chance of being serviced once in a while. So... maybe leave the depot per town and send the cars for servicing every once in a while (if breakdowns are on only).
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: TownCars AI
Hi.
This AI is a really great idea. The towns look so much better with cars in them. But I would select the towns randomly and not by size. With some AIs (got a game with five of them running) the large towns are really crowded while the rest of the map is "dead".
In my game all AIs went bankrupt after about four years. That's why I thought about a money maker for the AI companies. A money maker could keep the company in business. That leads to my next question: Does the AI upgrade its vehicles to newer models? The AI removes the depot right after all cars hit the road. This way the old cars of the company will stay on the roads forever if the company makes profit. In this case there should be some vehicle upgrade logic.
Kind regards
Zombie
This AI is a really great idea. The towns look so much better with cars in them. But I would select the towns randomly and not by size. With some AIs (got a game with five of them running) the large towns are really crowded while the rest of the map is "dead".
In my game all AIs went bankrupt after about four years. That's why I thought about a money maker for the AI companies. A money maker could keep the company in business. That leads to my next question: Does the AI upgrade its vehicles to newer models? The AI removes the depot right after all cars hit the road. This way the old cars of the company will stay on the roads forever if the company makes profit. In this case there should be some vehicle upgrade logic.
Kind regards
Zombie
OpenTTD: OpenTTD-Wiki
OpenTTDCoop: Blog, Wiki
My favorite patches: cargo destinations, shared infrastructure
OpenTTDCoop: Blog, Wiki
My favorite patches: cargo destinations, shared infrastructure
Re: TownCars AI
Thanks for your feedback.
Let me say like this, adding a airline between the two biggest towns might seam simple, but it requires quite some code additions. Upgrading/managing vehicles also requires quite some additional coding. Further improvements to this AI other than bug fixing is quite low on my list. Number of cars based on town size could happen as that is quite simple.
If anyone feel like doing improvements to this AI it is GPL 2, so just go ahead. You might want to fork it and use another name like TownCarsAdvanced so you can make a new entry on bananas for it.
For single player you can just open the cheat window and give it lot of money, and it will not bankrupt. For MP, yes then there can be a reason to have a MM. Or you can make a GRF that has free cars with zero running cost. Then the only cost will be to build the depots, and pay the annual company fee as well as the loan fee.
Let me say like this, adding a airline between the two biggest towns might seam simple, but it requires quite some code additions. Upgrading/managing vehicles also requires quite some additional coding. Further improvements to this AI other than bug fixing is quite low on my list. Number of cars based on town size could happen as that is quite simple.
If anyone feel like doing improvements to this AI it is GPL 2, so just go ahead. You might want to fork it and use another name like TownCarsAdvanced so you can make a new entry on bananas for it.
For single player you can just open the cheat window and give it lot of money, and it will not bankrupt. For MP, yes then there can be a reason to have a MM. Or you can make a GRF that has free cars with zero running cost. Then the only cost will be to build the depots, and pay the annual company fee as well as the loan fee.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: TownCars AI
Hi Zuu,
thank's for that inspiration! - I have taken your TownCars.3 and created StreetTraffic.1 from it.
Some of the suggested enhancements from here are implemented:
- The cars will be distributed more naturally, depending on the population of the town
- The cars will be distributed over a longer time, not all cars at once
- Only one depot will be built per city and those depots will not be destroyed, so that
- cars will be maintained
- cars will be re-newed
- If cars are being destroyed by crashes later, they will be replaced
- load/save is implemented
- more configurable options
I am planning to implement a simple money maker, depending on the configuration the StreetTraffic companies are running out of money within 5-10 years.
Any other suggestions welcome!
StreetTraffic is available from here (attachment) or on BaNaNaS.
Best regards from Texas, Frank/2
thank's for that inspiration! - I have taken your TownCars.3 and created StreetTraffic.1 from it.
Some of the suggested enhancements from here are implemented:
- The cars will be distributed more naturally, depending on the population of the town
- The cars will be distributed over a longer time, not all cars at once
- Only one depot will be built per city and those depots will not be destroyed, so that
- cars will be maintained
- cars will be re-newed
- If cars are being destroyed by crashes later, they will be replaced
- load/save is implemented
- more configurable options
I am planning to implement a simple money maker, depending on the configuration the StreetTraffic companies are running out of money within 5-10 years.
Any other suggestions welcome!
StreetTraffic is available from here (attachment) or on BaNaNaS.
Best regards from Texas, Frank/2
Zuu wrote:Thanks for your feedback.
Let me say like this, adding a airline between the two biggest towns might seam simple, but it requires quite some code additions. Upgrading/managing vehicles also requires quite some additional coding. Further improvements to this AI other than bug fixing is quite low on my list. Number of cars based on town size could happen as that is quite simple.
If anyone feel like doing improvements to this AI it is GPL 2, so just go ahead. You might want to fork it and use another name like TownCarsAdvanced so you can make a new entry on bananas for it.
For single player you can just open the cheat window and give it lot of money, and it will not bankrupt. For MP, yes then there can be a reason to have a MM. Or you can make a GRF that has free cars with zero running cost. Then the only cost will be to build the depots, and pay the annual company fee as well as the loan fee.
- Attachments
-
- StreetTraffic.1.tar
- (30 KiB) Downloaded 805 times
In a world without walls and fences, who needs windows and gates?
Re: TownCars AI
I have not had time to test it, but it looks like you have done a decent work there!
You say you have implemented save/load, then I suggest you add the tag 'save/load' to BaNaNaS, so users know that you have done that. Even TownCars was marked with 'save/load', but with a note that it was only limited save/load support. (Ie don't go crazy and rebuild everything when the game is load again)
You say you have implemented save/load, then I suggest you add the tag 'save/load' to BaNaNaS, so users know that you have done that. Even TownCars was marked with 'save/load', but with a note that it was only limited save/load support. (Ie don't go crazy and rebuild everything when the game is load again)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: TownCars AI
Hi Zuu,
the AI works a different now. See the settings here:

In the first phase the AI will select the 15 most populated towns from the game and will build a depot there. The relation between town_id and depot_tile will be stored into an AIList.
Then comes phase two, see the AI-Log here:

The program enters an endless loop in which the list of towns, selected in phase one is processed and
[current population]/100 * [number of cars per 100 inhabitants per town]
are built in each town. After each car a configurable amount of time is slept, as well as after processing of each town and at the end of the loop.
Because this loop runs until the company runs out of money, crashed cars will be replaced in later phases of the game and if there are newer vehicle types available, the existing cars will be replaced with newe ones.
I save the list of town_ids and depot_tiles together with the game, because i don't know (yet!) how to recreate it after a game is loaded - and i wanted to test the load/save functions of the AI framework.
Here's an example of how it looks like (sorry for the german...)

The depot in the center is the one owned by the AI.
Best regards from Texas, Frank/2
P.S. Currently i am using this AI to learn the API, maybe later this will end up in a new playing AI.
P.P.S Do you have a brief description of how i could build some random (bus-)stops in the towns to produce some money?
the AI works a different now. See the settings here:
In the first phase the AI will select the 15 most populated towns from the game and will build a depot there. The relation between town_id and depot_tile will be stored into an AIList.
Then comes phase two, see the AI-Log here:
The program enters an endless loop in which the list of towns, selected in phase one is processed and
[current population]/100 * [number of cars per 100 inhabitants per town]
are built in each town. After each car a configurable amount of time is slept, as well as after processing of each town and at the end of the loop.
Because this loop runs until the company runs out of money, crashed cars will be replaced in later phases of the game and if there are newer vehicle types available, the existing cars will be replaced with newe ones.
I save the list of town_ids and depot_tiles together with the game, because i don't know (yet!) how to recreate it after a game is loaded - and i wanted to test the load/save functions of the AI framework.

Here's an example of how it looks like (sorry for the german...)
The depot in the center is the one owned by the AI.
Best regards from Texas, Frank/2
P.S. Currently i am using this AI to learn the API, maybe later this will end up in a new playing AI.
P.P.S Do you have a brief description of how i could build some random (bus-)stops in the towns to produce some money?
Zuu wrote:I have not had time to test it, but it looks like you have done a decent work there!
You say you have implemented save/load, then I suggest you add the tag 'save/load' to BaNaNaS, so users know that you have done that. Even TownCars was marked with 'save/load', but with a note that it was only limited save/load support. (Ie don't go crazy and rebuild everything when the game is load again)
In a world without walls and fences, who needs windows and gates?
Re: TownCars AI
that's a great idea!!! thanx lot
but, how i can instal it?

but, how i can instal it?
Code: Select all
(>____<)
----------------------------------------------------------------------------
i had got a cake >_<
Re: TownCars AI
Use 0.7.0 or recent nightly.
* Click on the content download button in the menu.
* Select either TownCars or StreetTraffic from the list of downloads, by checking the download check box.
* Select GenericCars or other GRF containing city cars
* Click on download
* Close content download window
* Open NewGRF settings
* Add GenericCars to GRF list
* Close NewGRF settings
* Open AISettings
* Add TownCars/StreetTraffic to one of the slots (you need to set >= 1 AI players first)
* If you use GenericCars then TownCars and probably StreetTraffic default settings find the city cars. If you use another grf you need to fiddle with the settings (see my explanation in some of my posts above)
* Close AISettings
* Start a new game
* Wait until the AI starts. (by default 365 days +- some time)
* Click on the content download button in the menu.
* Select either TownCars or StreetTraffic from the list of downloads, by checking the download check box.
* Select GenericCars or other GRF containing city cars
* Click on download
* Close content download window
* Open NewGRF settings
* Add GenericCars to GRF list
* Close NewGRF settings
* Open AISettings
* Add TownCars/StreetTraffic to one of the slots (you need to set >= 1 AI players first)
* If you use GenericCars then TownCars and probably StreetTraffic default settings find the city cars. If you use another grf you need to fiddle with the settings (see my explanation in some of my posts above)
* Close AISettings
* Start a new game
* Wait until the AI starts. (by default 365 days +- some time)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: TownCars AI
This looks quit nice! StreetTraffic looks more promissing than townCars for now (nightly builds)
At least I tested both and sometimes townCars seems sometimes to refuse to create cars. StreetTraffic is not in the Download content. Maybe ships (sails if there was such grf) going around map would be nice also
I notice that StreetTraffic build depots in other cities but it start to creates cars in only one depot.
Usually I flow the cars by creating inter-city roads, but for sure you already know that.
How to send money to other company without cheating? (I see the option but i don't know how to use it). My transport company financing road traffic
At least I tested both and sometimes townCars seems sometimes to refuse to create cars. StreetTraffic is not in the Download content. Maybe ships (sails if there was such grf) going around map would be nice also

I notice that StreetTraffic build depots in other cities but it start to creates cars in only one depot.
Usually I flow the cars by creating inter-city roads, but for sure you already know that.
How to send money to other company without cheating? (I see the option but i don't know how to use it). My transport company financing road traffic

Re: TownCars AI
A friend of mine tried out your AI on an old savegame with old AIs, using OpenTTD 0.7.1, and got some funky problems, I'm guessing the AI isn't designed to take over other AIs.
Still if it helps, here are some screenshots of the AI Debug messages:
Still if it helps, here are some screenshots of the AI Debug messages:
- Attachments
-
- PRV Transport, 16th May 1958#1.png
- (217.77 KiB) Downloaded 120 times
-
- PRV Transport, 16th May 1958#2.png
- (215.17 KiB) Downloaded 93 times
Water train!
Re: TownCars AI
Have you tried that with the Nightly build? I think that OpenTTD would only load the same AI name.SupSuper wrote:A friend of mine tried out your AI on an old savegame with old AIs, using OpenTTD 0.7.1, and got some funky problems, I'm guessing the AI isn't designed to take over other AIs.
Still if it helps, here are some screenshots of the AI Debug messages:
Edit :: And of course StreetTrafic is not TownCars

Who is online
Users browsing this forum: Semrush [Bot] and 3 guests