Skip to content

Commit

Permalink
small pr to make firemode code easier | or, how firemode code was so …
Browse files Browse the repository at this point in the history
…fucking terrible that this pr touches like 20-30 files (shiptest-ss13#3061)

<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

Wanted to add pride flags for pride month, but had to get this 'small
pr' out the way. Oops.

tldr; as a player, this should not affect you. Like at all. Move along

This changes firemodes to not be fucking terrible codewise and to touch
as a developer. Yes, i HAD to touch gun.dm that much. That was how deep
rooted the rot was.

Also get's rid of the 0.4 second hardcoded fire delay, now pistols and
revolvers shoot as fast as they were intended. Great. This meant that i
had to touch a bunch of numbers i set to 0 out of frustration at it not
working, being completely unaware of the hardcoded fire delay.

This also fixes the E-40 to have laser full auto and to have an ammo
counter. I wasn't even trying to fix the E-40, but by unshittifying
firemode code i got it to work. Wow.

This should make the 3 upcoming gun expansions less ass to add.

<!-- Please add a short description of why you think these changes would
benefit the game. If you can't justify it in words, it might not be
worth adding. -->

:cl:
add: Changing firemodes on guns now have new sprites
fix: The E-40 now works as intended!
add: The E-40 now has an ammo counter
balance: The P16 shoots slightly faster.
balance: .299 Eoehoma caseless has gotten a slight nerf, while the E-40
shoots slightly faster.
balance: Two E-40s max are obtainable from the black market should it
spawn. Blank market price cap of the E-40 has also increased

/:cl:

<!-- Both :cl:'s are required for the changelog to work! You can put
your name to the right of the first :cl: if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->

---------

Co-authored-by: retlaw34 <[email protected]>
  • Loading branch information
2 people authored and MrCat15352 committed Jun 22, 2024
1 parent 25dac66 commit 46d3eae
Show file tree
Hide file tree
Showing 42 changed files with 924 additions and 646 deletions.
5 changes: 3 additions & 2 deletions code/__DEFINES/combat.dm
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@ GLOBAL_LIST_INIT(shove_disarming_types, typecacheof(list(/obj/item/gun)))
#define WEAPON_MEDIUM 2
/// You must wield the gun to fire this gun
#define WEAPON_HEAVY 3
/// You must FULLY wield (wait the full wield delay) the gun to fire this gun
#define WEAPON_VERY_HEAVY 4
//Gun trigger guards
#define TRIGGER_GUARD_ALLOW_ALL -1
#define TRIGGER_GUARD_NONE 0
#define TRIGGER_GUARD_NORMAL 1
//Gun bolt types
///Gun has a bolt, it stays closed while not cycling. The gun must be racked to have a bullet chambered when a mag is inserted.
/// Example: c20, shotguns, m90
///The gun has a closed bolt, when resting it's closed, and must be racked to get a bullet from a magazine. see: Every Fucking Videogame Gun Ever
#define BOLT_TYPE_STANDARD 1
///Gun has a bolt, it is open when ready to fire. The gun can never have a chambered bullet with no magazine, but the bolt stays ready when a mag is removed.
/// Example: Some SMGs, the L6
Expand Down
4 changes: 4 additions & 0 deletions code/__DEFINES/dcs/signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,10 @@
/// send when enabling/diabling an autofire component
#define COMSIG_GUN_DISABLE_AUTOFIRE "disable_autofire"
#define COMSIG_GUN_ENABLE_AUTOFIRE "enable_autofire"
#define COMSIG_GUN_SET_AUTOFIRE_SPEED "set_autofire_speed"

///sent when guns need to notify the gun hud to update. mostly for revolvers.
#define COMSIG_UPDATE_AMMO_HUD "update_ammo_hud"

///called in /obj/item/gun/process_chamber (src)
#define COMSIG_GUN_CHAMBER_PROCESSED "gun_chamber_processed"
Expand Down
6 changes: 6 additions & 0 deletions code/__DEFINES/guns.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@
#define MANUFACTURER_DONKCO "the Donk! Co. logo"
#define MANUFACTURER_PGF "the Etherbor Industries emblem"
#define MANUFACTURER_IMPORT "Lanchester Import Co."

#define FIREMODE_SEMIAUTO "single"
#define FIREMODE_BURST "burst"
#define FIREMODE_FULLAUTO "auto"
#define FIREMODE_OTHER "other"
#define FIREMODE_OTHER_TWO "other2"
1 change: 1 addition & 0 deletions code/datums/action.dm
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@

/datum/action/item_action/toggle_firemode
name = "Toggle Firemode"
icon_icon = 'icons/mob/actions/actions_items.dmi'

/datum/action/item_action/rcl_col
name = "Change Cable Color"
Expand Down
38 changes: 18 additions & 20 deletions code/datums/components/fullauto.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var/turf/target_loc //For dealing with locking on targets due to BYOND engine limitations (the mouse input only happening when mouse moves).
var/autofire_stat = AUTOFIRE_STAT_IDLE
var/mouse_parameters
var/autofire_shot_delay = 0.3 SECONDS //Time between individual shots.
var/autofire_shot_delay = 0.1 SECONDS //Time between individual shots.
var/mouse_status = AUTOFIRE_MOUSEUP //This seems hacky but there can be two MouseDown() without a MouseUp() in between if the user holds click and uses alt+tab, printscreen or similar.
var/enabled = TRUE

Expand All @@ -22,6 +22,7 @@
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, PROC_REF(wake_up))
RegisterSignal(parent, COMSIG_GUN_DISABLE_AUTOFIRE, PROC_REF(disable_autofire))
RegisterSignal(parent, COMSIG_GUN_ENABLE_AUTOFIRE, PROC_REF(enable_autofire))
RegisterSignal(parent, COMSIG_GUN_SET_AUTOFIRE_SPEED, PROC_REF(set_autofire_speed))
if(_autofire_shot_delay)
autofire_shot_delay = _autofire_shot_delay
if(autofire_stat == AUTOFIRE_STAT_IDLE && ismob(gun.loc))
Expand Down Expand Up @@ -161,7 +162,7 @@

