本文整理汇总了Python中MilitaryAI.get_preferred_max_military_portion_for_single_battle方法的典型用法代码示例。如果您正苦于以下问题:Python MilitaryAI.get_preferred_max_military_portion_for_single_battle方法的具体用法?Python MilitaryAI.get_preferred_max_military_portion_for_single_battle怎么用?Python MilitaryAI.get_preferred_max_military_portion_for_single_battle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MilitaryAI
的用法示例。
在下文中一共展示了MilitaryAI.get_preferred_max_military_portion_for_single_battle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evaluate_invasion_planet
# 需要导入模块: import MilitaryAI [as 别名]
# 或者: from MilitaryAI import get_preferred_max_military_portion_for_single_battle [as 别名]
#.........这里部分代码省略.........
max_path_threat = system_fleet_treat
mil_ship_rating = MilitaryAI.cur_best_mil_ship_rating()
for path_sys_id in least_jumps_path:
path_leg_status = aistate.systemStatus.get(path_sys_id, {})
path_leg_threat = path_leg_status.get('fleetThreat', 1000) + path_leg_status.get('monsterThreat', 0)
if path_leg_threat > 0.5 * mil_ship_rating:
clear_path = False
if path_leg_threat > max_path_threat:
max_path_threat = path_leg_threat
pop = planet.currentMeterValue(fo.meterType.population)
target_pop = planet.currentMeterValue(fo.meterType.targetPopulation)
troops = planet.currentMeterValue(fo.meterType.troops)
troop_regen = planet.currentMeterValue(fo.meterType.troops) - planet.initialMeterValue(fo.meterType.troops)
max_troops = planet.currentMeterValue(fo.meterType.maxTroops)
# TODO: refactor troop determination into function for use in mid-mission updates and also consider defender techs
max_troops += AIDependencies.TROOPS_PER_POP * (target_pop - pop)
this_system = universe.getSystem(system_id)
secure_targets = [system_id] + list(this_system.planetIDs)
system_secured = False
for mission in secure_fleet_missions:
if system_secured:
break
secure_fleet_id = mission.fleet.id
s_fleet = universe.getFleet(secure_fleet_id)
if not s_fleet or s_fleet.systemID != system_id:
continue
if mission.type in [MissionType.SECURE, MissionType.MILITARY]:
target_obj = mission.target.get_object()
if target_obj is not None and target_obj.id in secure_targets:
system_secured = True
break
system_secured = system_secured and system_status.get('myFleetRating', 0)
if verbose:
debug("Invasion eval of %s\n"
" - maxShields: %.1f\n"
" - sysFleetThreat: %.1f\n"
" - sysMonsterThreat: %.1f",
planet, planet.currentMeterValue(fo.meterType.maxShield), system_fleet_treat, system_monster_threat)
enemy_val = 0
if planet.owner != -1: # value in taking this away from an enemy
enemy_val = 20 * (planet.currentMeterValue(fo.meterType.targetIndustry) +
2*planet.currentMeterValue(fo.meterType.targetResearch))
# devalue invasions that would require too much military force
preferred_max_portion = MilitaryAI.get_preferred_max_military_portion_for_single_battle()
total_max_mil_rating = MilitaryAI.get_concentrated_tot_mil_rating()
threat_exponent = 2 # TODO: make this a character trait; higher aggression with a lower exponent
threat_factor = min(1, preferred_max_portion * total_max_mil_rating/(sys_total_threat+0.001))**threat_exponent
design_id, _, locs = ProductionAI.get_best_ship_info(PriorityType.PRODUCTION_INVASION)
if not locs or not universe.getPlanet(locs[0]):
# We are in trouble anyway, so just calculate whatever approximation...
build_time = 4
planned_troops = troops if system_secured else min(troops + troop_regen*(max_jumps + build_time), max_troops)
planned_troops += .01 # we must attack with more troops than there are defenders
troop_cost = math.ceil((planned_troops+_TROOPS_SAFETY_MARGIN) / 6.0) * 20 * FleetUtilsAI.get_fleet_upkeep()
else:
loc = locs[0]
species_here = universe.getPlanet(loc).speciesName
design = fo.getShipDesign(design_id)
cost_per_ship = design.productionCost(empire_id, loc)
build_time = design.productionTime(empire_id, loc)
troops_per_ship = CombatRatingsAI.weight_attack_troops(design.troopCapacity,
CombatRatingsAI.get_species_troops_grade(species_here))
planned_troops = troops if system_secured else min(troops + troop_regen*(max_jumps + build_time), max_troops)
planned_troops += .01 # we must attack with more troops than there are defenders
ships_needed = math.ceil((planned_troops+_TROOPS_SAFETY_MARGIN) / float(troops_per_ship))
troop_cost = ships_needed * cost_per_ship # fleet upkeep is already included in query from server
# apply some bias to expensive operations
normalized_cost = float(troop_cost) / max(fo.getEmpire().productionPoints, 1)
normalized_cost = max(1., normalized_cost)
cost_score = (normalized_cost**2 / 50.0) * troop_cost
base_score = colony_base_value + bld_tally + tech_tally + enemy_val - cost_score
# If the AI does have enough total miltary to attack this target, and the target is more than minimally valuable,
# don't let the threat_factor discount the adjusted value below MIN_INVASION_SCORE +1, so that if there are no
# other targets the AI could still pursue this one. Otherwise, scoring pressure from
# MilitaryAI.get_preferred_max_military_portion_for_single_battle might prevent the AI from attacking heavily
# defended but still defeatable targets even if it has no softer targets available.
if total_max_mil_rating > sys_total_threat and base_score > 2 * MIN_INVASION_SCORE:
threat_factor = max(threat_factor, (MIN_INVASION_SCORE + 1)/base_score)
planet_score = retaliation_risk_factor(planet.owner) * threat_factor * max(0, base_score)
if clear_path:
planet_score *= 1.5
if verbose:
debug(' - planet score: %.2f\n'
' - planned troops: %.2f\n'
' - projected troop cost: %.1f\n'
' - threat factor: %s\n'
' - planet detail: %s\n'
' - popval: %.1f\n'
' - bldval: %s\n'
' - enemyval: %s',
planet_score, planned_troops, troop_cost, threat_factor, detail, colony_base_value, bld_tally, enemy_val)
debug(' - system secured: %s' % system_secured)
return [planet_score, planned_troops]