Page 1 of 11

[GS] RCG - A city growth GameScript for OTTD

Posted: 12 Jan 2014 10:19
by keoz
Renewed City Growth - a GameScript for OpenTTD


RCG is a GameScript that manages towns growth in a new and balanced way, making growth depend on varied cargo delivery (passengers, food, goods, ...). The script supports Baseset, FIRS and ECS industries. It is born as a fork of kormer's GS.

SwissTrans, 1937-06-27#4.png
SwissTrans, 1937-06-27#4.png (478.61 KiB) Viewed 43437 times

How this works:

The script only triggers growth in the towns which are already exchanging passengers. This is the condition for town growth. If a town supplies passengers in any way, the script starts calculating cargo requirements for this town. Its growth rate is calculated (non linearly) on the basis of the degree of achievement for cargo requirements. If there is more cargo than necessary, it is stockpiled for later use.

Cargo requirements are not defined for individual cargo types, but for cargo categories. Depending on the used industry set, there are 3 or 5 categories;
For Baseset industries, we use 3 categories:
  • Cat 1: Passengers and Mail
  • Cat 2: General goods (includes food and goods)
  • Cat 3: Industrial materials (includes coal, wood, grain...)
For FIRS and ECS, we use 5 categories (but they can be reduced to 3 or 4 categories):
  • Cat 1: Passengers and mail (includes also ECS' Tourists)
  • Cat 2: General food (includes: food, alcohol, fruit...)
  • Cat 3: General goods (includes: goods, petrol, building material...)
  • Cat 4: Raw industrial material (includes: coal, oil, wood...)
  • Cat 5: Transformed industrial material (includes: chemicals, lumber,
    manufacturing supplies, farm supplies...)
It doesn't matter which type of cargo you deliver to achieve category goals. To achieve requirements for Cat. 2 (general food), you can deliver food, alcohol or fruits. Requirements increases depending on town size, in two ways:
- each category starts being required only on a defined town size. Passengers and mail are required immediately, while General food cargos are required only for towns bigger 500 and General goods cargos, for towns bigger than 1500.
- for each cargo category, requirement increases linearly depending on town size.
Hence, little towns only need Cat.1 cargos (Passengers and mail) to grow. Cities with at least 500 habitants also need - increasingly - food. When cities grow more, other categories come in play. That means, that in the end, you can only expect to have a full - and long term - city growth when developing some local industry, to which deliver raw and transformed industrial materials.


The StoryBook gives detailed informations about cargo categories. Here an example, for FIRS (Firs economy):
RCG-StoryBook.png
RCG-StoryBook.png (43.25 KiB) Viewed 41334 times
Other features/things to know:
  • The town box gives information about cargos, in the form Category: requirement / supplied (last month) / stockpiled (last month).
  • The growth rate is calculated using an average over 8 months, to avoid big gaps and smoothen transitions. Growth rates only change progressively and exponentially, depending on cargo supply.
  • Data are saved: you can safely save and reload your games without losing the stockpiling datas, growth rates, and so on.
  • There is a difficulty setting (50 = easy, 100 = medium, 150 = hard). 100 is the normal level that I recommend in order to have a real challenge, yet not to hard. Other settings allow better tuning the script.
  • For a more detailed description, see the readme.txt file.
Requirements:
  • OpenTTD version 1.4
  • SuperLib v. 38
Download:
  • The last stable script version (which is now v5), hosted on BaNaNaS can be downloaded from this link.
  • A recent development revision (which is now r126) can also be downloaded here (see attachment below). This might contain bugs, which I wait you to report, so you help me to make the script better !
  • You can browse the code or get last revisions on http://dev.openttdcoop.org//projects/gs-rcg/.
Please report bugs, either here on forum's topic, either on repository's bugtracker. That will be *greatly* appreciated. Also, before reporting bugs, make sure you are using the last revision (see below).

Have fun !


Updates

06/01/2015: Revision 127
- fix: better handle the save process if towndata are being updated
- fix: remove old warning storybook pages in monthly update

31/12/2014: version 5
- new: add several expert settings to fine tune calculations
- new: add a setting to disable growth rate text under town names
- new: add a setting allowing to merge some categories
- new: add a StoryPage with cargo category informations
- new: add support for YETI - needs testing and feedback
- new: add a method for checking whether industry setting is consistent
- change: only display required categories in townboxes
- fix: disabling original arctic and tropical cargo requirements
- fix: unifying variables style

28/08/2014: version 4
- added support for baseset industries (temperate, arctic, tropical,
toyland), all FIRS' economies and ECS (all vectors)
- introducing GSText and lang files
- townboxes text formatting improved
- added a method to check savegame compatibility between revisions
- savegame code completely rewritten and simplified
- code cleanup and additional comments
- readme.txt completely rewritten
- updated to SuperLib v. 38
- setting up hg repository
- fix: game is no more crashing when new towns are founded. Thanks to
krinn.
- fix: game is no more crashing when saving immediately after loading
- fix: the script now correctly counts the deliveries from all
companies
- fix: lot of bugs; no more know bugs

25/07/2014: version 2
- some bug fixes
- some recalculations, specially on the scaling of city growth, depending on goal achievements.
- no more pausing each month

12/01/2014: version 1

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 12 Jan 2014 13:40
by kamnet
keoz wrote: Known bugs:
  • If cities are created in game, the script is gonna to crash. Should be easy to fix, but for the moment, it is a problem. That's true also for the scenario editor.
Does this mean if you're developing a scenario, you should add all your cities first, and then add this script last?

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 12 Jan 2014 19:41
by Zuu
For uploading to bananas you can use either a) Bananas Web interface or b) musa. If you want to make FIRS a dependency, you must use musa. Otherwise I suggest starting with the web interface which probably is easier to get started with.

Some information about bananas can be read on the wiki

Worth to mention is to not edit bananas content via the bananas web interface if any of the dependencies that the content depends on has been updated. Doing this will remove the dependency.

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 12 Jan 2014 20:17
by keoz
Zuu wrote:For uploading to bananas you can use either a) Bananas Web interface or b) musa. If you want to make FIRS a dependency, you must use musa. Otherwise I suggest starting with the web interface which probably is easier to get started with.

Some information about bananas can be read on the wiki

Worth to mention is to not edit bananas content via the bananas web interface if any of the dependencies that the content depends on has been updated. Doing this will remove the dependency.
Already uploaded. Thank you for additional tips.
kamnet wrote:
keoz wrote: Known bugs:
  • If cities are created in game, the script is gonna to crash. Should be easy to fix, but for the moment, it is a problem. That's true also for the scenario editor.
Does this mean if you're developing a scenario, you should add all your cities first, and then add this script last?
I just discover that you can add a new GS in the scenario editor, therefore I suppose it should work. It would be better trying first though. In any case, if the bug occurs, there is a simple hack to do: before loading the game, erase the "!" in the file town.nut, line 26 and when the game is loaded, put it back.

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 21 Jan 2014 05:01
by kormer
This looks pretty cool, and I'm glad someone else was willing to take over my code. I've been way too busy with work lately.

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 24 Jan 2014 19:06
by Kogut
The script only triggers growth in the cities which are exchanging passengers.
So ignored towns, without any passenger stations, have an unlimited growth rate?

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 18 Feb 2014 01:42
by Saetan
keoz wrote:Known bugs:
  • If cities are created in game, the script is gonna to crash. Should be easy to fix, but for the moment, it is a problem. That's true also for the scenario editor.
Hi keoz

Does this known bug not only apply to new cities, but to tiny cities at all? Else I may have encountered another bug.


I'm using your script since some few games over several ingame years without any problem. Now in my recent game, still in the early start, the script crashes very often.

It all started after attaching a tiny town, less than 100 inhabitants, into my passenger route. Since then the script crashed nearly every month. The debug log tells of "sumgoals" that are zero. Meanwhile, the inhabitants decreased to less than 50, but I don't know if this happend because of these crashes. I played on difficulty easy (50), but for testing I increased to medium (100) and hard (150) ... even tried 250: The script doesn't crash that often anymore, as sumgoals aren't zero anymore that often. But it still does and that's annoying.


