Merge pull request #11275 from VOREStation/Arokha/commence_fighting

AI hostile mobs will not be OK with being eaten
This commit is contained in:
Aronai Sieyes
2021-07-28 12:22:56 -04:00
committed by GitHub
4 changed files with 38 additions and 11 deletions
+12 -1
View File
@@ -353,13 +353,24 @@
ai_log("handle_stance_tactical() : Going to handle_resist().", AI_LOG_TRACE)
handle_resist()
else if(istype(holder.loc, /obj/structure/closet))
var/atom/holder_loc = holder.loc
if(istype(holder_loc, /obj/structure/closet))
var/obj/structure/closet/C = holder.loc
ai_log("handle_stance_tactical() : Inside a closet. Going to attempt escape.", AI_LOG_TRACE)
if(C.sealed)
holder.resist()
else
C.open()
else if(isbelly(holder_loc))
ai_log("handle_stance_tactical() : Inside a belly, will move out to turf if owner is stat.", AI_LOG_TRACE)
var/obj/belly/B = holder_loc
var/mob/living/L = B.owner
if(B.owner?.stat)
var/mob/living/holder = src.holder
ai_log("handle_stance_tactical() : Owner was stat, moving.", AI_LOG_TRACE)
holder.forceMove(get_turf(L))
holder.visible_message("<span class='danger'>[src] climbs out of [L], ready to continue fighting!</span>")
playsound(holder, 'sound/effects/splat.ogg')
// Should we flee?
if(should_flee())
+18
View File
@@ -68,6 +68,7 @@
// We're not entirely sure how holder will do melee attacks since any /mob/living could be holder, but we don't have to care because Interfaces.
/datum/ai_holder/proc/melee_attack(atom/A)
ai_log("melee_attack() : Entering.", AI_LOG_TRACE)
pre_melee_attack(A)
. = holder.IAttack(A)
if(. == ATTACK_SUCCESSFUL)
@@ -75,6 +76,7 @@
// Ditto.
/datum/ai_holder/proc/ranged_attack(atom/A)
ai_log("ranged_attack() : Entering.", AI_LOG_TRACE)
pre_ranged_attack(A)
. = holder.IRangedAttack(A)
if(. == ATTACK_SUCCESSFUL)
@@ -82,11 +84,27 @@
// Most mobs probably won't have this defined but we don't care.
/datum/ai_holder/proc/special_attack(atom/movable/AM)
ai_log("special_attack() : Entering.", AI_LOG_TRACE)
pre_special_attack(AM)
. = holder.ISpecialAttack(AM)
if(. == ATTACK_SUCCESSFUL)
post_special_attack(AM)
// Almost entirely combat considerations so in this file.
/datum/ai_holder/proc/handle_eaten()
ai_log("handle_eaten() : Entering.", AI_LOG_TRACE)
forget_everything() // All of that is probably invalid now
if(!isbelly(holder.loc))
// Strange...!
stack_trace("AI tried to handle being eaten but didn't end up in a belly somehow.")
return
var/obj/belly/B = holder.loc
var/mob/living/L = B.owner
// Will return false if we decide to not do anything about it.
if(!react_to_attack(L))
ai_log("handle_eaten() : Deciding to sleep AI.", AI_LOG_TRACE)
go_sleep()
// Called when within striking/shooting distance, however cooldown is not considered.
// Override to do things like move in a random step for evasiveness.
// Note that this is called BEFORE the attack.
+7 -9
View File
@@ -114,6 +114,7 @@
return closest_targets
/datum/ai_holder/proc/can_attack(atom/movable/the_target, var/vision_required = TRUE)
ai_log("can_attack() : Entering.", AI_LOG_TRACE)
if(!can_see_target(the_target) && vision_required)
return FALSE
@@ -218,6 +219,7 @@
// Updates the last known position of the target.
/datum/ai_holder/proc/track_target_position()
ai_log("track_target_position() : Entering.", AI_LOG_TRACE)
if(!target)
lose_target_position()
@@ -231,6 +233,7 @@
// Resets the last known position to null.
/datum/ai_holder/proc/lose_target_position()
ai_log("lose_target_position() : Entering.", AI_LOG_TRACE)
if(last_turf_display && target_last_seen_turf)
target_last_seen_turf.cut_overlay(last_turf_overlay)
ai_log("lose_target_position() : Last position is being reset.", AI_LOG_INFO)
@@ -247,15 +250,10 @@
if(holder.IIsAlly(attacker)) // I'll overlook it THIS time...
ai_log("react_to_attack() : Was attacked by [attacker], but they were an ally.", AI_LOG_TRACE)
return FALSE
if(target) // Already fighting someone. Switching every time we get hit would impact our combat performance.
if(!retaliate) // If we don't get to fight back, we don't fight back...
ai_log("react_to_attack() : Was attacked by [attacker], but we already have a target.", AI_LOG_TRACE)
on_attacked(attacker) // So we attack immediately and not threaten.
return FALSE
else if(check_attacker(attacker) && world.time > last_target_time + 3 SECONDS) // Otherwise, let 'er rip
ai_log("react_to_attack() : Was attacked by [attacker]. Can retaliate, waited 3 seconds.", AI_LOG_INFO)
on_attacked(attacker) // So we attack immediately and not threaten.
return give_target(attacker) // Also handles setting the appropiate stance.
if(target && world.time < last_target_time + 8 SECONDS) // Already fighting someone. Switching every time we get hit would impact our combat performance.
ai_log("react_to_attack() : Was attacked by [attacker], but we switched targets too recently to change.", AI_LOG_TRACE)
on_attacked(attacker)
return FALSE
if(stance == STANCE_SLEEP) // If we're asleep, try waking up if someone's wailing on us.
ai_log("react_to_attack() : AI is asleep. Waking up.", AI_LOG_TRACE)
+1 -1
View File
@@ -218,7 +218,7 @@
vore_fx(M)
//Stop AI processing in bellies
if(M.ai_holder)
M.ai_holder.go_sleep()
M.ai_holder.handle_eaten()
// Called whenever an atom leaves this belly
/obj/belly/Exited(atom/movable/thing, atom/OldLoc)