本文整理汇总了Python中MilitaryAI.get_system_local_threat方法的典型用法代码示例。如果您正苦于以下问题:Python MilitaryAI.get_system_local_threat方法的具体用法?Python MilitaryAI.get_system_local_threat怎么用?Python MilitaryAI.get_system_local_threat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MilitaryAI
的用法示例。
在下文中一共展示了MilitaryAI.get_system_local_threat方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _portion_of_fleet_needed_here
# 需要导入模块: import MilitaryAI [as 别名]
# 或者: from MilitaryAI import get_system_local_threat [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)
示例2: trooper_move_reqs_met
# 需要导入模块: import MilitaryAI [as 别名]
# 或者: from MilitaryAI import get_system_local_threat [as 别名]
def trooper_move_reqs_met(main_fleet_mission, order, verbose):
"""
Indicates whether or not move requirements specific to invasion troopers are met for the provided mission and order.
:type main_fleet_mission: AIFleetMission.AIFleetMission
:type order: OrderMove
:param verbose: whether to print verbose decision details
:type verbose: bool
:rtype: bool
"""
# Don't advance outside of our fleet-supply zone unless the target either has no shields at all or there
# is already a military fleet assigned to secure the target, and don't take final jump unless the planet is
# (to the AI's knowledge) down to zero shields. Additional checks will also be done by the later
# generic movement code
invasion_target = main_fleet_mission.target
invasion_planet = invasion_target.get_object()
invasion_system = invasion_target.get_system()
supplied_systems = fo.getEmpire().fleetSupplyableSystemIDs
# if about to leave supply lines
if order.target.id not in supplied_systems or fo.getUniverse().jumpDistance(order.fleet.id, invasion_system.id) < 5:
if invasion_planet.currentMeterValue(fo.meterType.maxShield):
military_support_fleets = MilitaryAI.get_military_fleets_with_target_system(invasion_system.id)
if not military_support_fleets:
if verbose:
print ("trooper_move_reqs_met() holding Invasion fleet %d before leaving supply "
"because target (%s) has nonzero max shields and there is not yet a military fleet "
"assigned to secure the target system.") % (order.fleet.id, invasion_planet)
return False
# if there is a threat in the enemy system, do give military ships at least 1 turn to clear it
delay_to_move_troops = 1 if MilitaryAI.get_system_local_threat(order.target.id) else 0
def eta(fleet_id):
return FleetUtilsAI.calculate_estimated_time_of_arrival(fleet_id, invasion_system.id)
eta_this_fleet = eta(order.fleet.id)
if all(((eta_this_fleet - delay_to_move_troops) <= eta(fid) and eta(fid))
for fid in military_support_fleets):
if verbose:
print ("trooper_move_reqs_met() holding Invasion fleet %d before leaving supply "
"because target (%s) has nonzero max shields and no assigned military fleet would arrive"
"at least %d turn earlier than the invasion fleet") % (
order.fleet.id, invasion_planet, delay_to_move_troops)
return False
if verbose:
print ("trooper_move_reqs_met() allowing Invasion fleet %d to leave supply "
"because target (%s) has zero max shields or there is a military fleet assigned to secure "
"the target system which will arrive at least 1 turn before the invasion fleet.") % (order.fleet.id,
invasion_planet)
return True
示例3: check_mergers
# 需要导入模块: import MilitaryAI [as 别名]
# 或者: from MilitaryAI import get_system_local_threat [as 别名]
def check_mergers(self, context=""):
"""
Merge local fleets with same mission into this fleet.
:param context: Context of the function call for logging purposes
:type context: str
"""
debug("Considering to merge %s", self.__str__())
if self.type not in MERGEABLE_MISSION_TYPES:
debug("Mission type does not allow merging.")
return
if not self.target:
debug("Mission has no valid target - do not merge.")
return
universe = fo.getUniverse()
empire_id = fo.empireID()
fleet_id = self.fleet.id
main_fleet = universe.getFleet(fleet_id)
main_fleet_system_id = main_fleet.systemID
if main_fleet_system_id == INVALID_ID:
debug("Can't merge: fleet in middle of starlane.")
return
# only merge PROTECT_REGION if there is any threat near target
if self.type == MissionType.PROTECT_REGION:
neighbor_systems = universe.getImmediateNeighbors(self.target.id, empire_id)
if not any(MilitaryAI.get_system_local_threat(sys_id)
for sys_id in neighbor_systems):
debug("Not merging PROTECT_REGION fleet - no threat nearby.")
return
destroyed_list = set(universe.destroyedObjectIDs(empire_id))
aistate = get_aistate()
system_status = aistate.systemStatus[main_fleet_system_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:
debug("No other fleets here")
return
for fid in other_fleets_here:
fleet_mission = aistate.get_fleet_mission(fid)
if fleet_mission.type != self.type or fleet_mission.target != self.target:
debug("Local candidate %s does not have same mission." % fleet_mission)
continue
FleetUtilsAI.merge_fleet_a_into_b(fid, fleet_id, context="Order %s of mission %s" % (context, self))
示例4: _get_target_for_protection_mission
# 需要导入模块: import MilitaryAI [as 别名]
# 或者: from MilitaryAI import get_system_local_threat [as 别名]
def _get_target_for_protection_mission(self):
"""Get a target for a PROTECT_REGION mission.
1) If primary target (system target of this mission) is under attack, move to primary target.
2) If neighbors of primary target have local enemy forces weaker than this fleet, may move to attack
3) If no neighboring fleets or strongest enemy force is too strong, move to defend primary target
"""
# TODO: Also check fleet rating vs planets in decision making below not only vs fleets
universe = fo.getUniverse()
primary_objective = self.target.id
debug("Trying to find target for protection mission. Target: %s", self.target)
immediate_threat = MilitaryAI.get_system_local_threat(primary_objective)
if immediate_threat:
debug("Immediate threat! Moving to primary mission target")
return primary_objective
else:
debug("No immediate threats.")
# Try to eliminate neighbouring fleets
neighbors = universe.getImmediateNeighbors(primary_objective, fo.empireID())
threat_list = sorted(map(
lambda x: (MilitaryAI.get_system_local_threat(x), x),
neighbors
), reverse=True)
if not threat_list:
debug("No neighbors (?!). Moving to primary mission target")
return primary_objective
debug("%s", threat_list)
top_threat, candidate_system = threat_list[0]
if not top_threat:
# TODO: Move into second ring but needs more careful evaluation
# For now, consider staying at the current location if enemy
# owns a planet here which we can bombard.
current_system_id = self.fleet.get_current_system_id()
if current_system_id in neighbors:
system = universe.getSystem(current_system_id)
if assertion_fails(system is not None):
return primary_objective
empire_id = fo.empireID()
for planet_id in system.planetIDs:
planet = universe.getPlanet(planet_id)
if (planet and
not planet.ownedBy(empire_id) and
not planet.unowned):
debug("Currently no neighboring threats. "
"Staying for bombardment of planet %s", planet)
self.clear_fleet_orders()
self.set_target(MissionType.MILITARY, TargetSystem(current_system_id))
self.generate_fleet_orders()
self.issue_fleet_orders()
return INVALID_ID
# TODO consider attacking neighboring, non-military fleets
# - needs more careful evaluation against neighboring threats
# empire_id = fo.empireID()
# for sys_id in neighbors:
# system = universe.getSystem(sys_id)
# if assertion_fails(system is not None):
# continue
# local_fleets = system.fleetIDs
# for fleet_id in local_fleets:
# fleet = universe.getFleet(fleet_id)
# if not fleet or fleet.ownedBy(empire_id):
# continue
# return sys_id
debug("No neighboring threats. Moving to primary mission target")
return primary_objective
# TODO rate against threat in target system
# TODO only engage if can reach in 1 turn or leaves sufficient defense behind
fleet_rating = CombatRatingsAI.get_fleet_rating(self.fleet.id)
debug("This fleet rating: %d. Enemy Rating: %d", fleet_rating, top_threat)
safety_factor = get_aistate().character.military_safety_factor()
if fleet_rating < safety_factor*top_threat:
debug("Neighboring threat is too powerful. Moving to primary mission target")
return primary_objective # do not engage!
debug("Engaging neighboring threat: %d", candidate_system)
return candidate_system
示例5: issue_fleet_orders
# 需要导入模块: import MilitaryAI [as 别名]
# 或者: from MilitaryAI import get_system_local_threat [as 别名]
#.........这里部分代码省略.........
debug("Fleet %d has completed initial stage of its mission "
"to secure system %d (targeted for %s), "
"may release a portion of ships" % (self.fleet.id, last_sys_target, secure_type))
clear_all = False
# for PROTECT_REGION missions, only release fleet if no more threat
if self.type == MissionType.PROTECT_REGION:
# use military logic code below to determine if can release
# any or even all of the ships.
clear_all = False
last_sys_target = self.target.id
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)