Skip to content

Commit

Permalink
Bipod now gives you an option to switch to full auto when deploying (#…
Browse files Browse the repository at this point in the history
…5638)

# About the pull request

Attaching the bipod to weapons with full auto capability or firearms
marked with the GUN_SUPPORT_PLATFORM flag will give the user a button
toggle to immediately switch to full auto when deploying the bipod.


![image](https://github.com/cmss13-devs/cmss13/assets/17518895/cea29ccc-5761-4a7b-99bd-cbdd035bc52b)



If the full auto switch is turned on, the weapon will simply switch to
full auto when the bipod is deployed. If you undeploy it, it will switch
back to whatever previous firemode the weapon was in, e.g:

1. You set your pulse rifle to semi auto. 
2. You deploy the bipod. 
3. The pulse rifle is set to full auto. 
4. You undeploy the bipod. 
5. The pulse rifle will switch back to semi auto.

In cases where you switch the weapon's firemode when it's already
switched to full auto, it won't revert back to whatever firemode was set
before it was deployed, e.g:

1. You set your pulse rifle to semi auto. 
2. You deploy the bipod. 
3. The pulse rifle is set to full auto. 
4. You set your pulse rifle to burst fire.
5. You undeploy the bipod. 
6. The pulse rifle will stay on burst fire.

Also renames a couple of one letter variables.

# Explain why it's good for the game

Quality of life. Less messing around with firemode selectors which is a
terrible headache, especially for the HPR, which you usually want to
have on full auto 90% of the time. Those who want to stick with the old
way don't have to change anything, as the full auto switch is entirely
optional.

# Testing Photographs and Procedure
<details>
<summary>Screenshots & Videos</summary>



https://github.com/cmss13-devs/cmss13/assets/17518895/35bcc6e7-947d-4f82-971f-ac22b723537b



</details>


# Changelog
:cl:
qol: Attaching the bipod to weapons that have full auto (HPR included)
will give you a button toggle for immediately switching to full auto
when deploying the bipod.
/:cl:
  • Loading branch information
VileBeggar authored Feb 14, 2024
1 parent ab283fc commit cf0f0a1
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 33 deletions.
116 changes: 84 additions & 32 deletions code/modules/projectiles/gun_attachables.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3301,6 +3301,10 @@ Defined in conflicts.dm of the #defines folder.
var/bipod_deployed = FALSE
/// If this should anchor the user while in use
var/heavy_bipod = FALSE
// Are switching to full auto when deploying the bipod
var/full_auto_switch = FALSE
// Store our old firemode so we can switch to it when undeploying the bipod
var/old_firemode = null

/obj/item/attachable/bipod/New()
..()
Expand All @@ -3311,16 +3315,33 @@ Defined in conflicts.dm of the #defines folder.
scatter_mod = SCATTER_AMOUNT_TIER_9
recoil_mod = RECOIL_AMOUNT_TIER_5

/obj/item/attachable/bipod/Attach(obj/item/weapon/gun/G)
/obj/item/attachable/bipod/Attach(obj/item/weapon/gun/gun, mob/user)
..()

RegisterSignal(G, COMSIG_ITEM_DROPPED, PROC_REF(handle_drop))
if((GUN_FIREMODE_AUTOMATIC in gun.gun_firemode_list) || (gun.flags_gun_features & GUN_SUPPORT_PLATFORM))
var/given_action = FALSE
if(user && (gun == user.l_hand || gun == user.r_hand))
give_action(user, /datum/action/item_action/bipod/toggle_full_auto_switch, src, gun)
given_action = TRUE
if(!given_action)
new /datum/action/item_action/bipod/toggle_full_auto_switch(src, gun)

RegisterSignal(gun, COMSIG_ITEM_DROPPED, PROC_REF(handle_drop))

/obj/item/attachable/bipod/Detach(mob/user, obj/item/weapon/gun/detaching_gub)
UnregisterSignal(detaching_gub, COMSIG_ITEM_DROPPED)

//clear out anything related to full auto switching
full_auto_switch = FALSE
old_firemode = null
for(var/item_action in detaching_gub.actions)
var/datum/action/item_action/bipod/toggle_full_auto_switch/target_action = item_action
if(target_action.target == src)
qdel(item_action)
break

if(bipod_deployed)
undeploy_bipod(detaching_gub)
undeploy_bipod(detaching_gub, user)
..()

/obj/item/attachable/bipod/update_icon()
Expand All @@ -3334,86 +3355,92 @@ Defined in conflicts.dm of the #defines folder.
if(istype(loc, /obj/item/weapon/gun))
var/obj/item/weapon/gun/gun = loc
gun.update_attachable(slot)
for(var/datum/action/A as anything in gun.actions)
A.update_button_icon()
for(var/datum/action/item_action as anything in gun.actions)
if(!istype(item_action, /datum/action/item_action/bipod/toggle_full_auto_switch))
item_action.update_button_icon()

/obj/item/attachable/bipod/proc/handle_drop(obj/item/weapon/gun/G, mob/living/carbon/human/user)
/obj/item/attachable/bipod/proc/handle_drop(obj/item/weapon/gun/gun, mob/living/carbon/human/user)
SIGNAL_HANDLER

UnregisterSignal(user, COMSIG_MOB_MOVE_OR_LOOK)

if(bipod_deployed)
undeploy_bipod(G)
undeploy_bipod(gun, user)
user.apply_effect(1, SUPERSLOW)
user.apply_effect(2, SLOW)

/obj/item/attachable/bipod/proc/undeploy_bipod(obj/item/weapon/gun/G)
REMOVE_TRAIT(G, TRAIT_GUN_BIPODDED, "attached_bipod")
/obj/item/attachable/bipod/proc/undeploy_bipod(obj/item/weapon/gun/gun, mob/user)
REMOVE_TRAIT(gun, TRAIT_GUN_BIPODDED, "attached_bipod")
bipod_deployed = FALSE
accuracy_mod = -HIT_ACCURACY_MULT_TIER_5
scatter_mod = SCATTER_AMOUNT_TIER_9
recoil_mod = RECOIL_AMOUNT_TIER_5
burst_scatter_mod = 0
delay_mod = FIRE_DELAY_TIER_12
G.recalculate_attachment_bonuses()
G.stop_fire()
var/mob/living/user
if(isliving(G.loc))
user = G.loc
SEND_SIGNAL(user, COMSIG_MOB_UNDEPLOYED_BIPOD)
UnregisterSignal(user, COMSIG_MOB_MOVE_OR_LOOK)
//if we are no longer on full auto, don't bother switching back to the old firemode
if(full_auto_switch && gun.gun_firemode == GUN_FIREMODE_AUTOMATIC && gun.gun_firemode != old_firemode)
gun.do_toggle_firemode(user, null, old_firemode)

if(G.flags_gun_features & GUN_SUPPORT_PLATFORM)
G.remove_firemode(GUN_FIREMODE_AUTOMATIC)
gun.recalculate_attachment_bonuses()
gun.stop_fire()
SEND_SIGNAL(user, COMSIG_MOB_UNDEPLOYED_BIPOD)
UnregisterSignal(user, COMSIG_MOB_MOVE_OR_LOOK)

if(gun.flags_gun_features & GUN_SUPPORT_PLATFORM)
gun.remove_firemode(GUN_FIREMODE_AUTOMATIC)

if(heavy_bipod)
user.anchored = FALSE

if(!QDELETED(G))
if(!QDELETED(gun))
playsound(user,'sound/items/m56dauto_rotate.ogg', 55, 1)
update_icon()

/obj/item/attachable/bipod/activate_attachment(obj/item/weapon/gun/G,mob/living/user, turn_off)
/obj/item/attachable/bipod/activate_attachment(obj/item/weapon/gun/gun, mob/living/user, turn_off)
if(turn_off)
if(bipod_deployed)
undeploy_bipod(G)
undeploy_bipod(gun, user)
else
var/obj/support = check_bipod_support(G, user)
var/obj/support = check_bipod_support(gun, user)
if(!support&&!bipod_deployed)
to_chat(user, SPAN_NOTICE("You start deploying [src] on the ground."))
if(!do_after(user, 15, INTERRUPT_ALL, BUSY_ICON_HOSTILE, G,INTERRUPT_DIFF_LOC))
if(!do_after(user, 15, INTERRUPT_ALL, BUSY_ICON_HOSTILE, gun, INTERRUPT_DIFF_LOC))
return FALSE

bipod_deployed = !bipod_deployed
if(user)
if(bipod_deployed)
ADD_TRAIT(G, TRAIT_GUN_BIPODDED, "attached_bipod")
ADD_TRAIT(gun, TRAIT_GUN_BIPODDED, "attached_bipod")
to_chat(user, SPAN_NOTICE("You deploy [src] [support ? "on [support]" : "on the ground"]."))
SEND_SIGNAL(user, COMSIG_MOB_DEPLOYED_BIPOD)
playsound(user,'sound/items/m56dauto_rotate.ogg', 55, 1)
accuracy_mod = HIT_ACCURACY_MULT_TIER_5
scatter_mod = -SCATTER_AMOUNT_TIER_10
recoil_mod = -RECOIL_AMOUNT_TIER_4
burst_scatter_mod = -SCATTER_AMOUNT_TIER_8
if(istype(G,/obj/item/weapon/gun/rifle/sniper/M42A))
if(istype(gun, /obj/item/weapon/gun/rifle/sniper/M42A))
delay_mod = -FIRE_DELAY_TIER_7
else
delay_mod = -FIRE_DELAY_TIER_12
G.recalculate_attachment_bonuses()
G.stop_fire()
gun.recalculate_attachment_bonuses()
gun.stop_fire()

initial_mob_dir = user.dir
RegisterSignal(user, COMSIG_MOB_MOVE_OR_LOOK, PROC_REF(handle_mob_move_or_look))

if(G.flags_gun_features & GUN_SUPPORT_PLATFORM)
G.add_firemode(GUN_FIREMODE_AUTOMATIC)
if(gun.flags_gun_features & GUN_SUPPORT_PLATFORM)
gun.add_firemode(GUN_FIREMODE_AUTOMATIC)

if(heavy_bipod)
user.anchored = TRUE

old_firemode = gun.gun_firemode
if(full_auto_switch && gun.gun_firemode != GUN_FIREMODE_AUTOMATIC)
gun.do_toggle_firemode(user, null, GUN_FIREMODE_AUTOMATIC)

else
to_chat(user, SPAN_NOTICE("You retract [src]."))
undeploy_bipod(G)
undeploy_bipod(gun, user)

update_icon()

Expand All @@ -3430,10 +3457,10 @@ Defined in conflicts.dm of the #defines folder.


//when user fires the gun, we check if they have something to support the gun's bipod.
/obj/item/attachable/proc/check_bipod_support(obj/item/weapon/gun/G, mob/living/user)
/obj/item/attachable/proc/check_bipod_support(obj/item/weapon/gun/gun, mob/living/user)
return 0

/obj/item/attachable/bipod/check_bipod_support(obj/item/weapon/gun/G, mob/living/user)
/obj/item/attachable/bipod/check_bipod_support(obj/item/weapon/gun/gun, mob/living/user)
var/turf/T = get_turf(user)
for(var/obj/O in T)
if(O.throwpass && O.density && O.dir == user.dir && O.flags_atom & ON_BORDER)
Expand All @@ -3445,6 +3472,31 @@ Defined in conflicts.dm of the #defines folder.
return O2
return 0

//item actions for handling deployment to full auto.
/datum/action/item_action/bipod/toggle_full_auto_switch/New(Target, obj/item/holder)
. = ..()
name = "Toggle Full Auto Switch"
action_icon_state = "full_auto_switch"
button.name = name
button.overlays.Cut()
button.overlays += image('icons/mob/hud/actions.dmi', button, action_icon_state)

/datum/action/item_action/bipod/toggle_full_auto_switch/action_activate()
var/obj/item/weapon/gun/holder_gun = holder_item
var/obj/item/attachable/bipod/attached_bipod = holder_gun.attachments["under"]

attached_bipod.full_auto_switch = !attached_bipod.full_auto_switch
to_chat(owner, SPAN_NOTICE("[icon2html(holder_gun, owner)] You will [attached_bipod.full_auto_switch? "<B>start</b>" : "<B>stop</b>"] switching to full auto when deploying the bipod."))
playsound(owner, 'sound/weapons/handling/gun_burst_toggle.ogg', 15, 1)

if(attached_bipod.full_auto_switch)
button.icon_state = "template_on"
else
button.icon_state = "template"

button.overlays.Cut()
button.overlays += image('icons/mob/hud/actions.dmi', button, action_icon_state)


/obj/item/attachable/bipod/m60
name = "bipod"
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/gun_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ DEFINES in setup.dm, referenced here.
user.visible_message(SPAN_NOTICE("[user] attaches [attachment] to [src]."),
SPAN_NOTICE("You attach [attachment] to [src]."), null, 4)
user.temp_drop_inv_item(attachment)
attachment.Attach(src)
attachment.Attach(src, user)
update_attachable(attachment.slot)
playsound(user, 'sound/handling/attachment_add.ogg', 15, 1, 4)
return TRUE
Expand Down
Binary file modified icons/mob/hud/actions.dmi
Binary file not shown.

0 comments on commit cf0f0a1

Please sign in to comment.