[GS] RCG - A city growth GameScript for OTTD

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

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

Post by keoz » 07 Apr 2014 21:33

MrRB wrote: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!
Well at least for the city you're showing, it is normal that there is not any cargogoal indications. You need to exchange passengers before goals are calculated. When you start exchanging passengers, calculations starts and you will have goals (indicated in the city popup). Same for BCG.
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.

MrRB
Engineer
Engineer
Posts: 29
Joined: 12 Aug 2012 13:58

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

Post by MrRB » 08 Apr 2014 20:51

Wow, thanks for the insight! I'm sorry for wasting your time. That did the trick :D

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

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

Post by Zuu » 10 Apr 2014 22:18

MrRB wrote: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...
Neighbours are important uses the some 2000 ticks with (almost) free DoCommand calls that GS get in during word generation to set up all towns. If you start a large map with many towns, you'll see that world generation takes some time at the script step at the end. This is NAI setting up all towns. Then when the game starts and a company joins (human company or MP companies), the story book and company specific information will be set up quite quickly as there is not that much company specific stuff in NAI.

But it is all up to the script author to use this or not. It also depends on what the script tries to do if this is a workable solution or not. If town management is very CPU intensive, it might make sense to have towns at some idle state until you start to do work there. Though it might then be wise to append some help text to the town info window during the 2000 ticks startup to inform players about this, as most users don't read the Readme even how well things are explained there.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

McZapkie
Tycoon
Tycoon
Posts: 1176
Joined: 18 Jan 2014 18:10

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

Post by McZapkie » 27 Apr 2014 22:17

I played on multiplayer server and suddenly script paused and stick into paused state.
rcon pausing/unpausing of course didn't affect this state.
Any idea, what goes wrong?
Attachments
RCGstopped.sav
(597.35 KiB) Downloaded 69 times

Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4746
Joined: 09 Sep 2007 05:03
Location: home

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

Post by Alberth » 28 Apr 2014 10:17

Does the readme say anything about it?

There is a Pause command to stop the game http://nogo.openttd.org/api/trunk/class ... c36daa6eaa
My guess is that the script used it.

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

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

Post by Zuu » 28 Apr 2014 14:43

If the script uses the pause command, it is important that the setting about what is allowed to do in paused mode is respected and that the GS doesn't try to do anything that is not allowed. Failing to do so will make the game locked in pause forever. This is documented in FS#5283.

Neighbours are important did earlier trigger this bug, but have been reworked to not trigger the bug.


If you have a specific save game that you want to unlock, you can still do that, but it will involve compiling OpenTTD yourself and hack OpenTTD source code to forcefully remove the pause bit set by the GS. After doing that it will probably work in non-modified OpenTTD as long as you either disable the script or that the script at least don't pause the game again.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

McZapkie
Tycoon
Tycoon
Posts: 1176
Joined: 18 Jan 2014 18:10

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

Post by McZapkie » 28 Apr 2014 16:56

Zuu wrote:If the script uses the pause command, it is important that the setting about what is allowed to do in paused mode is respected and that the GS doesn't try to do anything that is not allowed.
OK, but it is my server settings fault, or game script bug?

User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

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

Post by keoz » 29 Apr 2014 10:59

McZapkie wrote:
Zuu wrote:If the script uses the pause command, it is important that the setting about what is allowed to do in paused mode is respected and that the GS doesn't try to do anything that is not allowed.
OK, but it is my server settings fault, or game script bug?
I'll have a look at that, when I find time (sorry, I'm quite busy atm).

What I can say for now, is that the script uses the pause command, at least the initial version on Bananas (I removed it in the last version, to have a smoother game). But, normally, the GS doesn't build things.

But I'll have a better look.
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.

Damrus
Engineer
Engineer
Posts: 21
Joined: 23 Apr 2014 14:23

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

Post by Damrus » 10 May 2014 21:07

The formatting of the cities requirements are kind of awfull : l

