Page 1 of 2

[AI] CityLifeAI 1.0

Posted: 12 Jul 2021 18:58
by Firrel
CityLifeAI

Have you ever been stuck behind a horse ridden carriage or a very rude cyclist when travelling to work? This will provide this experience and more!

Image

How this works:
Populates villages, towns and cities with traffic of eye candy vehicles available in several newGRFs. The vehicles are split into several categories: cars, mail trucks, service vehicles. The AI manages the number of each category dependent of the size of the city. No more five fire trucks in a small village.

By providing outstanding public services to the city, more people decide to use it, so the private transportation decreases. Also transporting mails decreases the number of small companies that provided this service, taking them out of business and out of traffic.

This AI was designed to support NRT roads of "any" kind. On top of that, when the city reaches enought population, they decide to finally connect to the nearby towns. However some of them are corrupt and use up the money without building anything or hire some questionable builder to build unconnected roads. But if they succeed, they celebrate it in a big way!

For more information, read the readme file:
readme.txt

Settings:
You can't change the decisions of the cities, they act on their own, no amount of trees can solve it.

Requirements:
- OpenTTD, v. 1.10.x or newer.
- SuperLib v. 40, SCPLib v. 45, AIToyLib v. 1 (all available in BaNaNaS and OTTD's "Online Content").
- Any eye candy road vehicle newGRF (with 0 running cost)
- Game Script which supports GSToyLib (otherwise it will bankrupt fast)

Recommended newGRFs and GS:
- Eyecandy Road Vehicles
- Funny Cars
- Generic Cars
- DROP
- Renewed Village Growth

Download:
The latest version can be downloaded from Changelogs and download links.
The development with source codes can be found in github: https://github.com/F1rrel/CityLifeAI

Changelogs and download links:
Version 2.4 by WalkedBy (2021/10/10)
CityLifeAI-2.4.tar
(69.5 KiB) Downloaded 331 times
[+] Spoiler
* ton of excessive unnecessary computations for Candy AI, makes 1.0 version unusable and blocks in game rewind
* buggy road building (bridges everywhere) which really should be optional
minor:
* AI/map car uncontrollable increase was possible because amount of cars was increasing lineary with city sizes
* candy cars are not updated with time, 1820 cars will stay all game up to 2100 and will block city traffic
* AI/map car overflow is prevented by using square root of population instead of linear steady grow
* some questionable calls removed from AI main loop to yearly/monthly/daily schedule
* AI will not try to build depots all game, only once
* all road building anyway not working and disabled, less safe part of script better be optional
* a bit more safety with small clean-ups and unnecessary while's replaced with for's
* numbers are adjusted for huge maps, i.e. slightly less density of cars per city
* added garbage truck (classic) other type
* (reupload 2.3) bugfix which prevented obsolete cars from updating without game save/load, should work fluently now in server mode

Version 1.0 (2021/07/12)
[+] Spoiler
- download link
* Initial release

Re: [AI] CityLifeAI 1.0

Posted: 13 Jul 2021 03:20
by Aegir
This is amazing, I love it. Could do with some settings to control max amount of vehicles per population/etc. though as it can produce some VERY crowded maps. I guess that's part of the charm though? I mean I could run it fine on a 1k x .5k map in JGRPP on a Surface Go with no major slowdowns.

Re: [AI] CityLifeAI 1.0

Posted: 13 Jul 2021 04:28
by gebik
Hi, I just went to test your AI, and have found a issue.
It builds roads with overhead wires even if it is pointless. Also it bulds roads with bridges and makes connection look absolutely ugly.
CityLifeAI.png
(711.81 KiB) Not downloaded yet
Would it be possible to put there a switch for roads construction? In JGRpp there are newly included prebuilt roads to every city.

Thanks!
MLG

Re: [AI] CityLifeAI 1.0

Posted: 13 Jul 2021 08:21
by Firrel
Aegir wrote: 13 Jul 2021 03:20 This is amazing, I love it. Could do with some settings to control max amount of vehicles per population/etc. though as it can produce some VERY crowded maps. I guess that's part of the charm though? I mean I could run it fine on a 1k x .5k map in JGRPP on a Surface Go with no major slowdowns.
Glad you like it. If you dont provide public service to the town, the people jump into their cars and produce traffic. You can control the amount of cars in the town by this, so there is no need for a setting. The values were chosen so that the towns are crowded without service, but even with 100% transported, there will still be some activity.
MLG wrote: 13 Jul 2021 04:28 Hi, I just went to test your AI, and have found a issue.
It builds roads with overhead wires even if it is pointless. Also it bulds roads with bridges and makes connection look absolutely ugly.

Would it be possible to put there a switch for roads construction? In JGRpp there are newly included prebuilt roads to every city.
The towns manage to have a budget for road construction after every 2000 population to up to 5 towns. If the connection already exists, another one will not be built. I will add the switch so that there will only be the JGRPP nicer roads.

You got very progressive governments in your cities, trying to electrify the intercity routes so you can run electric cars without needing to recharge. Also they are very environmentally minding by building bridges over wildlife areas so the animals can roam around uninterrupted. Otherwise, there is nothing I can do about it, tried to reduce the bridges, but increasing the cost of a bridge in A* either did nothing or failed the road finding. Also I have no easy way of knowing that the road is electrified, unless I parse the information from the name of the road, which may change with localization. Or I would need to check an electric vehicle for a road it cannot run, but an electric vehicle must exist at that time for it to work. Now it choses the fastest road that the eye candy vehicles can use.

Re: [AI] CityLifeAI 1.0

Posted: 13 Jul 2021 13:40
by justaplayer
i searched on BaNaNaS and couldn't find SCP LIB anywhere

Re: [AI] CityLifeAI 1.0

Posted: 13 Jul 2021 15:16
by Firrel
justaplayer wrote: 13 Jul 2021 13:40 i searched on BaNaNaS and couldn't find SCP LIB anywhere
Sorry, used the name of the library that is used in the code. Its full name is Script Communication for AI. You can find it in BaNaNaS, here is its forum topic and it should be automatically downloaded if you download this AI from the online content downloader.

Added links to BaNaNaS content to the first post.

Re: [AI] CityLifeAI 1.0

Posted: 13 Jul 2021 15:58
by justaplayer
Firrel wrote: 13 Jul 2021 15:16
justaplayer wrote: 13 Jul 2021 13:40 i searched on BaNaNaS and couldn't find SCP LIB anywhere
Sorry, used the name of the library that is used in the code. Its full name is Script Communication for AI. You can find it in BaNaNaS, here is its forum topic and it should be automatically downloaded if you download this AI from the online content downloader.

Added links to BaNaNaS content to the first post.
I just found the SCPlib. I tried the AI Its very good. 5/5

Edit: i just put DROP and the CityLife has decided to be very eco friendly. We should get an option for the ai to choose roads like the last road available in the road construction menu.

Edit of the edit: The ai is getting more and more ecofriendly (it's starting to use the CNG icon from the Slovak Bus set)

Re: [AI] CityLifeAI 1.0

Posted: 18 Jul 2021 11:11
by Aegir
Not sure what's happening, might need to do some more testing, but I'm getting an edge case where if the AI has already built the max amount of road vehicles allowed in the game settings, (I've tried 1000, 5000), it very quickly gets stuck in some sort of loop or something and starts chewing up a tonne of CPU time.

Let me know if there's any particular testing you'd like me to do to get to the bottom of this one,

Re: [AI] CityLifeAI 1.0

Posted: 18 Jul 2021 14:04
by gebik
MLG wrote: 13 Jul 2021 04:28 Hi, I just went to test your AI, and have found a issue.
It builds roads with overhead wires even if it is pointless.
I just found a way around that. In U&RaTT is option to choose speed limit for highway road. I had it at 130 km/h, that electrified road is 140 km/h. I set it at 150 km/h and it fixed the issue.

Re: [AI] CityLifeAI 1.0

Posted: 18 Jul 2021 19:09
by Firrel
Aegir wrote: 18 Jul 2021 11:11 Not sure what's happening, might need to do some more testing, but I'm getting an edge case where if the AI has already built the max amount of road vehicles allowed in the game settings, (I've tried 1000, 5000), it very quickly gets stuck in some sort of loop or something and starts chewing up a tonne of CPU time.

Let me know if there's any particular testing you'd like me to do to get to the bottom of this one,
Thanks for the info, I remember that I tried to reduce operations when it cannot build more vehicles, but it was not fully tested. Will look into it.
MLG wrote: 18 Jul 2021 14:04
MLG wrote: 13 Jul 2021 04:28 Hi, I just went to test your AI, and have found a issue.
It builds roads with overhead wires even if it is pointless.
I just found a way around that. In U&RaTT is option to choose speed limit for highway road. I had it at 130 km/h, that electrified road is 140 km/h. I set it at 150 km/h and it fixed the issue.
It choses the fastest road that a (random) vehicle can run on. Changing the max speed surely solves it in a way. There is actually no good general way of chosing the road type, but I have some ideas (hacks) that I can try.

Re: [AI] CityLifeAI 1.0

Posted: 21 Jul 2021 06:48
by Aegir
Firrel wrote: 18 Jul 2021 19:09
Aegir wrote: 18 Jul 2021 11:11 Not sure what's happening, might need to do some more testing, but I'm getting an edge case where if the AI has already built the max amount of road vehicles allowed in the game settings, (I've tried 1000, 5000), it very quickly gets stuck in some sort of loop or something and starts chewing up a tonne of CPU time.

Let me know if there's any particular testing you'd like me to do to get to the bottom of this one,
Thanks for the info, I remember that I tried to reduce operations when it cannot build more vehicles, but it was not fully tested. Will look into it.
Definitely seems to be tied to how many road vehicles it's targetting to make, maps with smaller combined town populations (never hits game max vehicle limit) you don't get the slow down, games where there's enough towns+population to want lots of road vehicles it trips.

Looking forward to the update :mrgreen:

Re: [AI] CityLifeAI 1.0

Posted: 20 Aug 2021 13:09
by WalkedBy
There were lots of issues with this script 1.0, major:
- ton of excessive unnecessary computations for Candy AI, makes 1.0 version unusable and blocks in game rewind
- buggy road building (bridges everywhere) which really should be optional
minor:
- AI/map car uncontrollable increase was possible because amount of cars was increasing lineary with city sizes
- candy cars are not updated with time, 1820 cars will stay all game up to 2100 and will block city traffic

fast fixes were made:
- AI/map car overflow is prevented by using square root of population instead of linear steady grow
- some questionable calls removed from AI main loop to yearly/monthly/daily schedule
- AI will not try to build depots all game, only once
- all road building anyway not working and disabled, less safe part of script better be optional
- a bit more safety with small clean-ups and unnecessary while's replaced with for's
- numbers are adjusted for huge maps, i.e. slightly less density of cars per city
- added garbage truck (classic) other type
- (reupload 2.3) bugfix which prevented obsolete cars from updating without game save/load, should work fluently now in server mode

attached, tested a bit, but not carefully, this is just fast fix to make script actually usable
in general, that was probably the best available cars script of all, others are much less advanced
P.S. sorry, for 2.0 uploaded wrong files and found problem, updated with 2.1 (warning: still not well tested)

Re: [AI] CityLifeAI 1.0

Posted: 22 Aug 2021 18:31
by Firrel
WalkedBy wrote: 20 Aug 2021 13:09
Thanks for providing so many fixes. I knew there will be problems, it was not quite finished. I wanted to get to fixing them, I still keep it in mind, but still cant get to it. So I am happy you did 2.1, so it will work well now.

Re: [AI] CityLifeAI 1.0

Posted: 09 Oct 2021 05:22
by Aegir
WalkedBy wrote: 20 Aug 2021 13:09 There were lots of issues with this script 1.0, major:
- ton of excessive unnecessary computations for Candy AI, makes 1.0 version unusable and blocks in game rewind
- buggy road building (bridges everywhere) which really should be optional
minor:
- AI/map car uncontrollable increase was possible because amount of cars was increasing lineary with city sizes
- candy cars are not updated with time, 1820 cars will stay all game up to 2100 and will block city traffic

fast fixes were made:
- AI/map car overflow is prevented by using square root of population instead of linear steady grow
- some questionable calls removed from AI main loop to yearly/monthly/daily schedule
- AI will not try to build depots all game, only once
- all road building anyway not working and disabled, less safe part of script better be optional
- a bit more safety with small clean-ups and unnecessary while's replaced with for's
- numbers are adjusted for huge maps, i.e. slightly less density of cars per city
- added garbage truck (classic) other type
- (reupload 2.3) bugfix which prevented obsolete cars from updating without game save/load, should work fluently now in server mode

attached, tested a bit, but not carefully, this is just fast fix to make script actually usable
in general, that was probably the best available cars script of all, others are much less advanced
P.S. sorry, for 2.0 uploaded wrong files and found problem, updated with 2.1 (warning: still not well tested)
I'm finding this version straight up refuses to build any depots/vehicles with either U&RATT or no NRT set loaded at all. Let me know if there's any debugging you want me to do.

Re: [AI] CityLifeAI 1.0

Posted: 10 Oct 2021 06:42
by WalkedBy
Aegir wrote: 09 Oct 2021 05:22 I'm finding this version straight up refuses to build any depots/vehicles with either U&RATT or no NRT set loaded at all. Let me know if there's any debugging you want me to do.
Some additional info:
We were using version above for about 100 years on server, noticed some uncritical, but annoying problems (road chunks and depots were recreated on converting to scenario). Then I added some small updates and admin restarted server and recreated AI keeping savegame (and passwords). But overall, both versions did not cause gamebreaking problems or crashes. Lots of potential problems very probably can be fixed with just restarting AI. Using these scripts for about 250 server years by now.
There is 1 unfixed problem yet - some cities get too much cars(like 2x-3x of planned amount), should not happen. That's barely noticeable, though.
For the version we currently use, attached it. It's still hammer-fixed and can' be considered final, but should just work.

Now, for the problem you described - tested this script just yet on new game, worked fine. Probably you just need to wait for next month start. Attached, how normal log should look like:
Output.png
(80.96 KiB) Not downloaded yet
If still not happens, please attach a savegame or what happens in AI log - will look into them.

P.S. how can I edit previous post so people did not download worse version? Forum blocks editing now
P.P.S. Ai asks for the money, but it's some sort of legacy ask and probably not required. Wait for 1 month and it will probably get some money on itself.

Re: [AI] CityLifeAI 1.0

Posted: 10 Oct 2021 06:47
by Aegir
WalkedBy wrote: 10 Oct 2021 06:42
Aegir wrote: 09 Oct 2021 05:22 I'm finding this version straight up refuses to build any depots/vehicles with either U&RATT or no NRT set loaded at all. Let me know if there's any debugging you want me to do.
Some additional info:
We were using version above for about 100 years on server, noticed some uncritical, but annoying problems (road chunks and depots were recreated on converting to scenario). Then I added some small updates and admin restarted server and recreated AI keeping savegame (and passwords). But overall, both versions did not cause gamebreaking problems or crashes. Lots of potential problems very probably can be fixed with just restarting AI. Using these scripts for about 250 server years by now.
There is 1 unfixed problem yet - some cities get too much cars(like 2x-3x of planned amount), should not happen. That's barely noticeable, though.
For the version we currently use, attached it. It's still hammer-fixed and can' be considered final, but should just work.

Now, for the problem you described - tested this script just yet on new game, worked fine. Probably you just need to wait for next month start. Attached, how normal log should look like:
Output.png
If still not happens, please attach a savegame or what happens in AI log - will look into them.

P.S. how can I edit previous post so people did not download worse version? Forum blocks editing now(
Nice, I'll give this version a shot. Thanks for the quick turnaround!

Edit: Right on the money! Works a treat!

Re: [AI] CityLifeAI 1.0

Posted: 28 Jun 2023 18:23
by kamnet
Firrel wrote: 22 Aug 2021 18:31 Thanks for providing so many fixes.
WalkedBy wrote: 10 Oct 2021 06:42 P.S. how can I edit previous post so people did not download worse version? Forum blocks editing now
P.P.S. Ai asks for the money, but it's some sort of legacy ask and probably not required. Wait for 1 month and it will probably get some money on itself.
Hitting a few birds with one stone here:

1. Can we get an update to support random vehicles for tramways? Quast65 and GarryG have been working on "eyecandy" tramways with invisible tracks for non-traditional vehicles (bicycles, motorcycles, animal herds, etc) to move along paths without blocking road vehicles. This makes for some interesting combinations and I think CityAI would be more helpful if it used these, it would be nice to have a setting to enable/disable the use of roadways or tramways.

2. If you need to edit a previous post and can't do so, a mod may be able to make a request, but it's usually better to leave it for historical reasons and just make a new post.

3. Money for AIs? IIRC there's a library for that which should probably be implemented.

Re: [AI] CityLifeAI 1.0

Posted: 19 Jan 2024 17:07
by Chico008
Tried this AI, and it's pretty nice having roadveh running over the map

but, how can i add this AI on a multiplayer game run from a dedicated server ?

Re: [AI] CityLifeAI 1.0

Posted: 15 Feb 2024 20:01
by peter1138
I don't know if this AI is still maintained, but the call

Code: Select all

local company_vehicles_count = AIVehicleList().Count();
in town.nut:156 is quite inefficient, as this call is expensive when there are lots of vehicles, and given the script does not rate limit itself, it will tank performance.

It can be replaced with the following line instead

Code: Select all

local company_vehicles_count = AIGroup.GetNumVehicles(AIGroup.GROUP_ALL, AIVehicle.VT_ROAD);
which uses a saved count of road vehicles and thus avoids counting every single vehicle in game every time. It can be several hundred times faster...

Re: [AI] CityLifeAI 1.0

Posted: 17 Mar 2024 19:42
by kamnet
Firrel wrote: 12 Jul 2021 18:58 Version 2.4 by WalkedBy (2021/10/10)
CityLifeAI-2.4.tar
It would be awesome if the above code change could be implemented, and then checked against OpenTTD 14 and uploaded to Bananas. This is a huge Quality of Life upgrade that many players don't know exists.