-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
retaliate.dm
59 lines (51 loc) · 1.67 KB
/
retaliate.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/mob/living/simple_animal/hostile/retaliate
///A list of weakrefs pointing at things that we consider targets
var/list/enemies = list()
/mob/living/simple_animal/hostile/retaliate/Found(atom/A)
if(isliving(A))
var/mob/living/L = A
if(!L.stat)
return L
else
enemies -= WEAKREF(L)
else if(ismecha(A))
var/obj/vehicle/sealed/mecha/M = A
if(LAZYLEN(M.occupants))
return A
/mob/living/simple_animal/hostile/retaliate/ListTargets()
if(!enemies.len)
return list()
var/list/see = ..()
var/list/actual_enemies = list()
for(var/datum/weakref/enemy as anything in enemies)
var/mob/flesh_and_blood = enemy.resolve()
if(!flesh_and_blood)
enemies -= enemy
continue
actual_enemies += flesh_and_blood
see &= actual_enemies // Remove all entries that aren't in enemies
return see
/mob/living/simple_animal/hostile/retaliate/proc/Retaliate()
var/list/around = view(src, vision_range)
for(var/atom/movable/A in around)
if(A == src)
continue
if(isliving(A))
var/mob/living/M = A
if(faction_check_mob(M) && attack_same || !faction_check_mob(M))
enemies |= WEAKREF(M)
else if(ismecha(A))
var/obj/vehicle/sealed/mecha/M = A
if(LAZYLEN(M.occupants))
enemies |= WEAKREF(M)
add_enemies(M.occupants)
for(var/mob/living/simple_animal/hostile/retaliate/H in around)
if(faction_check_mob(H) && !attack_same && !H.attack_same)
H.enemies |= enemies
/mob/living/simple_animal/hostile/retaliate/adjustHealth(amount, updating_health = TRUE, forced = FALSE)
. = ..()
if(. > 0 && stat == CONSCIOUS)
Retaliate()
/mob/living/simple_animal/hostile/retaliate/proc/add_enemies(new_enemies)
for(var/new_enemy in new_enemies)
enemies |= WEAKREF(new_enemy)