[GS] Think globally, act locally

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

HapticTactic
Engineer
Engineer
Posts: 23
Joined: 15 Mar 2019 19:56

Re: [GS] Think globally, act locally

Post by HapticTactic »

I have found a bug (I believe):

The time elapsed is reset when you load your saved game. Can you confirm?
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

HapticTactic wrote: The time elapsed is reset when you load your saved game. Can you confirm?
Yes, it is a bug, but I have no idea, how to fix it. I have variable for starting year saved:

Code: Select all

function GSToyHelper::Save() {
	local save_table = {};
	save_table.town_data_table <- {};
	if (firsttime_start) {
		save_table.town_data_table <- ::TownDataTable;
	} else {
		foreach (i, town in this.towns)
			{
				save_table.town_data_table[town.id] <- town.SavingTownData();
			}
		save_table.gamestart_year <- this.gamestart_year;
	}
	return save_table;
}
and loaded:

Code: Select all

function GSToyHelper::Load(version, saved_data)
{
	firsttime_start = false;
	foreach (townid, town_data in saved_data.town_data_table) {
		::TownDataTable[townid] <- town_data;
	}
	this.gamestart_year = saved_data.gamestart_year;
}
but it doesn't work, I have to little knowledge of squirrel to found out what is wrong.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
HapticTactic
Engineer
Engineer
Posts: 23
Joined: 15 Mar 2019 19:56

Re: [GS] Think globally, act locally

Post by HapticTactic »

Well, that's too bad. My programming skills for OTTD are non-existent.

What is the actual effect of this bug? Does it only mean that the script becomes easier in difficulty every time the time is reset because the global economy index grows?
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

HapticTactic wrote: What is the actual effect of this bug? Does it only mean that the script becomes easier in difficulty every time the time is reset because the global economy index grows?
Exactly yes. In case of multiplayer server, there is usually no problem due to lack of save/load procedures. In case of singleplayer, you can just pause game instead of quit.
HapticTactic
Engineer
Engineer
Posts: 23
Joined: 15 Mar 2019 19:56

Re: [GS] Think globally, act locally

Post by HapticTactic »

McZapkie wrote:
HapticTactic wrote: What is the actual effect of this bug? Does it only mean that the script becomes easier in difficulty every time the time is reset because the global economy index grows?
Exactly yes. In case of multiplayer server, there is usually no problem due to lack of save/load procedures. In case of singleplayer, you can just pause game instead of quit.
Well, I am currently using the script in a multiplayer game that we have saved and loaded numerous times (because the game is long).
rowdog
Engineer
Engineer
Posts: 67
Joined: 24 May 2017 12:51
Location: East Texas

Re: [GS] Think globally, act locally

Post by rowdog »

I'm just guessing but do you need to save gamestart_year on the first run? Maybe you can move that line out of the if() like so...

Code: Select all

function GSToyHelper::Save() {
	local save_table = {};
	save_table.town_data_table <- {};
	if (firsttime_start) {
		save_table.town_data_table <- ::TownDataTable;
	} else {
		foreach (i, town in this.towns)
			{
				save_table.town_data_table[town.id] <- town.SavingTownData();
			}
		//save_table.gamestart_year <- this.gamestart_year;
	}
	save_table.gamestart_year <- this.gamestart_year;
	return save_table;
}
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

Version 19 uploaded to bananas.
I removed all game duration stuff and simplified rules, now:
  • industry will be generated if amount of served industry (+ bonus from subsidies) is above threshold (settings);
  • density of industry generation depend on active subsidies and vary from 2 to 5 if above-mentioned criterion is fulfilled;
  • subsidies will be generated if amount of served towns is above threshold (settings);
  • town growth cargoes are now compatible with XIS.
Note, that you don't need to hunt for subsidies, you will collect them randomly if you have passenger/mail cargodist network,
because subsidies are generated between already served town and any other town, served or not.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
nihues
Engineer
Engineer
Posts: 85
Joined: 13 Jan 2015 10:26

Re: [GS] Think globally, act locally

Post by nihues »

Oops, started and got this error on map generation (latest XIS).
Attachments
Unnamed, Jan 1st, 1920.png
(2.5 MiB) Not downloaded yet
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

nihues wrote: 21 Jan 2021 13:21 Oops, started and got this error on map generation (latest XIS).
Could you show script settings?
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
nihues
Engineer
Engineer
Posts: 85
Joined: 13 Jan 2015 10:26

Re: [GS] Think globally, act locally

Post by nihues »

Just tried again with Industry setting OFF and works. It occurs when Industry: try to keep industries on map: ON

the rest are default.
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: [GS] Think globally, act locally

Post by Wahazar »

Fixed version 20 is on bananas. I also simplified city growth rules, below 50 city grow intself, below 500 it demands mail or pass, above this threshold it demand both mail and pass.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
Argus
Tycoon
Tycoon
Posts: 1204
Joined: 16 Oct 2018 08:31
Location: Heart of the Highlands. Not Scottish. Czech.

Re: [GS] Think globally, act locally

Post by Argus »

The game seems to ignore older versions of the script. When you start a game played with an older version, the script does not load.
AdmiralEllis
Engineer
Engineer
Posts: 12
Joined: 22 Jan 2023 23:17

Re: [GS] Think globally, act locally

Post by AdmiralEllis »

Playing on a snowy map, I can't get a town above the snow line to grow. It has been at 459 population since the start of the game and I have been keeping it above the passengers and mail threshold all the while. I have tried bringing food to it, but to no avail. I am using AXIS and Improved Town Layouts if that makes a difference. For what it's worth, the script does not seem to recognize the food from AXIS as food--maybe the way cargoes are defined internally needs to be looked at. I am going to continue with this save and try bringing goods once I have that set up.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 25 guests