From 0269577387e4364f292b8a59f3439048edd000a8 Mon Sep 17 00:00:00 2001 From: EvilDragonfiend <87972842+EvilDragonfiend@users.noreply.github.com> Date: Thu, 28 Dec 2023 17:56:37 +0900 Subject: [PATCH] Fixes is_station_level(z) macro throwing out of index runtime when it's given 0z, and minor fix to explo artefact (#10376) * No runtime for z * maybe we want this with ## to make sure * removes ## * Better logic * better logic * funny typo... * Final logic --- code/__HELPERS/level_traits.dm | 8 +++---- .../objective_types/alien_artifact.dm | 23 +++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/code/__HELPERS/level_traits.dm b/code/__HELPERS/level_traits.dm index b4730fc05b648..aa35b4871c796 100644 --- a/code/__HELPERS/level_traits.dm +++ b/code/__HELPERS/level_traits.dm @@ -10,15 +10,15 @@ GLOBAL_VAR(station_level_z_scratch) // Called a lot, somewhat slow, so has its own cache #define is_station_level(z) \ - ( \ + ( !z ? 0 : ( \ ( \ /* The right hand side of this guarantees that we'll have the space to fill later on, while also not failing the condition */ \ (GLOB.station_levels_cache.len < (GLOB.station_level_z_scratch = z) && (GLOB.station_levels_cache.len = GLOB.station_level_z_scratch)) \ || isnull(GLOB.station_levels_cache[GLOB.station_level_z_scratch]) \ ) \ - ? (GLOB.station_levels_cache[GLOB.station_level_z_scratch] = !!SSmapping.level_trait(z, ZTRAIT_STATION)) \ - : GLOB.station_levels_cache[GLOB.station_level_z_scratch] \ - ) + ? (GLOB.station_levels_cache[GLOB.station_level_z_scratch] = !!SSmapping.level_trait(z, ZTRAIT_STATION)) \ + : GLOB.station_levels_cache[GLOB.station_level_z_scratch] \ + ) ) #define is_mining_level(z) SSmapping.level_trait(z, ZTRAIT_MINING) diff --git a/code/modules/shuttle/super_cruise/orbital_poi_generator/objective_types/alien_artifact.dm b/code/modules/shuttle/super_cruise/orbital_poi_generator/objective_types/alien_artifact.dm index 11a1e84507f29..b70ecf6e0f1d1 100644 --- a/code/modules/shuttle/super_cruise/orbital_poi_generator/objective_types/alien_artifact.dm +++ b/code/modules/shuttle/super_cruise/orbital_poi_generator/objective_types/alien_artifact.dm @@ -1,14 +1,13 @@ /datum/orbital_objective/artifact name = "Artifact Recovery" - var/generated = FALSE - //The blackbox required to recover. - var/obj/item/xenoartifact/objective/linked_artifact + var/datum/weakref/weakref_artifact min_payout = 5000 max_payout = 25000 /datum/orbital_objective/artifact/generate_objective_stuff(turf/chosen_turf) - generated = TRUE - linked_artifact = new(chosen_turf) + var/obj/item/xenoartifact/objective/linked_artifact = new(chosen_turf) + weakref_artifact = WEAKREF(linked_artifact) + var/list/turfs = RANGE_TURFS(30, linked_artifact) var/list/valid_turfs = list() for(var/turf/open/floor/F in turfs) @@ -31,11 +30,15 @@ . += " The station is located at the beacon marked [linked_beacon.name]. Good luck." /datum/orbital_objective/artifact/check_failed() - if(!generated) + if(!weakref_artifact) // It looks fail-check is executed before we fully initialise the explo mission. return FALSE - if(is_station_level(linked_artifact.z)) - complete_objective() + var/obj/item/xenoartifact/objective/linked_artifact = weakref_artifact.resolve() + if(QDELETED(linked_artifact)) // failed to resolve or qdeleted means it never success + return TRUE + if(!(linked_artifact?.flags_1 & INITIALIZED_1)) // We checked this too early. return FALSE - if(!QDELETED(linked_artifact)) + if(!is_station_level(linked_artifact.z)) // It's not a real failure. Let's wait... return FALSE - return TRUE + + complete_objective() + return FALSE