AI code but cooler

This commit is contained in:
Sypsoti
2022-04-11 06:46:31 -05:00
committed by atermonera
parent 2fae0d653d
commit 8e92d375c4
4 changed files with 138 additions and 24 deletions

View File

@@ -11,13 +11,13 @@
if(get_dist(holder, target_last_seen_turf) > 1) // We last saw them over there.
// Go to where you last saw the enemy.
return give_destination(target_last_seen_turf, 1, TRUE) // Sets stance as well
// We last saw them next to us, so do a blind attack on that tile.
else if((melee_on_tile(target_last_seen_turf) != ATTACK_SUCCESSFUL) && (intelligence_level >= AI_NORMAL))
var/obj/O = find_escape_route()
if(istype(O))
return give_destination(get_turf(O), 0, TRUE)
else
return find_target()
else
return find_target()
// We last saw them next to us, so do a blind attack on that tile.
else if(melee_on_tile(target_last_seen_turf) != ATTACK_SUCCESSFUL && intelligence_level >= AI_NORMAL)
var/obj/O = find_escape_route()
if(istype(O))
return give_destination(get_turf(O), 0, TRUE)
else
return find_target()
else

View File

@@ -6,6 +6,7 @@
/datum/ai_holder/simple_mob/xeno_alien /// Basic
hostile = TRUE
retaliate = TRUE
conserve_ammo = TRUE
cooperative = TRUE
returns_home = FALSE
can_flee = FALSE
@@ -13,25 +14,63 @@
wander = TRUE
base_wander_delay = 4
/datum/ai_holder/simple_mob/xeno_alien/post_melee_attack(atom/A)
if(holder.Adjacent(A))
var/can_telegrab = FALSE
var/grab_defense = 2 /// Similar to gygax, how many non-targets before teleporting them away.
var/grab_defense_radius = 4
var/tele_range_min = 3
var/tele_range_max = 7
/datum/ai_holder/simple_mob/xeno_alien/on_engagement(atom/A)
if(holder.Adjacent(A)) /// Be hard to hit.
holder.IMove(get_step(holder, pick(alldirs)))
holder.face_atom(A)
/datum/ai_holder/simple_mob/xeno_alien/pre_special_attack(atom/A)
if(isliving(A))
var/mob/living/target = A
if(can_telegrab)
// Largely copied from electrical defense for Dark Gygax
var/tally = 0
var/list/potential_targets = list_targets()
for(var/atom/movable/AM in potential_targets)
if(get_dist(holder, AM) > grab_defense_radius)
continue
if(!can_attack(AM))
continue
tally++
// Displace them?
if(tally >= grab_defense)
holder.a_intent = I_GRAB
return
tally = 0
var/tar_dist = get_dist(holder, target)
if(tar_dist >= tele_range_min && tar_dist <= tele_range_max)
holder.a_intent = I_DISARM
return
/datum/ai_holder/simple_mob/xeno_alien/ranged /// Drones
pointblank = TRUE
ignore_incapacitated = TRUE /// We're squishier and our tox hits hard. Focus on who's up.
var/run_if_this_close = 4
var/max_distance = 6
tele_range_min = 1 /// Flee!
/datum/ai_holder/simple_mob/xeno_alien/ranged/on_engagement(atom/A)
/datum/ai_holder/simple_mob/xeno_alien/ranged/post_ranged_attack(atom/A)
if(get_dist(holder, A) < run_if_this_close)
holder.IMove(get_step_away(holder, A, run_if_this_close))
holder.face_atom(A)
else if(get_dist(holder, A) > max_distance)
holder.IMove(get_step_towards(holder, A))
holder.face_atom(A)
else if(prob(25)) /// Let's not yakkity sax too hard
step_rand(holder)
holder.face_atom(A)
/datum/ai_holder/simple_mob/xeno_alien/empress /// Big mama
ignore_incapacitated = TRUE /// Focus on better threats.
intelligence_level = AI_SMART /// She's got the brains
can_telegrab = TRUE
tele_range_min = 1
tele_range_max = 5 /// Give a chance to run if you've just spotted her.

View File

