Added 2 global functions for Position & g_map.getTiles().
This commit is contained in:
parent
f23e70ff08
commit
0ad45d6826
|
@ -51,6 +51,7 @@ class House;
|
|||
class Town;
|
||||
class CreatureType;
|
||||
class Spawn;
|
||||
class TileBlock;
|
||||
|
||||
typedef stdext::shared_object_ptr<MapView> MapViewPtr;
|
||||
typedef stdext::shared_object_ptr<LightView> LightViewPtr;
|
||||
|
@ -80,6 +81,7 @@ typedef std::vector<ItemTypePtr> ItemTypeList;
|
|||
typedef std::list<HousePtr> HouseList;
|
||||
typedef std::list<TownPtr> TownList;
|
||||
typedef std::list<ItemPtr> ItemList;
|
||||
typedef std::list<TilePtr> TileList;
|
||||
typedef std::vector<ItemPtr> ItemVector;
|
||||
typedef std::unordered_map<Position, TilePtr, PositionHasher> TileMap;
|
||||
typedef std::unordered_map<Position, CreatureTypePtr, PositionHasher> CreatureMap;
|
||||
|
|
|
@ -83,7 +83,7 @@ void Client::registerLuaFunctions()
|
|||
g_lua.bindSingletonFunction("g_houses", "removeHouse", &HouseManager::removeHouse, &g_houses);
|
||||
g_lua.bindSingletonFunction("g_houses", "getHouseList", &HouseManager::getHouseList, &g_houses);
|
||||
g_lua.bindSingletonFunction("g_houses", "filterHouses", &HouseManager::filterHouses, &g_houses);
|
||||
g_lua.bindSingletonFunction("g_houses", "sort", &HouseManager::sort, &g_houses);
|
||||
g_lua.bindSingletonFunction("g_houses", "sort", &HouseManager::sort, &g_houses);
|
||||
|
||||
g_lua.registerSingletonClass("g_towns");
|
||||
g_lua.bindSingletonFunction("g_towns", "getTown", &TownManager::getTown, &g_towns);
|
||||
|
@ -115,6 +115,7 @@ void Client::registerLuaFunctions()
|
|||
g_lua.bindSingletonFunction("g_map", "cleanTile", &Map::cleanTile, &g_map);
|
||||
g_lua.bindSingletonFunction("g_map", "cleanTexts", &Map::cleanTexts, &g_map);
|
||||
g_lua.bindSingletonFunction("g_map", "getTile", &Map::getTile, &g_map);
|
||||
g_lua.bindSingletonFunction("g_map", "getTiles", &Map::getTiles, &g_map);
|
||||
g_lua.bindSingletonFunction("g_map", "setCentralPosition", &Map::setCentralPosition, &g_map);
|
||||
g_lua.bindSingletonFunction("g_map", "getCentralPosition", &Map::getCentralPosition, &g_map);
|
||||
g_lua.bindSingletonFunction("g_map", "getCreatureById", &Map::getCreatureById, &g_map);
|
||||
|
@ -307,6 +308,8 @@ void Client::registerLuaFunctions()
|
|||
g_lua.bindSingletonFunction("g_shaders", "getShader", &ShaderManager::getShader, &g_shaders);
|
||||
|
||||
g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor);
|
||||
g_lua.bindGlobalFunction("getAngleFromPos", Position::getAngleFromPositions);
|
||||
g_lua.bindGlobalFunction("getDirectionFromPos", Position::getDirectionFromPositions);
|
||||
|
||||
g_lua.registerClass<ProtocolGame, Protocol>();
|
||||
g_lua.bindClassStaticFunction<ProtocolGame>("create", []{ return ProtocolGamePtr(new ProtocolGame); });
|
||||
|
@ -651,6 +654,7 @@ void Client::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<Tile>("getCreatures", &Tile::getCreatures);
|
||||
g_lua.bindClassMemberFunction<Tile>("getGround", &Tile::getGround);
|
||||
g_lua.bindClassMemberFunction<Tile>("isWalkable", &Tile::isWalkable);
|
||||
g_lua.bindClassMemberFunction<Tile>("isHouseTile", &Tile::isHouseTile);
|
||||
g_lua.bindClassMemberFunction<Tile>("isFullGround", &Tile::isFullGround);
|
||||
g_lua.bindClassMemberFunction<Tile>("isFullyOpaque", &Tile::isFullyOpaque);
|
||||
g_lua.bindClassMemberFunction<Tile>("isLookPossible", &Tile::isLookPossible);
|
||||
|
|
|
@ -318,6 +318,36 @@ const TilePtr& Map::getTile(const Position& pos)
|
|||
return m_nulltile;
|
||||
}
|
||||
|
||||
const TileList Map::getTiles(int floor/* = -1*/)
|
||||
{
|
||||
TileList tiles;
|
||||
if(floor > Otc::MAX_Z) {
|
||||
return tiles;
|
||||
}
|
||||
else if(floor < 0) {
|
||||
// Search all floors
|
||||
for(uint8_t z = 0; z <= Otc::MAX_Z; ++z) {
|
||||
for(const auto& pair : m_tileBlocks[z]) {
|
||||
const TileBlock& block = pair.second;
|
||||
for(const TilePtr& tile : block.getTiles()) {
|
||||
if(tile != nullptr)
|
||||
tiles.push_back(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(const auto& pair : m_tileBlocks[floor]) {
|
||||
const TileBlock& block = pair.second;
|
||||
for(const TilePtr& tile : block.getTiles()) {
|
||||
if(tile != nullptr)
|
||||
tiles.push_back(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tiles;
|
||||
}
|
||||
|
||||
void Map::cleanTile(const Position& pos)
|
||||
{
|
||||
if(!pos.isMapPosition())
|
||||
|
|
|
@ -186,6 +186,7 @@ public:
|
|||
const TilePtr& createTileEx(const Position& pos, const Items&... items);
|
||||
const TilePtr& getOrCreateTile(const Position& pos);
|
||||
const TilePtr& getTile(const Position& pos);
|
||||
const TileList getTiles(int floor = -1);
|
||||
void cleanTile(const Position& pos);
|
||||
|
||||
// tile zone related
|
||||
|
|
|
@ -467,7 +467,6 @@ void MapView::updateGeometry(const Size& visibleDimension, const Size& optimized
|
|||
}
|
||||
*/
|
||||
|
||||
|
||||
m_viewMode = viewMode;
|
||||
m_visibleDimension = visibleDimension;
|
||||
m_drawDimension = drawDimension;
|
||||
|
|
|
@ -110,20 +110,6 @@ public:
|
|||
return pos;
|
||||
}
|
||||
|
||||
double getAngleFromPosition(const Position& position) const {
|
||||
// Returns angle in radians from 0 to 2Pi. -1 means positions are equal.
|
||||
int dx = position.x - x;
|
||||
int dy = position.y - y;
|
||||
if(dx == 0 && dy == 0)
|
||||
return -1;
|
||||
|
||||
float angle = std::atan2(dy * -1, dx);
|
||||
if(angle < 0)
|
||||
angle += 2 * Fw::pi;
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
std::vector<Position> translatedToDirections(const std::vector<Otc::Direction>& dirs) const {
|
||||
Position lastPos = *this;
|
||||
std::vector<Position> positions;
|
||||
|
@ -143,8 +129,28 @@ public:
|
|||
return positions;
|
||||
}
|
||||
|
||||
Otc::Direction getDirectionFromPosition(const Position& position) const {
|
||||
float angle = getAngleFromPosition(position) * RAD_TO_DEC;
|
||||
static double getAngleFromPositions(const Position& fromPos, const Position& toPos) {
|
||||
// Returns angle in radians from 0 to 2Pi. -1 means positions are equal.
|
||||
int dx = toPos.x - fromPos.x;
|
||||
int dy = toPos.y - fromPos.y;
|
||||
if(dx == 0 && dy == 0)
|
||||
return -1;
|
||||
|
||||
float angle = std::atan2(dy * -1, dx);
|
||||
if(angle < 0)
|
||||
angle += 2 * Fw::pi;
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
double getAngleFromPosition(const Position& position) const {
|
||||
return getAngleFromPositions(*this, position);
|
||||
}
|
||||
|
||||
static Otc::Direction getDirectionFromPositions(const Position& fromPos,
|
||||
const Position& toPos)
|
||||
{
|
||||
float angle = getAngleFromPositions(fromPos, toPos) * RAD_TO_DEC;
|
||||
|
||||
if(angle >= 360 - 22.5 || angle < 0 + 22.5)
|
||||
return Otc::East;
|
||||
|
@ -166,6 +172,10 @@ public:
|
|||
return Otc::InvalidDirection;
|
||||
}
|
||||
|
||||
Otc::Direction getDirectionFromPosition(const Position& position) const {
|
||||
return getDirectionFromPositions(*this, position);
|
||||
}
|
||||
|
||||
bool isMapPosition() const { return (x >=0 && y >= 0 && z >= 0 && x < 65535 && y < 65535 && z <= Otc::MAX_Z); }
|
||||
bool isValid() const { return !(x == 65535 && y == 65535 && z == 255); }
|
||||
float distance(const Position& pos) const { return sqrt(pow((pos.x - x), 2) + pow((pos.y - y), 2)); }
|
||||
|
|
|
@ -120,7 +120,7 @@ public:
|
|||
|
||||
void setHouseId(uint32 hid) { m_houseId = hid; }
|
||||
uint32 getHouseId() { return m_houseId; }
|
||||
bool isHouseTile() const { return m_houseId != 0 && (m_flags & TILESTATE_HOUSE) == TILESTATE_HOUSE; }
|
||||
bool isHouseTile() { return m_houseId != 0 && (m_flags & TILESTATE_HOUSE) == TILESTATE_HOUSE; }
|
||||
|
||||
void select() { m_selected = true; }
|
||||
void unselect() { m_selected = false; }
|
||||
|
|
Loading…
Reference in New Issue