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 /src/resources/beinginfo.cpp | |
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
Diffstat (limited to 'src/resources/beinginfo.cpp')
-rw-r--r-- | src/resources/beinginfo.cpp | 54 |
1 files changed, 18 insertions, 36 deletions
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); } |