From ff918707ee14c9a35b31287c6edbacfc201c248b Mon Sep 17 00:00:00 2001 From: CitadelStationBot Date: Tue, 27 Feb 2018 05:03:42 -0600 Subject: [PATCH] [MIRROR] Cleanbot fix (#5720) * Cleanbot fix (#36003) cl selea fix: fixed floorbot fix: fixed cleanbot refactor: improved pathiding in case of given minimal distance;improved sanitation /cl closes #35995, #35919 * Cleanbot fix --- code/__HELPERS/AStar.dm | 49 ++++++++++--------- .../mob/living/simple_animal/bot/cleanbot.dm | 13 +++-- .../mob/living/simple_animal/bot/floorbot.dm | 37 +++++++------- 3 files changed, 50 insertions(+), 49 deletions(-) diff --git a/code/__HELPERS/AStar.dm b/code/__HELPERS/AStar.dm index c575a4b3d2..7de6ef522a 100644 --- a/code/__HELPERS/AStar.dm +++ b/code/__HELPERS/AStar.dm @@ -87,8 +87,9 @@ Actual Adjacent procs : return path -/proc/AStar(caller, var/turf/end, dist, maxnodes, maxnodedepth = 30, mintargetdist, adjacent = /turf/proc/reachableTurftest, id=null, turf/exclude=null, simulated_only = 1) +/proc/AStar(caller, _end, dist, maxnodes, maxnodedepth = 30, mintargetdist, adjacent = /turf/proc/reachableTurftest, id=null, turf/exclude=null, simulated_only = 1) //sanitation + var/turf/end = get_turf(_end) var/turf/start = get_turf(caller) if((!start)||(start.z != end.z)||(start == end)) //no pathfinding between z levels return 0 @@ -112,9 +113,8 @@ Actual Adjacent procs : var/closeenough if(mintargetdist) closeenough = call(cur.source,dist)(end) <= mintargetdist - //if too many steps, abandon that path - if(maxnodedepth && (cur.nt > maxnodedepth)) - continue + + //found the target turf (or close enough), let's create the path to it if(cur.source == end || closeenough) path = new() @@ -124,27 +124,28 @@ Actual Adjacent procs : path.Add(cur.source) break //get adjacents turfs using the adjacent proc, checking for access with id - for(var/i = 0 to 3) - var/f= 1<>1) //getting reverse direction throught swapping even and odd bits.((f & 01010101)<<1)|((f & 10101010)>>1) - var/newg = cur.g + call(cur.source,dist)(T) - if(CN) - //is already in open list, check if it's a better way from the current turf - CN.bf &= 15^r //we have no closed, so just cut off exceed dir.00001111 ^ reverse_dir.We don't need to expand to checked turf. - if(newg < CN.g) + if((!maxnodedepth)||(cur.nt <= maxnodedepth))//if too many steps, don't process that path + for(var/i = 0 to 3) + var/f= 1<>1) //getting reverse direction throught swapping even and odd bits.((f & 01010101)<<1)|((f & 10101010)>>1) + var/newg = cur.g + call(cur.source,dist)(T) + if(CN) + //is already in open list, check if it's a better way from the current turf + CN.bf &= 15^r //we have no closed, so just cut off exceed dir.00001111 ^ reverse_dir.We don't need to expand to checked turf. + if((newg < CN.g) ) + if(call(cur.source,adjacent)(caller, T, id, simulated_only)) + CN.setp(cur,newg,CN.h,cur.nt+1) + open.ReSort(CN)//reorder the changed element in the list + else + //is not already in open list, so add it if(call(cur.source,adjacent)(caller, T, id, simulated_only)) - CN.setp(cur,newg,CN.h,cur.nt+1) - open.ReSort(CN)//reorder the changed element in the list - else - //is not already in open list, so add it - if(call(cur.source,adjacent)(caller, T, id, simulated_only)) - CN = new(T,cur,newg,call(T,dist)(end),cur.nt+1,15^r) - open.Insert(CN) - openc[T] = CN + CN = new(T,cur,newg,call(T,dist)(end),cur.nt+1,15^r) + open.Insert(CN) + openc[T] = CN cur.bf = 0 CHECK_TICK //reverse the path to get it from start to finish diff --git a/code/modules/mob/living/simple_animal/bot/cleanbot.dm b/code/modules/mob/living/simple_animal/bot/cleanbot.dm index 6ed80afbb7..ff8b3fa0e9 100644 --- a/code/modules/mob/living/simple_animal/bot/cleanbot.dm +++ b/code/modules/mob/living/simple_animal/bot/cleanbot.dm @@ -145,6 +145,12 @@ mode = BOT_IDLE return + if(loc == get_turf(target)) + if(!(check_bot(target) && prob(50))) //Target is not defined at the parent. 50% chance to still try and clean so we dont get stuck on the last blood drop. + UnarmedAttack(target) //Rather than check at every step of the way, let's check before we do an action, so we can rescan before the other bot. + else + shuffle = TRUE //Shuffle the list the next time we scan so we dont both go the same way. + path = list() if(!path || path.len == 0) //No path, need a new one //Try to produce a path to the target, and ignore airlocks to which it has access. path = get_path_to(src, target.loc, /turf/proc/Distance_cardinal, 0, 30, id=access_card) @@ -159,13 +165,6 @@ mode = BOT_IDLE return - if(target && loc == target.loc) - if(!(check_bot(target) && prob(50))) //Target is not defined at the parent. 50% chance to still try and clean so we dont get stuck on the last blood drop. - UnarmedAttack(target) //Rather than check at every step of the way, let's check before we do an action, so we can rescan before the other bot. - else - shuffle = TRUE //Shuffle the list the next time we scan so we dont both go the same way. - path = list() - oldloc = loc /mob/living/simple_animal/bot/cleanbot/proc/get_targets() diff --git a/code/modules/mob/living/simple_animal/bot/floorbot.dm b/code/modules/mob/living/simple_animal/bot/floorbot.dm index 80493f526e..8b33886dcb 100644 --- a/code/modules/mob/living/simple_animal/bot/floorbot.dm +++ b/code/modules/mob/living/simple_animal/bot/floorbot.dm @@ -224,24 +224,7 @@ bot_patrol() if(target) - if(path.len == 0) - if(!isturf(target)) - var/turf/TL = get_turf(target) - path = get_path_to(src, TL, /turf/proc/Distance_cardinal, 0, 30, id=access_card,simulated_only = 0) - else - path = get_path_to(src, target, /turf/proc/Distance_cardinal, 0, 30, id=access_card,simulated_only = 0) - - if(!bot_move(target)) - add_to_ignore(target) - target = null - mode = BOT_IDLE - return - else if( !bot_move(target) ) - target = null - mode = BOT_IDLE - return - - if(loc == target || loc == target.loc) + if(loc == target || loc == get_turf(target)) if(check_bot(target)) //Target is not defined at the parent shuffle = TRUE if(prob(50)) //50% chance to still try to repair so we dont end up with 2 floorbots failing to fix the last breach @@ -262,6 +245,24 @@ target = null path = list() return + if(path.len == 0) + if(!isturf(target)) + var/turf/TL = get_turf(target) + path = get_path_to(src, TL, /turf/proc/Distance_cardinal, 0, 30, id=access_card,simulated_only = 0) + else + path = get_path_to(src, target, /turf/proc/Distance_cardinal, 0, 30, id=access_card,simulated_only = 0) + + if(!bot_move(target)) + add_to_ignore(target) + target = null + mode = BOT_IDLE + return + else if( !bot_move(target) ) + target = null + mode = BOT_IDLE + return + + oldloc = loc