mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-09 00:13:55 +00:00
* split area.contained_turfs up by zlevel, make init 10 seconds faster (#80941) ## About The Pull Request Situation: areas have a list of all turfs in their area. Problem: `/area/space` is an area and has a 6 to 7 digit count of turfs that has to be traversed for every turf we need to remove from it. This can take multiple byond ticks just to preform this action for a single space rune Solution: split the list by zlevel, and only search the right zlevel list when removing turfs from areas. replaces `area.get_contained_turfs()` with a few new procs: * `get_highest_zlevel()` - returns the highest zlevel the area contains turfs in. useful for use with `get_turfs_by_zlevel` * `get_turfs_by_zlevel(zlevel)` - returns a list of turfs in the area in a given zlevel. Useful for code that only cares about a specific zlevel or changes behavior based on zlevel like lighting init. * `get_turfs_from_all_zlevels()` - the replacement for `get_contained_turfs()`, renamed as such so anybody copying/cargo culting code gets a hint that a zlevel specific version might exist. Still used in for loops that type checked so byond would do that all at once * `get_zlevel_turf_lists()` - returns the area's zlevel lists of lists but only for non-empty zlevels. very useful for for loops. The area contents unit test has been rewritten to ensure any improper data triggers failures or runtimes by not having it use the helpers above (some of which ensure a list is always returned) and access the lists directly. * split area.contained_turfs up by zlevel, make init 10 seconds faster * eeyes * Update area_spawn_subsystem.dm * Unshits turf contain code slightly (#81023) Literally just implements my reviews from #80941 I am frankly a smidge pissed that the pr was merged without them being handled. No code is worth merging past known issues, and if the author is just gonna dip then that's life. I don't like privileging mso on stuff like this, especially because frankly I'm kinda mad at him rn but also because when a pr is made the onus on finishing it falls to the person who made it. Should not need to clean up after someone as a maintainer, and shouldn't normalize doing it. I'm not like mad at zypher directly mind he offered to do this too, just the idea he was espousing here. --------- Co-authored-by: Kyle Spier-Swenson <kyleshome@gmail.com> Co-authored-by: Gandalf <9026500+Gandalf2k15@users.noreply.github.com> Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
228 lines
9.7 KiB
Plaintext
228 lines
9.7 KiB
Plaintext
/obj/machinery/computer/cargo/express
|
|
name = "express supply console"
|
|
desc = "This console allows the user to purchase a package \
|
|
with 1/40th of the delivery time: made possible by Nanotrasen's new \"1500mm Orbital Railgun\".\
|
|
All sales are near instantaneous - please choose carefully"
|
|
icon_screen = "supply_express"
|
|
circuit = /obj/item/circuitboard/computer/cargo/express
|
|
blockade_warning = "Bluespace instability detected. Delivery impossible."
|
|
req_access = list(ACCESS_CARGO)
|
|
is_express = TRUE
|
|
interface_type = "CargoExpress"
|
|
|
|
var/message
|
|
var/printed_beacons = 0 //number of beacons printed. Used to determine beacon names.
|
|
var/list/meme_pack_data
|
|
var/obj/item/supplypod_beacon/beacon //the linked supplypod beacon
|
|
var/area/landingzone = /area/station/cargo/storage //where we droppin boys
|
|
var/podType = /obj/structure/closet/supplypod
|
|
var/cooldown = 0 //cooldown to prevent printing supplypod beacon spam
|
|
var/locked = TRUE //is the console locked? unlock with ID
|
|
var/usingBeacon = FALSE //is the console in beacon mode? exists to let beacon know when a pod may come in
|
|
|
|
/obj/machinery/computer/cargo/express/Initialize(mapload)
|
|
. = ..()
|
|
packin_up()
|
|
|
|
/obj/machinery/computer/cargo/express/on_construction(mob/user)
|
|
. = ..()
|
|
packin_up()
|
|
|
|
/obj/machinery/computer/cargo/express/Destroy()
|
|
if(beacon)
|
|
beacon.unlink_console()
|
|
return ..()
|
|
|
|
/obj/machinery/computer/cargo/express/attackby(obj/item/W, mob/living/user, params)
|
|
if(W.GetID() && allowed(user))
|
|
locked = !locked
|
|
to_chat(user, span_notice("You [locked ? "lock" : "unlock"] the interface."))
|
|
return
|
|
else if(istype(W, /obj/item/disk/cargo/bluespace_pod))
|
|
podType = /obj/structure/closet/supplypod/bluespacepod//doesnt effect circuit board, making reversal possible
|
|
to_chat(user, span_notice("You insert the disk into [src], allowing for advanced supply delivery vehicles."))
|
|
qdel(W)
|
|
return TRUE
|
|
else if(istype(W, /obj/item/supplypod_beacon))
|
|
var/obj/item/supplypod_beacon/sb = W
|
|
if (sb.express_console != src)
|
|
sb.link_console(src, user)
|
|
return TRUE
|
|
else
|
|
to_chat(user, span_alert("[src] is already linked to [sb]."))
|
|
..()
|
|
|
|
/obj/machinery/computer/cargo/express/emag_act(mob/user, obj/item/card/emag/emag_card)
|
|
if(obj_flags & EMAGGED)
|
|
return FALSE
|
|
if(user)
|
|
if (emag_card)
|
|
user.visible_message(span_warning("[user] swipes [emag_card] through [src]!"))
|
|
to_chat(user, span_notice("You change the routing protocols, allowing the Supply Pod to land anywhere on the station."))
|
|
obj_flags |= EMAGGED
|
|
contraband = TRUE
|
|
// This also sets this on the circuit board
|
|
var/obj/item/circuitboard/computer/cargo/board = circuit
|
|
board.obj_flags |= EMAGGED
|
|
board.contraband = TRUE
|
|
packin_up()
|
|
return TRUE
|
|
|
|
/obj/machinery/computer/cargo/express/proc/packin_up() // oh shit, I'm sorry
|
|
meme_pack_data = list() // sorry for what?
|
|
for(var/pack in SSshuttle.supply_packs) // our quartermaster taught us not to be ashamed of our supply packs
|
|
var/datum/supply_pack/P = SSshuttle.supply_packs[pack] // specially since they're such a good price and all
|
|
if(!meme_pack_data[P.group]) // yeah, I see that, your quartermaster gave you good advice
|
|
meme_pack_data[P.group] = list( // it gets cheaper when I return it
|
|
"name" = P.group, // mmhm
|
|
"packs" = list() // sometimes, I return it so much, I rip the manifest
|
|
) // see, my quartermaster taught me a few things too
|
|
if((P.hidden) || (P.special)) // like, how not to rip the manifest
|
|
continue// by using someone else's crate
|
|
if(P.contraband && !contraband) // will you show me?
|
|
continue // i'd be right happy to
|
|
meme_pack_data[P.group]["packs"] += list(list(
|
|
"name" = P.name,
|
|
"cost" = P.get_cost(),
|
|
"id" = pack,
|
|
"desc" = P.desc || P.name // If there is a description, use it. Otherwise use the pack's name.
|
|
))
|
|
|
|
/obj/machinery/computer/cargo/express/ui_data(mob/user)
|
|
var/canBeacon = beacon && (isturf(beacon.loc) || ismob(beacon.loc))//is the beacon in a valid location?
|
|
var/list/data = list()
|
|
var/datum/bank_account/D = SSeconomy.get_dep_account(cargo_account)
|
|
if(D)
|
|
data["points"] = D.account_balance
|
|
data["locked"] = locked//swipe an ID to unlock
|
|
data["siliconUser"] = user.has_unlimited_silicon_privilege
|
|
data["beaconzone"] = beacon ? get_area(beacon) : ""//where is the beacon located? outputs in the tgui
|
|
data["usingBeacon"] = usingBeacon //is the mode set to deliver to the beacon or the cargobay?
|
|
data["canBeacon"] = !usingBeacon || canBeacon //is the mode set to beacon delivery, and is the beacon in a valid location?
|
|
data["canBuyBeacon"] = cooldown <= 0 && D.account_balance >= BEACON_COST
|
|
data["beaconError"] = usingBeacon && !canBeacon ? "(BEACON ERROR)" : ""//changes button text to include an error alert if necessary
|
|
data["hasBeacon"] = beacon != null//is there a linked beacon?
|
|
data["beaconName"] = beacon ? beacon.name : "No Beacon Found"
|
|
data["printMsg"] = cooldown > 0 ? "Print Beacon for [BEACON_COST] credits ([cooldown])" : "Print Beacon for [BEACON_COST] credits"//buttontext for printing beacons
|
|
data["supplies"] = list()
|
|
message = "Sales are near-instantaneous - please choose carefully."
|
|
if(SSshuttle.supply_blocked)
|
|
message = blockade_warning
|
|
if(usingBeacon && !beacon)
|
|
message = "BEACON ERROR: BEACON MISSING"//beacon was destroyed
|
|
else if (usingBeacon && !canBeacon)
|
|
message = "BEACON ERROR: MUST BE EXPOSED"//beacon's loc/user's loc must be a turf
|
|
if(obj_flags & EMAGGED)
|
|
message = "(&!#@ERROR: R0UTING_#PRO7O&OL MALF(*CT#ON. $UG%ESTE@ ACT#0N: !^/PULS3-%E)ET CIR*)ITB%ARD."
|
|
data["message"] = message
|
|
if(!meme_pack_data)
|
|
packin_up()
|
|
stack_trace("There was no pack data for [src]")
|
|
data["supplies"] = meme_pack_data
|
|
if (cooldown > 0)//cooldown used for printing beacons
|
|
cooldown--
|
|
return data
|
|
|
|
/obj/machinery/computer/cargo/express/ui_act(action, params, datum/tgui/ui)
|
|
. = ..()
|
|
if(.)
|
|
return
|
|
|
|
switch(action)
|
|
if("LZCargo")
|
|
usingBeacon = FALSE
|
|
if (beacon)
|
|
beacon.update_status(SP_UNREADY) //ready light on beacon will turn off
|
|
if("LZBeacon")
|
|
usingBeacon = TRUE
|
|
if (beacon)
|
|
beacon.update_status(SP_READY) //turns on the beacon's ready light
|
|
if("printBeacon")
|
|
var/datum/bank_account/D = SSeconomy.get_dep_account(cargo_account)
|
|
if(D)
|
|
if(D.adjust_money(-BEACON_COST))
|
|
cooldown = 10//a ~ten second cooldown for printing beacons to prevent spam
|
|
var/obj/item/supplypod_beacon/C = new /obj/item/supplypod_beacon(drop_location())
|
|
C.link_console(src, usr)//rather than in beacon's Initialize(), we can assign the computer to the beacon by reusing this proc)
|
|
printed_beacons++//printed_beacons starts at 0, so the first one out will be called beacon # 1
|
|
beacon.name = "Supply Pod Beacon #[printed_beacons]"
|
|
|
|
|
|
if("add")//Generate Supply Order first
|
|
if(TIMER_COOLDOWN_RUNNING(src, COOLDOWN_EXPRESSPOD_CONSOLE))
|
|
say("Railgun recalibrating. Stand by.")
|
|
return
|
|
var/id = params["id"]
|
|
id = text2path(id) || id
|
|
var/datum/supply_pack/pack = SSshuttle.supply_packs[id]
|
|
if(!istype(pack))
|
|
CRASH("Unknown supply pack id given by express order console ui. ID: [params["id"]]")
|
|
var/name = "*None Provided*"
|
|
var/rank = "*None Provided*"
|
|
var/ckey = usr.ckey
|
|
if(ishuman(usr))
|
|
var/mob/living/carbon/human/H = usr
|
|
name = H.get_authentification_name()
|
|
rank = H.get_assignment(hand_first = TRUE)
|
|
else if(issilicon(usr))
|
|
name = usr.real_name
|
|
rank = "Silicon"
|
|
var/reason = ""
|
|
var/list/empty_turfs
|
|
var/datum/supply_order/SO = new(pack, name, rank, ckey, reason)
|
|
var/points_to_check
|
|
var/datum/bank_account/D = SSeconomy.get_dep_account(cargo_account)
|
|
if(D)
|
|
points_to_check = D.account_balance
|
|
if(!(obj_flags & EMAGGED))
|
|
if(SO.pack.get_cost() <= points_to_check)
|
|
var/LZ
|
|
if (istype(beacon) && usingBeacon)//prioritize beacons over landing in cargobay
|
|
LZ = get_turf(beacon)
|
|
beacon.update_status(SP_LAUNCH)
|
|
else if (!usingBeacon)//find a suitable supplypod landing zone in cargobay
|
|
landingzone = GLOB.areas_by_type[/area/station/cargo/storage]
|
|
if (!landingzone)
|
|
WARNING("[src] couldnt find a Quartermaster/Storage (aka cargobay) area on the station, and as such it has set the supplypod landingzone to the area it resides in.")
|
|
landingzone = get_area(src)
|
|
for(var/turf/open/floor/T in landingzone.get_turfs_from_all_zlevels())//uses default landing zone
|
|
if(T.is_blocked_turf())
|
|
continue
|
|
LAZYADD(empty_turfs, T)
|
|
CHECK_TICK
|
|
if(empty_turfs?.len)
|
|
LZ = pick(empty_turfs)
|
|
if (SO.pack.get_cost() <= points_to_check && LZ)//we need to call the cost check again because of the CHECK_TICK call
|
|
TIMER_COOLDOWN_START(src, COOLDOWN_EXPRESSPOD_CONSOLE, 5 SECONDS)
|
|
D.adjust_money(-SO.pack.get_cost())
|
|
if(pack.special_pod)
|
|
new /obj/effect/pod_landingzone(LZ, pack.special_pod, SO)
|
|
else
|
|
new /obj/effect/pod_landingzone(LZ, podType, SO)
|
|
. = TRUE
|
|
update_appearance()
|
|
else
|
|
if(SO.pack.get_cost() * (0.72*MAX_EMAG_ROCKETS) <= points_to_check) // bulk discount :^)
|
|
landingzone = GLOB.areas_by_type[pick(GLOB.the_station_areas)] //override default landing zone
|
|
for(var/turf/open/floor/T in landingzone.get_turfs_from_all_zlevels())
|
|
if(T.is_blocked_turf())
|
|
continue
|
|
LAZYADD(empty_turfs, T)
|
|
CHECK_TICK
|
|
if(empty_turfs?.len)
|
|
TIMER_COOLDOWN_START(src, COOLDOWN_EXPRESSPOD_CONSOLE, 10 SECONDS)
|
|
D.adjust_money(-(SO.pack.get_cost() * (0.72*MAX_EMAG_ROCKETS)))
|
|
|
|
SO.generateRequisition(get_turf(src))
|
|
for(var/i in 1 to MAX_EMAG_ROCKETS)
|
|
var/LZ = pick(empty_turfs)
|
|
LAZYREMOVE(empty_turfs, LZ)
|
|
if(pack.special_pod)
|
|
new /obj/effect/pod_landingzone(LZ, pack.special_pod, SO)
|
|
else
|
|
new /obj/effect/pod_landingzone(LZ, podType, SO)
|
|
. = TRUE
|
|
update_appearance()
|
|
CHECK_TICK
|
|
|