I'm playing on Win64, OpenTTD 1.4.0-beta4 ('cause of passenger and wares distribution) with the banana-version of your script.


Of course, as a workaround, I simply could detach this town from route or start a new game. But I would be really happy if you could solve this problem, if the reason for this problem (if it's the same as the quoted bug info) is already known. If you don't have time to solve it, you may could point me to the right direction to try it myself? (just don't have any knowledge of OpenTTD scripting yet).

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 18 Feb 2014 16:51
by keoz
Kogut wrote:
The script only triggers growth in the cities which are exchanging passengers.
So ignored towns, without any passenger stations, have an unlimited growth rate?
Kogut, I only see your post now, sorry. Ignored towns will just have no growth at all.
Saetan wrote:Now in my recent game, still in the early start, the script crashes very often. [...]
Saetan, I already have seen this bug here, though it only happened a few times, not so often as you. The problem should be solved in the actual development version. I attach it here, but i'm not sure it is compatible with the one you are using. Try it and let me know. If there is a problem, we should find a workaround.

If you find other bugs, I'm interested to see them.

As a note: I changed some calculations in the new version: not massively, but you may notice some changes in the goals and growth rates (basically, goals are a little bit easier to achieve).

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 18 Feb 2014 17:44
by Saetan
Hi keoz

Great there's already a fixed version to try, many thanks.


I may ask you for additional help? How to update banana-v1 to v1.4? ;-)

I don't get it, as the script seems to be embedded into the savegame. Or do I need to have to start a new game anyway?


edit:

I already tried to move the *.tar (unpacked *.gz first) into <username>\Document\OpenTTD\game directory, without success. Tried to rename it, so it fit's banana-v1 filename. At last attempt, I unpacked the *.tar so I got the four *.nut files and placed them in the directory. Anytime, the game seems to use banana ...

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 18 Feb 2014 18:24
by Zuu
keoz has not increased the internal version number of this script. It is still at version 1. Thus while users can download and install this from bananas they will then have multiple versions of this script that all claim to be version '1'. If the script author want to be sure that OpenTTD will know which of these that are newer/later, he/she must increase the internal version number (as returned by GetVersion() in info.nut). In order to allow users of older versions to upgrade to the new one, the author must define and provide a response from GetMinVersionToLoad that is lower or equal to the version of the script recorded in the save game.


Saetan: To work around this issue you as user can make sure to remove all past versions of this script from the OpenTTD search path (see readme on where it looks for files) so that OpenTTD will only find this version of the script. As it claims to be the same version as the past versions, OpenTTD will happily use it to load your save game.

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 18 Feb 2014 18:36
by keoz
Saetan wrote:I may ask you for additional help? How to update banana-v1 to v1.4? ;-)
I will, when the actual changes are completely finished. Still some work before the next release (version 2).
Saetan wrote:I don't get it, as the script seems to be embedded into the savegame. Or do I need to have to start a new game anyway?
Try the following:
1: Remove your version of the gamescript from the openttd content. Replace it with the new one and untar it.
2: Rename your savegame as a scenario (.sav -> .scn). Load it with the scenario editor.
3: Open the AI/gamescript configuration box and load the gamescript.

It should work.

Edit:
Saetan wrote:To work around this issue you as user can make sure to remove all past versions of this script from the OpenTTD search path (see readme on where it looks for files) so that OpenTTD will only find this version of the script. As it claims to be the same version as the past versions, OpenTTD will happily use it to load your save game.
I just tried that but for whatever reason, the game refused to load the script again. I had to load it with the scenario editor.

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 18 Feb 2014 18:43
by keoz
Edit: double posting.

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 18 Feb 2014 19:26
by Saetan
Thank you very much, keoz!

Btw., I didn't mean when you will update banana v1 to v1.4, but how to update from banana-v1 to dev-v1.4. ;-)

With your instruction I got it:

