Skip to content

Commit

Permalink
Improve mining magnet's clearing with terrainify
Browse files Browse the repository at this point in the history
Resolve issue with mining magnet generating impassible turfs with terrainify
Add flag for map generators to force a floor/interactible turf
  • Loading branch information
Azrun committed Jun 6, 2024
1 parent f88263f commit 1f5cb06
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 17 deletions.
2 changes: 1 addition & 1 deletion +secret
1 change: 1 addition & 0 deletions _std/map.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define MAPGEN_IGNORE_FAUNA (1 << 1)
#define MAPGEN_IGNORE_BUILDABLE (1 << 2)
#define MAPGEN_ALLOW_VEHICLES (1 << 3)
#define MAPGEN_FLOOR_ONLY (1 << 4)

#define MAPGEN_TURF_ONLY ( MAPGEN_IGNORE_FLORA | MAPGEN_IGNORE_FAUNA )

Expand Down
23 changes: 15 additions & 8 deletions code/modules/admin/terrainify.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ var/datum/station_zlevel_repair/station_repair = new
default_air.nitrogen = MOLES_N2STANDARD
default_air.temperature = T20C

proc/repair_turfs(turf/turfs, clear=FALSE)
proc/repair_turfs(turf/turfs, clear=FALSE, force_floor=FALSE)
if(src.station_generator)
var/gen_flags = MAPGEN_IGNORE_FLORA|MAPGEN_IGNORE_FAUNA
var/gen_flags = MAPGEN_IGNORE_FLORA | MAPGEN_IGNORE_FAUNA
gen_flags |= MAPGEN_ALLOW_VEHICLES * src.allows_vehicles
gen_flags |= MAPGEN_FLOOR_ONLY * force_floor
src.station_generator.generate_terrain(turfs, reuse_seed=TRUE, flags=gen_flags)

if(clear)
Expand Down Expand Up @@ -287,7 +288,7 @@ ABSTRACT_TYPE(/datum/terrainify)
for(var/turf/T in space_turfs)
if(!istype(T, /turf/space))
space_turfs -= T
station_repair.repair_turfs(space_turfs)
station_repair.repair_turfs(space_turfs, force_floor=TRUE)

logTheThing(LOG_DEBUG, null, "Prefab Z1 placement #[n] [P.type][P.required?" (REQUIRED)":""] succeeded. [target] @ [log_loc(target)]")
n++
Expand Down Expand Up @@ -680,12 +681,18 @@ ABSTRACT_TYPE(/datum/terrainify)
if(station_repair.allows_vehicles)
T.allows_vehicles = station_repair.allows_vehicles
T.UpdateOverlays(station_repair.weather_img, "weather")
ambient_value = lerp(20,80,T.x/300)
station_repair.ambient_light.color = rgb(ambient_value+((rand()*3)),ambient_value,ambient_value) //randomly shift red to reduce vertical banding
T.AddOverlays(station_repair.ambient_light, "ambient")

ambient_value = lerp(20,80,0.5)
station_repair.ambient_light.color = rgb(ambient_value+((rand()*3)),ambient_value,ambient_value)
if(params["Ambient Light Obj"])
T.vis_contents |= station_repair.ambient_obj
else
ambient_value = lerp(20,80,T.x/300)
station_repair.ambient_light.color = rgb(ambient_value+((rand()*3)),ambient_value,ambient_value) //randomly shift red to reduce vertical banding
T.AddOverlays(station_repair.ambient_light, "ambient")

if(station_repair.ambient_light)
ambient_value = lerp(20,80,0.5)
station_repair.ambient_light.color = rgb(ambient_value+((rand()*3)),ambient_value,ambient_value)

handle_mining(params, space)

log_terrainify(user, "turned space into Mars.")
Expand Down
3 changes: 3 additions & 0 deletions code/modules/atmospherics/FEA_gas_mixture.dm
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ What are the archived variables for?
/// * Similar to [/datum/gas_mixture/proc/share], except the model is not modified.
/// * Return: Moles of gas exchanged.
/datum/gas_mixture/proc/mimic(turf/model, border_multiplier = 1)
if (!model)
return FALSE