if(isgun(parent))
var/obj/item/gun/shoota = parent
if(!shoota.on_autofire_start(shooter)) //This is needed because the minigun has a do_after before firing and signals are async.
if(!shoota.on_autofire_start(shooter=shooter)) //This is needed because the minigun has a do_after before firing and signals are async.
stop_autofiring()
return
if(autofire_stat != AUTOFIRE_STAT_FIRING)
Expand Down Expand Up @@ -242,12 +243,12 @@

// Gun procs.

/obj/item/gun/proc/on_autofire_start(mob/living/shooter)
if(semicd || shooter.stat || !can_trigger_gun(shooter))
return FALSE
if(!can_shoot())
shoot_with_empty_chamber(shooter)
/obj/item/gun/proc/on_autofire_start(datum/source, atom/target, mob/living/shooter, params)
if(current_cooldown || shooter.stat)
return FALSE
if(!can_shoot()) //we call pre_fire so bolts/slides work correctly
INVOKE_ASYNC(src, PROC_REF(do_autofire_shot), source, target, shooter, params)
return NONE
if(weapon_weight == WEAPON_HEAVY && (!wielded))
to_chat(shooter, "<span class='warning'>You need a more secure grip to fire [src]!</span>")
return FALSE
Expand All @@ -262,32 +263,29 @@

/obj/item/gun/proc/do_autofire(datum/source, atom/target, mob/living/shooter, params)
SIGNAL_HANDLER
if(semicd || shooter.incapacitated())
if(current_cooldown || shooter.incapacitated())
return NONE
if(weapon_weight == WEAPON_HEAVY && (!wielded))
to_chat(shooter, "<span class='warning'>You need a more secure grip to fire [src]!</span>")
return NONE
if(!can_shoot())
shoot_with_empty_chamber(shooter)
if(!can_shoot()) //we stop if we cant shoot but also calling pre_fire so the bolt works correctly if it's a weird open bolt weapon.
INVOKE_ASYNC(src, PROC_REF(do_autofire_shot), source, target, shooter, params)
return NONE
INVOKE_ASYNC(src, PROC_REF(do_autofire_shot), source, target, shooter, params)
return COMPONENT_AUTOFIRE_SHOT_SUCCESS //All is well, we can continue shooting.