I was using the Real growth GS before and now Im trying this one out, but this one might benfit from some creative borrowing. As its far more clear what a city needs/Wants. With this script.

http://i1335.photobucket.com/albums/w67 ... 2e3c94.png

Just my 2 cents.

Gl : ]

User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

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

Post by keoz » 25 Jul 2014 17:13

A new relase of Renewed City Growth is now ready: version 2, available on Bananas.

Among the lot of changes:
- some bugs solved
- some calculations have been reworked
- the Script Game doesn't trigger Pause state anymore at each month, only when the game starts. That should avoid the problem described over by McZapkie and also, the game is more fluid.

Damrus: I'll give a thought about your suggestion.
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.

megbal
Engineer
Engineer
Posts: 1
Joined: 11 Aug 2014 11:07

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

Post by megbal » 11 Aug 2014 11:34

Programmer here. Was using your script and soon noticed it was broken. I've no idea about OpenTTD scripting, but I managed to find this anyway:

Code: Select all

for (local cid = GSCompany.COMPANY_FIRST; cid <= GSCompany.COMPANY_LAST; cid++)
{
	if (GSCompany.ResolveCompanyID(cid) != GSCompany.COMPANY_INVALID)
	{
		TownSupplied[i] = GSCargoMonitor.GetTownDeliveryAmount(cid, ::CargoList[i], this.id, true);
..etc...
Looking at the last line I'd say your scipt only uses the delivered amount of a single company (the one with the highest cid) for everything. I guess you're only testing with a single one...

The old Balanced Growth script has the correct "+=" in the code:

Code: Select all

this.TownSupplied[i] += GSCargoMonitor.GetTownDeliveryAmount(....)
Unless I'm mistaken, you may be slightly ashamed now. And again for not using English but French in your comments and debug text.

If everything else is balanced around this broken code you'll want to consider if cities will grow much too quickly once you fix it.

User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

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

Post by keoz » 11 Aug 2014 17:21

megbal wrote:[...]Looking at the last line I'd say your scipt only uses the delivered amount of a single company (the one with the highest cid) for everything. I guess you're only testing with a single one...

The old Balanced Growth script has the correct "+=" in the code:[...]
Thank you for reporting this ! You're perfectly right about that wrong line. It is fixed in the last revision (see initial post). I just could have a fast check on the fix and since I'm never playing with companies, I'd be glad if someone can confirm that it fixes the problem.
megbal wrote:Unless I'm mistaken, you may be slightly ashamed now. And again for not using English but French in your comments and debug text.
Well, some comments are in english. :wink:

But you're still right. This script tend to look a little bit as a warzone. Hopefully, that also will be progressively fixed.
megbal wrote:If everything else is balanced around this broken code you'll want to consider if cities will grow much too quickly once you fix it.
I think this souldn't be an issue. There is, in any case, a max possible city growth rate for cities (which is related to their size: a city of 10000 cannot grow more than 5 houses/month). Thus, if cities are overwhelmed by supplies, that will not trigger an extremely fast growth. Also, the settings are necessarily adapted to a specific gameplay style (mine), which is: working with one company on one map. But if several companies/players are on the same map, it is possible to adapt the gamescript by changing the difficulty setting (100 being the default).
Last edited by keoz on 13 Aug 2014 13:30, edited 2 times in total.
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.

krinn
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 29 Dec 2010 19:36

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

Post by krinn » 11 Aug 2014 19:42

You can discard many towns quick with GSTown::GetLastMonthTransportedPercentage
mytownlist.Valuate(GSTown.GetLastMonthTransportedPercent, thecargoidofpax)
mytownlist.RemoveValue(0);

If a town have 0 transportedpercent of pax cargo, you don't need to check any companies presence... and can discard the town just by that answer as you discard town that didn't supply any pax to a company in your MonthlyManageTown()
So MonthlyManageTown can only be call because at least a company has transport pax from that town this month, removing all the checks for town with no activities (and you can then also ease the checks in the function now you now at least one company is doing pax activity if the function is run).

You will each month reduce call to the cycle expansive MonthlyManageTown function by a huge amount (until your players actually really use all towns).
Right now, if a town get monitored because one company deliver 1 pax cargo one time, you set the this.MonitorCheck and the town goal/transported cargo... will always be monitored and update even nobody use that town again (company collapse, player remove bus...). If i'm right, your goal doesn't need any update if no company have done something better than previous check no?

ps: moi il ne me gène pas tes commentaires en français :)

krinn
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 29 Dec 2010 19:36

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

Post by krinn » 11 Aug 2014 20:09

Code: Select all

function GoalTown::CheckEvents()
{
while (GSEventController.IsEventWaiting())
	{
	local event = GSEventController.GetNextEvent();
	local eventType = event.GetEventType();
	switch (eventType) 
		{
		case GSEvent.ET_TOWN_FOUNDED:
			event = GSEventTownFounded.Convert(event);
			if (GSTown.IsValidTown(event))	this.towns.append(GoalTown(event));
		break;
		}
	}
}
Didn't test it, but this should fix your issue with new town.

User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

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

Post by keoz » 13 Aug 2014 13:42

Hello, krinn :)
krinn wrote:ps: moi il ne me gène pas tes commentaires en français :)
I'm glad to know that. And obviously, I understand you. :mrgreen:
krinn wrote:

Code: Select all

function GoalTown::CheckEvents()
{
while (GSEventController.IsEventWaiting()) [...]
}
Didn't test it, but this should fix your issue with new town.
Always getting useful comments from your part. Thank you *very much* for your peace of code, which pointed me out to the right way to deal with that. I had to do some changes, (such as extracting the town id before calling GoalTown), but it works fine now. No more crashes on town founding.

For your other suggestion, I still have to see in details. What I can say so far, is that the reason for which the check on cities is so bloated, is that very very little cities have extremely poor pax echanges. Thus, it is not enough to check on town deliveries, but I also need to check town supply to make them grow.
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.

User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

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

Post by keoz » 13 Aug 2014 14:44

Answer continuation.
krinn wrote:You can discard many towns quick with GSTown::GetLastMonthTransportedPercentage
mytownlist.Valuate(GSTown.GetLastMonthTransportedPercent, thecargoidofpax)
mytownlist.RemoveValue(0);
I've been looking a little more into this. Some precisions:
krinn wrote:If a town have 0 transportedpercent of pax cargo, you don't need to check any companies presence... and can discard the town just by that answer as you discard town that didn't supply any pax to a company in your MonthlyManageTown()
The problem is that I don't want to discard towns just because they don't transport anything in one month. I want to discard them when there is not anymore transportation over a long time (the limit is now 6 months). That's to avoid big gaps/fast changes in town growth rates, which I try to smoothen.

About the discarding in MonthlyManegeTown, keep in mind that this additional check (and hence, the call to GSCargoMonitor.GetTownPickupAmount), is only performed in a really rare case: when cities who are already under monitoring (MonitorCheck flag true) have no pax supply for one month. That's actually a corner case and the call is not performed often at all.
krinn wrote:So MonthlyManageTown can only be call because at least a company has transport pax from that town this month, removing all the checks for town with no activities (and you can then also ease the checks in the function now you now at least one company is doing pax activity if the function is run).
MonthlyManageTown is called each month for each town, but all the inactive cities are not fully checked. At the moment, the unmonitored cities (MonitorCheck flag false), are only checked each month for their passengers delivery and if there is no delivery from the city, the function is returned before making all the other checks. So basically an inactive town is out extremely fast from the function.
krinn wrote:Right now, if a town get monitored because one company deliver 1 pax cargo one time, you set the this.MonitorCheck and the town goal/transported cargo... will always be monitored and update even nobody use that town again (company collapse, player remove bus...). If i'm right, your goal doesn't need any update if no company have done something better than previous check no?
Actually, at the moment, a monitored town is discarded from monitoring after 6 months of total inactivity. But still, I think that cities who used to exchange passengers and suddendly lose all pax service are essentially a corner case.

