diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-02 12:55:32 +0000 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-02 12:55:32 +0000 |
commit | 5efaa5125fe92a5438b3cc2949f4d720bced5a7a (patch) | |
tree | 87f4da1382fb6179610182ca3e502e5365e66276 | |
parent | 2e60491ceb0548b0bea93207c13b974d6a6cf5cc (diff) | |
download | mana-5efaa5125fe92a5438b3cc2949f4d720bced5a7a.tar.gz mana-5efaa5125fe92a5438b3cc2949f4d720bced5a7a.tar.bz2 mana-5efaa5125fe92a5438b3cc2949f4d720bced5a7a.tar.xz mana-5efaa5125fe92a5438b3cc2949f4d720bced5a7a.zip |
General code cleanups
* Don't needlessly store or return raw pointers in BeingInfo
* Less copying, more moving
* Less else after return
* Make AddDEF a template instead of a macro
* Removed some unused includes
* Use range-based for loops
-rw-r--r-- | src/being.cpp | 12 | ||||
-rw-r--r-- | src/configuration.cpp | 30 | ||||
-rw-r--r-- | src/configuration.h | 5 | ||||
-rw-r--r-- | src/defaults.cpp | 26 | ||||
-rw-r--r-- | src/gui/setup_interface.cpp | 18 | ||||
-rw-r--r-- | src/gui/worldselectdialog.cpp | 1 | ||||
-rw-r--r-- | src/map.cpp | 6 | ||||
-rw-r--r-- | src/openglgraphics.cpp | 6 | ||||
-rw-r--r-- | src/playerrelations.cpp | 27 | ||||
-rw-r--r-- | src/playerrelations.h | 6 | ||||
-rw-r--r-- | src/resources/action.cpp | 4 | ||||
-rw-r--r-- | src/resources/action.h | 4 | ||||
-rw-r--r-- | src/resources/animation.cpp | 9 | ||||
-rw-r--r-- | src/resources/animation.h | 4 | ||||
-rw-r--r-- | src/resources/beinginfo.cpp | 54 | ||||
-rw-r--r-- | src/resources/beinginfo.h | 41 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 40 | ||||
-rw-r--r-- | src/resources/itemdb.h | 2 | ||||
-rw-r--r-- | src/resources/monsterdb.cpp | 22 | ||||
-rw-r--r-- | src/resources/npcdb.cpp | 8 | ||||
-rw-r--r-- | src/resources/specialdb.cpp | 6 | ||||
-rw-r--r-- | src/variabledata.h | 4 |
22 files changed, 122 insertions, 213 deletions
diff --git a/src/being.cpp b/src/being.cpp index 9549b625..6b21198a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -378,12 +378,12 @@ void Being::takeDamage(Being *attacker, int amount, } else if (attacker && attacker->getType() == MONSTER) { - const Attack *attack = attacker->getInfo()->getAttack(attackId); + const Attack &attack = attacker->getInfo()->getAttack(attackId); if (type != CRITICAL) - hitEffectId = attack->mHitEffectId; + hitEffectId = attack.mHitEffectId; else - hitEffectId = attack->mCriticalHitEffectId; + hitEffectId = attack.mCriticalHitEffectId; } else { @@ -414,7 +414,7 @@ void Being::handleAttack(Being *victim, int damage, int attackId) fireMissile(victim, mEquippedWeapon->getMissileParticleFile()); else fireMissile(victim, - mInfo->getAttack(attackId)->mMissileParticleFilename); + mInfo->getAttack(attackId).mMissileParticleFilename); sound.playSfx(mInfo->getSound((damage > 0) ? SOUND_EVENT_HIT : SOUND_EVENT_MISS), @@ -593,13 +593,13 @@ void Being::setAction(Action action, int attackId) } else { - currentAction = mInfo->getAttack(attackId)->mAction; + currentAction = mInfo->getAttack(attackId).mAction; reset(); // Attack particle effect if (Particle::enabled) { - int effectId = mInfo->getAttack(attackId)->mEffectId; + int effectId = mInfo->getAttack(attackId).mEffectId; int rotation = 0; switch (mSpriteDirection) { diff --git a/src/configuration.cpp b/src/configuration.cpp index f7718bdc..ca1f4438 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -128,19 +128,19 @@ VariableData* Configuration::getDefault(const std::string &key, { if (mDefaultsData) { - DefaultsData::const_iterator itdef = mDefaultsData->find(key); + auto itdef = mDefaultsData->find(key); if (itdef != mDefaultsData->end() && itdef->second && itdef->second->getType() == type) { return itdef->second; } - else - { - logger->log("%s: No value in registry for key %s", - mConfigPath.c_str(), key.c_str()); - } + + logger->log("%s: No value in registry for key %s", + mConfigPath.c_str(), + key.c_str()); } + return nullptr; } @@ -158,6 +158,7 @@ int Configuration::getIntValue(const std::string &key) const { defaultValue = atoi(iter->second.c_str()); } + return defaultValue; } @@ -167,16 +168,14 @@ std::string Configuration::getStringValue(const std::string &key) const auto iter = mOptions.find(key); if (iter == mOptions.end()) { - VariableData* vd = getDefault(key, - VariableData::DATA_STRING); - - if (vd) + if (VariableData *vd = getDefault(key, VariableData::DATA_STRING)) defaultValue = ((StringData*)vd)->getData(); } else { defaultValue = iter->second; } + return defaultValue; } @@ -187,16 +186,14 @@ float Configuration::getFloatValue(const std::string &key) const auto iter = mOptions.find(key); if (iter == mOptions.end()) { - VariableData* vd = getDefault(key, - VariableData::DATA_FLOAT); - - if (vd) + if (VariableData *vd = getDefault(key, VariableData::DATA_FLOAT)) defaultValue = ((FloatData*)vd)->getData(); } else { defaultValue = atof(iter->second.c_str()); } + return defaultValue; } @@ -206,10 +203,7 @@ bool Configuration::getBoolValue(const std::string &key) const auto iter = mOptions.find(key); if (iter == mOptions.end()) { - VariableData* vd = getDefault(key, - VariableData::DATA_BOOL); - - if (vd) + if (VariableData *vd = getDefault(key, VariableData::DATA_BOOL)) defaultValue = ((BoolData*)vd)->getData(); } else diff --git a/src/configuration.h b/src/configuration.h index cd56be05..5864829e 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -162,11 +162,10 @@ class ConfigurationObject template<class T, class CONT> CONT getList(const std::string &name, CONT empty, ConfigurationListManager<T, CONT> *manager) { - ConfigurationList *list = &(mContainerOptions[name]); CONT container = empty; - for (ConfigurationList::const_iterator it = list->begin(); it != list->end(); it++) - container = manager->readConfigItem(*it, container); + for (auto obj : mContainerOptions[name]) + container = manager->readConfigItem(obj, container); return container; } diff --git a/src/defaults.cpp b/src/defaults.cpp index 8cf79590..1830d394 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -21,45 +21,43 @@ #include "defaults.h" #include "being.h" -#include "graphics.h" #include "client.h" -#include <cstdlib> - -VariableData* createData(int defData) +VariableData *createData(int defData) { return new IntData(defData); } -VariableData* createData(double defData) +VariableData *createData(double defData) { return new FloatData(defData); } -VariableData* createData(float defData) +VariableData *createData(float defData) { return new FloatData(defData); } -VariableData* createData(const std::string &defData) +VariableData *createData(const std::string &defData) { return new StringData(defData); } -VariableData* createData(const char* defData) +VariableData *createData(const char* defData) { return new StringData(defData); } -VariableData* createData(bool defData) +VariableData *createData(bool defData) { return new BoolData(defData); } -#define AddDEF(defaultsData, key, value) \ - defaultsData->insert(std::pair<std::string, VariableData*> \ - (key, createData(value))); - +template<typename T> +void AddDEF(DefaultsData *defaultsData, const char *key, T value) +{ + defaultsData->insert(std::make_pair(key, createData(value))); +} DefaultsData* getConfigDefaults() { @@ -126,7 +124,7 @@ DefaultsData* getConfigDefaults() DefaultsData* getBrandingDefaults() { - auto* brandingData = new DefaultsData; + auto *brandingData = new DefaultsData; // Init config defaults AddDEF(brandingData, "wallpapersPath", ""); AddDEF(brandingData, "wallpaperFile", ""); diff --git a/src/gui/setup_interface.cpp b/src/gui/setup_interface.cpp index 3697285c..e30a85de 100644 --- a/src/gui/setup_interface.cpp +++ b/src/gui/setup_interface.cpp @@ -22,27 +22,16 @@ #include "gui/setup_interface.h" #include "configuration.h" -#include "game.h" -#include "graphics.h" #include "localplayer.h" -#include "log.h" -#include "main.h" -//#include "particle.h" - -#include "gui/okdialog.h" #include "gui/widgets/checkbox.h" #include "gui/widgets/label.h" #include "gui/widgets/layout.h" -#include "gui/widgets/listbox.h" -#include "gui/widgets/scrollarea.h" #include "gui/widgets/slider.h" #include "gui/widgets/spacer.h" -#include "gui/widgets/textfield.h" #include "gui/widgets/dropdown.h" #include "utils/gettext.h" -#include "utils/stringutils.h" #include <guichan/key.hpp> #include <guichan/listmodel.hpp> @@ -50,9 +39,6 @@ #include <SDL.h> #include <string> -#include <vector> - -extern Graphics *graphics; const char *SIZE_NAME[4] = { @@ -65,8 +51,6 @@ const char *SIZE_NAME[4] = class FontSizeChoiceListModel : public gcn::ListModel { public: - ~FontSizeChoiceListModel() override { } - int getNumberOfElements() override { return 4; @@ -277,6 +261,4 @@ void Setup_Interface::action(const gcn::ActionEvent &event) { config.setValue("logNpcInGui", mNPCLogCheckBox->isSelected()); } - } - diff --git a/src/gui/worldselectdialog.cpp b/src/gui/worldselectdialog.cpp index f2b31085..cab978de 100644 --- a/src/gui/worldselectdialog.cpp +++ b/src/gui/worldselectdialog.cpp @@ -30,7 +30,6 @@ #include "gui/widgets/listbox.h" #include "gui/widgets/scrollarea.h" -#include "net/logindata.h" #include "net/loginhandler.h" #include "net/net.h" #include "net/worldinfo.h" diff --git a/src/map.cpp b/src/map.cpp index 9639ddf2..76f6b56b 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -387,7 +387,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) { // We draw beings with a lower opacity to make them visible // even when covered by a wall or some other elements... - Actors::const_iterator ai = mActors.begin(); + auto ai = mActors.begin(); while (ai != mActors.end()) { if (Actor *actor = *ai) @@ -505,7 +505,7 @@ void Map::updateAmbientLayers(float scrollX, float scrollY) } void Map::drawAmbientLayers(Graphics *graphics, LayerType type, - float scrollX, float scrollY, int detail) + float scrollX, float scrollY, int detail) { // Detail 0 = no ambient effects except background image if (detail <= 0 && type != BACKGROUND_LAYERS) return; @@ -524,7 +524,7 @@ void Map::drawAmbientLayers(Graphics *graphics, LayerType type, // New type of ambient layers added here without adding it // to Map::drawAmbientLayers. assert(false); - break; + return; } // Draw overlays diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 2f83eea7..3cc1b9e3 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -678,8 +678,7 @@ bool OpenGLGraphics::pushClipArea(gcn::Rectangle area) transY = -mClipStack.top().yOffset; } - // Skip Graphics::popClipArea since we don't need to interact with SDL2 - bool result = gcn::Graphics::pushClipArea(area); + bool result = Graphics::pushClipArea(area); transX += mClipStack.top().xOffset; transY += mClipStack.top().yOffset; @@ -696,8 +695,7 @@ bool OpenGLGraphics::pushClipArea(gcn::Rectangle area) void OpenGLGraphics::popClipArea() { - // Skip Graphics::popClipArea since we don't need to interact with SDL2 - gcn::Graphics::popClipArea(); + Graphics::popClipArea(); if (mClipStack.empty()) return; diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp index 69e857a7..d0e4a195 100644 --- a/src/playerrelations.cpp +++ b/src/playerrelations.cpp @@ -24,7 +24,6 @@ #include "actorspritemanager.h" #include "being.h" #include "configuration.h" -#include "graphics.h" #include "playerrelations.h" #include "utils/dtor.h" @@ -97,12 +96,8 @@ PlayerRelationsManager::~PlayerRelationsManager() { delete_all(mIgnoreStrategies); - for (std::map<std::string, - PlayerRelation *>::const_iterator it = mRelations.begin(); - it != mRelations.end(); it++) - { - delete it->second; - } + for (auto &[_, relation] : mRelations) + delete relation; } void PlayerRelationsManager::clear() @@ -175,11 +170,8 @@ void PlayerRelationsManager::signalUpdate(const std::string &name) { store(); - for (std::list<PlayerRelationsListener *>::const_iterator it = mListeners.begin(); - it != mListeners.end(); it++) - { - (*it)->updatedPlayer(name); - } + for (auto listener : mListeners) + listener->updatedPlayer(name); } unsigned int PlayerRelationsManager::checkPermissionSilently( @@ -188,8 +180,7 @@ unsigned int PlayerRelationsManager::checkPermissionSilently( { PlayerRelation *r = nullptr; - std::map<std::string, PlayerRelation *>::const_iterator it = - mRelations.find(playerName); + auto it = mRelations.find(playerName); if (it != mRelations.end()) r = it->second; if (!r) @@ -341,9 +332,9 @@ public: } void ignore(Being *being, unsigned int flags) override - { - being->setSpeech("...", 500); - } + { + being->setSpeech("...", 500); + } }; @@ -365,7 +356,7 @@ public: std::vector<PlayerIgnoreStrategy *> * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (mIgnoreStrategies.size() == 0) + if (mIgnoreStrategies.empty()) { mIgnoreStrategies.push_back(new PIS_nothing()); mIgnoreStrategies.push_back(new PIS_dotdotdot()); diff --git a/src/playerrelations.h b/src/playerrelations.h index 9c696105..a836a976 100644 --- a/src/playerrelations.h +++ b/src/playerrelations.h @@ -71,7 +71,7 @@ public: std::string mDescription; std::string mShortName; - virtual ~PlayerIgnoreStrategy() {} + virtual ~PlayerIgnoreStrategy() = default; /** * Handle the ignoring of the indicated action by the indicated player. @@ -82,8 +82,8 @@ public: class PlayerRelationsListener { public: - PlayerRelationsListener() { } - virtual ~PlayerRelationsListener() { } + PlayerRelationsListener() = default; + virtual ~PlayerRelationsListener() = default; virtual void updatedPlayer(const std::string &name) = 0; }; diff --git a/src/resources/action.cpp b/src/resources/action.cpp index c35498a4..42a8f748 100644 --- a/src/resources/action.cpp +++ b/src/resources/action.cpp @@ -25,9 +25,7 @@ #include "utils/dtor.h" -Action::Action() -{ -} +Action::Action() = default; Action::~Action() { diff --git a/src/resources/action.h b/src/resources/action.h index bf229abd..8a9a76f2 100644 --- a/src/resources/action.h +++ b/src/resources/action.h @@ -43,9 +43,7 @@ class Action Animation *getAnimation(int direction) const; protected: - using Animations = std::map<int, Animation *>; - using AnimationIterator = Animations::iterator; - Animations mAnimations; + std::map<int, Animation *> mAnimations; }; #endif diff --git a/src/resources/animation.cpp b/src/resources/animation.cpp index 8ab7cc44..1be27c2c 100644 --- a/src/resources/animation.cpp +++ b/src/resources/animation.cpp @@ -21,13 +21,6 @@ #include "resources/animation.h" -#include "utils/dtor.h" - -Animation::Animation(): - mDuration(0) -{ -} - void Animation::addFrame(Image *image, int delay, int offsetX, int offsetY) { Frame frame = { image, delay, offsetX, offsetY }; @@ -42,5 +35,5 @@ void Animation::addTerminator() bool Animation::isTerminator(const Frame &candidate) { - return (candidate.image == nullptr); + return candidate.image == nullptr; } diff --git a/src/resources/animation.h b/src/resources/animation.h index 6363e49f..59601dc4 100644 --- a/src/resources/animation.h +++ b/src/resources/animation.h @@ -46,7 +46,7 @@ struct Frame class Animation { public: - Animation(); + Animation() = default; /** * Appends a new animation at the end of the sequence. @@ -81,7 +81,7 @@ class Animation protected: std::vector<Frame> mFrames; - int mDuration; + int mDuration = 0; }; #endif diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 539254ac..da65355a 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -24,17 +24,14 @@ #include "log.h" #include "configuration.h" -#include "utils/dtor.h" #include "utils/gettext.h" BeingInfo *BeingInfo::Unknown = new BeingInfo; BeingInfo::BeingInfo(): - mName(_("unnamed")), - mTargetCursorSize(ActorSprite::TC_MEDIUM), - mWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER - | Map::BLOCKMASK_MONSTER), - mBlockType(Map::BLOCKTYPE_CHARACTER) + mName(_("unnamed")), + mWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER + | Map::BLOCKMASK_MONSTER) { SpriteDisplay display; @@ -44,12 +41,7 @@ BeingInfo::BeingInfo(): setDisplay(display); } -BeingInfo::~BeingInfo() -{ - delete_all(mSounds); - delete_all(mAttacks); - mSounds.clear(); -} +BeingInfo::~BeingInfo() = default; void BeingInfo::setDisplay(SpriteDisplay display) { @@ -74,12 +66,7 @@ void BeingInfo::setTargetCursorSize(const std::string &size) void BeingInfo::addSound(SoundEvent event, const std::string &filename) { - if (mSounds.find(event) == mSounds.end()) - { - mSounds[event] = new std::vector<std::string>; - } - - mSounds[event]->push_back("sfx/" + filename); + mSounds[event].push_back("sfx/" + filename); } const std::string &BeingInfo::getSound(SoundEvent event) const @@ -87,30 +74,25 @@ const std::string &BeingInfo::getSound(SoundEvent event) const static const std::string empty; auto i = mSounds.find(event); - return (i == mSounds.end()) ? empty : - i->second->at(rand() % i->second->size()); + return i == mSounds.end() ? empty : + i->second.at(rand() % i->second.size()); } -const Attack *BeingInfo::getAttack(int id) const +const Attack &BeingInfo::getAttack(int id) const { - static auto *empty = new Attack(SpriteAction::ATTACK, - -1, // Default strike effect on monster - paths.getIntValue("hitEffectId"), - paths.getIntValue("criticalHitEffectId"), - std::string()); + static const Attack empty { + SpriteAction::ATTACK, + -1, // Default strike effect on monster + paths.getIntValue("hitEffectId"), + paths.getIntValue("criticalHitEffectId"), + std::string() + }; auto it = mAttacks.find(id); - return (it == mAttacks.end()) ? empty : it->second; + return it == mAttacks.end() ? empty : it->second; } -void BeingInfo::addAttack(int id, std::string action, int effectId, - int hitEffectId, int criticalHitEffectId, - const std::string &missileParticleFilename) +void BeingInfo::addAttack(int id, Attack attack) { - auto it = mAttacks.find(id); - if (it != mAttacks.end()) - delete it->second; - - mAttacks[id] = new Attack(action, effectId, hitEffectId, - criticalHitEffectId, missileParticleFilename); + mAttacks[id] = std::move(attack); } diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index 3fa5b8b6..e2d11c93 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -26,29 +26,19 @@ #include "resources/spritedef.h" -#include <list> #include <map> #include <string> #include <vector> -struct Attack { - std::string mAction; - int mEffectId, mHitEffectId, mCriticalHitEffectId; - std::string mMissileParticleFilename; - - Attack(std::string action, int effectId, int hitEffectId, - int criticalHitEffectId, std::string missileParticleFilename) - { - mAction = action; - mEffectId = effectId; - mHitEffectId = hitEffectId; - mCriticalHitEffectId = criticalHitEffectId; - mMissileParticleFilename = missileParticleFilename; - } +struct Attack +{ + std::string mAction = SpriteAction::ATTACK; + int mEffectId = 0; + int mHitEffectId = 0; + int mCriticalHitEffectId = 0; + std::string mMissileParticleFilename = std::string(); }; -using Attacks = std::map<int, Attack *>; - enum SoundEvent { SOUND_EVENT_HIT, @@ -57,8 +47,6 @@ enum SoundEvent SOUND_EVENT_DIE }; -using SoundEvents = std::map<SoundEvent, std::vector<std::string> *>; - /** * Holds information about a certain type of monster. This includes the name * of the monster, the sprite to display and the sounds the monster makes. @@ -97,11 +85,9 @@ class BeingInfo const std::string &getSound(SoundEvent event) const; - void addAttack(int id, std::string action, int effectId, - int hitEffectId, int criticalHitEffectId, - const std::string &missileParticleFilename); + void addAttack(int id, Attack attack); - const Attack *getAttack(int id) const; + const Attack &getAttack(int id) const; void setWalkMask(unsigned char mask) { mWalkMask = mask; } @@ -121,14 +107,13 @@ class BeingInfo private: SpriteDisplay mDisplay; std::string mName; - ActorSprite::TargetCursorSize mTargetCursorSize; - SoundEvents mSounds; - Attacks mAttacks; + ActorSprite::TargetCursorSize mTargetCursorSize = ActorSprite::TC_MEDIUM; + std::map<SoundEvent, std::vector<std::string>> mSounds; + std::map<int, Attack> mAttacks; unsigned char mWalkMask; - Map::BlockType mBlockType; + Map::BlockType mBlockType = Map::BLOCKTYPE_CHARACTER; }; using BeingInfos = std::map<int, BeingInfo *>; -using BeingInfoIterator = BeingInfos::iterator; #endif // BEINGINFO_H diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index cd027763..b910c639 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -42,23 +42,23 @@ void setStatsList(const std::list<ItemStat> &stats) static ItemType itemTypeFromString(const std::string &name, int id = 0) { - if (name=="generic") return ITEM_UNUSABLE; - else if (name=="usable") return ITEM_USABLE; - else if (name=="equip-1hand") return ITEM_EQUIPMENT_ONE_HAND_WEAPON; - else if (name=="equip-2hand") return ITEM_EQUIPMENT_TWO_HANDS_WEAPON; - else if (name=="equip-torso") return ITEM_EQUIPMENT_TORSO; - else if (name=="equip-arms") return ITEM_EQUIPMENT_ARMS; - else if (name=="equip-head") return ITEM_EQUIPMENT_HEAD; - else if (name=="equip-legs") return ITEM_EQUIPMENT_LEGS; - else if (name=="equip-shield") return ITEM_EQUIPMENT_SHIELD; - else if (name=="equip-ring") return ITEM_EQUIPMENT_RING; - else if (name=="equip-charm") return ITEM_EQUIPMENT_CHARM; - else if (name=="equip-necklace") return ITEM_EQUIPMENT_NECKLACE; - else if (name=="equip-feet") return ITEM_EQUIPMENT_FEET; - else if (name=="equip-ammo") return ITEM_EQUIPMENT_AMMO; - else if (name=="racesprite") return ITEM_SPRITE_RACE; - else if (name=="hairsprite") return ITEM_SPRITE_HAIR; - else return ITEM_UNUSABLE; + if (name == "generic") return ITEM_UNUSABLE; + if (name == "usable") return ITEM_USABLE; + if (name == "equip-1hand") return ITEM_EQUIPMENT_ONE_HAND_WEAPON; + if (name == "equip-2hand") return ITEM_EQUIPMENT_TWO_HANDS_WEAPON; + if (name == "equip-torso") return ITEM_EQUIPMENT_TORSO; + if (name == "equip-arms") return ITEM_EQUIPMENT_ARMS; + if (name == "equip-head") return ITEM_EQUIPMENT_HEAD; + if (name == "equip-legs") return ITEM_EQUIPMENT_LEGS; + if (name == "equip-shield") return ITEM_EQUIPMENT_SHIELD; + if (name == "equip-ring") return ITEM_EQUIPMENT_RING; + if (name == "equip-charm") return ITEM_EQUIPMENT_CHARM; + if (name == "equip-necklace") return ITEM_EQUIPMENT_NECKLACE; + if (name == "equip-feet") return ITEM_EQUIPMENT_FEET; + if (name == "equip-ammo") return ITEM_EQUIPMENT_AMMO; + if (name == "racesprite") return ITEM_SPRITE_RACE; + if (name == "hairsprite") return ITEM_SPRITE_HAIR; + return ITEM_UNUSABLE; } void ItemDB::loadEmptyItemDefinition() @@ -76,13 +76,11 @@ void ItemDB::loadEmptyItemDefinition() * Common itemDB functions */ -bool ItemDB::exists(int id) +bool ItemDB::exists(int id) const { assert(mLoaded); - ItemInfos::const_iterator i = mItemInfos.find(id); - - return i != mItemInfos.end(); + return mItemInfos.find(id) != mItemInfos.end(); } const ItemInfo &ItemDB::get(int id) diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 412e64ce..6a9988d0 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -89,7 +89,7 @@ class ItemDB bool isLoaded() const { return mLoaded; } - bool exists(int id); + bool exists(int id) const; const ItemInfo &get(int id); const ItemInfo &get(const std::string &name); diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 5f62f418..fa1ac5af 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -124,36 +124,32 @@ void MonsterDB::readMonsterNode(xmlNodePtr node, const std::string &filename) } else if (xmlStrEqual(spriteNode->name, BAD_CAST "attack")) { + Attack attack; const int id = XML::getProperty(spriteNode, "id", 0); - int effectId = XML::getProperty(spriteNode, "effect-id", -1); - int hitEffectId = + + attack.mEffectId = XML::getProperty(spriteNode, "effect-id", -1); + attack.mHitEffectId = XML::getProperty(spriteNode, "hit-effect-id", paths.getIntValue("hitEffectId")); - int criticalHitEffectId = + attack.mCriticalHitEffectId = XML::getProperty(spriteNode, "critical-hit-effect-id", paths.getIntValue("criticalHitEffectId")); - const std::string missileParticleFilename = + attack.mMissileParticleFilename = XML::getProperty(spriteNode, "missile-particle", ""); - const std::string spriteAction = XML::getProperty(spriteNode, - "action", - "attack"); + attack.mAction = XML::getProperty(spriteNode, "action", "attack"); - currentInfo->addAttack(id, spriteAction, effectId, - hitEffectId, criticalHitEffectId, - missileParticleFilename); + currentInfo->addAttack(id, std::move(attack)); } else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) { - display.particles.push_back( + display.particles.emplace_back( (const char*) spriteNode->xmlChildrenNode->content); } } currentInfo->setDisplay(display); mMonsterInfos[XML::getProperty(node, "id", 0) + mMonsterIdOffset] = currentInfo; - - } /** diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index fa12eced..6a0685d2 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -27,7 +27,6 @@ #include "utils/dtor.h" #include "utils/xml.h" -#include "configuration.h" namespace { @@ -40,7 +39,6 @@ void NPCDB::init() { if (mLoaded) unload(); - } void NPCDB::readNPCNode(xmlNodePtr node, const std::string &filename) @@ -101,8 +99,6 @@ BeingInfo *NPCDB::get(int id) logger->log("NPCDB: Warning, unknown NPC ID %d requested", id); return BeingInfo::Unknown; } - else - { - return i->second; - } + + return i->second; } diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp index b72c059f..89bd4d8d 100644 --- a/src/resources/specialdb.cpp +++ b/src/resources/specialdb.cpp @@ -33,8 +33,10 @@ namespace SpecialInfo::TargetMode SpecialDB::targetModeFromString(const std::string& str) { - if (str=="being") return SpecialInfo::TARGET_BEING; - else if (str=="point") return SpecialInfo::TARGET_POINT; + if (str == "being") + return SpecialInfo::TARGET_BEING; + if (str == "point") + return SpecialInfo::TARGET_POINT; logger->log("SpecialDB: Warning, unknown target mode \"%s\"", str.c_str() ); return SpecialInfo::TARGET_BEING; diff --git a/src/variabledata.h b/src/variabledata.h index be822050..4135e115 100644 --- a/src/variabledata.h +++ b/src/variabledata.h @@ -28,7 +28,7 @@ class Item; class VariableData { - public: +public: enum DataType { DATA_NONE, @@ -40,7 +40,7 @@ class VariableData DATA_ACTOR }; - virtual ~VariableData() {} + virtual ~VariableData() = default; virtual int getType() const = 0; }; |