/obj/item/gun/proc/do_autofire_shot(datum/source, atom/target, mob/living/shooter, params)
var/obj/item/gun/akimbo_gun = shooter.get_inactive_held_item()
var/bonus_spread = 0
if(istype(akimbo_gun) && weapon_weight < WEAPON_MEDIUM)
if(akimbo_gun.weapon_weight < WEAPON_MEDIUM && akimbo_gun.can_trigger_gun(shooter))
bonus_spread = dual_wield_spread
addtimer(CALLBACK(akimbo_gun, TYPE_PROC_REF(/obj/item/gun, process_fire), target, shooter, TRUE, params, null, bonus_spread), 1)
process_fire(target, shooter, TRUE, params, null, bonus_spread)

/datum/component/automatic_fire/proc/disable_autofire()
pre_fire(target, shooter, TRUE, params, null) //dual wielding is handled here

/datum/component/automatic_fire/proc/disable_autofire(datum/source)
enabled = FALSE

/datum/component/automatic_fire/proc/enable_autofire()
/datum/component/automatic_fire/proc/enable_autofire(datum/source)
enabled = TRUE

/datum/component/automatic_fire/proc/set_autofire_speed(datum/source, newspeed)
autofire_shot_delay = newspeed

#undef AUTOFIRE_MOUSEUP
#undef AUTOFIRE_MOUSEDOWN
2 changes: 1 addition & 1 deletion code/datums/components/gunpoint.dm
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
if(weapon.chambered && weapon.chambered.BB)
weapon.chambered.BB.damage *= damage_mult

weapon.process_fire(target, shooter)
weapon.pre_fire(target, shooter)
qdel(src)

/datum/component/gunpoint/proc/cancel()
Expand Down
1 change: 1 addition & 0 deletions code/game/machinery/recharger.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/obj/item/ammo_box/magazine/recharge,
/obj/item/modular_computer,
/obj/item/gun/ballistic/automatic/powered,
/obj/item/gun/ballistic/automatic/assault/e40,
))

