From 44401403198d52d4d932802ef288ef7aa8424b97 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Thu, 22 Apr 2021 02:27:04 +0200 Subject: [PATCH] [MIRROR] The CE can now buy the BYOS (#5079) * The CE can now buy the BYOS (#58389) * The CE can now buy the BYOS * aaa Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> Co-authored-by: Gandalf --- code/controllers/subsystem/mapping.dm | 2 +- code/controllers/subsystem/shuttle.dm | 14 ++++++ code/datums/shuttles.dm | 41 ++++++++--------- .../game/machinery/computer/communications.dm | 44 ++++++++++++++++++- code/modules/events/shuttle_catastrophe.dm | 2 +- .../advanced_shuttles/code/shuttles.dm | 4 +- .../modules/assaultops/code/shuttle.dm | 4 +- .../modules/faction/code/mapping/ruins.dm | 2 +- .../modules/mapping/code/datums/shuttles.dm | 2 +- 9 files changed, 85 insertions(+), 30 deletions(-) diff --git a/code/controllers/subsystem/mapping.dm b/code/controllers/subsystem/mapping.dm index a8bdad40058..95fac27c47d 100644 --- a/code/controllers/subsystem/mapping.dm +++ b/code/controllers/subsystem/mapping.dm @@ -452,7 +452,7 @@ GLOBAL_LIST_EMPTY(the_station_areas) var/datum/map_template/shuttle/S = new shuttle_type() if(unbuyable.Find(S.mappath)) - S.can_be_bought = FALSE + S.who_can_purchase = null shuttle_templates[S.shuttle_id] = S map_templates[S.shuttle_id] = S diff --git a/code/controllers/subsystem/shuttle.dm b/code/controllers/subsystem/shuttle.dm index 4e7c332afaf..9c3f4d462c4 100644 --- a/code/controllers/subsystem/shuttle.dm +++ b/code/controllers/subsystem/shuttle.dm @@ -59,6 +59,9 @@ SUBSYSTEM_DEF(shuttle) /// A listing of previously delivered supply packs var/list/orderhistory = list() + /// A list of job accesses that are able to purchase any shuttles + var/list/has_purchase_shuttle_access + var/list/hidden_shuttle_turfs = list() //all turfs hidden from navigation computers associated with a list containing the image hiding them and the type of the turf they are pretending to be var/list/hidden_shuttle_turf_images = list() //only the images from the above list @@ -103,6 +106,7 @@ SUBSYSTEM_DEF(shuttle) supply_packs[pack.id] = pack initial_load() + has_purchase_shuttle_access = init_has_purchase_shuttle_access() if(!arrivals) WARNING("No /obj/docking_port/mobile/arrivals placed on the map!") @@ -964,3 +968,13 @@ SUBSYSTEM_DEF(shuttle) var/set_purchase = alert(usr, "Do you want to also disable shuttle purchases/random events that would change the shuttle?", "Butthurt Admin Prevention", "Yes, disable purchases/events", "No, I want to possibly get owned") if(set_purchase == "Yes, disable purchases/events") SSshuttle.shuttle_purchased = SHUTTLEPURCHASE_FORCED + +/datum/controller/subsystem/shuttle/proc/init_has_purchase_shuttle_access() + var/list/has_purchase_shuttle_access = list() + + for (var/shuttle_id in SSmapping.shuttle_templates) + var/datum/map_template/shuttle/shuttle_template = SSmapping.shuttle_templates[shuttle_id] + if (!isnull(shuttle_template.who_can_purchase)) + has_purchase_shuttle_access |= shuttle_template.who_can_purchase + + return has_purchase_shuttle_access diff --git a/code/datums/shuttles.dm b/code/datums/shuttles.dm index 5a9c6586c72..bf825c822bb 100644 --- a/code/datums/shuttles.dm +++ b/code/datums/shuttles.dm @@ -10,8 +10,8 @@ var/admin_notes /// How much does this shuttle cost the cargo budget to purchase? Put in terms of CARGO_CRATE_VALUE to properly scale the cost with the current balance of cargo's income. var/credit_cost = INFINITY - /// Can the be legitimately purchased by the station? Used by hardcoded or pre-mapped shuttles like the lavaland or cargo shuttle. - var/can_be_bought = TRUE + /// What job accesses can buy this shuttle? If null, this shuttle cannot be bought. + var/list/who_can_purchase = list(ACCESS_CAPTAIN) /// If set, overrides default movement_force on shuttle var/list/movement_force @@ -114,7 +114,7 @@ /datum/map_template/shuttle/cargo port_id = "cargo" name = "Base Shuttle Template (Cargo)" - can_be_bought = FALSE + who_can_purchase = null /* //SKYRAT EDIT REMOVAL - MOVED TO MODULAR /datum/map_template/shuttle/ferry @@ -127,58 +127,58 @@ /datum/map_template/shuttle/labour port_id = "labour" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/mining port_id = "mining" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/mining_common port_id = "mining_common" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/arrival port_id = "arrival" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/infiltrator port_id = "infiltrator" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/aux_base port_id = "aux_base" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/escape_pod port_id = "escape_pod" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/assault_pod port_id = "assault_pod" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/pirate port_id = "pirate" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/hunter port_id = "hunter" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/ruin //For random shuttles in ruins port_id = "ruin" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/snowdin port_id = "snowdin" - can_be_bought = FALSE + who_can_purchase = null // Shuttles start here: /datum/map_template/shuttle/emergency/backup suffix = "backup" name = "Backup Shuttle" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/emergency/construction suffix = "construction" @@ -186,6 +186,7 @@ description = "For the enterprising shuttle engineer! The chassis will dock upon purchase, but launch will have to be authorized as usual via shuttle call. Comes stocked with construction materials. Unlocks the ability to buy shuttle engine crates from cargo." admin_notes = "No brig, no medical facilities, no shuttle console." credit_cost = CARGO_CRATE_VALUE * 5 + who_can_purchase = list(ACCESS_CAPTAIN, ACCESS_CE) /datum/map_template/shuttle/emergency/airless/post_load() . = ..() @@ -213,7 +214,7 @@ name = "Emergency Pods" description = "We did not expect an evacuation this quickly. All we have available is two escape pods." admin_notes = "For player punishment." - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/emergency/russiafightpit suffix = "russiafightpit" @@ -237,7 +238,7 @@ admin_notes = "WARNING: This shuttle WILL destroy a fourth of the station, likely picking up a lot of objects with it." credit_cost = CARGO_CRATE_VALUE * 250 movement_force = list("KNOCKDOWN" = 3, "THROW" = 5) - can_be_bought = FALSE //SKYRAT EDIT: Addition + who_can_purchase = null //SKYRAT EDIT CHANGE /datum/map_template/shuttle/emergency/luxury suffix = "luxury" @@ -263,7 +264,7 @@ description = "The glorious results of centuries of plasma research done by Nanotrasen employees. This is the reason why you are here. Get on and dance like you're on fire, burn baby burn!" admin_notes = "Flaming hot. The main area has a dance machine as well as plasma floor tiles that will be ignited by players every single time." credit_cost = CARGO_CRATE_VALUE * 20 - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/emergency/arena suffix = "arena" @@ -405,7 +406,7 @@ description = "How was space work today? Oh, pretty good. We got a new space station and the company will make a lot of money. What space station? I cannot tell you; it's space confidential. \ Aw, come space on. Why not? No, I can't. Anyway, how is your space roleplay life?" admin_notes = "Tiny, with a single airlock and wooden walls. What could go wrong?" - can_be_bought = FALSE + who_can_purchase = null movement_force = list("KNOCKDOWN" = 3, "THROW" = 2) /datum/map_template/shuttle/emergency/goon diff --git a/code/game/machinery/computer/communications.dm b/code/game/machinery/computer/communications.dm index 3433ea23941..e4d965cfddf 100755 --- a/code/game/machinery/computer/communications.dm +++ b/code/game/machinery/computer/communications.dm @@ -197,6 +197,8 @@ var/datum/map_template/shuttle/shuttle = locate(params["shuttle"]) in shuttles if (!istype(shuttle)) return + if (!can_purchase_this_shuttle(shuttle)) + return if (!shuttle.prerequisites_met()) to_chat(usr, "You have not met the requirements for purchasing this shuttle.") return @@ -457,8 +459,23 @@ for (var/shuttle_id in SSmapping.shuttle_templates) var/datum/map_template/shuttle/shuttle_template = SSmapping.shuttle_templates[shuttle_id] - if (!shuttle_template.can_be_bought || shuttle_template.credit_cost == INFINITY) + + if (shuttle_template.credit_cost == INFINITY) continue + + if (!can_purchase_this_shuttle(shuttle_template)) + continue + + var/has_access = FALSE + + for (var/purchase_access in shuttle_template.who_can_purchase) + if (purchase_access in authorize_access) + has_access = TRUE + break + + if (!has_access) + continue + shuttles += list(list( "name" = shuttle_template.name, "description" = shuttle_template.description, @@ -505,8 +522,19 @@ /obj/machinery/computer/communications/proc/can_buy_shuttles(mob/user) if (!SSmapping.config.allow_custom_shuttles) return FALSE - if (!authenticated_as_non_silicon_captain(user)) + if (issilicon(user)) return FALSE + + var/has_access = FALSE + + for (var/access in SSshuttle.has_purchase_shuttle_access) + if (access in authorize_access) + has_access = TRUE + break + + if (!has_access) + return FALSE + if (SSshuttle.emergency.mode != SHUTTLE_RECALL && SSshuttle.emergency.mode != SHUTTLE_IDLE) return "The shuttle is already in transit." if (SSshuttle.shuttle_purchased == SHUTTLEPURCHASE_PURCHASED) @@ -515,6 +543,18 @@ return "Due to unforseen circumstances, shuttle purchasing is no longer available." return TRUE +/// Returns whether we are authorized to buy this specific shuttle. +/// Does not handle prerequisite checks, as those should still *show*. +/obj/machinery/computer/communications/proc/can_purchase_this_shuttle(datum/map_template/shuttle/shuttle_template) + if (isnull(shuttle_template.who_can_purchase)) + return FALSE + + for (var/access in authorize_access) + if (access in shuttle_template.who_can_purchase) + return TRUE + + return FALSE + /obj/machinery/computer/communications/proc/can_send_messages_to_other_sectors(mob/user) if (!authenticated_as_non_silicon_captain(user)) return diff --git a/code/modules/events/shuttle_catastrophe.dm b/code/modules/events/shuttle_catastrophe.dm index 54da54ff865..bd5f67c5628 100644 --- a/code/modules/events/shuttle_catastrophe.dm +++ b/code/modules/events/shuttle_catastrophe.dm @@ -37,7 +37,7 @@ var/list/valid_shuttle_templates = list() for(var/shuttle_id in SSmapping.shuttle_templates) var/datum/map_template/shuttle/template = SSmapping.shuttle_templates[shuttle_id] - if(template.can_be_bought && template.credit_cost < INFINITY) //if we could get it from the communications console, it's cool for us to get it here + if(isnull(template.who_can_purchase) && template.credit_cost < INFINITY) //if we could get it from the communications console, it's cool for us to get it here valid_shuttle_templates += template new_shuttle = pick(valid_shuttle_templates) diff --git a/modular_skyrat/modules/advanced_shuttles/code/shuttles.dm b/modular_skyrat/modules/advanced_shuttles/code/shuttles.dm index beda515eed3..61d4531633e 100644 --- a/modular_skyrat/modules/advanced_shuttles/code/shuttles.dm +++ b/modular_skyrat/modules/advanced_shuttles/code/shuttles.dm @@ -2,7 +2,7 @@ name = "centcom ferry" port_id = "ferry" suffix = "skyrat" - can_be_bought = FALSE + who_can_purchase = null /obj/docking_port/mobile/arrivals_skyrat name = "arrivals interlink shuttle" @@ -44,7 +44,7 @@ prefix = "_maps/skyrat/shuttles/" port_id = "arrivals" suffix = "skyrat" - can_be_bought = FALSE + who_can_purchase = null /datum/map_template/shuttle/escape_pod/default name = "escape pod (Default)" diff --git a/modular_skyrat/modules/assaultops/code/shuttle.dm b/modular_skyrat/modules/assaultops/code/shuttle.dm index 044e448b624..469b901fd2b 100644 --- a/modular_skyrat/modules/assaultops/code/shuttle.dm +++ b/modular_skyrat/modules/assaultops/code/shuttle.dm @@ -42,7 +42,7 @@ prefix = "_maps/skyrat/shuttles/" port_id = "syndicate" suffix = "cruiser" - can_be_bought = FALSE + who_can_purchase = null /////////////FRIGATE /obj/machinery/computer/shuttle/syndicate_frigate @@ -75,4 +75,4 @@ prefix = "_maps/skyrat/shuttles/" port_id = "syndicate" suffix = "frigate" - can_be_bought = FALSE + who_can_purchase = null diff --git a/modular_skyrat/modules/faction/code/mapping/ruins.dm b/modular_skyrat/modules/faction/code/mapping/ruins.dm index 8436445a98c..5764eb292f6 100644 --- a/modular_skyrat/modules/faction/code/mapping/ruins.dm +++ b/modular_skyrat/modules/faction/code/mapping/ruins.dm @@ -1,6 +1,6 @@ /datum/map_template/shuttle/tradership prefix = "modular_skyrat/modules/faction/maps/shuttles/" suffix = "faction" - can_be_bought = FALSE + who_can_purchase = null name = "Faction Trader Ship" port_id = "tradership" diff --git a/modular_skyrat/modules/mapping/code/datums/shuttles.dm b/modular_skyrat/modules/mapping/code/datums/shuttles.dm index ab8c7f986a2..b2d57f25e2b 100644 --- a/modular_skyrat/modules/mapping/code/datums/shuttles.dm +++ b/modular_skyrat/modules/mapping/code/datums/shuttles.dm @@ -1,6 +1,6 @@ /datum/map_template/shuttle/shipstation port_id = "station" - can_be_bought = FALSE + who_can_purchase = null suffix = "ship" name = "NTSS 'Companionship'"