Skip to content

Commit

Permalink
Merge pull request #1518 from Dilvish-fo/ai_trooper_design_and_produc…
Browse files Browse the repository at this point in the history
…tion

fixes a problem with AI ship production location, which was particularly plaguing troopers, also limits total AI trooper size and allows AI trooper armor
  • Loading branch information
Dilvish-fo committed Apr 23, 2017
2 parents e29acd0 + c7c6ad6 commit fcd9ec0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion default/python/AI/ProductionAI.py
Expand Up @@ -128,11 +128,16 @@ def get_best_ship_info(priority, loc=None):
if not best_designs:
return None, None, None

# best_designs are already sorted by rating high to low, so the top rating is the first encountered within
# our planet search list
for design_stats in best_designs:
top_rating, pid, top_id, cost, stats = design_stats
if pid in planet_ids:
break
valid_locs = [item[1] for item in best_designs if item[0] == top_rating and item[2] == top_id]
else:
return None, None, None # apparently can't build for this priority within the desired planet group
valid_locs = [pid for rating, pid, design_id, _, _ in best_designs if
rating == top_rating and design_id == top_id and pid in planet_ids]
return top_id, fo.getShipDesign(top_id), valid_locs
else:
return None, None, None # must be missing a Shipyard or other orbital (or missing tech)
Expand Down
13 changes: 11 additions & 2 deletions default/python/AI/ShipDesignAI.py
Expand Up @@ -84,6 +84,14 @@
MISSING_REQUIREMENT_MULTIPLIER = -1000
INVALID_DESIGN_RATING = -999 # this needs to be negative but greater than MISSING_REQUIREMENT_MULTIPLIER

# For Trooper designs, set a maximum number of troopers per ship that will be considered for ratings purposes, to
# prevent the AI from settling on trooper designs with the absolute largest hulls, which may nominally have the lowest
# per-unit-cost but which then result in much trooper overkill/waste when actually deployed. The application of this
# limit does (in normal use) take into account shipbuilder species modifiers.
# Current limit set to 48 to allow up to a grav hull filled with Advanced Troop Pods and Good offensive troopers (or
# partly filled with Great advanced offensive troopers)
MAX_TROOPERS_PER_SHIP = 48

# Potentially, not adding techs to AIDependencies is intended for testing purposes.
# Therefore, chat the player only once to inform him about the issue to prevent spam.
_raised_warnings = set()
Expand Down Expand Up @@ -1796,7 +1804,7 @@ def _rating_function(self):
if self.design_stats.troops == 0:
return INVALID_DESIGN_RATING
else:
return self.design_stats.troops/self._adjusted_production_cost()
return min(MAX_TROOPERS_PER_SHIP, self.design_stats.troops)/self._adjusted_production_cost()

def _starting_guess(self, available_parts, num_slots):
# fill completely with biggest troop pods. If none are available for this slot type, leave empty.
Expand All @@ -1817,7 +1825,8 @@ def _starting_guess(self, available_parts, num_slots):

def _class_specific_filter(self, partname_dict):
for slot in partname_dict:
remaining_parts = [part for part in partname_dict[slot] if get_part_type(part).partClass in TROOPS]
remaining_parts = [part for part in partname_dict[slot] if
get_part_type(part).partClass in TROOPS.union(ARMOUR)]
partname_dict[slot] = remaining_parts


Expand Down

0 comments on commit fcd9ec0

Please sign in to comment.