diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/defines.h | 2 | ||||
-rw-r--r-- | src/common/manaserv_protocol.h | 39 | ||||
-rw-r--r-- | src/game-server/being.cpp | 5 | ||||
-rw-r--r-- | src/game-server/being.h | 8 | ||||
-rw-r--r-- | src/game-server/character.cpp | 16 | ||||
-rw-r--r-- | src/game-server/character.h | 8 | ||||
-rw-r--r-- | src/game-server/monster.cpp | 1 | ||||
-rw-r--r-- | src/game-server/monster.h | 8 | ||||
-rw-r--r-- | src/game-server/monstermanager.cpp | 5 | ||||
-rw-r--r-- | src/game-server/state.cpp | 2 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 38 | ||||
-rw-r--r-- | src/serialize/characterdata.h | 3 |
12 files changed, 91 insertions, 44 deletions
diff --git a/src/common/defines.h b/src/common/defines.h index 140a6929..ca596316 100644 --- a/src/common/defines.h +++ b/src/common/defines.h @@ -21,6 +21,8 @@ #ifndef DEFINES_H #define DEFINES_H +#include "common/manaserv_protocol.h" + // Precomputed square-root of 2. #define SQRT2 1.4142135623730950488 diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h index 13e7f8c1..7ad2bc12 100644 --- a/src/common/manaserv_protocol.h +++ b/src/common/manaserv_protocol.h @@ -22,6 +22,10 @@ #ifndef MANASERV_PROTOCOL_H #define MANASERV_PROTOCOL_H +#include <string> + +#include "utils/string.h" + namespace ManaServ { enum { @@ -112,8 +116,8 @@ enum { PGMSG_RESPAWN = 0x0180, // - GPMSG_BEING_ENTER = 0x0200, // B type, W being id, B action, W*2 position, B direction // character: S name, B hair style, B hair color, B gender, B sprite layers changed, { B slot type, W item id }* - // monster: W type id - // npc: W type id + // monster: W type id gender + // npc: W type id gender GPMSG_BEING_LEAVE = 0x0201, // W being id GPMSG_ITEM_APPEAR = 0x0202, // W item id, W*2 position GPMSG_BEING_LOOKS_CHANGE = 0x0210, // B sprite layers changed, { B slot type, W item id }* @@ -441,6 +445,37 @@ enum BeingGender GENDER_UNSPECIFIED }; +// Helper functions for gender + +/** +* Helper function for getting gender by int +*/ +inline ManaServ::BeingGender getGender(int gender) +{ + switch (gender) + { + case 0: + return ManaServ::GENDER_MALE; + case 1: + return ManaServ::GENDER_FEMALE; + default: + return ManaServ::GENDER_UNSPECIFIED; + } +}; + +/** +* Helper function for getting gender by string +*/ +inline ManaServ::BeingGender getGender(std::string gender) +{ + if (utils::toLower(gender) == "male") + return ManaServ::GENDER_MALE; + else if (utils::toLower(gender) == "female") + return ManaServ::GENDER_FEMALE; + else + return ManaServ::GENDER_UNSPECIFIED; +}; + } // namespace ManaServ #endif // MANASERV_PROTOCOL_H diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index fd9f8fe4..82080459 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -39,6 +39,7 @@ Being::Being(ThingType type): Actor(type), mAction(STAND), mTarget(NULL), + mGender(GENDER_UNSPECIFIED), mDirection(DOWN) { const AttributeScope &attr = attributeManager->getAttributeScope(BeingScope); @@ -731,3 +732,7 @@ bool Being::isTimerJustFinished(TimerID id) const return getTimer(id) == 0; } +void Being::setGender(BeingGender gender) +{ + mGender = gender; +} diff --git a/src/game-server/being.h b/src/game-server/being.h index 1747316c..c7739cc5 100644 --- a/src/game-server/being.h +++ b/src/game-server/being.h @@ -179,6 +179,13 @@ class Being : public Actor */ virtual Path findPath(); + /** Gets the gender of the being (male or female). */ + BeingGender getGender() const + { return mGender; } + + /** Sets the gender of the being (male or female). */ + void setGender(BeingGender gender); + /** * Sets an attribute. */ @@ -301,6 +308,7 @@ class Being : public Actor Being *mTarget; Point mOld; /**< Old coordinates. */ Point mDst; /**< Target coordinates. */ + BeingGender mGender; /**< Gender of the being. */ /** Sets timer unless already higher. */ void setTimerSoft(TimerID id, int value); diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index f1792261..9867b582 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -59,7 +59,6 @@ Character::Character(MessageIn &msg): mRechargePerSpecial(0), mSpecialUpdateNeeded(false), mDatabaseID(-1), - mGender(GENDER_UNSPECIFIED), mHairStyle(0), mHairColor(0), mLevel(1), @@ -297,21 +296,6 @@ void Character::cancelTransaction() } } -void Character::setGender(int gender) -{ - switch (gender) - { - case 0: - mGender = GENDER_MALE; - break; - case 1: - mGender = GENDER_FEMALE; - break; - default: - mGender = GENDER_UNSPECIFIED; - } -} - Trade *Character::getTrading() const { return mTransaction == TRANS_TRADE diff --git a/src/game-server/character.h b/src/game-server/character.h index 30e39633..dc452ba2 100644 --- a/src/game-server/character.h +++ b/src/game-server/character.h @@ -173,13 +173,6 @@ class Character : public Being int getDatabaseID() const { return mDatabaseID; } void setDatabaseID(int id) { mDatabaseID = id; } - /** Gets the gender of the character (male or female). */ - BeingGender getGender() const - { return mGender; } - - /** Sets the gender of the character (male or female). */ - void setGender(int gender); - int getHairStyle() const { return mHairStyle; } void setHairStyle(int style) { mHairStyle = style; } @@ -442,7 +435,6 @@ class Character : public Being bool mSpecialUpdateNeeded; int mDatabaseID; /**< Character's database ID. */ - BeingGender mGender; /**< Gender of the character. */ unsigned char mHairStyle; /**< Hair Style of the character. */ unsigned char mHairColor; /**< Hair Color of the character. */ int mLevel; /**< Level of the character. */ diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index a976b81c..f7218686 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -93,6 +93,7 @@ Monster::Monster(MonsterClass *specy): } setSize(specy->getSize()); + setGender(specy->getGender()); // Set positions relative to target from which the monster can attack int dist = specy->getAttackDistance(); diff --git a/src/game-server/monster.h b/src/game-server/monster.h index f5d64165..fe68a8a8 100644 --- a/src/game-server/monster.h +++ b/src/game-server/monster.h @@ -71,6 +71,7 @@ class MonsterClass MonsterClass(int id): mId(id), mName("unnamed"), + mGender(GENDER_UNSPECIFIED), mSpeed(1), mSize(16), mExp(-1), @@ -100,6 +101,12 @@ class MonsterClass void setName(const std::string &name) { mName = name; } + void setGender(BeingGender gender) + { mGender = gender; } + + const BeingGender getGender() const + { return mGender; } + /** * Sets monster drops. These are the items the monster drops when it * dies. @@ -193,6 +200,7 @@ class MonsterClass private: unsigned short mId; std::string mName; + BeingGender mGender; MonsterDrops mDrops; std::map<int, double> mAttributes; /**< Base attributes of the monster. */ diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp index 0f1686ca..313be34e 100644 --- a/src/game-server/monstermanager.cpp +++ b/src/game-server/monstermanager.cpp @@ -20,6 +20,8 @@ #include "game-server/monstermanager.h" +#include "common/defines.h" + #include "game-server/attributemanager.h" #include "game-server/itemmanager.h" #include "game-server/monster.h" @@ -153,6 +155,9 @@ void MonsterManager::initialize() monster->setSize(XML::getProperty(subnode, "size", -1)); float speed = (XML::getFloatProperty(subnode, "speed", -1.0f)); monster->setMutation(XML::getProperty(subnode, "mutation", 0)); + std::string genderString = XML::getProperty(subnode, "gender", + std::string()); + monster->setGender(getGender(genderString)); // Checking attributes for completeness and plausibility if (monster->getMutation() > MAX_MUTATION) diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index 30b57cae..67130070 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -285,6 +285,7 @@ static void informPlayer(MapComposite *map, Character *p, int worldTime) Monster *q = static_cast< Monster * >(o); enterMsg.writeInt16(q->getSpecy()->getId()); enterMsg.writeString(q->getName()); + enterMsg.writeInt8(q->getGender()); } break; case OBJECT_NPC: @@ -292,6 +293,7 @@ static void informPlayer(MapComposite *map, Character *p, int worldTime) NPC *q = static_cast< NPC * >(o); enterMsg.writeInt16(q->getNPC()); enterMsg.writeString(q->getName()); + enterMsg.writeInt8(q->getGender()); } break; default: diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 1bb75137..9f905bcd 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -27,6 +27,7 @@ extern "C" { #include <lauxlib.h> } +#include "common/defines.h" #include "common/resourcemanager.h" #include "game-server/accountconnection.h" #include "game-server/buysell.h" @@ -191,13 +192,16 @@ static int npc_create(lua_State *s) { const char *name = luaL_checkstring(s, 1); const int id = luaL_checkint(s, 2); - const int x = luaL_checkint(s, 3); - const int y = luaL_checkint(s, 4); + const int gender = luaL_checkint(s, 3); + const int x = luaL_checkint(s, 4); + const int y = luaL_checkint(s, 5); lua_pushlightuserdata(s, (void *)®istryKey); lua_gettable(s, LUA_REGISTRYINDEX); Script *t = static_cast<Script *>(lua_touserdata(s, -1)); NPC *q = new NPC(name, id, t); + q->setGender(getGender(gender)); + MapComposite *m = t->getMap(); if (!m) { @@ -1807,37 +1811,37 @@ static int chr_get_kill_count(lua_State *s) } /** - * mana.chr_get_gender(Character*): int - * Get the gender of the character. + * mana.being_get_gender(Being*): int + * Get the gender of the being. */ -static int chr_get_gender(lua_State *s) +static int being_get_gender(lua_State *s) { - Character *c = getCharacter(s, 1); - if (!c) + Being *b = getBeing(s, 1); + if (!b) { raiseScriptError(s, "chr_get_gender called for nonexistent character."); return 0; } - lua_pushinteger(s, c->getGender()); + lua_pushinteger(s, b->getGender()); return 1; } /** - * mana.chr_set_gender(Character*, int gender): void - * Set the gender of the character. + * mana.being_set_gender(Being*, int gender): void + * Set the gender of the being. */ -static int chr_set_gender(lua_State *s) +static int being_set_gender(lua_State *s) { - Character *c = getCharacter(s, 1); - if (!c) + Being *b = getBeing(s, 1); + if (!b) { - raiseScriptError(s, "chr_set_gender called for nonexistent character."); + raiseScriptError(s, "being_set_gender called for nonexistent character."); return 0; } const int gender = luaL_checkinteger(s, 2); - c->setGender(gender); + b->setGender(getGender(gender)); return 0; } @@ -2336,8 +2340,8 @@ LuaScript::LuaScript(): { "chr_set_hair_color", &chr_set_hair_color }, { "chr_get_hair_color", &chr_get_hair_color }, { "chr_get_kill_count", &chr_get_kill_count }, - { "chr_get_gender", &chr_get_gender }, - { "chr_set_gender", &chr_set_gender }, + { "being_get_gender", &being_get_gender }, + { "being_set_gender", &being_set_gender }, { "chr_give_special", &chr_give_special }, { "chr_has_special", &chr_has_special }, { "chr_take_special", &chr_take_special }, diff --git a/src/serialize/characterdata.h b/src/serialize/characterdata.h index c453e685..14a7097b 100644 --- a/src/serialize/characterdata.h +++ b/src/serialize/characterdata.h @@ -25,6 +25,7 @@ #include "common/defines.h" #include "common/inventorydata.h" +#include "common/manaserv_protocol.h" #include "net/messagein.h" #include "net/messageout.h" #include "utils/point.h" @@ -122,7 +123,7 @@ void deserializeCharacterData(T &data, MessageIn &msg) { // general character properties data.setAccountLevel(msg.readInt8()); - data.setGender(msg.readInt8()); + data.setGender(ManaServ::getGender(msg.readInt8())); data.setHairStyle(msg.readInt8()); data.setHairColor(msg.readInt8()); data.setLevel(msg.readInt16()); |