@@ -29,18 +29,28 @@
attack_sound = 'sound/weapons/bladeslice.ogg'
ai_holder_type = /datum/ai_holder/simple_mob/xeno_alien /// Found in xeno_alien_ai.dm
special_attack_min_range = 3
special_attack_min_range = 1
special_attack_max_range = 7
var/special_attack_distance = 1 /// Special cases for drone subtype that doesn't want to get close.
special_attack_cooldown = 5 SECONDS
var/teleport_distance = 1 /// How far away to be when we teleport.
special_attack_cooldown = 7 SECONDS
var/obj/effect/overlay/skathari_telegrab/displacement_warning = null
/mob/living/simple_mob/animal/space/alien/do_special_attack(atom/A)
. = TRUE
switch(a_intent)
if(I_DISARM)
xeno_teleport(A)
if(I_GRAB)
xeno_telegrab()
/mob/living/simple_mob/animal/space/alien/proc/xeno_teleport(atom/target)
/// Copied MOSTLY from bluespace slime's do_special_attack
if(!A)
if(!target)
to_chat(src, span("warning", "There's nothing to teleport to."))
return FALSE
var/list/nearby_things = range(special_attack_distance, A)
var/list/nearby_things = range(teleport_distance, target)
var/list/valid_turfs = list()
// Check tile density and distance.
@@ -51,7 +61,7 @@
for(var/atom/movable/AM in potential_turf)
if(AM.density)
valid_turf = FALSE
if(get_dist(potential_turf, A) != special_attack_distance) /// We want to maintain an acceptable distance.
if(get_dist(potential_turf, target) != teleport_distance) /// We want to maintain an acceptable distance.
valid_turf = FALSE
if(!can_see(src, potential_turf, 7)) /// We don't want to teleport out of sight!
valid_turf = FALSE
@@ -81,8 +91,62 @@
target_turf.visible_message(span("warning", "\The [src] appears!"))
s2.start()
if(Adjacent(A))
attack_target(A)
if(Adjacent(target))
attack_target(target)
/mob/living/simple_mob/animal/space/alien/proc/xeno_telegrab() /// Fair bit of copy from adv. gygax's electrical defense
set waitfor = FALSE
/// Create list of potential teleport spots.
var/list/nearby_things = range(7, src)
var/list/valid_turfs = list()
for(var/turf/potential_turf in nearby_things)
var/valid_turf = TRUE
if(potential_turf.density)
continue
for(var/atom/movable/AM in potential_turf)
if(AM.density)
valid_turf = FALSE
if(get_dist(potential_turf, src) <= 5) /// Get them a decent distance away!
valid_turf = FALSE
if(valid_turf)
valid_turfs.Add(potential_turf)
if(valid_turfs.len < 1)
return /// Nowhere to teleport them to!
displacement_warning = new(loc)
for(var/i = 1 to 3)
var/turf/T = get_turf(src)
if(get_turf(displacement_warning) != T)
displacement_warning.forceMove(T)
displacement_warning.set_light(i/2, i/2, "#2a84b9")
for(var/thing in range(3, src))
if(isliving(thing) || istype(thing, /obj/mecha))
var/mob/living/L = thing
if(L == src)
continue
if(L.stat)
continue
var/turf/target_turf = pick(valid_turfs)
var/datum/effect_system/spark_spread/sparks = new /datum/effect_system/spark_spread
sparks.set_up(5, 1, target_turf)
L.forceMove(target_turf)
to_chat(L, span("warning", "You were displaced to \the [target_turf]!"))
playsound(target_turf, 'sound/effects/phasein.ogg', 50, 1)
target_turf.visible_message(span("warning", "\The [src] appears suddenly!"))
sparks.start()
if(L && L.has_AI()) // Some mobs delete themselves when dying.
L.ai_holder.react_to_attack(src)
sleep(1 SECOND)
visible_message(span("warning", "\The [displacement_warning] pulses, displacing those nearby!"))
playsound(src, 'sound/effects/cascade.ogg', 100, 1, extrarange = 30)
qdel(displacement_warning)
sleep(1 SECOND)
/mob/living/simple_mob/animal/space/alien/death()
var/turf/center = get_turf(src)
@@ -96,6 +160,8 @@
)
new /obj/effect/decal/cleanable/blood/skathari (center)
new /obj/effect/temp_visual/bluespace_tear (center)
if(displacement_warning)
qdel(displacement_warning)
qdel(src)
..()
@@ -112,8 +178,7 @@
melee_damage_upper = 20
projectiletype = /obj/item/projectile/energy/skathari
ai_holder_type = /datum/ai_holder/simple_mob/xeno_alien/ranged
special_attack_min_range = 1 /// We want to move away quickly!
special_attack_distance = 5 /// Puts us right in the middle of our acceptable range.
teleport_distance = 5 /// Puts us right in the middle of our acceptable range.
/mob/living/simple_mob/animal/space/alien/queen/empress/mother
@@ -131,13 +196,13 @@
melee_damage_upper = 25
movement_cooldown = 8
projectiletype = /obj/item/projectile/energy/skathari
ai_holder_type = /datum/ai_holder/simple_mob/xeno_alien/empress
pixel_x = -32
old_x = -32
icon_expected_width = 96
icon_expected_height = 96
special_attack_distance = 3 /// Will encourage mix of ranged and melee attacks.
teleport_distance = 3 /// Will encourage mix of ranged and melee attacks.
/decl/mob_organ_names/skathari
hit_zones = list("carapace", "abdomen", "left forelegs", "right forelegs", "left hind legs", "right hind legs", "head")