After replacing the old file with the new, untared one in the "content download" and "game" directories, I renamed the savegame as scenario file as you told me. Then I had to open it in the scenario editor, where I activated the script and saved again, just to play this scenario afterwards.

The ingame script information still tells of version 1, but after five years of fast-forwarding, no single crash happend (on difficulty easy, 50) again and the town grew to ~200 inhabitants. So everything seems to be fine now.

So, I say thank you again for your help. :-)

If I recognize any further problems, I'll tell you.

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 18 Feb 2014 19:32
by keoz
Saetan wrote:Btw., I didn't mean when you will update banana v1 to v1.4, but how to update from banana-v1 to dev-v1.4. ;-)
Please, don't. I'll have to do some additional works and I prefer do it myself.
Saetan wrote:The ingame script information still tells of version 1, but after five years of fast-forwarding, no single crash happend (on difficulty easy, 50) again and the town grew to ~200 inhabitants. So everything seems to be fine now.
Great ! :D

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 18 Feb 2014 19:48
by Saetan
keoz wrote:
Saetan wrote:Btw., I didn't mean when you will update banana v1 to v1.4, but how to update from banana-v1 to dev-v1.4. ;-)
Please, don't. I'll have to do some additional works and I prefer do it myself.

*hehe* ... not updating the online distribution, I only meant, how to update my own game. Banana itself as distribution of your script, that part is completly your baby. ;-)

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 18 Feb 2014 22:11
by keoz
Saetan wrote:
keoz wrote:
Saetan wrote:Btw., I didn't mean when you will update banana v1 to v1.4, but how to update from banana-v1 to dev-v1.4. ;-)
Please, don't. I'll have to do some additional works and I prefer do it myself.

*hehe* ... not updating the online distribution, I only meant, how to update my own game. Banana itself as distribution of your script, that part is completly your baby. ;-)
Mmh ok, I completely misunderstood your point. Looks like I really played a little bit to much those days. :wink:

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 09 Mar 2014 10:42
by leifbk
This looks very interesting. I'd like to add a suggestion: Make city growth aware of the time period, such that pre c. 1850, growth should be very slow (1/8). From 1850-1900 a little quicker (1/4), then a new pace 1900-1950 (1/2), and "normal" (full) growth only from 1950. Some of us like to play with horses in the 18th century, but don't like megacities :)

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 07 Apr 2014 15:57
by MrRB
Hi Keoz/anyone reading,

Do you have any idea, why I experience the problem of not seeing the required cargo etc. for cities to grow, in the city screen? It's just a normal cityscreen like Always.

This is the same problem I've addressed with some other GS (except Neighbours Are Important). It may well be me, but I don't see what I'm doing wrong in that case...

Thanks for any clarification!

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 07 Apr 2014 16:54
by keoz
leifbk wrote:This looks very interesting. I'd like to add a suggestion: Make city growth aware of the time period, such that pre c. 1850, growth should be very slow (1/8). From 1850-1900 a little quicker (1/4), then a new pace 1900-1950 (1/2), and "normal" (full) growth only from 1950. Some of us like to play with horses in the 18th century, but don't like megacities :)
Hi,

these is theorically possible, but it would need a lot of rewrite and it's not gonna be on the top-list, at least for now. As a workaround, you can change the settings to harder for the earlier time (which is possible on a running game). Set it 400, then 200, then 100. That would make the job.
MrRB wrote:Do you have any idea, why I experience the problem of not seeing the required cargo etc. for cities to grow, in the city screen? It's just a normal cityscreen like Always.

This is the same problem I've addressed with some other GS (except Neighbours Are Important). It may well be me, but I don't see what I'm doing wrong in that case...
I absolutely don't know why. Could you post a screenshot of the problem and eventually, also a savegame ? Does the problem happens in all cities or only some of them ?

Re: [GS] RCG - A new city growth GS for OTTD/FIRS

Posted: 07 Apr 2014 20:40
by MrRB
Hey Keoz,

Here are a screenshot and a savegame.

I've had to make one, because I didn't start an actual game yet with your GS, because I immediately stumbled onto this glitch.

Thanks for your time!