Skip to content

Commit

Permalink
Change: WIP on experimental location of industries by town type
Browse files Browse the repository at this point in the history
  • Loading branch information
andythenorth committed Jul 2, 2021
1 parent e824040 commit c796646
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/industries/basic_oxygen_furnace.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
prob_map_gen="5",
map_colour="49",
special_flags=["IND_FLAG_MILITARY_HELICOPTER_CAN_EXPLODE"],
# it's rare to force co-location of secondaries, but this one is near blast furnace by design
location_checks=dict(
industry_max_distance=["blast_furnace", 72], same_type_distance=72
),
location_checks=dict(same_type_distance=72),
name="string(STR_IND_BASIC_OXYGEN_FURNACE)",
nearby_station_name="string(STR_STATION_FURNACE)",
fund_cost_multiplier="160",
TEST_town_types=[3],
TEST_requires_keystone=True,
)

industry.economy_variations["STEELTOWN"].enabled = True
Expand Down
2 changes: 2 additions & 0 deletions src/industries/blast_furnace.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
name="string(STR_IND_BLAST_FURNACE)",
nearby_station_name="string(STR_STATION_FURNACE)",
fund_cost_multiplier="190",
TEST_town_types=[3],
TEST_is_keystone=True,
)


Expand Down
1 change: 1 addition & 0 deletions src/industries/chlor_alkali_plant.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
name="string(STR_IND_CHLOR_ALKALI_PLANT)",
nearby_station_name="string(STR_STATION_BRINE_WORKS)",
fund_cost_multiplier="170",
TEST_town_types=[5],
)

###industry.economy_variations['BETTER_LIVING_THROUGH_CHEMISTRY'].enabled = True
Expand Down
2 changes: 2 additions & 0 deletions src/industries/coal_mine.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
name="TTD_STR_INDUSTRY_NAME_COAL_MINE",
nearby_station_name="string(STR_STATION_COLLIERY)",
fund_cost_multiplier="252",
TEST_town_types=[4],
TEST_is_keystone=True,
)


Expand Down
7 changes: 3 additions & 4 deletions src/industries/coke_oven.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
prob_in_game="3",
prob_map_gen="5",
map_colour="183",
# it's rare to force co-location of secondaries, but this one is near blast furnace by design
location_checks=dict(
industry_max_distance=["blast_furnace", 72], same_type_distance=72
),
location_checks=dict(same_type_distance=72),
name="string(STR_IND_COKE_OVEN)",
nearby_station_name="string(STR_STATION_BANK_TOP)",
fund_cost_multiplier="120",
TEST_town_types=[3, 4],
TEST_requires_keystone=True,
)

industry.economy_variations["STEELTOWN"].enabled = True
Expand Down
1 change: 1 addition & 0 deletions src/industries/cryo_plant.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
name="string(STR_IND_CRYO_PLANT)",
nearby_station_name="string(STR_STATION_CRYO_PLANT)",
fund_cost_multiplier="180",
TEST_town_types=[5],
)

industry.economy_variations["STEELTOWN"].enabled = True
Expand Down
2 changes: 2 additions & 0 deletions src/industries/electric_arc_furnace.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
name="string(STR_IND_ELECTRIC_ARC_FURNACE)",
nearby_station_name="string(STR_STATION_FURNACE)",
fund_cost_multiplier="160",
TEST_town_types=[3, 6],
TEST_is_keystone=True,
)

industry.economy_variations["STEELTOWN"].enabled = True
Expand Down
1 change: 1 addition & 0 deletions src/industries/glass_works.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
name="string(STR_IND_GLASS_WORKS)",
nearby_station_name="string(STR_STATION_SHARP_STREET)",
fund_cost_multiplier="95",
TEST_town_types=[5],
)

industry.economy_variations["BASIC_TEMPERATE"].enabled = True
Expand Down
1 change: 1 addition & 0 deletions src/industries/iron_ore_mine.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
location_checks=dict(cluster=[70, 3]),
nearby_station_name="string(STR_STATION_IRONSTONE)",
fund_cost_multiplier="232",
TEST_town_types=[4],
)


Expand Down
7 changes: 3 additions & 4 deletions src/industries/slag_grinding_plant.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
prob_map_gen="5",
map_colour="19",
special_flags=["IND_FLAG_MILITARY_AIRPLANE_CAN_EXPLODE"],
# it's rare to force co-location of secondaries, but this one is near blast furnace by design
location_checks=dict(
industry_max_distance=["blast_furnace", 72], same_type_distance=72
),
location_checks=dict(same_type_distance=72),
name="string(STR_IND_SLAG_GRINDING_PLANT)",
nearby_station_name="string(STR_STATION_SILO)",
fund_cost_multiplier="100 ",
TEST_town_types=[3, 6],
TEST_requires_keystone=True,
)

