Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
switch(FEAT_INDUSTRIES, PARENT, increment_town_monthly_cycle_industry_counter,
[
LOAD_PERM(${get_perm_num("this_cycle_industry_counter")}) < count_industries_in_town()
?
STORE_PERM(
LOAD_PERM(${get_perm_num("this_cycle_industry_counter")}) + 1,
${get_perm_num("this_cycle_industry_counter")}
)
:
0
]) {
return;
}
@andythenorth

This comment has been minimized.

Copy link
Owner Author

@andythenorth andythenorth commented Oct 9, 2021

// Name: increment_town_monthly_cycle_industry_counter
3042 * 174 02 0A F2 8A
7E F3 20 \dxFFFFFFFF // count_industries_in_town
\2sto 1A 20 \dx00000084
\2r 1A 20 \dxFFFFFFFF
\2sto 1A 20 \dx00000100
\2r 7C 01 20 \dxFFFFFFFF
\2cmp 7D 84 20 \dxFFFFFFFF
\2< 1A 20 \dx00000001
\2^ 1A 20 \dx00000001
\2sto 1A 20 \dx00000085 // guard
\2^ 1A 20 \dx00000001
\2sto 1A 20 \dx00000086 // !guard
\2r 7D 86 20 \dxFFFFFFFF
\2* 1A 20 \dx00000000
\2sto 1A 20 \dx00000087
\2r 1A 20 \dxFFFFFFFF
\2sto 1A 20 \dx00000100
\2r 1A 20 \dxFFFFFFFF
\2sto 1A 20 \dx00000100
\2r 7C 01 20 \dxFFFFFFFF
\2+ 1A 20 \dx00000001
\2psto 1A 20 \dx00000001
\2* 7D 85 20 \dxFFFFFFFF
\2+ 7D 87 00 \dxFFFFFFFF
\b0
\wx8000 // Return computed value

@andythenorth

This comment has been minimized.

Copy link
Owner Author

@andythenorth andythenorth commented Oct 9, 2021

switch(FEAT_INDUSTRIES, PARENT, increment_town_monthly_cycle_industry_counter,
[

STORE_PERM(100, ${get_perm_num("this_cycle_industry_counter")}),
LOAD_PERM(${get_perm_num("this_cycle_industry_counter")}) < 9
?
STORE_PERM(
LOAD_PERM(${get_perm_num("this_cycle_industry_counter")}) + 1,
${get_perm_num("this_cycle_industry_counter")}
)
:
0
]) {
return;
}

@andythenorth

This comment has been minimized.

Copy link
Owner Author

@andythenorth andythenorth commented Oct 9, 2021

switch(FEAT_INDUSTRIES, PARENT, increment_town_monthly_cycle_industry_counter,
[

STORE_PERM(100, 230),
LOAD_PERM(230) < 9
]) {
1: STORE_PERM(
LOAD_PERM(230) + 1,
${get_perm_num("this_cycle_industry_counter")}
);
0: 0;
return;
}

@andythenorth

This comment has been minimized.

Copy link
Owner Author

@andythenorth andythenorth commented Oct 9, 2021

Procedure monthly_town_loop is not read only (it writes to storage). However if the spurious STORE_PERM is not also used, the ${industry.id}__monthly_prod_change switch is evaluated as a constant result and optimised out.

switch(FEAT_INDUSTRIES, SELF, ${industry.id}_monthly_prod_change,
    [
        monthly_town_loop(
            ${industry.basic_needs_and_luxuries_score},
            ${industry.pollution_and_squalor_score}
        ),
        STORE_PERM(
            1,
            232
        )
    ]) {
    return CB_RESULT_IND_PROD_NO_CHANGE;
}

@glx22

This comment has been minimized.

Copy link

@glx22 glx22 commented Oct 9, 2021

replace https://github.com/OpenTTD/nml/blob/master/nml/ast/switch.py#L130-L131 with

   def is_read_only(self):
        for result in [r.result for r in self.body.ranges] + [self.body.default]:
            if result is not None and result.value is not None:
                if not result.value.is_read_only():
                    return false
        return self.expr.is_read_only()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment