Skip to content

Commit

Permalink
more fullauto things
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmunora committed Jan 6, 2021
1 parent bd9a0fd commit 6b5d58a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 25 deletions.
4 changes: 4 additions & 0 deletions _std/defines/component_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
#define COMSIG_ITEM_ATTACK_PRE "itm_atk_pre"
/// When an item is used in-hand
#define COMSIG_ITEM_ATTACK_SELF "itm_atk_self"
/// When an item is swapped to [does not include being picked up/taken out of bags/etc] (user)
#define COMSIG_ITEM_SWAP_TO "itm_swap_to"
/// When an item is swapped away from [does not include being picked up/taken out of bags/etc] (user)
#define COMSIG_ITEM_SWAP_AWAY "itm_swap_away"

// ---- implant signals ----
/// When implanted
Expand Down
5 changes: 5 additions & 0 deletions _std/defines/projectiles.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@

//default max range for 'unlimited' range projectiles
#define PROJ_INFINITE_RANGE 500

//fullauto stuff
#define FULLAUTO_INACTIVE 0
#define FULLAUTO_ACTIVE 1
#define FULLAUTO_ALWAYS_ACTIVE 2
83 changes: 59 additions & 24 deletions code/datums/components/fullauto.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
var/delaystart
var/delaymin
var/rampfactor
var/toggle = 0
var/list/obj/screen/fullautoAimHUD/hudSquares = list()

Initialize(delaystart = 4 DECI SECONDS, delaymin=1 DECI SECOND, rampfactor=0.9)
Initialize(delaystart = 4 DECI SECONDS, delaymin=1 DECI SECOND, rampfactor=0.9, toggle = FULLAUTO_ALWAYS_ACTIVE)
if(..() == COMPONENT_INCOMPATIBLE || !istype(parent, /obj/item/gun))
return COMPONENT_INCOMPATIBLE
else
src.toggle = toggle
var/obj/item/gun/G = parent
src.delaystart = delaystart
src.delaymin = delaymin
Expand All @@ -43,33 +45,64 @@
hudSquare.xOffset = x
hudSquare.yOffset = y
hudSquares["[x],[y]"] = hudSquare
if(src.toggle != FULLAUTO_ALWAYS_ACTIVE)
RegisterSignal(G, COMSIG_ITEM_ATTACK_SELF, .proc/toggle_fullauto_firemode)

if(ismob(G.loc))
on_pickup(null, G.loc)
if(src.toggle)
RegisterSignal(G, COMSIG_ITEM_SWAP_TO, .proc/init_fullauto_mode)
RegisterSignal(G, COMSIG_ITEM_SWAP_AWAY, .proc/end_fullauto_mode)
if(ismob(G.loc))
on_pickup(null, G.loc)

disposing()
for(var/hudSquare in hudSquares)
qdel(hudSquare)
. = ..()

on_pickup(datum/source, mob/user)
. = ..()
for(var/x in 1 to (istext(user.client?.view) ? WIDE_TILE_WIDTH : SQUARE_TILE_WIDTH))
for(var/y in 1 to 15)
var/obj/screen/fullautoAimHUD/FH = hudSquares["[x],[y]"]
FH.mouse_over_pointer = icon(cursors_selection[user.client?.preferences.target_cursor], "all")
if((y >= 7 && y <= 9) && (x >= ((istext(user.client?.view) ? WIDE_TILE_WIDTH : SQUARE_TILE_WIDTH)+1)/2 - 1 && x <= ((istext(user.client?.view) ? WIDE_TILE_WIDTH : SQUARE_TILE_WIDTH)+1)/2 + 1))
continue
user.client?.screen += hudSquares["[x],[y]"]
stopping = 0
if(toggle)
if(user.equipped() == parent)
init_fullauto_mode(source, user)
. = ..()

on_dropped(datum/source, mob/user)
end_shootloop(user)
for(var/x in 1 to (istext(user.client?.view) ? WIDE_TILE_WIDTH : SQUARE_TILE_WIDTH))
for(var/y in 1 to 15)
user.client?.screen -= hudSquares["[x],[y]"]
end_fullauto_mode(source, user)
. = ..()

/datum/component/holdertargeting/fullauto/proc/toggle_fullauto_firemode(datum/source, mob/user)
src.toggle = !src.toggle
var/obj/item/gun/G = parent
if(toggle)
RegisterSignal(G, COMSIG_ITEM_SWAP_TO, .proc/init_fullauto_mode)
RegisterSignal(G, COMSIG_ITEM_SWAP_AWAY, .proc/end_fullauto_mode)
if(user.equipped() == G)
on_pickup(source, user)
else
UnregisterSignal(G, COMSIG_ITEM_SWAP_TO)
UnregisterSignal(G, COMSIG_ITEM_SWAP_AWAY)
if(user.equipped() == G)
on_dropped(source, user)

/datum/component/holdertargeting/fullauto/proc/init_fullauto_mode(datum/source, mob/user)
for(var/x in 1 to (istext(user.client?.view) ? WIDE_TILE_WIDTH : SQUARE_TILE_WIDTH))
for(var/y in 1 to 15)
var/obj/screen/fullautoAimHUD/FH = hudSquares["[x],[y]"]
FH.mouse_over_pointer = icon(cursors_selection[user.client?.preferences.target_cursor], "all")
if((y >= 7 && y <= 9) && (x >= ((istext(user.client?.view) ? WIDE_TILE_WIDTH : SQUARE_TILE_WIDTH)+1)/2 - 1 && x <= ((istext(user.client?.view) ? WIDE_TILE_WIDTH : SQUARE_TILE_WIDTH)+1)/2 + 1))
continue
user.client?.screen += hudSquares["[x],[y]"]
stopping = 0