industry.economy_variations["STEELTOWN"].enabled = True
Expand Down
3 changes: 3 additions & 0 deletions src/industry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,9 @@ class Industry(object):
def __init__(self, id, graphics_change_dates=[], **kwargs):
self.id = id
self.graphics_change_dates = graphics_change_dates # 0-based, ordered list of dates for which graphics should change, match to graphics suffixed _1, _2, _3 etc.
self.TEST_town_types = kwargs.get("TEST_town_types", [])
self.TEST_requires_keystone = kwargs.get("TEST_requires_keystone", False)
self.TEST_is_keystone = kwargs.get("TEST_is_keystone", False)
self.tiles = []
self.sprites = []
self.smoke_sprites = []
Expand Down
11 changes: 10 additions & 1 deletion src/templates/extra_text_primary.pynml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--! Extra text in the industry window (callback 3A) -->

switch(FEAT_INDUSTRIES, SELF, ${industry.id}_extra_text, [
switch(FEAT_INDUSTRIES, SELF, ${industry.id}_extra_text_foo, [
STORE_TEMP((primary_level1_requirement * ${industry.supply_requirements[2]}) |
(primary_level2_requirement * ${industry.supply_requirements[2]}) << 16, 0x100),
LOAD_PERM(${industry.perm_storage.var_current_supplies_prod_factor})
Expand All @@ -10,6 +10,14 @@ switch(FEAT_INDUSTRIES, SELF, ${industry.id}_extra_text, [
return string(STR_${industry.supply_requirements[1]}_PRODUCTION_1X);
}


<!--!switch (FEAT_INDUSTRIES, PARENT, ${industry.id}_extra_text, ${"[STORE_PERM(var[0x41, 0, 0xFFFF] % " + str(industry.TEST_town_type) + ", 128)]" if industry.TEST_town_type is not None else 0}) {
return ${industry.id}_extra_text_foo;
}-->
switch (FEAT_INDUSTRIES, PARENT, ${industry.id}_extra_text, STORE_PERM(town_index % 3, 127)) {
return ${industry.id}_extra_text_foo;
}

<!--!
Additional text after the cargos in the industry window (callback 37)
The 0x3800 expressions here are related to using extended cb 37 before nml support was added, and can be removed when nml is updated
Expand Down Expand Up @@ -50,3 +58,4 @@ switch (FEAT_INDUSTRIES, SELF, ${industry.id}_cargo_subtype_display, getbits(ext
1: ${industry.id}_cargo_subtype_display_switch_economy;
return CB_RESULT_NO_TEXT;
}

8 changes: 7 additions & 1 deletion src/templates/extra_text_secondary.pynml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<!--! Extra text in the industry window (callback 3A) -->

switch (FEAT_INDUSTRIES, SELF, ${industry.id}_extra_text, economy) {
switch (FEAT_INDUSTRIES, SELF, ${industry.id}_extra_text_foo, economy) {
<tal:economies repeat="economy industry.economies_enabled_for_industry">
${economy.numeric_id}: return ${industry.get_extra_text_string(economy)};
</tal:economies>
}

<!--!switch (FEAT_INDUSTRIES, PARENT, ${industry.id}_extra_text, ${"[STORE_PERM(var[0x41, 0, 0xFFFF] % " + str(industry.TEST_town_type) + ", 128)]" if industry.TEST_town_type is not None else 0}) {
return ${industry.id}_extra_text_foo;
}-->
switch (FEAT_INDUSTRIES, PARENT, ${industry.id}_extra_text, STORE_PERM(town_index, 128)) {
return ${industry.id}_extra_text_foo;
}

<!--!
Additional text after the cargos in the industry window (callback 37)
Expand Down
2 changes: 1 addition & 1 deletion src/templates/industry_primary.pynml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
item(FEAT_INDUSTRIES, ${industry.id}, ${industry.numeric_id}) {
graphics {
construction_probability: ${industry.id}_check_availability;
build_prod_change: randomise_primary_production_on_build;
build_prod_change: randomise_primary_production_on_build(${1 if industry.TEST_is_keystone else 0});
produce_cargo_arrival: ${industry.id}_produce_cargo_arrival;
produce_256_ticks: ${industry.id}_produce_256_ticks;
monthly_prod_change: ${industry.id}_monthly_prod_change;
Expand Down
2 changes: 1 addition & 1 deletion src/templates/industry_primary_no_supplies.pynml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ switch (FEAT_INDUSTRIES, SELF, ${industry.id}_produce_256_ticks, economy) {
item(FEAT_INDUSTRIES, ${industry.id}, ${industry.numeric_id}) {
graphics {
construction_probability: ${industry.id}_check_availability;
build_prod_change: randomise_primary_production_on_build;
build_prod_change: randomise_primary_production_on_build(${1 if industry.TEST_is_keystone else 0});
produce_256_ticks: ${industry.id}_produce_256_ticks;
location_check: ${industry.id}_check_location;
monthly_prod_change: return CB_RESULT_IND_PROD_NO_CHANGE;
Expand Down
1 change: 1 addition & 0 deletions src/templates/industry_primary_town_producer.pynml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ switch(FEAT_INDUSTRIES, PARENT, ${industry.id}_produce, [
graphics {
produce_256_ticks: ${industry.id}_produce;
construction_probability:${industry.id}_check_availability;
build_prod_change: randomise_primary_production_on_build(${1 if industry.TEST_is_keystone else 0});
location_check: ${industry.id}_check_location;
monthly_prod_change: CB_RESULT_IND_PROD_NO_CHANGE;
random_prod_change: CB_RESULT_IND_PROD_NO_CHANGE;
Expand Down
1 change: 1 addition & 0 deletions src/templates/industry_secondary.pynml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
item(FEAT_INDUSTRIES, ${industry.id}, ${industry.numeric_id}) {
graphics {
construction_probability: ${industry.id}_check_availability;
build_prod_change: randomise_primary_production_on_build(${1 if industry.TEST_is_keystone else 0});
produce_cargo_arrival: ${industry.id}_produce_cargo_arrival;
monthly_prod_change: CB_RESULT_IND_PROD_NO_CHANGE;
random_prod_change: CB_RESULT_IND_PROD_NO_CHANGE;
Expand Down
2 changes: 1 addition & 1 deletion src/templates/industry_tertiary.pynml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
item(FEAT_INDUSTRIES, ${industry.id}, ${industry.numeric_id}) {
graphics {
construction_probability: ${industry.id}_check_availability;
build_prod_change: randomise_primary_production_on_build;
build_prod_change: randomise_primary_production_on_build(${1 if industry.TEST_is_keystone else 0});
produce_cargo_arrival: ${industry.id}_produce_cargo_arrival_economy_${economy.numeric_id};
<tal:has_production condition="industry.has_production">
produce_256_ticks: ${industry.id}_production_256_economy_${economy.numeric_id};
Expand Down
19 changes: 18 additions & 1 deletion src/templates/location_check_macros_industry.pynml
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,31 @@
Restrictions apply only to industries funded by the game.
founder == FOUNDER_GAME means founded by the game, 0 .. 15 are player companies */
-->
switch (FEAT_INDUSTRIES, SELF, ${location_check.switch_entry_point}, (
switch (FEAT_INDUSTRIES, SELF, ${location_check.switch_entry_point}_bar, (
(extra_callback_info2 == IND_CREATION_FUND) ||
(extra_callback_info2 == IND_CREATION_PROSPECT)
)
) {
1: return CB_RESULT_LOCATION_ALLOW;
${location_check.switch_result};
}
switch (FEAT_INDUSTRIES, PARENT, ${location_check.switch_entry_point}_foo, [LOAD_PERM(99)]) {
<tal:industry_requires_keystone condition="industry.TEST_requires_keystone">
0: return CB_RESULT_LOCATION_DISALLOW;
</tal:industry_requires_keystone>
return ${location_check.switch_entry_point}_bar;
}
switch (FEAT_INDUSTRIES, PARENT, ${location_check.switch_entry_point}, town_index % 8) {
<tal:town_type_required condition="len(industry.TEST_town_types) > 0">
<tal:town_type repeat="town_type industry.TEST_town_types">
${town_type}: return ${location_check.switch_entry_point}_foo;
</tal:town_type>
return CB_RESULT_LOCATION_DISALLOW;
</tal:town_type_required>
<tal:no_town_type_required condition="len(industry.TEST_town_types) == 0">
return ${location_check.switch_entry_point}_foo;
</tal:no_town_type_required>
}
</metal:check_founder>


Expand Down
7 changes: 6 additions & 1 deletion src/templates/randomise_primary_production_on_build.pynml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
random_switch(FEAT_INDUSTRIES, SELF, randomise_primary_production_on_build) {
random_switch(FEAT_INDUSTRIES, SELF, randomise_primary_production_on_build_foo) {
1: return 8;
1: return 12;
4: return 16;
Expand All @@ -8,3 +8,8 @@ random_switch(FEAT_INDUSTRIES, SELF, randomise_primary_production_on_build) {
1: return 32;
1: return 36;
}

switch (FEAT_INDUSTRIES, PARENT, randomise_primary_production_on_build, keystone_flag, [keystone_flag == 1 ? STORE_PERM(1, 99): 0]) {
return randomise_primary_production_on_build_foo;
}

0 comments on commit c796646

Please sign in to comment.