Anyway, as a matter of fact, this function needs to be optimized. I'll see if your suggestions can help to that.

Edit. As additional note, I just tested the functions GSTown.GetLastMonthTransportedPercentage, as also GSTown.GetLastMonthSupplied and quite surprisingly, those functions are more time-consuming than is checking with a for loop the CargoMonitor on a per company basis.
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.

krinn
Transport Coordinator
Transport Coordinator
Posts: 336
Joined: 29 Dec 2010 19:36

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

Post by krinn » 13 Aug 2014 15:58

keoz wrote:Edit. As additional note, I just tested the functions GSTown.GetLastMonthTransportedPercentage, as also GSTown.GetLastMonthSupplied and quite surprisingly, those functions are more time-consuming than is checking with a for loop the CargoMonitor on a per company basis.
Oops sorry so, didn't test it, but i was thinking it would be faster a one function run than the loop on all companies. I'm a bit surprise by your result.

User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

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

Post by keoz » 13 Aug 2014 16:08

krinn wrote:
keoz wrote:Edit. As additional note, I just tested the functions GSTown.GetLastMonthTransportedPercentage, as also GSTown.GetLastMonthSupplied and quite surprisingly, those functions are more time-consuming than is checking with a for loop the CargoMonitor on a per company basis.
Oops sorry so, didn't test it, but i was thinking it would be faster a one function run than the loop on all companies. I'm a bit surprise by your result.
I guess I already did a test once and I was really surprised by that.

I suppose the reason could be in the fact that the GetLastMonthSupplied() function itself runs some loop to addition company supply.
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.

User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

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

Post by keoz » 13 Aug 2014 18:20

Work is going on fast these days on the RCG script.

There is now a public repository for the script, with the help of planetmaker (thanks !). To checkout for last revisions, just:

Code: Select all

hg clone http://hg.openttdcoop.org/gs-rcg
The last revision (r25) includes:
- fix: the script now correctly counts the deliveries from all companies
- 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
- reviewing calculations
- savegame code completely rewritten and simplified
- a lot of code cleanup, including additional comments

With all those changes ... Well. Please report (eventual) bugs, either here on the topic, either on http://dev.openttdcoop.org/projects/gs-rcg/repository.
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.

User avatar
keoz
Transport Coordinator
Transport Coordinator
Posts: 321
Joined: 16 Jul 2009 10:04

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

Post by keoz » 19 Aug 2014 13:32

Still some changes on RCG (now: revision 41)

Apart the fact that there aren't known bugs anymore, the major evolution is that I included now support for other industry sets. Namely:
  • Baseset (temperate, arctic, tropical, toyland)
  • All Firs economies (FIRS general, temperate basic, arctic basic, tropic basic, Hearth of Darkness)
  • ECS (all vectors)
I tried to balance cargos properly in the different cargo categories. Baseset industries only use three cargo categories (Pax/mail, general goods, industry stuff), while other sets still uses 5 categories (see original topic for explanation about cargo categories). Even if I briefly tried all of them, I generally only play with FIRS general economy. Hence it would be useful having some feedback on gameplay with other sets.

I still don't want to upload that on bananas (as upcoming version 3), until recent changes have been well tested. For those interested in testing, see attachment for the last revision.

Note that this last versions needs GS Superlib v. 38 (downloadable on bananas).
Last edited by keoz on 21 Aug 2014 12:26, edited 11 times in total.
Patch - Let's timetable depot waiting time with the Wait in depot patch.
GameScript - Searching a new way to make your cities growing ? Try the Renewed City Growth GameScript.
My screenshots thread.

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 8 guests