Disabling industry spawning prevents industries from closing?

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

Post Reply
User avatar
Skarfester
Engineer
Engineer
Posts: 53
Joined: 07 Jun 2022 02:09

Disabling industry spawning prevents industries from closing?

Post by Skarfester »

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?
HGus
Engineer
Engineer
Posts: 121
Joined: 12 May 2013 22:28
Location: Argentina

Re: Disabling industry spawning prevents industries from closing?

Post by HGus »

Are you using the default industries or a NewGRF?
HGus
Engineer
Engineer
Posts: 121
Joined: 12 May 2013 22:28
Location: Argentina

Re: Disabling industry spawning prevents industries from closing?

Post by HGus »

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)
User avatar
Skarfester
Engineer
Engineer
Posts: 53
Joined: 07 Jun 2022 02:09

Re: Disabling industry spawning prevents industries from closing?

Post by Skarfester »

HGus wrote: 16 Apr 2023 16:25 Are you using the default industries or a NewGRF?
Actually I was using OpenGFX+ Industries, so I guess they behave like the base ones, but I'll check it anyways.
HGus wrote: 16 Apr 2023 16:36 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)
Thank you, I'll check those.
HGus
Engineer
Engineer
Posts: 121
Joined: 12 May 2013 22:28
Location: Argentina

Re: Disabling industry spawning prevents industries from closing?

Post by HGus »

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.
_dp_
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 18 Dec 2013 12:32

Re: Disabling industry spawning prevents industries from closing?

Post by _dp_ »

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.
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.

But if you want, you can use industry control flags or frozen economy to prevent closure.
User avatar
Skarfester
Engineer
Engineer
Posts: 53
Joined: 07 Jun 2022 02:09

Re: Disabling industry spawning prevents industries from closing?

Post by Skarfester »

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.
User avatar
jfs
Tycoon
Tycoon
Posts: 1764
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: Disabling industry spawning prevents industries from closing?

Post by jfs »

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.
Try changing these two game settings:
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.
User avatar
Skarfester
Engineer
Engineer
Posts: 53
Joined: 07 Jun 2022 02:09

Re: Disabling industry spawning prevents industries from closing?

Post by Skarfester »

I finally found the answer. What was happening in my game is described in the tt-wiki:
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.
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.
Problem solved. Thank you all for your help.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 13 guests