Code: Select all
Sub InitStack()
var chn = UO.GetName()
UO.SetGlobal('STACK'+str(chn), '0')
endsub
Sub Push(param)
var chn = UO.GetName()
var chk = val(UO.GetGlobal('STACK'+str(chn))) ; количество элементов в стеке
UO.SetGlobal('STACK'+str(chn),str(chk + 1))
UO.SetGlobal('STACK_'+str(chn)+str(chk), param)
UO.Print('Global Push ' +UO.GetGlobal('STACK'+str(chn)))
UO.Print('Global Push param ' +UO.GetGlobal('STACK_'+str(chn)+str(chk)))
endsub
Sub Pop()
var chn = UO.GetName()
var chk = val(UO.GetGlobal('STACK'+str(chn))) ; количество элементов в стеке
if chk then
UO.SetGlobal('STACK'+str(chn),str(chk + -1))
UO.Print('Global Pop ' +UO.GetGlobal('STACK'+str(chn)))
UO.Print('Global Pop param ' +UO.GetGlobal('STACK_'+str(chn)+str(chk + -1)))
return UO.GetGlobal('STACK_'+str(chn)+str(chk + -1))
else
return ''
endif
endsub
sub GoToXY(x,y,prec)
#original (c) ...
#modification 2.00 (c) SerrouS
dim turn[8] ; индекс - ГетДир, значение поворот направо под 45 градусов
turn[0] = 39
turn[1] = 34
turn[2] = 40
turn[3] = 35
turn[4] = 37
turn[5] = 36
turn[6] = 38
turn[7] = 33
dim deltax[8]; индекс - аналогично, значение - изменение координаты при проходе стенки
deltax[0] = 1
deltax[1] = 1
deltax[2] = 1
deltax[3] = 0
deltax[4] = -1
deltax[5] = -1
deltax[6] = -1
deltax[7] = 0
dim deltay[8]
deltay[0] = -1
deltay[1] = 0
deltay[2] = 1
deltay[3] = 1
deltay[4] = 1
deltay[5] = 0
deltay[6] = -1
deltay[7] = -1
var dx,dy, Exit=0
var mx,my ; current coords
var lx = 0, ly = 0, ld = -1 ; last move coords
var pathFind = 0 ; as logical 0 - norm, 1 - block
var ind
var recursInd = 0
var fout = 0
var stepdelay = 500
InitStack()
repeat
CheckLag()
CheckPause()
mx=UO.GetX()
my=UO.GetY()
; calculating for precision coming
dx = mx + -x
If dx < 0 Then
dx = 0 + -dx
EndIf ;get ABS diff
dy = my + -y
If dy < 0 Then
dy = 0 + -dy
EndIf
If dy > dx Then
dx = dy
EndIf
If dx <= prec Then
Exit=1
Return 1
EndIf
if mx == x and my == y then
Exit=1
return 1
endif
lx = mx
ly = my
ld = UO.GetDir() ; cause once pressing can only change the direcction
if mx == x and my > y then
UO.Press(33)
endif
if mx == x and my < y then
UO.Press(35)
endif
if mx < x and my == y then
UO.Press(34)
endif
if mx < x and my > y then
UO.Press(39)
endif
if mx < x and my < y then
UO.Press(40)
endif
if mx > x and my == y then
UO.Press(36)
endif
if mx > x and my > y then
UO.Press(38)
endif
if mx > x and my < y then
UO.Press(37)
endif
; UO.Print('KeyPressed')
CheckLag()
CheckPause()
;wait( stepdelay )
if lx == UO.GetX() and ly == UO.GetY() and ld == UO.GetDir() then
; now there is a stop situation
UO.Print('PathFind')
recursInd = 0
#################################################
repeat
ind = ld
; UO.Print(str(ind))
fout = 0
repeat ; идем в обход пока не упремся снова или не кончится стена
; UO.Print('Iteration')
mx = UO.GetX()
my = UO.GetY()
ld = UO.GetDir()
UO.Press(turn[ind])
CheckLag()
CheckPause()
wait(stepdelay)
if (UO.GetX() == mx and UO.GetY() == my and ld == UO.GetDir()) then
fout = 1 ; уперлись
else
dx = UO.GetX() + -mx
dy = UO.GetY() + -my
; UO.Print('deltas '+str(dx)+' '+str(dy))
if deltax[ind] == dx and deltay[ind] == dy then
fout = 2 ; препятствие пройдено
endif
endif
until fout
; UO.Print('fout '+ str(fout))
if fout == 1 then ; уходим на следующий поворот
recursInd = recursInd + 1
Push(str(ind))
;ld = ind
else ; fout == 2
; надо попытаться восстановить контекст из стека, или выйти из обхода
; UO.Print('Iter '+ str(recursInd))
pathFind = 0
if recursInd then ; восстановление
pathFind = 1
recursInd = recursInd + -1
ld = val(Pop()) + -1
if ld == -1 then
ld = 7
endif
UO.Press(turn[ld])
CheckLag()
CheckPause()
wait(stepdelay) ; в сиду того, что ондо нажатие меняет напрваление
endif
endif
until not recursInd and not pathFind
#################################################
UO.Print('PathFind END')
endif
until Exit==1
Return 1
endsub