diff options
37 files changed, 371 insertions, 380 deletions
@@ -1,3 +1,27 @@ +2007-01-03 Guillaume Melquiond <guillaume.melquiond@gmail.com> + + * src/debug.h, src/debug.cpp, src/Makefile.am: Removed obsolete debug + helpers. + * src/playerdata.hpp: Taken persistent data out of Player. + * src/being.h, src/being.cpp, src/object.h, src/object.cpp, src/map.h, + src/player.h, src/player.cpp, src/inventory.h, src/inventory.cpp, + src/map.cpp: Moved to src/game-server directory and changed header + extension to hpp. + * src/controller.h, src/item.h, src/game-server/mapcomposite.cpp, + src/game-server/mapreader.cpp, src/game-server/mapcomposite.hpp, + src/game-server/trigger.cpp, src/game-server/trigger.hpp, + src/game-server/accountconnection.cpp, src/game-server/gamehandler.hpp, + src/game-server/state.cpp, src/game-server/accountconnection.hpp, + src/game-server/itemmanager.cpp: Updated accordingly. + * src/account-server/account.hpp, src/account-server/serverhandler.cpp, + src/account-server/dalstorage.cpp, src/chat-server/chatchannel.hpp, + src/account-server/serverhandler.hpp, src/chat-server/chathandler.cpp, + src/account-server/accounthandler.cpp: Relied on PlayerData to remove + dependencies on Thing, Object, MovingObject, etc. + * src/defines.h: Fixed enumerations. + * src/games-server/gamehandler.cpp, src/game-server/player.cpp: + Commented in inventory code back. + 2007-01-02 Guillaume Melquiond <guillaume.melquiond@gmail.com> * tmwserv.cbp, tmwserv.dev, runserv.sh: Removed obsolete project files diff --git a/src/Makefile.am b/src/Makefile.am index 759927e5..255b25e7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,17 +6,10 @@ bin_PROGRAMS = tmwserv-account tmwserv-game tmwserv_account_SOURCES = \ account-server/main-account.cpp \ - being.h \ configuration.h \ configuration.cpp \ - debug.h \ - debug.cpp \ defines.h \ - inventory.h \ - item.h \ - object.h \ - player.h \ - player.cpp \ + playerdata.hpp \ point.h \ resourcemanager.h \ resourcemanager.cpp \ @@ -70,25 +63,14 @@ tmwserv_account_SOURCES = \ tmwserv_game_SOURCES = \ game-server/main-game.cpp \ - being.h \ - being.cpp \ configuration.h \ configuration.cpp \ controller.h \ controller.cpp \ - debug.h \ - debug.cpp \ defines.h \ - inventory.h \ - inventory.cpp \ item.h \ item.cpp \ - map.h \ - map.cpp \ - object.h \ - object.cpp \ - player.h \ - player.cpp \ + playerdata.hpp \ point.h \ resourcemanager.h \ resourcemanager.cpp \ @@ -96,16 +78,26 @@ tmwserv_game_SOURCES = \ skill.cpp \ game-server/accountconnection.hpp \ game-server/accountconnection.cpp \ + game-server/being.hpp \ + game-server/being.cpp \ game-server/gamehandler.hpp \ game-server/gamehandler.cpp \ + game-server/inventory.hpp \ + game-server/inventory.cpp \ game-server/itemmanager.hpp \ game-server/itemmanager.cpp \ + game-server/map.hpp \ + game-server/map.cpp \ game-server/mapcomposite.hpp \ game-server/mapcomposite.cpp \ game-server/mapmanager.hpp \ game-server/mapmanager.cpp \ game-server/mapreader.hpp \ game-server/mapreader.cpp \ + game-server/object.hpp \ + game-server/object.cpp \ + game-server/player.hpp \ + game-server/player.cpp \ game-server/state.hpp \ game-server/state.cpp \ game-server/testing.cpp \ diff --git a/src/account-server/account.hpp b/src/account-server/account.hpp index e9d9e408..a97158a7 100644 --- a/src/account-server/account.hpp +++ b/src/account-server/account.hpp @@ -25,7 +25,8 @@ #include <string> -#include "player.h" +#include "defines.h" +#include "playerdata.hpp" /** * Notes: diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 72a23818..004e1b8b 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -22,7 +22,6 @@ */ #include "configuration.h" -#include "debug.h" #include "point.h" #include "account-server/accounthandler.hpp" #include "account-server/account.hpp" @@ -182,7 +181,7 @@ AccountHandler::processMessage(NetComputer *comp, MessageIn &message) std::string address; short port; - if (!serverHandler->getGameServerFromMap(chars[charNum]->getMapId(), address, port)) + if (!serverHandler->getGameServerFromMap(chars[charNum]->getMap(), address, port)) { result.writeByte(ERRMSG_FAILURE); LOG_ERROR("Character Selection: No game server for the map.", 0); @@ -194,11 +193,8 @@ AccountHandler::processMessage(NetComputer *comp, MessageIn &message) PlayerPtr selectedChar = computer.getCharacter(); result.writeByte(ERRMSG_OK); - selectedChar->setDestination(selectedChar->getPosition()); - selectedChar->setSpeed(150); // TODO - LOG_INFO(selectedChar->getName() - << " is trying to enter the servers.", 1); + << " is trying to enter the servers.", 1); std::string magic_token(32, ' '); for (int i = 0; i < 32; ++i) { @@ -552,9 +548,9 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, MessageIn &msg) { std::string name = msg.readString(); - char hairStyle = msg.readByte(); - char hairColor = msg.readByte(); - Gender gender = (Gender) msg.readByte(); + int hairStyle = msg.readByte(); + int hairColor = msg.readByte(); + int gender = msg.readByte(); MessageOut reply(APMSG_CHAR_CREATE_RESPONSE); @@ -572,17 +568,17 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, LOG_INFO(name << ": has got double quotes in it.", 1); reply.writeByte(ERRMSG_INVALID_ARGUMENT); } - else if ((hairStyle < 0) || (hairStyle > (signed) MAX_HAIRSTYLE_VALUE)) + else if (hairStyle < 0 || hairStyle > MAX_HAIRSTYLE_VALUE) { LOG_INFO(name << ": Character's hair Style is invalid.", 1); reply.writeByte(CREATE_INVALID_HAIRSTYLE); } - else if ((hairColor < 0) || (hairColor > (signed) MAX_HAIRCOLOR_VALUE)) + else if (hairColor < 0 || hairColor > MAX_HAIRCOLOR_VALUE) { LOG_INFO(name << ": Character's hair Color is invalid.", 1); reply.writeByte(CREATE_INVALID_HAIRCOLOR); } - else if ((gender < 0) || (gender > (signed) MAX_GENDER_VALUE)) + else if (gender < 0 || gender > MAX_GENDER_VALUE) { LOG_INFO(name << ": Character's gender is invalid.", 1); reply.writeByte(CREATE_INVALID_GENDER); @@ -665,7 +661,7 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, } else { - PlayerPtr newCharacter(new Player(name)); + PlayerPtr newCharacter(new PlayerData(name)); for (int i = 0; i < NB_RSTAT; ++i) newCharacter->setRawStat(i, rawStats.stats[i]); newCharacter->setMoney(0); @@ -673,10 +669,10 @@ AccountHandler::handleCharacterCreateMessage(AccountClient &computer, newCharacter->setGender(gender); newCharacter->setHairStyle(hairStyle); newCharacter->setHairColor(hairColor); - newCharacter->setMapId((int) config.getValue("defaultMap", 1)); + newCharacter->setMap((int) config.getValue("defaultMap", 1)); Point startingPos = { (int) config.getValue("startX", 0), (int) config.getValue("startY", 0) }; - newCharacter->setPosition(startingPos); + newCharacter->setPos(startingPos); computer.getAccount()->addCharacter(newCharacter); LOG_INFO("Character " << name << " was created for " diff --git a/src/account-server/dalstorage.cpp b/src/account-server/dalstorage.cpp index 2208a91e..ee9901fa 100644 --- a/src/account-server/dalstorage.cpp +++ b/src/account-server/dalstorage.cpp @@ -309,14 +309,14 @@ PlayerPtr DALStorage::getCharacter(int id) // a string to an unsigned short. string_to< unsigned short > toUshort; - Player *player = new Player(charInfo(0, 2), toUint(charInfo(0, 0))); - player->setGender((Gender)toUshort(charInfo(0, 3))); + PlayerData *player = new PlayerData(charInfo(0, 2), toUint(charInfo(0, 0))); + player->setGender(toUshort(charInfo(0, 3))); player->setHairStyle(toUshort(charInfo(0, 4))); player->setHairColor(toUshort(charInfo(0, 5))); player->setLevel(toUshort(charInfo(0, 6))); player->setMoney(toUint(charInfo(0, 7))); Point pos = { toUshort(charInfo(0, 8)), toUshort(charInfo(0, 9)) }; - player->setPosition(pos); + player->setPos(pos); for (int i = 0; i < NB_RSTAT; ++i) { player->setRawStat(i, toUshort(charInfo(0, 11 + i))); @@ -325,13 +325,13 @@ PlayerPtr DALStorage::getCharacter(int id) int mapId = toUint(charInfo(0, 10)); if (mapId > 0) { - player->setMapId(mapId); + player->setMap(mapId); } else { // Set player to default map and one of the default location // Default map is to be 1, as not found return value will be 0. - player->setMapId((int)config.getValue("defaultMap", 1)); + player->setMap((int)config.getValue("defaultMap", 1)); } PlayerPtr ptr(player); @@ -659,9 +659,9 @@ void DALStorage::flush(AccountPtr const &account) << (int)(*it)->getHairColor() << ", " << (int)(*it)->getLevel() << ", " << (*it)->getMoney() << ", " - << (*it)->getPosition().x << ", " - << (*it)->getPosition().y << ", " - << (*it)->getMapId() << ", " + << (*it)->getPos().x << ", " + << (*it)->getPos().y << ", " + << (*it)->getMap() << ", " << (*it)->getRawStat(STAT_STRENGTH) << ", " << (*it)->getRawStat(STAT_AGILITY) << ", " << (*it)->getRawStat(STAT_VITALITY) << ", " @@ -691,9 +691,9 @@ void DALStorage::flush(AccountPtr const &account) << " hair_color = " << (int)(*it)->getHairColor() << ", " << " level = " << (int)(*it)->getLevel() << ", " << " money = " << (*it)->getMoney() << ", " - << " x = " << (*it)->getPosition().x << ", " - << " y = " << (*it)->getPosition().y << ", " - << " map_id = " << (*it)->getMapId() << ", " + << " x = " << (*it)->getPos().x << ", " + << " y = " << (*it)->getPos().y << ", " + << " map_id = " << (*it)->getMap() << ", " << " str = " << (*it)->getRawStat(STAT_STRENGTH) << ", " << " agi = " << (*it)->getRawStat(STAT_AGILITY) << ", " << " vit = " << (*it)->getRawStat(STAT_VITALITY) << ", " diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index 3d3846a7..2a1af5ee 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -71,7 +71,7 @@ bool ServerHandler::getGameServerFromMap(unsigned mapId, std::string &address, s void ServerHandler::registerGameClient(std::string const &token, PlayerPtr ptr) { - unsigned mapId = ptr->getMapId(); + unsigned mapId = ptr->getMap(); MessageOut msg(AGMSG_PLAYER_ENTER); msg.writeLong(ptr->getDatabaseID()); msg.writeString(ptr->getName()); @@ -82,7 +82,7 @@ void ServerHandler::registerGameClient(std::string const &token, PlayerPtr ptr) msg.writeShort(ptr->getMoney()); for (int j = 0; j < NB_RSTAT; ++j) msg.writeShort(ptr->getRawStat(j)); - Point pos = ptr->getPosition(); + Point pos = ptr->getPos(); msg.writeShort(pos.x); msg.writeShort(pos.y); msg.writeShort(mapId); @@ -130,7 +130,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) int id = msg.readLong(); Storage &store = Storage::instance("tmw"); PlayerPtr ptr = store.getCharacter(id); - ptr->setGender((Gender)msg.readByte()); + ptr->setGender(msg.readByte()); ptr->setHairStyle(msg.readByte()); ptr->setHairColor(msg.readByte()); ptr->setLevel(msg.readByte()); @@ -140,8 +140,8 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) int x = msg.readShort(); int y = msg.readShort(); Point pos = { x, y }; - ptr->setPosition(pos); - ptr->setMapId(msg.readShort()); + ptr->setPos(pos); + ptr->setMap(msg.readShort()); } break; case GAMSG_REDIRECT: @@ -156,7 +156,7 @@ void ServerHandler::processMessage(NetComputer *comp, MessageIn &msg) PlayerPtr ptr = store.getCharacter(id); std::string address; short port; - if (serverHandler->getGameServerFromMap(ptr->getMapId(), address, port)) + if (serverHandler->getGameServerFromMap(ptr->getMap(), address, port)) { registerGameClient(magic_token, ptr); result.writeShort(AGMSG_REDIRECT_RESPONSE); diff --git a/src/account-server/serverhandler.hpp b/src/account-server/serverhandler.hpp index 797e0a48..1325b065 100644 --- a/src/account-server/serverhandler.hpp +++ b/src/account-server/serverhandler.hpp @@ -26,7 +26,7 @@ #include <map> -#include "player.h" +#include "playerdata.hpp" #include "net/connectionhandler.hpp" /** diff --git a/src/chat-server/chatchannel.hpp b/src/chat-server/chatchannel.hpp index 29a0734e..0fd6d4be 100644 --- a/src/chat-server/chatchannel.hpp +++ b/src/chat-server/chatchannel.hpp @@ -27,8 +27,6 @@ #include <string> #include <vector> -#include "being.h" - class ChatChannel { public: typedef std::vector< std::string > ChannelUsers; diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp index bb56c160..323abe76 100644 --- a/src/chat-server/chathandler.cpp +++ b/src/chat-server/chathandler.cpp @@ -21,6 +21,7 @@ * $Id$ */ +#include "defines.h" #include "chat-server/chatchannelmanager.hpp" #include "chat-server/chathandler.hpp" #include "net/connectionhandler.hpp" diff --git a/src/controller.h b/src/controller.h index 7a76d33d..adbc54a7 100644 --- a/src/controller.h +++ b/src/controller.h @@ -23,7 +23,7 @@ #ifndef _TMWSERV_CONTROLLER_H_ #define _TMWSERV_CONTROLLER_H_ -#include "being.h" +#include "game-server/being.hpp" /** * A controller can take control of a being. diff --git a/src/debug.cpp b/src/debug.cpp deleted file mode 100644 index 671528a2..00000000 --- a/src/debug.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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$ - */ - -// This file contains debugging global functions - -#include "debug.h" - -// global debugging flag (set to false in release version) -int debugflag = false; - - -void debugCatch(int result) -{ - if (!debugflag) { - return; // break out if we are not debugging - } - - - switch (result) - { - case TMW_SUCCESS: // function successful - return; - break; - case TMW_ACCOUNTERROR_NOEXIST: // account does not exist - // show the programmer a message - break; - case TMW_ACCOUNTERROR_BANNED: // account is banned - // show the programmer a message - break; - case TMW_ACCOUNTERROR_ALREADYASSIGNED: // account is in use - // show the programmer a message (this may signal a logout bug - break; - case TMW_ACCOUNTERROR_CHARNOTFOUND: // the character is not found - // show a message - break; - case TMW_ACCOUNTERROR_ASSIGNFAILED: // failed to assign the handle to the user - // show a message - break; - } -} diff --git a/src/debug.h b/src/debug.h deleted file mode 100644 index 65a95e36..00000000 --- a/src/debug.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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_DEBUG_H_ -#define _TMWSERV_DEBUG_H_ - -// This file defines the return types for debugging - -/** - * Returns a message on function failure if the debug flag is set to true. - */ -extern void debugCatch(int result); - - -// message handler definitions -// add your definitions to this list, sorted by type. Each group starts with a -// different multiple of 100 - - // GENERAL -#define TMW_SUCCESS 1 // the function completed successfully - - // ACCOUNT -#define TMW_ACCOUNTERROR_NOEXIST 100 -#define TMW_ACCOUNTERROR_BANNED 101 -#define TMW_ACCOUNTERROR_ALREADYASSIGNED 102 -#define TMW_ACCOUNTERROR_CHARNOTFOUND 103 -#define TMW_ACCOUNTERROR_ASSIGNFAILED 104 - -#endif diff --git a/src/defines.h b/src/defines.h index fc8c8705..ba2ba4af 100644 --- a/src/defines.h +++ b/src/defines.h @@ -44,17 +44,10 @@ typedef enum { AL_RESTRICTED // User rights have been restricted } AccountLevel; - -/** - * Enumeration type for the player genders. - */ -typedef enum { - GENDER_MALE, - GENDER_FEMALE -} Gender; - +enum +{ // Network related -const unsigned int MAX_CLIENTS = 1024, + MAX_CLIENTS = 1024, // Chat related /** @@ -97,8 +90,8 @@ const unsigned int MAX_CLIENTS = 1024, /** * Determine the area in which a character is aware of other beings */ - AROUND_AREA = 320; - + AROUND_AREA = 320 +}; /** * Enumerated type for communicated messages @@ -201,7 +194,7 @@ enum { ERRMSG_NO_LOGIN, // the user is not yet logged ERRMSG_NO_CHARACTER_SELECTED, // the user needs a character ERRMSG_INSUFFICIENT_RIGHTS, // the user is not privileged - ERRMSG_INVALID_ARGUMENT, // part of the received message was invalid + ERRMSG_INVALID_ARGUMENT // part of the received message was invalid }; // Login specific return values @@ -238,7 +231,7 @@ enum { // Chat errors return values enum { CHAT_USING_BAD_WORDS = 0x40, - CHAT_UNHANDLED_COMMAND, + CHAT_UNHANDLED_COMMAND }; // Chat channels event values diff --git a/src/game-server/accountconnection.cpp b/src/game-server/accountconnection.cpp index ceb0b5dd..d536abfc 100644 --- a/src/game-server/accountconnection.cpp +++ b/src/game-server/accountconnection.cpp @@ -23,10 +23,10 @@ #include "configuration.h" #include "defines.h" -#include "player.h" #include "game-server/accountconnection.hpp" #include "game-server/gamehandler.hpp" #include "game-server/mapmanager.hpp" +#include "game-server/player.hpp" #include "net/messagein.hpp" #include "net/messageout.hpp" #include "utils/logger.h" @@ -53,7 +53,7 @@ bool AccountConnection::start() return true; } -void AccountConnection::sendPlayerData(Player *p) +void AccountConnection::sendPlayerData(PlayerData *p) { MessageOut msg(GAMSG_PLAYER_DATA); msg.writeLong(p->getDatabaseID()); @@ -64,10 +64,10 @@ void AccountConnection::sendPlayerData(Player *p) msg.writeShort(p->getMoney()); for (int j = 0; j < NB_RSTAT; ++j) msg.writeShort(p->getRawStat(j)); - Point pos = p->getPosition(); + Point pos = p->getPos(); msg.writeShort(pos.x); msg.writeShort(pos.y); - msg.writeShort(p->getMapId()); + msg.writeShort(p->getMap()); send(msg); } @@ -80,7 +80,7 @@ void AccountConnection::processMessage(MessageIn &msg) int id = msg.readLong(); std::string name = msg.readString(); Player *ptr = new Player(name, id); - ptr->setGender((Gender)msg.readByte()); + ptr->setGender(msg.readByte()); ptr->setHairStyle(msg.readByte()); ptr->setHairColor(msg.readByte()); ptr->setLevel(msg.readByte()); diff --git a/src/game-server/accountconnection.hpp b/src/game-server/accountconnection.hpp index 9722fe69..e418a111 100644 --- a/src/game-server/accountconnection.hpp +++ b/src/game-server/accountconnection.hpp @@ -26,7 +26,7 @@ #include "net/connection.hpp" -class Player; +class PlayerData; /** * A connection to the account server. @@ -43,7 +43,7 @@ class AccountConnection: public Connection /** * Sends data of given player. */ - void sendPlayerData(Player *); + void sendPlayerData(PlayerData *); protected: /** diff --git a/src/being.cpp b/src/game-server/being.cpp index cece203a..64986c26 100644 --- a/src/being.cpp +++ b/src/game-server/being.cpp @@ -20,7 +20,7 @@ * $Id$ */ -#include "being.h" +#include "game-server/being.hpp" #include "game-server/mapcomposite.hpp" #include "utils/logger.h" diff --git a/src/being.h b/src/game-server/being.hpp index 760bea73..32b30b1e 100644 --- a/src/being.h +++ b/src/game-server/being.hpp @@ -28,7 +28,7 @@ #include <vector> #include "defines.h" -#include "object.h" +#include "game-server/object.hpp" #include "utils/countedptr.h" class MapComposite; @@ -36,7 +36,8 @@ class MapComposite; /** * Element attribute for beings, actors and items. */ -typedef enum { +enum +{ ELEMENT_NEUTRAL = 0, ELEMENT_FIRE, ELEMENT_WATER, @@ -44,13 +45,14 @@ typedef enum { ELEMENT_AIR, ELEMENT_SACRED, ELEMENT_DEATH -} Element; +}; /** * States attribute for beings, and actors. * States can be multiple for the same being. */ -struct BeingState { +struct BeingState +{ bool STATE_NORMAL; bool STATE_POISONED; bool STATE_STONED; @@ -66,7 +68,8 @@ struct BeingState { /** * Moves enum for beings and actors for others players vision. */ -typedef enum { +enum +{ ACTION_DEFAULT = 0, ACTION_STAND, ACTION_WALK, @@ -85,44 +88,25 @@ typedef enum { ACTION_HURT, ACTION_DEAD, ACTION_INVALID -} SpriteAction; +}; /** * Beings and actors directions */ -enum { +enum +{ DIRECTION_DOWN = 1, DIRECTION_UP, DIRECTION_LEFT, DIRECTION_RIGHT }; -/** - * Raw statistics of a Player. - */ -enum { - STAT_STRENGTH = 0, - STAT_AGILITY, - STAT_VITALITY, - STAT_INTELLIGENCE, - STAT_DEXTERITY, - STAT_LUCK, - NB_RSTAT -}; - -/** - * Structure types for the raw statistics of a Player. - */ -struct RawStatistics -{ - unsigned short stats[NB_RSTAT]; -}; - /** * Computed statistics of a Being. */ -enum { +enum +{ STAT_HEAT = 0, STAT_ATTACK, STAT_DEFENCE, diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index 56b9533c..f7a3905a 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -24,8 +24,8 @@ #include <cassert> #include <map> -#include "map.h" #include "game-server/gamehandler.hpp" +#include "game-server/map.hpp" #include "game-server/state.hpp" #include "net/messagein.hpp" #include "net/messageout.hpp" @@ -231,7 +231,6 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) gameState->sayAround(computer.character, say); } break; - /* case PGMSG_PICKUP: { // add item to inventory (this is too simplistic atm) @@ -260,7 +259,6 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) result.writeByte(ERRMSG_FAILURE); } } break; - */ case PGMSG_WALK: { @@ -272,7 +270,6 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) // no response should be required } break; - /* case PGMSG_EQUIP: { message.readLong(); // ItemId: Not useful, the inventory knows it @@ -282,7 +279,6 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) result.writeByte(computer.character->equip(slot) ? ERRMSG_OK : ERRMSG_FAILURE); } break; - */ case PGMSG_ATTACK: { diff --git a/src/game-server/gamehandler.hpp b/src/game-server/gamehandler.hpp index f574d9ec..faeff656 100644 --- a/src/game-server/gamehandler.hpp +++ b/src/game-server/gamehandler.hpp @@ -24,7 +24,7 @@ #ifndef _TMW_SERVER_GAMEHANDLER_ #define _TMW_SERVER_GAMEHANDLER_ -#include "player.h" +#include "game-server/player.hpp" #include "net/connectionhandler.hpp" /** diff --git a/src/inventory.cpp b/src/game-server/inventory.cpp index 97f29737..b3b8a254 100644 --- a/src/inventory.cpp +++ b/src/game-server/inventory.cpp @@ -21,7 +21,7 @@ * $Id$ */ -#include "inventory.h" +#include "game-server/inventory.hpp" #include "game-server/itemmanager.hpp" // --------- diff --git a/src/inventory.h b/src/game-server/inventory.hpp index d2e7961c..61bc5818 100644 --- a/src/inventory.h +++ b/src/game-server/inventory.hpp @@ -24,40 +24,43 @@ #ifndef INVENTORY_H #define INVENTORY_H -#include "being.h" +#include "game-server/being.hpp" +enum +{ // items in inventory : -const unsigned char MAX_ITEMS_IN_INVENTORY = 50, // Max 252. + MAX_ITEMS_IN_INVENTORY = 50, // Max 252. // Equipment rules: // 1 Brest equipment - EQUIP_BREST_SLOT = 0, + EQUIP_BREST_SLOT = 0, // 1 arms equipment - EQUIP_ARMS_SLOT = 1, + EQUIP_ARMS_SLOT = 1, // 1 head equipment - EQUIP_HEAD_SLOT = 2, + EQUIP_HEAD_SLOT = 2, // 1 legs equipment - EQUIP_LEGS_SLOT = 3, + EQUIP_LEGS_SLOT = 3, // 1 feet equipment - EQUIP_FEET_SLOT = 4, + EQUIP_FEET_SLOT = 4, // 2 rings - EQUIP_RING1_SLOT = 5, - EQUIP_RING2_SLOT = 6, + EQUIP_RING1_SLOT = 5, + EQUIP_RING2_SLOT = 6, // 1 necklace - EQUIP_NECKLACE_SLOT = 7, + EQUIP_NECKLACE_SLOT = 7, // Fight: // 2 one-handed weapons - EQUIP_FIGHT1_SLOT = 8, - EQUIP_FIGHT2_SLOT = 9, + EQUIP_FIGHT1_SLOT = 8, + EQUIP_FIGHT2_SLOT = 9, // or 1 two-handed weapon // or 1 one-handed weapon + 1 shield. // Projectiles - EQUIP_PROJECTILES_SLOT = 10, + EQUIP_PROJECTILES_SLOT = 10, // = 10 total slots for equipment. - TOTAL_EQUIPMENT_SLOTS = 11, + TOTAL_EQUIPMENT_SLOTS = 11, // Error codes - NOT_EQUIPPABLE = 253, - NO_ITEM_TO_EQUIP = 254, - INVENTORY_FULL = 255; + NOT_EQUIPPABLE = 253, + NO_ITEM_TO_EQUIP = 254, + INVENTORY_FULL = 255 +}; /** * Stored Item only contains id reference to items diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 3ce8350c..01b957a6 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -18,7 +18,7 @@ * 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:$ + * $Id$ */ #include "resourcemanager.h" @@ -81,7 +81,7 @@ ItemManager::ItemManager(std::string const &itemReferenceFile) std::string scriptName = XML::getProperty(node, "script_name", std::string()); Modifiers modifiers; - modifiers.element = (Element)XML::getProperty(node, "element", 0); + modifiers.element = XML::getProperty(node, "element", 0); modifiers.lifetime = XML::getProperty(node, "lifetime", 0); modifiers.rawStats[STAT_STRENGTH] = XML::getProperty(node, "strength", 0); modifiers.rawStats[STAT_AGILITY] = XML::getProperty(node, "agility", 0); diff --git a/src/map.cpp b/src/game-server/map.cpp index ec6767af..876ba674 100644 --- a/src/map.cpp +++ b/src/game-server/map.cpp @@ -21,12 +21,9 @@ * $Id$ */ -#include "map.h" - #include <queue> -#include "being.h" - +#include "game-server/map.hpp" MetaTile::MetaTile(): whichList(0) diff --git a/src/map.h b/src/game-server/map.hpp index a7c1fe2a..a7c1fe2a 100644 --- a/src/map.h +++ b/src/game-server/map.hpp diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp index 8b7ef9d7..1b824447 100644 --- a/src/game-server/mapcomposite.cpp +++ b/src/game-server/mapcomposite.cpp @@ -24,8 +24,10 @@ #include <algorithm> #include <cassert> -#include "map.h" +#include "point.h" +#include "game-server/map.hpp" #include "game-server/mapcomposite.hpp" +#include "game-server/player.hpp" /* TODO: Implement overlapping map zones instead of strict partitioning. Purpose: to decrease the number of zone changes, as overlapping allows for @@ -393,7 +395,7 @@ ZoneIterator MapComposite::getInsideRectangleIterator(Rectangle const &p) const return ZoneIterator(r, this); } -ZoneIterator MapComposite::getAroundPlayerIterator(Player *obj, int radius) const +ZoneIterator MapComposite::getAroundPlayerIterator(MovingObject *obj, int radius) const { MapRegion r1; fillRegion(r1, obj->getOldPosition(), radius); diff --git a/src/game-server/mapcomposite.hpp b/src/game-server/mapcomposite.hpp index 0623f602..526b36e2 100644 --- a/src/game-server/mapcomposite.hpp +++ b/src/game-server/mapcomposite.hpp @@ -26,11 +26,14 @@ #include <vector> -#include "object.h" -#include "player.h"
- class Map; class MapComposite; +class MovingObject; +class Object; +class Player; +class Point; +class Rectangle; +class Thing; /** * Ordered sets of zones of a map. @@ -191,7 +194,7 @@ class MapComposite { * Gets an iterator on the objects around the old and new positions of * a player (including the ones that were but are now elsewhere). */ - ZoneIterator getAroundPlayerIterator(Player *, int radius) const; + ZoneIterator getAroundPlayerIterator(MovingObject *, int radius) const; /** * Gets everything related to the map. diff --git a/src/game-server/mapmanager.cpp b/src/game-server/mapmanager.cpp index d3f431b2..accf7ca0 100644 --- a/src/game-server/mapmanager.cpp +++ b/src/game-server/mapmanager.cpp @@ -23,8 +23,8 @@ #include <cassert> -#include "map.h" #include "resourcemanager.h" +#include "game-server/map.hpp" #include "game-server/mapmanager.hpp" #include "game-server/mapreader.hpp" #include "utils/logger.h" diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp index d3a49a3c..63d81a64 100644 --- a/src/game-server/mapreader.cpp +++ b/src/game-server/mapreader.cpp @@ -21,8 +21,8 @@ * $Id$ */ -#include "map.h" #include "resourcemanager.h" +#include "game-server/map.hpp" #include "game-server/mapreader.hpp" #include "utils/base64.h" #include "utils/logger.h" diff --git a/src/object.cpp b/src/game-server/object.cpp index c2e11a7f..9921182d 100644 --- a/src/object.cpp +++ b/src/game-server/object.cpp @@ -20,9 +20,9 @@ * $Id$ */ -#include "map.h" -#include "object.h" +#include "game-server/map.hpp" #include "game-server/mapmanager.hpp" +#include "game-server/object.hpp" void MovingObject::move() { diff --git a/src/object.h b/src/game-server/object.hpp index 4ad8c0be..498680e4 100644 --- a/src/object.h +++ b/src/game-server/object.hpp @@ -29,7 +29,8 @@ #include "point.h" // Object type enumeration -enum { +enum +{ OBJECT_ITEM = 0, // A simple item OBJECT_ACTOR, // An item that toggle map/quest actions (doors, switchs, ...) and can speak (map panels). OBJECT_NPC, // Non-Playable-Character is an actor capable of movement and maybe actions diff --git a/src/player.cpp b/src/game-server/player.cpp index e7d84d3e..294239f9 100644 --- a/src/player.cpp +++ b/src/game-server/player.cpp @@ -23,7 +23,7 @@ #include <cassert> #include "defines.h" -#include "player.h" +#include "game-server/player.hpp" /** * Update the internal status. @@ -31,12 +31,16 @@ void Player::update() { // computed stats. - setStat(STAT_HEAT, 20 + (20 * mRawStats.stats[STAT_VITALITY])); - setStat(STAT_ATTACK, 10 + mRawStats.stats[STAT_STRENGTH]); - setStat(STAT_DEFENCE, 10 + mRawStats.stats[STAT_STRENGTH]); - setStat(STAT_MAGIC, 10 + mRawStats.stats[STAT_INTELLIGENCE]); - setStat(STAT_ACCURACY, 50 + mRawStats.stats[STAT_DEXTERITY]); - setStat(STAT_SPEED, mRawStats.stats[STAT_DEXTERITY]); + setStat(STAT_HEAT, 20 + (20 * getRawStat(STAT_VITALITY))); + setStat(STAT_ATTACK, 10 + getRawStat(STAT_STRENGTH)); + setStat(STAT_DEFENCE, 10 + getRawStat(STAT_STRENGTH)); + setStat(STAT_MAGIC, 10 + getRawStat(STAT_INTELLIGENCE)); + setStat(STAT_ACCURACY, 50 + getRawStat(STAT_DEXTERITY)); + setStat(STAT_SPEED, getRawStat(STAT_DEXTERITY)); + + // Update persistent data. + setPos(getPosition()); + setMap(getMapId()); // attacking if (mIsAttacking) @@ -52,7 +56,6 @@ void Player::update() } } -/* void Player::setInventory(const Inventory &inven) { inventory = inven; @@ -82,4 +85,3 @@ bool Player::unequip(unsigned char slot) { return false; // TODO } -*/ diff --git a/src/game-server/player.hpp b/src/game-server/player.hpp new file mode 100644 index 00000000..4ecef616 --- /dev/null +++ b/src/game-server/player.hpp @@ -0,0 +1,124 @@ +/* + * 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 "playerdata.hpp" +#include "game-server/being.hpp" +#include "game-server/inventory.hpp" + +class GameClient; + +class Player : public Being, public PlayerData +{ + public: + + Player(std::string const &name, int id = -1) + : Being(OBJECT_PLAYER, 65535), + PlayerData(name, id), + mClient(NULL), + mIsAttacking(false) + {} + + /** + * Updates the internal status. + */ + void update();
+
+ /** + * Sets inventory. + */ + void + setInventory(const Inventory &inven); + + /** + * Adds item with ID to inventory. + * + * @return Item add success/failure + */ + bool + addItem(unsigned int itemId, unsigned char amount = 1); + + /** + * Removes item with ID from inventory. + * + * @return Item delete success/failure + */ + bool + removeItem(unsigned int itemId, unsigned char amount = 0); + + /** + * 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 char slot); + + /** + * Un-equips item. + * + * @return Un-equip success/failure + */ + bool + unequip(unsigned char slot); + + /** + * Set attacking state + **/ + void setAttacking(bool isAttacking) + { mIsAttacking = isAttacking; } + + /** + * Gets client computer. + */ + GameClient *getClient() const + { return mClient; } + + /** + * Sets client computer. + */ + void setClient(GameClient *c) + { mClient = c; } + + private: + Player(Player const &); + Player &operator=(Player const &); + + GameClient *mClient; /**< Client computer. */ + Inventory inventory; /**< Player inventory and equipment. */ + bool mIsAttacking; /**< Attacking state. */ +}; + +#endif // _TMWSERV_PLAYER_H_ diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index 7e78857e..9763d459 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -23,12 +23,11 @@ #include <cassert> -#include "controller.h" #include "defines.h" -#include "map.h" #include "point.h" #include "game-server/accountconnection.hpp" #include "game-server/gamehandler.hpp" +#include "game-server/map.hpp" #include "game-server/mapcomposite.hpp" #include "game-server/mapmanager.hpp" #include "game-server/state.hpp" diff --git a/src/game-server/trigger.cpp b/src/game-server/trigger.cpp index 22a25697..469fb544 100644 --- a/src/game-server/trigger.cpp +++ b/src/game-server/trigger.cpp @@ -21,8 +21,8 @@ * $Id$ */ -#include "player.h" #include "game-server/mapcomposite.hpp" +#include "game-server/object.hpp" #include "game-server/state.hpp" #include "game-server/trigger.hpp" diff --git a/src/game-server/trigger.hpp b/src/game-server/trigger.hpp index a3149812..bb4f776d 100644 --- a/src/game-server/trigger.hpp +++ b/src/game-server/trigger.hpp @@ -24,7 +24,7 @@ #ifndef _TMWSERV_TRIGGER #define _TMWSERV_TRIGGER -#include "object.h" +class Object; class TriggerAction { @@ -24,7 +24,8 @@ #ifndef ITEM_H #define ITEM_H -#include "being.h" +#include "playerdata.hpp" +#include "game-server/being.hpp" /** * Enumeration of available Item types. @@ -103,7 +104,7 @@ typedef enum BeingStateEffect { struct Modifiers { // General - Element element; /**< Item Element */ + unsigned char element; /**< Item Element */ BeingStateEffect beingStateEffect; /**< Being State (dis)alteration */ unsigned short lifetime; /**< Modifiers lifetime in seconds. */ diff --git a/src/player.h b/src/playerdata.hpp index deffb752..cc4a4b46 100644 --- a/src/player.h +++ b/src/playerdata.hpp @@ -20,29 +20,54 @@ * $Id$ */ -#ifndef _TMWSERV_PLAYER_H_ -#define _TMWSERV_PLAYER_H_ +#ifndef _TMWSERV_PLAYERDATA +#define _TMWSERV_PLAYERDATA #include <string> #include <vector> -#include "being.h" -#include "defines.h" -#include "inventory.h" +#include "point.h" #include "utils/countedptr.h" -class GameClient; +/** + * Gender of a Player. + */ +enum +{ + GENDER_MALE = 0, + GENDER_FEMALE +}; -class Player : public Being +/** + * Raw statistics of a Player. + */ +enum +{ + STAT_STRENGTH = 0, + STAT_AGILITY, + STAT_VITALITY, + STAT_INTELLIGENCE, + STAT_DEXTERITY, + STAT_LUCK, + NB_RSTAT +}; + +/** + * Structure types for the raw statistics of a Player. + */ +struct RawStatistics +{ + unsigned short stats[NB_RSTAT]; +}; + + +class PlayerData { public: - Player(std::string const &name, int id = -1) - : Being(OBJECT_PLAYER, 65535), - mDatabaseID(id), - mName(name), - mClient(NULL), - mIsAttacking(false) + PlayerData(std::string const &name, int id = -1) + : mDatabaseID(id), + mName(name) {} /** @@ -58,7 +83,7 @@ class Player : public Being * * @param style the new hair style. */ - void setHairStyle(unsigned char style) + void setHairStyle(int style) { mHairStyle = style; } /** @@ -66,7 +91,7 @@ class Player : public Being * * @return the hair style value. */ - unsigned char getHairStyle() const + int getHairStyle() const { return mHairStyle; } /** @@ -74,7 +99,7 @@ class Player : public Being * * @param color the new hair color. */ - void setHairColor(unsigned char color) + void setHairColor(int color) { mHairColor = color; } /** @@ -82,7 +107,7 @@ class Player : public Being * * @return the hair color value. */ - unsigned char getHairColor() const + int getHairColor() const { return mHairColor; } /** @@ -90,7 +115,7 @@ class Player : public Being * * @param gender the new gender. */ - void setGender(Gender gender) + void setGender(int gender) { mGender = gender; } /** @@ -98,7 +123,7 @@ class Player : public Being * * @return the gender. */ - Gender getGender() const + int getGender() const { return mGender; } /** @@ -106,7 +131,7 @@ class Player : public Being * * @param level the new level. */ - void setLevel(unsigned char level) + void setLevel(int level) { mLevel = level; } /** @@ -114,7 +139,7 @@ class Player : public Being * * @return the level. */ - unsigned char getLevel() const + int getLevel() const { return mLevel; } /** @@ -122,7 +147,7 @@ class Player : public Being * * @param amount the new amount. */ - void setMoney(unsigned int amount) + void setMoney(int amount) { mMoney = amount; } /** @@ -130,7 +155,7 @@ class Player : public Being * * @return the amount of money. */ - unsigned int getMoney() const + int getMoney() const { return mMoney; } /** @@ -139,7 +164,7 @@ class Player : public Being * @param numStat the statistic number. * @param value the new value. */ - void setRawStat(int numStat, unsigned short value) + void setRawStat(int numStat, int value) { mRawStats.stats[numStat] = value; } /** @@ -148,120 +173,78 @@ class Player : public Being * @param numStat the statistic number. * @return the statistic value. */ - unsigned short getRawStat(int numStat) + int getRawStat(int numStat) { return mRawStats.stats[numStat]; } /** - * Updates the internal status. - */ - void update();
-
- /** - * Sets inventory. - */ - void - setInventory(const Inventory &inven); - - /** - * Adds item with ID to inventory. + * Gets database ID. * - * @return Item add success/failure + * @return the database ID, a negative number if none yet. */ - bool - addItem(unsigned int itemId, unsigned char amount = 1); + int getDatabaseID() const + { return mDatabaseID; } /** - * Removes item with ID from inventory. - * - * @return Item delete success/failure + * Sets database ID. + * The object shall not have any ID yet. */ - bool - removeItem(unsigned int itemId, unsigned char amount = 0); + void setDatabaseID(int id) + { mDatabaseID = id; } /** - * Checks if character has an item. + * Gets the map this thing is located on. * - * @return true if being has item, false otherwise + * @return ID of map. */ - bool - hasItem(unsigned int itemId); + int getMap() const + { return mMapId; } /** - * Equips item with ID in equipment slot. - * - * @return Equip success/failure + * Sets the map this thing is located on. */ - bool - equip(unsigned char slot); + void setMap(int mapId) + { mMapId = mapId; } /** - * Un-equips item. + * Sets the coordinates. * - * @return Un-equip success/failure + * @param p the coordinates. */ - bool - unequip(unsigned char slot); - - /** - * Set attacking state - **/ - void setAttacking(bool isAttacking) - { mIsAttacking = isAttacking; } + void setPos(const Point &p) + { mPos = p; } /** - * Gets database ID. + * Gets the coordinates. * - * @return the database ID, a negative number if none yet. - */ - int getDatabaseID() const - { return mDatabaseID; } - - /** - * Sets database ID. - * The object shall not have any ID yet. - */ - void setDatabaseID(int id) - { mDatabaseID = id; } - - /** - * Gets client computer. - */ - GameClient *getClient() const - { return mClient; } - - /** - * Sets client computer. + * @return the coordinates. */ - void setClient(GameClient *c) - { mClient = c; } + Point const &getPos() const + { return mPos; } private: - Player(Player const &); - Player &operator=(Player const &); - - int mDatabaseID; /**< Player database ID (unique with respect to its type) */ - std::string mName; /**< name of the being */ - GameClient *mClient; /**< client computer, directly set by GameClient */ - 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 */ - - Inventory inventory; /**< Player inventory and Equipment */ - - bool mIsAttacking; /**< attacking state */ + PlayerData(PlayerData const &); + PlayerData &operator=(PlayerData const &); + + int mDatabaseID; /**< Player database ID. */ + std::string mName; /**< Name of the being. */ + unsigned char 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 short mMapId; /**< Map the being is on. */ + Point mPos; /**< Position the being is at. */ + unsigned int mMoney; /**< Wealth of the being. */ + RawStatistics mRawStats; /**< Raw statistics of the being. */ }; /** - * Type definition for a smart pointer to Player. + * Type definition for a smart pointer to PlayerData. */ -typedef utils::CountedPtr<Player> PlayerPtr; +typedef utils::CountedPtr< PlayerData > PlayerPtr; /** * Type definition for a list of Players. */ -typedef std::vector<PlayerPtr> Players; +typedef std::vector< PlayerPtr > Players; -#endif // _TMWSERV_PLAYER_H_ +#endif |