Fixes map element overwriting option (#31978)

* Fixes vault overwriting option

* Saner method of looping

* Actually works nice now

* Makes this static for performance

* Some debug logging for how long a vault takes to load

* Here too

* Removing logging, for future PR

* Changing this to handle qdels better

* Fixes how vending machines do it too

* Requested changes

* Forgot this too

* And this

* APC cells

* Set this to null too

Co-authored-by: kanef <kanef9x@protonmail.com>
This commit is contained in:
kane-f
2022-02-11 10:32:44 +00:00
committed by GitHub
parent 998025428c
commit f801f7d0e8
7 changed files with 44 additions and 34 deletions

View File

@@ -106,14 +106,14 @@
L[T] = MAX_VALUE //Set them equal to the max value which is unlikely to collide with any other pregenerated value L[T] = MAX_VALUE //Set them equal to the max value which is unlikely to collide with any other pregenerated value
//Removes returns a new list which only contains elements from the original list of a certain type //Removes returns a new list which only contains elements from the original list of a certain type
/proc/prune_list_to_type(list/L, datum/A) /proc/prune_list_to_type(list/L, datum/A, var/exclude_type = FALSE)
if(!L || !L.len || !A) if(!L || !L.len || !A)
return 0 return list()
if(!ispath(A)) if(!ispath(A))
A = A.type A = A.type
var/list/nu = L.Copy() var/list/nu = L.Copy()
for(var/element in nu) for(var/element in nu)
if(!istype(element,A)) if(istype(element,A) == exclude_type)
nu -= element nu -= element
return nu return nu

View File

@@ -37,7 +37,7 @@ var/list/datum/map_element/map_elements = list()
for(var/atom/A in objects) for(var/atom/A in objects)
A.spawned_by_map_element(src, objects) A.spawned_by_map_element(src, objects)
/datum/map_element/proc/load(x, y, z, rotate=0, override_can_rotate = FALSE) /datum/map_element/proc/load(x, y, z, rotate=0, overwrite = FALSE, override_can_rotate = FALSE)
//Location is always lower left corner. //Location is always lower left corner.
//In some cases, location is set to null (when creating a new z-level, for example) //In some cases, location is set to null (when creating a new z-level, for example)
//To account for that, location is set again in maploader's load_map() proc //To account for that, location is set again in maploader's load_map() proc
@@ -53,7 +53,7 @@ var/list/datum/map_element/map_elements = list()
if(file_path) if(file_path)
var/file = file(file_path) var/file = file(file_path)
if(isfile(file)) if(isfile(file))
var/list/L = maploader.load_map(file, z, x, y, src, rotation) var/list/L = maploader.load_map(file, z, x, y, src, rotation, overwrite)
initialize(L) initialize(L)
return L return L
else //No file specified - empty map element else //No file specified - empty map element

View File

@@ -187,7 +187,12 @@ var/global/num_vending_terminals = 1
if(wires) if(wires)
qdel(wires) qdel(wires)
wires = null wires = null
if(coinbox)
qdel(coinbox)
coinbox = null
..()
/obj/machinery/vending/proc/dump_vendpack_and_coinbox()
if(product_records.len && cardboard) //Only spit out if we have slotted cardboard if(product_records.len && cardboard) //Only spit out if we have slotted cardboard
if(is_custom_machine) if(is_custom_machine)
var/obj/structure/vendomatpack/custom/newpack = new(src.loc) var/obj/structure/vendomatpack/custom/newpack = new(src.loc)
@@ -207,7 +212,6 @@ var/global/num_vending_terminals = 1
if(coinbox) if(coinbox)
coinbox.forceMove(get_turf(src)) coinbox.forceMove(get_turf(src))
..()
/obj/machinery/vending/examine(var/mob/user) /obj/machinery/vending/examine(var/mob/user)
..() ..()
@@ -322,10 +326,12 @@ var/global/num_vending_terminals = 1
/obj/machinery/vending/ex_act(severity) /obj/machinery/vending/ex_act(severity)
switch(severity) switch(severity)
if(1.0) if(1.0)
dump_vendpack_and_coinbox()
qdel(src) qdel(src)
return return
if(2.0) if(2.0)
if (prob(50)) if (prob(50))
dump_vendpack_and_coinbox()
qdel(src) qdel(src)
return return
if(3.0) if(3.0)
@@ -337,6 +343,7 @@ var/global/num_vending_terminals = 1
if(prob(75)) if(prob(75))
malfunction() malfunction()
else else
dump_vendpack_and_coinbox()
qdel(src) qdel(src)
/obj/machinery/vending/emp_act(severity) /obj/machinery/vending/emp_act(severity)

View File

@@ -86,11 +86,6 @@
..() ..()
take_contents() take_contents()
// Fix for #383 - C4 deleting fridges with corpses
/obj/structure/closet/Destroy()
dump_contents()
..()
/obj/structure/closet/alter_health() /obj/structure/closet/alter_health()
return get_turf(src) return get_turf(src)
@@ -340,6 +335,7 @@
for(var/atom/movable/A in src)//pulls everything else out of the locker and hits it with an explosion for(var/atom/movable/A in src)//pulls everything else out of the locker and hits it with an explosion
A.forceMove(src.loc) A.forceMove(src.loc)
A.ex_act(severity++) A.ex_act(severity++)
dump_contents()
qdel(src) qdel(src)
if(2) if(2)
if(prob(50)) if(prob(50))
@@ -350,6 +346,7 @@
for (var/atom/movable/A as mob|obj in src) for (var/atom/movable/A as mob|obj in src)
A.forceMove(src.loc) A.forceMove(src.loc)
A.ex_act(severity++) A.ex_act(severity++)
dump_contents()
qdel(src) qdel(src)
if(3) if(3)
if(prob(5)) if(prob(5))
@@ -360,6 +357,7 @@
for(var/atom/movable/A as mob|obj in src) for(var/atom/movable/A as mob|obj in src)
A.forceMove(src.loc) A.forceMove(src.loc)
A.ex_act(severity++) A.ex_act(severity++)
dump_contents()
qdel(src) qdel(src)
/obj/structure/closet/shuttle_act() /obj/structure/closet/shuttle_act()
@@ -376,8 +374,7 @@
broken = 1 broken = 1
if(has_electronics) if(has_electronics)
dump_electronics() dump_electronics()
for(var/atom/movable/A as mob|obj in src) dump_contents()
A.forceMove(src.loc)
qdel(src) qdel(src)
return return
@@ -428,8 +425,7 @@
broken = 1 broken = 1
if(has_electronics) if(has_electronics)
dump_electronics() dump_electronics()
for(var/atom/movable/A as mob|obj in src) dump_contents()
A.forceMove(src.loc)
qdel(src) qdel(src)
// this should probably use dump_contents() // this should probably use dump_contents()
@@ -439,8 +435,7 @@
broken = 1 broken = 1
if(has_electronics) if(has_electronics)
dump_electronics() dump_electronics()
for(var/atom/movable/A as mob|obj in src) dump_contents()
A.forceMove(src.loc)
qdel(src) qdel(src)
/obj/structure/closet/attackby(obj/item/weapon/W as obj, mob/user as mob) /obj/structure/closet/attackby(obj/item/weapon/W as obj, mob/user as mob)
@@ -463,6 +458,7 @@
M.show_message("<span class='notice'>\The [src] has been cut apart by [user] with \the [WT].</span>", 1, "You hear welding.", 2) M.show_message("<span class='notice'>\The [src] has been cut apart by [user] with \the [WT].</span>", 1, "You hear welding.", 2)
if(has_electronics) if(has_electronics)
dump_electronics() dump_electronics()
dump_contents()
qdel(src) qdel(src)
return return
@@ -473,6 +469,7 @@
M.show_message("<span class='notice'>\The [src] has been dismantled by [user] with \the [WT].</span>", 1) M.show_message("<span class='notice'>\The [src] has been dismantled by [user] with \the [WT].</span>", 1)
if(has_electronics) if(has_electronics)
dump_electronics() dump_electronics()
dump_contents()
qdel(src) qdel(src)
return return

View File

@@ -1211,10 +1211,11 @@ var/list/admin_verbs_mod = list(
if(rotate == null) if(rotate == null)
return return
log_admin("[key_name(src)] is loading [ME.file_path] at z-level 2 (location chosen automatically) rotated by [rotate] degrees.") var/rotatetext = rotate ? " rotated by [rotate] degrees" : ""
message_admins("[key_name_admin(src)] is loading [ME.file_path] at z-level 2 (location chosen automatically) rotated by [rotate] degrees") log_admin("[key_name(src)] is loading [ME.file_path] at z-level 2 (location chosen automatically)[rotatetext].")
message_admins("[key_name_admin(src)] is loading [ME.file_path] at z-level 2 (location chosen automatically)[rotatetext].")
load_dungeon(ME, rotate, TRUE) load_dungeon(ME, rotate, TRUE)
message_admins("[ME.file_path] loaded at [ME.location ? formatJumpTo(ME.location) : "[x_coord], [y_coord], [z_coord]"] rotated by [rotate] degrees") message_admins("[ME.file_path] loaded at [ME.location ? formatJumpTo(ME.location) : "[x_coord], [y_coord], [z_coord]"][rotatetext].")
return return
@@ -1223,10 +1224,12 @@ var/list/admin_verbs_mod = list(
return return
var/overwrite = alert("Overwrite original objects in area?","Map element loading","Yes","No") == "Yes" var/overwrite = alert("Overwrite original objects in area?","Map element loading","Yes","No") == "Yes"
log_admin("[key_name(src)] is loading [ME.file_path] at [x_coord], [y_coord], [z_coord] rotated by [rotate] degrees") var/rotatetext = rotate ? " rotated by [rotate] degrees" : ""
message_admins("[key_name_admin(src)] is loading [ME.file_path] at [x_coord], [y_coord], [z_coord] rotated by [rotate] degrees") log_admin("[key_name(src)] is loading [ME.file_path] at [x_coord], [y_coord], [z_coord][rotatetext].")
ME.load(x_coord - 1, y_coord - 1, z_coord, rotate, overwrite, TRUE) //Reduce X and Y by 1 because these arguments are actually offsets, and they're added to 1;1 in the map loader. Without this, spawning something at 1;1 would result in it getting spawned at 2;2 message_admins("[key_name_admin(src)] is loading [ME.file_path] at [x_coord], [y_coord], [z_coord][rotatetext].")
message_admins("[ME.file_path] loaded at [ME.location ? formatJumpTo(ME.location) : "[x_coord], [y_coord], [z_coord]"] rotated by [rotate] degrees") //Reduce X and Y by 1 because these arguments are actually offsets, and they're added to 1;1 in the map loader. Without this, spawning something at 1;1 would result in it getting spawned at 2;2
ME.load(x_coord - 1, y_coord - 1, z_coord, rotate, overwrite, TRUE)
message_admins("[ME.file_path] loaded at [ME.location ? formatJumpTo(ME.location) : "[x_coord], [y_coord], [z_coord]"][rotatetext].")
/client/proc/create_awaymission() /client/proc/create_awaymission()
set category = "Admin" set category = "Admin"

View File

@@ -55,6 +55,7 @@ var/list/map_dimension_cache = list()
* *
*/ */
/dmm_suite/load_map(var/dmm_file as file, var/z_offset as num, var/x_offset as num, var/y_offset as num, var/datum/map_element/map_element as null, var/rotate as num, var/overwrite as num) /dmm_suite/load_map(var/dmm_file as file, var/z_offset as num, var/x_offset as num, var/y_offset as num, var/datum/map_element/map_element as null, var/rotate as num, var/overwrite as num)
if((rotate % 90) != 0) //If not divisible by 90, make it if((rotate % 90) != 0) //If not divisible by 90, make it
rotate += (rotate % 90) rotate += (rotate % 90)
@@ -303,8 +304,14 @@ var/list/map_dimension_cache = list()
members.Remove(members[index]) members.Remove(members[index])
//then instance the /turf and, if multiple tiles are presents, simulates the DMM underlays piling effect (only the last turf is spawned, other ones are drawn as underlays) if(overwrite) //make this come first so lighting overlays don't die
var/turf/T_old = locate(xcrd,ycrd,zcrd)
var/static/list/blacklisted_types = list(/mob/dead/observer,/mob/dview,/atom/movable/lighting_overlay)
for(var/atom/thing as anything in T_old.contents)
if(!is_type_in_list(thing.type,blacklisted_types))
qdel(thing)
//then instance the /turf and, if multiple tiles are presents, simulates the DMM underlays piling effect (only the last turf is spawned, other ones are drawn as underlays)
var/first_turf_index = 1 var/first_turf_index = 1
while(!ispath(members[first_turf_index],/turf)) //find first /turf object in members while(!ispath(members[first_turf_index],/turf)) //find first /turf object in members
first_turf_index++ first_turf_index++
@@ -329,10 +336,6 @@ var/list/map_dimension_cache = list()
spawned_atoms.Add(T) spawned_atoms.Add(T)
//finally instance all remainings objects/mobs //finally instance all remainings objects/mobs
if(overwrite)
var/turf/T_old = locate(xcrd,ycrd,zcrd)
for(var/atom/thing in T_old)
qdel(T_old)
for(index=1,index < first_turf_index,index++) for(index=1,index < first_turf_index,index++)
var/atom/new_atom = instance_atom(members[index],members_attributes[index],xcrd,ycrd,zcrd,rotate) var/atom/new_atom = instance_atom(members[index],members_attributes[index],xcrd,ycrd,zcrd,rotate)
spawned_atoms.Add(new_atom) spawned_atoms.Add(new_atom)
@@ -363,7 +366,7 @@ var/list/map_dimension_cache = list()
if(use_preloader && instance)//second preloader pass, for those atoms that don't ..() in New() if(use_preloader && instance)//second preloader pass, for those atoms that don't ..() in New()
_preloader.load(instance) _preloader.load(instance)
return instance return instance
//text trimming (both directions) helper proc //text trimming (both directions) helper proc

View File

@@ -584,6 +584,9 @@
"<span class='warning'>[src] has been cut from the wall by [user.name] with the weldingtool.</span>",\ "<span class='warning'>[src] has been cut from the wall by [user.name] with the weldingtool.</span>",\
"You cut the APC frame from the wall.",\ "You cut the APC frame from the wall.",\
"<span class='warning'>You hear welding.</span>") "<span class='warning'>You hear welding.</span>")
if(cell)
cell.forceMove(loc)
cell = null
qdel(src) qdel(src)
return return
else if (istype(W, /obj/item/mounted/frame/apc_frame) && opened && emagged) else if (istype(W, /obj/item/mounted/frame/apc_frame) && opened && emagged)
@@ -1275,9 +1278,6 @@
/obj/machinery/power/apc/ex_act(severity) /obj/machinery/power/apc/ex_act(severity)
switch(severity) switch(severity)
if(1) if(1)
if(cell)
qdel(cell)
cell = null
qdel(src) qdel(src)
if(2) if(2)
if(prob(50)) if(prob(50))
@@ -1342,7 +1342,7 @@
malfvacate(1) malfvacate(1)
if(cell) if(cell)
cell.forceMove(loc) qdel(cell)
cell = null cell = null
if(wires) if(wires)