All pastes #732866 Raw Edit

Something

public text v1 · immutable
·published 2007-10-11 10:39 UTC
rendered paste body
#####################################################
#####################################################
#####################################################
#####################################################
#####################################################
#####################################################
#####################################################
# WW  W  WW   AA    LL     Kk  k  EE  EE  RRR       #
# WW  W  WW  AA A   LL     Kk k   EEE     R  R      #
# WW WW  WW  AAAA   LL     KkK    EEE     RRR       #
#  WWW WWW  AA   A   LLLL  Kk kk  EE  EE  R  R      #
#####################################################

sub tttt()
walker(1172,1692)
end sub
             
var Prec=2
var MaxTraceDistance=20
var Speed=1
var StepTimeOut=500

Sub Walker(GoX,GoY)
  UO.SetGlobal("Logging","1")
  UO.SetGlobal("BlindWalk","0")
  var LastDir
  UO.SetGlobal("GlobalGoX",str(GoX))
  UO.SetGlobal("GlobalGoY",str(GoY))
  while not IsEnd(GoX,GoY)
    LogInfo('Just walking')
    LastDir=GoUntilHit(GoX,GoY)
    if not IsEnd(GoX,GoY) then
      LogInfo('Tracing')
      FullAroundTrace(LastDir,GoX,GoY)
    end if
  wend
end sub

Sub FullAroundTrace(StartDir,GoX,GoY)
  var LineX=UO.GetX()
  var LineY=UO.GetY()
  var CurDir=StartDir
  var Direction=CountDirection(GoX,GoY,CurDir)
  var StartX,StartY
  var MovesDone=0
  repeat
    StartX=UO.GetX()
    StartY=UO.GetY()
    CurDir=Tracer(CurDir,Direction)
    if MovesDone>0 and PrevMoveCross(GetDirToDir(UO.GetDir()),LineX,LineY,GoX,GoY,StartX,StartY) then
      return
    end if
    MovesDone=MovesDone+1
    CurDir=AddToDir(CurDir,-Direction)
  until MovesDone>MaxTraceDistance
end sub

Sub CountDirection(GoX,GoY,StartDir)
  var GoDir=GetDir(GoX,GoY)
  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 and GoY>MyY) OR (GoDir==7 and GoY<MyY) then
      return -1
    else
      return 1
    end if
  else
    if (GoDir==1 and GoX<MyX) or (GoDir==5 and GoX>MyX) then
      return -1
    else
      return 1
    end if
  end if
end sub

Sub PrevMoveCross(Dir,x1,y1,x2,y2,StartX,StartY)
  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)
end sub

Sub LinesCrossing(x1,y1,x2,y2,x3,y3,x4,y4)
  if x1==x3 and y1==y3 then
    return false
  end if
  var z1=(x3-x1)*(y2-y1)-(y3-y1)*(x2-x1)
  var z2=(x4-x1)*(y2-y1)-(y4-y1)*(x2-x1)
  if z1*z2>0 then 
    return false
  else
    LogInfo('Vector 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
  end if
end sub

Sub IsDiap(X,X0,X1)
  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)
  var LastDir
  LastDir=GetDir(GoX,GoY)
  var CouldMove
  repeat
    LastDir=GetDir(GoX,GoY)
    if LastDir<>0 and not IsEnd(GoX,GoY) then
      CouldMove=TryDir(LastDir) 
    end if
  until LastDir==0 or IsEnd(GoX,GoY) or not CouldMove
  return LastDir
end sub

Sub IsEnd(GoX,GoY)
  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)
  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)
  var CurDir=StartDir
  var Result
  repeat
    Result=TryDir(CurDir)
    if not Result then
      CurDir=AddToDir(CurDir,Direction)
    end if
  until Result
  return Result
end sub

Sub AddToDir(Dir,Cnt)
  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)
  var BegX=UO.GetX() # Начальное Х
  var BegY=UO.GetY() # Начальное Y
  var Counter=0
  var GoX=BegX
  var GoY=BegY
  GoX=XFromDir(Dir)
  GoY=YFromDir(Dir)
  if not IsPass(UO.asmMapGetTile(GoX,GoY,0)) then
    LogInfo(str(UO.asmMapGetTile(GoX,GoY,0))+' is not passable')
  	return false
  end if
  return TurnAndGoDir(Dir)
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)
  var StartDir=GetDirToDir(UO.GetDir())
  var StartX=UO.GetX()
  var StartY=UO.GetY()
  var EndDir
  var Counter=0
  GoDir(Dir)
  repeat
    EndDir=GetDirToDir(UO.GetDir())
    wait(100)
    Counter=Counter+1
  until StartDir<>EndDir or StartY<>UO.GetY() or StartX<>UO.GetX() or Counter>=8
  if Counter>=8 then
  	return 0
  end if
  if StartY<>UO.GetY() or StartX<>UO.GetX() then
  	return Dir
  else
  	GoDir(Dir)
    repeat
      wait(100)
      Counter=Counter+1
    until StartY<>UO.GetY() or StartX<>UO.GetX() or Counter>=StepTimeOut/100
    if Counter>=StepTimeOut/100 then 
      LogInfo('Step timeout reached')
      return 0
    else
      return Dir
    end if
  end if
end sub

sub Test2()
Tracer(7,1)
end sub

Sub GetDirToDir(GotDir)
var ChangedDir=-GotDir
ChangedDir=AddToDir(ChangedDir,5)
return ChangedDir
end sub

Sub DirToInj(Dir)
var OutDir
if Dir==1 then
OutDir=1
end if
if Dir==2 then
OutDir=2
end if
if Dir==3 then
OutDir=3
end if
if Dir==4 then
OutDir=6
end if
if Dir==5 then
OutDir=9
end if
if Dir==6 then
OutDir=8
end if
if Dir==7 then
OutDir=7
end if
if Dir==8 then
OutDir=4
end if
return OutDir
end sub

Sub GoDir(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

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(ID)
  if UO.GetGlobal("BlindWalk") then
    return true
  endif
  dim Types[60]
  Types[0]=4
  Types[1]=3
  Types[2]=5
  Types[3]=6
  Types[4]=203
  Types[5]=197
  Types[6]=212
  Types[7]=242
  Types[8]=241
  Types[9]=196
  Types[10]=198
  Types[11]=199
  Types[12]=1713
  Types[13]=1724
  Types[14]=243
  Types[15]=240
  Types[16]=219
  Types[17]=209
  Types[18]=214
  Types[19]=57
  Types[20]=24
  Types[21]=52
  Types[22]=22
  Types[23]=56
  Types[24]=23
  Types[25]=25
  Types[26]=58
  Types[27]=53
  Types[28]=61
  Types[29]=59
  Types[30]=580
  Types[31]=585
  Types[32]=581
  Types[33]=582
  Types[34]=583
  Types[35]=584
  Types[36]=596
  Types[37]=152
  Types[38]=81
  Types[39]=93
  Types[40]=95
  Types[41]=83
  Types[42]=142
  Types[43]=503
  Types[44]=141
  Types[45]=143
  Types[46]=500
  Types[47]=1088
  Types[48]=1089
  Types[49]=1086
  Types[50]=155
  Types[51]=501
  Types[52]=98
  Types[53]=90
  Types[54]=502
  Types[55]=1087
  Types[56]=598
  Types[57]=582
  Types[58]=200
  Types[59]=216
  
  for var i=0 to 59
    if Types[i]==ID 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())+" - "+str(Line));
  end if
end sub

Sub Abs(X)
  if X>0 then
    return X
  else
    return (-X)
  end if
end sub