Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Wed Dec 12, 2018 1:24 pm

All times are UTC




Post new topic  Reply to topic  [ 20 posts ] 
Author Message
PostPosted: Thu Jan 19, 2012 4:10 am 
Offline
President
President
User avatar

Joined: Tue Nov 23, 2010 9:25 pm
Posts: 958
Location: ::1
Since the introduction of version 1.2 beta series of this game, that includes a small feature that shows the rate of town growth, on this particular server that I help to maintain (coop's Welcome Server), I've seen multiple instance of pointless city growth by random players. (It's just too fun to watch how fast a city can grow, and they get to boast to others how they've accomplished such a feat.)

Then it just dawned on me - is it possible to limit the city growth by rate of the passengers transported from that city?

With that idea, with some tips from planetmaker and inspiration from Zuu's Neighbors are Important script (actually, I copied much of the code from it), I came up with this crude script. It checks the rate of passengers and mail transported compared to what that city generated. More of them are transported - the town grows faster. Also, smaller cities will grow at faster pace. That's all this script does. It doesn't add any cargo requirements for the city growth.

I wanted to post the script here first before posting it on bananas to see
1) are there any bugs people come across?
2) what do people think about the growth rate set by the script?
3) any other feed back?


Last edited by Sylf on Sat Aug 30, 2014 7:04 am, edited 1 time in total.

Top
   
PostPosted: Thu Jan 19, 2012 8:00 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4538
Location: /home/sweden
You can probably remove this from the Start function:
Code:
Log.Info("Create town list ... (can take a while on large maps)", Log.LVL_INFO);


Just looping over all towns and add them to a list is not that slow even with lots of towns. What I do is to for each town also loop over all other towns. That is why it take long time on maps with many towns.


Edit: Perhaps degrade this log statement to LVL_DEBUG or LVL_SUB_DECISIONS:
Code:
   Log.Info("End of Town Management.", Log.LVL_INFO);

Otherwise you use the log system for no good really if you log everything at the same log level, you could just use GSLog.Info(..) directly.


Edit2: In Town.nut, use Helper.GetPAXCargo() and Helper.GetMailCargo() to aquire the id of those cargos instead of hard coding 0 and 2. That way you keep better compatibility with NewGRFs. Both those functions cache the result in a hidden global variable, so except for the first call, they are very fast.

Edit3: You should change version.nut to indicate the version of your Game Script, which I believe is 1 and not 3. Usually this value is kept in info.nut, but I moved it to version.nut that is included by both info.nut and main.nut so that I can access the version number of the script at run time. If you don't need that you can remove version.nut and replace SELF_VERSION with 1 in info.nut.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
PostPosted: Sat Jan 21, 2012 7:29 am 
Offline
President
President
User avatar

Joined: Tue Nov 23, 2010 9:25 pm
Posts: 958
Location: ::1
Thanks for the code review, Zuu.

The comment about log level was a good one. The comment about cargo class helper was very helpful. I assumed there would be such function somewhere, but I couldn't find it on my own before posting it.

I made the fixes to address those issues, as well as to fine tune other sections of the script. Here's the updated version. I'll go ahead and post this to bananas and wait for more reactions.


Attachments:
City_Growth_Limiter-1.1.tar [29 KiB]
Downloaded 293 times
Top
   
PostPosted: Sat Jan 21, 2012 9:46 pm 
Offline
Engineer
Engineer

Joined: Fri Jun 03, 2011 12:20 pm
Posts: 2
hello,
how can I use the script? So where do I extract it to?


Top
   
PostPosted: Sat Jan 21, 2012 9:53 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4538
Location: /home/sweden
You must use OpenTTD 1.2 beta or a recent nightly.

Preferable download it using the in-game online content download. That way you get dependencies automatically. If you can't use online content, place
  • City_Growth_Limiter-1.1.tar in OpenTTD/game
  • SuperLib-19.tar in OpenTTD/game/library

Where OpenTTD can either be your installation directory or eg. C:users<your name>DocumentsOpenTTD or the equivalent of that on your OS.

Edit: Link to the NoGo edition of SuperLib and not the AI edition.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Last edited by Zuu on Sun Jan 22, 2012 11:12 am, edited 1 time in total.

Top
   
PostPosted: Sun Jan 22, 2012 1:28 am 
Offline
Traffic Manager
Traffic Manager
User avatar

Joined: Tue Feb 01, 2011 12:41 pm
Posts: 226
Zuu wrote:
Zuu, you link to the AI version of your library, not the GameScript version (which is what is needed here).

_________________
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department


Top
   
PostPosted: Sun Jan 22, 2012 11:13 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4538
Location: /home/sweden
Thanks for noticing. I've fixed my post.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
PostPosted: Sun Feb 05, 2012 11:59 am 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Sun Sep 09, 2007 5:03 am
Posts: 4677
Location: home
Your script is generating a lot of town growth commands, which are the same almost every time.
This causes a lot of useless network traffic in MP games.

Attached you will find a patch with a possible solution, I hope it is of use to you.


Attachments:
changes.patch [2.33 KiB]
Downloaded 152 times
Top
   
PostPosted: Mon May 26, 2014 4:54 pm 
Offline
Chief Executive
Chief Executive
User avatar

Joined: Mon Dec 23, 2013 4:33 pm
Posts: 726
Location: Bærum, Norway
This script doesn't seem to work in ottd 1.4.0. I tried it in a new game, and set the passenger and mail limits to 20 %, and the population totally exploded.

_________________
My screenshots
The 1700-2050 Ships & RVs thread
Norwegian Alternate Town Names


Top
   
PostPosted: Sat Aug 30, 2014 7:04 am 
Offline
President
President
User avatar

Joined: Tue Nov 23, 2010 9:25 pm
Posts: 958
Location: ::1
I just uploaded updated version of this script on bananas. It should work well with OpenTTD 1.4 and up.

I've reworked much of the code inside. Not only should it work well, it shoud be more efficient, thanks to ideas contained in Alberth's patch above.

More details in this update:
  • The calculation for growth rate for each town is much simpler: If the goal is met, rate is set to OpenTTD default. If it's not met, city won't grow.
  • The transport rate is now displayed in the town dialog window
  • The growth rate for the city is updated only if the new rate is different from the last time the transport rate is checked
  • The script exits immediately upon loading the map if town_growth_rate is set to 0
  • The script exits immediately upon loading the map if both pax rate and mail rate parameters are set to 0%


Top
   
PostPosted: Sun Sep 14, 2014 4:55 pm 
Offline
Tycoon
Tycoon

Joined: Tue Feb 22, 2011 6:34 pm
Posts: 2658
Starting a game with this GS and setting the required mail to 0 results in a script crash.


Attachments:
Unnamed, 1st Jan 2173.png [123.66 KiB]
Downloaded 6 times

_________________
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
Top
   
PostPosted: Tue Sep 16, 2014 12:30 am 
Offline
President
President
User avatar

Joined: Tue Nov 23, 2010 9:25 pm
Posts: 958
Location: ::1
Thanks for checking it out and reporting that bug.

I made the fix, and uploaded version 5 (complete with changelog file this time!) to bananas.


Top
   
PostPosted: Tue Sep 16, 2014 12:22 pm 
Offline
President
President
User avatar

Joined: Tue Feb 01, 2011 11:22 am
Posts: 910
Location: Beer
Thanks! :)

_________________
ImageImageImage


Top
   
PostPosted: Fri Oct 03, 2014 3:44 pm 
Offline
Tycoon
Tycoon

Joined: Tue Feb 22, 2011 6:34 pm
Posts: 2658
Bug-ish report: This script seems to disable the setting to fund new buildings, is that intended behavior?

Feature Request-ish request: Would it be possible to increase the maximum value for the minimum size setting? Currently it is limited to 1000 inhabitants, which I think is a bit low. Personally I would prefer to only have limits after ~2000-3000 inhabitants.

_________________
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML


Top
   
