8000 "Allows repeated species" should match expectations · Issue #5222 · freeorion/freeorion · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
"Allows repeated species" should match expectations #5222
Open
@SomeTroglodyte

Description

@SomeTroglodyte

Feature request

Idea

RULE_ALLOW_REPEATED_SPECIES should work as a human player expects the narrative to work: "If I choose humans and duplicates are to be avoided, I should find myself to be the only human-founded empire in most games" - fact currently is, your starting species will more often found another empire than not.

Gain

Please players

POC

Index: default/python/universe_generation/empires.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/default/python/universe_generation/empires.py b/default/python/universe_generation/empires.py
--- a/default/python/universe_generation/empires.py	(revision 61de7441fe8e709b5fc2d3095879f2460e2e793f)
+++ b/default/python/universe_generation/empires.py	(date 1746973059365)
@@ -42,13 +42,14 @@
 empire_name_generator = get_empire_name_generator()
 
 
-def get_starting_species_pool():
+def get_starting_species_pool(alreadyUsed = None):
     """
     Empire species pool generator, return random empire species and ensure somewhat even distribution
+    @param alreadyUsed - if set, then RULE_ALLOW_REPEATED_SPECIES is false and it contains the species already in use e.g. by player's choice
     """
     # fill the initial pool of playable species, without repetitions unless RULE_ALLOW_REPEATED_SPECIES is true
-    if not fo.getGameRules().getToggle("RULE_ALLOW_REPEATED_SPECIES"):
-        pool = fo.get_playable_species()
+    if alreadyUsed:
+        pool = [species for species in fo.get_playable_species() if species not in alreadyUsed]
     else:
         pool = fo.get_playable_species() * 2
 
@@ -66,10 +67,6 @@
         yield pool.pop()
 
 
-# generates starting species for empires, use next(starting_species_pool) to get next species
-starting_species_pool = get_starting_species_pool()
-
-
 def count_planets_in_systems(systems, planet_types_filter=HS_ACCEPTABLE_PLANET_TYPES):
     """
     Return the total number of planets in the specified group of systems,
@@ -545,7 +542,7 @@
 
 
 # noqa: C901
-def setup_empire(empire, empire_name, home_system, starting_species, player_name, gsd):  # noqa: C901
+def setup_empire(empire, empire_name, home_system, starting_species, player_name, gsd, starting_species_pool):  # noqa: C901
     """
     Sets up various aspects of an empire, like empire name, homeworld, etc.
     """
Index: default/python/universe_generation/universe_generator.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/default/python/universe_generation/universe_generator.py b/default/python/universe_generation/universe_generator.py
--- a/default/python/universe_generation/universe_generator.py	(revision 61de7441fe8e709b5fc2d3095879f2460e2e793f)
+++ b/default/python/universe_generation/universe_generator.py	(date 1746970879983)
@@ -10,7 +10,7 @@
 from common.handlers import init_handlers
 from common.listeners import listener
 from common.option_tools import parse_config
-from empires import compile_home_system_list, setup_empire
+from empires import compile_home_system_list, setup_empire, get_starting_species_pool
 from fields import generate_fields
 from galaxy import calc_star_system_positions
 from monsters import generate_monsters
@@ -120,6 +120,11 @@
         raise Exception(err_msg)
     print("Home systems:", home_systems)
 
+    usedSpecies = None if fo.getGameRules().getToggle("RULE_ALLOW_REPEATED_SPECIES") else \
+        {psd.starting_species for psd in psd_map.values() if psd.starting_species and psd.starting_species != "RANDOM"}
+    # generates starting species for empires, use next(starting_species_pool) to get next species
+    starting_species_pool = get_starting_species_pool(usedSpecies)
+
     teams = {}
     for psd in psd_map.values():
         if psd.starting_team >= 0:
@@ -141,7 +146,7 @@
                 else:
                     placed = True
                     if not setup_empire(
-                        empire, psd.empire_name, home_system, psd.starting_species, psd.player_name, gsd
+                        empire, psd.empire_name, home_system, psd.starting_species, psd.player_name, gsd, starting_species_pool
                     ):
                         report_error("Python create_universe: couldn't set up empire for player %s" % psd.player_name)
             if not placed:
@@ -149,12 +154,12 @@
             psds = psds_new
         # place leftovers
         for (empire, psd), home_system in zip(psds, hs):
-            if not setup_empire(empire, psd.empire_name, home_system, psd.starting_species, psd.player_name, gsd):
+            if not setup_empire(empire, psd.empire_name, home_system, psd.starting_species, psd.player_name, gsd, starting_species_pool):
                 report_error("Python create_universe: couldn't set up empire for player %s" % psd.player_name)
     else:
         # set up empires for each player
         for empire, psd, home_system in zip(psd_map.keys(), psd_map.values(), home_systems):
-            if not setup_empire(empire, psd.empire_name, home_system, psd.starting_species, psd.player_name, gsd):
+            if not setup_empire(empire, psd.empire_name, home_system, psd.starting_species, psd.player_name, gsd, starting_species_pool):
                 report_error("Python create_universe: couldn't set up empire for player %s" % psd.player_name)
 
     # assign names to all star systems and their planets

... this works as I would expect it to.

Original feature PR: #3748

Metadata

Metadata

Assignees

Labels

category:bugThe Issue/PR describes or solves a perceived malfunction within the game.category:tweakThe PR contains insignificant code changes, like code style grooming or value tweaking.component:content scriptingThe Issue/PR deals with the FOCS language, turn events or the universe generator.component:game mechanicThe Issue/PR deals with the currently used or planned game mechanics.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0