diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | src/game-server/gamehandler.cpp | 2 | ||||
-rw-r--r-- | src/game-server/player.cpp | 4 | ||||
-rw-r--r-- | src/game-server/player.hpp | 29 |
4 files changed, 29 insertions, 8 deletions
@@ -23,6 +23,8 @@ items. Embeded handling of client message directly into the class. * src/defines.h, src/game-server/gamehandler.cpp: Added full update of Inventory on Player connection. + * src/game-server/gamehandler.cpp, src/game-server/player.hpp, + src/game-server/player.cpp: Generalized player state. 2007-01-04 Guillaume Melquiond <guillaume.melquiond@gmail.com> diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index b171a9b9..ae18e893 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -300,7 +300,7 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) LOG_DEBUG("Player " << computer.character->getPublicID() << " attacks", 0); computer.character->setDirection(message.readByte()); - computer.character->setAttacking(true); + computer.character->setAction(PLAYER_ATTACK); } break; default: diff --git a/src/game-server/player.cpp b/src/game-server/player.cpp index 2160cbb6..f687cba6 100644 --- a/src/game-server/player.cpp +++ b/src/game-server/player.cpp @@ -39,14 +39,14 @@ void Player::update() setStat(STAT_SPEED, getRawStat(STAT_DEXTERITY)); // attacking - if (mIsAttacking) + if (mAction == PLAYER_ATTACK) { // plausibility check of attack command if (mActionTime <= 0) { // request perform attack mActionTime = 1000; - mIsAttacking = false; + mAction = PLAYER_STAND; raiseUpdateFlags(ATTACK); } } diff --git a/src/game-server/player.hpp b/src/game-server/player.hpp index 5a0336a8..426738d7 100644 --- a/src/game-server/player.hpp +++ b/src/game-server/player.hpp @@ -31,6 +31,19 @@ class GameClient; +/** + * Actions for a player being. + */ +enum +{ + PLAYER_STAND = 0, + PLAYER_SIT, + PLAYER_ATTACK +}; + +/** + * Stores the data of a remote client. + */ class Player : public Being, public PlayerData { public: @@ -39,7 +52,7 @@ class Player : public Being, public PlayerData : Being(OBJECT_PLAYER, 65535), PlayerData(name, id), mClient(NULL), - mIsAttacking(false) + mAction(PLAYER_STAND) {} /** @@ -48,10 +61,16 @@ class Player : public Being, public PlayerData void update(); /** - * Set attacking state + * Sets next action. + **/ + void setAction(int s) + { mAction = s; } + + /** + * Gets next action. **/ - void setAttacking(bool isAttacking) - { mIsAttacking = isAttacking; } + int getAction() const + { return mAction; } /** * Gets client computer. @@ -70,7 +89,7 @@ class Player : public Being, public PlayerData Player &operator=(Player const &); GameClient *mClient; /**< Client computer. */ - bool mIsAttacking; /**< Attacking state. */ + unsigned char mAction; /**< Player state. */ }; #endif // _TMWSERV_PLAYER_H_ |