PostPosted: Fri Oct 03, 2014 4:48 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sun Jun 20, 2010 11:16 pm
Posts: 1255
Hi, i tried to add this script to (the famous) Cindini's scenario, and when launching a game the script crash right a the start.
Also the AI/script window poping up have nothing written inside !
(i tried on 1.4.0 and on 1.4.2)

Of course i m assuming we can add a script to a scenario after creation (it seems to work with other script at least), but i may be wrong ;)


Top
   
PostPosted: Fri Oct 03, 2014 10:59 pm 
Offline
President
President
User avatar

Joined: Tue Nov 23, 2010 9:25 pm
Posts: 958
Location: ::1
@Transportman Yes, I disabled funding of new buildings specifically. It's not a bug. If you want to grow a town for a brief period of time, you can run advertisement campaigns, and that should help in the cities where the transport % has fallen below the requirements. I may still give an option to re-enable funding of new buildings.

As for the request, I'll probably allow it - I will look into it at the same time I fix the issue seen in Cindini scenario.

@romazoon As the game script debug console does not indicate any reason for crash what so ever, it may take a while before I can find exactly what is causing the crash at all. I'll report back when I find anything on this issue.


Top
   
PostPosted: Sat Oct 04, 2014 12:06 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Sun Jun 20, 2010 11:16 pm
Posts: 1255
i know i should have made a screenshot but i didnt my apologies... the very first time the script crash showed up, something was written(one small line) about API 1.4.0 (or 1.4.2 i m not so sure anymore) but not in red. when i retried nothing at all was written.

Have you reproduced the script crash with my indication or ? and no rush from me, take your time ;)


Top
   
PostPosted: Sat Oct 04, 2014 12:22 am 
Offline
President
President
User avatar

Joined: Tue Nov 23, 2010 9:25 pm
Posts: 958
Location: ::1
Yes, the script crashed when I loaded this script on your scenario.

It is almost an intended behavior, actually. The script expects the town growth speed set to something other than "None" in advanced settings. Change this setting in your scenario before loading the script, and it will work without crashing.

On the technical side... It wasn't really crashing. The script terminated itself because it detected the above advanced setting. But because the game script engine doesn't expect the script to terminate, the game reported that the script crashed.

I'm going to release a new version that will display a friendly message before crashing itself.


Top
   
PostPosted: Sat Oct 04, 2014 1:06 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Sun Jun 20, 2010 11:16 pm
Posts: 1255
thanks for that answer, i effectively had growth on off.


Top
   
PostPosted: Mon Mar 23, 2015 11:15 pm 
Offline
Engineer
Engineer

Joined: Thu Mar 12, 2015 2:41 am
Posts: 9
Hello! I have created a fork of "City Growth Limiter" v6, named "City Growth Limiter Minimal" (super imaginative)
with a simple premise:

> The script now only focuses on vanilla passenger transport, and with that
> It should be as simple, smooth and fast as I can possibly make it.

It is basically a reorganization and simplification of the code by Sylf, with a few minor additions. I consider it a
"sub-set"/"stripped-down" version of Sylf's gamescript, and that's why I don't think it merits its own thread but a
post here.

This is the changelog:

Code:
version 1 - March 17, 2015
* The GameScript now only focuses on Passenger transport (no Mail requirements).
* The Gamescript now only supports vanilla cargos (but it could still work with other sets).
* Dropped SuperLib dependency. There are now no external dependencies aside from NoGo (built in).
* Added some error checking to prevent misbehavior with some NewGRFs and game settings.
* The main loop's workload is now distributed along the 28-day cycle with respect to town count.
* Rearranged internal structure to suit new limitations and requirements.
* Added Spanish translation for in-game messages.


It has been working very well, but you are welcome to take a look at the code and tell me if I've messed everything up!
Or what could be improved.

The license requires I put my name around when I change the code, but really all credit for this goes to Sylf.

(Uploaded script here)


Attachments:
CiGrLiMin-1.zip [14.22 KiB]
Downloaded 78 times
Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 20 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2018 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2018.
Hosted by Zernebok Hosting.