From 1ccc5763b18db0fd82b4059d6bbd5bab0560de1e Mon Sep 17 00:00:00 2001 From: "Yi Yang @ Aquamarine" Date: Mon, 20 Nov 2023 22:43:21 +0800 Subject: [PATCH] (Aegis) WIP: tropical --- agrf/parameters/__init__.py | 3 + industry/aegis_gen.py | 24 ++-- industry/economies/firs_tropical.py | 203 ++++++++++++++++++++++++++++ industry/lib/parameters.py | 2 +- 4 files changed, 218 insertions(+), 14 deletions(-) create mode 100644 industry/economies/firs_tropical.py diff --git a/agrf/parameters/__init__.py b/agrf/parameters/__init__.py index fc9e6f2a..9f64ed60 100644 --- a/agrf/parameters/__init__.py +++ b/agrf/parameters/__init__.py @@ -52,6 +52,9 @@ def add(self, g, s): def index(self, name): return [i for i, p in enumerate(self.parameters) if p.name == name][0] + def __getitem__(self, name): + return self.parameters[self.index(name)] + class SearchSpace: def __init__(self, choices, parameter_list): diff --git a/industry/aegis_gen.py b/industry/aegis_gen.py index bdba56cc..e5d9eb0b 100644 --- a/industry/aegis_gen.py +++ b/industry/aegis_gen.py @@ -2,12 +2,19 @@ import grf import struct import argparse -from industry.economies import vanilla_temperate, vanilla_subarctic, vanilla_subtropical, firs_temperate, firs_arctic -from industry.lib.parameters import parameter_choices +from industry.economies import ( + vanilla_temperate, + vanilla_subarctic, + vanilla_subtropical, + firs_temperate, + firs_arctic, + firs_tropical, +) +from industry.lib.parameters import parameter_list, parameter_choices from industry.lib.validator import validate -all_economies = [vanilla_temperate, vanilla_subarctic, vanilla_subtropical, firs_temperate, firs_arctic] +all_economies = [vanilla_temperate, vanilla_subarctic, vanilla_subtropical, firs_temperate, firs_arctic, firs_tropical] all_industries = [] all_cargos = [] @@ -81,16 +88,7 @@ def initialize_metadata(): 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( + index = (parameter_list["ECONOMY"].enum[i],) + tuple( variation[i] for i in ( "POLICY", diff --git a/industry/economies/firs_tropical.py b/industry/economies/firs_tropical.py new file mode 100644 index 00000000..f1a9fe7d --- /dev/null +++ b/industry/economies/firs_tropical.py @@ -0,0 +1,203 @@ +from industry.lib.economy import ( + MetaEconomy, + Economy, + PrimaryIndustry, + WorkerYard, + FreePort, + SecondaryIndustry, + TertiaryIndustry, + Town, +) +from industry.cargos import ( + alcohol, + beans, + chemicals, + china_clay, + coffee, + copper, + copper_ore, + engineering_supplies, + explosives, + farm_supplies, + fertiliser, + fish, + food, + fruit, + grain, + livestock, + mail, + nitrates, + oil, + paper, + passengers, + peat, + phosphate, + potash, + pyrite_ore, + sulphur, + timber, + tired_workers, + water, + wood, + wool, + workers, + zinc, +) +from industry.industries import ( + nitrate_mine, + chemical_plant, + clay_pit, + fish_farm, + fishing_grounds, + fishing_harbor, + forest, + general_store, + herding_coop, + paper_mill, + peatlands, + phosphate_mine, + port, + potash_mine, + power_station, + pyrite_mine, + pyrite_smelter, + sawmill, + towns, + trading_centre, + water_supply, + water_tower, + wharf, + worker_yard, +) + + +class TheEconomy(MetaEconomy): + def __init__(self): + super().__init__("BASIC_TROPICAL") + + def get_economy(self, parameters): + ret = Economy( + { + nitrate_mine: PrimaryIndustry(nitrates), + clay_pit: PrimaryIndustry(china_clay), + peatlands: PrimaryIndustry(peat), + phosphate_mine: PrimaryIndustry(phosphate), + potash_mine: PrimaryIndustry(potash), + pyrite_mine: PrimaryIndustry(pyrite_ore), + fish_farm: PrimaryIndustry(fish), + fishing_grounds: PrimaryIndustry(fish), + forest: PrimaryIndustry(wood), + herding_coop: PrimaryIndustry(food), + pyrite_smelter: SecondaryIndustry(pyrite_ore, (sulphur, zinc)), + sawmill: SecondaryIndustry(wood, timber), + chemical_plant: SecondaryIndustry( + (phosphate, sulphur, nitrates, potash), + (explosives, fertiliser), + ), + fishing_harbor: SecondaryIndustry(fish, food), + paper_mill: SecondaryIndustry((wood, sulphur, china_clay), paper), + power_station: TertiaryIndustry(peat), + general_store: TertiaryIndustry((explosives, fertiliser, zinc, timber)), + towns: Town(passengers, mail, food, paper), + }, + parameters, + ) + if parameters["POLICY"] == "SELF_SUFFICIENT": + ret.graph[port] = FreePort((zinc, fertiliser, paper), (china_clay, nitrates)) + ret.graph[wharf] = FreePort((peat, timber, explosives), potash) + del ret.graph[general_store] # FIXME + elif parameters["POLICY"] in ("FREE_TRADE", "EXPORT"): + ret.graph[port] = FreePort((zinc, fertiliser, paper), (china_clay, nitrates)) + ret.graph[wharf] = FreePort((peat, timber, explosives), potash) + del ret.graph[general_store] # FIXME + del ret.graph[potash_mine] + del ret.graph[nitrate_mine] + del ret.graph[clay_pit] + + if parameters["PRIMARY_INDUSTRY_GROWTH"] == "UNIVERSAL_SUPPLIES": + if nitrate_mine in ret.graph: + ret.graph[nitrate_mine].boosters = engineering_supplies + if clay_pit in ret.graph: + ret.graph[clay_pit].boosters = engineering_supplies + if potash_mine in ret.graph: + ret.graph[potash_mine].boosters = engineering_supplies + ret.graph[peatlands].boosters = engineering_supplies + ret.graph[phosphate_mine].boosters = engineering_supplies + ret.graph[pyrite_mine].boosters = engineering_supplies + + ret.graph[fish_farm].boosters = engineering_supplies + ret.graph[forest].boosters = engineering_supplies + ret.graph[herding_coop].boosters = engineering_supplies + + if parameters["POLICY"] in ("SELF_SUFFICIENT", "FREE_TRADE", "EXPORT"): + ret.graph[port].produces += (engineering_supplies,) + ret.graph[wharf].produces += (engineering_supplies,) + else: + ret.graph[paper_mill].produces += (engineering_supplies,) + + elif parameters["PRIMARY_INDUSTRY_GROWTH"] == "GENERIC_SUPPLIES": + if nitrate_mine in ret.graph: + ret.graph[nitrate_mine].boosters = engineering_supplies + if clay_pit in ret.graph: + ret.graph[clay_pit].boosters = engineering_supplies + if potash_mine in ret.graph: + ret.graph[potash_mine].boosters = engineering_supplies + ret.graph[peatlands].boosters = engineering_supplies + ret.graph[phosphate_mine].boosters = engineering_supplies + ret.graph[pyrite_mine].boosters = engineering_supplies + + ret.graph[fish_farm].boosters = farm_supplies + ret.graph[forest].boosters = farm_supplies + ret.graph[herding_coop].boosters = farm_supplies + + if parameters["POLICY"] in ("SELF_SUFFICIENT", "FREE_TRADE", "EXPORT"): + ret.graph[port].produces += (engineering_supplies, farm_supplies) + ret.graph[wharf].produces += (engineering_supplies, farm_supplies) + else: + ret.graph[paper_mill].produces += (engineering_supplies,) + ret.graph[chemical_plant].produces += (farm_supplies,) + + if parameters["WORKFORCE"].startswith("YETI"): + if parameters["WORKFORCE"] == "YETI": + ret.graph[worker_yard] = WorkerYard(workers, boosters=(paper, zinc)) + elif parameters["WORKFORCE"] == "YETI_PASSENGERS": + ret.graph[worker_yard] = WorkerYard(workers, boosters=(paper, zinc, passengers)) + elif parameters["WORKFORCE"] == "YETI_MAIL": + ret.graph[worker_yard] = WorkerYard(workers, boosters=(paper, zinc, mail)) + elif parameters["WORKFORCE"] == "YETI_TIRED": + ret.graph[worker_yard] = WorkerYard(workers, boosters=(paper, zinc, tired_workers)) + + # FIXME: remove PRESET; support SECONDARY + if parameters["WORKER_PARTICIPATION"] in ("PRESET", "NONE"): + ret.graph[fishing_grounds].boosters = workers + if parameters["WORKFORCE"] == "YETI_TIRED": + ret.graph[fishing_grounds].produces += (tired_workers,) + if parameters["WORKER_PARTICIPATION"] in ("PRIMARY_INDUSTRY", "SECONDARY_INDUSTRY", "BOTH"): + for i in [ + nitrate_mine, + clay_pit, + potash_mine, + peatlands, + phosphate_mine, + pyrite_mine, + fish_farm, + forest, + herding_coop, + ]: + if i in ret.graph: + ret.graph[i] = ret.graph[i].to_secondary(workers) + if parameters["WORKFORCE"] == "YETI_TIRED": + ret.graph[i].produces += (tired_workers,) + + if port in ret.graph: + if parameters["SEA_INDUSTRY"] == "LAND_ONLY": + ret.graph[trading_centre] = ret.graph[port] + del ret.graph[port] + elif parameters["SEA_INDUSTRY"] == "BOTH": + ret.graph[trading_centre] = ret.graph[port] + + if parameters["TOWN_GOODS"] == "FOOD_AND_WATER": + ret.graph[water_supply] = PrimaryIndustry(water) + ret.graph[water_tower] = TertiaryIndustry(water) + + return ret diff --git a/industry/lib/parameters.py b/industry/lib/parameters.py index b25c4694..4399d39c 100644 --- a/industry/lib/parameters.py +++ b/industry/lib/parameters.py @@ -12,8 +12,8 @@ 2: "VANILLA_SUBTROPICAL", 3: "BASIC_TEMPERATE", 4: "BASIC_ARCTIC", + 5: "BASIC_TROPICAL", # ?: "TOYLAND", - # ?: "BASIC_SUBTROPICAL", }, ), Parameter(