From 1de5df28bb9e600fb2fd4e183f810d3e605d25be Mon Sep 17 00:00:00 2001 From: warriorstar-orion Date: Fri, 30 Aug 2024 09:27:54 -0400 Subject: [PATCH] Fix runtimes in Lavaland river procgen. (#26606) * Fix runtimes in Lavaland river procgen. * fucking what, sanity check * add back attempt bailout --- code/game/turfs/simulated/river.dm | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/code/game/turfs/simulated/river.dm b/code/game/turfs/simulated/river.dm index 2febfc20d78..7c9034b9ea5 100644 --- a/code/game/turfs/simulated/river.dm +++ b/code/game/turfs/simulated/river.dm @@ -67,21 +67,25 @@ var/detouring = 0 var/cur_dir = get_dir(cur_turf, target_turf) while(cur_turf != target_turf) - if(detouring) //randomly snake around a bit - if(prob(21)) - detouring = 0 - cur_dir = get_dir(cur_turf, target_turf) - else if(prob(20)) - detouring = 1 - if(prob(50)) - cur_dir = turn(cur_dir, 45) + var/attempts = 100 + do + if(detouring) //randomly snake around a bit + if(prob(20)) + detouring = 0 + cur_dir = get_dir(cur_turf, target_turf) + else if(prob(20)) + detouring = 1 + if(prob(50)) + cur_dir = turn(cur_dir, 45) + else + cur_dir = turn(cur_dir, -45) else - cur_dir = turn(cur_dir, -45) - else - cur_dir = get_dir(cur_turf, target_turf) + cur_dir = get_dir(cur_turf, target_turf) + // we may veer off the map entirely, returning a null turf; if so, go back and try again + while(get_step(cur_turf, cur_dir) == null && attempts-- > 0) cur_turf = get_step(cur_turf, cur_dir) - if(isnull(cur_turf)) //This might be the fuck up. Kill the loop if this happens + if(isnull(cur_turf)) stack_trace("Encountered a null turf in river loop, target turf was [target_turf], x=[target_turf.x], y=[target_turf.y].") break var/area/new_area = get_area(cur_turf)