Page 1 of 1

Skipped waypoints

Posted: Fri Apr 09, 2010 12:07 am
by rock5
I've noticed, in some situations, that waypoints get skipped when they shouldn't.

I've now done a few tests to see under what conditions this happens. I've found 2.
  • 1st. When you use loadpaths you get a message saying something like "Point #3 is closer than Point #1 so we will start with point #3". The point 3 would be the closest but it goes to the next point instead, skipping 3 altogether.
  • 2nd. When using __WPL:setWaypointIndex(9), instead of going to waypoint 9 it goes to 10.
In both these situations you should always go to the closest waypoint first. I'm not sure why it skips them.

I know that in most waypoint files this wont cause too much trouble but there are situations where it can completely screw up the planned progression of your waypoint files.

I hope this can be fixed.

Re: Skipped waypoints

Posted: Fri Apr 09, 2010 4:26 am
by Administrator
Line 444 of rom/functions.lua has this:

Code: Select all

		__WPL:setWaypointIndex(__WPL:getNearestWaypoint(player.X, player.Z));
Change to:

Code: Select all

		local wpi = __WPL:getNearestWaypoint(player.X, player.Z);
		if( wpi == 1 ) then wpi = #__WPL.Waypoints else wpi = wpi - 1; end;
		__WPL:setWaypointIndex(wpi);
That should get you moving to the closest waypoint properly. Let me know if this works.

The CWaypoint:setWaypointIndex() is working as intended. It's not to set which waypoint you want to move to, but rather, which waypoint you are moving from.

Re: Skipped waypoints

Posted: Fri Apr 09, 2010 6:12 am
by rock5
Administrator wrote:Line 444 of rom/functions.lua has this:

Code: Select all

		__WPL:setWaypointIndex(__WPL:getNearestWaypoint(player.X, player.Z));
Change to:

Code: Select all

		local wpi = __WPL:getNearestWaypoint(player.X, player.Z);
		if( wpi == 1 ) then wpi = #__WPL.Waypoints else wpi = wpi - 1; end;
		__WPL:setWaypointIndex(wpi);
That should get you moving to the closest waypoint properly. Let me know if this works.
Seems to work, yes. Thank you.
Administrator wrote:The CWaypoint:setWaypointIndex() is working as intended. It's not to set which waypoint you want to move to, but rather, which waypoint you are moving from.
That's in contradiction of everything I've read and seems counter intuitive.
http://www.solarstrike.net/wiki/index.p ... _Functions states:

Code: Select all

__WPL:setWaypointIndex( number);
Set the waypoint # 'number' as next waypoint to reach
It is also accepted, I believe, that to set the nearest waypoint as the next waypoint manually you would use;

Code: Select all

__WPL:setWaypointIndex(__WPL:getNearestWaypoint(player.X, player.Z))
Correct?

According to you then, it should be;

Code: Select all

__WPL:setWaypointIndex(__WPL:getNearestWaypoint(player.X, player.Z)-1)
I'm sure that would confuse a lot of people.

What do you think?

Re: Skipped waypoints

Posted: Fri Apr 09, 2010 11:47 am
by Administrator
The bot will always try to move to __WPL:getNextWaypoint(), which is CurrentIndex + 1. To change that would require a lot of editing. It might not seem like a big deal, but remember that there are several times when it would need to return to the last reached waypoint rather than continue forward. It could cause a lot of unforseen bugs to change just CWaypointList:getNextWaypoint() and __WPL:setWaypointIndex().

Code: Select all

__WPL:setWaypointIndex(__WPL:getNearestWaypoint(player.X, player.Z)-1)
Generally, yes. But there's got to be a special case to loop around from 1 to the last waypoint in the list.

Re: Skipped waypoints

Posted: Fri Apr 09, 2010 12:26 pm
by rock5
Should I be using __WPL:getNextWaypoint() somehow?

Isn't the next waypoint stored anywhere? Isn't there anyway to just set the next waypoint instead of using the previous waypoint?

Maybe you could create a __WPL:setNextWaypointIndex function that works out and sets __WPL:setWaypointIndex() correctly?

That shouldn't be too difficult to do.

Re: Skipped waypoints

Posted: Fri Apr 09, 2010 7:42 pm
by Administrator
It's easier to just work around it so that we don't have to worry about fixing any additional bugs. A new function specifically for this could be added, though:

Code: Select all

function CWaypoint:setCurrentWaypoint(wpi)
      if( wpi == 1 ) then wpi = #__WPL.Waypoints else wpi = wpi - 1; end;
      __WPL:setWaypointIndex(wpi);
end

Re: Skipped waypoints

Posted: Fri Apr 09, 2010 8:49 pm
by rock5
Administrator wrote:It's easier to just work around it so that we don't have to worry about fixing any additional bugs. A new function specifically for this could be added, though:

Code: Select all

function CWaypoint:setCurrentWaypoint(wpi)
      if( wpi == 1 ) then wpi = #__WPL.Waypoints else wpi = wpi - 1; end;
      __WPL:setWaypointIndex(wpi);
end
Yes, that's exactly what I meant.

So you'd use it like this to take you to the nearest waypoint;

Code: Select all

__WPL:setCurrentWaypoint(__WPL:getNearestWaypoint(player.X, player.Z))
Right?

Are you going to implement it or do you want me to test it first?

If you want me to test it, where should I put it?

Re: Skipped waypoints

Posted: Fri Apr 09, 2010 9:31 pm
by Administrator
Test it. Just put it in rom/classes/waypointlist.lua outside of any other function.

Re: Skipped waypoints

Posted: Sun Apr 11, 2010 5:40 am
by rock5
rock5 wrote:
Administrator wrote:Line 444 of rom/functions.lua has this:

Code: Select all

		__WPL:setWaypointIndex(__WPL:getNearestWaypoint(player.X, player.Z));
Change to:

Code: Select all

		local wpi = __WPL:getNearestWaypoint(player.X, player.Z);
		if( wpi == 1 ) then wpi = #__WPL.Waypoints else wpi = wpi - 1; end;
		__WPL:setWaypointIndex(wpi);
That should get you moving to the closest waypoint properly. Let me know if this works.
Seems to work, yes. Thank you.
I spoke too soon. With this fix it correctly moves to the closest waypoint when using loadpaths but when you start the first waypoint file it moves to the closest point -1 first.

Re: Skipped waypoints

Posted: Mon Apr 12, 2010 6:37 am
by rock5
Revision 431 did not fix it.

As stated in the above post, when 1 waypoint file loads another waypoint file with the loadpaths command then it correctly moves to the closest point but when you load your first waypoint file it starts from the point before the closest point.

So in fixing loadpaths you broke loading the first file which was working correctly in revision 430.