diff options
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/beinginfo.cpp | 43 | ||||
-rw-r--r-- | src/resources/beinginfo.h | 107 | ||||
-rw-r--r-- | src/resources/monsterdb.cpp | 35 | ||||
-rw-r--r-- | src/resources/npcdb.cpp | 8 |
4 files changed, 68 insertions, 125 deletions
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 30c06080..17e270dc 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -28,7 +28,18 @@ #include <optional> -BeingInfo *BeingInfo::Unknown = new BeingInfo; +static BeingInfo *createUnknownBeingInfo() +{ + auto info = new BeingInfo; + info->name = _("unnamed"); + + SpriteReference errorSprite { paths.getStringValue("spriteErrorFile"), 0 }; + info->display.sprites.push_back(std::move(errorSprite)); + + return info; +} + +BeingInfo *BeingInfo::Unknown = createUnknownBeingInfo(); static std::optional<ActorSprite::TargetCursorSize> targetCursorSizeFromString(const std::string &cursor) { @@ -54,34 +65,18 @@ static std::optional<Cursor> cursorFromString(const std::string &cursor) return {}; } -BeingInfo::BeingInfo(): - mName(_("unnamed")), - mWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER | Map::BLOCKMASK_MONSTER) -{ - SpriteDisplay display; - - SpriteReference errorSprite { paths.getStringValue("spriteErrorFile"), 0 }; - display.sprites.push_back(errorSprite); - - setDisplay(std::move(display)); -} - +BeingInfo::BeingInfo() = default; BeingInfo::~BeingInfo() = default; -void BeingInfo::setDisplay(SpriteDisplay display) -{ - mDisplay = std::move(display); -} - void BeingInfo::setTargetCursorSize(const std::string &size) { - const auto targetCursorSize = targetCursorSizeFromString(size); - if (!targetCursorSize) + const auto cursorSize = targetCursorSizeFromString(size); + if (!cursorSize) { logger->log("Unknown targetCursor value \"%s\" for %s", - size.c_str(), getName().c_str()); + size.c_str(), name.c_str()); } - setTargetCursorSize(targetCursorSize.value_or(ActorSprite::TC_MEDIUM)); + targetCursorSize = cursorSize.value_or(ActorSprite::TC_MEDIUM); } void BeingInfo::setHoverCursor(const std::string &cursorName) @@ -90,9 +85,9 @@ void BeingInfo::setHoverCursor(const std::string &cursorName) if (!cursor) { logger->log("Unknown hoverCursor value \"%s\" for %s", - cursorName.c_str(), getName().c_str()); + cursorName.c_str(), name.c_str()); } - setHoverCursor(cursor.value_or(Cursor::POINTER)); + hoverCursor = cursor.value_or(Cursor::POINTER); } void BeingInfo::addSound(SoundEvent event, const std::string &filename) diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index 10411848..2eac4237 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -23,6 +23,7 @@ #define BEINGINFO_H #include "actorsprite.h" +#include "map.h" #include "gui/gui.h" #include "resources/spritedef.h" @@ -33,19 +34,19 @@ struct Attack { - std::string mAction = SpriteAction::ATTACK; - int mEffectId = 0; - int mHitEffectId = 0; - int mCriticalHitEffectId = 0; - std::string mMissileParticleFilename = std::string(); + std::string action = SpriteAction::ATTACK; + int effectId = 0; + int hitEffectId = 0; + int criticalHitEffectId = 0; + std::string missileParticleFilename; }; -enum SoundEvent +enum class SoundEvent { - SOUND_EVENT_HIT, - SOUND_EVENT_MISS, - SOUND_EVENT_HURT, - SOUND_EVENT_DIE + HIT, + MISS, + HURT, + DIE }; /** @@ -57,78 +58,32 @@ enum SoundEvent */ class BeingInfo { - public: - static BeingInfo *Unknown; +public: + static BeingInfo *Unknown; - BeingInfo(); + BeingInfo(); + ~BeingInfo(); - ~BeingInfo(); + std::string name; + SpriteDisplay display; + ActorSprite::TargetCursorSize targetCursorSize = ActorSprite::TC_MEDIUM; + Cursor hoverCursor = Cursor::POINTER; + unsigned char walkMask = Map::BLOCKMASK_ALL; + Map::BlockType blockType = Map::BLOCKTYPE_CHARACTER; + bool targetSelection = true; - void setName(const std::string &name) { mName = name; } + void setTargetCursorSize(const std::string &size); + void setHoverCursor(const std::string &cursorName); - const std::string &getName() const - { return mName; } + void addSound(SoundEvent event, const std::string &filename); + const std::string &getSound(SoundEvent event) const; - void setDisplay(SpriteDisplay display); + void addAttack(int id, Attack attack); + const Attack &getAttack(int id) const; - const SpriteDisplay &getDisplay() const - { return mDisplay; } - - void setTargetCursorSize(const std::string &size); - - void setTargetCursorSize(ActorSprite::TargetCursorSize targetSize) - { mTargetCursorSize = targetSize; } - - ActorSprite::TargetCursorSize getTargetCursorSize() const - { return mTargetCursorSize; } - - void setHoverCursor(const std::string &cursorName); - - void setHoverCursor(Cursor cursor) - { mHoverCursor = cursor; } - - Cursor getHoverCursor() const - { return mHoverCursor; } - - void addSound(SoundEvent event, const std::string &filename); - - const std::string &getSound(SoundEvent event) const; - - void addAttack(int id, Attack attack); - - const Attack &getAttack(int id) const; - - void setWalkMask(unsigned char mask) - { mWalkMask = mask; } - - /** - * Gets the way the being is blocked by other objects - */ - unsigned char getWalkMask() const - { return mWalkMask; } - - void setBlockType(Map::BlockType blockType) - { mBlockType = blockType; } - - Map::BlockType getBlockType() const - { return mBlockType; } - - void setTargetSelection(bool n) - { mTargetSelection = n; } - - bool isTargetSelection() const - { return mTargetSelection; } - - private: - SpriteDisplay mDisplay; - std::string mName; - ActorSprite::TargetCursorSize mTargetCursorSize = ActorSprite::TC_MEDIUM; - Cursor mHoverCursor = Cursor::POINTER; - std::map<SoundEvent, std::vector<std::string>> mSounds; - std::map<int, Attack> mAttacks; - unsigned char mWalkMask; - Map::BlockType mBlockType = Map::BLOCKTYPE_CHARACTER; - bool mTargetSelection = true; +private: + std::map<SoundEvent, std::vector<std::string>> mSounds; + std::map<int, Attack> mAttacks; }; #endif // BEINGINFO_H diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index 3ad03117..38806f13 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -69,22 +69,19 @@ void MonsterDB::readMonsterNode(xmlNodePtr node, const std::string &filename) { auto *currentInfo = new BeingInfo; - currentInfo->setWalkMask(Map::BLOCKMASK_WALL - | Map::BLOCKMASK_CHARACTER - | Map::BLOCKMASK_MONSTER); - currentInfo->setBlockType(Map::BLOCKTYPE_MONSTER); + currentInfo->blockType = Map::BLOCKTYPE_MONSTER; - currentInfo->setName(XML::getProperty(node, "name", _("unnamed"))); + currentInfo->name = XML::getProperty(node, "name", _("unnamed")); currentInfo->setTargetCursorSize(XML::getProperty(node, "targetCursor", "medium")); currentInfo->setHoverCursor(XML::getProperty(node, "hoverCursor", "attack")); - currentInfo->setTargetSelection(XML::getProperty( - node, "targetSelection", true)); + currentInfo->targetSelection = XML::getProperty( + node, "targetSelection", true); - SpriteDisplay display; + SpriteDisplay &display = currentInfo->display; for (auto spriteNode : XML::Children(node)) { @@ -101,26 +98,26 @@ void MonsterDB::readMonsterNode(xmlNodePtr node, const std::string &filename) if (event == "hit") { - currentInfo->addSound(SOUND_EVENT_HIT, soundFile); + currentInfo->addSound(SoundEvent::HIT, soundFile); } else if (event == "miss") { - currentInfo->addSound(SOUND_EVENT_MISS, soundFile); + currentInfo->addSound(SoundEvent::MISS, soundFile); } else if (event == "hurt") { - currentInfo->addSound(SOUND_EVENT_HURT, soundFile); + currentInfo->addSound(SoundEvent::HURT, soundFile); } else if (event == "die") { - currentInfo->addSound(SOUND_EVENT_DIE, soundFile); + currentInfo->addSound(SoundEvent::DIE, soundFile); } else { logger->log("MonsterDB: Warning, sound effect %s for " "unknown event %s of monster %s in %s", soundFile, event.c_str(), - currentInfo->getName().c_str(), + currentInfo->name.c_str(), filename.c_str()); } } @@ -129,17 +126,17 @@ void MonsterDB::readMonsterNode(xmlNodePtr node, const std::string &filename) Attack attack; const int id = XML::getProperty(spriteNode, "id", 0); - attack.mEffectId = XML::getProperty(spriteNode, "effect-id", -1); - attack.mHitEffectId = + attack.effectId = XML::getProperty(spriteNode, "effect-id", -1); + attack.hitEffectId = XML::getProperty(spriteNode, "hit-effect-id", paths.getIntValue("hitEffectId")); - attack.mCriticalHitEffectId = + attack.criticalHitEffectId = XML::getProperty(spriteNode, "critical-hit-effect-id", paths.getIntValue("criticalHitEffectId")); - attack.mMissileParticleFilename = + attack.missileParticleFilename = XML::getProperty(spriteNode, "missile-particle", ""); - attack.mAction = XML::getProperty(spriteNode, "action", "attack"); + attack.action = XML::getProperty(spriteNode, "action", "attack"); currentInfo->addAttack(id, std::move(attack)); } @@ -149,7 +146,6 @@ void MonsterDB::readMonsterNode(xmlNodePtr node, const std::string &filename) (const char*) spriteNode->children->content); } } - currentInfo->setDisplay(std::move(display)); mMonsterInfos[XML::getProperty(node, "id", 0) + mMonsterIdOffset] = currentInfo; } @@ -170,7 +166,6 @@ void MonsterDB::unload() mLoaded = false; } - BeingInfo *MonsterDB::get(int id) { auto i = mMonsterInfos.find(id); diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index 13d01699..a8d0f60f 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -57,10 +57,10 @@ void NPCDB::readNPCNode(xmlNodePtr node, const std::string &filename) currentInfo->setHoverCursor(XML::getProperty(node, "hoverCursor", "talk")); - currentInfo->setTargetSelection(XML::getProperty( - node, "targetSelection", true)); + currentInfo->targetSelection = XML::getProperty( + node, "targetSelection", true); - SpriteDisplay display; + SpriteDisplay &display = currentInfo->display; for (auto spriteNode : XML::Children(node)) { if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) @@ -76,8 +76,6 @@ void NPCDB::readNPCNode(xmlNodePtr node, const std::string &filename) } } - currentInfo->setDisplay(std::move(display)); - mNPCInfos[id] = currentInfo; } |