#define _DELTA_GAS(GAS, ...) var/delta_##GAS = QUANTIZE(((src.ARCHIVED(GAS) - model.GAS)/5)*border_multiplier/src.group_multiplier);
APPLY_TO_GASES(_DELTA_GAS)
#undef _DELTA_GAS
Expand Down
2 changes: 1 addition & 1 deletion code/modules/events/minor/trader.dm
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
start_location.color = OCEAN_COLOR
#endif

station_repair.repair_turfs(dest_turfs)
station_repair.repair_turfs(dest_turfs, force_floor=TRUE)

/proc/get_hiding_jerk(var/atom/movable/container)
for(var/atom/movable/AM in container)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/transport/shuttle/shuttle_controller.dm
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ var/global/datum/shuttle_controller/emergency_shuttle/emergency_shuttle
if(station_repair.station_generator)
var/list/turf/turfs_to_fix = get_area_turfs(start_location)
if(length(turfs_to_fix))
station_repair.repair_turfs(turfs_to_fix)
station_repair.repair_turfs(turfs_to_fix, force_floor=TRUE)

DEBUG_MESSAGE("Done moving shuttle!")
settimeleft(SHUTTLETRANSITTIME)
Expand Down
4 changes: 3 additions & 1 deletion code/modules/worldgen/mapgen/IceMoonGenerator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
var/height = text2num(rustg_noise_get_at_coordinates("[height_seed]", "[drift_x]", "[drift_y]"))

var/datum/biome/selected_biome
if(height <= 0.85) //If height is less than 0.85, we generate biomes based on the heat and humidity of the area.
if(flags & MAPGEN_FLOOR_ONLY)
selected_biome = /datum/biome/icemoon/snow
else if(height <= 0.85) //If height is less than 0.85, we generate biomes based on the heat and humidity of the area.
var/humidity = text2num(rustg_noise_get_at_coordinates("[humidity_seed]", "[drift_x]", "[drift_y]"))
var/heat = text2num(rustg_noise_get_at_coordinates("[heat_seed]", "[drift_x]", "[drift_y]"))
var/heat_level //Type of heat zone we're in LOW-MEDIUM-HIGH
Expand Down
2 changes: 2 additions & 0 deletions code/modules/worldgen/mapgen/LavaMoonGenerator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@
var/datum/biome/selected_biome
if(length(near_station?.get_nearby(gen_turf, range=6)))
selected_biome = /datum/biome/lavamoon
else if(flags & MAPGEN_FLOOR_ONLY)
selected_biome = /datum/biome/lavamoon
else if(lava_value)
selected_biome = /datum/biome/lavamoon/lava
else if(height <= 0.85) //If height is less than 0.85, we generate biomes based on the heat and humidity of the area.
Expand Down
7 changes: 6 additions & 1 deletion code/modules/worldgen/mapgen/MarsGenerator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
)
///Used to select "zoom" level into the perlin noise, higher numbers result in slower transitions
var/perlin_zoom = 65
var/floor_only_biome = /datum/biome/mars
wall_turf_type = /turf/simulated/wall/auto/asteroid/mars
floor_turf_type = /turf/unsimulated/floor/plating/asteroid/mars

Expand Down Expand Up @@ -87,6 +88,8 @@
BIOME_HIGH_HUMIDITY = /datum/biome/mars/martian_area/duststorm
)
)
floor_only_biome = /datum/biome/mars/duststorm
floor_turf_type = /turf/unsimulated/floor/setpieces/martian/station_duststorm

///Seeds the rust-g perlin noise with a random number.
/datum/map_generator/mars_generator/generate_terrain(list/turfs, reuse_seed, flags)
Expand All @@ -103,7 +106,9 @@
var/height = text2num(rustg_noise_get_at_coordinates("[height_seed]", "[drift_x]", "[drift_y]"))

