diff --git a/code/modules/cargo/packs.dm b/code/modules/cargo/packs.dm index 8d7698e0bce..9aa8f8ca7fe 100644 --- a/code/modules/cargo/packs.dm +++ b/code/modules/cargo/packs.dm @@ -2538,3 +2538,27 @@ /obj/item/stock_parts/subspace/ansible ) crate_name = "crate" + +///Special supply crate that generates random syndicate gear up to a determined TC value +/datum/supply_pack/misc/syndicate + name = "Assorted Syndicate Gear" + desc = "Contains a random assortment of syndicate gear." + special = TRUE ///Cannot be ordered via cargo + contains = list() + crate_name = "syndicate gear crate" + crate_type = /obj/structure/closet/crate + var/crate_value = 30 ///Total TC worth of contained uplink items + +///Generate assorted uplink items, taking into account the same surplus modifiers used for surplus crates +/datum/supply_pack/misc/syndicate/fill(obj/structure/closet/crate/C) + var/list/uplink_items = get_uplink_items(SSticker.mode) + while(crate_value) + var/category = pick(uplink_items) + var/item = pick(uplink_items[category]) + var/datum/uplink_item/I = uplink_items[category][item] + if(!I.surplus || prob(100 - I.surplus)) + continue + if(crate_value < I.cost) + continue + crate_value -= I.cost + new I.item(C) diff --git a/code/modules/events/stray_cargo.dm b/code/modules/events/stray_cargo.dm new file mode 100644 index 00000000000..f7ff0e6bc57 --- /dev/null +++ b/code/modules/events/stray_cargo.dm @@ -0,0 +1,99 @@ +///Spawns a cargo pod containing a random cargo supply pack on a random area of the station +/datum/round_event_control/stray_cargo + name = "Stray Cargo Pod" + typepath = /datum/round_event/stray_cargo + weight = 20 + max_occurrences = 4 + earliest_start = 10 MINUTES + +///Spawns a cargo pod containing a random cargo supply pack on a random area of the station +/datum/round_event/stray_cargo + var/area/impact_area ///Randomly picked area + announceChance = 75 + var/list/possible_pack_types = list() ///List of possible supply packs dropped in the pod, if empty picks from the cargo list + var/static/list/stray_spawnable_supply_packs = list() ///List of default spawnable supply packs, filtered from the cargo list + +/datum/round_event/stray_cargo/announce(fake) + priority_announce("Stray cargo pod detected on long-range scanners. Expected location of impact: [impact_area.name].", "Collision Alert") + +/** +* Tries to find a valid area, throws an error if none are found +* Also randomizes the start timer +*/ +/datum/round_event/stray_cargo/setup() + startWhen = rand(20, 40) + impact_area = find_event_area() + if(!impact_area) + CRASH("No valid areas for cargo pod found.") + var/list/turf_test = get_area_turfs(impact_area) + if(!turf_test.len) + CRASH("Stray Cargo Pod : No valid turfs found for [impact_area] - [impact_area.type]") + + if(!stray_spawnable_supply_packs.len) + stray_spawnable_supply_packs = SSshuttle.supply_packs.Copy() + for(var/pack in stray_spawnable_supply_packs) + var/datum/supply_pack/pack_type = pack + if(initial(pack_type.special)) + stray_spawnable_supply_packs -= pack + +///Spawns a random supply pack, puts it in a pod, and spawns it on a random tile of the selected area +/datum/round_event/stray_cargo/start() + var/list/turf/valid_turfs = get_area_turfs(impact_area) + //Only target non-dense turfs to prevent wall-embedded pods + for(var/i in valid_turfs) + var/turf/T = i + if(T.density) + valid_turfs -= T + var/turf/LZ = pick(valid_turfs) + var/pack_type + if(possible_pack_types.len) + pack_type = pick(possible_pack_types) + else + pack_type = pick(stray_spawnable_supply_packs) + var/datum/supply_pack/SP = new pack_type + var/obj/structure/closet/crate/crate = SP.generate(null) + crate.locked = FALSE //Unlock secure crates + crate.update_icon() + var/obj/structure/closet/supplypod/pod = make_pod() + new /obj/effect/DPtarget(LZ, pod, crate) + +///Handles the creation of the pod, in case it needs to be modified beforehand +/datum/round_event/stray_cargo/proc/make_pod() + var/obj/structure/closet/supplypod/S = new + return S + +///Picks an area that wouldn't risk critical damage if hit by a pod explosion +/datum/round_event/stray_cargo/proc/find_event_area() + var/static/list/allowed_areas + if(!allowed_areas) + ///Places that shouldn't explode + var/list/safe_area_types = typecacheof(list( + /area/ai_monitored/turret_protected/ai, + /area/ai_monitored/turret_protected/ai_upload, + /area/engine, + /area/shuttle) + ) + + ///Subtypes from the above that actually should explode. + var/list/unsafe_area_subtypes = typecacheof(list(/area/engine/break_room)) + allowed_areas = make_associative(GLOB.the_station_areas) - safe_area_types + unsafe_area_subtypes + var/list/possible_areas = typecache_filter_list(GLOB.sortedAreas,allowed_areas) + if (length(possible_areas)) + return pick(possible_areas) + +///A rare variant that drops a crate containing syndicate uplink items +/datum/round_event_control/stray_cargo/syndicate + name = "Stray Syndicate Cargo Pod" + typepath = /datum/round_event/stray_cargo/syndicate + weight = 6 + max_occurrences = 1 + earliest_start = 30 MINUTES + +/datum/round_event/stray_cargo/syndicate + possible_pack_types = list(/datum/supply_pack/misc/syndicate) + +///Apply the syndicate pod skin +/datum/round_event/stray_cargo/syndicate/make_pod() + var/obj/structure/closet/supplypod/S = new + S.setStyle(STYLE_SYNDICATE) + return S diff --git a/tgstation.dme b/tgstation.dme index dfba0817a6c..a6d482b40d4 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -1795,6 +1795,7 @@ #include "code\modules\events\spacevine.dm" #include "code\modules\events\spider_infestation.dm" #include "code\modules\events\spontaneous_appendicitis.dm" +#include "code\modules\events\stray_cargo.dm" #include "code\modules\events\vent_clog.dm" #include "code\modules\events\wisdomcow.dm" #include "code\modules\events\wormholes.dm"