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

support for partially-filled/empty guns which still have magazines #3008

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@
dir = 4
},
/obj/item/ammo_box/magazine/co9mm{
start_empty = 1
percent_fill = 0
},
/obj/item/ammo_casing/c9mm{
icon_state = "pistol-brass-empty";
Expand Down Expand Up @@ -2714,7 +2714,7 @@
dir = 1
},
/obj/item/ammo_box/magazine/smgm9mm{
start_empty = 1
percent_fill = 0
},
/obj/item/gun/ballistic/automatic/smg/proto,
/turf/open/floor/plasteel/dark,
Expand Down Expand Up @@ -4361,7 +4361,7 @@
"RC" = (
/obj/effect/turf_decal/siding/white,
/obj/item/ammo_box/magazine/m10mm{
start_empty = 1
percent_fill = 0
},
/obj/item/ammo_casing/c10mm{
icon_state = "pistol-steel-empty";
Expand Down Expand Up @@ -5014,7 +5014,7 @@
/obj/effect/decal/cleanable/blood/old,
/obj/effect/turf_decal/siding/white,
/obj/item/ammo_box/magazine/m10mm{
start_empty = 1
percent_fill = 0
},
/turf/open/floor/concrete/pavement/lava,
/area/overmap_encounter/planetoid/lava/explored)
Expand Down
2 changes: 1 addition & 1 deletion _maps/RandomRuins/SpaceRuins/spacemall.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -12885,7 +12885,7 @@
/obj/item/ammo_box/magazine/co9mm{
pixel_x = 6;
pixel_y = 4;
start_empty = 1
percent_fill = 0
},
/turf/open/floor/plasteel,
/area/ruin/space/has_grav/spacemall/shop2)
Expand Down
9 changes: 9 additions & 0 deletions code/modules/cargo/packs/ammo.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/datum/supply_pack/ammo
group = "Ammunition"
crate_type = /obj/structure/closet/crate/secure/gear
var/start_empty = FALSE

/datum/supply_pack/ammo/fill(obj/structure/closet/crate/C)
. = ..()
if(!start_empty)
return .
for(var/obj/item/ammo_box/magazine/clippy in C.contents)
var/list/boolets = clippy.ammo_list(TRUE)
QDEL_LIST(boolets)

