mirror of
https://github.com/PolarisSS13/Polaris.git
synced 2026-01-02 05:23:01 +00:00
Rewrote targeting.
This commit is contained in:
12
code/modules/projectiles/targeting/targeting_client.dm
Normal file
12
code/modules/projectiles/targeting/targeting_client.dm
Normal file
@@ -0,0 +1,12 @@
|
||||
//These are called by the on-screen buttons, adjusting what the victim can and cannot do.
|
||||
/client/proc/add_gun_icons()
|
||||
if(!usr) return 1 // This can runtime if someone manages to throw a gun out of their hand before the proc is called.
|
||||
screen |= usr.item_use_icon
|
||||
screen |= usr.gun_move_icon
|
||||
screen |= usr.radio_use_icon
|
||||
|
||||
/client/proc/remove_gun_icons()
|
||||
if(!usr) return 1 // Runtime prevention on N00k agents spawning with SMG
|
||||
screen -= usr.item_use_icon
|
||||
screen -= usr.gun_move_icon
|
||||
screen -= usr.radio_use_icon
|
||||
21
code/modules/projectiles/targeting/targeting_gun.dm
Normal file
21
code/modules/projectiles/targeting/targeting_gun.dm
Normal file
@@ -0,0 +1,21 @@
|
||||
//Removing the lock and the buttons.
|
||||
/obj/item/weapon/gun/dropped(var/mob/living/user)
|
||||
if(istype(user))
|
||||
user.stop_aiming(src)
|
||||
return ..()
|
||||
|
||||
/obj/item/weapon/gun/equipped(var/mob/living/user, var/slot)
|
||||
if(istype(user) && (slot != slot_l_hand && slot != slot_r_hand))
|
||||
user.stop_aiming(src)
|
||||
return ..()
|
||||
|
||||
//Compute how to fire.....
|
||||
//Return 1 if a target was found, 0 otherwise.
|
||||
/obj/item/weapon/gun/proc/PreFire(var/atom/A, var/mob/living/user, var/params)
|
||||
if(!user.aiming)
|
||||
user.aiming = new(user)
|
||||
user.face_atom(A)
|
||||
if(ismob(A) && user.aiming)
|
||||
user.aiming.aim_at(A, src)
|
||||
return 1
|
||||
return 0
|
||||
44
code/modules/projectiles/targeting/targeting_mob.dm
Normal file
44
code/modules/projectiles/targeting/targeting_mob.dm
Normal file
@@ -0,0 +1,44 @@
|
||||
/mob/living/var/obj/aiming_overlay/aiming
|
||||
/mob/living/var/list/aimed = list()
|
||||
|
||||
/mob/living/proc/stop_aiming(var/obj/item/thing, var/no_message = 0)
|
||||
if(!aiming)
|
||||
aiming = new(src)
|
||||
if(thing && aiming.aiming_with != thing)
|
||||
return
|
||||
aiming.cancel_aiming(no_message)
|
||||
|
||||
/mob/living/death(gibbed,deathmessage="seizes up and falls limp...")
|
||||
if(..())
|
||||
stop_aiming(no_message=1)
|
||||
|
||||
/mob/living/update_canmove()
|
||||
..()
|
||||
if(lying)
|
||||
stop_aiming(no_message=1)
|
||||
|
||||
/mob/living/Weaken(amount)
|
||||
stop_aiming(no_message=1)
|
||||
..()
|
||||
|
||||
/mob/living/Destroy()
|
||||
if(aiming)
|
||||
qdel(aiming)
|
||||
aiming = null
|
||||
aimed.Cut()
|
||||
return ..()
|
||||
|
||||
/turf/Enter(var/mob/living/mover)
|
||||
. = ..()
|
||||
if(istype(mover))
|
||||
if(mover.aiming && mover.aiming.aiming_at)
|
||||
mover.aiming.update_aiming()
|
||||
if(mover.aimed.len)
|
||||
mover.trigger_aiming(TARGET_CAN_MOVE)
|
||||
|
||||
/mob/living/forceMove(var/atom/destination)
|
||||
. = ..()
|
||||
if(aiming && aiming.aiming_at)
|
||||
aiming.update_aiming()
|
||||
if(aimed.len)
|
||||
trigger_aiming(TARGET_CAN_MOVE)
|
||||
213
code/modules/projectiles/targeting/targeting_overlay.dm
Normal file
213
code/modules/projectiles/targeting/targeting_overlay.dm
Normal file
@@ -0,0 +1,213 @@
|
||||
/obj/aiming_overlay
|
||||
name = "target indicator"
|
||||
desc = "Stick 'em up!"
|
||||
icon = 'icons/effects/Targeted.dmi'
|
||||
icon_state = "locking"
|
||||
anchored = 1
|
||||
density = 0
|
||||
opacity = 0
|
||||
layer = FLY_LAYER
|
||||
simulated = 0
|
||||
|
||||
var/mob/living/aiming_at // Who are we currently targeting, if anyone?
|
||||
var/obj/item/aiming_with // What are we targeting with?
|
||||
var/mob/owner // Who do we belong to?
|
||||
var/locked = 0 // Have we locked on?
|
||||
var/lock_time = 0 // When -will- we lock on?
|
||||
var/active = 0 // Is our owner intending to take hostages?
|
||||
var/target_permissions = 0 // Permission bitflags.
|
||||
|
||||
/obj/aiming_overlay/New(var/newowner)
|
||||
..()
|
||||
owner = newowner
|
||||
loc = null
|
||||
|
||||
/obj/aiming_overlay/proc/toggle_permission(var/perm)
|
||||
|
||||
if(target_permissions & perm)
|
||||
target_permissions &= ~perm
|
||||
else
|
||||
target_permissions |= perm
|
||||
|
||||
// Update HUD icons.
|
||||
if(owner.gun_move_icon)
|
||||
if(!(target_permissions & TARGET_CAN_MOVE))
|
||||
owner.gun_move_icon.icon_state = "no_walk0"
|
||||
owner.gun_move_icon.name = "Allow Movement"
|
||||
else
|
||||
owner.gun_move_icon.icon_state = "no_walk1"
|
||||
owner.gun_move_icon.name = "Disallow Movement"
|
||||
|
||||
if(owner.item_use_icon)
|
||||
if(!(target_permissions & TARGET_CAN_CLICK))
|
||||
owner.item_use_icon.icon_state = "no_item0"
|
||||
owner.item_use_icon.name = "Allow Item Use"
|
||||
else
|
||||
owner.item_use_icon.icon_state = "no_item1"
|
||||
owner.item_use_icon.name = "Disallow Item Use"
|
||||
|
||||
if(owner.radio_use_icon)
|
||||
if(!(target_permissions & TARGET_CAN_RADIO))
|
||||
owner.radio_use_icon.icon_state = "no_radio0"
|
||||
owner.radio_use_icon.name = "Allow Radio Use"
|
||||
else
|
||||
owner.radio_use_icon.icon_state = "no_radio1"
|
||||
owner.radio_use_icon.name = "Disallow Radio Use"
|
||||
|
||||
var/message = "no longer permitted to "
|
||||
var/use_span = "warning"
|
||||
if(target_permissions & perm)
|
||||
message = "now permitted to "
|
||||
use_span = "notice"
|
||||
|
||||
switch(perm)
|
||||
if(TARGET_CAN_MOVE)
|
||||
message += "move"
|
||||
if(TARGET_CAN_CLICK)
|
||||
message += "use items"
|
||||
if(TARGET_CAN_RADIO)
|
||||
message += "use a radio"
|
||||
else
|
||||
return
|
||||
|
||||
owner << "<span class='[use_span]'>[aiming_at ? "\The [aiming_at] is" : "Your targets are"] [message].</span>"
|
||||
if(aiming_at)
|
||||
aiming_at << "<span class='[use_span]'>You are [message].</span>"
|
||||
|
||||
/obj/aiming_overlay/process()
|
||||
if(!owner)
|
||||
qdel(src)
|
||||
return
|
||||
..()
|
||||
update_aiming()
|
||||
|
||||
/obj/aiming_overlay/Destroy()
|
||||
if(aiming_at)
|
||||
aiming_at.aimed -= src
|
||||
aiming_at = null
|
||||
owner = null
|
||||
aiming_with = null
|
||||
processing_objects -= src
|
||||
return ..()
|
||||
|
||||
obj/aiming_overlay/proc/update_aiming_deferred()
|
||||
set waitfor = 0
|
||||
sleep(0)
|
||||
update_aiming()
|
||||
|
||||
/obj/aiming_overlay/proc/update_aiming()
|
||||
|
||||
if(!owner)
|
||||
qdel(src)
|
||||
return
|
||||
|
||||
if(!aiming_at)
|
||||
cancel_aiming()
|
||||
return
|
||||
|
||||
if(!locked && lock_time >= world.time)
|
||||
locked = 1
|
||||
update_icon()
|
||||
|
||||
var/cancel_aim = 1
|
||||
if(!(aiming_with in owner) || (owner.l_hand != aiming_with && owner.r_hand != aiming_with))
|
||||
owner << "<span class='warning'>You must keep hold of your weapon!</span>"
|
||||
else if(!aiming_at || !istype(aiming_at.loc, /turf))
|
||||
owner << "<span class='warning'>You have lost sight of your target!</span>"
|
||||
else if(owner.incapacitated() || owner.lying || owner.restrained())
|
||||
owner << "<span class='warning'>You must be conscious and standing to keep track of your target!</span>"
|
||||
else if(aiming_at.alpha == 0 || (aiming_at.invisibility > owner.see_invisible))
|
||||
owner << "<span class='warning'>Your target has become invisible!</span>"
|
||||
else if(get_dist(get_turf(owner), get_turf(aiming_at)) > 7) // !(owner in viewers(aiming_at, 7))
|
||||
owner << "<span class='warning'>Your target is too far away to track!</span>"
|
||||
else
|
||||
cancel_aim = 0
|
||||
|
||||
forceMove(get_turf(aiming_at))
|
||||
|
||||
if(cancel_aim)
|
||||
cancel_aiming()
|
||||
return
|
||||
|
||||
if(!owner.incapacitated() && owner.client)
|
||||
spawn(0)
|
||||
owner.set_dir(get_dir(get_turf(owner), get_turf(src)))
|
||||
|
||||
/obj/aiming_overlay/proc/aim_at(var/mob/target, var/obj/thing)
|
||||
|
||||
if(!owner)
|
||||
return
|
||||
|
||||
if(owner.incapacitated())
|
||||
owner << "<span class='warning'>You cannot aim a gun in your current state.</span>"
|
||||
return
|
||||
if(owner.lying)
|
||||
owner << "<span class='warning'>You cannot aim a gun while prone.</span>"
|
||||
return
|
||||
if(owner.restrained())
|
||||
owner << "<span class='warning'>You cannot aim a gun while handcuffed.</span>"
|
||||
return
|
||||
|
||||
if(aiming_at)
|
||||
if(aiming_at == target)
|
||||
return
|
||||
aiming_at.aimed -= src
|
||||
owner.visible_message("<span class='danger'>\The [owner] turns \the [thing] on \the [target]!</span>")
|
||||
else
|
||||
owner.visible_message("<span class='danger'>\The [owner] aims \the [thing] at \the [target]!</span>")
|
||||
|
||||
if(owner.client)
|
||||
owner.client.add_gun_icons()
|
||||
target << "<span class='danger'>You now have a gun pointed at you. No sudden moves!</span>"
|
||||
aiming_with = thing
|
||||
aiming_at = target
|
||||
if(istype(aiming_with, /obj/item/weapon/gun))
|
||||
playsound(get_turf(owner), 'sound/weapons/TargetOn.ogg', 50,1)
|
||||
forceMove(get_turf(target))
|
||||
processing_objects |= src
|
||||
|
||||
aiming_at.aimed |= src
|
||||
toggle_active(1)
|
||||
locked = 0
|
||||
update_icon()
|
||||
lock_time = world.time + 35
|
||||
|
||||
/obj/aiming_overlay/update_icon()
|
||||
if(locked)
|
||||
icon_state = "locked"
|
||||
else
|
||||
icon_state = "locking"
|
||||
|
||||
/obj/aiming_overlay/proc/toggle_active(var/force_state = null)
|
||||
if(!isnull(force_state))
|
||||
if(active == force_state)
|
||||
return
|
||||
active = force_state
|
||||
else
|
||||
active = !active
|
||||
|
||||
if(!active)
|
||||
cancel_aiming()
|
||||
|
||||
if(owner.client)
|
||||
if(active)
|
||||
owner << "<span class='notice'>You will now aim rather than fire.</span>"
|
||||
owner.client.add_gun_icons()
|
||||
else
|
||||
owner << "<span class='notice'>You will no longer aim rather than fire.</span>"
|
||||
owner.client.remove_gun_icons()
|
||||
|
||||
/obj/aiming_overlay/proc/cancel_aiming(var/no_message = 0)
|
||||
if(!aiming_with || !aiming_at)
|
||||
return
|
||||
if(istype(aiming_with, /obj/item/weapon/gun))
|
||||
playsound(get_turf(owner), 'sound/weapons/TargetOff.ogg', 50,1)
|
||||
if(!no_message)
|
||||
owner.visible_message("<span class='notice'>\The [owner] lowers \the [aiming_with].</span>")
|
||||
|
||||
aiming_with = null
|
||||
aiming_at.aimed -= src
|
||||
aiming_at = null
|
||||
loc = null
|
||||
processing_objects -= src
|
||||
|
||||
29
code/modules/projectiles/targeting/targeting_triggers.dm
Normal file
29
code/modules/projectiles/targeting/targeting_triggers.dm
Normal file
@@ -0,0 +1,29 @@
|
||||
/mob/living/proc/trigger_aiming(var/trigger_type)
|
||||
if(!aimed.len)
|
||||
return
|
||||
for(var/obj/aiming_overlay/AO in aimed)
|
||||
if(AO.aiming_at == src)
|
||||
AO.update_aiming()
|
||||
if(AO.aiming_at == src)
|
||||
AO.trigger(trigger_type)
|
||||
AO.update_aiming_deferred()
|
||||
|
||||
/obj/aiming_overlay/proc/trigger(var/perm)
|
||||
if(!owner || !aiming_with || !aiming_at || !locked)
|
||||
return
|
||||
if(perm && (target_permissions & perm))
|
||||
return
|
||||
if(!owner.canClick())
|
||||
return
|
||||
owner.setClickCooldown(5) // Spam prevention, essentially.
|
||||
if(owner.a_intent == I_HELP)
|
||||
owner << "<span class='warning'>You refrain from firing \the [aiming_with] as your intent is set to help.</span>"
|
||||
return
|
||||
owner.visible_message("<span class='danger'>\The [owner] pulls the trigger reflexively!</span>")
|
||||
var/obj/item/weapon/gun/G = aiming_with
|
||||
if(istype(G))
|
||||
G.Fire(aiming_at, owner)
|
||||
|
||||
/mob/living/ClickOn(var/atom/A, var/params)
|
||||
. = ..()
|
||||
trigger_aiming(TARGET_CAN_CLICK)
|
||||
Reference in New Issue
Block a user