mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-08-22 11:38:12 +01:00
Fixes several bugs with AI mobs
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
// Base AIs for simple mobs.
|
||||
// Mob-specific AIs are in their mob's file.
|
||||
|
||||
/datum/ai_holder/simple_mob
|
||||
hostile = TRUE // The majority of simplemobs are hostile.
|
||||
cooperative = TRUE
|
||||
returns_home = FALSE
|
||||
can_flee = FALSE
|
||||
speak_chance = 1 // If the mob's saylist is empty, nothing will happen.
|
||||
wander = TRUE
|
||||
base_wander_delay = 4
|
||||
|
||||
// For non-hostile animals, and pets like Ian and Runtime.
|
||||
/datum/ai_holder/simple_mob/passive
|
||||
hostile = FALSE
|
||||
can_flee = TRUE
|
||||
violent_breakthrough = FALSE
|
||||
|
||||
// Won't wander away as quickly, ideal for event-spawned mobs like carp or drones.
|
||||
/datum/ai_holder/simple_mob/event
|
||||
base_wander_delay = 8
|
||||
|
||||
// Doesn't really act until told to by something on the outside.
|
||||
/datum/ai_holder/simple_mob/inert
|
||||
hostile = FALSE
|
||||
retaliate = FALSE
|
||||
can_flee = FALSE
|
||||
wander = FALSE
|
||||
speak_chance = 0
|
||||
cooperative = FALSE
|
||||
violent_breakthrough = FALSE // So it can open doors but not attack windows and shatter the literal illusion.
|
||||
|
||||
// Used for technomancer illusions, to resemble player movement better.
|
||||
/datum/ai_holder/simple_mob/inert/astar
|
||||
use_astar = TRUE
|
||||
|
||||
// Ranged mobs.
|
||||
|
||||
/datum/ai_holder/simple_mob/ranged
|
||||
// ranged = TRUE
|
||||
|
||||
// Tries to not waste ammo.
|
||||
/datum/ai_holder/simple_mob/ranged/careful
|
||||
conserve_ammo = TRUE
|
||||
|
||||
/datum/ai_holder/simple_mob/ranged/pointblank
|
||||
pointblank = TRUE
|
||||
|
||||
// Runs away from its target if within a certain distance.
|
||||
/datum/ai_holder/simple_mob/ranged/kiting
|
||||
pointblank = TRUE // So we don't need to copypaste post_melee_attack().
|
||||
var/run_if_this_close = 4 // If anything gets within this range, it'll try to move away.
|
||||
var/moonwalk = TRUE // If true, mob turns to face the target while kiting, otherwise they turn in the direction they moved towards.
|
||||
|
||||
/datum/ai_holder/simple_mob/ranged/kiting/threatening
|
||||
threaten = TRUE
|
||||
threaten_delay = 1 SECOND // Less of a threat and more of pre-attack notice.
|
||||
threaten_timeout = 30 SECONDS
|
||||
conserve_ammo = TRUE
|
||||
|
||||
// For event-spawned malf drones.
|
||||
/datum/ai_holder/simple_mob/ranged/kiting/threatening/event
|
||||
base_wander_delay = 8
|
||||
|
||||
/datum/ai_holder/simple_mob/ranged/kiting/no_moonwalk
|
||||
moonwalk = FALSE
|
||||
|
||||
/datum/ai_holder/simple_mob/ranged/kiting/on_engagement(atom/A)
|
||||
if(get_dist(holder, A) < run_if_this_close)
|
||||
holder.IMove(get_step_away(holder, A, run_if_this_close))
|
||||
if(moonwalk)
|
||||
holder.face_atom(A)
|
||||
|
||||
// Closes distance from the target even while in range.
|
||||
/datum/ai_holder/simple_mob/ranged/aggressive
|
||||
pointblank = TRUE
|
||||
var/closest_distance = 1 // How close to get to the target. By default they will get into melee range (and then pointblank them).
|
||||
|
||||
/datum/ai_holder/simple_mob/ranged/aggressive/on_engagement(atom/A)
|
||||
if(get_dist(holder, A) > closest_distance)
|
||||
holder.IMove(get_step_towards(holder, A))
|
||||
holder.face_atom(A)
|
||||
|
||||
// Yakkity saxes while firing at you.
|
||||
/datum/ai_holder/hostile/ranged/robust/on_engagement(atom/movable/AM)
|
||||
step_rand(holder)
|
||||
holder.face_atom(AM)
|
||||
|
||||
// Switches intents based on specific criteria.
|
||||
// Used for special mobs who do different things based on intents (and aren't slimes).
|
||||
// Intent switching is generally done in pre_[ranged/special]_attack(), so that the mob can use the right attack for the right time.
|
||||
/datum/ai_holder/simple_mob/intentional
|
||||
|
||||
|
||||
// These try to avoid collateral damage.
|
||||
/datum/ai_holder/simple_mob/restrained
|
||||
violent_breakthrough = FALSE
|
||||
conserve_ammo = TRUE
|
||||
destructive = FALSE
|
||||
|
||||
// This does the opposite of the above subtype.
|
||||
/datum/ai_holder/simple_mob/destructive
|
||||
destructive = TRUE
|
||||
|
||||
// Melee mobs.
|
||||
|
||||
/datum/ai_holder/simple_mob/melee
|
||||
|
||||
// Dances around the enemy its fighting, making it harder to fight back.
|
||||
/datum/ai_holder/simple_mob/melee/evasive
|
||||
|
||||
/datum/ai_holder/simple_mob/melee/evasive/post_melee_attack(atom/A)
|
||||
if(holder.Adjacent(A))
|
||||
holder.IMove(get_step(holder, pick(alldirs)))
|
||||
holder.face_atom(A)
|
||||
|
||||
|
||||
|
||||
// This AI hits something, then runs away for awhile.
|
||||
// It will (almost) always flee if they are uncloaked, AND their target is not stunned.
|
||||
/datum/ai_holder/simple_mob/melee/hit_and_run
|
||||
can_flee = TRUE
|
||||
|
||||
// Used for the 'running' part of hit and run.
|
||||
/datum/ai_holder/simple_mob/melee/hit_and_run/special_flee_check()
|
||||
if(!holder.is_cloaked())
|
||||
if(isliving(target))
|
||||
var/mob/living/L = target
|
||||
return !L.incapacitated(INCAPACITATION_DISABLED) // Don't flee if our target is stunned in some form, even if uncloaked. This is so the mob keeps attacking a stunned opponent.
|
||||
return TRUE // We're out in the open, uncloaked, and our target isn't stunned, so lets flee.
|
||||
return FALSE
|
||||
|
||||
|
||||
// Simple mobs that aren't hostile, but will fight back.
|
||||
/datum/ai_holder/simple_mob/retaliate
|
||||
hostile = FALSE
|
||||
retaliate = TRUE
|
||||
|
||||
// Simple mobs that retaliate and support others in their faction who get attacked.
|
||||
/datum/ai_holder/simple_mob/retaliate/cooperative
|
||||
cooperative = TRUE
|
||||
@@ -0,0 +1,266 @@
|
||||
// Specialized AI for slime simplemobs.
|
||||
// Unlike the parent AI code, this will probably break a lot of things if you put it on something that isn't /mob/living/simple_mob/slime/xenobio
|
||||
|
||||
/datum/ai_holder/simple_mob/xenobio_slime
|
||||
hostile = TRUE
|
||||
cooperative = TRUE
|
||||
firing_lanes = TRUE
|
||||
var/rabid = FALSE // Will attack regardless of discipline.
|
||||
var/discipline = 0 // Beating slimes makes them less likely to lash out. In theory.
|
||||
var/resentment = 0 // 'Unjustified' beatings make this go up, and makes it more likely for abused slimes to go rabid.
|
||||
var/obedience = 0 // Conversely, 'justified' beatings make this go up, and makes discipline decay slower, potentially making it not decay at all.
|
||||
|
||||
var/always_stun = FALSE // If true, the slime will elect to attempt to permastun the target.
|
||||
|
||||
var/last_discipline_decay = null // Last world.time discipline was reduced from decay.
|
||||
var/discipline_decay_time = 5 SECONDS // Earliest that one discipline can decay.
|
||||
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/sapphire
|
||||
always_stun = TRUE // They know that stuns are godly.
|
||||
intelligence_level = AI_SMART // Also knows not to walk while confused if it risks death.
|
||||
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/light_pink
|
||||
discipline = 10
|
||||
obedience = 10
|
||||
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/passive/New() // For Kendrick.
|
||||
..()
|
||||
pacify()
|
||||
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/New()
|
||||
..()
|
||||
ASSERT(istype(holder, /mob/living/simple_mob/slime/xenobio))
|
||||
|
||||
// Checks if disciplining the slime would be 'justified' right now.
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/proc/is_justified_to_discipline()
|
||||
if(rabid)
|
||||
return TRUE
|
||||
if(target)
|
||||
if(ishuman(target))
|
||||
var/mob/living/carbon/human/H = target
|
||||
if(istype(H.species, /datum/species/monkey))
|
||||
return FALSE // Attacking monkeys is okay.
|
||||
return TRUE // Otherwise attacking other things is bad.
|
||||
return FALSE // Not attacking anything.
|
||||
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/proc/can_command(mob/living/commander)
|
||||
if(rabid)
|
||||
return FALSE
|
||||
if(!hostile)
|
||||
return SLIME_COMMAND_OBEY
|
||||
// if(commander in friends)
|
||||
// return SLIME_COMMAND_FRIEND
|
||||
if(holder.IIsAlly(commander))
|
||||
return SLIME_COMMAND_FACTION
|
||||
if(discipline > resentment && obedience >= 5)
|
||||
return SLIME_COMMAND_OBEY
|
||||
return FALSE
|
||||
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/proc/adjust_discipline(amount, silent)
|
||||
var/mob/living/simple_mob/slime/xenobio/my_slime = holder
|
||||
if(amount > 0)
|
||||
if(rabid)
|
||||
return
|
||||
var/justified = is_justified_to_discipline()
|
||||
lost_target() // Stop attacking.
|
||||
|
||||
if(justified)
|
||||
obedience++
|
||||
if(!silent)
|
||||
holder.say(pick("Fine...", "Okay...", "Sorry...", "I yield...", "Mercy..."))
|
||||
else
|
||||
if(prob(resentment * 20))
|
||||
enrage()
|
||||
holder.say(pick("Evil...", "Kill...", "Tyrant..."))
|
||||
else
|
||||
if(!silent)
|
||||
holder.say(pick("Why...?", "I don't understand...?", "Cruel...", "Stop...", "Nooo..."))
|
||||
resentment++ // Done after check so first time will never enrage.
|
||||
|
||||
discipline = between(0, discipline + amount, 10)
|
||||
my_slime.update_mood()
|
||||
|
||||
// This slime always enrages if disciplined.
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/red/adjust_discipline(amount, silent)
|
||||
if(amount > 0 && !rabid)
|
||||
holder.say("Grrr...")
|
||||
holder.add_modifier(/datum/modifier/berserk, 30 SECONDS)
|
||||
enrage()
|
||||
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/handle_special_strategical()
|
||||
discipline_decay()
|
||||
|
||||
// Handles decay of discipline.
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/proc/discipline_decay()
|
||||
if(discipline > 0 && last_discipline_decay + discipline_decay_time < world.time)
|
||||
if(!prob(75 + (obedience * 5)))
|
||||
adjust_discipline(-1)
|
||||
last_discipline_decay = world.time
|
||||
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/handle_special_tactic()
|
||||
evolve_and_reproduce()
|
||||
|
||||
// Hit the correct verbs to keep the slime species going.
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/proc/evolve_and_reproduce()
|
||||
var/mob/living/simple_mob/slime/xenobio/my_slime = holder
|
||||
if(my_slime.amount_grown >= 10)
|
||||
// Press the correct verb when we can.
|
||||
if(my_slime.is_adult)
|
||||
my_slime.reproduce() // Splits into four new baby slimes.
|
||||
else
|
||||
my_slime.evolve() // Turns our holder into an adult slime.
|
||||
|
||||
|
||||
// Called when pushed too far (or a red slime core was used).
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/proc/enrage()
|
||||
var/mob/living/simple_mob/slime/xenobio/my_slime = holder
|
||||
if(my_slime.harmless)
|
||||
return
|
||||
rabid = TRUE
|
||||
my_slime.update_mood()
|
||||
my_slime.visible_message(span("danger", "\The [src] enrages!"))
|
||||
|
||||
// Called when using a pacification agent (or it's Kendrick being initalized).
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/proc/pacify()
|
||||
lost_target() // So it stops trying to kill them.
|
||||
rabid = FALSE
|
||||
hostile = FALSE
|
||||
retaliate = FALSE
|
||||
cooperative = FALSE
|
||||
|
||||
// The holder's attack changes based on intent. This lets the AI choose what effect is desired.
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/pre_melee_attack(atom/A)
|
||||
if(istype(A, /mob/living))
|
||||
var/mob/living/L = A
|
||||
var/mob/living/simple_mob/slime/xenobio/my_slime = holder
|
||||
|
||||
if( (!L.lying && prob(30 + (my_slime.power_charge * 7) ) || (!L.lying && always_stun) ))
|
||||
my_slime.a_intent = I_DISARM // Stun them first.
|
||||
else if(my_slime.can_consume(L) && L.lying)
|
||||
my_slime.a_intent = I_GRAB // Then eat them.
|
||||
else
|
||||
my_slime.a_intent = I_HURT // Otherwise robust them.
|
||||
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/closest_distance(atom/movable/AM)
|
||||
if(istype(AM, /mob/living))
|
||||
var/mob/living/L = AM
|
||||
if(ishuman(L))
|
||||
var/mob/living/carbon/human/H = L
|
||||
if(istype(H.species, /datum/species/monkey))
|
||||
return 1 // Otherwise ranged slimes will eat a lot less often.
|
||||
if(L.stat >= UNCONSCIOUS)
|
||||
return 1 // Melee (eat) the target if dead/dying, don't shoot it.
|
||||
return ..()
|
||||
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/can_attack(atom/movable/AM)
|
||||
. = ..()
|
||||
if(.) // Do some additional checks because we have Special Code(tm).
|
||||
if(ishuman(AM))
|
||||
var/mob/living/carbon/human/H = AM
|
||||
if(istype(H.species, /datum/species/monkey)) // istype() is so they'll eat the alien monkeys too.
|
||||
return TRUE // Monkeys are always food (sorry Pun Pun).
|
||||
else if(H.species && H.species.name == SPECIES_PROMETHEAN)
|
||||
return FALSE // Prometheans are always our friends.
|
||||
if(discipline && !rabid)
|
||||
return FALSE // We're a good slime.
|
||||
|
||||
// Commands, reactions, etc
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/on_hear_say(mob/living/speaker, message)
|
||||
ai_log("xenobio_slime/on_hear_say([speaker], [message]) : Entered.", AI_LOG_DEBUG)
|
||||
var/mob/living/simple_mob/slime/xenobio/my_slime = holder
|
||||
|
||||
if((findtext(message, num2text(my_slime.number)) || findtext(message, my_slime.name) || findtext(message, "slimes"))) // Talking to us.
|
||||
|
||||
// First, make sure it's actually a player saying something and not an AI, or else we risk infinite loops.
|
||||
if(!speaker.client)
|
||||
return
|
||||
|
||||
// Are all slimes being referred to?
|
||||
// var/mass_order = FALSE
|
||||
// if(findtext(message, "slimes"))
|
||||
// mass_order = TRUE
|
||||
|
||||
// Say hello back.
|
||||
if(findtext(message, "hello") || findtext(message, "hi") || findtext(message, "greetings"))
|
||||
delayed_say(pick("Hello...", "Hi..."), speaker)
|
||||
|
||||
// Follow request.
|
||||
if(findtext(message, "follow") || findtext(message, "come with me"))
|
||||
if(!can_command(speaker))
|
||||
delayed_say(pick("No...", "I won't follow..."), speaker)
|
||||
return
|
||||
|
||||
delayed_say("Yes... I follow \the [speaker]...", speaker)
|
||||
set_follow(speaker)
|
||||
|
||||
// Squish request.
|
||||
if(findtext(message , "squish"))
|
||||
if(!can_command(speaker))
|
||||
delayed_say("No...", speaker)
|
||||
return
|
||||
|
||||
spawn(rand(1 SECOND, 2 SECONDS))
|
||||
if(!src || !holder || !can_act()) // We might've died/got deleted/etc in the meantime.
|
||||
return
|
||||
my_slime.squish()
|
||||
|
||||
|
||||
// Stop request.
|
||||
if(findtext(message, "stop") || findtext(message, "halt") || findtext(message, "cease"))
|
||||
if(my_slime.victim) // We're being asked to stop eatting someone.
|
||||
if(!can_command(speaker) || !is_justified_to_discipline())
|
||||
delayed_say("No...", speaker)
|
||||
return
|
||||
else
|
||||
delayed_say("Fine...", speaker)
|
||||
adjust_discipline(1, TRUE)
|
||||
my_slime.stop_consumption()
|
||||
|
||||
if(target) // We're being asked to stop chasing someone.
|
||||
if(!can_command(speaker) || !is_justified_to_discipline())
|
||||
delayed_say("No...", speaker)
|
||||
return
|
||||
else
|
||||
delayed_say("Fine...", speaker)
|
||||
adjust_discipline(1, TRUE) // This must come before losing the target or it will be unjustified.
|
||||
lost_target()
|
||||
|
||||
|
||||
if(leader) // We're being asked to stop following someone.
|
||||
if(can_command(speaker) == SLIME_COMMAND_FRIEND || leader == speaker)
|
||||
delayed_say("Yes... I'll stop...", speaker)
|
||||
lose_follow()
|
||||
else
|
||||
delayed_say("No... I'll keep following \the [leader]...", speaker)
|
||||
|
||||
/* // Commented out since its mostly useless now due to slimes refusing to attack if it would make them naughty.
|
||||
// Murder request
|
||||
if(findtext(message, "harm") || findtext(message, "attack") || findtext(message, "kill") || findtext(message, "murder") || findtext(message, "eat") || findtext(message, "consume") || findtext(message, "absorb"))
|
||||
if(can_command(speaker) < SLIME_COMMAND_FACTION)
|
||||
delayed_say("No...", speaker)
|
||||
return
|
||||
|
||||
for(var/mob/living/L in view(7, my_slime) - list(my_slime, speaker))
|
||||
if(L == src)
|
||||
continue // Don't target ourselves.
|
||||
var/list/valid_names = splittext(L.name, " ") // Should output list("John", "Doe") as an example.
|
||||
for(var/line in valid_names) // Check each part of someone's name.
|
||||
if(findtext(message, lowertext(line))) // If part of someone's name is in the command, the slime targets them if allowed to.
|
||||
if(!(mass_order && line == "slime")) //don't think random other slimes are target
|
||||
if(can_attack(L))
|
||||
delayed_say("Okay... I attack \the [L]...", speaker)
|
||||
give_target(L)
|
||||
return
|
||||
else
|
||||
delayed_say("No... I won't attack \the [L].", speaker)
|
||||
return
|
||||
|
||||
// If we're here, it couldn't find anyone with that name.
|
||||
delayed_say("No... I don't know who to attack...", speaker)
|
||||
*/
|
||||
ai_log("xenobio_slime/on_hear_say() : Exited.", AI_LOG_DEBUG)
|
||||
|
||||
/datum/ai_holder/simple_mob/xenobio_slime/can_violently_breakthrough()
|
||||
if(discipline && !rabid) // Good slimes don't shatter the windows because their buddy in an adjacent cell decided to piss off Slimesky.
|
||||
return FALSE
|
||||
return ..()
|
||||
@@ -0,0 +1,239 @@
|
||||
// Used for assigning a target for attacking.
|
||||
|
||||
/datum/ai_holder
|
||||
var/hostile = FALSE // Do we try to hurt others?
|
||||
var/retaliate = FALSE // Attacks whatever struck it first. Mobs will still attack back if this is false but hostile is true.
|
||||
|
||||
var/atom/movable/target = null // The thing (mob or object) we're trying to kill.
|
||||
var/atom/movable/preferred_target = null// If set, and if given the chance, we will always prefer to target this over other options.
|
||||
var/turf/target_last_seen_turf = null // Where the mob last observed the target being, used if the target disappears but the mob wants to keep fighting.
|
||||
|
||||
var/vision_range = 7 // How far the targeting system will look for things to kill. Note that values higher than 7 are 'offscreen' and might be unsporting.
|
||||
var/respect_alpha = TRUE // If true, mobs with a sufficently low alpha will be treated as invisible.
|
||||
var/alpha_vision_threshold = 127 // Targets with an alpha less or equal to this will be considered invisible. Requires above var to be true.
|
||||
|
||||
var/lose_target_time = 0 // world.time when a target was lost.
|
||||
var/lose_target_timeout = 5 SECONDS // How long until a mob 'times out' and stops trying to find the mob that disappeared.
|
||||
|
||||
var/list/attackers = list() // List of strings of names of people who attacked us before in our life.
|
||||
// This uses strings and not refs to allow for disguises, and to avoid needing to use weakrefs.
|
||||
var/destructive = FALSE // Will target 'neutral' structures/objects and not just 'hostile' ones.
|
||||
|
||||
// A lot of this is based off of /TG/'s AI code.
|
||||
|
||||
// Step 1, find out what we can see.
|
||||
/datum/ai_holder/proc/list_targets()
|
||||
. = hearers(vision_range, holder) - src // Remove ourselves to prevent suicidal decisions.
|
||||
|
||||
var/static/hostile_machines = typecacheof(list(/obj/machinery/porta_turret, /obj/mecha))
|
||||
|
||||
for(var/HM in typecache_filter_list(range(vision_range, holder), hostile_machines))
|
||||
if(can_see(holder, HM, vision_range))
|
||||
. += HM
|
||||
|
||||
// Step 2, filter down possible targets to things we actually care about.
|
||||
/datum/ai_holder/proc/find_target(var/list/possible_targets, var/has_targets_list = FALSE)
|
||||
if(!hostile) // So retaliating mobs only attack the thing that hit it.
|
||||
return null
|
||||
. = list()
|
||||
if(!has_targets_list)
|
||||
possible_targets = list_targets()
|
||||
for(var/possible_target in possible_targets)
|
||||
var/atom/A = possible_target
|
||||
if(found(A)) // In case people want to override this.
|
||||
. = list(A)
|
||||
break
|
||||
if(can_attack(A)) // Can we attack it?
|
||||
. += A
|
||||
continue
|
||||
|
||||
var/new_target = pick_target(.)
|
||||
give_target(new_target)
|
||||
return new_target
|
||||
|
||||
// Step 3, pick among the possible, attackable targets.
|
||||
/datum/ai_holder/proc/pick_target(list/targets)
|
||||
if(target != null) // If we already have a target, but are told to pick again, calculate the lowest distance between all possible, and pick from the lowest distance targets.
|
||||
targets = target_filter_distance(targets)
|
||||
// for(var/possible_target in targets)
|
||||
// var/atom/A = possible_target
|
||||
// var/target_dist = get_dist(holder, target)
|
||||
// var/possible_target_distance = get_dist(holder, A)
|
||||
// if(target_dist < possible_target_distance)
|
||||
// targets -= A
|
||||
if(!targets.len) // We found nothing.
|
||||
return
|
||||
|
||||
var/chosen_target
|
||||
if(preferred_target && preferred_target in targets)
|
||||
chosen_target = preferred_target
|
||||
else
|
||||
chosen_target = pick(targets)
|
||||
return chosen_target
|
||||
|
||||
// Step 4, give us our selected target.
|
||||
/datum/ai_holder/proc/give_target(new_target)
|
||||
target = new_target
|
||||
if(target != null)
|
||||
if(should_threaten())
|
||||
set_stance(STANCE_ALERT)
|
||||
else
|
||||
set_stance(STANCE_APPROACH)
|
||||
return TRUE
|
||||
|
||||
// Filters return one or more 'preferred' targets.
|
||||
|
||||
// This one is for closest targets.
|
||||
/datum/ai_holder/proc/target_filter_distance(list/targets)
|
||||
for(var/possible_target in targets)
|
||||
var/atom/A = possible_target
|
||||
var/target_dist = get_dist(holder, target)
|
||||
var/possible_target_distance = get_dist(holder, A)
|
||||
if(target_dist < possible_target_distance)
|
||||
targets -= A
|
||||
return targets
|
||||
|
||||
/datum/ai_holder/proc/can_attack(atom/movable/the_target)
|
||||
if(!can_see_target(the_target))
|
||||
return FALSE
|
||||
|
||||
if(istype(the_target, /mob/zshadow))
|
||||
return FALSE // no
|
||||
|
||||
if(isliving(the_target))
|
||||
var/mob/living/L = the_target
|
||||
if(L.stat == DEAD)
|
||||
return FALSE
|
||||
if(holder.IIsAlly(L))
|
||||
return FALSE
|
||||
return TRUE
|
||||
|
||||
if(istype(the_target, /obj/mecha))
|
||||
var/obj/mecha/M = the_target
|
||||
if(M.occupant)
|
||||
return can_attack(M.occupant)
|
||||
return destructive // Empty mechs are 'neutral'.
|
||||
|
||||
if(istype(the_target, /obj/machinery/porta_turret))
|
||||
var/obj/machinery/porta_turret/P = the_target
|
||||
if(P.stat & BROKEN)
|
||||
return FALSE // Already dead.
|
||||
if(P.faction == holder.faction)
|
||||
return FALSE // Don't shoot allied turrets.
|
||||
if(!P.raised && !P.raising)
|
||||
return FALSE // Turrets won't get hurt if they're still in their cover.
|
||||
return TRUE
|
||||
|
||||
return TRUE
|
||||
// return FALSE
|
||||
|
||||
// Override this for special targeting criteria.
|
||||
// If it returns true, the mob will always select it as the target.
|
||||
/datum/ai_holder/proc/found(atom/movable/the_target)
|
||||
return FALSE
|
||||
|
||||
//We can't see the target, go look or attack where they were last seen.
|
||||
/datum/ai_holder/proc/lose_target()
|
||||
if(target)
|
||||
target = null
|
||||
lose_target_time = world.time
|
||||
|
||||
give_up_movement()
|
||||
|
||||
|
||||
//Target is no longer valid (?)
|
||||
/datum/ai_holder/proc/lost_target()
|
||||
set_stance(STANCE_IDLE)
|
||||
lose_target_position()
|
||||
lose_target()
|
||||
|
||||
// Check if target is visible to us.
|
||||
/datum/ai_holder/proc/can_see_target(atom/movable/the_target, view_range = vision_range)
|
||||
ai_log("can_see_target() : Entering.", AI_LOG_TRACE)
|
||||
|
||||
if(!the_target) // Nothing to target.
|
||||
ai_log("can_see_target() : There is no target. Exiting.", AI_LOG_WARNING)
|
||||
return FALSE
|
||||
|
||||
if(holder.see_invisible < the_target.invisibility) // Real invis.
|
||||
ai_log("can_see_target() : Target ([the_target]) was invisible to holder. Exiting.", AI_LOG_TRACE)
|
||||
return FALSE
|
||||
|
||||
if(respect_alpha && the_target.alpha <= alpha_vision_threshold) // Fake invis.
|
||||
ai_log("can_see_target() : Target ([the_target]) was sufficently transparent to holder and is hidden. Exiting.", AI_LOG_TRACE)
|
||||
return FALSE
|
||||
|
||||
if(get_dist(holder, the_target) > view_range) // Too far away.
|
||||
ai_log("can_see_target() : Target ([the_target]) was too far from holder. Exiting.", AI_LOG_TRACE)
|
||||
return FALSE
|
||||
|
||||
if(!can_see(holder, the_target, view_range))
|
||||
ai_log("can_see_target() : Target ([the_target]) failed can_see(). Exiting.", AI_LOG_TRACE)
|
||||
return FALSE
|
||||
|
||||
ai_log("can_see_target() : Target ([the_target]) can be seen. Exiting.", AI_LOG_TRACE)
|
||||
return TRUE
|
||||
|
||||
// Updates the last known position of the target.
|
||||
/datum/ai_holder/proc/track_target_position()
|
||||
if(!target)
|
||||
lose_target_position()
|
||||
|
||||
if(last_turf_display && target_last_seen_turf)
|
||||
target_last_seen_turf.overlays -= last_turf_overlay
|
||||
|
||||
target_last_seen_turf = get_turf(target)
|
||||
|
||||
if(last_turf_display)
|
||||
target_last_seen_turf.overlays += last_turf_overlay
|
||||
|
||||
// Resets the last known position to null.
|
||||
/datum/ai_holder/proc/lose_target_position()
|
||||
if(last_turf_display && target_last_seen_turf)
|
||||
target_last_seen_turf.overlays -= last_turf_overlay
|
||||
ai_log("lose_target_position() : Last position is being reset.", AI_LOG_INFO)
|
||||
target_last_seen_turf = null
|
||||
|
||||
// Responds to a hostile action against its mob.
|
||||
/datum/ai_holder/proc/react_to_attack(atom/movable/attacker)
|
||||
if(holder.stat) // We're dead.
|
||||
ai_log("react_to_attack() : Was attacked by [attacker], but we are dead/unconscious.", AI_LOG_TRACE)
|
||||
return FALSE
|
||||
if(!hostile && !retaliate) // Not allowed to defend ourselves.
|
||||
ai_log("react_to_attack() : Was attacked by [attacker], but we are not allowed to attack back.", AI_LOG_TRACE)
|
||||
return FALSE
|
||||
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.
|
||||
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
|
||||
|
||||
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)
|
||||
go_wake()
|
||||
|
||||
ai_log("react_to_attack() : Was attacked by [attacker].", AI_LOG_INFO)
|
||||
on_attacked(attacker) // So we attack immediately and not threaten.
|
||||
return give_target(attacker) // Also handles setting the appropiate stance.
|
||||
|
||||
// Sets a few vars so mobs that threaten will react faster to an attacker or someone who attacked them before.
|
||||
/datum/ai_holder/proc/on_attacked(atom/movable/AM)
|
||||
last_conflict_time = world.time
|
||||
if(isliving(AM))
|
||||
var/mob/living/L = AM
|
||||
attackers |= L.name
|
||||
|
||||
// Causes targeting to prefer targeting the taunter if possible.
|
||||
// This generally occurs if more than one option is within striking distance, including the taunter.
|
||||
// Otherwise the default filter will prefer the closest target.
|
||||
/datum/ai_holder/proc/receive_taunt(atom/movable/taunter, force_target_switch = FALSE)
|
||||
ai_log("receive_taunt() : Was taunted by [taunter].", AI_LOG_INFO)
|
||||
preferred_target = taunter
|
||||
if(force_target_switch)
|
||||
give_target(taunter)
|
||||
|
||||
/datum/ai_holder/proc/lose_taunt()
|
||||
ai_log("lose_taunt() : Resetting preferred_target.", AI_LOG_INFO)
|
||||
preferred_target = null
|
||||
Reference in New Issue
Block a user