Factorio: add option "Tech Cost Distribution" (#1404)

* Factorio: add option "Tech Cost Distribution"

* TextClient: None out game on disconnect

* TextClient: disconnect is async
This commit is contained in:
Fabian Dill 2023-01-28 00:38:12 +01:00 committed by GitHub
parent dfdcad28e5
commit cf2204a861
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -61,6 +61,19 @@ class MaxTechCost(TechCost):
default = 500 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): class TechCostMix(Range):
"""Percent chance that a preceding Science Pack is also required. """Percent chance that a preceding Science Pack is also required.
Chance is rolled per preceding pack.""" Chance is rolled per preceding pack."""
@ -379,6 +392,7 @@ factorio_options: typing.Dict[str, type(Option)] = {
"tech_tree_layout": TechTreeLayout, "tech_tree_layout": TechTreeLayout,
"min_tech_cost": MinTechCost, "min_tech_cost": MinTechCost,
"max_tech_cost": MaxTechCost, "max_tech_cost": MaxTechCost,
"tech_cost_distribution": TechCostDistribution,
"tech_cost_mix": TechCostMix, "tech_cost_mix": TechCostMix,
"ramping_tech_costs": RampingTechCosts, "ramping_tech_costs": RampingTechCosts,
"silo": Silo, "silo": Silo,

View File

@ -7,7 +7,7 @@ import typing
from BaseClasses import Region, Entrance, Location, Item, RegionType, Tutorial, ItemClassification from BaseClasses import Region, Entrance, Location, Item, RegionType, Tutorial, ItemClassification
from worlds.AutoWorld import World, WebWorld from worlds.AutoWorld import World, WebWorld
from .Mod import generate_mod 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 .Shapes import get_shapes
from .Technologies import base_tech_table, recipe_sources, base_technology_table, \ from .Technologies import base_tech_table, recipe_sources, base_technology_table, \
all_ingredient_names, all_product_sources, required_technologies, get_rocket_requirements, \ 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) location_names = self.multiworld.random.sample(location_pool, location_count)
self.locations = [FactorioScienceLocation(player, loc_name, self.location_name_to_id[loc_name], nauvis) self.locations = [FactorioScienceLocation(player, loc_name, self.location_name_to_id[loc_name], nauvis)
for loc_name in location_names] for loc_name in location_names]
rand_values = sorted(random.randint(self.multiworld.min_tech_cost[self.player], distribution: TechCostDistribution = self.multiworld.tech_cost_distribution[self.player]
self.multiworld.max_tech_cost[self.player]) for _ in self.locations) 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]: if self.multiworld.ramping_tech_costs[self.player]:
def sorter(loc: FactorioScienceLocation): def sorter(loc: FactorioScienceLocation):
return loc.complexity, loc.rel_cost return loc.complexity, loc.rel_cost