diff --git a/Jobs/ARMY_TRACK.eai b/Jobs/ARMY_TRACK.eai index 408a608b9..6d21d9a75 100644 --- a/Jobs/ARMY_TRACK.eai +++ b/Jobs/ARMY_TRACK.eai @@ -254,6 +254,7 @@ function UpdateTownThreat takes nothing returns nothing local integer i = lastFreeNum local real accepted_threat_level = LinearInterpolation(atl_time_start, atl_time_end, atl_time_start_val, atl_time_end_val, TimerGetElapsed(tq_timer)) * LinearInterpolation(atl_enemy_start, atl_enemy_end, atl_enemy_start_mult, atl_enemy_end_mult, c_enemy_total) local real playerthreat = 0 + local integer enemy_army = -1 if i == 0 then //call Trace("ARMY_TRACK: Town threat update") set most_threatened_town = -1 @@ -282,12 +283,22 @@ function UpdateTownThreat takes nothing returns nothing if town_threat[most_threatened_player_town] > accepted_threat_level and town_threat[most_threatened_player_town] <= playerthreat then //and town_threat[most_threatened_town] > (I2R(c_ally_total + 1) / c_enemy_total) * town_threat[most_threatened_enemy_town] then set town_threatened = true set most_threatened_town = most_threatened_player_town - call SetCaptainHome(BOTH_CAPTAINS, GetLocationX(town_loc[most_threatened_player_town]), GetLocationY(town_loc[most_threatened_player_town])) + set enemy_army = town_threat_army[most_threatened_town] + if enemy_army >= 0 then + call SetCaptainHome(BOTH_CAPTAINS,GetLocationX(army_loc[enemy_army]), GetLocationY(army_loc[enemy_army])) + else + call SetCaptainHome(BOTH_CAPTAINS, GetLocationX(town_loc[most_threatened_player_town]), GetLocationY(town_loc[most_threatened_player_town])) + endif set captain_home = town_loc[most_threatened_player_town] set captain_tp = town_can_tp[most_threatened_player_town] elseif town_threat[most_threatened_town] > accepted_threat_level * 1.2 and town_threat[most_threatened_town] <= playerthreat then set town_threatened = true - call SetCaptainHome(BOTH_CAPTAINS, GetLocationX(town_loc[most_threatened_town]), GetLocationY(town_loc[most_threatened_town])) + set enemy_army = town_threat_army[most_threatened_town] + if enemy_army >= 0 then + call SetCaptainHome(BOTH_CAPTAINS,GetLocationX(army_loc[enemy_army]), GetLocationY(army_loc[enemy_army])) + else + call SetCaptainHome(BOTH_CAPTAINS, GetLocationX(town_loc[most_threatened_town]), GetLocationY(town_loc[most_threatened_town])) + endif set captain_home = town_loc[most_threatened_town] set captain_tp = town_can_tp[most_threatened_town] elseif town_threat[most_threatened_player_town] > 0 and town_threat[most_threatened_player_town] <= playerthreat then diff --git a/Jobs/RETREAT_CONTROL.eai b/Jobs/RETREAT_CONTROL.eai index 9fd70b5cd..f72e5b5a6 100644 --- a/Jobs/RETREAT_CONTROL.eai +++ b/Jobs/RETREAT_CONTROL.eai @@ -119,10 +119,11 @@ if not isfleeing and canflee and (CaptainRetreating() or CaptainIsHome()) then set isfleeing = true endif -if ((not attack_running and not isfleeing) or isfleeing or (town_threatened and town_threat_break)) then +if ((not attack_running and not isfleeing) or isfleeing or (town_threatened and town_threat_break) or player_defeated) then set break_attack = attack_running - if CaptainIsHome() or (not attack_running and not isfleeing) then - call Trace("===Retreat control ended===") + call TraceAll("RETREAT: Pending End fleeing:" + B2S(isfleeing)) + if CaptainIsHome() or (not attack_running and not isfleeing) or player_defeated or (main_army >= 0 and DistanceBetweenPoints(army_loc[main_army], captain_home) <= 750) then + call TraceAll("===Retreat control ended===") set retreat_controlled = false set canflee = false set isfleeing = false // home so no need to be retreating. Also prevents bug in the captainretreating condition @@ -134,8 +135,16 @@ if ((not attack_running and not isfleeing) or isfleeing or (town_threatened and endif if isfleeing or (town_threatened and town_threat_break) then - call ClearCaptainTargets() - call CaptainGoHome() + //call ClearCaptainTargets() + if not CaptainIsHome() and not CaptainRetreating() then + call TraceAll("Retreat Home Fix") + call CaptainGoHome() + endif +endif + +if isfleeing then + call TQAddJob(2 * sleep_multiplier, RETREAT_CONTROL, 0) + return endif if attack_running then @@ -211,13 +220,12 @@ if attack_running then set ally_strength_sum = ally_sum call Trace("RETREAT_CONTROL: Our strength: " + Real2Str(ally_strength_sum) + " Enemy strength: " + Real2Str(enemy_strength_sum)) - if not desperation_assault and (enemy_strength_sum > ApplyFleeStrengthModifier(ally_strength_sum, true) or (town_threatened and town_threat_break and attack_running) or ally_strength_sum == 0) then + if CaptainInCombat(true) and not desperation_assault and (enemy_strength_sum > ApplyFleeStrengthModifier(ally_strength_sum, true) or (town_threatened and town_threat_break and attack_running) or ally_strength_sum == 0) then call TraceAll("RETREAT_CONTROL: Flee!!!!") set break_attack = attack_running - call ClearCaptainTargets() call CaptainGoHome() set isfleeing = true - elseif not desperation_assault and (enemy_strength_sum > ApplyFleeStrengthModifier(ally_strength_sum, false) or (battle_radius == creep_battle_radius and enemy_strength_sum > ally_strength_sum )) then + elseif CaptainInCombat(true) and not desperation_assault and (enemy_strength_sum > ApplyFleeStrengthModifier(ally_strength_sum, false) or (battle_radius == creep_battle_radius and enemy_strength_sum > ally_strength_sum )) then call TraceAll("RETREAT_CONTROL: Allowed to Flee") call SetGroupsFlee(true) set canflee = true diff --git a/common.eai b/common.eai index 4351196d2..d0bf2bba1 100644 --- a/common.eai +++ b/common.eai @@ -13016,15 +13016,18 @@ function SleepUntilTownDefended takes integer ai_strength returns nothing local integer enemy_army = -1 set own_strength = ai_strength call Trace("==Sleep Defend Town==" ) - call CaptainGoHome() - call FormGroupAM(0) - if town_threatened and most_threatened_town >= 0 then + if not CaptainIsHome() and not CaptainRetreating() then + call CaptainGoHome() + endif + // Attack logic still overridden by allies, so commented out - just return to home location + //call FormGroupAM(0) + //if town_threatened and most_threatened_town >= 0 then // We want to intercept the army - set enemy_army = town_threat_army[most_threatened_town] - call CaptainAttack(GetLocationX(army_loc[enemy_army]), GetLocationY(army_loc[enemy_army]))// Not attack move to get here fast - else - call CaptainAttack(GetLocationX(captain_home), GetLocationY(captain_home)) // Unknown where the threat is return home - endif + // set enemy_army = town_threat_army[most_threatened_town] + // call CaptainAttack(GetLocationX(army_loc[enemy_army]), GetLocationY(army_loc[enemy_army]))// Not attack move to get here fast + //else + // call CaptainAttack(GetLocationX(captain_home), GetLocationY(captain_home)) // Unknown where the threat is return home + //endif loop //call DisplayToAll("Town Threatened:" + B2S(town_threatened) + " HardTown Threatened:" + B2S(TownThreatened()) + " CaptainInCombat:" + B2S(CaptainInCombat(false)) + " i:" ) call CreateDebugTagLoc("Sleep until town defended", 10, GetLocationX(captain_home), GetLocationY(captain_home), 1.00, 0.80) @@ -13033,25 +13036,32 @@ function SleepUntilTownDefended takes integer ai_strength returns nothing set defense_length_counter = defense_length_counter + 1 if defense_length_counter > attack_reform_length then set defense_length_counter = 0 - call FormGroupAM(0) + //call FormGroupAM(0) endif - if CaptainAtGoal() or CaptainInCombat(true) or CaptainInCombat(false) then + if not CaptainIsHome() and not CaptainRetreating() and not CaptainInCombat(false) then + call CaptainGoHome() + endif + //if CaptainAtGoal() or CaptainInCombat(true) or CaptainInCombat(false) then // Attack move to actually defend - if town_threatened and most_threatened_town >= 0 then - set enemy_army = town_threat_army[most_threatened_town] - call AttackMoveXY(R2I(GetLocationX(army_loc[enemy_army])), R2I(GetLocationY(army_loc[enemy_army]))) // Only attack move when at target - else - call AttackMoveXY(R2I(GetLocationX(captain_home)), R2I(GetLocationY(captain_home))) - endif - else + // if town_threatened and most_threatened_town >= 0 then + // set enemy_army = town_threat_army[most_threatened_town] + // call AttackMoveXY(R2I(GetLocationX(army_loc[enemy_army])), R2I(GetLocationY(army_loc[enemy_army]))) // Only attack move when at target + //call TeleportCaptain(GetLocationX(army_loc[enemy_army]), GetLocationY(army_loc[enemy_army])) + // else + // call AttackMoveXY(R2I(GetLocationX(captain_home)), R2I(GetLocationY(captain_home))) + //call TeleportCaptain(GetLocationX(captain_home), GetLocationY(captain_home)) + // endif + //else // This ensures units return to defend location and don't wonder - if town_threatened and most_threatened_town >= 0 then - set enemy_army = town_threat_army[most_threatened_town] - call CaptainAttack(GetLocationX(army_loc[enemy_army]), GetLocationY(army_loc[enemy_army]))// Not attack move to get here fast - else - call CaptainAttack(GetLocationX(captain_home), GetLocationY(captain_home)) // Unknown where the threat is return home - endif - endif + // if town_threatened and most_threatened_town >= 0 then + // set enemy_army = town_threat_army[most_threatened_town] + //call CaptainAttack(GetLocationX(army_loc[enemy_army]), GetLocationY(army_loc[enemy_army]))// Not attack move to get here fast + // call TeleportCaptain(GetLocationX(army_loc[enemy_army]), GetLocationY(army_loc[enemy_army])) + // else + //call CaptainAttack(GetLocationX(captain_home), GetLocationY(captain_home)) // Unknown where the threat is return home + // call TeleportCaptain(GetLocationX(captain_home), GetLocationY(captain_home)) + // endif + //endif call StaggerSleep(2 * sleep_multiplier, (2 * sleep_multiplier) + 2) endloop call CaptainGoHome() @@ -13733,6 +13743,7 @@ function universal_attack_sequence takes nothing returns nothing local integer ai_strength = 0 //local integer ai_antiair_strength = 0 local integer exp_strength = 0 + local integer defense_length_counter = attack_reform_length if hero_unit[1] == null and ver_heroes and not desperation_assault then call Sleep(sleep_multiplier) @@ -13766,9 +13777,25 @@ function universal_attack_sequence takes nothing returns nothing call Sleep(1) endloop + + loop exitwhen not retreat_controlled call CreateDebugTagLoc("Sleep until retreated", 10, GetLocationX(home_location), GetLocationY(home_location), 1.00, 0.80) + if retreat_controlled and isfleeing then + set defense_length_counter = defense_length_counter + 1 + if defense_length_counter > attack_reform_length then + set defense_length_counter = 0 + //call FormGroupAM(0) + //call TraceAll("Retreat FIX") + //call InitAssault() + endif + //if main_army >= 0 + //if not CaptainAtGoal() then + //call CaptainAttack(GetLocationX(captain_home), GetLocationY(captain_home)) // Prevent fight and flight behaviour + //call TeleportCaptain(GetLocationX(captain_home), GetLocationY(captain_home)) // Prevent fight and flight behaviour + //endif + endif call Sleep(1) // Retreat must have fully run its course, units are sent home via job endloop @@ -13782,7 +13809,6 @@ function universal_attack_sequence takes nothing returns nothing if go_home then call Trace("UNIVERSAL ATTACK: Going home" ) - call ClearCaptainTargets() call CaptainGoHome() endif set break_attack = false