[MIRROR] Dunking handle_atom_del() in the trash bin. [MDB IGNORE] (#23183)

* Dunking handle_atom_del() in the trash bin.

* Update _box_magazine.dm

* Modular paths

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
Co-authored-by: Giz <13398309+vinylspiders@users.noreply.github.com>
This commit is contained in:
SkyratBot
2023-08-18 18:17:04 +02:00
committed by GitHub
parent da34f6839a
commit d21e06104f
70 changed files with 356 additions and 468 deletions

View File

@@ -50,6 +50,15 @@
QDEL_LIST(stored_ammo)
return ..()
/obj/item/ammo_box/Exited(atom/movable/gone, direction)
. = ..()
if(gone in stored_ammo)
remove_from_stored_ammo(gone)
/obj/item/ammo_box/proc/remove_from_stored_ammo(atom/movable/gone)
stored_ammo -= gone
update_appearance()
/obj/item/ammo_box/add_weapon_description()
AddElement(/datum/element/weapon_description, attached_proc = PROC_REF(add_notes_box))
@@ -84,19 +93,19 @@
return
for(var/i in max(1, stored_ammo.len) to max_ammo)
stored_ammo += new round_check() //SKYRAT EDTI CHANGE - SEC_HUAL - Moving to nullspace seems to help with lag.
stored_ammo += new round_check(src)
update_appearance()
///gets a round from the magazine, if keep is TRUE the round will stay in the gun
///gets a round from the magazine, if keep is TRUE the round will be moved to the bottom of the list.
/obj/item/ammo_box/proc/get_round(keep = FALSE)
if (!stored_ammo.len)
var/ammo_len = length(stored_ammo)
if (!ammo_len)
return null
else
var/b = stored_ammo[stored_ammo.len]
stored_ammo -= b
if (keep)
stored_ammo.Insert(1,b)
return b
var/casing = stored_ammo[ammo_len]
if (keep)
stored_ammo -= casing
stored_ammo.Insert(1,casing)
return casing
///puts a round into the magazine
/obj/item/ammo_box/proc/give_round(obj/item/ammo_casing/R, replace_spent = 0)
@@ -106,7 +115,7 @@
if (stored_ammo.len < max_ammo)
stored_ammo += R
R.moveToNullspace() //SKYRAT EDTI CHANGE - SEC_HUAL - Moving to nullspace seems to help with lag.
R.forceMove(src)
return TRUE
//for accessibles magazines (e.g internal ones) when full, start replacing spent ammo
@@ -117,7 +126,7 @@
AC.forceMove(get_turf(src.loc))
stored_ammo += R
R.moveToNullspace() //SKYRAT EDTI CHANGE - SEC_HUAL - Moving to nullspace seems to help with lag.
R.forceMove(src)
return TRUE
return FALSE
@@ -173,7 +182,6 @@
desc = "[initial(desc)] There [(shells_left == 1) ? "is" : "are"] [shells_left] shell\s left!"
/obj/item/ammo_box/update_icon_state()
. = ..()
var/shells_left = LAZYLEN(stored_ammo)
switch(multiple_sprites)
if(AMMO_BOX_PER_BULLET)
@@ -181,19 +189,20 @@
if(AMMO_BOX_FULL_EMPTY)
icon_state = "[multiple_sprite_use_base ? base_icon_state : initial(icon_state)]-[shells_left ? "full" : "empty"]"
/obj/item/ammo_box/update_overlays()
. = ..()
if(ammo_band_color && ammo_band_icon)
. += update_ammo_band()
update_ammo_band()
return ..()
/obj/item/ammo_box/proc/update_ammo_band()
overlays.Cut()
var/band_icon = ammo_band_icon
if(!(length(stored_ammo)) && ammo_band_icon_empty)
band_icon = ammo_band_icon_empty
var/image/ammo_band_image = image(icon, src, band_icon)
ammo_band_image.color = ammo_band_color
ammo_band_image.appearance_flags = RESET_COLOR|KEEP_APART
return ammo_band_image
overlays += ammo_band_image
///Count of number of bullets in the magazine
/obj/item/ammo_box/magazine/proc/ammo_count(countempties = TRUE)
@@ -204,11 +213,8 @@
return boolets
///list of every bullet in the magazine
/obj/item/ammo_box/magazine/proc/ammo_list(drop_list = FALSE)
var/list/L = stored_ammo.Copy()
if(drop_list)
stored_ammo.Cut()
return L
/obj/item/ammo_box/magazine/proc/ammo_list()
return stored_ammo.Copy()
///drops the entire contents of the magazine on the floor
/obj/item/ammo_box/magazine/proc/empty_magazine()
@@ -216,14 +222,3 @@
for(var/obj/item/ammo in stored_ammo)
ammo.forceMove(turf_mag)
stored_ammo -= ammo
/obj/item/ammo_box/magazine/handle_atom_del(atom/A)
stored_ammo -= A
update_appearance()
//SKRYAT EDIT ADDITION BEGIN - SEC_HAUL
/obj/item/ammo_box/Destroy()
. = ..()
for(var/i in stored_ammo)
qdel(i)
//SKYRAT EDIT END

View File

@@ -4,14 +4,18 @@
caliber = CALIBER_357
max_ammo = 7
/obj/item/ammo_box/magazine/internal/cylinder/get_round(keep = 0)
///Here, we have to maintain the list size, to emulate a cylinder with several chambers, empty or otherwise.
/obj/item/ammo_box/magazine/internal/cylinder/remove_from_stored_ammo(atom/movable/gone)
for(var/index in 1 to length(stored_ammo))
var/obj/item/ammo_casing/bullet = stored_ammo[index]
if(gone == bullet)
stored_ammo[index] = null
update_appearance()
return
/obj/item/ammo_box/magazine/internal/cylinder/get_round()
rotate()
var/b = stored_ammo[1]
if(!keep)
stored_ammo[1] = null
return b
return stored_ammo[1]
/obj/item/ammo_box/magazine/internal/cylinder/proc/rotate()
var/b = stored_ammo[1]
@@ -22,15 +26,10 @@
for(var/i in 1 to rand(0, max_ammo*2))
rotate()
/obj/item/ammo_box/magazine/internal/cylinder/ammo_list(drop_list = FALSE)
var/list/L = list()
for(var/i=1 to stored_ammo.len)
var/obj/item/ammo_casing/bullet = stored_ammo[i]
if(bullet)
L.Add(bullet)
if(drop_list)//We have to maintain the list size, to emulate a cylinder
stored_ammo[i] = null
return L
/obj/item/ammo_box/magazine/internal/cylinder/ammo_list()
var/list/no_nulls_ammo = stored_ammo.Copy()
list_clear_nulls(no_nulls_ammo)
return no_nulls_ammo
/obj/item/ammo_box/magazine/internal/cylinder/give_round(obj/item/ammo_casing/R, replace_spent = 0)
if(!R || !(caliber ? (caliber == R.caliber) : (ammo_type == R.type)))

View File

@@ -111,22 +111,19 @@
/obj/item/gun/proc/add_seclight_point()
return
/obj/item/gun/handle_atom_del(atom/A)
if(A == pin)
/obj/item/gun/Exited(atom/movable/gone, direction)
. = ..()
if(gone == pin)
pin = null
if(A == chambered)
if(gone == chambered)
chambered = null
update_appearance()
if(A == suppressed)
if(gone == suppressed)
clear_suppressor()
return ..()
/obj/item/gun/Exited(atom/movable/gone, direction)
if(gone == bayonet)
bayonet = null
if(!QDELING(src))
update_appearance()
return ..()
///Clears var and updates icon. In the case of ballistic weapons, also updates the gun's weight.
/obj/item/gun/proc/clear_suppressor()

View File

@@ -259,27 +259,34 @@
stack_trace("Trying to move a qdeleted casing of type [casing.type]!")
chambered = null
else if(casing_ejector || !from_firing)
chambered = null
casing.forceMove(drop_location()) //Eject casing onto ground.
if(!QDELETED(casing))
casing.bounce_away(TRUE)
SEND_SIGNAL(casing, COMSIG_CASING_EJECTED)
else if(empty_chamber)
UnregisterSignal(chambered, COMSIG_MOVABLE_MOVED)
chambered = null
if (chamber_next_round && (magazine?.max_ammo > 1))
chamber_round()
///Used to chamber a new round and eject the old one
/obj/item/gun/ballistic/proc/chamber_round(keep_bullet = FALSE, spin_cylinder, replace_new_round)
/obj/item/gun/ballistic/proc/chamber_round(spin_cylinder, replace_new_round)
if (chambered || !magazine)
return
if (magazine.ammo_count())
chambered = magazine.get_round(keep_bullet || bolt_type == BOLT_TYPE_NO_BOLT)
chambered = magazine.get_round((bolt_type == BOLT_TYPE_OPEN && !bolt_locked) || bolt_type == BOLT_TYPE_NO_BOLT)
if (bolt_type != BOLT_TYPE_OPEN)
chambered.forceMove(src)
else
RegisterSignal(chambered, COMSIG_MOVABLE_MOVED, PROC_REF(clear_chambered))
if(replace_new_round)
magazine.give_round(new chambered.type)
/obj/item/gun/ballistic/proc/clear_chambered(datum/source)
SIGNAL_HANDLER
UnregisterSignal(chambered, COMSIG_MOVABLE_MOVED)
chambered = null
///updates a bunch of racking related stuff and also handles the sound effects and the like
/obj/item/gun/ballistic/proc/rack(mob/user = null)
if (bolt_type == BOLT_TYPE_NO_BOLT) //If there's no bolt, nothing to rack
@@ -323,7 +330,7 @@
else
playsound(src, load_empty_sound, load_sound_volume, load_sound_vary)
if (bolt_type == BOLT_TYPE_OPEN && !bolt_locked)
chamber_round(TRUE)
chamber_round()
update_appearance()
return TRUE
else
@@ -510,7 +517,7 @@
if(bolt_type == BOLT_TYPE_NO_BOLT)
chambered = null
var/num_unloaded = 0
for(var/obj/item/ammo_casing/CB in get_ammo_list(FALSE, TRUE))
for(var/obj/item/ammo_casing/CB as anything in get_ammo_list(FALSE))
CB.forceMove(drop_location())
CB.bounce_away(FALSE, NONE)
num_unloaded++
@@ -561,14 +568,12 @@
return bullets
///gets a list of every bullet in the gun
/obj/item/gun/ballistic/proc/get_ammo_list(countchambered = TRUE, drop_all = FALSE)
/obj/item/gun/ballistic/proc/get_ammo_list(countchambered = TRUE)
var/list/rounds = list()
if(chambered && countchambered)
rounds.Add(chambered)
if(drop_all)
chambered = null
if(magazine)
rounds.Add(magazine.ammo_list(drop_all))
rounds.Add(magazine.ammo_list())
return rounds
#define BRAINS_BLOWN_THROW_RANGE 3

View File

@@ -33,38 +33,33 @@
if(isnull(chambered))
return ..()
chambered.forceMove(drop_location())
magazine.get_round(keep = FALSE)
var/obj/item/ammo_casing/arrow/our_arrow = chambered
user.put_in_hands(our_arrow)
drawn = FALSE
chambered = null
user.put_in_hands(chambered)
chambered = magazine.get_round()
update_appearance()
/obj/item/gun/ballistic/bow/proc/drop_arrow()
drawn = FALSE
if(chambered)
chambered.forceMove(drop_location())
magazine.get_round(keep = FALSE)
chambered = null
chambered.forceMove(drop_location())
chambered = magazine.get_round()
update_appearance()
/obj/item/gun/ballistic/bow/chamber_round(keep_bullet = FALSE, spin_cylinder, replace_new_round)
/obj/item/gun/ballistic/bow/chamber_round(spin_cylinder, replace_new_round)
if(chambered || !magazine)
return
if(magazine.ammo_count())
chambered = magazine.get_round(TRUE)
chambered.forceMove(src)
chambered = magazine.get_round()
RegisterSignal(chambered, COMSIG_MOVABLE_MOVED, PROC_REF(clear_chambered))
update_appearance()
/obj/item/gun/ballistic/bow/clear_chambered(datum/source)
. = ..()
drawn = FALSE
/obj/item/gun/ballistic/bow/attack_self(mob/user)
if(!chambered)
balloon_alert(user, "no arrow nocked!")
else
balloon_alert(user, "[drawn ? "string released" : "string drawn"]")
drawn = !drawn
playsound(src, 'sound/weapons/gun/bow/bow_draw.ogg', 25, TRUE)
return
balloon_alert(user, "[drawn ? "string released" : "string drawn"]")
drawn = !drawn
playsound(src, 'sound/weapons/gun/bow/bow_draw.ogg', 25, TRUE)
update_appearance()
/obj/item/gun/ballistic/bow/afterattack(atom/target, mob/living/user, flag, params, passthrough = FALSE)
@@ -74,11 +69,8 @@
if(!drawn)
to_chat(user, span_warning("Without drawing the bow, the arrow uselessly falls to the ground."))
drop_arrow()
update_appearance()
return
drawn = FALSE
. = ..() //fires, removing the arrow
update_appearance()
return ..() //fires, removing the arrow
/obj/item/gun/ballistic/bow/equipped(mob/user, slot, initial)
. = ..()
@@ -94,10 +86,11 @@
addtimer(CALLBACK(src, PROC_REF(drop_arrow_if_not_held)), 0.1 SECONDS)
/obj/item/gun/ballistic/bow/proc/drop_arrow_if_not_held()
if(!ismob(loc))
if(drawn)
playsound(src, 'sound/weapons/gun/bow/bow_fire.ogg', 25, TRUE)
drop_arrow()
if(ismob(loc) || !chambered)
return
if(drawn)
playsound(src, 'sound/weapons/gun/bow/bow_fire.ogg', 25, TRUE)
drop_arrow()
/obj/item/gun/ballistic/bow/shoot_with_empty_chamber(mob/living/user)
return //no clicking sounds please

View File

@@ -21,13 +21,17 @@
last_fire = world.time
/obj/item/gun/ballistic/revolver/chamber_round(keep_bullet, spin_cylinder = TRUE, replace_new_round)
/obj/item/gun/ballistic/revolver/chamber_round(spin_cylinder = TRUE, replace_new_round)
if(!magazine) //if it mag was qdel'd somehow.
CRASH("revolver tried to chamber a round without a magazine!")
if(chambered)
UnregisterSignal(chambered, COMSIG_MOVABLE_MOVED)
if(spin_cylinder)
chambered = magazine.get_round(TRUE)
else
chambered = magazine.stored_ammo[1]
if(chambered)
RegisterSignal(chambered, COMSIG_MOVABLE_MOVED, PROC_REF(clear_chambered))
/obj/item/gun/ballistic/revolver/shoot_with_empty_chamber(mob/living/user as mob|obj)
..()

View File

@@ -139,11 +139,11 @@
return ..()
/obj/item/gun/energy/handle_atom_del(atom/A)
if(A == cell)
/obj/item/gun/energy/Exited(atom/movable/gone, direction)
. = ..()
if(gone == cell)
cell = null
update_appearance()
return ..()
/obj/item/gun/energy/process(seconds_per_tick)
if(selfcharge && cell && cell.percent() < 100)

View File

@@ -62,11 +62,11 @@
cached_target = null
return ..()
/obj/item/gun/blastcannon/handle_atom_del(atom/A)
if(A == bomb)
/obj/item/gun/blastcannon/Exited(atom/movable/gone, direction)
. = ..()
if(gone == bomb)
bomb = null
update_appearance()
return ..()
/obj/item/gun/blastcannon/assume_air(datum/gas_mixture/giver)
qdel(giver)

View File

@@ -38,10 +38,10 @@
max_syringes = reset_fantasy_variable("max_syringes", max_syringes)
return ..()
/obj/item/gun/syringe/handle_atom_del(atom/A)
/obj/item/gun/syringe/Exited(atom/movable/gone, direction)
. = ..()
if(A in syringes)
syringes.Remove(A)
if(gone in syringes)
syringes -= gone
/obj/item/gun/syringe/recharge_newshot()
if(!syringes.len)