Need help with obstacle avoidance

Help section from before the user variable changes that broke all macros

Moderator: MacroQuest Developers

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Need help with obstacle avoidance

Post by Mckorr » Fri Jul 11, 2003 3:31 pm

Have an autofight routine I use as an include in macros... actually, I believe it was stolen almost directly from L124RD's macrokit.

Problem I'm having is that if I use this to autohunt I get stuck on trees, rocks, etc. I have a subroutine that will back up and strafe... but can't figure out a working way to call that subroutine. Can anyone help me out with this?

Code: Select all

sub Attack
  /varset a(8,0) "$target(name,clean)"
  /varset a(8,1) $target(level)
  /varset a(8,2) $target(name)
  /varset a(8,3) $target(id)
  /echo Fighting a level $a(8,1) $a(8,0)
  /face
  /sendkey down up


:CloserAF
  /if "$target(id)"!="$a(8,3)" /goto :EndAF

  /if n $target(distance)>10 /sendkey down up
  /if n $target(distance)<6 /sendkey down down
  /if n $target(distance)<11 /sendkey up up
  /if n $target(distance)>5 /sendkey up down
  /if n $target(distance)<12 /attack on
  /if n $target(distance)>19 /attack off
  /face fast nopredict
  /if n $char(ability,"Bash")>0 /doability "Bash"
  /if n $char(ability,"Kick")>0 /doability "Kick"
  /if n $char(ability,"Disarm")>0 /doability "Disarm"
  /goto :CloserAF

:EndAF
  /echo The level $a(8,1) $a(8,0) is dead...
  /sendkey up up
  /sendkey up down
  /attack off
  /varset a(8,3) 0
/return

sub Obstacle 
   | We appear to be stuck so try and backup and strafe sideways 
   /sendkey up up 
   /sendkey down down 
   /delay 2 
   /sendkey up down 
   /sendkey down ctrl 
   /if n $rand(99)>50 { 
      /sendkey down right 
   } else { 
      /sendkey down left 
   } 
   /delay 3 
   /sendkey up right 
   /sendkey up left 
   /sendkey up ctrl 
   /sendkey down up 
/return 
MQ2: Think of it as Evolution in action.

MagnanImus
decaying skeleton
decaying skeleton
Posts: 4
Joined: Thu Feb 06, 2003 11:29 pm

This is what i use for obstacle avoidance

Post by MagnanImus » Fri Jul 11, 2003 4:07 pm

This is what i use for obstacle avoidance. Yes the code is rather sloppy, i am in the process of rewriting all of my movement routines...but this should get the job done, or atleast point you in the right direction so you can get your own version made.


It turns 90 degress and moves a bit and then continues on its course. If it hits an obstacle again within a specified time. It will turn again 120 degrees. It will keep turning in increased increments of 30 until. I added these increments when i was getting stuck in buildings and it couldn't find the exit. If you set $a(99,95) to 1. It will gate after a few attempts at getting unstuck, by calling Sub Cast.


If you are using it to walk to a specific location, it needs $p0 to be the y,x location. If you are approaching a target, it doesn't need any parameters.

You can edit its sensitivity to objects by changing the /if statement

/if n $calc($abs($calc($v27-$v17))+$abs($calc($v28-$v18)))<0.30.

Changing 0.30 to 0.20 makes it less sensitive. A larger number makes it more sensitive

Code: Select all

sub loccheck
  /if "$v27"=="" /varset v27 100000
  /if "$v28"=="" /varset v28 100000
  /if "$v17"=="" /varset v17 $char(x)
  /if "$v18"=="" /varset v18 $char(y)
  /if "$char(state)"=="DUCK" {
  /stand
  /goto :Endcheck
  }
  /varset v55 0
  /if n $t19==0 /varset a(99,77) 90
  /if n $t19!=0 /varadd a(99,77) 30
  /if "$p0"!="" {
    /if n $distance($p0)<30 /goto :Endcheck
  }
  /if $target()==TRUE {
  /if n $target(distance)<30 /goto :Endcheck
  }
  /if n $calc($abs($calc($v27-$v17))+$abs($calc($v28-$v18)))<0.30 {
  /varadd t19 80
    /sendkey down down
    /delay 6
    /sendkey up down
    /face fast heading $calc($char(heading)+$a(99,77))
    /sendkey Down Up
    /delay 15
    /sendkey Up Up
    /varset v55 1
    }
  }
  
  

| ****** Set $a(99,95) to 1 to use the gateout feature *****|

  /if n $a(99,95)==1 {
    /if n $t19>250 {
    /sendkey up up
    /delay 10
    /call cast gate
    /varset t19 0
    /delay 20
    /press esc
    /sendkey down up
    }
  }

  :Endcheck
  /varset v27 $v17
  /varset v28 $v18
  /varset v17 $char(x)
  /varset v18 $char(y)
  /return
-Mag
Last edited by MagnanImus on Fri Jul 11, 2003 4:21 pm, edited 1 time in total.

GoatFoot
a lesser mummy
a lesser mummy
Posts: 68
Joined: Fri Jan 17, 2003 1:48 am

Post by GoatFoot » Fri Jul 11, 2003 4:07 pm

Code: Select all

#define INTERVAL 2 | time between checks for stuckness.
#define STUCK 5  | How far away do you have to be from last loc to not be considered stuck

:CloserAF
  /varset v1 $char(y)
  /varset v2 $char(x)
  /varset v3 $running
  .
  .
  .
  /if n $running>$calc($v3+INTERVAL) /if n $distance($v1,$v2)<STUCK /call Obstacle
/goto :CloserAF
 

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Fri Jul 11, 2003 4:15 pm

Thanks GoatFoot, appreciate the help.
MQ2: Think of it as Evolution in action.

GoatFoot
a lesser mummy
a lesser mummy
Posts: 68
Joined: Fri Jan 17, 2003 1:48 am

Post by GoatFoot » Fri Jul 11, 2003 4:20 pm

might want to toss a

Code: Select all

 /if $combat!=TRUE
test in there for when you've closed and are fighting the critter.

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Sat Jul 12, 2003 10:50 am

Yeah, thought of that when I noticed that I'd end up strafing in the middle of a fight....
MQ2: Think of it as Evolution in action.

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Mon Jul 14, 2003 10:24 am

Unfortunately this doesn't work. sub Obstacle never gets called, no matter how long you are stuck on a rock. Back to the drawing board.
MQ2: Think of it as Evolution in action.

Zeus
a hill giant
a hill giant
Posts: 180
Joined: Wed Feb 19, 2003 10:03 am
Contact:

Post by Zeus » Wed Jul 16, 2003 7:15 am

Dumb question but, do you have the stuck check at the start or end of every cycle and made sure the check is being done?

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Wed Jul 16, 2003 10:28 am

I got it figured out. I borrowed some code from hunter.mac, but called my strafing routine instead of turning off at an angle. Works pretty well, though I've still managed to get stuck once or twice.

Need a minor adjustment to take into account getting stuck while chasing something I've already engaged, but that's simple enough.

Thanks for all the help.

Oh, and yes, the check for stickiness needs to be at the beginning of the movement routine.
MQ2: Think of it as Evolution in action.