/datum/component/holdertargeting/fullauto/proc/end_fullauto_mode(datum/source, mob/user)
end_shootloop(user)
for(var/x in 1 to (istext(user.client?.view) ? WIDE_TILE_WIDTH : SQUARE_TILE_WIDTH))
for(var/y in 1 to 15)
user.client?.screen -= hudSquares["[x],[y]"]



/datum/component/holdertargeting/fullauto/proc/begin_shootloop(mob/living/user, object, location, control, params)
if(!stopping)
src.retarget(user, object, location, control, params)
Expand Down Expand Up @@ -122,17 +155,19 @@
G.suppress_fire_msg = 1
sleep(max(delay*=rampfactor, delaymin))

stopping = 0
shooting = 0

/datum/component/holdertargeting/fullauto/proc/end_shootloop(mob/living/user)
//loop ended - reset values
var/obj/item/gun/G = parent
G.suppress_fire_msg = initial(G.suppress_fire_msg)
UnregisterSignal(L, COMSIG_FULLAUTO_MOUSEDRAG)
UnregisterSignal(L, COMSIG_MOUSEUP)
UnregisterSignal(L, COMSIG_MOVABLE_MOVED)
UnregisterSignal(user, COMSIG_FULLAUTO_MOUSEDRAG)
UnregisterSignal(user, COMSIG_MOUSEUP)
UnregisterSignal(user, COMSIG_MOVABLE_MOVED)

for(var/x in ((istext(L.client?.view) ? WIDE_TILE_WIDTH : SQUARE_TILE_WIDTH)+1)/2 - 1 to ((istext(L.client?.view) ? WIDE_TILE_WIDTH : SQUARE_TILE_WIDTH)+1)/2 + 1)
for(var/x in ((istext(user.client?.view) ? WIDE_TILE_WIDTH : SQUARE_TILE_WIDTH)+1)/2 - 1 to ((istext(user.client?.view) ? WIDE_TILE_WIDTH : SQUARE_TILE_WIDTH)+1)/2 + 1)
for(var/y in 7 to 9)
L.client?.screen -= hudSquares["[x],[y]"]
stopping = 0
shooting = 0
user.client?.screen -= hudSquares["[x],[y]"]

/datum/component/holdertargeting/fullauto/proc/end_shootloop(mob/living/user)
stopping = 1
10 changes: 9 additions & 1 deletion code/mob/living/carbon/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2211,14 +2211,22 @@
return 0

/mob/living/carbon/human/swap_hand(var/specify=-1)
if(src.hand == specify)
return
var/obj/item/grab/block/B = src.check_block(ignoreStuns = 1)
if(B && hand != specify)
if(B)
qdel(B)
var/obj/item/old = src.equipped()
if (specify >= 0)
src.hand = specify
else
src.hand = !src.hand
hud.update_hands()
if(old != src.equipped())
if(old)
SEND_SIGNAL(old, COMSIG_ITEM_SWAP_AWAY, src)
if(src.equipped())
SEND_SIGNAL(src.equipped(), COMSIG_ITEM_SWAP_TO, src)
if(src.equipped() && (src.equipped().item_function_flags & USE_INTENT_SWITCH_TRIGGER) && !src.equipped().two_handed)
src.equipped().intent_switch_trigger(src)

Expand Down
13 changes: 13 additions & 0 deletions code/mob/living/critter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -509,22 +509,34 @@
if (new_hand == active_hand)
return 1
if (new_hand > 0 && new_hand <= hands.len)
var/obj/item/old = src.equipped()
active_hand = new_hand
hand = active_hand
hud.update_hands()
if(old != src.equipped())
if(old)
SEND_SIGNAL(old, COMSIG_ITEM_SWAP_AWAY, src)
if(src.equipped())
SEND_SIGNAL(src.equipped(), COMSIG_ITEM_SWAP_TO, src)
return 1
return 0

swap_hand()
if (!handcheck())
return
var/obj/item/old = src.equipped()
if (active_hand < hands.len)
active_hand++
hand = active_hand
else
active_hand = 1
hand = active_hand
hud.update_hands()
if(old != src.equipped())
if(old)
SEND_SIGNAL(old, COMSIG_ITEM_SWAP_AWAY, src)
if(src.equipped())
SEND_SIGNAL(src.equipped(), COMSIG_ITEM_SWAP_TO, src)

hand_range_attack(atom/target, params)
.= 0
Expand Down Expand Up @@ -633,6 +645,7 @@
reagents = R

equipped()
RETURN_TYPE(/obj/item)
if (active_hand)
if (hands.len >= active_hand)
var/datum/handHolder/HH = hands[active_hand]
Expand Down
1 change: 1 addition & 0 deletions code/obj/item/gun/gun_parent.dm
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ var/list/forensic_IDs = new/list() //Global list of all guns, based on bioholder
return 0

/obj/item/gun/attack_self(mob/user as mob)
..()
if(src.projectiles && src.projectiles.len > 1)
src.current_projectile_num = ((src.current_projectile_num) % src.projectiles.len) + 1
src.current_projectile = src.projectiles[src.current_projectile_num]
Expand Down

0 comments on commit 6b5d58a

Please sign in to comment.