diff options
-rw-r--r-- | ChangeLog | 21 | ||||
-rw-r--r-- | data/graphics/images/error.png | bin | 0 -> 314 bytes | |||
-rw-r--r-- | src/being.cpp | 6 | ||||
-rw-r--r-- | src/being.h | 4 | ||||
-rw-r--r-- | src/engine.cpp | 1 | ||||
-rw-r--r-- | src/main.cpp | 6 | ||||
-rw-r--r-- | src/player.cpp | 35 | ||||
-rw-r--r-- | src/player.h | 2 | ||||
-rw-r--r-- | src/resources/equipmentdb.cpp | 157 | ||||
-rw-r--r-- | src/resources/equipmentdb.h | 52 | ||||
-rw-r--r-- | src/resources/equipmentinfo.h | 52 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 6 | ||||
-rw-r--r-- | src/resources/itemdb.h | 53 |
13 files changed, 327 insertions, 68 deletions
@@ -1,4 +1,23 @@ -2006-11-05 Philipp Sehmisch <tmw@crushnet.org> +2006-11-26 Philipp Sehmisch <tmw@crushnet.org> + + * src/being.cpp, src/being.h, src/engine.cpp, src/main.cpp, src/player.cpp, + src/player.h, src/resources/equipmentdb.h, src/resources/equipmentdb.cpp, + src/resources/equipmentinfo.h, src/resources/itemdb.cpp, + src/resources/itemdb.h, data/graphics/images/error.png, + data/graphics/sprites/error.xml: + Added the EquipmentDB namespace that reads the equipment.xml, maps + equipment IDs to sprite definition files and thus allows gender specific + equipment sprites. + * data/graphics/sprites/chest-leather-female.png, + data/graphics/sprites/chest-leather-male.png, + data/graphics/sprites/chest-leather-female.xml, + data/graphics/sprites/chest-leather-male.xml, + data/equipment.xml: + Added and defined male and female leather shirt as proof of concept of the + gender specific equipment. + * data/graphics/tiles/desert_x2.png: Added new cactus by Yosuhara. + +2006-11-24 Philipp Sehmisch <tmw@crushnet.org> * src/engine.cpp, src/floor_item.cpp, src/item.h, src/main.cpp, src/gui/buy.cpp, src/gui/popupmenu.cpp, src/gui/sell.cpp, src/gui/shop.cpp, diff --git a/data/graphics/images/error.png b/data/graphics/images/error.png Binary files differnew file mode 100644 index 00000000..6fd7c1a8 --- /dev/null +++ b/data/graphics/images/error.png diff --git a/src/being.cpp b/src/being.cpp index 14d2df00..37552df3 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -62,7 +62,8 @@ Being::Being(Uint32 id, Uint16 job, Map *map): mSpeechTime(0), mDamageTime(0), mShowSpeech(false), mShowDamage(false), - mSprites(VECTOREND_SPRITE, NULL) + mSprites(VECTOREND_SPRITE, NULL), + mEquipmentSpriteIDs(VECTOREND_SPRITE, 0) { setMap(map); } @@ -122,8 +123,9 @@ Being::setHairStyle(Uint16 style) } void -Being::setVisibleEquipment(Uint8 slot, Uint8 id) +Being::setVisibleEquipment(Uint8 slot, int id) { + mEquipmentSpriteIDs[slot] = id; } void diff --git a/src/being.h b/src/being.h index 362fa393..3c497b75 100644 --- a/src/being.h +++ b/src/being.h @@ -189,7 +189,7 @@ class Being : public Sprite * Sets visible equipments for this being. */ virtual void - setVisibleEquipment(Uint8 slot, Uint8 id); + setVisibleEquipment(Uint8 slot, int id); /** * Sets the sex for this being. @@ -333,7 +333,6 @@ class Being : public Sprite getYOffset() const { return getOffset(UP, DOWN); } std::auto_ptr<Equipment> mEquipment; - int mVisibleEquipment[6]; /**< Visible equipments */ protected: /** @@ -372,6 +371,7 @@ class Being : public Sprite Sint32 mPx, mPy; /**< Pixel coordinates */ std::vector<AnimatedSprite*> mSprites; + std::vector<int> mEquipmentSpriteIDs; }; #endif diff --git a/src/engine.cpp b/src/engine.cpp index 0be41e2a..d0d37c67 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -44,6 +44,7 @@ #include "net/messageout.h" #include "net/protocol.h" + #include "resources/mapreader.h" #include "resources/resourcemanager.h" #include "resources/spriteset.h" diff --git a/src/main.cpp b/src/main.cpp index 5379086c..70bc469b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,6 +71,7 @@ #include "net/messageout.h" #include "net/network.h" +#include "resources/equipmentdb.h" #include "resources/image.h" #include "resources/itemdb.h" #include "resources/resourcemanager.h" @@ -305,7 +306,8 @@ void init_engine(const Options &options) logger->log("Warning: %s", err); } - // Initialize item database + // Load XML databases + EquipmentDB::load(); ItemDB::load(); } @@ -332,6 +334,8 @@ void exit_engine() ResourceManager::deleteInstance(); delete logger; + // Unload XML databases + EquipmentDB::unload(); ItemDB::unload(); } diff --git a/src/player.cpp b/src/player.cpp index df9b74f6..d6bd42f1 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -27,6 +27,8 @@ #include "game.h" #include "graphics.h" +#include "resources/equipmentdb.h" + #include "utils/tostring.h" #include "gui/gui.h" @@ -87,6 +89,7 @@ Player::setSex(Uint8 sex) { if (sex != mSex) { + //reload base sprite delete mSprites[BASE_SPRITE]; if (sex == 0) { @@ -98,7 +101,20 @@ Player::setSex(Uint8 sex) mSprites[BASE_SPRITE] = new AnimatedSprite( "graphics/sprites/player_female_base.xml", 0); } + + //reload equipment + for (int i=1; i<VECTOREND_SPRITE ; i++) + { + if (i != HAIR_SPRITE && mEquipmentSpriteIDs.at(i) != 0) + { + delete mSprites[i]; + mSprites[i] = new AnimatedSprite( + "graphics/sprites/" + EquipmentDB::get(mEquipmentSpriteIDs.at(i))->getSprite(sex), + 0); + } + } } + Being::setSex(sex); } @@ -170,7 +186,7 @@ Player::setHairStyle(Uint16 style) } void -Player::setVisibleEquipment(Uint8 slot, Uint8 id) +Player::setVisibleEquipment(Uint8 slot, int id) { // Translate eAthena specific slot Uint8 position = 0; @@ -194,11 +210,20 @@ Player::setVisibleEquipment(Uint8 slot, Uint8 id) } else { - char stringId[4]; - sprintf(stringId, "%03i", id); + AnimatedSprite *equipmentSprite; + + if (mSex == 0) + { + equipmentSprite = new AnimatedSprite( + "graphics/sprites/" + EquipmentDB::get(id)->getSprite(0), + 0); + } + else { + equipmentSprite = new AnimatedSprite( + "graphics/sprites/" + EquipmentDB::get(id)->getSprite(1), + 0); + } - AnimatedSprite *equipmentSprite = new AnimatedSprite( - "graphics/sprites/item" + toString(stringId) + ".xml", 0); equipmentSprite->setDirection(getSpriteDirection()); delete mSprites[position]; diff --git a/src/player.h b/src/player.h index dab081f8..d666a485 100644 --- a/src/player.h +++ b/src/player.h @@ -56,7 +56,7 @@ class Player : public Being setHairStyle(Uint16 style); virtual void - setVisibleEquipment(Uint8 slot, Uint8 id); + setVisibleEquipment(Uint8 slot, int id); virtual void setWeapon(Uint16 weapon); diff --git a/src/resources/equipmentdb.cpp b/src/resources/equipmentdb.cpp new file mode 100644 index 00000000..8bbfc177 --- /dev/null +++ b/src/resources/equipmentdb.cpp @@ -0,0 +1,157 @@ +/*
+ * The Mana World
+ * Copyright 2006 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:
+ */
+
+#include "equipmentdb.h"
+
+#include "resourcemanager.h"
+
+#include "../log.h"
+
+#include "../utils/dtor.h"
+#include "../utils/xml.h"
+
+namespace
+{
+ EquipmentDB::EquipmentInfos mEquipmentInfos;
+ EquipmentInfo mUnknown;
+ bool mLoaded = false;
+}
+
+void
+EquipmentDB::load()
+{
+ mUnknown.setSprite("error.xml", 0);
+ mUnknown.setSprite("error.xml", 1);
+
+ ResourceManager *resman = ResourceManager::getInstance();
+ int size;
+ char *data = (char*)resman->loadFile("equipment.xml", size);
+
+ if (!data)
+ {
+ logger->error("Equipment Database: Could not find equipment.xml!");
+ }
+
+ xmlDocPtr doc = xmlParseMemory(data, size);
+ free(data);
+
+ if (!doc)
+ {
+ logger->error("Equipment Database: Error while parsing equipment database (equipment.xml)!");
+ }
+
+ xmlNodePtr rootNode = xmlDocGetRootElement(doc);
+ if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "equipments"))
+ {
+ logger->error("Equipment Database: equipment.xml is not a valid database file!");
+ }
+
+ //iterate <equipment>s
+ for ( xmlNodePtr equipmentNode = rootNode->xmlChildrenNode;
+ equipmentNode != NULL;
+ equipmentNode = equipmentNode->next)
+ {
+
+ if (!xmlStrEqual(equipmentNode->name, BAD_CAST "equipment"))
+ {
+ continue;
+ }
+
+ EquipmentInfo *currentInfo = new EquipmentInfo();
+
+ currentInfo->setSlot (XML::getProperty(equipmentNode, "slot", 0));
+
+ //iterate <sprite>s
+ for ( xmlNodePtr spriteNode = equipmentNode->xmlChildrenNode;
+ spriteNode != NULL;
+ spriteNode = spriteNode->next)
+ {
+ if (!xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
+ {
+ continue;
+ }
+
+ std::string gender = XML::getProperty(spriteNode, "gender", "unisex");
+ std::string filename = (const char*) spriteNode->xmlChildrenNode->content;
+
+ if (gender == "male" || gender == "unisex")
+ {
+ currentInfo->setSprite(filename, 0);
+ }
+
+ if (gender == "female" || gender == "unisex")
+ {
+ currentInfo->setSprite(filename, 1);
+ }
+ }
+
+ setEquipment( XML::getProperty(equipmentNode, "id", 0),
+ currentInfo);
+ }
+
+ mLoaded = true;
+}
+
+void
+EquipmentDB::unload()
+{
+ // kill EquipmentInfos
+ for_each ( mEquipmentInfos.begin(), mEquipmentInfos.end(),
+ make_dtor(mEquipmentInfos));
+ mEquipmentInfos.clear();
+
+ mLoaded = false;
+}
+
+EquipmentInfo*
+EquipmentDB::get(int id)
+{
+ if (!mLoaded) {
+ logger->error("Error: Equipment database used before initialization!");
+ }
+
+ EquipmentInfoIterator i = mEquipmentInfos.find(id);
+
+ if (i == mEquipmentInfos.end() )
+ {
+ logger->log("EquipmentDB: Error, unknown equipment ID# %d", id);
+ return &mUnknown;
+ }
+ else
+ {
+ return i->second;
+ }
+}
+
+void
+EquipmentDB::setEquipment(int id, EquipmentInfo* equipmentInfo)
+{
+ if (mEquipmentInfos.find(id) != mEquipmentInfos.end()) {
+ logger->log("Warning: Equipment Piece with ID %d defined multiple times",
+ id);
+ delete equipmentInfo;
+ }
+ else {
+ mEquipmentInfos[id] = equipmentInfo;
+ };
+}
diff --git a/src/resources/equipmentdb.h b/src/resources/equipmentdb.h new file mode 100644 index 00000000..b8618f5f --- /dev/null +++ b/src/resources/equipmentdb.h @@ -0,0 +1,52 @@ +/*
+ * The Mana World
+ * Copyright 2006 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 _TMW_EQUIPMENT_DB_H
+#define _TMW_EQUIPMENT_DB_H
+
+#include <map>
+
+#include "equipmentinfo.h"
+
+namespace EquipmentDB
+{
+ /**
+ * Loads the equipment info from Items.xml
+ */
+ void load();
+
+ /**
+ * Frees equipment data
+ */
+ void unload();
+
+ void setEquipment(int id, EquipmentInfo* equipmentInfo);
+
+ EquipmentInfo* get(int id);
+
+ // Equipment database types
+ typedef std::map<int, EquipmentInfo*> EquipmentInfos;
+ typedef EquipmentInfos::iterator EquipmentInfoIterator;
+}
+
+#endif
diff --git a/src/resources/equipmentinfo.h b/src/resources/equipmentinfo.h new file mode 100644 index 00000000..bc3bdd8d --- /dev/null +++ b/src/resources/equipmentinfo.h @@ -0,0 +1,52 @@ +/*
+ * The Mana World
+ * Copyright 2006 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 _TMW_EQUIPMENTINFO_H_
+#define _TMW_EQUIPMENTINFO_H_
+
+#include <string>
+#include <map>
+
+class EquipmentInfo
+{
+ public:
+ EquipmentInfo():
+ mSlot (0)
+ {
+ };
+
+ void
+ setSlot (int slot) { mSlot = slot; };
+
+ std::string
+ getSprite(int gender) {return animationFiles[gender]; };
+
+ void
+ setSprite(std::string animationFile, int gender) {animationFiles[gender] = animationFile; };
+
+ private:
+ int mSlot; //not used at the moment but maybe useful on our own server
+ std::map<int, std::string> animationFiles;
+};
+
+#endif
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 2f791f07..d57a3780 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.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: itemmanager.cpp 2650 2006-09-03 15:00:47Z b_lindeijer $
+ * $Id:
*/
#include "itemdb.h"
@@ -38,9 +38,9 @@ target = cast((const char*)prop); \
xmlFree(prop); \
}
-namespace ItemDB
+namespace
{
- ItemInfos mItemInfos;
+ ItemDB::ItemInfos mItemInfos;
ItemInfo mUnknown;
}
diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 2821a2cf..5922984a 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -51,56 +51,3 @@ namespace ItemDB }
#endif
-/*
- * The Mana World
- * 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: itemdb.h 2650 2006-09-03 15:00:47Z b_lindeijer $
- */
-
-#ifndef _TMW_ITEM_MANAGER_H
-#define _TMW_ITEM_MANAGER_H
-
-#include "iteminfo.h"
-
-#include <map>
-
-/**
- * The namespace that holds the item information
- */
-namespace ItemDB
-{
- /**
- * Loads the item data from Items.xml
- */
- void load();
-
- /**
- * Frees item data
- */
- void unload();
-
- const ItemInfo& get(int id);
-
- // Items database
- typedef std::map<int, ItemInfo*> ItemInfos;
- typedef ItemInfos::iterator ItemInfoIterator;
-}
-
-#endif
|