mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-10-11 17:01:22 +00:00
Update JPS.h & fix typos in incremental pathfinding Lua API that prevented things from ever working
This commit is contained in:
parent
361915947b
commit
a88ca0a90d
3 changed files with 208 additions and 51 deletions
|
@ -217,11 +217,10 @@ void PathFinding::beginFindPath(PathFinding::State *state, const Vector& start,
|
|||
|
||||
bool PathFinding::updateFindPath(PathFinding::State *state, int limit)
|
||||
{
|
||||
int oldres = state->result;
|
||||
if(oldres == JPS::NEED_MORE_STEPS)
|
||||
if(state->result == JPS::NEED_MORE_STEPS)
|
||||
{
|
||||
state->result = state->searcher.findPathStep(limit);
|
||||
return oldres != state->result;
|
||||
return state->result != JPS::NEED_MORE_STEPS;
|
||||
}
|
||||
return true; // done
|
||||
}
|
||||
|
@ -229,7 +228,7 @@ bool PathFinding::updateFindPath(PathFinding::State *state, int limit)
|
|||
bool PathFinding::finishFindPath(PathFinding::State *state, VectorPath& path, unsigned step /* = 0 */)
|
||||
{
|
||||
if(state->result != JPS::FOUND_PATH)
|
||||
return false;
|
||||
return state->result == JPS::EMPTY_PATH;
|
||||
|
||||
JPS::PathVector rawpath;
|
||||
state->searcher.findPathFinish(rawpath, step);
|
||||
|
|
|
@ -8996,9 +8996,9 @@ luaFunc(createFindPath)
|
|||
luaFunc(findPathBegin)
|
||||
{
|
||||
PathFinding::State *state = *(PathFinding::State**)luaL_checkudata(L, 1, "pathfinder");
|
||||
Vector start(lua_tonumber(L, 1), lua_tonumber(L, 2));
|
||||
Vector end(lua_tonumber(L, 3), lua_tonumber(L, 4));
|
||||
ObsType obs = ObsType(lua_tointeger(L, 8));
|
||||
Vector start(lua_tonumber(L, 2), lua_tonumber(L, 3));
|
||||
Vector end(lua_tonumber(L, 4), lua_tonumber(L, 5));
|
||||
ObsType obs = ObsType(lua_tointeger(L, 6));
|
||||
PathFinding::beginFindPath(state, start, end, obs);
|
||||
luaReturnNil();
|
||||
}
|
||||
|
@ -9015,12 +9015,12 @@ luaFunc(findPathFinish)
|
|||
{
|
||||
PathFinding::State *state = *(PathFinding::State**)luaL_checkudata(L, 1, "pathfinder");
|
||||
VectorPath path;
|
||||
bool found = PathFinding::finishFindPath(state, path);
|
||||
bool found = PathFinding::finishFindPath(state, path, lua_tointeger(L, 2));
|
||||
if(!found)
|
||||
luaReturnBool(false);
|
||||
|
||||
lua_pushinteger(L, (int)path.getNumPathNodes());
|
||||
_fillPathfindTables(L, path, 2, 3);
|
||||
_fillPathfindTables(L, path, 3, 4);
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
@ -9041,20 +9041,38 @@ luaFunc(castLine)
|
|||
int tiletype = lua_tointeger(L, 5);
|
||||
if(!tiletype)
|
||||
tiletype = OT_BLOCKING;
|
||||
bool invert = getBool(L, 6);
|
||||
Vector step = end - v;
|
||||
int steps = step.getLength2D() / TILE_SIZE;
|
||||
step.setLength2D(TILE_SIZE);
|
||||
|
||||
for(int i = 0; i < steps; ++i)
|
||||
if(!invert)
|
||||
{
|
||||
if(dsq->game->getGridRaw(TileVector(v)) & tiletype)
|
||||
for(int i = 0; i < steps; ++i)
|
||||
{
|
||||
lua_pushinteger(L, dsq->game->getGrid(TileVector(v)));
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 3;
|
||||
if(dsq->game->getGridRaw(TileVector(v)) & tiletype)
|
||||
{
|
||||
lua_pushinteger(L, dsq->game->getGrid(TileVector(v)));
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 3;
|
||||
}
|
||||
v += step;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < steps; ++i)
|
||||
{
|
||||
if(!(dsq->game->getGridRaw(TileVector(v)) & tiletype))
|
||||
{
|
||||
lua_pushinteger(L, dsq->game->getGrid(TileVector(v)));
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 3;
|
||||
}
|
||||
v += step;
|
||||
}
|
||||
v += step;
|
||||
}
|
||||
|
||||
lua_pushboolean(L, false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue