[NoGo] Neighbours are important

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
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Neighbours are important

Post by Zuu »

Update - Version 16

Many new and updated translations. Thank you everyone that contributed to this script :-)
  • New translation: Korean (kevin)
  • New translation: Catalan (juanjo)
  • New translation: Finnish (Arexander)
  • New translation: US English (Supercheese)
  • Updated translation: Spanish (SilverSurferZzZ)
  • Updated translation: Dutch (Alberth)
  • Updated translation: Croatian (Voyager1)
  • Updated translation: Russian (George)
  • Updated translation: German (planetmaker)
  • Doc: Document that it is a good idea to post here if you made translation updates and would like to see them in a new version of the script
I'm sorry the US English translation is not mentioned in readme.txt now but will be so in version 17 when that is released, as I didn't find out until I already uploaded version 16.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
HGus
Engineer
Engineer
Posts: 121
Joined: 12 May 2013 22:28
Location: Argentina

Re: [NoGo] Neighbours are important

Post by HGus »

Thanks :)
User avatar
Expresso
Tycoon
Tycoon
Posts: 1760
Joined: 09 Aug 2004 00:14
Location: Gouda, the Netherlands

Re: [NoGo] Neighbours are important

Post by Expresso »

Fun gamescript!

Currently I'm playing a game in which I only transport pax and have industry construction set to manual. However, the gamescript still requires goods to be delivered to the towns and as my towns grow, the towns start to require goods (which I do not have on the map).

Is it possible to introduce a setting to disable the cargo requirements, have individual settings for the different cargo types (much like cargodist has) or have the gamescript detect that industries are set to funding only and thus not use cargo for town growth requirements?

EDIT: just had this idea:
How about having larger towns checking in on more and further away neighbors as they grow larger? As towns grow beyond certain points, new important neighbors could be added. This could stimulate the player to connect more towns to his network.
bouchacha
Engineer
Engineer
Posts: 14
Joined: 04 Dec 2015 03:47

Re: [NoGo] Neighbours are important

Post by bouchacha »

Do the cargo needs change once a city gets bigger? I notice there are stockpiles for Food and Goods but I'm at 16k population and none of those have been required for growth.
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: [NoGo] Neighbours are important

Post by Sylf »

bouchacha wrote:...stockpiles...
Are you actually delivering those cargoes to the city? You're not transferring those at the station by any chance, are you?
Or, perhaps unloading those at the station that's not accepting them?
I don't think you should be seeing stockpiles of anything anywhere except for at the factory/food processing plant stations.

Maybe some screen shots or a copy of the game save file would help us see what's exactly going on.
bouchacha
Engineer
Engineer
Posts: 14
Joined: 04 Dec 2015 03:47

Re: [NoGo] Neighbours are important

Post by bouchacha »

Image
This is from a subartic game.

I thought stockpiles were a well-established feature of this script. If you deliver too much of the needed cargo, the city will "store" up to 10 times the monthly requirement. Barfingley on the left has passengers and food stockpiled, and the mail needs were newly met so it's growing. Duborough doesn't have any needs met. You'll notice however that both have stockpiles for Goods and Petrol even though none require them for growth (so far). I was wondering if those requirements kick in at a higher population level.
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: [NoGo] Neighbours are important

Post by Sylf »

Ah, my bad. The last time I played with this GS was before it had the stockpile feature, I thought the "stockpile" was some cargo build-up at a station.
HGus
Engineer
Engineer
Posts: 121
Joined: 12 May 2013 22:28
Location: Argentina

Re: [NoGo] Neighbours are important

Post by HGus »

Let's explain some things.

Both cities require passengers, mail and food to grow.

Barfingley already got the requirements. excess from past months are stockpiled (1875 food/30 pass), the excess that you see in mail (40-28) will be stockpiled for next month. Even if goods and petrol were not required their listings are there for future use and scripting efficiency.

Duborough did not get any reguired cargo yet (as far as the last script checking), that you see as red text.

The "Stockpile Info" listing that you see in there is included in all cities. They doesn't mean that the cargos are required, just the cargo excess from past requirements if they were delivered or just zeroes if no cargo was required or if required but not delivered in excess.

You talked about a city with 16k people. Do you want to know the population trigger for petrol and goods? Or if there is a bug in the script that never trigs those requirements?
User avatar
Gremnon
Tycoon
Tycoon
Posts: 1517
Joined: 16 Sep 2005 12:23
Skype: the_gremnon
Location: /home
Contact:

Re: [NoGo] Neighbours are important

Post by Gremnon »

I'm not sure about bouchacha, but I'd like to know if the extra two are ever required - and at what point. It'd be useful for planning ahead better so I'm not delivering cargoes I don't actually need to, instead of sending them where I could make better use of them.
bouchacha
Engineer
Engineer
Posts: 14
Joined: 04 Dec 2015 03:47

Re: [NoGo] Neighbours are important

Post by bouchacha »

Gremnon wrote:I'm not sure about bouchacha, but I'd like to know if the extra two are ever required - and at what point. It'd be useful for planning ahead better so I'm not delivering cargoes I don't actually need to, instead of sending them where I could make better use of them.
That's exactly what I want to know!

I found out that Tim's patch pack has a feature where you can set the population parameters at world generation so I ran some tests!

The requirements change depending on the climate and whether FIRS is installed.

Temperate:
No matter what the population is (tested up to 500k), cities require only mail, passengers, and goods/gasoline depending on whether FIRS is installed. Once FIRS is installed, the stockpiles show up no matter what, even though they seem to have no purpose.

Image
Image

Sub-Artic:
Towns require mail, passengers, and food, and then at 20k population they also require goods/gasoline depending on whether FIRS is installed. The stockpiles seem to be left over or a result of coding necessity.
Image
Image

I'm not sure if Tim's pack changes anything fundamental about these results but there you have it. I must say that it would've been very interesting if the towns started requiring all 5 cargos! Oh well.
HGus
Engineer
Engineer
Posts: 121
Joined: 12 May 2013 22:28
Location: Argentina

Re: [NoGo] Neighbours are important

Post by HGus »

I am lost.

In my games, cities still require all 5 cargoes even with FIRS at lower pop...

And what is "Tim's pack"?

:?
bouchacha
Engineer
Engineer
Posts: 14
Joined: 04 Dec 2015 03:47

Re: [NoGo] Neighbours are important

Post by bouchacha »

HGus wrote:I am lost.

In my games, cities still require all 5 cargoes even with FIRS at lower pop...

And what is "Tim's pack"?

:?
Would you mind posting a screenshot? Tim's pack is a patch pack, I only used it because it happened to have a useful setting which allowed you to generate large cities from the beginning.

Edit: I just installed a fresh copy of vanilla OpenTTD and this script and didn't see anything that would contradict my testing above.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Neighbours are important

Post by Zuu »

HGus wrote:You talked about a city with 16k people. Do you want to know the population trigger for petrol and goods? Or if there is a bug in the script that never trigs those requirements?
The requirements in short-term increase by increased population and at some point additional cargoes are added. However, don't forget that you play with Neighbours are important. In this script, the size of the neighbouring towns play an important role in the requirements of your town. By growing your neighbours, you lower the requirements of your town.

Which towns are your neighbours?
That is included in the town info window. It is calculated when the game starts and doesn't change.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
bouchacha
Engineer
Engineer
Posts: 14
Joined: 04 Dec 2015 03:47

Re: [NoGo] Neighbours are important

Post by bouchacha »

Zuu wrote:
HGus wrote:You talked about a city with 16k people. Do you want to know the population trigger for petrol and goods? Or if there is a bug in the script that never trigs those requirements?
The requirements in short-term increase by increased population and at some point additional cargoes are added. However, don't forget that you play with Neighbours are important. In this script, the size of the neighbouring towns play an important role in the requirements of your town. By growing your neighbours, you lower the requirements of your town.

