Skip to content

Commit

Permalink
(Aegis) make variants; now it fails due to action7 bytelength
Browse files Browse the repository at this point in the history
  • Loading branch information
ahyangyi committed Nov 7, 2023
1 parent d024199 commit ddc8635
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 35 deletions.
3 changes: 3 additions & 0 deletions cargos/cargos.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
# OTIS
"OTI1": {},
"OTI2": {},
# AEGIS
"WRKR": {},
"TRWK": {},
}

cargo_info = {k.encode(): v for k, v in cargo_info.items()}
Expand Down
33 changes: 25 additions & 8 deletions industry/aegis_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,39 @@ def initialize_metadata():
all_cargos.append(cargo)

for industry in all_industries:
industry._props["exists"] = SplitDefinition(("ECONOMY",), {})
industry._props["production_types"] = SplitDefinition(("ECONOMY",), {})
industry._props["acceptance_types"] = SplitDefinition(("ECONOMY",), {})
industry._props["exists"] = SplitDefinition(
("ECONOMY", "POLICY", "PRIMARY_INDUSTRY_GROWTH", "WORKFORCE", "SEA_INDUSTRY", "TOWN_GOODS"), {}
)
industry._props["production_types"] = SplitDefinition(
("ECONOMY", "POLICY", "PRIMARY_INDUSTRY_GROWTH", "WORKFORCE", "SEA_INDUSTRY", "TOWN_GOODS"), {}
)
industry._props["acceptance_types"] = SplitDefinition(
("ECONOMY", "POLICY", "PRIMARY_INDUSTRY_GROWTH", "WORKFORCE", "SEA_INDUSTRY", "TOWN_GOODS"), {}
)

for i, meta_economy in enumerate(all_economies):
for variation in parameter_choices.iterate_variations():
economy = meta_economy.get_economy(variation)
index = (
{
# FIXME
0: "VANILLA_TEMPERATE",
1: "VANILLA_SUBARCTIC",
2: "VANILLA_SUBTROPICAL",
3: "BASIC_TEMPERATE",
4: "BASIC_ARCTIC",
}[i],
) + tuple(
variation[i] for i in ("POLICY", "PRIMARY_INDUSTRY_GROWTH", "WORKFORCE", "SEA_INDUSTRY", "TOWN_GOODS")
)
for industry in all_industries:
if industry in economy.industries:
industry._props["exists"].branches[(i,)] = True
industry._props["exists"].branches[index] = True
else:
industry._props["exists"].branches[(i,)] = False
industry._props["exists"].branches[index] = False
for industry, flow_desc in economy.graph.items():
industry._props["production_types"].branches[(i,)] = flow_desc.translated_produces
industry._props["acceptance_types"].branches[(i,)] = flow_desc.translated_accepts
break
industry._props["production_types"].branches[index] = flow_desc.translated_produces
industry._props["acceptance_types"].branches[index] = flow_desc.translated_accepts


def get_string_manager():
Expand Down
2 changes: 1 addition & 1 deletion industry/economies/firs_arctic.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def get_economy(self, parameters):
elif parameters["SEA_INDUSTRY"] == "BOTH":
ret.graph[trading_centre] = ret.graph[port]

if parameters["TOWN_GOODS"] == "SUBTROPICAL":
if parameters["TOWN_GOODS"] == "FOOD_AND_WATER":
ret.graph[water_supply] = PrimaryIndustry(water)
ret.graph[water_tower] = TertiaryIndustry(water)

Expand Down
2 changes: 1 addition & 1 deletion industry/economies/firs_temperate.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_economy(self, parameters):
elif parameters["SEA_INDUSTRY"] == "BOTH":
ret.graph[trading_centre] = ret.graph[port]

if parameters["TOWN_GOODS"] == "SUBTROPICAL":
if parameters["TOWN_GOODS"] == "FOOD_AND_WATER":
ret.graph[water_supply] = PrimaryIndustry(water)
ret.graph[water_tower] = TertiaryIndustry(water)

Expand Down
2 changes: 1 addition & 1 deletion industry/economies/vanilla_subarctic.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_economy(self, parameters):
elif parameters["SEA_INDUSTRY"] == "BOTH":
ret.graph[trading_centre] = ret.graph[port]

if parameters["TOWN_GOODS"] == "SUBTROPICAL":
if parameters["TOWN_GOODS"] == "FOOD_AND_WATER":
ret.graph[water_supply] = PrimaryIndustry(water)
ret.graph[water_tower] = TertiaryIndustry(water)

Expand Down
2 changes: 1 addition & 1 deletion industry/economies/vanilla_subtropical.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_economy(self, parameters):
# FIXME
ret.graph[diamond_mine].boosters = workers

if parameters["TOWN_GOODS"] in ("ORGANIC", "SUBTROPICAL"):
if parameters["TOWN_GOODS"] in ("ORGANIC", "FOOD_AND_WATER"):
ret.graph[water_supply] = PrimaryIndustry(water)
ret.graph[water_tower] = TertiaryIndustry(water)

Expand Down
4 changes: 2 additions & 2 deletions industry/economies/vanilla_temperate.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_economy(self, parameters):
# FIXME
ret.graph[coal_mine].boosters = workers

