diff --git a/GlobalMethods.h b/GlobalMethods.h index bf83b1f..6993669 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -1986,6 +1986,7 @@ namespace LuaGlobalFunctions uint32 price = Eluna::CHECKVAL(L, 4, 0); uint32 pathId = Eluna::CHECKVAL(L, 5, 0); lua_pushvalue(L, 1); + // Stack: {nodes}, mountA, mountH, price, pathid, {nodes} std::list nodes; @@ -1993,53 +1994,57 @@ namespace LuaGlobalFunctions int end = start; Eluna::Push(L); + // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, nil while (lua_next(L, -2) != 0) { + // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, key, value luaL_checktype(L, -1, LUA_TTABLE); Eluna::Push(L); + // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, key, value, nil while (lua_next(L, -2) != 0) { + // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, key, value, key2, value2 lua_insert(L, end++); + // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, value2, key, value, key2 } + // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, value2, key, value if (start == end) continue; if (end - start < 4) // no mandatory args, dont add - { - while (end != start) - if (!lua_isnone(L, --end)) - lua_remove(L, end); - continue; - } + return luaL_argerror(L, 1, "all waypoints do not have mandatory arguments"); while (end - start < 8) // fill optional args with 0 { Eluna::Push(L, 0); lua_insert(L, end++); + // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, node, key, value } - TaxiPathNodeEntry* entry = new TaxiPathNodeEntry(); + TaxiPathNodeEntry entry; // mandatory - entry->mapid = Eluna::CHECKVAL(L, start); - entry->x = Eluna::CHECKVAL(L, start + 1); - entry->y = Eluna::CHECKVAL(L, start + 2); - entry->z = Eluna::CHECKVAL(L, start + 3); + entry.mapid = Eluna::CHECKVAL(L, start); + entry.x = Eluna::CHECKVAL(L, start + 1); + entry.y = Eluna::CHECKVAL(L, start + 2); + entry.z = Eluna::CHECKVAL(L, start + 3); // optional - entry->actionFlag = Eluna::CHECKVAL(L, start + 4, 0); - entry->delay = Eluna::CHECKVAL(L, start + 5, 0); + entry.actionFlag = Eluna::CHECKVAL(L, start + 4, 0); + entry.delay = Eluna::CHECKVAL(L, start + 5, 0); - nodes.push_back(*entry); + nodes.push_back(entry); while (end != start) // remove args if (!lua_isnone(L, --end)) lua_remove(L, end); + // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, key, value lua_pop(L, 1); + // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, key } + // Stack: {nodes}, mountA, mountH, price, pathid, {nodes} + lua_pop(L, 1); + // Stack: {nodes}, mountA, mountH, price, pathid if (nodes.size() < 2) - { - Eluna::Push(L); return 1; - } if (!pathId) pathId = sTaxiPathNodesByPath.size(); if (sTaxiPathNodesByPath.size() <= pathId) @@ -2049,9 +2054,9 @@ namespace LuaGlobalFunctions static uint32 nodeId = 500; uint32 startNode = nodeId; uint32 index = 0; - for (std::list::const_iterator it = nodes.begin(); it != nodes.end(); ++it) + for (std::list::iterator it = nodes.begin(); it != nodes.end(); ++it) { - TaxiPathNodeEntry entry = *it; + TaxiPathNodeEntry& entry = *it; entry.path = pathId; TaxiNodesEntry* nodeEntry = new TaxiNodesEntry(); nodeEntry->ID = index; @@ -2063,14 +2068,17 @@ namespace LuaGlobalFunctions nodeEntry->z = entry.z; sTaxiNodesStore.SetEntry(nodeId, nodeEntry); entry.index = nodeId++; - sTaxiPathNodesByPath[pathId].set(index++, TaxiPathNodePtr(new TaxiPathNodeEntry(entry))); + sTaxiPathNodesByPath[pathId].set(index++, new TaxiPathNodeEntry(entry)); } if (startNode >= nodeId) - { - Eluna::Push(L); return 1; - } sTaxiPathSetBySource[startNode][nodeId - 1] = TaxiPathBySourceAndDestination(pathId, price); + TaxiPathEntry* pathEntry = new TaxiPathEntry(); + pathEntry->from = startNode; + pathEntry->to = nodeId - 1; + pathEntry->ID = pathId; + pathEntry->price = price; + sTaxiPathStore.SetEntry(pathId, pathEntry); Eluna::Push(L, pathId); return 1; } diff --git a/LuaEngine.cpp b/LuaEngine.cpp index 7a7ddff..c9cefcc 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -656,11 +656,11 @@ void Eluna::Push(lua_State* luastate, const char* str) } void Eluna::Push(lua_State* luastate, Pet const* pet) { - Push(luastate, pet->ToCreature()); + Push(luastate, pet); } void Eluna::Push(lua_State* luastate, TempSummon const* summon) { - Push(luastate, summon->ToCreature()); + Push(luastate, summon); } void Eluna::Push(lua_State* luastate, Unit const* unit) { diff --git a/PlayerMethods.h b/PlayerMethods.h index 8cd3d65..97b8d65 100644 --- a/PlayerMethods.h +++ b/PlayerMethods.h @@ -3027,19 +3027,7 @@ namespace LuaPlayer { uint32 pathId = Eluna::CHECKVAL(L, 2); - if (pathId >= sTaxiPathNodesByPath.size()) - return 0; - - TaxiPathNodeList const& path = sTaxiPathNodesByPath[pathId]; - if (path.size() < 2) - return 0; - - std::vector nodes; - nodes.resize(2); - nodes[0] = path[0].index; - nodes[1] = path[path.size() - 1].index; - - player->ActivateTaxiPathTo(nodes); + player->ActivateTaxiPathTo(pathId); return 0; }