alias setcurrent {
set %i 1
set %min 1
while %i <= %olistitems {
if $calc(%olist.g [ $+ [ %min ] ] + %olist.h [ $+ [ %min ] ]) > $calc(%olist.h [ $+ [ %i ] ] + %olist.g [ $+ [ %i ] ]) { set %min %i }
inc %i
}
set %current.x %olist.x [ $+ [ %min ] ]
set %current.y %olist.y [ $+ [ %min ] ]
set %current.g %olist.g [ $+ [ %min ] ]
set %current.h %olist.h [ $+ [ %min ] ]
set %olist.x [ $+ [ %min ] ] %olist.x [ $+ [ %olistitems ] ]
set %olist.y [ $+ [ %min ] ] %olist.y [ $+ [ %olistitems ] ]
set %olist.g [ $+ [ %min ] ] %olist.g [ $+ [ %olistitems ] ]
set %olist.h [ $+ [ %min ] ] %olist.h [ $+ [ %olistitems ] ]
dec %olistitems
}
alias clistadd {
inc %clistitems
set %clist.x [ $+ [ %clistitems ] ] $1
set %clist.y [ $+ [ %clistitems ] ] $2
set %clist.g [ $+ [ %clistitems ] ] $3
set %clist.h [ $+ [ %clistitems ] ] $calc($abs(%current.x - %d.x) + $abs(%current.y - %d.y))
set %clist.px [ $+ [ %clistitems ] ] $4
set %clist.py [ $+ [ %clistitems ] ] $5
return 1
}
alias clistexists {
set %i 1
while %i <= %clistitems {
if (%clist.x [ $+ [ %i ] ] == $1 && %clist.y [ $+ [ %i ] ] == $2) { return 1 }
inc %i
}
return 0
}
alias olistexists {
set %i 1
while %i <= %olistitems {
if (%olist.x [ $+ [ %i ] ] == $1 && %olist.y [ $+ [ %i ] ] == $2) { return 1 }
inc %i
}
return 0
}
alias olistadd {
inc %olistitems
set %olist.x [ $+ [ %olistitems ] ] $1
set %olist.y [ $+ [ %olistitems ] ] $2
set %olist.g [ $+ [ %olistitems ] ] $3
set %olist.h [ $+ [ %olistitems ] ] $calc($abs(%current.x - %d.x) + $abs(%current.y - %d.y))
set %olist.px [ $+ [ %olistitems ] ] $4
set %olist.py [ $+ [ %olistitems ] ] $5
return 1
}
;**************************************************************************************
alias findpath {
set %olistitems 0 | set %clistitems 0
set %start.x $1 | set %start.y $2
.echo -a $olistadd($1,$2,0,$1,$2)
set %current.x $1 | set %current.y $2
while (%current.x != %d.x && %current.y != %d.y) {
setcurrent ;;removes from open list :)
.echo -a $clistadd(%current.x,%current.y,%current.g,%current.px,%current.py)
set %a -1 |
while %a <= 1 {
set %b -2
while %b <= 0 {
inc %b
if (%a == 0 && %b == 0) { continue }
if (%a != 0 && %b != 0) { continue }
if $clistexists($calc(%current.x + %a),$calc(%current.y + %b)) == 1 { continue }
if (%diggermap [ $+ [ $calc(%current.x + %a) ] ] [ $+ [ $calc(%current.y + %b) ] ] == enemy || %diggermap [ $+ [ $calc(%current.x + %a) ] ] [ $+ [ $calc(%current.y + %b) ] ] == empty || %diggermap [ $+ [ $calc(%current.x + %a) ] ] [ $+ [ $calc(%current.y + %b) ] ] == digger) {
;*****************************************************************************************************************************************
if ($olistexists($calc(%current.x + %a),$calc(%current.y + %b)) == 0) { .echo -a $olistadd($calc(%current.x + %a),$calc(%current.y + %b),$calc(%current.g + 10),%current.x,%current.y) }
;*****************************************************************************************************************************************
}
}
inc %a
}
if ($calc(%current.x + %a) == %d.x && $calc(%current.y + %b) == %d.y) { return 1 }
if %olistitems == 0 { return 0 }
}
}