diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-02-12 18:04:27 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-02-13 10:18:06 +0100 |
commit | 91ab54b6b638c9e803e484b5252db819ad3f5872 (patch) | |
tree | dab56b82c6fbae9f5dc15135746728b314055e3b | |
parent | 787a8f1e72a7640eb4c356e692fe763ac185f159 (diff) | |
download | mana-91ab54b6b638c9e803e484b5252db819ad3f5872.tar.gz mana-91ab54b6b638c9e803e484b5252db819ad3f5872.tar.bz2 mana-91ab54b6b638c9e803e484b5252db819ad3f5872.tar.xz mana-91ab54b6b638c9e803e484b5252db819ad3f5872.zip |
TMWA: Reduce magic numbers when converting direction
-rw-r--r-- | src/net/tmwa/messagein.cpp | 43 | ||||
-rw-r--r-- | src/net/tmwa/protocol.h | 14 |
2 files changed, 28 insertions, 29 deletions
diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index 7c142619..c0db0fca 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -21,6 +21,9 @@ #include "net/tmwa/messagein.h" +#include "being.h" +#include "net/tmwa/protocol.h" + #include <SDL_endian.h> #define MAKEWORD(low,high) \ @@ -88,38 +91,20 @@ void MessageIn::readCoordinates(uint16_t &x, uint16_t &y, uint8_t &direction) direction = data[2] & 0x000f; // Translate from tmwAthena format - switch (direction) + switch (static_cast<DIR>(direction)) { - case 0: - direction = 1; - break; - case 1: - direction = 3; - break; - case 2: - direction = 2; - break; - case 3: - direction = 6; - break; - case 4: - direction = 4; - break; - case 5: - direction = 12; - break; - case 6: - direction = 8; - break; - case 7: - direction = 9; - break; - case 8: - direction = 8; - break; + case DIR::S: direction = Being::DOWN; break; + case DIR::SW: direction = Being::DOWN | Being::LEFT; break; + case DIR::W: direction = Being::LEFT; break; + case DIR::NW: direction = Being::UP | Being::LEFT; break; + case DIR::N: direction = Being::UP; break; + case DIR::NE: direction = Being::UP | Being::RIGHT; break; + case DIR::E: direction = Being::RIGHT; break; + case DIR::SE: direction = Being::DOWN | Being::RIGHT; break; default: // OOPSIE! Impossible or unknown direction = 0; + break; } } mPos += 3; @@ -162,7 +147,7 @@ std::string MessageIn::readString(int length) if (length < 0 || mPos + length > mLength) { mPos = mLength + 1; - return ""; + return std::string(); } // Read the string diff --git a/src/net/tmwa/protocol.h b/src/net/tmwa/protocol.h index d00a5f4f..532ac90e 100644 --- a/src/net/tmwa/protocol.h +++ b/src/net/tmwa/protocol.h @@ -79,6 +79,20 @@ enum class LOOK : uint8_t MISC2 = 13, }; +enum class DIR : uint8_t +{ + S = 0, + SW = 1, + W = 2, + NW = 3, + N = 4, + NE = 5, + E = 6, + SE = 7, + + COUNT, +}; + enum NpcCommand { NPC_REQUEST_LANG = 0, |