Hey So I am working on my monger script, decided it was time to start diving into actual ship movement. I am looking for advice on how to effectively move the ship to a set of coordinates with little to no issues and no multiple commands, IE don't yell forward three times etc. This is what I have at the moment. Its a bit wonky at the end coordinates. Let me know what y'all think and if you know of a better way to go about this let me know i'm open to anything. I seem to always miss the target by 1 or 2 tiles and then the end mess happens.
Sub ShipGoToLocation
Set %GoalX #CHARPOSX + 10 ;change these values to set destination
Set %GoalY #CHARPOSY - 20 ; change these values to set destination
NavStart:
if #CHARPOSY > %GoalY
{
;;;
if #CHARPOSX = %GoalX
{
event Macro 3 0 Forward
while #CHARPOSY > %GoalY + 1
{
}
event Macro 3 0 stop
GOTO NavStart
}
;;;
if #CHARPOSX > %GoalX
{
event Macro 3 0 forward left
while #CHARPOSX > %GoalX +1 && #CHARPOSY > %GoalY + 1
{
}
event Macro 3 0 stop
GOTO NavStart
}
;;;
if #CHARPOSX < %GoalX
{
event Macro 3 0 forward right
while #CHARPOSX < %GoalX +1 && #CHARPOSY > %GoalY + 1
{
}
event Macro 3 0 stop
GOTO NavStart
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if #CHARPOSY = %GoalY
{
if #CHARPOSX = %GoalX
{
event Macro 3 0 stop
halt
}
;;;
if #CHARPOSX > %GoalX
{
event Macro 3 0 left
while #CHARPOSX > %GoalX +1 && #CHARPOSY = %GoalY
{
}
event Macro 3 0 stop
GOTO NavStart
}
;;;
if #CHARPOSX < %GoalX
{
event Macro 3 0 right
while #CHARPOSX < %GoalX && #CHARPOSY = %GoalY
{
}
event Macro 3 0 stop
GOTO NavStart
}
}
if #CHARPOSY < %GoalY
{
if #CHARPOSX = %GoalX
{
event Macro 3 0 back
while #CHARPOSX < %GoalX && #CHARPOSY < %GoalY
{
}
event Macro 3 0 stop
GOTO NavStart
}
if #CHARPOSX > %GoalX
{
event Macro 3 0 back left
while #CHARPOSX > %GoalX && #CHARPOSY < %GoalY
{
}
event Macro 3 0 stop
GOTO NavStart
}
if #CHARPOSX < %GoalX
{
event Macro 3 0 forward right
while #CHARPOSX < %GoalX && #CHARPOSY < %GoalY
{
}
event Macro 3 0 stop
GOTO NavStart
}
}
halt