/*
Pistol ammo
Expand Down
8 changes: 8 additions & 0 deletions code/modules/cargo/packs/gun.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/datum/supply_pack/gun
group = "Guns"
crate_type = /obj/structure/closet/crate/secure/weapon
var/start_empty = FALSE

/datum/supply_pack/gun/fill(obj/structure/closet/crate/C)
. = ..()
if(!start_empty)
return .
for(var/obj/item/gun/thegun in C.contents)
thegun.set_empty()

/*
Pistols
Expand Down
11 changes: 6 additions & 5 deletions code/modules/projectiles/boxes_magazines/_box_magazine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
var/multiload = TRUE
///Whether or not an ammo box skips the do_after process (e.g. speedloaders)
var/instant_load = FALSE
///Whether the magazine should start with nothing in it
var/start_empty = FALSE
///Amount of our max ammo we should start with, as a multiplier. Can be overridden by Initialize.
var/percent_fill = 1
///cost of all the bullets in the magazine/box
var/list/bullet_cost
///cost of the materials in the magazine/box itself
var/list/base_cost

/obj/item/ammo_box/Initialize()
/obj/item/ammo_box/Initialize(mapload, ammo_mod = percent_fill)
. = ..()
if(!base_icon_state)
base_icon_state = icon_state
Expand All @@ -48,8 +48,9 @@
material_amount *= 0.90 // 10% for the container
material_amount /= max_ammo
LAZYSET(bullet_cost, material, material_amount)
if(!start_empty)
for(var/i = 1, i <= max_ammo, i++)
if(ammo_mod)
var/bullets = round(max_ammo * clamp(ammo_mod, 0, 1), 1)
for(var/i = 1, i <= bullets, i++)
stored_ammo += new ammo_type(src)
update_ammo_count()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "generic ammo box"
desc = "A generic, unbranded box of ammo. It doesn't have great capacity, but it can hold a variety of different calibers."
max_ammo = 20
start_empty = TRUE
percent_fill = 0
icon_state = "generic-ammo"
/// Does the box currently have an ammo type set?
var/ammo_set = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
name = "bowstring"
ammo_type = /obj/item/ammo_casing/caseless/arrow
max_ammo = 1
start_empty = TRUE
percent_fill = 0
caliber = "arrow"
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
name = "improvised shotgun internal magazine"
ammo_type = /obj/item/ammo_casing/shotgun/improvised
max_ammo = 1
start_empty = TRUE
percent_fill = 0

/obj/item/ammo_box/magazine/internal/shot/riot
name = "riot shotgun internal magazine"
Expand Down
6 changes: 6 additions & 0 deletions code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
var/knife_x_offset = 0
var/knife_y_offset = 0

///Amount of max ammo our magazine or cell spawns with, as a multiplier. Used by energy/ballistic guns
var/percent_fill = 1

var/ammo_x_offset = 0 //used for positioning ammo count overlay on sprite
var/ammo_y_offset = 0
var/flight_x_offset = 0
Expand Down Expand Up @@ -160,6 +163,9 @@
. = ..()
AddComponent(/datum/component/two_handed)

/// Used to empty this gun's magazine/cell/etc post-spawn
/obj/item/gun/proc/set_empty()

/// triggered on wield of two handed item
/obj/item/gun/proc/on_wield(obj/item/source, mob/user)
wielded = TRUE
Expand Down
13 changes: 10 additions & 3 deletions code/modules/projectiles/guns/ballistic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,25 @@
///If we have the 'snowflake mechanic,' how long should it take to reload?
var/tactical_reload_delay = 1 SECONDS

/obj/item/gun/ballistic/Initialize()
/obj/item/gun/ballistic/Initialize(mapload, ammo_mod = percent_fill)
. = ..()
if (!spawnwithmagazine && !ispath(mag_type, /obj/item/ammo_box/magazine/internal))
bolt_locked = TRUE
update_appearance()
return
if (!magazine)
magazine = new mag_type(src)
magazine = new mag_type(src, ammo_mod)
if (!spawnwithmagazine)
get_ammo_list (drop_all = TRUE)
set_empty()
chamber_round()
update_appearance()

/obj/item/gun/ballistic/set_empty()
if(magazine)
var/list/L = get_ammo_list(drop_all = TRUE)
QDEL_LIST(L)
update_appearance()

/obj/item/gun/ballistic/update_icon_state()
if(current_skin)
icon_state = "[unique_reskin[current_skin]][sawn_off ? "_sawn" : ""]"
Expand Down
1 change: 1 addition & 0 deletions code/modules/projectiles/guns/ballistic/revolver.dm
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@
mag_type = /obj/item/ammo_box/magazine/internal/cylinder/rev38
obj_flags = UNIQUE_RENAME
semi_auto = TRUE //double action
spawnwithmagazine = FALSE
safety_wording = "safety"
unique_reskin = list("Default" = "detective",
"Stainless Steel" = "detective_stainless",
Expand Down
13 changes: 8 additions & 5 deletions code/modules/projectiles/guns/energy.dm
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,23 @@
/obj/item/gun/energy/get_cell()
return cell

/obj/item/gun/energy/Initialize()
/obj/item/gun/energy/Initialize(mapload, ammo_mod = percent_fill)
. = ..()
if(cell_type)
cell = new cell_type(src)
else
cell = new(src)
if(!dead_cell)
cell.give(cell.maxcharge)
if(ammo_mod)
cell.give(cell.maxcharge * ammo_mod)
update_ammo_types()
recharge_newshot(TRUE)
if(selfcharge)
START_PROCESSING(SSobj, src)
update_appearance()

/obj/item/gun/energy/set_empty()
if(cell)
cell.use(cell.maxcharge)
update_appearance()

/obj/item/gun/energy/ComponentInitialize()
. = ..()
AddElement(/datum/element/update_icon_updates_onmob)
Expand Down
Loading