Which towns are your neighbours?
That is included in the town info window. It is calculated when the game starts and doesn't change.
I've generated multiple maps and did not find any correlation with whether or not a town has neighbors (as designated by the script) or whether their population makes a difference.

I'm really surprised that there is so much ambiguity over the question of cargo needs ?(
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Neighbours are important

Post by Zuu »

bouchacha wrote:I've generated multiple maps and did not find any correlation with whether or not a town has neighbors (as designated by the script) or whether their population makes a difference.

I'm really surprised that there is so much ambiguity over the question of cargo needs ?(
It is the relative size to its neighbours that matters. Not if it has neighbours or not. I assume here you have not disabled this part in the settings but use the default script settings.

Here is the code that set the goals if you like to get into details: (if you like to look into eg. GetNeighborhoodFactor, this code is from town.nut)

Edit: Mind that this.SetCargoGoal is where stockpile happens. Stockpile is btw a user contributed patch that has been included in this script. Basically, the stockpile give you a reduction in the goal, as this script rely on OpenTTD checking if you fulfilled the goal or not. The stockpile on the other hand is implemented script-side only. So you may want to disable it or look at towns without any cargo delivery or at least not any stockpiles when you compare town goals.

Code: Select all

function GoalTown::SetGoal()
{
	// Check the vehicle congestion of the town
	//this.CheckCongestion(); // Called by ManageTown - the only caller of this method

	local population = GSTown.GetPopulation(this.id);
	local location = GSTown.GetLocation(this.id);

	// Neighbour factor:
	local n_percent = GSController.GetSetting("enable_neighbours") == 1?
		this.GetNeighborhoodFactor(population) : 0;
	local n_factor = n_percent > 0? n_percent / 100.0 : 1.0;

	// Difficulty factor:
	local d_percent = GSController.GetSetting("goal_scale_factor");
	local d_factor = d_percent > 0? d_percent / 100.0 : 1.0; // Use 1.0 if setting is missing

	// Compute a combined neighbour + difficulty factor
	local factor = n_factor * d_factor;

	Log.Info(GSTown.GetName(this.id) + " has overall factor " + factor, Log.LVL_DEBUG);

	switch (GSGame.GetLandscape()) {
		case GSGame.LT_TEMPERATE:
		case GSGame.LT_TOYLAND:
			this.SetCargoGoal(GSCargo.TE_PASSENGERS, MaxAsInt(((population / 10) - 5) * factor, 1));
			this.SetCargoGoal(GSCargo.TE_MAIL,       MaxAsInt(((population / 50) - 5) * factor, 0));
			this.SetCargoGoal(GSCargo.TE_GOODS,      MaxAsInt(((population / 100) - 5) * factor, 0));
			break;

		case GSGame.LT_ARCTIC:
			this.SetCargoGoal(GSCargo.TE_PASSENGERS, MaxAsInt(((population / 10) - 5) * factor, 1));
			this.SetCargoGoal(GSCargo.TE_FOOD,       MaxAsInt(((population / 20) - 5) * factor, 0));
			this.SetCargoGoal(GSCargo.TE_MAIL,       MaxAsInt(((population / 50) - 10) * factor, 0));
			this.SetCargoGoal(GSCargo.TE_GOODS,      MaxAsInt(((population / 100) - 200) * factor, 0));
			break;

		case GSGame.LT_TROPIC:
			// non-desert towns have the 'water' requirement added to the food requirement instead.
			// It will not make food requirement kick in earlier, but when it does it will grow quicker.
			local desert_town = Town.IsDesertTown(this.id);
			Log.Info(GSTown.GetName(this.id) + " at " + Tile.GetTileString(location) + " is desert: " + desert_town, Log.LVL_DEBUG);
			local water_requirement = MaxAsInt(((population / 50) - 2) * factor, 0);
			this.SetCargoGoal(GSCargo.TE_PASSENGERS, MaxAsInt(((population / 10) - 5) * factor, 1));
			this.SetCargoGoal(GSCargo.TE_FOOD,       MaxAsInt(((population / 20) - 5) * factor, 0) + (desert_town? 0 : water_requirement));
			this.SetCargoGoal(GSCargo.TE_WATER,      desert_town? water_requirement : 0);
			this.SetCargoGoal(GSCargo.TE_MAIL,       MaxAsInt(((population / 50) - 10) * factor, 0));
			this.SetCargoGoal(GSCargo.TE_GOODS,      MaxAsInt(((population / 100) - 20) * factor, 0));
			break;
	}
}
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
bouchacha
Engineer
Engineer
Posts: 14
Joined: 04 Dec 2015 03:47

