Skip to content

Commit ec12dd5

Browse files
Makes gun targeting actually work with item and vehicle usage (#36997)
* initial commit * removes this, it works * feedback cleanup * vanquishes usr * catching this * client checks are back too * redundant * adds this here too * clarification * update syntax * for the user too * specifies * fix * compiles * clearer
1 parent 0a6c20d commit ec12dd5

File tree

8 files changed

+65
-48
lines changed

8 files changed

+65
-48
lines changed

code/_hooks/events.dm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
// atom/movable/mover: the movable itself.
2727
/event/moved
2828

29+
// Called whenever an /atom/movable relay-moves.
30+
// Arguments:
31+
// atom/movable/mover: the movable itself.
32+
/event/relaymoved
33+
2934
// Called right before an /atom/movable attempts to move or change dir.
3035
/event/before_move
3136

code/game/atoms.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ its easier to just keep the beam vertical.
511511
bug.removed(usr)
512512

513513
/atom/proc/relaymove()
514-
return
514+
INVOKE_EVENT(src, /event/relaymoved, "mover" = src)
515515

516516
// Try to override a mob's eastface(), westface() etc. (CTRL+RIGHTARROW, CTRL+LEFTARROW). Return 1 if successful, which blocks the mob's own eastface() etc.
517517
// Called first on the mob's loc (turf, locker, mech), then on whatever the mob is buckled to, if anything.

code/game/mecha/mecha.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@
355355
//////////////////////////////////
356356

357357
/obj/mecha/relaymove(mob/user,direction)
358+
..()
358359
if(user != src.occupant) //While not "realistic", this piece is player friendly.
359360
user.forceMove(get_turf(src))
360361
to_chat(user, "You climb out from [src]")

code/game/objects/structures/vehicles/vehicle.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184

185185

186186
/obj/structure/bed/chair/vehicle/relaymove(var/mob/living/user, direction)
187+
..()
187188
if(user.incapacitated())
188189
unlock_atom(user)
189190
return

code/modules/mob/mob_movement.dm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@
351351
var/old_dir = mob.dir
352352

353353
mob.delayNextMove(move_delay)
354-
mob.last_move_intent = world.time + 10
355354
mob.set_glide_size(DELAY2GLIDESIZE(move_delay)) //Since we're moving OUT OF OUR OWN VOLITION AND BY OURSELVES we can update our glide_size here!
356355

357356
INVOKE_EVENT(mob, /event/before_move)

code/modules/projectiles/gun.dm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
var/tmp/lock_time = -100
5555
var/mouthshoot = 0 ///To stop people from suiciding twice... >.>
5656
var/automatic = 0 //Used to determine if you can target multiple people.
57-
var/tmp/mob/living/last_moved_mob //Used to fire faster at more than one person.
5857
var/tmp/told_cant_shoot = 0 //So that it doesn't spam them with the fact they cannot hit them.
5958
var/firerate = 1 // 0 for one bullet after tarrget moves and aim is lowered,
6059
//1 for keep shooting until aim is lowered

code/modules/projectiles/projectile.dm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,11 @@ var/list/impact_master = list()
778778
return //cannot shoot yourself
779779
if(istype(A, /obj/item/projectile))
780780
return
781-
if(istype(A, /mob/living))
782-
result = 2 //We hit someone, return 1!
783-
return
781+
if(ismovable(A))
782+
var/atom/movable/AM = A
783+
if(isliving(AM) || (locate(/mob/living) in AM) || (locate(/mob/living) in AM.locked_atoms))
784+
result = 2 //We hit someone, return 1!
785+
return
784786
result = 1
785787
return
786788

code/modules/projectiles/targeting.dm

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,35 @@
7676
M.Targeted(src)
7777

7878
//HE MOVED, SHOOT HIM!
79-
/obj/item/weapon/gun/proc/TargetActed(var/mob/living/T)
80-
var/mob/living/M = loc
81-
if(M == T)
79+
/obj/item/weapon/gun/proc/TargetMoved(mob/living/mover)
80+
TargetActed(mover) //alias just so events work
81+
82+
/obj/item/weapon/gun/proc/TargetActed(mob/living/user,modifiers,atom/target)
83+
if(world.time <= lock_time)
8284
return
83-
if(!istype(M))
85+
if(target && (isturf(target) || istype(target,/obj/abstract/screen))) // these are okay to click
8486
return
85-
if(src != M.get_active_hand())
87+
lock_time = world.time + 15
88+
//if(last_moved_mob == user) //If they were the last ones to move, give them more of a grace period, so that an automatic weapon can hold down a room better.
89+
//lock_time = world.time + 15 //just look at the logic of this... it did nothing!!! uncomment if you want this to work again too. be sure to add the variable back.
90+
var/mob/living/M = loc
91+
if(M == user || !istype(M))
92+
return
93+
if(!M.client || src != M.get_active_hand())
8694
stop_aim()
8795
return
88-
M.last_move_intent = world.time
96+
if(M.client.target_can_click && target) // this var only gets filled in from the click event calls, so that's a way of knowing
97+
return
98+
if(M.client.target_can_move)
99+
if(!M.client.target_can_run && !user.locked_to && user.m_intent != "run") // if the user is relaymoving i'm pretty sure that's NOT walking
100+
return
101+
else if(!target)
102+
return
89103
if(canbe_fired())
90-
var/firing_check = can_hit(T,usr) //0 if it cannot hit them, 1 if it is capable of hitting, and 2 if a special check is preventing it from firing.
104+
var/firing_check = can_hit(user,M) //0 if it cannot hit them, 1 if it is capable of hitting, and 2 if a special check is preventing it from firing.
91105
if(firing_check > 0)
92106
if(firing_check == 1)
93-
Fire(T,usr, reflex = 1)
107+
Fire(user,M, reflex = 1)
94108
else if(!told_cant_shoot)
95109
to_chat(M, "<span class='warning'>They can't be hit from here!</span>")
96110
told_cant_shoot = 1
@@ -99,10 +113,10 @@
99113
else
100114
click_empty(M)
101115

102-
usr.dir = get_cardinal_dir(src, T)
116+
M.dir = get_cardinal_dir(src, user)
103117

104118
if (!firerate) // If firerate is set to lower aim after one shot, untarget the target
105-
T.NotTargeted(src)
119+
user.NotTargeted(src)
106120

107121
/proc/GunTrace(X1,Y1,X2,Y2,Z=1,exc_obj,PX1=16,PY1=16,PX2=16,PY2=16)
108122
// to_chat(bluh, "Tracin' [X1],[Y1] to [X2],[Y2] on floor [Z].")
@@ -153,9 +167,6 @@
153167
//Targeting management procs
154168
/mob
155169
var/list/targeted_by
156-
var/target_time = -100
157-
var/last_move_intent = -100
158-
var/last_target_click = -5
159170
var/target_locked = null
160171

161172
/mob/living/proc/Targeted(var/obj/item/weapon/gun/I) //Self explanitory.
@@ -176,10 +187,6 @@
176187
targeted_by = list()
177188
targeted_by += I
178189
I.lock_time = world.time + 20 //Target has 2 second to realize they're targeted and stop (or target the opponent).
179-
to_chat(src, "((<span class='danger'>Your character is being targeted. They have 2 seconds to stop any click or move actions. </span>While targeted, they may \
180-
drag and drop items in or into the map, speak, and click on interface buttons. Clicking on the map objects (floors and walls are fine), their items \
181-
(other than a weapon to de-target), or moving will result in being fired upon. <span class='warning'>The aggressor may also fire manually, </span>\
182-
so try not to get on their bad side.\black ))")
183190

