Skip to content

Commit bc43ed4

Browse files
authored
Add logging for mobs being bumped into grille/suppermatter (vgstation-coders#37563)
* Add logging for mobs being bumped into grille/suppermatter * rust * Fixes things + weakrefs
1 parent 19e45d4 commit bc43ed4

File tree

5 files changed

+47
-9
lines changed

5 files changed

+47
-9
lines changed

code/__HELPERS/mobs.dm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,13 @@ Proc for attack log creation, because really why not
243243

244244
/proc/add_logs(mob/user, mob/target, what_done, var/admin=1, var/object=null, var/addition=null)
245245
if(user && ismob(user))
246-
user.attack_log += text("\[[time_stamp()]\] <font color='red'>Has [what_done] [target ? "[target.name][(ismob(target) && target.ckey) ? "([target.ckey])" : ""]" : "NON-EXISTANT SUBJECT"][object ? " with [object]" : " "]. [addition]</font>")
246+
user.attack_log += "\[[time_stamp()]\] Has [what_done] [target ? "[target.name][(ismob(target) && target.ckey) ? "([target.ckey])" : ""]" : "NON-EXISTANT SUBJECT"][object ? " with [object]" : " "]. [addition]"
247247
if(target && ismob(target))
248-
target.attack_log += text("\[[time_stamp()]\] <font color='orange'>Has been [what_done] by [user ? "[user.name][(ismob(user) && user.ckey) ? "([user.ckey])" : ""]" : "NON-EXISTANT SUBJECT"][object ? " with [object]" : " "]. [addition]</font>")
248+
target.attack_log += "\[[time_stamp()]\] Has been [what_done] by [user ? "[user.name][(ismob(user) && user.ckey) ? "([user.ckey])" : ""]" : "NON-EXISTANT SUBJECT"][object ? " with [object]" : " "]. [addition]"
249249
target.assaulted_by(user)
250250
if(admin)
251251
log_attack("<font color='red'>[user ? "[user.name][(ismob(user) && user.ckey) ? "([user.ckey])" : ""]" : "NON-EXISTANT SUBJECT"] [what_done] [target ? "[target.name][(ismob(target) && target.ckey)? "([target.ckey])" : ""]" : "NON-EXISTANT SUBJECT"][object ? " with [object]" : " "]. [addition]</font>")
252+
message_admins("[user ? "[user.name][(ismob(user) && user.ckey) ? "([user.ckey])" : ""]" : "NON-EXISTANT SUBJECT"] <font color='red'>[what_done]</font> [target ? "[target.name][(ismob(target) && target.ckey)? "([target.ckey])" : ""]" : "NON-EXISTANT SUBJECT"][object ? " with [object]" : " "]. [addition][formatJumpTo(target)]")
252253

253254
/proc/add_ghostlogs(var/mob/user, var/obj/target, var/what_done, var/admin=1, var/addition=null)
254255
var/target_text = "NON-EXISTENT TARGET"

code/game/objects/structures/grille.dm

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,19 @@
7676

7777
/obj/structure/grille/Bumped(atom/user)
7878
if(ismob(user))
79-
shock(user, 60) //Give the user the benifit of the doubt
79+
var/mob/M = user
80+
var/damage_dealt = shock(M, 60) //Give the user the benifit of the doubt
81+
if (damage_dealt && M.client)
82+
if(M.pulledby)
83+
add_logs(M.pulledby, M, "pulled into a shocked grille", TRUE, src, get_coordinates_string(src))
84+
else if(M.last_bumped_by_timestamp - 0.1 SECONDS <= world.time <= M.last_bumped_by_timestamp + 0.1 SECONDS) // If got bumped into a grille
85+
var/mob/hostile = M.last_bumped_by.get()
86+
add_logs(hostile, M, "bumped into a shocked grille", TRUE, src, get_coordinates_string(src))
87+
else if(M.last_thrown_by_timestamp - 0.1 SECONDS <= world.time <= M.last_thrown_by_timestamp + 2 SECONDS) // If got thrown into a grille
88+
var/mob/hostile = M.last_thrown_by.get()
89+
add_logs(hostile, src, "thrown into a shocked grilled", TRUE, src, get_coordinates_string(src))
90+
else
91+
M.attack_log += "\[[time_stamp()]\]: walked into a shocked grille (no bumper/no pusher)"
8092

8193
/obj/structure/grille/hitby(var/atom/movable/AM)
8294
. = ..()

code/modules/mob/living/living.dm

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,8 @@ Thanks.
13691369
var/mob/M = AM
13701370
INVOKE_EVENT(src, /event/before_move)
13711371
step(M, t)
1372+
M.last_bumped_by = makeweakref(src)
1373+
M.last_bumped_by_timestamp = world.time
13721374
INVOKE_EVENT(src, /event/after_move)
13731375
else
13741376
step(AM, t)
@@ -1535,11 +1537,14 @@ Thanks.
15351537
var/start_T_descriptor = "<font color='#6b5d00'>tile at [start_T.x], [start_T.y], [start_T.z] in area [get_area(start_T)]</font>"
15361538
var/end_T_descriptor = "<font color='#6b4400'>tile at [end_T.x], [end_T.y], [end_T.z] in area [get_area(end_T)]</font>"
15371539

1538-
M.attack_log += text("\[[time_stamp()]\] <font color='orange'>Has been thrown by [usr.name] ([usr.ckey]) from [start_T_descriptor] with the target [end_T_descriptor]</font>")
1539-
usr.attack_log += text("\[[time_stamp()]\] <font color='red'>Has thrown [M.name] ([M.ckey]) from [start_T_descriptor] with the target [end_T_descriptor]</font>")
1540+
M.attack_log += text("\[[time_stamp()]\] <font color='orange'>Has been thrown by [src.name] ([src.ckey]) from [start_T_descriptor] with the target [end_T_descriptor]</font>")
1541+
src.attack_log += text("\[[time_stamp()]\] <font color='red'>Has thrown [M.name] ([M.ckey]) from [start_T_descriptor] with the target [end_T_descriptor]</font>")
15401542

1541-
log_attack("<font color='red'>[usr.name] ([usr.ckey]) Has thrown [M.name] ([M.ckey]) from [start_T_descriptor] with the target [end_T_descriptor]</font>")
1542-
M.assaulted_by(usr)
1543+
M.last_thrown_by = makeweakref(src)
1544+
M.last_thrown_by_timestamp = world.time
1545+
1546+
log_attack("<font color='red'>[src.name] ([src.ckey]) Has thrown [M.name] ([M.ckey]) from [start_T_descriptor] with the target [end_T_descriptor]</font>")
1547+
M.assaulted_by(src)
15431548
qdel(G)
15441549
if(!item)
15451550
return FAILED_THROW //Grab processing has a chance of returning null

code/modules/mob/mob.dm

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272

7373
if (ticker && ticker.mode)
7474
ticker.mode.mob_destroyed(src)
75+
QDEL_NULL(last_thrown_by)
76+
QDEL_NULL(last_bumped_by)
77+
QDEL_NULL(lastassailant)
7578
..()
7679

7780
/mob/projectile_check()
@@ -1877,7 +1880,17 @@ Use this proc preferably at the end of an equipment loadout
18771880
if(SS)
18781881
SS.supermatter_act(source)
18791882
else
1880-
1883+
if (client)
1884+
if(pulledby) // If we have a client, we add attack logs
1885+
add_logs(pulledby, src, "pulled into a suppermatter object", TRUE, source, get_coordinates_string(source))
1886+
else if(last_bumped_by_timestamp - 0.1 SECONDS <= world.time <= last_bumped_by_timestamp + 0.1 SECONDS) // If got bumped into a supermatter
1887+
var/mob/hostile = last_bumped_by.get()
1888+
add_logs(hostile, src, "bumped into a supermatter object", TRUE, source, get_coordinates_string(source))
1889+
else if(last_thrown_by_timestamp - 0.1 SECONDS <= world.time <= last_thrown_by_timestamp + 2 SECONDS) // If got thrown into a supermatter
1890+
var/mob/hostile = last_thrown_by.get()
1891+
add_logs(hostile, src, "thrown into a supermatter object", TRUE, source, get_coordinates_string(source))
1892+
else
1893+
attack_log += "\[[time_stamp()]\]: walked into supermatter (no bumper/no pusher)"
18811894
if(severity == SUPERMATTER_DUST)
18821895
dust()
18831896
return 1

code/modules/mob/mob_defines.dm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,11 @@
296296

297297
var/list/huds = list() // List of active huds on a mob
298298

299-
var/is_dexterous = FALSE //allows mobs to be made dextrous, mostly for monkeys
299+
var/is_dexterous = FALSE //allows mobs to be made dextrous, mostly for monkeys
300+
301+
// Log things.
302+
var/datum/weakref/last_bumped_by = null // weakrefs
303+
var/last_bumped_by_timestamp = -INFINITY
304+
305+
var/datum/weakref/last_thrown_by = null // weakrefs
306+
var/last_thrown_by_timestamp = -INFINITY

0 commit comments

Comments
 (0)