var/datum/biome/selected_biome
if(height <= 0.85) //If height is less than 0.85, we generate biomes based on the heat and humidity of the area.
if(flags & MAPGEN_FLOOR_ONLY)
selected_biome = floor_only_biome
else if(height <= 0.85) //If height is less than 0.85, we generate biomes based on the heat and humidity of the area.
var/humidity = text2num(rustg_noise_get_at_coordinates("[humidity_seed]", "[drift_x]", "[drift_y]"))
var/heat = text2num(rustg_noise_get_at_coordinates("[heat_seed]", "[drift_x]", "[drift_y]"))
var/heat_level //Type of heat zone we're in LOW-MEDIUM-HIGH
Expand Down
4 changes: 4 additions & 0 deletions code/modules/worldgen/mapgen/RoomMaze.dm
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,13 @@
/datum/map_generator/room_maze_generator/proc/assign_turf(turf/T, flags)
var/cell_value = src.cell_grid[T.x][T.y]

if(flags & MAPGEN_FLOOR_ONLY)
cell_value = FLOOR

switch(cell_value)
if(WALL, null)
T.ReplaceWith(wall_turf_type, handle_air=FALSE)

if(FLOOR)
T.ReplaceWith(floor_turf_type, handle_air=FALSE)

Expand Down
6 changes: 5 additions & 1 deletion code/modules/worldgen/mapgen/StorehouseGenerator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@

var/generate_stuff = !(flags & (MAPGEN_IGNORE_FLORA|MAPGEN_IGNORE_FAUNA))

if(flags & MAPGEN_FLOOR_ONLY)
cell_value = FLOOR_ONLY

switch(cell_value)
if(FLOOR)
T.ReplaceWith(floor_path)
Expand Down Expand Up @@ -324,9 +327,10 @@
meaty = text2num(meatier[T.x * world.maxx + T.y])
if(index <= length(stomach))
stomach_goop = text2num(stomach[T.x * world.maxx + T.y])
if(flags & MAPGEN_FLOOR_ONLY)
cell_value = FLOOR_ONLY

var/datum/biome/selected_biome

switch(cell_value)
if(FLOOR)
if(meaty && stomach_goop)
Expand Down
2 changes: 1 addition & 1 deletion code/obj/machinery/computer/shuttle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ ABSTRACT_TYPE(/obj/machinery/computer/transit_shuttle)
if (currentlocation.z == Z_LEVEL_STATION && station_repair.station_generator)
var/list/turf/turfs_to_fix = get_area_turfs(currentlocation)
if(length(turfs_to_fix))
station_repair.repair_turfs(turfs_to_fix)
station_repair.repair_turfs(turfs_to_fix, force_floor=TRUE)

for(var/obj/machinery/computer/transit_shuttle/Console in machine_registry[MACHINES_SHUTTLECOMPS])
if (Console.shuttlename != src.shuttlename) continue
Expand Down
8 changes: 6 additions & 2 deletions code/obj/mining.dm
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,16 @@
var/sleep_time = attract_time
if (sleep_time < 1)
sleep_time = 20
sleep_time /= 2
sleep_time /= 3

if (malfunctioning && prob(20))
do_malfunction()
sleep(sleep_time)

// Ensure area is erased, helps if atmos is being a jerk
target.erase_area()
sleep(sleep_time)

var/datum/mining_encounter/MC

if(selectable_encounter_id != null)
Expand Down Expand Up @@ -662,7 +666,7 @@
var/turf/origin = get_turf(target)
for (var/turf/space/T in block(origin, locate(origin.x + target.width - 1, origin.y + target.height - 1, origin.z)))
repair_turfs += T
station_repair.repair_turfs(repair_turfs)
station_repair.repair_turfs(repair_turfs, force_floor=TRUE)

sleep(sleep_time)
if (malfunctioning && prob(20))
Expand Down
3 changes: 3 additions & 0 deletions code/turf/turf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ proc/generate_space_color()
return

/turf/proc/delay_space_conversion()
return

/turf/simulated/delay_space_conversion()
if(air_master?.is_busy)
air_master.tiles_to_space |= src
return TRUE
Expand Down

0 comments on commit 1f5cb06

Please sign in to comment.