Disabling industry spawning prevents industries from closing?
Moderator: OpenTTD Developers
- Skarfester
- Engineer
- Posts: 53
- Joined: 07 Jun 2022 02:09
Disabling industry spawning prevents industries from closing?
I'm writing a simple industry limiter script that stops the spawning of new industries when a certain amount of them are in the map. While testing, at the beginning everything works normal but later in the game, when the limit is reached, industries stop appearing (as intended) but the existing ones don't close either. I ignored completely some industries and the production goes up and down but never close.
Is there a way to fix this or both effects are directly related?
Is there a way to fix this or both effects are directly related?
Re: Disabling industry spawning prevents industries from closing?
Are you using the default industries or a NewGRF?
Re: Disabling industry spawning prevents industries from closing?
From a GSIndustryList for each GSIndustry check GetControlFlags for INDCTL_NO_CLOSURE and DCTL_NO_PRODUCTION_DECREASE flags. The former prevents closure no matter the production (it can be zero), the later disables production decrease (then never reaching zero)
- Skarfester
- Engineer
- Posts: 53
- Joined: 07 Jun 2022 02:09
Re: Disabling industry spawning prevents industries from closing?
Actually I was using OpenGFX+ Industries, so I guess they behave like the base ones, but I'll check it anyways.
Thank you, I'll check those.
Re: Disabling industry spawning prevents industries from closing?
I got this from an AI:
Code: Select all
function checkIndustries() {
local industryList = GSIndustryList();
foreach (industry in industryList) {
local controlFlags = industry.GetControlFlags();
if (controlFlags & INDCTL_NO_CLOSURE) {
GSLog.Info ("Industry " + industry.GetName() + " has INDCTL_NO_CLOSURE flag activated");
}
if (controlFlags & INDCTL_NO_PRODUCTION_DECREASE) {
GSLog.Info ("Industry " + industry.GetName() + " has IINDCTL_NO_PRODUCTION_DECREASE flag activated.");
}
}
}
Last edited by HGus on 17 Apr 2023 19:14, edited 3 times in total.
Re: Disabling industry spawning prevents industries from closing?
That is already vanilla behavior, it keeps industry density at about the same level. So you shouldn't need to write any game script for that.Skarfester wrote: ↑15 Apr 2023 23:04 I'm writing a simple industry limiter script that stops the spawning of new industries when a certain amount of them are in the map.
But if you want, you can use industry control flags or frozen economy to prevent closure.
- Skarfester
- Engineer
- Posts: 53
- Joined: 07 Jun 2022 02:09
Re: Disabling industry spawning prevents industries from closing?
Thank you HGus for the code.
_dp_: In my experience, even if I start with few industries on the map they keep appearing over time and became too much for my taste. This code will be part of my Overpopulation script as an optional setting.
_dp_: In my experience, even if I start with few industries on the map they keep appearing over time and became too much for my taste. This code will be part of my Overpopulation script as an optional setting.
Re: Disabling industry spawning prevents industries from closing?
Try changing these two game settings:Skarfester wrote: ↑19 Apr 2023 01:38 Thank you HGus for the code.
_dp_: In my experience, even if I start with few industries on the map they keep appearing over time and became too much for my taste. This code will be part of my Overpopulation script as an optional setting.
Industry density = Funding only
Economy type = Frozen
If you change the settings to this, the game won't construct any new industries, and the existing industries will never close down.
- Skarfester
- Engineer
- Posts: 53
- Joined: 07 Jun 2022 02:09
Re: Disabling industry spawning prevents industries from closing?
I finally found the answer. What was happening in my game is described in the tt-wiki:
Problem solved. Thank you all for your help.
It says TTDPatch but I'm pretty sure OpenTTD has the same behaviour. So, in my game I was playing with minimal industries (one of each) and that was preventing them from closing. When I started a new game with a lot more industries on map, they keep closing even after the spawning of new ones was disabled, thus opening "slots" for new ones to appear, just as I intended in the first place.By default, TTDPatch tries to ensure that cargo chains don't get broken. To achieve this, TTDPatch always generates at least one instance from every available industry type during random map generation, and prevents the last instance from closing down even when the production change callback says it should.
Problem solved. Thank you all for your help.
Who is online
Users browsing this forum: No registered users and 13 guests