if parameters["TOWN_GOODS"] in ("SUBARCTIC", "SUBTROPICAL"):
if parameters["TOWN_GOODS"] in ("FOOD", "FOOD_AND_WATER"):
ret.graph[food_processing_plant] = SecondaryIndustry(
(
livestock,
Expand All @@ -105,7 +105,7 @@ def get_economy(self, parameters):
)
ret.graph[factory].consumes = tuple(x for x in ret.graph[factory].consumes if x not in [livestock, grain])
ret.graph[towns].food = food
if parameters["TOWN_GOODS"] == "SUBTROPICAL":
if parameters["TOWN_GOODS"] == "FOOD_AND_WATER":
ret.graph[water_supply] = PrimaryIndustry(water)
ret.graph[water_tower] = TertiaryIndustry(water)

Expand Down
33 changes: 18 additions & 15 deletions industry/lib/industry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@

class SplitDefinition:
def __init__(self, variables, branches):
if isinstance(variables, int):
# Legacy format
variables = (variables,)
branches = {(i,): b for i, b in branches.items()}
elif isinstance(variables, str):
idx = parameter_list.index(variables)
p = parameter_list.parameters[idx]
variables = (idx,)
branches = {(p.enum_index(i),): b for i, b in branches.items()}
elif isinstance(variables[0], str):
variables = tuple(parameter_list.index(idx) for idx in variables)
branches = {
tuple(parameter_list.index(idx).enum_index(s) for idx, s in zip(variables, i)): b
for i, b in branches.items()
}
self.variables = variables
self.branches = branches

def fixup(self):
if isinstance(self.variables, int):
# Legacy format
self.variables = (self.variables,)
self.branches = {(i,): b for i, b in self.branches.items()}
elif isinstance(self.variables, str):
idx = parameter_list.index(self.variables)
self.variables = (idx,)
self.branches = {(parameter_list.parameters[idx].enum_index(i),): b for i, b in self.branches.items()}
elif isinstance(self.variables[0], str):
self.variables = tuple(parameter_list.index(idx) for idx in self.variables)
self.branches = {
tuple(parameter_list.parameters[idx].enum_index(s) for idx, s in zip(self.variables, i)): b
for i, b in self.branches.items()
}


class AIndustry(grf.SpriteGenerator):
def __init__(self, *, name, id=None, callbacks={}, **props):
Expand All @@ -45,6 +46,7 @@ def dynamic_prop_variables(self):
ret = set()
for p in self._props.values():
if isinstance(p, SplitDefinition):
p.fixup()
for v in p.variables:
ret.add(v)
return list(sorted(ret))
Expand All @@ -54,6 +56,7 @@ def resolve_props(self, parameters):
miss = False
for k, v in self._props.items():
while isinstance(v, SplitDefinition):
v.fixup()
branch_key = tuple(parameters[var] for var in v.variables)
if branch_key in v.branches:
v = v.branches[branch_key]
Expand Down
23 changes: 19 additions & 4 deletions industry/lib/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,26 @@

parameter_choices = SearchSpace(
[
("POLICY", ["AUTARKY", "SELF_SUFFICIENT", "FREE_TRADE", "EXPORT"]),
("PRIMARY_INDUSTRY_GROWTH", ["NONE", "UNIVERSAL_SUPPLIES", "GENERIC_SUPPLIES", "SPECIFIC_SUPPLIES"]),
# FIXME: handle preset
("POLICY", ["PRESET", "AUTARKY", "SELF_SUFFICIENT", "FREE_TRADE", "EXPORT"]),
(
"PRIMARY_INDUSTRY_GROWTH",
[
"PRESET",
"NONE",
"UNIVERSAL_SUPPLIES",
"GENERIC_SUPPLIES",
"SPECIFIC_SUPPLIES",
"TOWN_POPULATION",
"WORKERS",
"DISCRETE",
"CONTINUOUS",
],
),
(
"WORKFORCE",
[
"PRESET",
"ABSTRACT",
"PROFESSIONAL",
"PROFESSIONAL_PASSENGERS",
Expand All @@ -191,8 +206,8 @@
"YETI_TIRED",
],
),
("SEA_INDUSTRY", ["ORGANIC", "LAND_ONLY", "BOTH", "SEA_ONLY"]),
("TOWN_GOODS", ["ORGANIC", "NONE", "SUBARCTIC", "SUBTROPICAL"]),
("SEA_INDUSTRY", ["PRESET", "ORGANIC", "LAND_ONLY", "BOTH", "EITHER", "SEA_ONLY"]),
("TOWN_GOODS", ["PRESET", "ORGANIC", "NONE", "FOOD", "FOOD_AND_WATER"]),
],
parameter_list,
)
Expand Down
4 changes: 2 additions & 2 deletions industry/lib/validator/climate_supplies.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def check_climate_supplies(economy):
if economy.parameters["TOWN_GOODS"] in ("SUBARCTIC", "SUBTROPICAL"):
if economy.parameters["TOWN_GOODS"] in ("FOOD", "FOOD_AND_WATER"):
assert any(x.label == b"FOOD" for x in economy.cargos)
if economy.parameters["TOWN_GOODS"] == "SUBTROPICAL":
if economy.parameters["TOWN_GOODS"] == "FOOD_AND_WATER":
assert any(x.label == b"WATR" for x in economy.cargos)

0 comments on commit ddc8635

Please sign in to comment.