diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/Makefile.am | 33 | ||||
-rw-r--r-- | src/account.h | 5 | ||||
-rw-r--r-- | src/being.h | 205 | ||||
-rw-r--r-- | src/gameclient.h | 2 | ||||
-rw-r--r-- | src/player.cpp (renamed from src/being.cpp) | 3 | ||||
-rw-r--r-- | src/player.h | 230 | ||||
-rw-r--r-- | src/point.h | 2 | ||||
-rw-r--r-- | src/state.h | 2 |
9 files changed, 259 insertions, 227 deletions
@@ -4,6 +4,10 @@ src/dalstorage.cpp, src/object.h, src/state.cpp, src/gamehandler.cpp, src/map.h, src/Makefile.am: Introduced Point class to replace the confusing and clumsy usage of std::pair. + * src/point.h, src/player.cpp, src/account.h, src/being.cpp, + src/player.h, src/gameclient.h, src/state.h, src/Makefile.am, + src/being.h: Put Player class in its own module instead of defining it + together with Being. 2006-08-27 Guillaume Melquiond <guillaume.melquiond@gmail.com> diff --git a/src/Makefile.am b/src/Makefile.am index d543290b..b981b40f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,8 +12,9 @@ tmwclient_SOURCES = client.cpp \ messagein.cpp tmwserv_SOURCES = main.cpp \ - configuration.h \ - configuration.cpp \ + being.h \ + account.h \ + account.cpp \ accountclient.h \ accountclient.cpp \ accounthandler.h \ @@ -24,18 +25,17 @@ tmwserv_SOURCES = main.cpp \ chatchannel.cpp \ chatchannelmanager.h \ chatchannelmanager.cpp \ + configuration.h \ + configuration.cpp \ connectionhandler.h \ connectionhandler.cpp \ + debug.h \ + debug.cpp \ + defines.h \ gameclient.h \ gameclient.cpp \ gamehandler.h \ gamehandler.cpp \ - properties.h \ - state.h \ - state.cpp \ - debug.h \ - debug.cpp \ - defines.h \ items.h \ items.cpp \ map.cpp \ @@ -50,19 +50,20 @@ tmwserv_SOURCES = main.cpp \ messageout.cpp \ netcomputer.h \ netcomputer.cpp \ + object.h \ + object.cpp \ + player.h \ + player.cpp \ point.h \ - skill.h \ - skill.cpp \ + properties.h \ resourcemanager.cpp \ resourcemanager.h \ + skill.h \ + skill.cpp \ + state.h \ + state.cpp \ storage.h \ storage.cpp \ - account.h \ - account.cpp \ - object.h \ - object.cpp \ - being.h \ - being.cpp \ dalstorage.h \ dalstorage.cpp \ dal/dalexcept.h \ diff --git a/src/account.h b/src/account.h index 2ae61baa..e9d9e408 100644 --- a/src/account.h +++ b/src/account.h @@ -20,15 +20,12 @@ * $Id$ */ - #ifndef _TMWSERV_ACCOUNT_H_ #define _TMWSERV_ACCOUNT_H_ - #include <string> -#include "being.h" - +#include "player.h" /** * Notes: diff --git a/src/being.h b/src/being.h index 6e2fbda6..6ca8f293 100644 --- a/src/being.h +++ b/src/being.h @@ -20,11 +20,9 @@ * $Id$ */ - #ifndef _TMWSERV_BEING_H_ #define _TMWSERV_BEING_H_ - #include <string> #include <vector> @@ -32,11 +30,8 @@ #include "object.h" #include "utils/countedptr.h" -/** Maximum number of equipped slots */ -const unsigned int MAX_EQUIP_SLOTS = 5; - /** - * Raw statistics of a Player + * Raw statistics of a Player. */ enum { STAT_STR = 0, @@ -49,7 +44,7 @@ enum { }; /** - * Structure types for the raw statistics of a Player + * Structure types for the raw statistics of a Player. */ struct RawStatistics { @@ -57,7 +52,7 @@ struct RawStatistics }; /** - * Computed statistics of a Being + * Computed statistics of a Being. */ enum { STAT_HEA = 0, @@ -116,190 +111,6 @@ class Being : public MovingObject Statistics mStats; /**< stats modifiers or computed stats */ }; -class Player : public Being -{ - public: - - Player(std::string const &name, int id = -1) - : Being(OBJECT_PLAYER, id), - mName(name) - {} - - /** - * Gets the name. - * - * @return the name. - */ - std::string const &getName() const - { return mName; } - - /** - * Sets the hair style. - * - * @param style the new hair style. - */ - void setHairStyle(unsigned char style) - { mHairStyle = style; } - - /** - * Gets the hair style. - * - * @return the hair style value. - */ - unsigned char getHairStyle() const - { return mHairStyle; } - - /** - * Sets the hair color. - * - * @param color the new hair color. - */ - void setHairColor(unsigned char color) - { mHairColor = color; } - - /** - * Gets the hair color. - * - * @return the hair color value. - */ - unsigned char getHairColor() const - { return mHairColor; } - - /** - * Sets the gender. - * - * @param gender the new gender. - */ - void setGender(Gender gender) - { mGender = gender; } - - /** - * Gets the gender. - * - * @return the gender. - */ - Gender getGender() const - { return mGender; } - - /** - * Sets the level. - * - * @param level the new level. - */ - void setLevel(unsigned char level) - { mLevel = level; } - - /** - * Gets the level. - * - * @return the level. - */ - unsigned char getLevel() const - { return mLevel; } - - /** - * Sets the money. - * - * @param amount the new amount. - */ - void setMoney(unsigned int amount) - { mMoney = amount; } - - /** - * Gets the amount of money. - * - * @return the amount of money. - */ - unsigned int getMoney() const - { return mMoney; } - - /** - * Sets a raw statistic. - * - * @param numStat the statistic number. - * @param value the new value. - */ - void setRawStat(int numStat, unsigned short value) - { mRawStats.stats[numStat] = value; } - - /** - * Gets a raw statistic. - * - * @param numStat the statistic number. - * @return the statistic value. - */ - unsigned short getRawStat(int numStat) - { return mRawStats.stats[numStat]; } - - /** - * Updates the internal status. - */ - void update(); - - /** - * Sets inventory. - */ - void - setInventory(const std::vector<unsigned int> &inven); - - /** - * Adds item with ID to inventory. - * - * @return Item add success/failure - */ - bool - addInventory(unsigned int itemId); - - /** - * Removes item with ID from inventory. - * - * @return Item delete success/failure - */ - bool - delInventory(unsigned int itemId); - - /** - * Checks if character has an item. - * - * @return true if being has item, false otherwise - */ - bool - hasItem(unsigned int itemId); - - /** - * Equips item with ID in equipment slot. - * - * @return Equip success/failure - */ - bool - equip(unsigned int itemId, unsigned char slot); - - /** - * Un-equips item. - * - * @return Un-equip success/failure - */ - bool - unequip(unsigned char slot); - - private: - Player(Player const &); - Player &operator=(Player const &); - - std::string mName; /**< name of the being */ - Gender mGender; /**< gender of the being */ - unsigned char mHairStyle; /**< Hair Style of the being */ - unsigned char mHairColor; /**< Hair Color of the being */ - unsigned char mLevel; /**< level of the being */ - unsigned int mMoney; /**< wealth of the being */ - RawStatistics mRawStats; /**< raw stats of the being */ - - std::vector<unsigned int> inventory; /**< Player inventory */ - - /** Equipped item ID's (from inventory) */ - unsigned int equipment[MAX_EQUIP_SLOTS]; -}; - /** * Type definition for a smart pointer to Being. */ @@ -310,14 +121,4 @@ typedef utils::CountedPtr<Being> BeingPtr; */ typedef std::vector<BeingPtr> Beings; -/** - * Type definition for a smart pointer to Player. - */ -typedef utils::CountedPtr<Player> PlayerPtr; - -/** - * Type definition for a list of Players. - */ -typedef std::vector<PlayerPtr> Players; - #endif // _TMWSERV_BEING_H_ diff --git a/src/gameclient.h b/src/gameclient.h index 67994b4e..7133a38d 100644 --- a/src/gameclient.h +++ b/src/gameclient.h @@ -26,7 +26,7 @@ #include "netcomputer.h" -#include "being.h" +#include "player.h" #include <enet/enet.h> diff --git a/src/being.cpp b/src/player.cpp index ae339ad8..cd793d96 100644 --- a/src/being.cpp +++ b/src/player.cpp @@ -20,8 +20,7 @@ * $Id$ */ - -#include "being.h" +#include "player.h" /** * Update the internal status. diff --git a/src/player.h b/src/player.h new file mode 100644 index 00000000..0dc8ae58 --- /dev/null +++ b/src/player.h @@ -0,0 +1,230 @@ +/* + * The Mana World Server + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or any later version. + * + * The Mana World is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with The Mana World; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMWSERV_PLAYER_H_ +#define _TMWSERV_PLAYER_H_ + +#include <string> +#include <vector> + +#include "being.h" +#include "defines.h" +#include "utils/countedptr.h" + +/** Maximum number of equipped slots */ +const unsigned int MAX_EQUIP_SLOTS = 5; + +class Player : public Being +{ + public: + + Player(std::string const &name, int id = -1) + : Being(OBJECT_PLAYER, id), + mName(name) + {} + + /** + * Gets the name. + * + * @return the name. + */ + std::string const &getName() const + { return mName; } + + /** + * Sets the hair style. + * + * @param style the new hair style. + */ + void setHairStyle(unsigned char style) + { mHairStyle = style; } + + /** + * Gets the hair style. + * + * @return the hair style value. + */ + unsigned char getHairStyle() const + { return mHairStyle; } + + /** + * Sets the hair color. + * + * @param color the new hair color. + */ + void setHairColor(unsigned char color) + { mHairColor = color; } + + /** + * Gets the hair color. + * + * @return the hair color value. + */ + unsigned char getHairColor() const + { return mHairColor; } + + /** + * Sets the gender. + * + * @param gender the new gender. + */ + void setGender(Gender gender) + { mGender = gender; } + + /** + * Gets the gender. + * + * @return the gender. + */ + Gender getGender() const + { return mGender; } + + /** + * Sets the level. + * + * @param level the new level. + */ + void setLevel(unsigned char level) + { mLevel = level; } + + /** + * Gets the level. + * + * @return the level. + */ + unsigned char getLevel() const + { return mLevel; } + + /** + * Sets the money. + * + * @param amount the new amount. + */ + void setMoney(unsigned int amount) + { mMoney = amount; } + + /** + * Gets the amount of money. + * + * @return the amount of money. + */ + unsigned int getMoney() const + { return mMoney; } + + /** + * Sets a raw statistic. + * + * @param numStat the statistic number. + * @param value the new value. + */ + void setRawStat(int numStat, unsigned short value) + { mRawStats.stats[numStat] = value; } + + /** + * Gets a raw statistic. + * + * @param numStat the statistic number. + * @return the statistic value. + */ + unsigned short getRawStat(int numStat) + { return mRawStats.stats[numStat]; } + + /** + * Updates the internal status. + */ + void update(); + + /** + * Sets inventory. + */ + void + setInventory(const std::vector<unsigned int> &inven); + + /** + * Adds item with ID to inventory. + * + * @return Item add success/failure + */ + bool + addInventory(unsigned int itemId); + + /** + * Removes item with ID from inventory. + * + * @return Item delete success/failure + */ + bool + delInventory(unsigned int itemId); + + /** + * Checks if character has an item. + * + * @return true if being has item, false otherwise + */ + bool + hasItem(unsigned int itemId); + + /** + * Equips item with ID in equipment slot. + * + * @return Equip success/failure + */ + bool + equip(unsigned int itemId, unsigned char slot); + + /** + * Un-equips item. + * + * @return Un-equip success/failure + */ + bool + unequip(unsigned char slot); + + private: + Player(Player const &); + Player &operator=(Player const &); + + std::string mName; /**< name of the being */ + Gender mGender; /**< gender of the being */ + unsigned char mHairStyle; /**< Hair Style of the being */ + unsigned char mHairColor; /**< Hair Color of the being */ + unsigned char mLevel; /**< level of the being */ + unsigned int mMoney; /**< wealth of the being */ + RawStatistics mRawStats; /**< raw stats of the being */ + + std::vector<unsigned int> inventory; /**< Player inventory */ + + /** Equipped item ID's (from inventory) */ + unsigned int equipment[MAX_EQUIP_SLOTS]; +}; + +/** + * Type definition for a smart pointer to Player. + */ +typedef utils::CountedPtr<Player> PlayerPtr; + +/** + * Type definition for a list of Players. + */ +typedef std::vector<PlayerPtr> Players; + +#endif // _TMWSERV_PLAYER_H_ diff --git a/src/point.h b/src/point.h index 2d6b337d..bc894cdd 100644 --- a/src/point.h +++ b/src/point.h @@ -43,7 +43,7 @@ class Point {} /** - * Check whether the given point is range of this point. This is + * Check whether the given point is within range of this point. This is * defined as lying within the distance of client awareness. */ bool inRangeOf(const Point &p) const diff --git a/src/state.h b/src/state.h index 5a114e20..955b37da 100644 --- a/src/state.h +++ b/src/state.h @@ -26,7 +26,7 @@ #include <map> -#include "being.h" +#include "player.h" class Map; |