Skip to content

Commit

Permalink
Reduce cost of xenoarch jungle generation significantly
Browse files Browse the repository at this point in the history
  • Loading branch information
liz-lavenza committed Mar 31, 2024
1 parent 6dd2fad commit 7951956
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
38 changes: 20 additions & 18 deletions code/game/turfs/simulated/river.dm
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,35 @@
/turf/proc/Spread(probability = 30, prob_loss = 25, whitelisted_area)
if(probability <= 0)
return
var/list/cardinal_turfs = list()
var/list/diagonal_turfs = list()
var/logged_turf_type
for(var/turf/T in orange(1, src))
var/area/new_area = get_area(T)
if(!T || (T.density && !ismineralturf(T)) || istype(T, /turf/open/indestructible) || (whitelisted_area && !istype(new_area, whitelisted_area)) || (T.flags_1 & NO_LAVA_GEN_1) )
if((T.density && !ismineralturf(T)) || istype(T, /turf/open/indestructible) || (whitelisted_area && !istype(new_area, whitelisted_area)) || (T.flags_1 & NO_LAVA_GEN_1) )
continue

if(!logged_turf_type && ismineralturf(T))
var/turf/closed/mineral/M = T
logged_turf_type = M.turf_type

if(get_dir(src, T) in GLOB.cardinals)
cardinal_turfs += T
else
diagonal_turfs += T

for(var/turf/T as anything in cardinal_turfs) //cardinal turfs are always changed but don't always spread
if(!istype(T, logged_turf_type) && T.ChangeTurf(type, baseturfs, CHANGETURF_IGNORE_AIR) && prob(probability))
T.Spread(probability - prob_loss, prob_loss, whitelisted_area)

for(var/turf/T as anything in diagonal_turfs) //diagonal turfs only sometimes change, but will always spread if changed
if(!istype(T, logged_turf_type) && prob(probability) && T.ChangeTurf(type, baseturfs, CHANGETURF_IGNORE_AIR))
T.Spread(probability - prob_loss, prob_loss, whitelisted_area)
else if(ismineralturf(T))
var/turf/closed/mineral/M = T
M.ChangeTurf(M.turf_type, M.baseturfs, CHANGETURF_IGNORE_AIR)
for(var/turf/T in orange(1, src))
var/area/new_area = get_area(T)
if((T.density && !ismineralturf(T)) || istype(T, /turf/open/indestructible) || (whitelisted_area && !istype(new_area, whitelisted_area)) || (T.flags_1 & NO_LAVA_GEN_1) )
continue
var/opponent_dir = get_dir(src, T) // Use some clever bitmath to check if the direction is diagonal.
if(opponent_dir & (opponent_dir - 1)) //diagonal turfs only sometimes change, but will always spread if changed
// NOTE: WE ARE SKIPPING CHANGETURF HERE
// The calls in this proc only serve to provide a satisfactory (if it's not ALREADY this) check. They do not actually call changeturf
// This is safe because this proc can only be run during mapload, and nothing has initialized by now so there's nothing to inherit or delete
if(!istype(T, logged_turf_type) && !istype(T, type) && prob(probability) && T.ChangeTurf(type, baseturfs, CHANGETURF_SKIP))
T.Spread(probability - prob_loss, prob_loss, whitelisted_area)
else if(ismineralturf(T))
var/turf/closed/mineral/M = T
// SEE ABOVE, THIS IS ONLY VERY RARELY SAFE
M.ChangeTurf(M.turf_type, M.baseturfs, CHANGETURF_SKIP)
else //cardinal turfs are always changed but don't always spread
// Important NOTE: SEE ABOVE
if(!istype(T, logged_turf_type) && !istype(T, type) && T.ChangeTurf(type, baseturfs, CHANGETURF_SKIP) && prob(probability))
T.Spread(probability - prob_loss, prob_loss, whitelisted_area)


#undef RANDOM_UPPER_X
Expand Down
14 changes: 7 additions & 7 deletions modular_splurt/code/modules/mapping/lavaland_jungle_gen.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
continue
W.connected = 1
var/turf/cur_turf = get_turf(W)
cur_turf.ChangeTurf(turf_type, new_baseturfs, CHANGETURF_IGNORE_AIR)
cur_turf.ChangeTurf(turf_type, new_baseturfs, CHANGETURF_SKIP) // HEY! Don't use CHANGETURF_SKIP unless you're SURE it can only ever run prior to turf init!
var/turf/target_turf = get_turf(pick(river_nodes - W))
if(!target_turf)
break
Expand Down Expand Up @@ -56,7 +56,7 @@
cur_turf = get_step(cur_turf, cur_dir)
continue
else
var/turf/river_turf = cur_turf.ChangeTurf(turf_type, new_baseturfs, CHANGETURF_IGNORE_AIR)
var/turf/river_turf = cur_turf.ChangeTurf(turf_type, new_baseturfs, CHANGETURF_SKIP) // HEY! Don't use CHANGETURF_SKIP unless you're SURE it can only ever run prior to turf init!
river_turf.Spread(30, 11, whitelist_area)

for(var/WP in river_nodes)
Expand Down Expand Up @@ -111,7 +111,7 @@
if(Trange <= radius + 0.5)
var/circ_area = get_area(T)
if(istype(circ_area, whitelist_area))
T.ChangeTurf(turf_type, new_baseturfs, CHANGETURF_IGNORE_AIR)
T.ChangeTurf(turf_type, new_baseturfs, CHANGETURF_SKIP) // HEY! Don't use CHANGETURF_SKIP unless you're SURE it can only ever run prior to turf init!
affected |= T
if(Trange > radius - 1)
T.Spread(21, 11, whitelist_area)
Expand All @@ -126,21 +126,21 @@
dir_turf = get_step(dir_turf, dir)
var/dir_area = get_area(dir_turf)
if(istype(dir_area, whitelist_area))
dir_turf = dir_turf.ChangeTurf(turf_type, new_baseturfs, CHANGETURF_IGNORE_AIR)
dir_turf = dir_turf.ChangeTurf(turf_type, new_baseturfs, CHANGETURF_SKIP) // HEY! Don't use CHANGETURF_SKIP unless you're SURE it can only ever run prior to turf init!
affected |= dir_turf
if(i == radius)
dir_turf.Spread(21, 11, whitelist_area)
//Fixes to diagional checker board
if(dir in GLOB.diagonals)
if(dir & (dir-1))
var/turf/diag_turf = locate(dir_turf.x,(dir_turf.y-1),target_z)
var/diag_area = get_area(diag_turf)
if(istype(diag_area, whitelist_area))
diag_turf = diag_turf.ChangeTurf(turf_type, new_baseturfs, CHANGETURF_IGNORE_AIR)
diag_turf = diag_turf.ChangeTurf(turf_type, new_baseturfs, CHANGETURF_SKIP) // HEY! Don't use CHANGETURF_SKIP unless you're SURE it can only ever run prior to turf init!
affected |= diag_turf

var/area/new_area = get_area(cur_turf)
if(istype(new_area, whitelist_area))
cur_turf.ChangeTurf(turf_type, new_baseturfs, CHANGETURF_IGNORE_AIR)
cur_turf.ChangeTurf(turf_type, new_baseturfs, CHANGETURF_SKIP) // HEY! Don't use CHANGETURF_SKIP unless you're SURE it can only ever run prior to turf init!
affected |= cur_turf
else
detouring = 0
Expand Down

0 comments on commit 7951956

Please sign in to comment.