本文整理汇总了Python中CombatRatingsAI.get_fleet_rating方法的典型用法代码示例。如果您正苦于以下问题:Python CombatRatingsAI.get_fleet_rating方法的具体用法?Python CombatRatingsAI.get_fleet_rating怎么用?Python CombatRatingsAI.get_fleet_rating使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CombatRatingsAI
的用法示例。
在下文中一共展示了CombatRatingsAI.get_fleet_rating方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: can_issue_order
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def can_issue_order(self, verbose=False):
if not super(OrderMove, self).can_issue_order(verbose=verbose):
return False
# TODO: figure out better way to have invasions (& possibly colonizations) require visibility on target without needing visibility of all intermediate systems
# if False and main_mission_type not in [MissionType.ATTACK, # TODO: consider this later
# MissionType.MILITARY,
# MissionType.SECURE,
# MissionType.HIT_AND_RUN,
# MissionType.EXPLORATION]:
# if not universe.getVisibility(target_id, foAI.foAIstate.empireID) >= fo.visibility.partial:
# #if not target_id in interior systems
# foAI.foAIstate.needsEmergencyExploration.append(fleet.systemID)
# return False
system_id = self.fleet.get_system().id
if system_id == self.target.get_system().id:
return True # TODO: already there, but could consider retreating
fleet_rating = CombatRatingsAI.get_fleet_rating(self.fleet.id)
target_sys_status = foAI.foAIstate.systemStatus.get(self.target.id, {})
f_threat = target_sys_status.get('fleetThreat', 0)
m_threat = target_sys_status.get('monsterThreat', 0)
p_threat = target_sys_status.get('planetThreat', 0)
threat = f_threat + m_threat + p_threat
safety_factor = MilitaryAI.get_safety_factor()
universe = fo.getUniverse()
if fleet_rating >= safety_factor * threat:
return True
elif not p_threat and self.target.id in fo.getEmpire().supplyUnobstructedSystems:
return True
else:
sys1 = universe.getSystem(system_id)
sys1_name = sys1 and sys1.name or "unknown"
target_system = self.target.get_system()
target_system_name = (target_system and target_system.get_object().name) or "unknown"
my_other_fleet_rating = foAI.foAIstate.systemStatus.get(self.target.id, {}).get('myFleetRating', 0) # TODO: adjust calc for any departing fleets
is_military = foAI.foAIstate.get_fleet_role(self.fleet.id) == MissionType.MILITARY
total_rating = my_other_fleet_rating + fleet_rating
if any((
(my_other_fleet_rating > 3 * safety_factor * threat),
(is_military and total_rating > safety_factor * threat),
(is_military and total_rating > 0.8 * safety_factor * threat and fleet_rating > 0.2 * threat)
)):
if verbose:
print "\tAdvancing fleet %d (rating %d) at system %d (%s) into system %d (%s) with threat %d because of sufficient empire fleet strength already at destination" % (
self.fleet.id, fleet_rating, system_id, sys1_name, self.target.id, target_system_name, threat)
return True
elif threat == p_threat and not self.fleet.get_object().aggressive and not my_other_fleet_rating and not target_sys_status.get('localEnemyFleetIDs', [-1]):
if verbose:
print ("\tAdvancing fleet %d (rating %d) at system %d (%s) into system %d (%s) with planet threat %d because nonaggressive" +
" and no other fleets present to trigger combat") % (self.fleet.id, fleet_rating, system_id, sys1_name, self.target.id, target_system_name, threat)
return True
else:
if verbose:
print "\tHolding fleet %d (rating %d) at system %d (%s) before travelling to system %d (%s) with threat %d" % (self.fleet.id, fleet_rating, system_id, sys1_name, self.target.id, target_system_name, threat)
needs_vis = foAI.foAIstate.misc.setdefault('needs_vis', [])
if self.target.id not in needs_vis:
needs_vis.append(self.target.id)
return False
return True
示例2: merge_fleet_a_into_b
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def merge_fleet_a_into_b(fleet_a_id, fleet_b_id, leave_rating=0, need_rating=0, context=""):
universe = fo.getUniverse()
fleet_a = universe.getFleet(fleet_a_id)
fleet_b = universe.getFleet(fleet_b_id)
if not fleet_a or not fleet_b:
return 0
system_id = fleet_a.systemID
if fleet_b.systemID != system_id:
return 0
remaining_rating = CombatRatingsAI.get_fleet_rating(fleet_a_id)
transferred_rating = 0
for ship_id in fleet_a.shipIDs:
this_ship = universe.getShip(ship_id)
if not this_ship:
continue
this_rating = CombatRatingsAI.ShipCombatStats(ship_id).get_rating()
remaining_rating = CombatRatingsAI.rating_needed(remaining_rating, this_rating)
if remaining_rating < leave_rating: # merging this would leave old fleet under minimum rating, try other ships.
continue
transferred = fo.issueFleetTransferOrder(ship_id, fleet_b_id)
if transferred:
transferred_rating = CombatRatingsAI.combine_ratings(transferred_rating, this_rating)
else:
print " *** transfer of ship %4d, formerly of fleet %4d, into fleet %4d failed; %s" % (
ship_id, fleet_a_id, fleet_b_id, (" context is %s" % context) if context else "")
if need_rating != 0 and need_rating <= transferred_rating:
break
fleet_a = universe.getFleet(fleet_a_id)
if not fleet_a or fleet_a.empty or fleet_a_id in universe.destroyedObjectIDs(fo.empireID()):
foAI.foAIstate.delete_fleet_info(fleet_a_id)
foAI.foAIstate.update_fleet_rating(fleet_b_id)
示例3: _portion_of_fleet_needed_here
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def _portion_of_fleet_needed_here(self):
"""Calculate the portion of the fleet needed in target system considering enemy forces."""
# TODO check rating against planets
if assertion_fails(self.type in COMBAT_MISSION_TYPES, msg=str(self)):
return 0
if assertion_fails(self.target and self.target.id != INVALID_ID, msg=str(self)):
return 0
system_id = self.target.id
aistate = get_aistate()
local_defenses = MilitaryAI.get_my_defense_rating_in_system(system_id)
potential_threat = CombatRatingsAI.combine_ratings(
MilitaryAI.get_system_local_threat(system_id),
MilitaryAI.get_system_neighbor_threat(system_id)
)
universe = fo.getUniverse()
system = universe.getSystem(system_id)
# tally planetary defenses
total_defense = total_shields = 0
for planet_id in system.planetIDs:
planet = universe.getPlanet(planet_id)
total_defense += planet.currentMeterValue(fo.meterType.defense)
total_shields += planet.currentMeterValue(fo.meterType.shield)
planetary_ratings = total_defense * (total_shields + total_defense)
potential_threat += planetary_ratings # TODO: rewrite to return min rating vs planets as well
# consider safety factor just once here rather than everywhere below
safety_factor = aistate.character.military_safety_factor()
potential_threat *= safety_factor
fleet_rating = CombatRatingsAI.get_fleet_rating(self.fleet.id)
return CombatRatingsAI.rating_needed(potential_threat, local_defenses) / float(fleet_rating)
示例4: get_tot_mil_rating
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def get_tot_mil_rating():
"""
Give an assessment of total miltary rating considering all fleets as if distributed to separate systems.
:return: a military rating value
:rtype: float
"""
return sum(CombatRatingsAI.get_fleet_rating(fleet_id)
for fleet_id in FleetUtilsAI.get_empire_fleet_ids_by_role(MissionType.MILITARY))
示例5: __str__
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def __str__(self):
fleet = self.fleet.get_object()
fleet_id = self.fleet.id
return "%-25s [%-11s] ships: %2d; total rating: %4d; target: %s" % (fleet,
"NONE" if self.type is None else self.type,
(fleet and len(fleet.shipIDs)) or 0,
CombatRatingsAI.get_fleet_rating(fleet_id),
self.target or 'no target')
示例6: get_concentrated_tot_mil_rating
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def get_concentrated_tot_mil_rating():
"""
Give an assessment of total miltary rating as if all fleets were merged into a single mega-fleet.
:return: a military rating value
:rtype: float
"""
return CombatRatingsAI.combine_ratings_list([CombatRatingsAI.get_fleet_rating(fleet_id) for fleet_id in
FleetUtilsAI.get_empire_fleet_ids_by_role(MissionType.MILITARY)])
示例7: get_rating
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def get_rating(self, fleet_id, force_new=False, enemy_stats=None):
"""Returns a dict with various rating info."""
if fleet_id in self.fleetStatus and not force_new and enemy_stats is None:
return self.fleetStatus[fleet_id].get('rating', 0)
else:
fleet = fo.getUniverse().getFleet(fleet_id)
if not fleet:
return {} # TODO: also ensure any info for that fleet is deleted
status = {'rating': CombatRatingsAI.get_fleet_rating(fleet_id, enemy_stats), # TODO
'sysID': fleet.systemID, 'nships': len(fleet.shipIDs)}
self.fleetStatus[fleet_id] = status
return status['rating']
示例8: __report_last_turn_fleet_missions
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def __report_last_turn_fleet_missions(self):
"""Print a table reviewing last turn fleet missions to the log file."""
universe = fo.getUniverse()
mission_table = Table(
[Text('Fleet'), Text('Mission'), Text('Ships'), Float('Rating'), Float('Troops'), Text('Target')],
table_name="Turn %d: Fleet Mission Review from Last Turn" % fo.currentTurn())
for fleet_id, mission in self.get_fleet_missions_map().items():
fleet = universe.getFleet(fleet_id)
if not fleet:
continue
if not mission:
mission_table.add_row([fleet])
else:
mission_table.add_row([
fleet,
mission.type or "None",
len(fleet.shipIDs),
CombatRatingsAI.get_fleet_rating(fleet_id),
FleetUtilsAI.count_troops_in_fleet(fleet_id),
mission.target or "-"
])
info(mission_table)
示例9: split_new_fleets
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def split_new_fleets(self):
"""Split any new fleets (at new game creation, can have unplanned mix of ship roles)."""
universe = fo.getUniverse()
mission_table = Table([Text('Fleet'), Text('Mission'), Text('Ships'), Float('Rating'), Float('Troops'), Text('Target')],
table_name="Turn %d: Fleet Mission Review from Last Turn" % fo.currentTurn())
for fleet_id, mission in self.get_fleet_missions_map().items():
fleet = universe.getFleet(fleet_id)
if not fleet:
continue
if not mission:
mission_table.add_row([fleet])
else:
mission_table.add_row([
fleet,
mission.type or "None",
len(fleet.shipIDs),
CombatRatingsAI.get_fleet_rating(fleet_id),
FleetUtilsAI.count_troops_in_fleet(fleet_id),
mission.target or "-"
])
mission_table.print_table()
# TODO: check length of fleets for losses or do in AIstat.__cleanRoles
known_fleets = self.get_fleet_roles_map()
self.newlySplitFleets.clear()
fleets_to_split = [fleet_id for fleet_id in FleetUtilsAI.get_empire_fleet_ids() if fleet_id not in known_fleets]
if fleets_to_split:
print "Splitting new fleets"
for fleet_id in fleets_to_split:
fleet = universe.getFleet(fleet_id)
if not fleet:
print >> sys.stderr, "After splitting fleet: resulting fleet ID %d appears to not exist" % fleet_id
continue
fleet_len = len(list(fleet.shipIDs))
if fleet_len == 1:
continue
new_fleets = FleetUtilsAI.split_fleet(fleet_id) # try splitting fleet
print "\t from splitting fleet ID %4d with %d ships, got %d new fleets:" % (fleet_id, fleet_len, len(new_fleets))
示例10: merge_fleet_a_into_b
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def merge_fleet_a_into_b(fleet_a_id, fleet_b_id, leave_rating=0, need_rating=0, context=""):
universe = fo.getUniverse()
fleet_a = universe.getFleet(fleet_a_id)
fleet_b = universe.getFleet(fleet_b_id)
if not fleet_a or not fleet_b:
return 0
remaining_rating = CombatRatingsAI.get_fleet_rating(fleet_a_id)
transferred_rating = 0
b_has_monster = False
for ship_id in fleet_b.shipIDs:
this_ship = universe.getShip(ship_id)
if not this_ship:
continue
if this_ship.isMonster:
b_has_monster = True
break
for ship_id in fleet_a.shipIDs:
this_ship = universe.getShip(ship_id)
if not this_ship or this_ship.isMonster != b_has_monster: # TODO Is there any reason for the monster check?
continue
this_rating = CombatRatingsAI.ShipCombatStats(ship_id).get_rating()
remaining_rating = CombatRatingsAI.rating_needed(remaining_rating, this_rating)
if remaining_rating < leave_rating: # merging this would leave old fleet under minimum rating, try other ships.
continue
transferred = fo.issueFleetTransferOrder(ship_id, fleet_b_id)
if transferred:
transferred_rating = CombatRatingsAI.combine_ratings(transferred_rating, this_rating)
else:
print " *** transfer of ship %4d, formerly of fleet %4d, into fleet %4d failed; %s" % (
ship_id, fleet_a_id, fleet_b_id, [" context is %s" % context, ""][context == ""])
if need_rating != 0 and need_rating <= transferred_rating:
break
fleet_a = universe.getFleet(fleet_a_id)
if not fleet_a or fleet_a.empty or fleet_a_id in universe.destroyedObjectIDs(fo.empireID()):
foAI.foAIstate.delete_fleet_info(fleet_a_id)
foAI.foAIstate.update_fleet_rating(fleet_b_id)
示例11: update_system_status
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def update_system_status(self):
print 10 * "=", "Updating System Threats", 10 * "="
universe = fo.getUniverse()
empire = fo.getEmpire()
empire_id = fo.empireID()
destroyed_object_ids = universe.destroyedObjectIDs(empire_id)
supply_unobstructed_systems = set(empire.supplyUnobstructedSystems)
min_hidden_attack = 4
min_hidden_health = 8
system_id_list = universe.systemIDs # will normally look at this, the list of all known systems
# for use in debugging
verbose = False
# assess enemy fleets that may have been momentarily visible
cur_e_fighters = {CombatRatingsAI.default_ship_stats().get_stats(hashable=True): [0]} # start with a dummy entry
old_e_fighters = {CombatRatingsAI.default_ship_stats().get_stats(hashable=True): [0]} # start with a dummy entry
enemy_fleet_ids = []
enemies_by_system = {}
my_fleets_by_system = {}
fleet_spot_position = {}
saw_enemies_at_system = {}
my_milship_rating = MilitaryAI.cur_best_mil_ship_rating()
current_turn = fo.currentTurn()
for fleet_id in universe.fleetIDs:
fleet = universe.getFleet(fleet_id)
if fleet is None:
continue
if not fleet.empty:
# TODO: check if currently in system and blockaded before accepting destination as location
this_system_id = (fleet.nextSystemID != INVALID_ID and fleet.nextSystemID) or fleet.systemID
if fleet.ownedBy(empire_id):
if fleet_id not in destroyed_object_ids:
my_fleets_by_system.setdefault(this_system_id, []).append(fleet_id)
fleet_spot_position.setdefault(fleet.systemID, []).append(fleet_id)
else:
dead_fleet = fleet_id in destroyed_object_ids
if not fleet.ownedBy(-1) and (fleet.hasArmedShips or fleet.hasFighterShips):
ship_stats = CombatRatingsAI.FleetCombatStats(fleet_id).get_ship_stats(hashable=True)
e_f_dict = [cur_e_fighters, old_e_fighters][dead_fleet] # track old/dead enemy fighters for rating assessments in case not enough current info
for stats in ship_stats:
attacks = stats[0]
if attacks:
e_f_dict.setdefault(stats, [0])[0] += 1
partial_vis_turn = universe.getVisibilityTurnsMap(fleet_id, empire_id).get(fo.visibility.partial, -9999)
if not dead_fleet:
# TODO: consider checking death of individual ships. If ships had been moved from this fleet
# into another fleet, we might have witnessed their death in that other fleet but if this fleet
# had not been seen since before that transfer then the ships might also still be listed here.
sys_status = self.systemStatus.setdefault(this_system_id, {})
sys_status['enemy_ship_count'] = sys_status.get('enemy_ship_count', 0) + len(fleet.shipIDs)
if partial_vis_turn >= current_turn - 1: # only interested in immediately recent data
saw_enemies_at_system[fleet.systemID] = True
enemy_fleet_ids.append(fleet_id)
enemies_by_system.setdefault(this_system_id, []).append(fleet_id)
if not fleet.ownedBy(-1):
self.misc.setdefault('enemies_sighted', {}).setdefault(current_turn, []).append(fleet_id)
rating = CombatRatingsAI.get_fleet_rating(fleet_id, enemy_stats=CombatRatingsAI.get_empire_standard_fighter())
if rating > 0.25 * my_milship_rating:
self.misc.setdefault('dangerous_enemies_sighted', {}).setdefault(current_turn, []).append(fleet_id)
e_f_dict = [cur_e_fighters, old_e_fighters][len(cur_e_fighters) == 1]
std_fighter = sorted([(v, k) for k, v in e_f_dict.items()])[-1][1]
self.__empire_standard_enemy = std_fighter
self.empire_standard_enemy_rating = self.get_standard_enemy().get_rating()
# TODO: If no current information available, rate against own fighters
# assess fleet and planet threats & my local fleets
for sys_id in system_id_list:
sys_status = self.systemStatus.setdefault(sys_id, {})
system = universe.getSystem(sys_id)
if verbose:
print "AIState threat evaluation for %s" % system
# update fleets
sys_status['myfleets'] = my_fleets_by_system.get(sys_id, [])
sys_status['myFleetsAccessible'] = fleet_spot_position.get(sys_id, [])
local_enemy_fleet_ids = enemies_by_system.get(sys_id, [])
sys_status['localEnemyFleetIDs'] = local_enemy_fleet_ids
if system:
sys_status['name'] = system.name
for fid in system.fleetIDs:
if fid in destroyed_object_ids: # TODO: double check are these checks/deletes necessary?
self.delete_fleet_info(fid) # this is safe even if fleet wasn't mine
continue
fleet = universe.getFleet(fid)
if not fleet or fleet.empty:
self.delete_fleet_info(fid) # this is safe even if fleet wasn't mine
continue
# update threats
sys_vis_dict = universe.getVisibilityTurnsMap(sys_id, fo.empireID())
partial_vis_turn = sys_vis_dict.get(fo.visibility.partial, -9999)
mob_ratings = [] # for mobile unowned monster fleets
lost_fleet_rating = 0
enemy_ratings = []
monster_ratings = []
mobile_fleets = []
for fid in local_enemy_fleet_ids:
fleet = universe.getFleet(fid)
if not fleet:
continue
#.........这里部分代码省略.........
示例12: issue_fleet_orders
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
#.........这里部分代码省略.........
debug("Check if PROTECT_REGION mission with target %d is finished.", last_sys_target)
fleet_id = self.fleet.id
if clear_all:
if orders:
debug("Fleet %d has completed its mission; clearing all orders and targets." % self.fleet.id)
debug("Full set of orders were:")
for this_order in orders:
debug("\t\t %s" % this_order)
self.clear_fleet_orders()
self.clear_target()
if aistate.get_fleet_role(fleet_id) in (MissionType.MILITARY, MissionType.SECURE):
allocations = MilitaryAI.get_military_fleets(mil_fleets_ids=[fleet_id],
try_reset=False,
thisround="Fleet %d Reassignment" % fleet_id)
if allocations:
MilitaryAI.assign_military_fleets_to_systems(use_fleet_id_list=[fleet_id],
allocations=allocations)
else: # no orders
debug("No Current Orders")
else:
potential_threat = CombatRatingsAI.combine_ratings(
MilitaryAI.get_system_local_threat(last_sys_target),
MilitaryAI.get_system_neighbor_threat(last_sys_target)
)
threat_present = potential_threat > 0
debug("Fleet threat present? %s", threat_present)
target_system = universe.getSystem(last_sys_target)
if not threat_present and target_system:
for pid in target_system.planetIDs:
planet = universe.getPlanet(pid)
if (planet and
planet.owner != fo.empireID() and
planet.currentMeterValue(fo.meterType.maxDefense) > 0):
debug("Found local planetary threat: %s", planet)
threat_present = True
break
if not threat_present:
debug("No current threat in target system; releasing a portion of ships.")
# at least first stage of current task is done;
# release extra ships for potential other deployments
new_fleets = FleetUtilsAI.split_fleet(self.fleet.id)
if self.type == MissionType.PROTECT_REGION:
self.clear_fleet_orders()
self.clear_target()
new_fleets.append(self.fleet.id)
else:
debug("Threat remains in target system; Considering to release some ships.")
new_fleets = []
fleet_portion_to_remain = self._portion_of_fleet_needed_here()
if fleet_portion_to_remain > 1:
debug("Can not release fleet yet due to large threat.")
elif fleet_portion_to_remain > 0:
debug("Not all ships are needed here - considering releasing a few")
fleet_remaining_rating = CombatRatingsAI.get_fleet_rating(fleet_id)
fleet_min_rating = fleet_portion_to_remain * fleet_remaining_rating
debug("Starting rating: %.1f, Target rating: %.1f",
fleet_remaining_rating, fleet_min_rating)
allowance = CombatRatingsAI.rating_needed(fleet_remaining_rating, fleet_min_rating)
debug("May release ships with total rating of %.1f", allowance)
ship_ids = list(self.fleet.get_object().shipIDs)
for ship_id in ship_ids:
ship_rating = CombatRatingsAI.get_ship_rating(ship_id)
debug("Considering to release ship %d with rating %.1f", ship_id, ship_rating)
if ship_rating > allowance:
debug("Remaining rating insufficient. Not released.")
continue
debug("Splitting from fleet.")
new_fleet_id = FleetUtilsAI.split_ship_from_fleet(fleet_id, ship_id)
if assertion_fails(new_fleet_id and new_fleet_id != INVALID_ID):
break
new_fleets.append(new_fleet_id)
fleet_remaining_rating = CombatRatingsAI.rating_difference(
fleet_remaining_rating, ship_rating)
allowance = CombatRatingsAI.rating_difference(
fleet_remaining_rating, fleet_min_rating)
debug("Remaining fleet rating: %.1f - Allowance: %.1f",
fleet_remaining_rating, allowance)
if new_fleets:
aistate.get_fleet_role(fleet_id, force_new=True)
aistate.update_fleet_rating(fleet_id)
aistate.ensure_have_fleet_missions(new_fleets)
else:
debug("Planetary defenses are deemed sufficient. Release fleet.")
new_fleets = FleetUtilsAI.split_fleet(self.fleet.id)
new_military_fleets = []
for fleet_id in new_fleets:
if aistate.get_fleet_role(fleet_id) in COMBAT_MISSION_TYPES:
new_military_fleets.append(fleet_id)
allocations = []
if new_military_fleets:
allocations = MilitaryAI.get_military_fleets(
mil_fleets_ids=new_military_fleets,
try_reset=False,
thisround="Fleet Reassignment %s" % new_military_fleets
)
if allocations:
MilitaryAI.assign_military_fleets_to_systems(use_fleet_id_list=new_military_fleets,
allocations=allocations)
示例13: check_mergers
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def check_mergers(self, context=""):
"""
If possible and reasonable, merge this fleet with others.
:param context: Context of the function call for logging purposes
:type context: str
"""
if self.type not in MERGEABLE_MISSION_TYPES:
return
universe = fo.getUniverse()
empire_id = fo.empireID()
fleet_id = self.fleet.id
main_fleet = universe.getFleet(fleet_id)
system_id = main_fleet.systemID
if system_id == INVALID_ID:
return # can't merge fleets in middle of starlane
system_status = foAI.foAIstate.systemStatus[system_id]
destroyed_list = list(universe.destroyedObjectIDs(empire_id))
other_fleets_here = [fid for fid in system_status.get('myFleetsAccessible', []) if fid != fleet_id and
fid not in destroyed_list and universe.getFleet(fid).ownedBy(empire_id)]
if not other_fleets_here:
return
target_id = self.target.id if self.target else None
main_fleet_role = foAI.foAIstate.get_fleet_role(fleet_id)
for fid in other_fleets_here:
fleet_role = foAI.foAIstate.get_fleet_role(fid)
if fleet_role not in COMPATIBLE_ROLES_MAP[main_fleet_role]:
continue
fleet = universe.getFleet(fid)
if not fleet or fleet.systemID != system_id or len(fleet.shipIDs) == 0:
continue
if not (fleet.speed > 0 or main_fleet.speed == 0): # TODO(Cjkjvfnby) Check this condition
continue
fleet_mission = foAI.foAIstate.get_fleet_mission(fid)
do_merge = False
need_left = 0
if (main_fleet_role == MissionType.ORBITAL_DEFENSE) or (fleet_role == MissionType.ORBITAL_DEFENSE):
if main_fleet_role == fleet_role:
do_merge = True
elif (main_fleet_role == MissionType.ORBITAL_INVASION) or (fleet_role == MissionType.ORBITAL_INVASION):
if main_fleet_role == fleet_role:
do_merge = False # TODO: could allow merger if both orb invaders and both same target
elif not fleet_mission and (main_fleet.speed > 0) and (fleet.speed > 0):
do_merge = True
else:
if not self.target and (main_fleet.speed > 0 or fleet.speed == 0):
do_merge = True
else:
target = fleet_mission.target.id if fleet_mission.target else None
if target == target_id:
print "Military fleet %d has same target as %s fleet %d. Merging." % (fid, fleet_role, fleet_id)
do_merge = True # TODO: should probably ensure that fleetA has aggression on now
elif main_fleet.speed > 0:
neighbors = foAI.foAIstate.systemStatus.get(system_id, {}).get('neighbors', [])
if target == system_id and target_id in neighbors and self.type == MissionType.SECURE:
# consider 'borrowing' for work in neighbor system # TODO check condition
need_left = 1.5 * sum(foAI.foAIstate.systemStatus.get(nid, {}).get('fleetThreat', 0)
for nid in neighbors if nid != target_id)
fleet_rating = CombatRatingsAI.get_fleet_rating(fid)
if need_left < fleet_rating:
do_merge = True
if do_merge:
FleetUtilsAI.merge_fleet_a_into_b(fid, fleet_id, need_left,
context="Order %s of mission %s" % (context, self))
return
示例14: __clean_fleet_roles
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def __clean_fleet_roles(self, just_resumed=False):
"""Removes fleetRoles if a fleet has been lost, and update fleet Ratings."""
universe = fo.getUniverse()
current_empire_fleets = FleetUtilsAI.get_empire_fleet_ids()
self.shipCount = 0
destroyed_object_ids = universe.destroyedObjectIDs(fo.empireID())
fleet_table = Table([
Text('Fleet'), Float('Rating'), Float('Troops'),
Text('Location'), Text('Destination')],
table_name="Fleet Summary Turn %d" % fo.currentTurn()
)
# need to loop over a copy as entries are deleted in loop
for fleet_id in list(self.__fleetRoleByID):
fleet_status = self.fleetStatus.setdefault(fleet_id, {})
rating = CombatRatingsAI.get_fleet_rating(fleet_id, self.get_standard_enemy())
old_sys_id = fleet_status.get('sysID', -2) # TODO: Introduce helper function instead
fleet = universe.getFleet(fleet_id)
if fleet:
sys_id = fleet.systemID
if old_sys_id in [-2, -1]:
old_sys_id = sys_id
fleet_status['nships'] = len(fleet.shipIDs) # TODO: Introduce helper function instead
self.shipCount += fleet_status['nships']
else:
# can still retrieve a fleet object even if fleet was just destroyed, so shouldn't get here
# however,this has been observed happening, and is the reason a fleet check was added a few lines below.
# Not at all sure how this came about, but was throwing off threat assessments
sys_id = old_sys_id
# check if fleet is destroyed and if so, delete stored information
if fleet_id not in current_empire_fleets: # or fleet.empty:
# TODO(Morlic): Is this condition really correct? Seems like should actually be in destroyed object ids
if (fleet and self.__fleetRoleByID.get(fleet_id, -1) != -1 and
fleet_id not in destroyed_object_ids and
any(ship_id not in destroyed_object_ids for ship_id in fleet.shipIDs)):
if not just_resumed:
fleetsLostBySystem.setdefault(old_sys_id, []).append(max(rating, MilitaryAI.MinThreat))
self.delete_fleet_info(fleet_id)
continue
# if reached here, the fleet does still exist
this_sys = universe.getSystem(sys_id)
next_sys = universe.getSystem(fleet.nextSystemID)
fleet_table.add_row([
fleet,
rating,
FleetUtilsAI.count_troops_in_fleet(fleet_id),
this_sys or 'starlane',
next_sys or '-',
])
fleet_status['rating'] = rating
if next_sys:
fleet_status['sysID'] = next_sys.id
elif this_sys:
fleet_status['sysID'] = this_sys.id
else:
error("Fleet %s has no valid system." % fleet)
info(fleet_table)
# Next string used in charts. Don't modify it!
print "Empire Ship Count: ", self.shipCount
print "Empire standard fighter summary: ", CombatRatingsAI.get_empire_standard_fighter().get_stats()
print "------------------------"
示例15: __update_system_status
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import get_fleet_rating [as 别名]
def __update_system_status(self):
print 10 * "=", "Updating System Threats", 10 * "="
universe = fo.getUniverse()
empire = fo.getEmpire()
empire_id = fo.empireID()
destroyed_object_ids = universe.destroyedObjectIDs(empire_id)
supply_unobstructed_systems = set(empire.supplyUnobstructedSystems)
min_hidden_attack = 4
min_hidden_health = 8
observed_empires = self.misc.setdefault("observed_empires", set())
# TODO: Variables that are recalculated each turn from scratch should not be stored in AIstate
# clear previous game state
for sys_id in self.systemStatus:
self.systemStatus[sys_id]['enemy_ship_count'] = 0
self.systemStatus[sys_id]['myFleetRating'] = 0
self.systemStatus[sys_id]['myFleetRatingVsPlanets'] = 0
# for use in debugging
verbose = False
# assess enemy fleets that may have been momentarily visible
enemies_by_system = {}
my_fleets_by_system = {}
fleet_spot_position = {}
current_turn = fo.currentTurn()
for fleet_id in universe.fleetIDs:
fleet = universe.getFleet(fleet_id)
if not fleet or fleet.empty:
self.delete_fleet_info(fleet_id) # this is safe even if fleet wasn't mine
continue
# TODO: check if currently in system and blockaded before accepting destination as location
this_system_id = fleet.nextSystemID if fleet.nextSystemID != INVALID_ID else fleet.systemID
dead_fleet = fleet_id in destroyed_object_ids
if dead_fleet:
self.delete_fleet_info(fleet_id)
if fleet.ownedBy(empire_id):
if not dead_fleet:
my_fleets_by_system.setdefault(this_system_id, []).append(fleet_id)
fleet_spot_position.setdefault(fleet.systemID, []).append(fleet_id)
continue
# TODO: consider checking death of individual ships. If ships had been moved from this fleet
# into another fleet, we might have witnessed their death in that other fleet but if this fleet
# had not been seen since before that transfer then the ships might also still be listed here.
if dead_fleet:
continue
# we are only interested in immediately recent data
if get_partial_visibility_turn(fleet_id) < (current_turn - 1):
continue
sys_status = self.systemStatus.setdefault(this_system_id, {})
sys_status['enemy_ship_count'] = sys_status.get('enemy_ship_count', 0) + len(fleet.shipIDs)
enemies_by_system.setdefault(this_system_id, []).append(fleet_id)
if not fleet.unowned:
self.misc.setdefault('enemies_sighted', {}).setdefault(current_turn, []).append(fleet_id)
observed_empires.add(fleet.owner)
# assess fleet and planet threats & my local fleets
for sys_id in universe.systemIDs:
sys_status = self.systemStatus.setdefault(sys_id, {})
system = universe.getSystem(sys_id)
if verbose:
print "AIState threat evaluation for %s" % system
# update fleets
sys_status['myfleets'] = my_fleets_by_system.get(sys_id, [])
sys_status['myFleetsAccessible'] = fleet_spot_position.get(sys_id, [])
local_enemy_fleet_ids = enemies_by_system.get(sys_id, [])
sys_status['localEnemyFleetIDs'] = local_enemy_fleet_ids
if system:
sys_status['name'] = system.name
# update threats
monster_ratings = [] # immobile
enemy_ratings = [] # owned & mobile
mob_ratings = [] # mobile & unowned
mobile_fleets = [] # mobile and either owned or unowned
for fid in local_enemy_fleet_ids:
fleet = universe.getFleet(fid) # ensured to exist
fleet_rating = CombatRatingsAI.get_fleet_rating(
fid, enemy_stats=CombatRatingsAI.get_empire_standard_fighter())
if fleet.speed == 0:
monster_ratings.append(fleet_rating)
if verbose:
print "\t immobile enemy fleet %s has rating %.1f" % (fleet, fleet_rating)
continue
if verbose:
print "\t mobile enemy fleet %s has rating %.1f" % (fleet, fleet_rating)
mobile_fleets.append(fid)
if fleet.unowned:
mob_ratings.append(fleet_rating)
else:
enemy_ratings.append(fleet_rating)
enemy_rating = CombatRatingsAI.combine_ratings_list(enemy_ratings)
monster_rating = CombatRatingsAI.combine_ratings_list(monster_ratings)
#.........这里部分代码省略.........