Advertisement
kajacx

CRPL move code

Jun 1st, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. once
  2. <-Speed 2.0 div div ( <-Rotation 2.0 div sin ) ->R #diameter of the blind circle
  3. endonce
  4.  
  5. :MoveToTarget # f f - b
  6. #moves the unit close to the desired position (pass pixel coordinates) - returns: arrived at destination
  7. ->ty ->tx
  8.  
  9. #compute current angle and distance
  10. CurrentPixelCoords ->cy ->cx
  11. <-cx <-cy <-tx <-ty Distance ->distance
  12. <-ty <-cy sub <-tx <-cx sub atan2 ->desiredAngle
  13. "D A" <-distance <-desiredAngle Trace3
  14.  
  15. #teleport to target if close enought
  16. <-distance <-Speed lt if
  17. Self CONST_PIXELCOORDX <-tx SetUnitAttribute
  18. Self CONST_PIXELCOORDY <-ty SetUnitAttribute
  19. 1 return
  20. endif
  21.  
  22. # do first half of the movement BEFORE the angle is adjusted
  23. Self CONST_PIXELCOORDX SetUnitAttribute ( <-cx <-angle cos <-Speed 2.0 div mul add )
  24. Self CONST_PIXELCOORDY SetUnitAttribute ( <-cy <-angle sin <-Speed 2.0 div mul add )
  25.  
  26. <-angle <-desiredAngle ShortestAngle ->angleDiff
  27. <-angleDiff abs <-Rotation lt if
  28. #move straight
  29. <-desiredAngle ->angle
  30. else
  31. #check for blind spot + save sign
  32. <-angleDiff 0 gt if
  33. #turning left
  34. <-angle PI 2 div add ->blindAngle
  35. 1 ->sign
  36. else
  37. #turning right
  38. <-angle PI 2 div sub ->blindAngle
  39. -1 ->sign
  40. endif
  41.  
  42. # blind circle position
  43. <-cx <-blindAngle cos <-R mul add ->bx
  44. <-cy <-blindAngle sin <-R mul add ->by
  45.  
  46. #is the target in the blind spot?
  47. <-bx <-by <-tx <-ty Distance <-R lt if
  48. # must reverse the turning direction -> change sign
  49. "IN CIRCLE" Trace
  50. <-sign -1 mul ->sign
  51. endif
  52.  
  53. #finally, update angle
  54. <-angle <-Rotation <-sign mul add ->angle
  55. endif
  56.  
  57. CurrentPixelCoords ->cy ->cx
  58. # do first half of the movement AFTER the angle is adjusted
  59. Self CONST_PIXELCOORDX SetUnitAttribute ( <-cx <-angle cos <-Speed 2.0 div mul add )
  60. Self CONST_PIXELCOORDY SetUnitAttribute ( <-cy <-angle sin <-Speed 2.0 div mul add )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement