diff --git a/src/definitions.h b/src/definitions.h index 44ad5c5..7001a5d 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -47,6 +47,7 @@ static constexpr auto AUTHENTICATOR_PERIOD = 30U; #pragma warning(disable : 4244) // 'argument' : conversion from 'type1' to 'type2', possible loss of data #pragma warning(disable : 4250) // 'class1' : inherits 'class2::member' via dominance #pragma warning(disable : 4267) // 'var' : conversion from 'size_t' to 'type', possible loss of data +#pragma warning(disable : 4275) // can be ignored in Visual C++ if you are deriving from a type in the C++ STL #pragma warning(disable : 4319) // '~': zero extending 'unsigned int' to 'lua_Number' of greater size #pragma warning(disable : 4351) // new behavior: elements of array will be default initialized #pragma warning(disable : 4458) // declaration hides class member diff --git a/src/iomapserialize.cpp b/src/iomapserialize.cpp index 1350fb5..bdcabc1 100644 --- a/src/iomapserialize.cpp +++ b/src/iomapserialize.cpp @@ -8,8 +8,6 @@ #include "bed.h" #include "game.h" -#include - extern Game g_game; void IOMapSerialize::loadHouseItems(Map* map) @@ -324,7 +322,8 @@ bool IOMapSerialize::saveHouseInfo() std::string listText; if (house->getAccessList(GUEST_LIST, listText) && !listText.empty()) { - if (!stmt.addRow(fmt::format("{:d}, {}, {:s}", house->getId(), GUEST_LIST, db.escapeString(listText)))) { + if (!stmt.addRow(fmt::format("{:d}, {}, {:s}", house->getId(), format_as(GUEST_LIST), + db.escapeString(listText)))) { return false; } @@ -332,7 +331,8 @@ bool IOMapSerialize::saveHouseInfo() } if (house->getAccessList(SUBOWNER_LIST, listText) && !listText.empty()) { - if (!stmt.addRow(fmt::format("{:d}, {}, {:s}", house->getId(), SUBOWNER_LIST, db.escapeString(listText)))) { + if (!stmt.addRow(fmt::format("{:d}, {}, {:s}", house->getId(), format_as(SUBOWNER_LIST), + db.escapeString(listText)))) { return false; } diff --git a/src/protocolgame.cpp b/src/protocolgame.cpp index 460fa64..56467fe 100644 --- a/src/protocolgame.cpp +++ b/src/protocolgame.cpp @@ -1740,16 +1740,16 @@ void ProtocolGame::sendCloseContainer(uint8_t cid) writeToOutputBuffer(msg); } -void ProtocolGame::sendCreatureTurn(const Creature* creature, uint32_t stackPos) +void ProtocolGame::sendCreatureTurn(const Creature* creature, uint32_t stackpos) { - if (stackPos == -1 || stackPos >= MAX_STACKPOS_THINGS || !canSee(creature)) { + if (stackpos >= MAX_STACKPOS_THINGS || !canSee(creature)) { return; } NetworkMessage msg; msg.addByte(0x6B); msg.addPosition(creature->getPosition()); - msg.addByte(static_cast(stackPos)); + msg.addByte(static_cast(stackpos)); msg.add(0x63); msg.add(creature->getID()); @@ -1944,7 +1944,7 @@ void ProtocolGame::sendMapDescription(const Position& pos) void ProtocolGame::sendAddTileItem(const Position& pos, uint32_t stackpos, const Item* item) { - if (!canSee(pos)) { + if (stackpos >= MAX_STACKPOS_THINGS || !canSee(pos)) { return; } @@ -1958,7 +1958,7 @@ void ProtocolGame::sendAddTileItem(const Position& pos, uint32_t stackpos, const void ProtocolGame::sendUpdateTileItem(const Position& pos, uint32_t stackpos, const Item* item) { - if (!canSee(pos)) { + if (stackpos >= MAX_STACKPOS_THINGS || !canSee(pos)) { return; } @@ -1983,7 +1983,7 @@ void ProtocolGame::sendRemoveTileThing(const Position& pos, uint32_t stackpos) void ProtocolGame::sendUpdateTileCreature(const Position& pos, uint32_t stackpos, const Creature* creature) { - if (stackpos == -1 || stackpos >= MAX_STACKPOS_THINGS || !canSee(pos)) { + if (stackpos >= MAX_STACKPOS_THINGS || !canSee(pos)) { return; } @@ -2037,7 +2037,7 @@ void ProtocolGame::sendAddCreature(const Creature* creature, const Position& pos } if (creature != player) { - if (stackpos != -1 && stackpos < MAX_STACKPOS_THINGS) { + if (stackpos < MAX_STACKPOS_THINGS) { NetworkMessage msg; msg.addByte(0x6A); msg.addPosition(pos); @@ -2103,9 +2103,7 @@ void ProtocolGame::sendMoveCreature(const Creature* creature, const Position& ne const Position& oldPos, int32_t oldStackPos, bool teleport) { if (creature == player) { - if (oldStackPos >= MAX_STACKPOS_THINGS) { - sendMapDescription(newPos); - } else if (teleport) { + if (teleport || oldStackPos >= MAX_STACKPOS_THINGS) { sendRemoveTileThing(oldPos, oldStackPos); sendMapDescription(newPos); } else { @@ -2480,7 +2478,7 @@ void ProtocolGame::AddCreatureLight(NetworkMessage& msg, const Creature* creatur // tile void ProtocolGame::RemoveTileThing(NetworkMessage& msg, const Position& pos, uint32_t stackpos) { - if (stackpos == -1 || stackpos >= MAX_STACKPOS_THINGS) { + if (stackpos >= MAX_STACKPOS_THINGS) { return; } diff --git a/src/protocolgame.h b/src/protocolgame.h index 65c86ac..a640648 100644 --- a/src/protocolgame.h +++ b/src/protocolgame.h @@ -149,7 +149,7 @@ class ProtocolGame final : public Protocol void sendCreatureHealth(const Creature* creature); void sendSkills(); void sendPing(); - void sendCreatureTurn(const Creature* creature, uint32_t stackPos); + void sendCreatureTurn(const Creature* creature, uint32_t stackpos); void sendCreatureSay(const Creature* creature, SpeakClasses type, std::string_view text, const Position* pos = nullptr); diff --git a/src/tile.cpp b/src/tile.cpp index 396b72b..d93b432 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -1204,24 +1204,18 @@ int32_t Tile::getStackposOfItem(const Player* player, const Item* item) const for (auto it = items->getBeginTopItem(), end = items->getEndTopItem(); it != end; ++it) { if (*it == item) { return n; - } else if (++n == MAX_STACKPOS_THINGS) { - return -1; } + ++n; } } else { n += items->getTopItemCount(); - if (n >= MAX_STACKPOS_THINGS) { - return -1; - } } } if (const CreatureVector* creatures = getCreatures()) { for (const Creature* creature : *creatures) { if (player->canSeeCreature(creature)) { - if (++n >= MAX_STACKPOS_THINGS) { - return -1; - } + ++n; } } } @@ -1230,9 +1224,8 @@ int32_t Tile::getStackposOfItem(const Player* player, const Item* item) const for (auto it = items->getBeginDownItem(), end = items->getEndDownItem(); it != end; ++it) { if (*it == item) { return n; - } else if (++n >= MAX_STACKPOS_THINGS) { - return -1; } + ++n; } } return -1; diff --git a/src/tools.h b/src/tools.h index b4ef8b3..96de1a7 100644 --- a/src/tools.h +++ b/src/tools.h @@ -76,4 +76,10 @@ int64_t OTSYS_TIME(); SpellGroup_t stringToSpellGroup(std::string_view value); +template +auto format_as(E e) +{ + return fmt::underlying(e); +} + #endif