diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-01-30 01:34:16 +0100 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-02-09 20:00:07 +0100 |
commit | 1b1050da1c7b84cc72b7efbb2229294975be9e10 (patch) | |
tree | 68d15ccb015d58aeb5797ffd06efca3e55997c24 /src/resources | |
parent | 0d4142a891cd228da24ee3aa3bbd7dc622da5b75 (diff) | |
parent | 955a7613d1fe116fe5e1da07a222b6849b3c885c (diff) | |
download | mana-1b1050da1c7b84cc72b7efbb2229294975be9e10.tar.gz mana-1b1050da1c7b84cc72b7efbb2229294975be9e10.tar.bz2 mana-1b1050da1c7b84cc72b7efbb2229294975be9e10.tar.xz mana-1b1050da1c7b84cc72b7efbb2229294975be9e10.zip |
Merged with Aethyra master as of 2009-01-27
Conflicts:
Almost everywhere.
Diffstat (limited to 'src/resources')
41 files changed, 580 insertions, 185 deletions
diff --git a/src/resources/action.cpp b/src/resources/action.cpp index 3fd3237e..e2cb11f2 100644 --- a/src/resources/action.cpp +++ b/src/resources/action.cpp @@ -20,12 +20,10 @@ */ #include "action.h" - #include "animation.h" #include "../utils/dtor.h" - Action::Action() { } diff --git a/src/resources/action.h b/src/resources/action.h index c557e6da..649d3828 100644 --- a/src/resources/action.h +++ b/src/resources/action.h @@ -44,11 +44,9 @@ class Action */ ~Action(); - void - setAnimation(int direction, Animation *animation); + void setAnimation(int direction, Animation *animation); - Animation* - getAnimation(int direction) const; + Animation* getAnimation(int direction) const; protected: typedef std::map<int, Animation*> Animations; diff --git a/src/resources/ambientoverlay.cpp b/src/resources/ambientoverlay.cpp index ef034acf..32ed47d1 100644 --- a/src/resources/ambientoverlay.cpp +++ b/src/resources/ambientoverlay.cpp @@ -20,7 +20,6 @@ */ #include "ambientoverlay.h" - #include "image.h" #include "../graphics.h" diff --git a/src/resources/animation.cpp b/src/resources/animation.cpp index 62e5ac16..8d7156a9 100644 --- a/src/resources/animation.cpp +++ b/src/resources/animation.cpp @@ -19,10 +19,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "animation.h" - #include <algorithm> +#include "animation.h" + #include "../utils/dtor.h" Animation::Animation(): @@ -30,22 +30,19 @@ Animation::Animation(): { } -void -Animation::addFrame(Image *image, unsigned int delay, int offsetX, int offsetY) +void Animation::addFrame(Image *image, unsigned int delay, int offsetX, int offsetY) { Frame frame = { image, delay, offsetX, offsetY }; mFrames.push_back(frame); mDuration += delay; } -void -Animation::addTerminator() +void Animation::addTerminator() { addFrame(NULL, 0, 0, 0); } -bool -Animation::isTerminator(const Frame &candidate) +bool Animation::isTerminator(const Frame &candidate) { return (candidate.image == NULL); } diff --git a/src/resources/animation.h b/src/resources/animation.h index 29c99209..0c461ebe 100644 --- a/src/resources/animation.h +++ b/src/resources/animation.h @@ -54,39 +54,33 @@ class Animation /** * Appends a new animation at the end of the sequence. */ - void - addFrame(Image *image, unsigned int delay, int offsetX, int offsetY); + void addFrame(Image *image, unsigned int delay, int offsetX, int offsetY); /** * Appends an animation terminator that states that the animation * should not loop. */ - void - addTerminator(); + void addTerminator(); /** * Returns the frame at the specified index. */ - Frame* - getFrame(int index) { return &(mFrames[index]); } + Frame* getFrame(int index) { return &(mFrames[index]); } /** * Returns the length of this animation in frames. */ - unsigned int - getLength() const { return mFrames.size(); } + unsigned int getLength() const { return mFrames.size(); } /** * Returns the duration of this animation. */ - int - getDuration() const { return mDuration; } + int getDuration() const { return mDuration; } /** * Determines whether the given animation frame is a terminator. */ - static bool - isTerminator(const Frame &phase); + static bool isTerminator(const Frame &phase); protected: std::vector<Frame> mFrames; diff --git a/src/resources/buddylist.cpp b/src/resources/buddylist.cpp index 24198f59..541acabe 100644 --- a/src/resources/buddylist.cpp +++ b/src/resources/buddylist.cpp @@ -21,13 +21,13 @@ #include <algorithm> #include <cstring> -#include <iostream> #include <fstream> +#include <iostream> #include "buddylist.h" -#include "../main.h" #include "../configuration.h" +#include "../main.h" BuddyList::BuddyList() { @@ -111,7 +111,7 @@ bool BuddyList::removeBuddy(const std::string buddy) return false; } -int BuddyList::getNumberOfElements() +int BuddyList::getNumberOfElements() { return mBuddylist.size(); } diff --git a/src/resources/buddylist.h b/src/resources/buddylist.h index 33fcde4d..d769b2b8 100644 --- a/src/resources/buddylist.h +++ b/src/resources/buddylist.h @@ -52,7 +52,7 @@ class BuddyList : public gcn::ListModel { /** * Returns the number of buddy on the list */ - int getNumberOfElements(); + int getNumberOfElements(); /** * Returns the buddy of the number or null diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp new file mode 100644 index 00000000..f80ca6b3 --- /dev/null +++ b/src/resources/colordb.cpp @@ -0,0 +1,125 @@ +/* + * Aethyra + * Copyright 2008 Aethyra Development Team + * + * This file is part of Aethyra. + * + * Aethyra 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. + * + * Aethyra 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 Aethyra; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <cassert> +#include <libxml/tree.h> + +#include "colordb.h" + +#include "../log.h" + +#include "../utils/dtor.h" +#include "../utils/gettext.h" +#include "../utils/xml.h" + +#define HAIR_COLOR_FILE "colors.xml" +#define TMW_COLOR_FILE "hair.xml" + +namespace +{ + ColorDB::Colors mColors; + bool mLoaded = false; + std::string mFail = "#ffffff"; +} + +void ColorDB::load() +{ + if (mLoaded) + { + return; + } + + XML::Document *doc = new XML::Document(HAIR_COLOR_FILE); + xmlNodePtr root = doc->rootNode(); + bool TMWHair = false; + + if (!root || !xmlStrEqual(root->name, BAD_CAST "colors")) + { + logger->log(_("Trying TMW's color file, %s."), TMW_COLOR_FILE); + + TMWHair = true; + + delete doc; + + doc = new XML::Document(TMW_COLOR_FILE); + root = doc->rootNode(); + if (!root || !xmlStrEqual(root->name, BAD_CAST "colors")) + { + logger->log(_("ColorDB: Failed")); + mColors[0] = mFail; + mLoaded = true; + + delete doc; + + return; + } + } + for_each_xml_child_node(node, root) + { + if (xmlStrEqual(node->name, BAD_CAST "color")) + { + int id = XML::getProperty(node, "id", 0); + + if (mColors.find(id) != mColors.end()) + { + logger->log(_("ColorDB: Redefinition of dye ID %d"), id); + } + + TMWHair ? mColors[id] = XML::getProperty(node, "value", "#FFFFFF") : + mColors[id] = XML::getProperty(node, "dye", "#FFFFFF"); + } + } + + delete doc; + + mLoaded = true; +} + +void ColorDB::unload() +{ + logger->log(_("Unloading color database...")); + + mColors.clear(); + mLoaded = false; +} + +std::string& ColorDB::get(int id) +{ + if(!mLoaded) + load(); + + ColorIterator i = mColors.find(id); + + if (i == mColors.end()) + { + logger->log(_("ColorDB: Error, unknown dye ID# %d"), id); + return mFail; + } + else + { + return i->second; + } +} + +int ColorDB::size() +{ + return mColors.size(); +} diff --git a/src/resources/colordb.h b/src/resources/colordb.h new file mode 100644 index 00000000..65b7f759 --- /dev/null +++ b/src/resources/colordb.h @@ -0,0 +1,52 @@ +/* + * Aethyra + * Copyright 2008 Aethyra Development Team + * + * This file is part of Aethyra. + * + * Aethyra 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. + * + * Aethyra 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 Aethyra; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef COLOR_MANAGER_H +#define COLOR_MANAGER_H + +#include <map> +#include <string> + +/** + * The class that holds the color information. + */ +namespace ColorDB +{ + /** + * Loads the color data from <code>colors.xml</code>. + */ + void load(); + + /** + * Clear the color data + */ + void unload(); + + std::string& get(int id); + + int size(); + + // Color DB + typedef std::map<int, std::string> Colors; + typedef Colors::iterator ColorIterator; +} + +#endif diff --git a/src/resources/dye.h b/src/resources/dye.h index d32c3f22..3cef334a 100644 --- a/src/resources/dye.h +++ b/src/resources/dye.h @@ -22,6 +22,7 @@ #ifndef DYE_H #define DYE_H +#include <string> #include <vector> /** @@ -36,7 +37,7 @@ class Palette * The string is either a file name or a sequence of hexadecimal RGB * values separated by ',' and starting with '#'. */ - Palette(const std::string &); + Palette(const std::string &pallete); /** * Gets a pixel color depending on its intensity. @@ -63,7 +64,7 @@ class Dye * The parts of string are separated by semi-colons. Each part starts * by an uppercase letter, followed by a colon and then a palette name. */ - Dye(const std::string &); + Dye(const std::string &dye); /** * Destroys the associated palettes. diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp new file mode 100644 index 00000000..2f43822d --- /dev/null +++ b/src/resources/emotedb.cpp @@ -0,0 +1,143 @@ +/* + * Aethyra + * Copyright 2009 Aethyra Development Team + * + * This file is part of Aethyra. + * + * Aethyra 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. + * + * Aethyra 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 Aethyra; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "emotedb.h" +#include "resourcemanager.h" + +#include "../log.h" + +#include "../utils/dtor.h" +#include "../utils/gettext.h" +#include "../utils/xml.h" + +namespace +{ + EmoteInfos mEmoteInfos; + EmoteInfo mUnknown; + bool mLoaded = false; + int mLastEmote = 0; +} + +void EmoteDB::load() +{ + if (mLoaded) + return; + + mLastEmote = 0; + + EmoteSprite *unknownSprite = new EmoteSprite; + unknownSprite->sprite = "error.xml"; + unknownSprite->name = "unknown"; + unknownSprite->variant = 0; + mUnknown.sprites.push_back(unknownSprite); + + logger->log(_("Initializing emote database...")); + + XML::Document doc("emotes.xml"); + xmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "emotes")) + { + logger->log(_("Emote Database: Error while loading emotes.xml!")); + return; + } + + //iterate <emote>s + for_each_xml_child_node(emoteNode, rootNode) + { + if (!xmlStrEqual(emoteNode->name, BAD_CAST "emote")) + continue; + + int id = XML::getProperty(emoteNode, "id", -1); + if (id == -1) + { + logger->log(_("Emote Database: Emote with missing ID in emotes.xml!")); + continue; + } + + EmoteInfo *currentInfo = new EmoteInfo; + + for_each_xml_child_node(spriteNode, emoteNode) + { + if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) + { + EmoteSprite *currentSprite = new EmoteSprite; + currentSprite->sprite = (const char*) spriteNode->xmlChildrenNode->content; + currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); + currentInfo->sprites.push_back(currentSprite); + } + else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) + { + std::string particlefx = (const char*) spriteNode->xmlChildrenNode->content; + currentInfo->particles.push_back(particlefx); + } + } + mEmoteInfos[id] = currentInfo; + if (id > mLastEmote) mLastEmote = id; + } + + mLoaded = true; +} + +void EmoteDB::unload() +{ + for ( EmoteInfosIterator i = mEmoteInfos.begin(); + i != mEmoteInfos.end(); + i++) + { + while (!i->second->sprites.empty()) + { + delete i->second->sprites.front(); + i->second->sprites.pop_front(); + } + delete i->second; + } + + mEmoteInfos.clear(); + + while (!mUnknown.sprites.empty()) + { + delete mUnknown.sprites.front(); + mUnknown.sprites.pop_front(); + } + + mLoaded = false; +} + +const EmoteInfo& EmoteDB::get(int id) +{ + EmoteInfosIterator i = mEmoteInfos.find(id); + + if (i == mEmoteInfos.end()) + { + logger->log(_("EmoteDB: Warning, unknown emote ID %d requested"), id); + return mUnknown; + } + else + { + return *(i->second); + } +} + +const int& EmoteDB::getLast() +{ + return mLastEmote; +} diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h new file mode 100644 index 00000000..0962edad --- /dev/null +++ b/src/resources/emotedb.h @@ -0,0 +1,60 @@ +/* + * Aethyra + * Copyright 2009 Aethyra Development Team + * + * This file is part of Aethyra. + * + * Aethyra 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. + * + * Aethyra 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 Aethyra; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef EMOTE_DB_H +#define EMOTE_DB_H + +#include <list> +#include <map> +#include <string> + +struct EmoteSprite +{ + std::string sprite; + std::string name; + int variant; +}; + +struct EmoteInfo +{ + std::list<EmoteSprite*> sprites; + std::list<std::string> particles; +}; + +typedef std::map<int, EmoteInfo*> EmoteInfos; + +/** + * Emote information database. + */ +namespace EmoteDB +{ + void load(); + + void unload(); + + const EmoteInfo& get(int id); + + const int& getLast(); + + typedef EmoteInfos::iterator EmoteInfosIterator; +} + +#endif diff --git a/src/resources/image.cpp b/src/resources/image.cpp index cc986c81..c3310849 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -21,9 +21,8 @@ #include <SDL_image.h> -#include "image.h" - #include "dye.h" +#include "image.h" #include "../log.h" diff --git a/src/resources/image.h b/src/resources/image.h index 963fbb24..a4048803 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -22,9 +22,10 @@ #ifndef IMAGE_H #define IMAGE_H +#include <SDL.h> + #include "../main.h" -#include <SDL.h> #ifdef USE_OPENGL /* The definition of OpenGL extensions by SDL is giving problems with recent @@ -96,7 +97,6 @@ class Image : public Resource virtual int getWidth() const { return mBounds.w; } - /** * Returns the height of the image. */ @@ -129,7 +129,6 @@ class Image : public Resource static void setLoadAsOpenGL(bool useOpenGL); #endif - protected: /** * Constructor. diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp index 5aad7c52..7895d33d 100644 --- a/src/resources/imageloader.cpp +++ b/src/resources/imageloader.cpp @@ -21,12 +21,12 @@ #include <cassert> #include <string> + #include <guichan/color.hpp> #include <guichan/sdl/sdlpixel.hpp> -#include "imageloader.h" - #include "image.h" +#include "imageloader.h" #include "resourcemanager.h" ProxyImage::ProxyImage(SDL_Surface *s): diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp index 458b0405..92bb3242 100644 --- a/src/resources/imageset.cpp +++ b/src/resources/imageset.cpp @@ -19,12 +19,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "image.h" #include "imageset.h" #include "../log.h" -#include "image.h" - #include "../utils/dtor.h" ImageSet::ImageSet(Image *img, int width, int height) @@ -45,8 +44,7 @@ ImageSet::~ImageSet() delete_all(mImages); } -Image* -ImageSet::get(size_type i) const +Image* ImageSet::get(size_type i) const { if (i >= mImages.size()) { diff --git a/src/resources/imageset.h b/src/resources/imageset.h index 00a36754..f59c76bb 100644 --- a/src/resources/imageset.h +++ b/src/resources/imageset.h @@ -28,7 +28,6 @@ class Image; - /** * Stores a set of subimages originating from a single image. */ diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index d6bb4659..c350ac07 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -19,11 +19,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "imagewriter.h" - #include <png.h> -#include <string> #include <SDL.h> +#include <string> + +#include "imagewriter.h" #include "../log.h" diff --git a/src/resources/imagewriter.h b/src/resources/imagewriter.h index 8eb6cead..a9133846 100644 --- a/src/resources/imagewriter.h +++ b/src/resources/imagewriter.h @@ -27,5 +27,5 @@ class ImageWriter { public: static bool writePNG(SDL_Surface *surface, - const std::string &filename); + const std::string &filename); }; diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 1678eda8..773febd7 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -20,10 +20,10 @@ */ #include <cassert> + #include <libxml/tree.h> #include "itemdb.h" - #include "iteminfo.h" #include "resourcemanager.h" @@ -36,6 +36,7 @@ namespace { ItemDB::ItemInfos mItemInfos; + ItemDB::NamedItemInfos mNamedItemInfos; ItemInfo *mUnknown; bool mLoaded = false; } @@ -49,20 +50,20 @@ void ItemDB::load() if (mLoaded) return; - logger->log("Initializing item database..."); + logger->log(_("Initializing item database...")); mUnknown = new ItemInfo(); - mUnknown->setName("Unknown item"); + mUnknown->setName(_("Unknown item")); mUnknown->setImageName(""); mUnknown->setSprite("error.xml", GENDER_MALE); mUnknown->setSprite("error.xml", GENDER_FEMALE); - XML::Document doc("items.xml"); + XML::Document doc(_("items.xml")); xmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "items")) { - logger->error("ItemDB: Error while loading items.xml!"); + logger->error(_("ItemDB: Error while loading items.xml!")); } for_each_xml_child_node(node, rootNode) @@ -74,12 +75,12 @@ void ItemDB::load() if (id == 0) { - logger->log("ItemDB: Invalid or missing item ID in items.xml!"); + logger->log(_("ItemDB: Invalid or missing item ID in items.xml!")); continue; } else if (mItemInfos.find(id) != mItemInfos.end()) { - logger->log("ItemDB: Redefinition of item ID %d", id); + logger->log(_("ItemDB: Redefinition of item ID %d"), id); } int type = XML::getProperty(node, "type", 0); @@ -95,6 +96,7 @@ void ItemDB::load() if (id) { ItemInfo *itemInfo = new ItemInfo; + itemInfo->setId(id); itemInfo->setImageName(image); itemInfo->setName(name.empty() ? _("Unnamed") : name); itemInfo->setDescription(description); @@ -117,6 +119,34 @@ void ItemDB::load() } mItemInfos[id] = itemInfo; + if (!name.empty()) + { + NamedItemInfoIterator itr = mNamedItemInfos.find(name); + if (itr == mNamedItemInfos.end()) + { + std::string temp = name; + while (temp[0] == ' ') + { + temp = temp.substr(1, temp.size()); + } + while (temp[temp.size()] == ' ') + { + temp = temp.substr(0, temp.size() - 1); + } + + for (unsigned int i = 0; i < temp.size(); i++) + { + temp[i] = (char) tolower(temp[i]); + } + + mNamedItemInfos[temp] = itemInfo; + } + else + { + logger->log(_("ItemDB: Duplicate name of item found item %d"), + id); + } + } } #define CHECK_PARAM(param, error_value) \ @@ -126,9 +156,9 @@ void ItemDB::load() CHECK_PARAM(name, ""); CHECK_PARAM(image, ""); CHECK_PARAM(description, ""); - CHECK_PARAM(effect, ""); + // CHECK_PARAM(effect, ""); // CHECK_PARAM(type, 0); - // CHECK_PARAM(weight, 0); + CHECK_PARAM(weight, 0); // CHECK_PARAM(slot, 0); #undef CHECK_PARAM @@ -139,7 +169,7 @@ void ItemDB::load() void ItemDB::unload() { - logger->log("Unloading item database..."); + logger->log(_("Unloading item database...")); delete mUnknown; mUnknown = NULL; @@ -157,7 +187,24 @@ const ItemInfo& ItemDB::get(int id) if (i == mItemInfos.end()) { - logger->log("ItemDB: Error, unknown item ID# %d", id); + logger->log(_("ItemDB: Error, unknown item ID# %d"), id); + return *mUnknown; + } + else + { + return *(i->second); + } +} + +const ItemInfo& ItemDB::get(const std::string &name) +{ + assert(mLoaded && !name.empty()); + + NamedItemInfoIterator i = mNamedItemInfos.find(name); + + if (i == mNamedItemInfos.end()) + { + logger->log("ItemDB: Error, unknown item name %s", name.c_str()); return *mUnknown; } else @@ -175,7 +222,6 @@ void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) { itemInfo->setSprite(filename, GENDER_MALE); } - if (gender == "female" || gender == "unisex") { itemInfo->setSprite(filename, GENDER_FEMALE); @@ -197,7 +243,7 @@ void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node) } else { - logger->log("ItemDB: Ignoring unknown sound event '%s'", + logger->log(_("ItemDB: Ignoring unknown sound event '%s'"), event.c_str()); } } diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 03fb1eed..e7c23ca2 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -22,10 +22,10 @@ #ifndef ITEM_MANAGER_H #define ITEM_MANAGER_H -#include "iteminfo.h" - #include <map> +#include "iteminfo.h" + /** * The namespace that holds the item information. */ @@ -42,10 +42,13 @@ namespace ItemDB void unload(); const ItemInfo& get(int id); + const ItemInfo& get(const std::string &name); // Items database typedef std::map<int, ItemInfo*> ItemInfos; + typedef std::map<std::string, ItemInfo*> NamedItemInfos; typedef ItemInfos::iterator ItemInfoIterator; + typedef NamedItemInfos::iterator NamedItemInfoIterator; } #endif diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index b924c591..2f118284 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -19,12 +19,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "iteminfo.h" - #include "itemdb.h" +#include "iteminfo.h" -const std::string& -ItemInfo::getSprite(Gender gender) const +const std::string& ItemInfo::getSprite(Gender gender) const { if (mView) { @@ -67,15 +65,12 @@ void ItemInfo::setWeaponType(int type) } } -void -ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename) +void ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename) { mSounds[event].push_back("sfx/" + filename); } - -const std::string& -ItemInfo::getSound(EquipmentSoundEvent event) const +const std::string& ItemInfo::getSound(EquipmentSoundEvent event) const { static const std::string empty; std::map< EquipmentSoundEvent, std::vector<std::string> >::const_iterator i; diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index a04213ff..86725ca2 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -54,6 +54,12 @@ class ItemInfo { } + void setId(int id) + { mId = id; } + + int getId() const + { return mId; } + void setName(const std::string &name) { mName = name; } @@ -115,6 +121,7 @@ class ItemInfo char mType; /**< Item type. */ short mWeight; /**< Weight in grams. */ int mView; /**< Item ID of how this item looks. */ + int mId; /**< Item ID */ // Equipment related members SpriteAction mAttackType; /**< Attack type, in case of weapon. */ diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 21125c2a..ddf48df0 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -19,14 +19,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "mapreader.h" - #include <cassert> #include <iostream> #include <zlib.h> -#include "resourcemanager.h" #include "image.h" +#include "mapreader.h" +#include "resourcemanager.h" #include "../log.h" #include "../map.h" @@ -205,14 +204,11 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path) // Take the filename off the path const std::string pathDir = path.substr(0, path.rfind("/") + 1); - //xmlChar *prop = xmlGetProp(node, BAD_CAST "version"); - //xmlFree(prop); - const int w = XML::getProperty(node, "width", 0); const int h = XML::getProperty(node, "height", 0); - const int tw = XML::getProperty(node, "tilewidth", DEFAULT_TILE_WIDTH); - const int th = XML::getProperty(node, "tileheight", DEFAULT_TILE_HEIGHT); - Map *map = new Map(w, h, tw, th); + const int tilew = XML::getProperty(node, "tilewidth", DEFAULT_TILE_WIDTH); + const int tileh = XML::getProperty(node, "tileheight", DEFAULT_TILE_HEIGHT); + Map *map = new Map(w, h, tilew, tileh); for_each_xml_child_node(childNode, node) { @@ -236,8 +232,8 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path) // The object group offset is applied to each object individually const int tileOffsetX = XML::getProperty(childNode, "x", 0); const int tileOffsetY = XML::getProperty(childNode, "y", 0); - const int offsetX = tileOffsetX * tw; - const int offsetY = tileOffsetY * th; + const int offsetX = tileOffsetX * tilew; + const int offsetY = tileOffsetY * tileh; for_each_xml_child_node(objectNode, childNode) { @@ -326,8 +322,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) const int offsetY = XML::getProperty(node, "y", 0); const std::string name = XML::getProperty(node, "name", ""); - const bool isFringeLayer = (name == "Fringe"); - const bool isCollisionLayer = (name == "Collision"); + const bool isFringeLayer = (name.substr(0,6) == "Fringe"); + const bool isCollisionLayer = (name.substr(0,9) == "Collision"); MapLayer *layer = 0; @@ -370,7 +366,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) while (*charStart) { if (*charStart != ' ' && *charStart != '\t' && - *charStart != '\n') + *charStart != '\n') { *charIndex = *charStart; charIndex++; @@ -461,15 +457,20 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path, Map *map) { + int firstGid = XML::getProperty(node, "firstgid", 0); + XML::Document* doc = NULL; Tileset *set = NULL; if (xmlHasProp(node, BAD_CAST "source")) { - logger->log("Warning: External tilesets not supported yet."); - return set; + std::string filename = XML::getProperty(node, "source", ""); + while (filename.substr(0, 3) == "../") + filename.erase(0, 3); // Remove "../" + doc = new XML::Document(filename); + node = doc->rootNode(); + firstGid += XML::getProperty(node, "firstgid", 0); } - const int firstGid = XML::getProperty(node, "firstgid", 0); const int tw = XML::getProperty(node, "tilewidth", map->getTileWidth()); const int th = XML::getProperty(node, "tileheight", map->getTileHeight()); @@ -545,5 +546,7 @@ Tileset *MapReader::readTileset(xmlNodePtr node, } } + delete doc; + return set; } diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h index 8cb2749d..ef945c3f 100644 --- a/src/resources/mapreader.h +++ b/src/resources/mapreader.h @@ -26,8 +26,8 @@ #include <libxml/tree.h> -class Properties; class Map; +class Properties; class Tileset; /** diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 5d452db2..c7926260 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -20,12 +20,12 @@ */ #include "monsterdb.h" - #include "resourcemanager.h" #include "../log.h" #include "../utils/dtor.h" +#include "../utils/gettext.h" #include "../utils/xml.h" namespace @@ -35,23 +35,22 @@ namespace bool mLoaded = false; } -void -MonsterDB::load() +void MonsterDB::load() { if (mLoaded) return; mUnknown.addSprite("error.xml"); - mUnknown.setName("unnamed"); + mUnknown.setName(_("unnamed")); - logger->log("Initializing monster database..."); + logger->log(_("Initializing monster database...")); - XML::Document doc("monsters.xml"); + XML::Document doc(_("monsters.xml")); xmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "monsters")) { - logger->error("Monster Database: Error while loading monster.xml!"); + logger->error(_("Monster Database: Error while loading monster.xml!")); } //iterate <monster>s @@ -82,7 +81,7 @@ MonsterDB::load() } else { - logger->log("MonsterDB: Unknown target cursor type \"%s\" for %s - using medium sized one", + logger->log(_("MonsterDB: Unknown target cursor type \"%s\" for %s - using medium sized one"), targetCursor.c_str(), currentInfo->getName().c_str()); currentInfo->setTargetCursorSize(Being::TC_MEDIUM); } @@ -119,11 +118,17 @@ MonsterDB::load() } else { - logger->log("MonsterDB: Warning, sound effect %s for unknown event %s of monster %s", + logger->log(_("MonsterDB: Warning, sound effect %s for unknown event %s of monster %s"), filename, event.c_str(), currentInfo->getName().c_str()); } } + if (xmlStrEqual(spriteNode->name, BAD_CAST "attack")) + { + std::string event = XML::getProperty(spriteNode, "particle-effect", ""); + currentInfo->addAttackParticleEffect(event); + } + if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) { currentInfo->addParticleEffect( @@ -151,7 +156,7 @@ const MonsterInfo &MonsterDB::get(int id) if (i == mMonsterInfos.end()) { - logger->log("MonsterDB: Warning, unknown monster ID %d requested", id); + logger->log(_("MonsterDB: Warning, unknown monster ID %d requested"), id); return mUnknown; } else diff --git a/src/resources/monsterdb.h b/src/resources/monsterdb.h index 8555670b..6fbde55f 100644 --- a/src/resources/monsterdb.h +++ b/src/resources/monsterdb.h @@ -31,11 +31,9 @@ */ namespace MonsterDB { - void - load(); + void load(); - void - unload(); + void unload(); const MonsterInfo& get(int id); diff --git a/src/resources/monsterinfo.cpp b/src/resources/monsterinfo.cpp index d8ff8be3..503990e7 100644 --- a/src/resources/monsterinfo.cpp +++ b/src/resources/monsterinfo.cpp @@ -36,8 +36,7 @@ MonsterInfo::~MonsterInfo() } -void -MonsterInfo::addSound(MonsterSoundEvent event, std::string filename) +void MonsterInfo::addSound(MonsterSoundEvent event, std::string filename) { if (mSounds.find(event) == mSounds.end()) { @@ -48,8 +47,7 @@ MonsterInfo::addSound(MonsterSoundEvent event, std::string filename) } -std::string -MonsterInfo::getSound(MonsterSoundEvent event) const +std::string MonsterInfo::getSound(MonsterSoundEvent event) const { std::map<MonsterSoundEvent, std::vector<std::string>* >::const_iterator i; diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h index b37ac1a9..75464035 100644 --- a/src/resources/monsterinfo.h +++ b/src/resources/monsterinfo.h @@ -22,14 +22,13 @@ #ifndef MONSTERINFO_H #define MONSTERINFO_H +#include <list> #include <map> #include <string> #include <vector> -#include <list> #include "../being.h" - enum MonsterSoundEvent { MONSTER_EVENT_HIT, @@ -57,39 +56,39 @@ class MonsterInfo */ ~MonsterInfo(); - void - setName(std::string name) { mName = name; } + void setName(std::string name) { mName = name; } - void - addSprite(std::string filename) { mSprites.push_back(filename); } + void addSprite(std::string filename) { mSprites.push_back(filename); } - void - setTargetCursorSize(Being::TargetCursorSize targetCursorSize) + void setTargetCursorSize(Being::TargetCursorSize targetCursorSize) { mTargetCursorSize = targetCursorSize; } - void - addSound(MonsterSoundEvent event, std::string filename); + void addSound(MonsterSoundEvent event, std::string filename); + + void addParticleEffect(std::string filename); + + const std::string& getName() const + { return mName; } - void - addParticleEffect(std::string filename); + const std::list<std::string>& getSprites() const + { return mSprites; } - const std::string& - getName() const { return mName; } + Being::TargetCursorSize getTargetCursorSize() const + { return mTargetCursorSize; } - const std::list<std::string>& - getSprites() const { return mSprites; } + std::string getSound(MonsterSoundEvent event) const; - Being::TargetCursorSize - getTargetCursorSize() const { return mTargetCursorSize; } + std::string getAttackParticleEffect() const { return mAttackParticle; } - std::string - getSound(MonsterSoundEvent event) const; + void addAttackParticleEffect(const std::string &particleEffect) + { mAttackParticle = particleEffect; } - const std::list<std::string>& - getParticleEffects() const { return mParticleEffects; } + const std::list<std::string>& getParticleEffects() const + { return mParticleEffects; } private: std::string mName; + std::string mAttackParticle; std::list<std::string> mSprites; Being::TargetCursorSize mTargetCursorSize; std::map<MonsterSoundEvent, std::vector<std::string>* > mSounds; diff --git a/src/resources/music.cpp b/src/resources/music.cpp index 3b81d05b..ed78a541 100644 --- a/src/resources/music.cpp +++ b/src/resources/music.cpp @@ -55,8 +55,7 @@ Resource *Music::load(void *buffer, unsigned bufferSize) } } -bool -Music::play(int loops) +bool Music::play(int loops) { /* * Warning: loops should be always set to -1 (infinite) with current @@ -71,8 +70,7 @@ Music::play(int loops) return mChannel != -1; } -void -Music::stop() +void Music::stop() { /* * Warning: very dungerous trick, it could try to stop channels occupied diff --git a/src/resources/music.h b/src/resources/music.h index cff18338..65f1ee88 100644 --- a/src/resources/music.h +++ b/src/resources/music.h @@ -56,14 +56,12 @@ class Music : public Resource * @return <code>true</code> if the playback started properly * <code>false</code> otherwise. */ - virtual bool - play(int loops); + virtual bool play(int loops); /** * Stops the music. */ - virtual void - stop(); + virtual void stop(); protected: /** diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index 9faef60d..88572481 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -20,12 +20,12 @@ */ #include "npcdb.h" - #include "resourcemanager.h" #include "../log.h" #include "../utils/dtor.h" +#include "../utils/gettext.h" #include "../utils/xml.h" namespace @@ -45,17 +45,17 @@ void NPCDB::load() unknownSprite->variant = 0; mUnknown.sprites.push_back(unknownSprite); - logger->log("Initializing NPC database..."); + logger->log(_("Initializing NPC database...")); XML::Document doc("npcs.xml"); xmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "npcs")) { - logger->error("NPC Database: Error while loading items.xml!"); + logger->error(_("NPC Database: Error while loading npcs.xml!")); } - //iterate <monster>s + //iterate <npc>s for_each_xml_child_node(npcNode, rootNode) { if (!xmlStrEqual(npcNode->name, BAD_CAST "npc")) @@ -64,7 +64,7 @@ void NPCDB::load() int id = XML::getProperty(npcNode, "id", 0); if (id == 0) { - logger->log("NPC Database: NPC with missing ID in npcs.xml!"); + logger->log(_("NPC Database: NPC with missing ID in npcs.xml!")); continue; } @@ -91,8 +91,7 @@ void NPCDB::load() mLoaded = true; } -void -NPCDB::unload() +void NPCDB::unload() { for ( NPCInfosIterator i = mNPCInfos.begin(); i != mNPCInfos.end(); @@ -117,14 +116,13 @@ NPCDB::unload() mLoaded = false; } -const NPCInfo& -NPCDB::get(int id) +const NPCInfo& NPCDB::get(int id) { NPCInfosIterator i = mNPCInfos.find(id); if (i == mNPCInfos.end()) { - logger->log("NPCDB: Warning, unknown NPC ID %d requested", id); + logger->log(_("NPCDB: Warning, unknown NPC ID %d requested"), id); return mUnknown; } else diff --git a/src/resources/npcdb.h b/src/resources/npcdb.h index a7f28c50..af6764bf 100644 --- a/src/resources/npcdb.h +++ b/src/resources/npcdb.h @@ -22,8 +22,8 @@ #ifndef NPC_DB_H #define NPC_DB_H -#include <map> #include <list> +#include <map> #include <string> struct NPCsprite @@ -45,11 +45,9 @@ typedef std::map<int, NPCInfo*> NPCInfos; */ namespace NPCDB { - void - load(); + void load(); - void - unload(); + void unload(); const NPCInfo& get(int id); diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index 4c173962..d1c3ada4 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -22,21 +22,18 @@ #include <cassert> #include "resource.h" - #include "resourcemanager.h" Resource::~Resource() { } -void -Resource::incRef() +void Resource::incRef() { mRefCount++; } -void -Resource::decRef() +void Resource::decRef() { // Reference may not already have reached zero assert(mRefCount != 0); diff --git a/src/resources/resource.h b/src/resources/resource.h index 0dc50c03..303b82c8 100644 --- a/src/resources/resource.h +++ b/src/resources/resource.h @@ -41,8 +41,7 @@ class Resource /** * Increments the internal reference count. */ - void - incRef(); + void incRef(); /** * Decrements the reference count and deletes the object @@ -51,8 +50,7 @@ class Resource * @return <code>true</code> if the object was deleted * <code>false</code> otherwise. */ - void - decRef(); + void decRef(); /** * Return the path identifying this resource. diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index febcf0d0..3f58076e 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -20,24 +20,22 @@ */ #include <cassert> -#include <sstream> -#include <sys/time.h> - #include <physfs.h> #include <SDL_image.h> +#include <sstream> -#include "resourcemanager.h" +#include <sys/time.h> #include "dye.h" #include "image.h" +#include "imageset.h" #include "music.h" +#include "resourcemanager.h" #include "soundeffect.h" -#include "imageset.h" #include "spritedef.h" #include "../log.h" - ResourceManager *ResourceManager::instance = NULL; ResourceManager::ResourceManager() @@ -155,8 +153,8 @@ bool ResourceManager::addToSearchPath(const std::string &path, bool append) } void ResourceManager::searchAndAddArchives(const std::string &path, - const std::string &ext, - bool append) + const std::string &ext, + bool append) { const char *dirSep = PHYSFS_getDirSeparator(); char **list = PHYSFS_enumerateFiles(path.c_str()); @@ -420,8 +418,7 @@ void *ResourceManager::loadFile(const std::string &fileName, int &fileSize) return buffer; } -std::vector<std::string> -ResourceManager::loadTextFile(const std::string &fileName) +std::vector<std::string> ResourceManager::loadTextFile(const std::string &fileName) { int contentsLength; char *fileContents = (char*)loadFile(fileName, contentsLength); diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 6a7a2ed6..73f55fd3 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -27,11 +27,11 @@ #include <string> #include <vector> -class Resource; class Image; +class ImageSet; class Music; +class Resource; class SoundEffect; -class ImageSet; class SpriteDef; struct SDL_Surface; diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp index 21488511..3a285730 100644 --- a/src/resources/soundeffect.cpp +++ b/src/resources/soundeffect.cpp @@ -47,8 +47,7 @@ Resource *SoundEffect::load(void *buffer, unsigned bufferSize) } } -bool -SoundEffect::play(int loops, int volume) +bool SoundEffect::play(int loops, int volume) { Mix_VolumeChunk(mChunk, volume); diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h index 5f511b29..05ec9e54 100644 --- a/src/resources/soundeffect.h +++ b/src/resources/soundeffect.h @@ -58,8 +58,7 @@ class SoundEffect : public Resource * @return <code>true</code> if the playback started properly * <code>false</code> otherwise. */ - virtual bool - play(int loops, int volume); + virtual bool play(int loops, int volume); protected: /** diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 64ce8b0a..af3281be 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -21,14 +21,13 @@ #include <set> -#include "spritedef.h" - #include "action.h" #include "animation.h" #include "dye.h" #include "image.h" #include "imageset.h" #include "resourcemanager.h" +#include "spritedef.h" #include "../log.h" #include "../utils/xml.h" diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index b86a4c4d..b9d7b85d 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -25,10 +25,10 @@ #include <map> #include <string> -#include "resource.h" - #include <libxml/tree.h> +#include "resource.h" + class Action; class ImageSet; @@ -89,7 +89,6 @@ class SpriteDef : public Resource static SpriteDirection makeSpriteDirection(const std::string &direction); - private: /** * Constructor. @@ -140,7 +139,6 @@ class SpriteDef : public Resource */ void substituteAction(SpriteAction complete, SpriteAction with); - typedef std::map<std::string, ImageSet*> ImageSets; typedef ImageSets::iterator ImageSetIterator; |