Refactor weather to use Z traits, assorted related cleanup (#34633)

* Add a proc for getting the station center

* Add a couple of comments to ZTRAIT defines

* Remove unused global_map list

* Refactor weather to use the trait system

* Un-hardcode the transit z-level

* Use Z traits to determine Portal Storm event areas

* Fix loading away missions containing anything that reads traits
This commit is contained in:
Tad Hardesty
2018-01-21 11:33:11 -08:00
committed by CitadelStationBot
parent f692ffaa0c
commit 4451aca2e8
26 changed files with 114 additions and 122 deletions

View File

@@ -37,18 +37,13 @@ Last space-z level = empty
//zlevel defines, can be overridden for different maps in the appropriate _maps file.
#define ZLEVEL_STATION_PRIMARY 2
#define ZLEVEL_LAVALAND 5
#define ZLEVEL_EMPTY_SPACE 12
//Unless you modify it in map config should be equal to ZLEVEL_SPACEMAX
#define ZLEVEL_TRANSIT 13
#define ZLEVEL_SPACEMIN 3
#define ZLEVEL_SPACEMAX 13
#define SPACERUIN_MAP_EDGE_PAD 15
#define ZLEVEL_SPACE_RUIN_COUNT 5
// traits
// boolean - marks a level as having that property if present
#define ZTRAIT_CENTCOM "CentCom"
#define ZTRAIT_STATION "Station"
#define ZTRAIT_MINING "Mining"
@@ -57,6 +52,7 @@ Last space-z level = empty
#define ZTRAIT_AWAY "Away Mission"
#define ZTRAIT_SPACE_RUINS "Space Ruins"
#define ZTRAIT_LAVA_RUINS "Lava Ruins"
// number - bombcap is multiplied by this before being applied to bombs
#define ZTRAIT_BOMBCAP_MULTIPLIER "Bombcap Multiplier"
// trait definitions

View File

@@ -1199,19 +1199,6 @@ B --><-- A
sleep(duration)
A.cut_overlay(O)
/proc/get_areas_in_z(zlevel)
. = list()
var/validarea = FALSE
for(var/V in GLOB.sortedAreas)
var/area/A = V
validarea = TRUE
for(var/turf/T in A)
if(T.z != zlevel)
validarea = FALSE
break
if(validarea)
. += A
/proc/get_closest_atom(type, list, source)
var/closest_atom
var/closest_distance

View File

@@ -2,17 +2,6 @@ GLOBAL_LIST_INIT(cardinals, list(NORTH, SOUTH, EAST, WEST))
GLOBAL_LIST_INIT(alldirs, list(NORTH, SOUTH, EAST, WEST, NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST))
GLOBAL_LIST_INIT(diagonals, list(NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST))
GLOBAL_LIST(global_map)
//list/global_map = list(list(1,5),list(4,3))//an array of map Z levels.
//Resulting sector map looks like
//|_1_|_4_|
//|_5_|_3_|
//
//1 - SS13
//4 - Derelict
//3 - AI satellite
//5 - empty space
GLOBAL_LIST_EMPTY(landmarks_list) //list of all landmarks created
GLOBAL_LIST_EMPTY(start_landmarks_list) //list of all spawn points created
GLOBAL_LIST_EMPTY(department_security_spawns) //list of all department security spawns

View File

@@ -24,6 +24,7 @@ SUBSYSTEM_DEF(mapping)
// Z-manager stuff
var/list/z_list
var/datum/space_level/transit
/datum/controller/subsystem/mapping/PreInit()
if(!config)
@@ -47,12 +48,10 @@ SUBSYSTEM_DEF(mapping)
for(var/I in 1 to ZLEVEL_SPACE_RUIN_COUNT)
add_new_zlevel("Empty Area [2 + I]", CROSSLINKED, list(ZTRAIT_SPACE_RUINS = TRUE))
add_new_zlevel("Empty Area [3 + ZLEVEL_SPACE_RUIN_COUNT]", CROSSLINKED, list()) // no ruins
add_new_zlevel("Transit", UNAFFECTED, list(ZTRAIT_TRANSIT = TRUE))
transit = add_new_zlevel("Transit", UNAFFECTED, list(ZTRAIT_TRANSIT = TRUE))
// Pick a random away mission.
createRandomZlevel()
if (z_list.len < world.maxz)
add_new_zlevel("Away Mission", UNAFFECTED, list(ZTRAIT_AWAY = TRUE))
// Generate mining ruins
loading_ruins = TRUE

View File

@@ -84,8 +84,9 @@ SUBSYSTEM_DEF(shuttle)
/datum/controller/subsystem/shuttle/proc/setup_transit_zone()
// transit zone
var/turf/A = get_turf(locate(SHUTTLE_TRANSIT_BORDER,SHUTTLE_TRANSIT_BORDER,ZLEVEL_TRANSIT))
var/turf/B = get_turf(locate(world.maxx - SHUTTLE_TRANSIT_BORDER,world.maxy - SHUTTLE_TRANSIT_BORDER,ZLEVEL_TRANSIT))
var/z = SSmapping.transit.z_value
var/turf/A = get_turf(locate(SHUTTLE_TRANSIT_BORDER,SHUTTLE_TRANSIT_BORDER,z))
var/turf/B = get_turf(locate(world.maxx - SHUTTLE_TRANSIT_BORDER,world.maxy - SHUTTLE_TRANSIT_BORDER,z))
for(var/i in block(A, B))
var/turf/T = i
T.ChangeTurf(/turf/open/space)
@@ -94,8 +95,9 @@ SUBSYSTEM_DEF(shuttle)
#ifdef HIGHLIGHT_DYNAMIC_TRANSIT
/datum/controller/subsystem/shuttle/proc/color_space()
var/turf/A = get_turf(locate(SHUTTLE_TRANSIT_BORDER,SHUTTLE_TRANSIT_BORDER,ZLEVEL_TRANSIT))
var/turf/B = get_turf(locate(world.maxx - SHUTTLE_TRANSIT_BORDER,world.maxy - SHUTTLE_TRANSIT_BORDER,ZLEVEL_TRANSIT))
var/z = SSmapping.transit.z_value
var/turf/A = get_turf(locate(SHUTTLE_TRANSIT_BORDER,SHUTTLE_TRANSIT_BORDER,z))
var/turf/B = get_turf(locate(world.maxx - SHUTTLE_TRANSIT_BORDER,world.maxy - SHUTTLE_TRANSIT_BORDER,z))
for(var/i in block(A, B))
var/turf/T = i
// Only dying the "pure" space, not the transit tiles

View File

@@ -1,3 +1,8 @@
#define STARTUP_STAGE 1
#define MAIN_STAGE 2
#define WIND_DOWN_STAGE 3
#define END_STAGE 4
//Used for all kinds of weather, ex. lavaland ash storms.
SUBSYSTEM_DEF(weather)
name = "Weather"
@@ -5,50 +10,61 @@ SUBSYSTEM_DEF(weather)
wait = 10
runlevels = RUNLEVEL_GAME
var/list/processing = list()
var/list/existing_weather = list()
var/list/eligible_zlevels = list(ZLEVEL_LAVALAND)
var/list/eligible_zlevels = list()
/datum/controller/subsystem/weather/fire()
// process active weather
for(var/V in processing)
var/datum/weather/W = V
if(W.aesthetic)
if(W.aesthetic || W.stage != MAIN_STAGE)
continue
for(var/i in GLOB.mob_living_list)
var/mob/living/L = i
if(W.can_weather_act(L))
W.weather_act(L)
for(var/Z in eligible_zlevels)
var/list/possible_weather_for_this_z = list()
for(var/V in existing_weather)
var/datum/weather/WE = V
if(WE.target_z == Z && WE.probability) //Another check so that it doesn't run extra weather
possible_weather_for_this_z[WE] = WE.probability
var/datum/weather/W = pickweight(possible_weather_for_this_z)
run_weather(W.name, Z)
eligible_zlevels -= Z
addtimer(CALLBACK(src, .proc/make_z_eligible, Z), rand(3000, 6000) + W.weather_duration_upper, TIMER_UNIQUE) //Around 5-10 minutes between weathers
// start random weather on relevant levels
for(var/z in eligible_zlevels)
var/possible_weather = eligible_zlevels[z]
var/datum/weather/W = pickweight(possible_weather)
run_weather(W, list(text2num(z)))
eligible_zlevels -= z
addtimer(CALLBACK(src, .proc/make_eligible, z, possible_weather), rand(3000, 6000) + initial(W.weather_duration_upper), TIMER_UNIQUE) //Around 5-10 minutes between weathers
/datum/controller/subsystem/weather/Initialize(start_timeofday)
..()
for(var/V in subtypesof(/datum/weather))
new V //Weather's New() will handle adding stuff to the list
var/datum/weather/W = V
var/probability = initial(W.probability)
var/target_trait = initial(W.target_trait)
/datum/controller/subsystem/weather/proc/run_weather(weather_name, Z)
if(!weather_name)
// any weather with a probability set may occur at random
if (probability)
for(var/z in SSmapping.levels_by_trait(target_trait))
LAZYINITLIST(eligible_zlevels["[z]"])
eligible_zlevels["[z]"][W] = probability
..()
/datum/controller/subsystem/weather/proc/run_weather(datum/weather/weather_datum_type, z_levels)
if (istext(weather_datum_type))
for (var/V in subtypesof(/datum/weather))
var/datum/weather/W = V
if (initial(W.name) == weather_datum_type)
weather_datum_type = V
break
if (!ispath(weather_datum_type, /datum/weather))
CRASH("run_weather called with invalid weather_datum_type: [weather_datum_type || "null"]")
return
for(var/V in existing_weather)
var/datum/weather/W = V
if(W.name == weather_name && W.target_z == Z)
W.telegraph()
/datum/controller/subsystem/weather/proc/is_weather_affecting_area(area/A, weather_datum_type)
for(var/V in processing)
var/datum/weather/W = V
if(!istype(W, weather_datum_type))
continue
if(A in W.impacted_areas)
return TRUE
return FALSE
if (isnull(z_levels))
z_levels = SSmapping.levels_by_trait(initial(weather_datum_type.target_trait))
else if (isnum(z_levels))
z_levels = list(z_levels)
else if (!islist(z_levels))
CRASH("run_weather called with invalid z_levels: [z_levels || "null"]")
return
/datum/controller/subsystem/weather/proc/make_z_eligible(zlevel)
eligible_zlevels |= zlevel
var/datum/weather/W = new weather_datum_type(z_levels)
W.telegraph()
/datum/controller/subsystem/weather/proc/make_eligible(z, possible_weather)
eligible_zlevels[z] = possible_weather

View File

@@ -1,10 +1,5 @@
//The effects of weather occur across an entire z-level. For instance, lavaland has periodic ash storms that scorch most unprotected creatures.
#define STARTUP_STAGE 1
#define MAIN_STAGE 2
#define WIND_DOWN_STAGE 3
#define END_STAGE 4
/datum/weather
var/name = "space wind"
var/desc = "Heavy gusts of wind blanket the area, periodically knocking down anyone caught in the open."
@@ -30,7 +25,7 @@
var/area_type = /area/space //Types of area to affect
var/list/impacted_areas = list() //Areas to be affected by the weather, calculated when the weather begins
var/list/protected_areas = list()//Areas that are protected and excluded from the affected areas.
var/target_z = ZLEVEL_STATION_PRIMARY //The z-level to affect
var/impacted_z_levels // The list of z-levels that this weather is actively affecting
var/overlay_layer = AREA_LAYER //Since it's above everything else, this is the layer used by default. TURF_LAYER is below mobs and walls if you need to use that.
var/aesthetic = FALSE //If the weather has no purpose other than looks
@@ -38,15 +33,13 @@
var/stage = END_STAGE //The stage of the weather, from 1-4
var/probability = FALSE //Percent chance to happen if there are other possible weathers on the z-level
// These are read by the weather subsystem and used to determine when and where to run the weather.
var/probability = 0 // Weight amongst other eligible weather. If zero, will never happen randomly.
var/target_trait = ZTRAIT_STATION // The z-level trait to affect when run randomly or when not overridden.
/datum/weather/New()
..()
SSweather.existing_weather += src
/datum/weather/Destroy()
SSweather.existing_weather -= src
/datum/weather/New(z_levels)
..()
impacted_z_levels = z_levels
/datum/weather/proc/telegraph()
if(stage == STARTUP_STAGE)
@@ -59,13 +52,14 @@
affectareas -= get_areas(V)
for(var/V in affectareas)
var/area/A = V
if(A.z == target_z)
if(A.z in impacted_z_levels)
impacted_areas |= A
weather_duration = rand(weather_duration_lower, weather_duration_upper)
START_PROCESSING(SSweather, src)
update_areas()
for(var/V in GLOB.player_list)
var/mob/M = V
if(M.z == target_z)
for(var/M in GLOB.player_list)
var/turf/mob_turf = get_turf(M)
if(mob_turf && (mob_turf.z in impacted_z_levels))
if(telegraph_message)
to_chat(M, telegraph_message)
if(telegraph_sound)
@@ -77,14 +71,13 @@
return
stage = MAIN_STAGE
update_areas()
for(var/V in GLOB.player_list)
var/mob/M = V
if(M.z == target_z)
for(var/M in GLOB.player_list)
var/turf/mob_turf = get_turf(M)
if(mob_turf && (mob_turf.z in impacted_z_levels))
if(weather_message)
to_chat(M, weather_message)
if(weather_sound)
SEND_SOUND(M, sound(weather_sound))
START_PROCESSING(SSweather, src)
addtimer(CALLBACK(src, .proc/wind_down), weather_duration)
/datum/weather/proc/wind_down()
@@ -92,25 +85,25 @@
return
stage = WIND_DOWN_STAGE
update_areas()
for(var/V in GLOB.player_list)
var/mob/M = V
if(M.z == target_z)
for(var/M in GLOB.player_list)
var/turf/mob_turf = get_turf(M)
if(mob_turf && (mob_turf.z in impacted_z_levels))
if(end_message)
to_chat(M, end_message)
if(end_sound)
SEND_SOUND(M, sound(end_sound))
STOP_PROCESSING(SSweather, src)
addtimer(CALLBACK(src, .proc/end), end_duration)
/datum/weather/proc/end()
if(stage == END_STAGE)
return 1
stage = END_STAGE
STOP_PROCESSING(SSweather, src)
update_areas()
/datum/weather/proc/can_weather_act(mob/living/L) //Can this weather impact a mob?
var/turf/mob_turf = get_turf(L)
if(mob_turf && (mob_turf.z != target_z))
if(mob_turf && !(mob_turf.z in impacted_z_levels))
return
if(immunity_type in L.weather_immunities)
return

View File

@@ -18,7 +18,7 @@
end_sound = 'sound/ambience/acidrain_end.ogg'
area_type = /area/lavaland/surface/outdoors
target_z = ZLEVEL_LAVALAND
target_trait = ZTRAIT_MINING
immunity_type = "acid" // temp

View File

@@ -14,7 +14,7 @@
end_duration = 0
area_type = /area
target_z = ZLEVEL_STATION_PRIMARY
target_trait = ZTRAIT_STATION
/datum/weather/advanced_darkness/update_areas()
for(var/V in impacted_areas)

View File

@@ -17,7 +17,7 @@
end_overlay = "light_ash"
area_type = /area/lavaland/surface/outdoors
target_z = ZLEVEL_LAVALAND
target_trait = ZTRAIT_MINING
immunity_type = "ash"
@@ -32,7 +32,9 @@
. = ..()
var/list/inside_areas = list()
var/list/outside_areas = list()
var/list/eligible_areas = SSmapping.areas_in_z["[target_z]"]
var/list/eligible_areas = list()
for (var/z in impacted_z_levels)
eligible_areas += SSmapping.areas_in_z["[z]"]
for(var/i in 1 to eligible_areas.len)
var/area/place = eligible_areas[i]
if(place.outdoors)

View File

@@ -16,14 +16,14 @@
area_type = /area
protected_areas = list(/area/space)
target_z = ZLEVEL_STATION_PRIMARY
target_trait = ZTRAIT_STATION
overlay_layer = ABOVE_OPEN_TURF_LAYER //Covers floors only
immunity_type = "lava"
/datum/weather/floor_is_lava/weather_act(mob/living/L)
for(var/obj/structure/O in L.loc)
for(var/obj/structure/O in L.loc)
if(O.density || (L in O.buckled_mobs && istype(O, /obj/structure/bed)))
return
if(L.loc.density)

View File

@@ -19,7 +19,7 @@
area_type = /area
protected_areas = list(/area/maintenance, /area/ai_monitored/turret_protected/ai_upload, /area/ai_monitored/turret_protected/ai_upload_foyer,
/area/ai_monitored/turret_protected/ai, /area/storage/emergency/starboard, /area/storage/emergency/port, /area/shuttle)
target_z = ZLEVEL_STATION_PRIMARY
target_trait = ZTRAIT_STATION
immunity_type = "rad"

View File

@@ -384,9 +384,9 @@ GLOBAL_LIST_EMPTY(teleportlocs)
icon_state = "blue-red"
else
var/weather_icon
for(var/V in SSweather.existing_weather)
for(var/V in SSweather.processing)
var/datum/weather/W = V
if(src in W.impacted_areas)
if(W.stage != END_STAGE && (src in W.impacted_areas))
W.update_areas()
weather_icon = TRUE
if(!weather_icon)

View File

@@ -657,7 +657,7 @@
flags_2 |= STATIONLOVING_2
/atom/movable/proc/relocate()
var/targetturf = find_safe_turf(ZLEVEL_STATION_PRIMARY)
var/targetturf = find_safe_turf()
if(!targetturf)
if(GLOB.blobstart.len > 0)
targetturf = get_turf(pick(GLOB.blobstart))

View File

@@ -330,7 +330,7 @@
QDEL_IN(src, 3)
sleep(3)
GLOB.clockwork_gateway_activated = TRUE
var/turf/T = locate(round(world.maxx * 0.5, 1), round(world.maxy * 0.5, 1), ZLEVEL_STATION_PRIMARY) //approximate center of the station
var/turf/T = SSmapping.get_station_center()
new /obj/structure/destructible/clockwork/massive/ratvar(T)
SSticker.force_ending = TRUE
var/x0 = T.x

View File

@@ -422,7 +422,7 @@
L.fix()
if("floorlava")
SSweather.run_weather("the floor is lava")
SSweather.run_weather(/datum/weather/floor_is_lava)
if("virus")
if(!check_rights(R_FUN))

View File

@@ -8,7 +8,7 @@ GLOBAL_LIST_INIT(potentialRandomZlevels, generateMapList(filename = "config/away
if(GLOB.potentialRandomZlevels && GLOB.potentialRandomZlevels.len)
to_chat(world, "<span class='boldannounce'>Loading away mission...</span>")
var/map = pick(GLOB.potentialRandomZlevels)
load_new_z_level(map)
load_new_z_level(map, "Away Mission")
to_chat(world, "<span class='boldannounce'>Away mission loaded.</span>")
/proc/reset_gateway_spawns(reset = FALSE)

View File

@@ -33,14 +33,16 @@
var/list/hostiles_spawn = list()
var/list/hostile_types = list()
var/number_of_hostiles
var/list/station_areas = list()
var/list/station_areas
var/mutable_appearance/storm
/datum/round_event/portal_storm/setup()
storm = mutable_appearance('icons/obj/tesla_engine/energy_ball.dmi', "energy_ball_fast", FLY_LAYER)
storm.color = "#00FF00"
station_areas = get_areas_in_z(ZLEVEL_STATION_PRIMARY)
station_areas = list()
for (var/z in SSmapping.levels_by_trait(ZTRAIT_STATION))
station_areas |= SSmapping.areas_in_z["[z]"]
number_of_bosses = 0
for(var/boss in boss_types)

View File

@@ -16,4 +16,4 @@
//sound not longer matches the text, but an audible warning is probably good
/datum/round_event/radiation_storm/start()
SSweather.run_weather("radiation storm",ZLEVEL_STATION_PRIMARY)
SSweather.run_weather(/datum/weather/rad_storm)

View File

@@ -13,4 +13,4 @@
/datum/round_event/wizard/darkness/start()
if(!started)
started = TRUE
SSweather.run_weather("advanced darkness", ZLEVEL_STATION_PRIMARY)
SSweather.run_weather(/datum/weather/advanced_darkness)

View File

@@ -12,4 +12,4 @@
/datum/round_event/wizard/lava/start()
if(!started)
started = TRUE
SSweather.run_weather("the floor is lava", ZLEVEL_STATION_PRIMARY)
SSweather.run_weather(/datum/weather/floor_is_lava)

View File

@@ -52,7 +52,8 @@
var/x = round((world.maxx - width)/2)
var/y = round((world.maxy - height)/2)
var/list/bounds = maploader.load_map(file(mappath), x, y)
var/datum/space_level/level = SSmapping.add_new_zlevel(name, UNAFFECTED, list(ZTRAIT_AWAY = TRUE))
var/list/bounds = maploader.load_map(file(mappath), x, y, level.z_value, no_changeturf=(SSatoms.initialized == INITIALIZATION_INSSATOMS))
if(!bounds)
return FALSE

View File

@@ -44,3 +44,8 @@
if (S.traits[trait])
. += S.z_value
break
// Prefer not to use this one too often
/datum/controller/subsystem/mapping/proc/get_station_center()
var/station_z = levels_by_trait(ZTRAIT_STATION)[1]
return locate(round(world.maxx * 0.5, 1), round(world.maxy * 0.5, 1), station_z)

View File

@@ -24,7 +24,7 @@
// TODO: sleep here if the Z level needs to be cleared
var/datum/space_level/S = new z_type(new_z, name, linkage, traits)
z_list += S
return new_z
return S
/datum/controller/subsystem/mapping/proc/get_level(z)
. = z_list[z]

View File

@@ -107,7 +107,7 @@ GLOBAL_VAR_INIT(observer_default_invisibility, INVISIBILITY_OBSERVER)
if(turfs.len)
T = pick(turfs)
else
T = locate(round(world.maxx/2), round(world.maxy/2), ZLEVEL_STATION_PRIMARY) //middle of the station
T = SSmapping.get_station_center()
forceMove(T)

View File

@@ -170,17 +170,18 @@ Difficulty: Medium
return
var/area/user_area = get_area(user)
if(user_area.type in excluded_areas)
var/turf/user_turf = get_turf(user)
if(!user_area || !user_turf || (user_area.type in excluded_areas))
to_chat(user, "<span class='warning'>Something is preventing you from using the staff here.</span>")
return
var/datum/weather/A
for(var/V in SSweather.existing_weather)
for(var/V in SSweather.processing)
var/datum/weather/W = V
if(W.target_z == user.z && W.area_type == user_area.type)
if((user_turf.z in W.impacted_z_levels) && W.area_type == user_area.type)
A = W
break
if(A)
if(A)
if(A.stage != END_STAGE)
if(A.stage == WIND_DOWN_STAGE)
to_chat(user, "<span class='warning'>The storm is already ending! It would be a waste to use the staff now.</span>")
@@ -191,10 +192,9 @@ Difficulty: Medium
A.wind_down()
return
else
A = new storm_type
A = new storm_type(list(user_turf.z))
A.name = "staff storm"
A.area_type = user_area.type
A.target_z = user.z
A.telegraph_duration = 100
A.end_duration = 100