/obj/machinery/recharger/RefreshParts()
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/chrono_eraser.dm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
item_flags = DROPDEL
ammo_type = list(/obj/item/ammo_casing/energy/chrono_beam)
can_charge = FALSE
fire_delay = 50
fire_delay = 5 SECONDS
var/obj/item/chrono_eraser/TED = null
var/obj/structure/chrono_field/field = null
var/turf/startpos = null
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/devices/paicard.dm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
pai.master_dna = M.dna.unique_enzymes
to_chat(pai, "<span class='notice'>You have been bound to a new master.</span>")
pai.laws.set_zeroth_law("Serve your master.")
pai.emittersemicd = FALSE
pai.emittercurrent_cooldown = FALSE
if(href_list["wipe"])
var/confirm = input("Are you CERTAIN you wish to delete the current personality? This action cannot be undone.", "Personality Wipe") in list("Yes", "No")
if(confirm == "Yes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
ammo_type = list(/obj/item/ammo_casing/energy/shrink)
item_state = "shrink_ray"
icon_state = "shrink_ray"
fire_delay = 30
fire_delay = 3 SECONDS
selfcharge = 1//shot costs 200 energy, has a max capacity of 1000 for 5 shots. self charge returns 25 energy every couple ticks, so about 1 shot charged every 12~ seconds
trigger_guard = TRIGGER_GUARD_ALLOW_ALL// variable-size trigger, get it? (abductors need this to be set so the gun is usable for them)

Expand Down
2 changes: 1 addition & 1 deletion code/modules/antagonists/changeling/powers/mutations.dm
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
fire_sound = 'sound/effects/splat.ogg'
force = 0
max_charges = 1
fire_delay = 1
fire_delay = 0.1 SECONDS
throwforce = 0 //Just to be on the safe side
throw_range = 0
throw_speed = 0
Expand Down
6 changes: 3 additions & 3 deletions code/modules/cargo/blackmarket/blackmarket_items/weapons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
pair_item = /datum/blackmarket_item/weapon/e40_mag

price_min = 7000
price_max = 13000
stock = 1
price_max = 15000
stock_max = 2
availability_prob = 20

/datum/blackmarket_item/weapon/e40_mag
Expand All @@ -134,7 +134,7 @@
price_min = 750
price_max = 1250
stock_min = 2
stock_max = 4
stock_max = 6
availability_prob = 0

/datum/blackmarket_item/weapon/e50
Expand Down
4 changes: 2 additions & 2 deletions code/modules/mining/lavaland/necropolis_chests.dm
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@
return COMPONENT_NO_ATTACK_OBJ

//A version of the Cave Story refrence that a deranged scientist got their hands on. Better? Not really. Different? Definitely.
//TODO: replace with a proper polar star and spur, not to mention a proper sprite
/obj/item/gun/energy/spur
name = "Slowpoke"
desc = "The work of a truly genius gunsmith, altered and \"improved\" by a truly deranged Nanotrasen scientist, using components from a kinetic accelerator and beam rifle. Draw, partner!"
Expand All @@ -961,11 +962,10 @@
righthand_file = 'icons/mob/inhands/weapons/guns_righthand.dmi'
icon_state = "spur"
item_state = "spur"
fire_delay = 0.5 //BRATATAT! This is a cowboy's six-shooter after all.
selfcharge = 1
charge_delay = 1
slot_flags = ITEM_SLOT_BELT
fire_delay = 1
fire_delay = 0.1 SECONDS
recoil = 1
cell_type = /obj/item/stock_parts/cell/gun
ammo_type = list(/obj/item/ammo_casing/energy/spur)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/mob/living/silicon/pai/pai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
var/emitterregen = 0.25
var/emittercd = 50
var/emitteroverloadcd = 100
var/emittersemicd = FALSE
var/emittercurrent_cooldown = FALSE

var/overload_ventcrawl = 0
var/overload_bulletblock = 0 //Why is this a good idea?
Expand Down Expand Up @@ -125,7 +125,7 @@

. = ..()

emittersemicd = TRUE
emittercurrent_cooldown = TRUE
addtimer(CALLBACK(src, PROC_REF(emittercool)), 600)

if(!holoform)
Expand Down
8 changes: 4 additions & 4 deletions code/modules/mob/living/silicon/pai/pai_shell.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
. = fold_in(force)
return

if(emittersemicd)
if(emittercurrent_cooldown)
to_chat(src, "<span class='warning'>Error: Holochassis emitters recycling. Please try again later.</span>")
return FALSE

emittersemicd = TRUE
emittercurrent_cooldown = TRUE
addtimer(CALLBACK(src, PROC_REF(emittercool)), emittercd)
REMOVE_TRAIT(src, TRAIT_IMMOBILIZED, PAI_FOLDED)
REMOVE_TRAIT(src, TRAIT_HANDS_BLOCKED, PAI_FOLDED)
Expand All @@ -42,10 +42,10 @@
holoform = TRUE

/mob/living/silicon/pai/proc/emittercool()
emittersemicd = FALSE
emittercurrent_cooldown = FALSE

/mob/living/silicon/pai/proc/fold_in(force = FALSE)
emittersemicd = TRUE
emittercurrent_cooldown = TRUE
if(!force)
addtimer(CALLBACK(src, PROC_REF(emittercool)), emittercd)
else
Expand Down
2 changes: 0 additions & 2 deletions code/modules/projectiles/ammunition/_firing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

if(click_cooldown_override)
user.changeNext_move(click_cooldown_override)
else
user.changeNext_move(CLICK_CD_RANGE)

user.newtonian_move(get_dir(target, user))
update_appearance()
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/ammunition/ballistic/rifle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@
icon_state = "caseless"
caliber = ".299 caseless"
projectile_type = /obj/projectile/bullet/c299
bullet_per_box = 80
bullet_per_box = 100
2 changes: 1 addition & 1 deletion code/modules/projectiles/ammunition/energy/laser.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
projectile_type = /obj/projectile/beam/laser/weak/negative_ap
e_cost = 799 //12 shots with a normal power cell, 25 with an upgraded
select_name = "kill"
delay = 0.1 SECONDS
delay = 0.13 SECONDS

/obj/item/ammo_casing/energy/lasergun/old
projectile_type = /obj/projectile/beam/laser
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/ammunition/energy/stun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
/obj/item/ammo_casing/energy/disabler/smg
projectile_type = /obj/projectile/beam/disabler/weak/negative_ap
e_cost = 330
delay = 0.1 SECONDS
delay = 0.13 SECONDS
Loading

0 comments on commit 46d3eae

Please sign in to comment.