184191
if(targeted_by.len == 1)
185192
spawn(0)
@@ -199,34 +206,37 @@
199206
else
200207
I.lower_aim()
201208
return
202-
if(m_intent == "run" && T.client.target_can_move == 1 && T.client.target_can_run == 0 && (ishuman(T)))
203-
to_chat(src, "<spanclass='warning'>Your captive is allowing you to walk. Make sure to change your move intent to walk before trying to move, or you will be fired upon.</span>")//Self explanitory.
204-
209+
var/msg = ""
210+
if(!T.client.target_can_click)
211+
msg += "While targeted, they may drag and drop items in or into the map, speak, and click on interface buttons. \
212+
Clicking on the map objects (floors and walls are fine), their items (other than a weapon to de-target) will result in being fired upon.\n"
213+
if(!T.client.target_can_move)
214+
msg += "Moving will result in being fired upon.\n"
215+
else if(m_intent == "run" && !T.client.target_can_run && (ishuman(T))) //Self explanitory.
216+
msg += "<span class='warning'>Your captive is allowing you to walk. \
217+
Make sure to change your move intent to walk before trying to move, or you will be fired upon.</span>\n"
218+
to_chat(src, "<span class='danger'>Your character is being targeted. They have 2 seconds to stop any of the following actions: </span>\n \
219+
[msg]\n \
220+
<span class='warning'>The aggressor may also fire manually, so try not to get on their bad side.</span>")
221+
205222
//set_m_intent("walk") -there's a real fucked up exploit behind this, so it's been removed. Needs testing. -Angelite-
206-
207-
//Processing the aiming. Should be probably in separate object with process() but lasy.
208-
while(targeted_by && T.client)
209-
if((last_move_intent > I.lock_time + 10) && !T.client.target_can_move) //If target moved when not allowed to
210-
I.TargetActed(src)
211-
if(I.last_moved_mob == src) //If they were the last ones to move, give them more of a grace period, so that an automatic weapon can hold down a room better.
212-
I.lock_time = world.time + 5
213-
I.lock_time = world.time + 5
214-
I.last_moved_mob = src
215-
else if((last_move_intent > I.lock_time + 10) && !T.client.target_can_run && m_intent == "run") //If the target ran while targeted
216-
I.TargetActed(src)
217-
if(I.last_moved_mob == src) //If they were the last ones to move, give them more of a grace period, so that an automatic weapon can hold down a room better.
218-
I.lock_time = world.time + 5
219-
I.lock_time = world.time + 5
220-
I.last_moved_mob = src
221-
if((last_target_click > I.lock_time + 10) && !T.client.target_can_click) //If the target clicked the map to pick something up/shoot/etc
222-
I.TargetActed(src)
223-
if(I.last_moved_mob == src) //If they were the last ones to move, give them more of a grace period, so that an automatic weapon can hold down a room better.
224-
I.lock_time = world.time + 5
225-
I.lock_time = world.time + 5
226-
I.last_moved_mob = src
227-
sleep(1)
223+
224+
if(!T.client.target_can_move || !T.client.target_can_run)
225+
register_event(/event/moved, I, nameof(I::TargetMoved()))
226+
register_event(/event/relaymoved, I, nameof(I::TargetMoved()))
227+
if(!T.client.target_can_click)
228+
register_event(/event/clickon, I, nameof(I::TargetActed()))
229+
register_event(/event/logout, T, nameof(src::TargeterLogout()))
230+
231+
/mob/living/proc/TargeterLogout(mob/living/user)
232+
for(var/obj/item/weapon/gun/G in user)
233+
NotTargeted(G)
234+
unregister_event(/event/logout, user, nameof(src::TargeterLogout()))
228235

229236
/mob/living/proc/NotTargeted(var/obj/item/weapon/gun/I)
237+
unregister_event(/event/moved, I, nameof(I::TargetMoved()))
238+
unregister_event(/event/relaymoved, I, nameof(I::TargetMoved()))
239+
unregister_event(/event/clickon, I, nameof(I::TargetActed()))
230240
if(!I.silenced)
231241
for(var/mob/living/M in viewers(src))
232242
M << 'sound/weapons/TargetOff.ogg'

0 commit comments

Comments
 (0)