[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
This commit is contained in:
CitadelStationBot
2018-02-27 05:03:42 -06:00
committed by Poojawa
parent f38a3b3a39
commit ff918707ee
3 changed files with 50 additions and 49 deletions
+25 -24
View File
@@ -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<<i //get cardinal directions.1,2,4,8
if(cur.bf & f)
var/T = get_step(cur.source,f)
if(T != exclude)
var/datum/PathNode/CN = openc[T] //current checking turf
var/r=((f & MASK_ODD)<<1)|((f & MASK_EVEN)>>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<<i //get cardinal directions.1,2,4,8
if(cur.bf & f)
var/T = get_step(cur.source,f)
if(T != exclude)
var/datum/PathNode/CN = openc[T] //current checking turf
var/r=((f & MASK_ODD)<<1)|((f & MASK_EVEN)>>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
@@ -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()
@@ -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