Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big gun refactor #3212

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
071f32b
tweaks to recoil and spread
FalloutFalcon Jun 10, 2024
dbae8b5
Merge branch 'master' of https://github.com/shiptest-ss13/Shiptest in…
FalloutFalcon Jul 15, 2024
ce21564
combines some vars
FalloutFalcon Jul 15, 2024
7078c76
more var smushing
FalloutFalcon Jul 15, 2024
b16ed83
more stream lining of vars
FalloutFalcon Jul 15, 2024
81ec85f
yes but rn ballistics dont have mags so thats bad
FalloutFalcon Jul 15, 2024
330794e
mag types changed
FalloutFalcon Jul 15, 2024
a5a617c
a unit test for the allowed_ammo_types
FalloutFalcon Jul 15, 2024
b2ad0e9
yea
FalloutFalcon Jul 15, 2024
67609d4
yea
FalloutFalcon Jul 15, 2024
b503fb0
gun code
FalloutFalcon Aug 8, 2024
363f30a
Merge branch 'master' of https://github.com/shiptest-ss13/Shiptest in…
FalloutFalcon Aug 10, 2024
4b8a64c
bunch of tweaks, less duplicate code soon.
FalloutFalcon Aug 12, 2024
9f3f094
alot of changes to gun code
FalloutFalcon Aug 12, 2024
942ca2a
stuff
FalloutFalcon Aug 12, 2024
38d9c0f
ammo reciver toggles open
FalloutFalcon Aug 12, 2024
b940927
those arent mags silly.
FalloutFalcon Sep 5, 2024
d2b26ef
Revert "ammo reciver toggles open", thats a whole diffrent pr, out of…
FalloutFalcon Sep 5, 2024
ef1aa05
Merge branch 'master' of https://github.com/shiptest-ss13/Shiptest in…
FalloutFalcon Sep 5, 2024
960454e
yea
FalloutFalcon Sep 5, 2024
375194d
unit test!
FalloutFalcon Sep 5, 2024
6981d3b
yea
FalloutFalcon Sep 5, 2024
302aa94
yea
FalloutFalcon Sep 5, 2024
fac20d6
skip emtpy guns in unit test
FalloutFalcon Sep 5, 2024
e89a59d
update check_regex
FalloutFalcon Sep 5, 2024
aeacbd7
wrong spot for that
FalloutFalcon Sep 5, 2024
2e430c4
powered is really a thorn in my side
FalloutFalcon Sep 5, 2024
037fc6c
aghhh i hate powered
FalloutFalcon Sep 5, 2024
6baae32
moving more ballistics into gun
FalloutFalcon Sep 5, 2024
709f9bb
fix unit tests doin nothin
FalloutFalcon Sep 5, 2024
13330ec
one more is path.
FalloutFalcon Sep 5, 2024
4a9ebba
more refactor
FalloutFalcon Sep 6, 2024
28371ab
yea
FalloutFalcon Sep 6, 2024
0739e4b
prefire check
FalloutFalcon Sep 6, 2024
b10f22d
nearly done with factoring ballistic out
FalloutFalcon Sep 6, 2024
f66870c
spans
FalloutFalcon Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@
/area/ruin/unpowered/listening_post)
"te" = (
/obj/item/gun/ballistic/automatic/smg/c20r{
spawnwithmagazine = 0
default_ammo_type = null
},
/obj/item/ammo_box/magazine/smgm45{
start_empty = 1
Expand Down
2 changes: 1 addition & 1 deletion _maps/shuttles/independent/independent_kilo.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@
},
/obj/item/ammo_box/a12g/rubbershot,
/obj/item/gun/ballistic/shotgun/doublebarrel/presawn{
spawnwithmagazine = 0
default_ammo_type = null
},
/obj/structure/cable/pink{
icon_state = "4-10"
Expand Down
2 changes: 1 addition & 1 deletion check_regex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ standards:
- exactly: [1, "/area text paths", '"/area']
- exactly: [17, "/datum text paths", '"/datum']
- exactly: [4, "/mob text paths", '"/mob']
- exactly: [43, "/obj text paths", '"/obj']
- exactly: [41, "/obj text paths", '"/obj']
- exactly: [0, "/turf text paths", '"/turf']
- exactly: [116, "text2path uses", "text2path"]

Expand Down
28 changes: 28 additions & 0 deletions code/__DEFINES/guns.dm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@
#define MANUFACTURER_PGF "the Etherbor Industries emblem"
#define MANUFACTURER_IMPORT "Lanchester Import Co."

//Gun defines for gun related thing. More in the projectile folder.
//gun_features_flags
#define GUN_AMMO_COUNTER (1<<0)
#define GUN_WIELDED_FIRING_ONLY (1<<1)
#define GUN_WIELDED_STABLE_FIRING_ONLY (1<<2)
//To be removed
#define GUN_ENERGY (1<<3)
#define GUN_AMMO_COUNT_BY_PERCENTAGE (1<<4)
#define GUN_AMMO_COUNT_BY_SHOTS_REMAINING (1<<5)

//reciever_flags. Used to determin how the gun cycles, what kind of ammo it uses, etc.
#define AMMO_RECIEVER_REQUIRES_UNIQUE_ACTION (1<<0)
#define AMMO_RECIEVER_UNIQUE_ACTION_LOCKS (1<<1)
#define AMMO_RECIEVER_MAGAZINES (1<<2)
#define AMMO_RECIEVER_AUTO_EJECT (1<<3)
#define AMMO_RECIEVER_HANDFULS (1<<4)
#define AMMO_RECIEVER_TOGGLES_OPEN (1<<5)
#define AMMO_RECIEVER_TOGGLES_OPEN_EJECTS (1<<6)
#define AMMO_RECIEVER_CLOSED (1<<7)
#define AMMO_RECIEVER_ROTATES_CHAMBER (1<<8)
#define AMMO_RECIEVER_DO_NOT_EJECT_HANDFULS (1<<9)
#define AMMO_RECIEVER_DO_NOT_EMPTY_ROUNDS_AFTER_FIRE (1<<10)
#define AMMO_RECIEVER_CYCLE_ONLY_BEFORE_FIRE (1<<11) //The ammo stay in the magazine until the last moment
#define AMMO_RECIEVER_AUTO_EJECT_LOCKED (1<<12) //Not allowed to turn automatic unloading off
//To be removed
#define AMMO_RECIEVER_CELL (1<<13)
#define AMMO_RECIEVER_SECONDARY_CELL (1<<14)

/////////////////
// ATTACHMENTS //
/////////////////
Expand Down
27 changes: 27 additions & 0 deletions code/_globalvars/bitfields.dm
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,30 @@ DEFINE_BITFIELD(bodytype, list(
"BODYTYPE_KEPORI" = BODYTYPE_KEPORI,
"BODYTYPE_VOX" = BODYTYPE_VOX
))

DEFINE_BITFIELD(gun_features_flags, list(
"GUN_AMMO_COUNTER" = GUN_AMMO_COUNTER,
"GUN_WIELDED_FIRING_ONLY" = GUN_WIELDED_FIRING_ONLY,
"GUN_WIELDED_STABLE_FIRING_ONLY" = GUN_WIELDED_STABLE_FIRING_ONLY,
"GUN_ENERGY" = GUN_ENERGY,
"GUN_AMMO_COUNT_BY_PERCENTAGE" = GUN_AMMO_COUNT_BY_PERCENTAGE,
"GUN_AMMO_COUNT_BY_SHOTS_REMAINING" = GUN_AMMO_COUNT_BY_SHOTS_REMAINING,
))

DEFINE_BITFIELD(reciever_flags, list(
"AMMO_RECIEVER_REQUIRES_UNIQUE_ACTION" = AMMO_RECIEVER_REQUIRES_UNIQUE_ACTION,
"AMMO_RECIEVER_UNIQUE_ACTION_LOCKS" = AMMO_RECIEVER_UNIQUE_ACTION_LOCKS,
"AMMO_RECIEVER_MAGAZINES" = AMMO_RECIEVER_MAGAZINES,
"AMMO_RECIEVER_AUTO_EJECT" = AMMO_RECIEVER_AUTO_EJECT,
"AMMO_RECIEVER_HANDFULS" = AMMO_RECIEVER_HANDFULS,
"AMMO_RECIEVER_TOGGLES_OPEN" = AMMO_RECIEVER_TOGGLES_OPEN,
"AMMO_RECIEVER_TOGGLES_OPEN_EJECTS" = AMMO_RECIEVER_TOGGLES_OPEN_EJECTS,
"AMMO_RECIEVER_CLOSED" = AMMO_RECIEVER_CLOSED,
"AMMO_RECIEVER_ROTATES_CHAMBER" = AMMO_RECIEVER_ROTATES_CHAMBER,
"AMMO_RECIEVER_DO_NOT_EJECT_HANDFULS" = AMMO_RECIEVER_DO_NOT_EJECT_HANDFULS,
"AMMO_RECIEVER_DO_NOT_EMPTY_ROUNDS_AFTER_FIRE" = AMMO_RECIEVER_DO_NOT_EMPTY_ROUNDS_AFTER_FIRE,
"AMMO_RECIEVER_CYCLE_ONLY_BEFORE_FIRE" = AMMO_RECIEVER_CYCLE_ONLY_BEFORE_FIRE,
"AMMO_RECIEVER_AUTO_EJECT_LOCKED" = AMMO_RECIEVER_AUTO_EJECT_LOCKED,
"AMMO_RECIEVER_CELL" = AMMO_RECIEVER_CELL,
"AMMO_RECIEVER_SECONDARY_CELL" = AMMO_RECIEVER_SECONDARY_CELL
))
2 changes: 1 addition & 1 deletion code/game/machinery/porta_turret/portable_turret.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ DEFINE_BITFIELD(turret_flags, list(

/obj/item/gun/ballistic/get_turret_properties()
. = ..()
var/obj/item/ammo_box/mag = mag_type
var/obj/item/ammo_box/mag = default_ammo_type
var/obj/item/ammo_casing/primary_ammo = initial(mag.ammo_type)

.["base_icon_state"] = "syndie"
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/recharger.dm
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@
if(!(machine_stat & (NOPOWER|BROKEN)) && anchored)
if(istype(charging, /obj/item/gun/energy))
var/obj/item/gun/energy/E = charging
if(E.cell)
E.cell.emp_act(severity)
if(E.installed_cell)
E.installed_cell.emp_act(severity)

else if(istype(charging, /obj/item/melee/baton))
var/obj/item/melee/baton/B = charging
Expand Down
3 changes: 3 additions & 0 deletions code/game/objects/items/attachments/stock.dm
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@
/obj/item/attachment/foldable_stock/spitter
icon = 'icons/obj/guns/manufacturer/frontier_import/48x32.dmi'
icon_state = "spitter_stock"

pixel_shift_x = 24
pixel_shift_y = 23
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 @@ -148,7 +148,7 @@
name = "eradication beam"
projectile_type = /obj/projectile/energy/chrono_beam
icon_state = "caseless"
e_cost = 0
rounds_per_shot = 0
var/obj/item/gun/energy/chrono_gun/gun

/obj/item/ammo_casing/energy/chrono_beam/Initialize()
Expand Down
21 changes: 17 additions & 4 deletions code/modules/awaymissions/capture_the_flag.dm
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@
/obj/item/gun/ballistic/automatic/pistol/deagle/ctf
desc = "This looks like it could really hurt in melee."
force = 75
mag_type = /obj/item/ammo_box/magazine/m50/ctf
default_ammo_type = /obj/item/ammo_box/magazine/m50/ctf
allowed_ammo_types = list(
/obj/item/ammo_box/magazine/m50/ctf,
)


/obj/item/gun/ballistic/automatic/pistol/deagle/ctf/dropped()
. = ..()
Expand All @@ -429,7 +433,10 @@
. = ..()

/obj/item/gun/ballistic/automatic/laser/ctf
mag_type = /obj/item/ammo_box/magazine/recharge/ctf
default_ammo_type = /obj/item/ammo_box/magazine/recharge/ctf
allowed_ammo_types = list(
/obj/item/ammo_box/magazine/recharge/ctf,
)
desc = "This looks like it could really hurt in melee."
force = 50

Expand Down Expand Up @@ -477,7 +484,10 @@
// RED TEAM GUNS

/obj/item/gun/ballistic/automatic/laser/ctf/red
mag_type = /obj/item/ammo_box/magazine/recharge/ctf/red
default_ammo_type = /obj/item/ammo_box/magazine/recharge/ctf/red
allowed_ammo_types = list(
/obj/item/ammo_box/magazine/recharge/ctf/red,
)

/obj/item/ammo_box/magazine/recharge/ctf/red
ammo_type = /obj/item/ammo_casing/caseless/laser/ctf/red
Expand All @@ -492,7 +502,10 @@
// BLUE TEAM GUNS

/obj/item/gun/ballistic/automatic/laser/ctf/blue
mag_type = /obj/item/ammo_box/magazine/recharge/ctf/blue
default_ammo_type = /obj/item/ammo_box/magazine/recharge/ctf/blue
allowed_ammo_types = list(
/obj/item/ammo_box/magazine/recharge/ctf/blue,
)

/obj/item/ammo_box/magazine/recharge/ctf/blue
ammo_type = /obj/item/ammo_casing/caseless/laser/ctf/blue
Expand Down
4 changes: 2 additions & 2 deletions code/modules/hydroponics/hydroponics.dm
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@
update_appearance()
else if(istype(O, /obj/item/gun/energy/floragun))
var/obj/item/gun/energy/floragun/flowergun = O
if(flowergun.cell.charge < REVOLUTION_CHARGE) // In case an admin var edits the gun or guns gain the ability to have their cell upgraded
if(flowergun.installed_cell.charge < REVOLUTION_CHARGE) // In case an admin var edits the gun or guns gain the ability to have their cell upgraded
to_chat(user, "<span class='notice'>[flowergun] must be charged to lock in a mutation!</span>")
return
if(!myseed)
Expand All @@ -634,7 +634,7 @@
return
myseed.mutatelist = list(fresh_mut_list[locked_mutation])
myseed.endurance = (myseed.endurance/2)
flowergun.cell.use(REVOLUTION_CHARGE)
flowergun.installed_cell.use(REVOLUTION_CHARGE)
flowergun.update_appearance()
to_chat(user, "<span class='notice'>[myseed.plantname]'s mutation was set to [locked_mutation], depleting [flowergun]'s cell!</span>")
return
Expand Down
21 changes: 10 additions & 11 deletions code/modules/mining/lavaland/necropolis_chests.dm
Original file line number Diff line number Diff line change
Expand Up @@ -873,12 +873,11 @@
righthand_file = GUN_RIGHTHAND_ICON
icon_state = "spur"
item_state = "spur"
selfcharge = 1
selfcharge = TRUE
charge_delay = 1
slot_flags = ITEM_SLOT_BELT
fire_delay = 0.1 SECONDS
recoil = 1
cell_type = /obj/item/stock_parts/cell/gun
ammo_type = list(/obj/item/ammo_casing/energy/spur)
supports_variations = VOX_VARIATION
var/chargesound
Expand All @@ -888,14 +887,14 @@
. += "<span class='notice'>This weapon contains a gradual heat accelerator that increases shot power as the weapon's energy stores are depleted. Shots at low power are significantly stronger, but also have incredibly short range.</span>"

/obj/item/gun/energy/spur/update_appearance()
if(!cell)
if(!installed_cell)
chargesound = null
recoil = 1
fire_sound = 'sound/weapons/spur_high.ogg'
return

var/maxcharge = cell.maxcharge
var/charge = cell.charge
var/maxcharge = installed_cell.maxcharge
var/charge = installed_cell.charge

var/oldsound = chargesound
var/obj/item/ammo_casing/energy/AC = ammo_type[select]
Expand All @@ -907,7 +906,7 @@
chargesound = 'sound/weapons/spur_chargemed.ogg'
recoil = 0
fire_sound = 'sound/weapons/spur_medium.ogg'
else if(charge >= AC.e_cost) // less than that
else if(charge >= AC.rounds_per_shot) // less than that
chargesound = 'sound/weapons/spur_chargehigh.ogg'
recoil = 0
fire_sound = 'sound/weapons/spur_high.ogg'
Expand All @@ -924,7 +923,7 @@
/obj/item/ammo_casing/energy/spur
projectile_type = /obj/projectile/bullet/spur
select_name = "polar star lens"
e_cost = 1300
rounds_per_shot = 1300
fire_sound = null
harmful = TRUE

Expand All @@ -942,8 +941,8 @@
return ..()

var/obj/item/gun/energy/spur/fired_gun = fired_from
var/maxcharge = fired_gun.cell.maxcharge
var/charge = fired_gun.cell.charge
var/maxcharge = fired_gun.installed_cell.maxcharge
var/charge = fired_gun.installed_cell.charge

if(charge >= ((maxcharge/3) * 2)) // 2 third charged
icon_state = "spur_low"
Expand Down Expand Up @@ -1018,8 +1017,8 @@
return ..()

var/obj/item/gun/energy/spur/fired_gun = fired_from
var/maxcharge = fired_gun.cell.maxcharge
var/charge = fired_gun.cell.charge
var/maxcharge = fired_gun.installed_cell.maxcharge
var/charge = fired_gun.installed_cell.charge

if(charge >= ((maxcharge/3) * 2)) // 2 third charged
icon_state = "spur_high"
Expand Down
4 changes: 2 additions & 2 deletions code/modules/mob/living/silicon/robot/robot_modules.dm
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,9 @@
..()
var/obj/item/gun/energy/e_gun/advtaser/cyborg/T = locate(/obj/item/gun/energy/e_gun/advtaser/cyborg) in basic_modules
if(T)
if(T.cell.charge < T.cell.maxcharge)
if(T.installed_cell.charge < T.installed_cell.maxcharge)
var/obj/item/ammo_casing/energy/S = T.ammo_type[T.select]
T.cell.give(S.e_cost * coeff)
T.installed_cell.give(S.rounds_per_shot * coeff)
T.update_appearance()
else
T.charge_tick = 0
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/simple_animal/bot/bot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@

else if(istype(dropped_item, /obj/item/gun/energy))
var/obj/item/gun/energy/dropped_gun = dropped_item
dropped_gun.cell.charge = 0
dropped_gun.installed_cell.charge = 0
dropped_gun.update_appearance()

//Generalized behavior code, override where needed!
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/simple_animal/bot/secbot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ Auto Patrol: []"},
Sa.created_name = name
new /obj/item/assembly/prox_sensor(Tsec)
var/obj/item/gun/energy/disabler/G = new (Tsec)
G.cell.charge = 0
G.installed_cell.charge = 0
G.update_appearance()
if(prob(50))
new /obj/item/bodypart/leg/left/robot(Tsec)
Expand Down
8 changes: 4 additions & 4 deletions code/modules/mob/living/simple_animal/hostile/mimic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ GLOBAL_LIST_INIT(protected_objects, list(/obj/structure/table, /obj/structure/ca
TrueGun = G
if(istype(G, /obj/item/gun/ballistic))
Pewgun = G
var/obj/item/ammo_box/magazine/M = Pewgun.mag_type
var/obj/item/ammo_box/magazine/M = Pewgun.default_ammo_type
casingtype = initial(M.ammo_type)
if(istype(G, /obj/item/gun/energy))
Zapgun = G
Expand All @@ -234,10 +234,10 @@ GLOBAL_LIST_INIT(protected_objects, list(/obj/structure/table, /obj/structure/ca

/mob/living/simple_animal/hostile/mimic/copy/ranged/OpenFire(the_target)
if(Zapgun)
if(Zapgun.cell)
if(Zapgun.installed_cell)
var/obj/item/ammo_casing/energy/shot = Zapgun.ammo_type[Zapgun.select]
if(Zapgun.cell.charge >= shot.e_cost)
Zapgun.cell.use(shot.e_cost)
if(Zapgun.installed_cell.charge >= shot.rounds_per_shot)
Zapgun.installed_cell.use(shot.rounds_per_shot)
Zapgun.update_appearance()
..()
else if(Pewgun)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/ammunition/energy/_energy.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
desc = "The part of the gun that makes the laser go pew."
caliber = "energy"
projectile_type = /obj/projectile/energy
var/e_cost = 1000 //The amount of energy a cell needs to expend to create this shot.
var/rounds_per_shot = 1000 //The amount of energy a cell needs to expend to create this shot.
var/select_name = "energy"
fire_sound = 'sound/weapons/gun/laser/nt-fire.ogg'
firing_effect_type = /obj/effect/temp_visual/dir_setting/firing_effect/energy
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/ammunition/energy/ebow.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/obj/item/ammo_casing/energy/bolt
projectile_type = /obj/projectile/energy/bolt
select_name = "bolt"
e_cost = 500
rounds_per_shot = 500
fire_sound = 'sound/weapons/genhit.ogg'

/obj/item/ammo_casing/energy/bolt/halloween
Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/ammunition/energy/gravity.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/obj/item/ammo_casing/energy/gravity
e_cost = 0
rounds_per_shot = 0
fire_sound = 'sound/weapons/wave.ogg'
select_name = "gravity"
delay = 50
Expand Down
Loading
Loading