Seperated battle finding logic from CitizenMilitary.find_battle_and_fight method
This commit is contained in:
parent
b88e7973e8
commit
b338ea598a
@ -1673,9 +1673,8 @@ class CitizenMilitary(CitizenTravel):
|
||||
def has_battle_contribution(self):
|
||||
return bool(self.__last_war_update_data.get("citizen_contribution", []))
|
||||
|
||||
def find_battle_and_fight(self):
|
||||
if self.should_fight()[0]:
|
||||
self.write_log("Checking for battles to fight in...")
|
||||
def find_battle_to_fight(self, silent: bool = False) -> Tuple[classes.Battle, classes.BattleDivision, classes.BattleSide]:
|
||||
self.update_war_info()
|
||||
for battle in self.sorted_battles(self.config.sort_battles_time):
|
||||
if not isinstance(battle, classes.Battle):
|
||||
continue
|
||||
@ -1687,7 +1686,7 @@ class CitizenMilitary(CitizenTravel):
|
||||
if self.config.air and div.is_air:
|
||||
battle_zone = div
|
||||
break
|
||||
elif self.config.ground and not div.is_air and (div.div == self.division or self.maverick):
|
||||
elif self.config.ground and not div.is_air and (div.div == self.division or (self.maverick and self.config.maverick)):
|
||||
battle_zone = div
|
||||
break
|
||||
else:
|
||||
@ -1705,6 +1704,7 @@ class CitizenMilitary(CitizenTravel):
|
||||
defender_side = self.details.current_country in battle.defender.allies + [battle.defender.country, ]
|
||||
side = battle.defender if defender_side else battle.invader
|
||||
|
||||
if not silent:
|
||||
self.write_log(battle)
|
||||
|
||||
travel = (self.config.travel_to_fight and self.should_travel_to_fight() or self.config.force_travel) \
|
||||
@ -1712,6 +1712,17 @@ class CitizenMilitary(CitizenTravel):
|
||||
|
||||
if not travel:
|
||||
continue
|
||||
yield battle, battle_zone, side
|
||||
|
||||
def find_battle_and_fight(self):
|
||||
if self.should_fight()[0]:
|
||||
self.write_log("Checking for battles to fight in...")
|
||||
for battle, division, side in self.find_battle_to_fight():
|
||||
|
||||
allies = battle.invader.deployed + battle.defender.deployed + [battle.invader.country,
|
||||
battle.defender.country]
|
||||
|
||||
travel_needed = self.details.current_country not in allies
|
||||
|
||||
if battle.start > self.now:
|
||||
self.sleep(utils.get_sleep_seconds(battle.start))
|
||||
@ -1728,9 +1739,9 @@ class CitizenMilitary(CitizenTravel):
|
||||
|
||||
if not self.travel_to_battle(battle, countries_to_travel):
|
||||
break
|
||||
if self.change_division(battle, battle_zone):
|
||||
self.set_default_weapon(battle, battle_zone)
|
||||
self.fight(battle, battle_zone, side)
|
||||
if self.change_division(battle, division):
|
||||
self.set_default_weapon(battle, division)
|
||||
self.fight(battle, division, side)
|
||||
self.travel_to_residence()
|
||||
break
|
||||
|
||||
|
@ -719,11 +719,11 @@ class BattleSide:
|
||||
|
||||
def __repr__(self):
|
||||
side_text = "Defender" if self.is_defender else "Invader "
|
||||
return f"<BattleSide: {side_text} {self.country.name}|{self.points:02d}p>"
|
||||
return f"<BattleSide: {side_text} {self.country.name}|{self.points:>2d}p>"
|
||||
|
||||
def __str__(self):
|
||||
side_text = "Defender" if self.is_defender else "Invader "
|
||||
return f"{side_text} {self.country.name} - {self.points:02d} points"
|
||||
return f"{side_text} {self.country.name} - {self.points:>2d} points"
|
||||
|
||||
def __format__(self, format_spec):
|
||||
return self.country.iso
|
||||
@ -789,7 +789,7 @@ class BattleDivision:
|
||||
return constants.TERRAINS[self.terrain]
|
||||
|
||||
def __str__(self):
|
||||
base_name = f"Div #{self.id} d{self.div}"
|
||||
base_name = f"D{self.div} #{self.id}"
|
||||
if self.terrain:
|
||||
base_name += f" ({self.terrain_display})"
|
||||
if self.div_end:
|
||||
@ -899,8 +899,8 @@ class Battle:
|
||||
else:
|
||||
time_part = "-{}".format(self.start - time_now)
|
||||
|
||||
return (f"Battle {self.id} for {self.region_name[:16]} | "
|
||||
f"{self.invader} : {self.defender} | Round time {time_part}")
|
||||
return (f"Battle {self.id} for {self.region_name[:16]:16} | "
|
||||
f"{self.invader} : {self.defender} | Round time {time_part} | {'R'+str(self.zone_id):>3}")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Battle #{self.id} {self.invader}:{self.defender} R{self.zone_id}>"
|
||||
|
Loading…
x
Reference in New Issue
Block a user