From cf2204a861a235ef89872d58fc7cb7e722d018bd Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sat, 28 Jan 2023 00:38:12 +0100 Subject: [PATCH] Factorio: add option "Tech Cost Distribution" (#1404) * Factorio: add option "Tech Cost Distribution" * TextClient: None out game on disconnect * TextClient: disconnect is async --- worlds/factorio/Options.py | 14 ++++++++++++++ worlds/factorio/__init__.py | 15 ++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/worlds/factorio/Options.py b/worlds/factorio/Options.py index c5afb730..eda5eec7 100644 --- a/worlds/factorio/Options.py +++ b/worlds/factorio/Options.py @@ -61,6 +61,19 @@ class MaxTechCost(TechCost): default = 500 +class TechCostDistribution(Choice): + """Random distribution of costs of the Science Packs. + Even: any number between min and max is equally likely. + Low: low costs, near the minimum, are more likely. + Middle: medium costs, near the average, are more likely. + High: high costs, near the maximum, are more likely.""" + display_name = "Tech Cost Distribution" + option_even = 0 + option_low = 1 + option_middle = 2 + option_high = 3 + + class TechCostMix(Range): """Percent chance that a preceding Science Pack is also required. Chance is rolled per preceding pack.""" @@ -379,6 +392,7 @@ factorio_options: typing.Dict[str, type(Option)] = { "tech_tree_layout": TechTreeLayout, "min_tech_cost": MinTechCost, "max_tech_cost": MaxTechCost, + "tech_cost_distribution": TechCostDistribution, "tech_cost_mix": TechCostMix, "ramping_tech_costs": RampingTechCosts, "silo": Silo, diff --git a/worlds/factorio/__init__.py b/worlds/factorio/__init__.py index a48e7592..4b6d6b9e 100644 --- a/worlds/factorio/__init__.py +++ b/worlds/factorio/__init__.py @@ -7,7 +7,7 @@ import typing from BaseClasses import Region, Entrance, Location, Item, RegionType, Tutorial, ItemClassification from worlds.AutoWorld import World, WebWorld from .Mod import generate_mod -from .Options import factorio_options, MaxSciencePack, Silo, Satellite, TechTreeInformation, Goal +from .Options import factorio_options, MaxSciencePack, Silo, Satellite, TechTreeInformation, Goal, TechCostDistribution from .Shapes import get_shapes from .Technologies import base_tech_table, recipe_sources, base_technology_table, \ all_ingredient_names, all_product_sources, required_technologies, get_rocket_requirements, \ @@ -97,8 +97,17 @@ class Factorio(World): location_names = self.multiworld.random.sample(location_pool, location_count) self.locations = [FactorioScienceLocation(player, loc_name, self.location_name_to_id[loc_name], nauvis) for loc_name in location_names] - rand_values = sorted(random.randint(self.multiworld.min_tech_cost[self.player], - self.multiworld.max_tech_cost[self.player]) for _ in self.locations) + distribution: TechCostDistribution = self.multiworld.tech_cost_distribution[self.player] + min_cost = self.multiworld.min_tech_cost[self.player] + max_cost = self.multiworld.max_tech_cost[self.player] + if distribution == distribution.option_even: + rand_values = (random.randint(min_cost, max_cost) for _ in self.locations) + else: + mode = {distribution.option_low: min_cost, + distribution.option_middle: (min_cost+max_cost)//2, + distribution.option_high: max_cost}[distribution.value] + rand_values = (random.triangular(min_cost, max_cost, mode) for _ in self.locations) + rand_values = sorted(rand_values) if self.multiworld.ramping_tech_costs[self.player]: def sorter(loc: FactorioScienceLocation): return loc.complexity, loc.rel_cost