Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var MaxTraceDistance=10
- var TraceLoopIncrease=10
- var LimitTrace=20
- var Speed=2
- var StepTimeOut=500
- var CheckCnt=1
- var DynamicPause=30
- #Return True if END should be forced
- Sub CustomIsEnd(GoX,GoY,Prec)
- return false
- end sub
- Sub Walker(GoX,GoY,Prec)
- UO.SetGlobal("Logging","0")
- UO.SetGlobal("BlindWalk","0")
- var LastDir
- var MoveRes
- var TracerCnt
- var TraceDirection
- UO.SetGlobal("GlobalGoX",str(GoX))
- UO.SetGlobal("GlobalGoY",str(GoY))
- while not IsEnd(GoX,GoY,Prec)
- LogInfo('Just walking')
- LastDir=GoUntilHit(GoX,GoY,Prec)
- if IsEnd(GoX,GoY,Prec) then
- return 1
- end if
- TraceDirection=CountDirection(GoX,GoY,CurDir,Prec)
- TracerCnt=MaxTraceDistance
- repeat
- LogInfo('Tracing')
- MoveRes = FullAroundTrace(LastDir,TraceDirection,GoX,GoY,Prec,TracerCnt)
- TracerCnt = TracerCnt + TraceLoopIncrease
- TraceDirection = -TraceDirection
- until (MoveRes == 1) OR (TracerCnt > LimitTrace)
- wend
- return 1
- end sub
- Sub FullAroundTrace(StartDir,Direction,GoX,GoY,Prec,MaxTrace)
- var LineX=UO.GetX()
- var LineY=UO.GetY()
- var CurDir=StartDir
- var StartX,StartY
- var MovesDone=0
- repeat
- StartX=UO.GetX()
- StartY=UO.GetY()
- CurDir=Tracer(CurDir,Direction,Prec)
- if (CurDir==GetDir(GoX,GoY,Prec)) then
- return 1
- endif
- if MovesDone>0 and PrevMoveCross(GetDirToDir(UO.GetDir(),Prec),LineX,LineY,GoX,GoY,StartX,StartY,Prec) then
- return 1
- end if
- MovesDone=MovesDone+1
- CurDir=AddToDir(CurDir,-Direction,Prec)
- until MovesDone>MaxTrace
- return 0
- end sub
- Sub CountDirection(GoX,GoY,StartDir,Prec)
- var GoDir=GetDir(GoX,GoY,Prec)
- var MyX=UO.GetX()
- var MyY=UO.GetY()
- if GoDir<StartDir then
- return -1
- end if
- if GoDir>StartDir then
- return 1
- end if
- if Abs(MyX-GoX)>Abs(MyY-GoY) then
- if (GoDir==3) OR (GoDir==7) then
- return -1
- else
- return 1
- end if
- else
- if (GoDir==1) or (GoDir==5) then
- return -1
- else
- return 1
- end if
- end if
- end sub
- Sub PrevMoveCross(Dir,x1,y1,x2,y2,StartX,StartY,Prec)
- var x3,y3,x4,y4
- x3=StartX
- y3=StartY
- x4=StartX+(XFromDir(Dir)-StartX)*Speed
- y4=StartY+(YFromDir(Dir)-StartY)*Speed
- return LinesCrossing(x1,y1,x2,y2,x3,y3,x4,y4,Prec)
- end sub
- Sub LinesCrossing(x1,y1,x2,y2,x3,y3,x4,y4,Prec)
- if x1==x3 and y1==y3 then
- return false
- end if
- LogInfo('Start cross check')
- var ua1=(x4-x3)*(y1-y3)-(y4-y3)*(x1-x3)
- var ub1=(y4-y3)*(x2-x1)-(x4-x3)*(y2-y1)
- var ua2=(x2-x1)*(y1-y3)-(y2-y1)*(x1-x3)
- var ub2=(y4-y3)*(x2-x1)-(x4-x3)*(y2-y1)
- #Check for parallel lines
- if (ub1 == 0) or (ub2 == 0) then
- return false
- end if
- var u1=ua1/ub1
- var u2=ua2/ub2
- if IsDiap(u1,0,1,0.01) and IsDiap(u2,0,1,0.01) then
- LogInfo('Vectors crossing info:')
- LogInfo('x1= '+str(x1))
- LogInfo('y1= '+str(y1))
- LogInfo('x2= '+str(x2))
- LogInfo('y2= '+str(y2))
- LogInfo('x3= '+str(x3))
- LogInfo('y3= '+str(y3))
- LogInfo('x4= '+str(x4))
- LogInfo('y4= '+str(y4))
- return true
- else
- LogInfo('End cross check')
- return false
- end if
- end sub
- Sub IsDiap(X,X0,X1,Prec)
- if X<=X0+Prec and X>=X1-Prec OR X>=X0-Prec and X<=X1+Prec then
- return true
- end if
- return false
- end sub
- Sub GoUntilHit(GoX,GoY,Prec)
- var LastDir
- LastDir=GetDir(GoX,GoY,Prec)
- var CouldMove
- repeat
- LastDir=GetDir(GoX,GoY,Prec)
- if LastDir<>0 and not IsEnd(GoX,GoY,Prec) then
- CouldMove=TryDir(LastDir,Prec)
- end if
- until LastDir==0 or IsEnd(GoX,GoY,Prec) or not CouldMove
- return LastDir
- end sub
- Sub IsEnd(GoX,GoY,Prec)
- if (CustomIsEnd(GoX, GoY, Prec) == true) then
- return true
- end if
- if Abs(UO.GetX()-GoX)<=Prec and Abs(UO.GetY()-GoY)<=Prec then
- LogInfo('END FOUND')
- return true
- else
- return false
- end if
- end sub
- Sub GetDir(GoX,GoY,Prec)
- var MyX=UO.GetX()
- var MyY=UO.GetY()
- var DiffX=Abs(UO.GetX()-GoX)
- var DiffY=Abs(UO.GetY()-GoY)
- var GoDir=0
- if (DiffX/(DiffY+0.1))>=2 then
- if (MyX>GoX) then
- GoDir=7
- else
- GoDir=3
- end if
- else
- if (DiffY/(DiffX+0.1))>=2 then
- if (MyY>GoY) then
- GoDir=5
- else
- GoDir=1
- end if
- else
- if (MyX>GoX) and (MyY>GoY) then
- GoDir=6
- else
- if (MyX>GoX) and (MyY<GoY) then
- GoDir=8
- else
- if (MyX<GoX) and (MyY>GoY) then
- GoDir=4
- else
- if (MyX<GoX) and (MyY<GoY) then
- GoDir=2
- end if
- end if
- end if
- end if
- end if
- end if
- return GoDir
- end sub
- Sub Tracer(StartDir,Direction,Prec)
- var CurDir=StartDir
- var Result
- repeat
- Result=TryDir(CurDir,Prec)
- if not Result then
- CurDir=AddToDir(CurDir,Direction,Prec)
- end if
- until Result
- return Result
- end sub
- Sub AddToDir(Dir,Cnt,Prec)
- var NewDir=Dir
- NewDir=NewDir+Cnt
- while NewDir>8
- NewDir=NewDir-8
- wend
- while NewDir<1
- NewDir=NewDir+8
- wend
- return NewDir
- end sub
- Sub TryDir(Dir,Prec)
- var BegX=UO.GetX() # Ia?aeuiia O
- var BegY=UO.GetY() # Ia?aeuiia Y
- var Counter=0
- var GoX=BegX
- var GoY=BegY
- GoX=XFromDir(Dir)
- GoY=YFromDir(Dir)
- if not IsPass(GoX,GoY) then
- LogInfo(str(GoX)+':'+str(GoY)+' is not passable')
- return false
- end if
- return TurnAndGoDir(Dir,Prec)
- end sub
- Sub XFromDir(Dir)
- if Dir==2 OR Dir==3 Or Dir==4 then
- return (UO.GetX()+1)
- end if
- if Dir==6 OR Dir==7 Or Dir==8 then
- return (UO.GetX()-1)
- end if
- return (UO.GetX())
- end sub
- Sub YFromDir(Dir)
- if Dir==8 OR Dir==1 Or Dir==2 then
- return (UO.GetY()+1)
- end if
- if Dir==4 OR Dir==5 Or Dir==6 then
- return (UO.GetY()-1)
- end if
- return (UO.GetY())
- end sub
- Sub TurnAndGoDir(Dir,Prec)
- var StartDir=GetDirToDir(UO.GetDir(),Prec)
- var StartX=UO.GetX()
- var StartY=UO.GetY()
- var EndDir
- var Counter=0
- var TestCounter=CheckCnt
- #Direction Test
- repeat
- Counter = 0
- LogInfo('Dir: '+str(StartDir)+' Counter: '+str(Counter))
- PressDir(Dir)
- repeat
- EndDir=GetDirToDir(UO.GetDir(),Prec)
- wait(DynamicPause)
- Counter=Counter+1
- until StartDir<>EndDir or StartY<>UO.GetY() or StartX<>UO.GetX() or Counter>=StepTimeOut/DynamicPause
- TestCounter = TestCounter - 1
- LogInfo('Dir: '+str(EndDir)+' Counter: '+str(Counter))
- until TestCounter <= 0 or Counter < StepTimeOut/DynamicPause
- if Counter>=StepTimeOut/DynamicPause then
- LogInfo('Direction timeout reached')
- return 0
- end if
- #End direction Test
- if StartY<>UO.GetY() or StartX<>UO.GetX() then
- return Dir
- end if
- #Start Primary test
- TestCounter=CheckCnt
- repeat
- GoDir(Dir,Prec)
- Counter=0
- repeat
- wait(DynamicPause)
- Counter=Counter+1
- until StartY<>UO.GetY() or StartX<>UO.GetX() or Counter>=StepTimeOut/DynamicPause
- TestCounter = TestCounter - 1
- until TestCounter <= 0 or Counter < StepTimeOut/DynamicPause
- #End primary test
- if Counter>=StepTimeOut/DynamicPause then
- LogInfo('Step timeout reached')
- return 0
- else
- return Dir
- end if
- end sub
- Sub GetDirToDir(GotDir,Prec)
- var ChangedDir=-GotDir
- ChangedDir=AddToDir(ChangedDir,5,Prec)
- return ChangedDir
- end sub
- Sub DirToInj(Dir)
- dim Dirs[9]
- Dirs[1]=1
- Dirs[2]=2
- Dirs[3]=3
- Dirs[4]=6
- Dirs[5]=9
- Dirs[6]=8
- Dirs[7]=7
- Dirs[8]=4
- return (Dirs[Dir])
- end sub
- Sub PressDir(Dir)
- dim Dirs[9]
- Dirs[1]=35
- Dirs[2]=40
- Dirs[3]=34
- Dirs[4]=39
- Dirs[5]=33
- Dirs[6]=38
- Dirs[7]=36
- Dirs[8]=37
- UO.Press(Dirs[Dir],1)
- end sub
- Sub GoDir(Dir,Prec)
- dim Dirs[9]
- Dirs[1]=35
- Dirs[2]=40
- Dirs[3]=34
- Dirs[4]=39
- Dirs[5]=33
- Dirs[6]=38
- Dirs[7]=36
- Dirs[8]=37
- var DistanceX=Abs(UO.GetX()-val(UO.GetGlobal("GlobalGoX")))
- var DistanceY=Abs(UO.GetY()-val(UO.GetGlobal("GlobalGoY")))
- var GoDistance
- if (DistanceX-Prec)<Speed then
- GoDistance=DistanceX-Prec
- else
- if (DistanceY-Prec)<Speed then
- GoDistance=DistanceY-Prec
- else
- GoDistance=Speed
- endif
- endif
- UO.Press(Dirs[Dir],GoDistance)
- end sub
- Sub IsPass(X,Y)
- if UO.GetGlobal("BlindWalk") then
- return true
- endif
- dim Types[60]
- Types[1]=3
- Types[2]=25
- Types[3]=51
- Types[4]=63
- Types[5]=113
- Types[6]=140
- Types[7]=172
- Types[8]=219
- Types[9]=232
- Types[10]=235
- Types[11]=239
- Types[12]=243
- Types[13]=248
- Types[14]=251
- Types[15]=264
- Types[16]=267
- Types[17]=282
- Types[18]=289
- Types[19]=321
- Types[20]=379
- Types[21]=420
- Types[22]=440
- Types[23]=476
- Types[24]=499
- Types[25]=513
- Types[26]=542
- Types[27]=578
- Types[28]=586
- Types[29]=622
- Types[30]=700
- Types[31]=804
- Types[32]=1740
- Types[33]=1758
- Types[34]=1770
- Types[35]=1779
- Types[36]=1779
- Types[37]=1881
- Types[38]=1886
- Types[39]=1801
- Types[40]=1805
- Types[41]=1813
- Types[42]=1820
- Types[43]=1831
- Types[44]=1833
- Types[45]=1843
- Types[46]=1850
- Types[47]=1873
- Types[48]=1876
- Types[49]=1885
- Types[50]=1888
- Types[51]=1946
- Types[52]=1969
- Types[53]=2500
- Types[54]=2539
- for var i=1 TO 53 STEP 2
- if UO.PrivateGetTile(X,Y,-1,Types[i],Types[i+1]) then
- return true
- end if
- next
- return false
- end sub
- Sub LogInfo(Line)
- if not UO.GetGlobal("Logging")=="0" then
- UO.TextOpen()
- UO.TextPrint(str(UO.GetX())+":"+str(UO.GetY())+" - "+Line);
- end if
- end sub
- Sub Abs(X)
- if X>0 then
- return X
- else
- return (-X)
- end if
- end sub
- ########################################## ????? ??????? 3 ##########################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement