本文整理汇总了Python中CombatRatingsAI.rating_needed方法的典型用法代码示例。如果您正苦于以下问题:Python CombatRatingsAI.rating_needed方法的具体用法?Python CombatRatingsAI.rating_needed怎么用?Python CombatRatingsAI.rating_needed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CombatRatingsAI
的用法示例。
在下文中一共展示了CombatRatingsAI.rating_needed方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _portion_of_fleet_needed_here
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import rating_needed [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: merge_fleet_a_into_b
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import rating_needed [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: _maximum_allocation
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import rating_needed [as 别名]
def _maximum_allocation(self, threat):
"""
Calculate the maximum allocation for the system.
The default maximum allocation is the missing forces
to obtain a rating given by the threat weighted with
the subclass' *max_alloc_factor*.
Existing military missions are considered.
Subclasses may choose to override this method and
implement a different logic.
:param float threat:
:rtype: float
"""
return CombatRatingsAI.rating_needed(
self._max_alloc_factor * threat,
self.assigned_rating)
示例4: merge_fleet_a_into_b
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import rating_needed [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)
示例5: issue_fleet_orders
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import rating_needed [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)
示例6: _minimum_allocation
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import rating_needed [as 别名]
def _minimum_allocation(self, threat):
nearby_forces = CombatRatingsAI.combine_ratings(
self.assigned_rating, self._potential_support())
return max(
CombatRatingsAI.rating_needed(self._regional_threat(), nearby_forces),
CombatRatingsAI.rating_needed(1.4*threat, self.assigned_rating))
示例7: _allocation_vs_planets
# 需要导入模块: import CombatRatingsAI [as 别名]
# 或者: from CombatRatingsAI import rating_needed [as 别名]
def _allocation_vs_planets(self):
return CombatRatingsAI.rating_needed(
self.safety_factor*self._planet_threat_multiplier()*self._planet_threat(),
self.assigned_rating_vs_planets)