Re: [NoGo] Neighbours are important

Post by bouchacha »

Thank you for posting the code! It looks like the interpretation of my tests were correct after all. You only need Passengers, Mail, and eventually Goods (I'm ignoring climate-dependent food and water requirements for now) to grow and it looks like FIRS changes the Goods requirement to Gasoline instead. Good to know!!
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Neighbours are important

Post by Zuu »

As for your question regarding FIRS, you see in the code I pasted, when it sets goals it is tied to what town effects that are available in temperate without any NewGRFs. The stockpiles code on the other hand ask OpenTTD for a list of town effects and thus fail to regard that SetGoal() will not use town effects that have no cargoes in temperate without any NewGRFs.

What you can do (without any code work) is to use desert climate as it will use more town effects. With code work it is of course possible to come up with some way for the goal assignment code to regard what town effects that have cargoes available. Either with a setting to use the legacy method for old saves or that the method at least when for games w/o NewGRFs gives the same result.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Gremnon
Tycoon
Tycoon
Posts: 1517
Joined: 16 Sep 2005 12:23
Skype: the_gremnon
Location: /home
Contact:

Re: [NoGo] Neighbours are important

Post by Gremnon »

Can scripts see NewGRF's or their parameters? I only ask because I've discovered using FIRS (1.4.5, shows up in NewGRF list as 1.4.4M) in Temperate Basic Economy, because Petrol isn't defined there's no third cargo needed for growth - just Passengers and Mail. Goods is defined, and is listed in the stockpiles, but it doesn't get used. I'm guessing that because Petrol might be defined by FIRS, it won't fallback to Goods, or something similar?
HGus
Engineer
Engineer
Posts: 121
Joined: 12 May 2013 22:28
Location: Argentina

Re: [NoGo] Neighbours are important

Post by HGus »

Zuu wrote:As for your question regarding FIRS, you see in the code I pasted, when it sets goals it is tied to what town effects that are available in temperate without any NewGRFs. The stockpiles code on the other hand ask OpenTTD for a list of town effects and thus fail to regard that SetGoal() will not use town effects that have no cargoes in temperate without any NewGRFs.

What you can do (without any code work) is to use desert climate as it will use more town effects. With code work it is of course possible to come up with some way for the goal assignment code to regard what town effects that have cargoes available. Either with a setting to use the legacy method for old saves or that the method at least when for games w/o NewGRFs gives the same result.
Hi. This city in Temperate with FIRS using FIRS economy, does really need "petrol" to grow or delivering goods is enough and the message is a script glitch?
Attachments
Dibujo.PNG
Dibujo.PNG (44.22 KiB) Viewed 5273 times
User avatar
Sylf
President
President
Posts: 957
Joined: 23 Nov 2010 21:25
Location: ::1

Re: [NoGo] Neighbours are important

Post by Sylf »

HGus wrote:Hi. This city in Temperate with FIRS using FIRS economy, does really need "petrol" to grow or delivering goods is enough and the message is a script glitch?
That's probably controlled by FIRS, with this line for the definition of petrol

Code: Select all

town_growth_effect = 'TOWNGROWTH_GOODS',
And the game script takes whatever is defined as TOWNGROWTH_GOODS and use it as the required cargo for the town.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests