diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2011-12-27 05:59:55 +0800 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-01-02 19:59:31 +0800 |
commit | e4a7536e7ca14dcc257d60f8562a9dab61c4fd34 (patch) | |
tree | f4f1e8630b1fc15cf2bc9bfd13f25a69bb4c99cc | |
parent | 646fb10397e440ab67fb5a678bf034c53b050109 (diff) | |
download | manaserv-e4a7536e7ca14dcc257d60f8562a9dab61c4fd34.tar.gz manaserv-e4a7536e7ca14dcc257d60f8562a9dab61c4fd34.tar.xz manaserv-e4a7536e7ca14dcc257d60f8562a9dab61c4fd34.zip |
Made all beings capable of having a gender
Reviewed-by: o11c, bjorn, Bertram.
-rw-r--r-- | example/clientdata/monsters.xml | 1 | ||||
-rw-r--r-- | example/serverdata/scripts/maps/desert.lua | 14 | ||||
-rw-r--r-- | example/serverdata/scripts/npcs/banker.lua | 4 | ||||
-rw-r--r-- | example/serverdata/scripts/npcs/merchant.lua | 2 | ||||
-rw-r--r-- | scripts/lua/libmana.lua | 4 | ||||
-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 |
17 files changed, 104 insertions, 56 deletions
diff --git a/example/clientdata/monsters.xml b/example/clientdata/monsters.xml index a268096..ba882cc 100644 --- a/example/clientdata/monsters.xml +++ b/example/clientdata/monsters.xml @@ -163,6 +163,7 @@ exp<TAG>: Tells how much experience point a monster is giving up magical-evade="30" physical-defence="5" magical-defence="0" + gender="female" /> <!-- also quite lazy when unprovoked but much more territorial than the normal one--> diff --git a/example/serverdata/scripts/maps/desert.lua b/example/serverdata/scripts/maps/desert.lua index 753375b..8b7da1f 100644 --- a/example/serverdata/scripts/maps/desert.lua +++ b/example/serverdata/scripts/maps/desert.lua @@ -21,26 +21,26 @@ require "scripts/npcs/shaker" atinit(function() -- Barber examples - create_npc("Barber Twin", 1, 14 * TILESIZE + TILESIZE / 2, 9 * TILESIZE + TILESIZE / 2, Barber, nil) - create_npc("Barber Twin", 1, 20 * TILESIZE + TILESIZE / 2, 11 * TILESIZE + TILESIZE / 2, npclib.talk(Barber, {14, 15, 16}, {}), nil) + create_npc("Barber Twin", 1, GENDER_MALE, 14 * TILESIZE + TILESIZE / 2, 9 * TILESIZE + TILESIZE / 2, Barber, nil) + create_npc("Barber Twin", 1, GENDER_MALE, 20 * TILESIZE + TILESIZE / 2, 11 * TILESIZE + TILESIZE / 2, npclib.talk(Barber, {14, 15, 16}, {}), nil) -- A simple banker - create_npc("Banker", 8, 35 * TILESIZE + TILESIZE / 2, 24 * TILESIZE + TILESIZE / 2, Banker, nil) + create_npc("Banker", 8, GENDER_MALE, 35 * TILESIZE + TILESIZE / 2, 24 * TILESIZE + TILESIZE / 2, Banker, nil) -- A simple merchant. merchant_buy_table = { {"Candy", 10, 20}, {"Regenerative trinket", 10, 30}, {"Minor health potion", 10, 50}, {11, 10, 60}, {12, 10, 40} } merchant_sell_table = { {"Candy", 10, 19}, {"Sword", 10, 30}, {"Bow", 10, 200}, {"Leather shirt", 10, 300} } - create_npc("Merchant", 3, 4 * TILESIZE + TILESIZE / 2, 16 * TILESIZE + TILESIZE / 2, npclib.talk(Merchant, merchant_buy_table, merchant_sell_table), nil) + create_npc("Merchant", 3, GENDER_MALE, 4 * TILESIZE + TILESIZE / 2, 16 * TILESIZE + TILESIZE / 2, npclib.talk(Merchant, merchant_buy_table, merchant_sell_table), nil) -- Another Merchant, selling some equipment, and buying everything... smith_buy_table = { {"Sword", 10, 50}, {7, 10, 70}, {10, 10, 20} } - create_npc("Smith", 5, 15 * TILESIZE + TILESIZE / 2, 16 * TILESIZE + TILESIZE / 2, npclib.talk(Merchant, smith_buy_table), nil) + create_npc("Smith", 5, GENDER_MALE, 15 * TILESIZE + TILESIZE / 2, 16 * TILESIZE + TILESIZE / 2, npclib.talk(Merchant, smith_buy_table), nil) -- The most simple NPC - Welcoming new ones around. - create_npc("Harmony", 11, 4 * TILESIZE + TILESIZE / 2, 25 * TILESIZE + TILESIZE / 2, npclib.talk(Harmony, "Welcome in the template world!\nI hope you'll find here whatever you were searching for.", "Do look around to find some interesting things coming along!"), Harmony_update) + create_npc("Harmony", 11, GENDER_FEMALE, 4 * TILESIZE + TILESIZE / 2, 25 * TILESIZE + TILESIZE / 2, npclib.talk(Harmony, "Welcome in the template world!\nI hope you'll find here whatever you were searching for.", "Do look around to find some interesting things coming along!"), Harmony_update) -- Creates a Monster an let it talk for testing purpose. - create_npc("Tamer", 9, 28 * TILESIZE + TILESIZE / 2, 21 * TILESIZE + TILESIZE / 2, Tamer, nil) + create_npc("Tamer", 9, GENDER_UNSPECIFIED, 28 * TILESIZE + TILESIZE / 2, 21 * TILESIZE + TILESIZE / 2, Tamer, nil) end) -- Global variable used to know whether Harmony talked to someone. diff --git a/example/serverdata/scripts/npcs/banker.lua b/example/serverdata/scripts/npcs/banker.lua index 7a6e6b4..4e04865 100644 --- a/example/serverdata/scripts/npcs/banker.lua +++ b/example/serverdata/scripts/npcs/banker.lua @@ -11,9 +11,9 @@ ---------------------------------------------------------------------------------- function Banker(npc, ch) - if mana.chr_get_gender(ch) == GENDER_MALE then + if mana.being_get_gender(ch) == GENDER_MALE then do_message(npc, ch, "Welcome to the bank, sir!") - elseif mana.chr_get_gender(ch) == GENDER_FEMALE then + elseif mana.being_get_gender(ch) == GENDER_FEMALE then do_message(npc, ch, "Welcome to the bank, madam!") else do_message(npc, ch, "Welcome to the bank... uhm... person of unspecified gender!") diff --git a/example/serverdata/scripts/npcs/merchant.lua b/example/serverdata/scripts/npcs/merchant.lua index 3b80298..34f309e 100644 --- a/example/serverdata/scripts/npcs/merchant.lua +++ b/example/serverdata/scripts/npcs/merchant.lua @@ -29,7 +29,7 @@ function Merchant(npc, ch, buy_sell_table) elseif (rights >= 2) then do_message(npc, ch, "How can I assist you in your testing duties?") elseif (rights >= 1) then - if mana.chr_get_gender(ch) == GENDER_FEMALE then + if mana.being_get_gender(ch) == GENDER_FEMALE then do_message(npc, ch, "What do you want, Madam?") else do_message(npc, ch, "Wat do you want, Sir?") diff --git a/scripts/lua/libmana.lua b/scripts/lua/libmana.lua index d0d8666..361fd7d 100644 --- a/scripts/lua/libmana.lua +++ b/scripts/lua/libmana.lua @@ -40,8 +40,8 @@ local timer -- Creates an NPC and associates the given handler. -- Note: Cannot be called until map initialization has started. -function create_npc(name, id, x, y, talkfunct, updatefunct) - local npc = mana.npc_create(name, id, x, y) +function create_npc(name, id, gender, x, y, talkfunct, updatefunct) + local npc = mana.npc_create(name, id, gender, x, y) if talkfunct then npc_talk_functs[npc] = function(npc, ch) talkfunct(npc, ch) diff --git a/src/common/defines.h b/src/common/defines.h index 140a692..ca59631 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 13e7f8c..7ad2bc1 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 fd9f8fe..8208045 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 1747316..c7739cc 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 f179226..9867b58 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 30e3963..dc452ba 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 a976b81..f721868 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 f5d6416..fe68a8a 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 0f1686c..313be34 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 30b57ca..6713007 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 1bb7513..9f905bc 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 c453e68..14a7097 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()); |