Only a idear and yes I've got many today ^^ ->My other Posts.
I wrote this today after I thought what is the bot so heavy calc after he lootet a mop
Hm the getNearestWaypoint functions is........hell.O.O (yeah I've got humor)
Because I saw you still have the same version in the new bot I might share some thouht.
2 Point are a propleme
1. The calc of this is too much it is not needed to be that much.
2. That may cause errors so that the bot run in part cycles or I saw some really crazy thing, maybe the bot will start with the wrong way Point
My solution (testing at the moment):
Code: Select all
function CWaypointList:getNearestWaypoint(_x, _z, _y)
local closest = 1;
--I'm assume one of them is close enough
local point0 = self.CurrentWaypoint - 1;
local point1 = self.CurrentWaypoint;
local point2 = self.CurrentWaypoint + 1;
local point3 = self.CurrentWaypoint + 2;
local distlist = {};
local distindex = 1;
local waypointlist = {};
if( point0 > 0)then
if(self.Waypoints[point0] ~=nil)then
local waypointA = self.Waypoints[point0];
distlist[distindex] = distance(_x, _z, _y, waypointA.X, waypointA.Z, waypointA.Y)
waypointlist[distindex] = point0;
distindex = distindex + 1;
end
end
if(self.Waypoints[point1] ~=nil)then
local waypointA = self.Waypoints[point1];
distlist[distindex] = distance(_x, _z, _y, waypointA.X, waypointA.Z, waypointA.Y)
waypointlist[distindex] = point1;
distindex = distindex + 1;
end
if(self.Waypoints[point2] ~=nil)then
local waypointA = self.Waypoints[point2];
distlist[distindex] = distance(_x, _z, _y, waypointA.X, waypointA.Z, waypointA.Y)
waypointlist[distindex] = point2;
distindex = distindex + 1;
end
if(self.Waypoints[point3] ~=nil)then
local waypointA = self.Waypoints[point3];
distlist[distindex] = distance(_x, _z, _y, waypointA.X, waypointA.Z, waypointA.Y)
waypointlist[distindex] = point3;
distindex = distindex + 1;
end
distindex = distindex - 1; -- true lenght of the table. Not needed
local assume = 1;
for i,v in pairs(distlist) do
if( v < distlist[assume])then
assume = i;
end
end
if(distlist[assume] < 600)then -- if greater then 600 we are pulled far away from everything searching the old way then
return waypointlist[assume];
else
for i,v in pairs(self.Waypoints) do
local oldClosestWp = self.Waypoints[closest];
if( distance(_x, _z, _y, v.X, v.Z, v.Y) < distance(_x, _z, _y, oldClosestWp.X, oldClosestWp.Z, oldClosestWp.Y) )then
closest = i;
end
end
return closest;
end
end
guessed 40%-60% faster now