def run_simulation(att_units, def_units, options, it): outcomes = [0, 0, 0] # Filter units based on ground combat vs space combat if options["ground_combat"]: att_units, def_units = filters.filter_ground(att_units, def_units, options) else: att_units, def_units = filters.filter_space(att_units, def_units, options) att_units, def_units, options = mods_before_combat(att_units, def_units, options) for i in range(it): att_unit_cp = [a.get_copy() for a in att_units] def_unit_cp = [d.get_copy() for d in def_units] res = iteration(att_unit_cp, def_unit_cp, options) # Yin flagship if options["att_faction"] == "Yin" and util.has_flagship( att_units) and res == 2: res = 0 if options["def_faction"] == "Yin" and util.has_flagship( def_units) and res == 1: res = 0 outcomes[res] += 1 return outcomes
def filter_space(att_units, def_units, options): if options["att_faction"] == "Nekro" and util.has_flagship(att_units): att_result = list( filter( lambda x: not x.ground or len(x.cannon) > 0 or x.name == "infantry", att_units)) else: att_result = list( filter(lambda x: not x.ground or len(x.cannon) > 0, att_units)) if options["def_faction"] == "Nekro" and util.has_flagship(def_units): def_result = list( filter( lambda x: not x.ground or len(x.cannon) > 0 or x.name == "infantry", def_units)) else: def_result = list( filter(lambda x: not x.ground or len(x.cannon) > 0, def_units)) return att_result, def_result
def generate_hits(units, faction, bonus, prototype, fire_team, war_funding, war_funding_o, sol_agent, letnev_agent): hits = 0 non_fighter_hits = 0 # Sol agent if sol_agent: units, modified_unit = faction_abilities.apply_sol_agent(units) # Letnev agent if letnev_agent: units, modified_unit = faction_abilities.apply_letnev_agent(units) for u in units: for val in u.combat: x, extra_hits = roll_for_hit(units, u, faction, bonus, prototype) hits += extra_hits if x >= val: # L1Z1X Flagship if faction == "L1Z1X" and util.has_flagship( units) and u.name in ["flagship", "dread"]: non_fighter_hits += 1 else: hits += 1 # Fire Team / War Funding re-roll else: if fire_team: # re-roll if it was a miss, ground combat only (so no prototype, L1 flagship) x = util.roll() x += bonus if x >= val: hits += 1 if war_funding or war_funding_o: # space combat only x, extra_hits = roll_for_hit(units, u, faction, bonus, prototype) hits += extra_hits if x >= val: hits += 1 # Sol agent if sol_agent: # noinspection PyUnboundLocalVariable modified_unit.combat = modified_unit.combat[:-1] # Letnev agent if letnev_agent: modified_unit.combat = modified_unit.combat[:-1] return hits, non_fighter_hits
def filter_ground(att_units, def_units, options): att_res, def_res = [], [] shield = shield_active(att_units, def_units, options) for u in att_units: if u.ground: if shield: u.bombard = [] att_res.append(u) elif u.bombard and not shield: att_res.append(u) for u in def_units: if u.ground or u.cannon: def_res.append(u) # Naalu flagship if options["att_faction"] == "Naalu" and util.has_flagship(att_units): att_res = faction_abilities.naalu_flagship(att_units) + att_res if options["def_faction"] == "Naalu" and util.has_flagship(def_units): def_res = faction_abilities.naalu_flagship(def_units) + def_res return att_res, def_res
def roll_for_hit(units, u, faction, bonus, prototype): x = util.roll() extra_hits = 0 # Jol-Nar flagship if faction == "Jol-Nar" and u.name == "flagship": if x >= 9: extra_hits += 2 # Sardakk flagship if faction == "Sardakk" and util.has_flagship( units) and u.name != "flagship": x += 1 # Morale Boost / Supercharge x += bonus # Prototype Fighter if prototype and u.fighter: x += 2 return x, extra_hits
def mods_before_combat(att_units, def_units, options): # Non-Euclidean Shielding if options["att_letnev_noneuclidean_nekro_hide"]: att_units = tech_abilities.noneuclidean(att_units) if options["def_letnev_noneuclidean_nekro_hide"]: def_units = tech_abilities.noneuclidean(def_units) # Naaz-Rokha flagship if options["att_faction"] == "Naaz-Rokha" and util.has_flagship(att_units): att_units = faction_abilities.naaz_flagship(att_units) if options["def_faction"] == "Naaz-Rokha" and util.has_flagship(def_units): def_units = faction_abilities.naaz_flagship(def_units) # Winnu commander if options["att_winnu_commander"]: att_units = faction_abilities.winnu_commander(att_units) if options["def_winnu_commander"]: def_units = faction_abilities.winnu_commander(def_units) # Antimass Deflectors if options["att_antimass"]: for u in def_units: u.cannon = [x + 1 for x in u.cannon] if options["def_antimass"]: for u in att_units: u.cannon = [x + 1 for x in u.cannon] # Strike Wing Ambuscade if options["att_argent_prom"] or options["def_argent_prom"]: att_units, def_units = faction_abilities.argent_prom( att_units, def_units, options) # Titan agent if options["att_titans_agent"]: att_units = faction_abilities.titans_agent(att_units) if options["def_titans_agent"]: def_units = faction_abilities.titans_agent(def_units) if options["ground_combat"]: # Naalu mech / Nekro mech if options["att_naalu_mech_hide"] or options["att_nekro_mech_hide"]: att_units = faction_abilities.naalu_nekro_mech(att_units) if options["def_naalu_mech_hide"] or options["def_nekro_mech_hide"]: def_units = faction_abilities.naalu_nekro_mech(def_units) # Jol-Nar mech if options["att_faction"] == "Jol-Nar" and util.has_mech(att_units): att_units = faction_abilities.jol_nar_mech(att_units) if options["def_faction"] == "Jol-Nar" and util.has_mech(def_units): def_units = faction_abilities.jol_nar_mech(def_units) # L4 Disruptors if options["att_letnev_l4_nekro_hide"]: for u in def_units: u.cannon = [] # Conventions of War if options["conventions"]: for u in att_units: u.bombard = [] # Tekklar Legion if options["att_tekklar"] or options["def_tekklar"]: att_units, def_units = faction_abilities.tekklar( att_units, def_units, options) # Sol commander if options["def_sol_commander"] and any( map(lambda x: x.ground, def_units)): extra_infantry = [ units.infantry2(options["def_faction"]) if options["def_infantry2"] else units.infantry( options["def_faction"]) ] def_units = extra_infantry + def_units else: # space combat # Mahact flagship if options["att_mahact_flagship_hide"]: att_units = faction_abilities.mahact_flagship(att_units) if options["def_mahact_flagship_hide"]: def_units = faction_abilities.mahact_flagship(def_units) # The Cavalry if options["att_cavalry1"] or options["att_cavalry2"]: att_units = faction_abilities.cavalry( att_units, upgraded=options["att_cavalry2"]) if options["def_cavalry1"] or options["def_cavalry2"]: def_units = faction_abilities.cavalry( def_units, upgraded=options["def_cavalry2"]) # Argent flagship if options["att_faction"] == "Argent" or options[ "def_faction"] == "Argent": att_units, def_units = faction_abilities.argent_flagship( att_units, def_units, options) # Mentak flagship if options["att_faction"] == "Mentak" or options[ "def_faction"] == "Mentak": att_units, def_units = faction_abilities.mentak_flagship( att_units, def_units, options) # Defending in Nebula if options["def_nebula"] and not options["ground_combat"]: for u in def_units: u.combat = [x - 1 for x in u.combat] # Publicize Weapon Schematics if options["publicize"]: for u in att_units + def_units: if u.name == "warsun": u.sustain = False u.can_sustain = False return att_units, def_units, options