Skip to content

Commit

Permalink
Fixes is_station_level(z) macro throwing out of index runtime when it…
Browse files Browse the repository at this point in the history
…'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
  • Loading branch information
EvilDragonfiend authored Dec 28, 2023
1 parent f5440d4 commit 0269577
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions code/__HELPERS/level_traits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

0 comments on commit 0269577

Please sign in to comment.