summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp33
-rw-r--r--src/map.h3
-rw-r--r--src/resources/beinginfo.cpp43
-rw-r--r--src/resources/beinginfo.h107
-rw-r--r--src/resources/monsterdb.cpp35
-rw-r--r--src/resources/npcdb.cpp8
6 files changed, 86 insertions, 143 deletions
diff --git a/src/being.cpp b/src/being.cpp
index c9eee2c6..26b98115 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -106,12 +106,12 @@ void Being::setSubtype(Uint16 subtype)
{
case MONSTER:
mInfo = MonsterDB::get(mSubType);
- setName(mInfo->getName());
- setupSpriteDisplay(mInfo->getDisplay());
+ setName(mInfo->name);
+ setupSpriteDisplay(mInfo->display);
break;
case NPC:
mInfo = NPCDB::get(mSubType);
- setupSpriteDisplay(mInfo->getDisplay(), false);
+ setupSpriteDisplay(mInfo->display, false);
break;
case PLAYER: {
int id = -100 - subtype;
@@ -128,30 +128,29 @@ void Being::setSubtype(Uint16 subtype)
break;
}
}
-
bool Being::isTargetSelection() const
{
- return mInfo->isTargetSelection();
+ return mInfo->targetSelection;
}
ActorSprite::TargetCursorSize Being::getTargetCursorSize() const
{
- return mInfo->getTargetCursorSize();
+ return mInfo->targetCursorSize;
}
Cursor Being::getHoverCursor() const
{
- return mInfo->getHoverCursor();
+ return mInfo->hoverCursor;
}
unsigned char Being::getWalkMask() const
{
- return mInfo->getWalkMask();
+ return mInfo->walkMask;
}
Map::BlockType Being::getBlockType() const
{
- return mInfo->getBlockType();
+ return mInfo->blockType;
}
void Being::setMoveSpeed(const Vector &speed)
@@ -360,7 +359,7 @@ void Being::takeDamage(Being *attacker, int amount,
if (amount > 0)
{
- auto &hurtSfx = mInfo->getSound(SOUND_EVENT_HURT);
+ auto &hurtSfx = mInfo->getSound(SoundEvent::HURT);
if (attacker)
sound.playSfx(hurtSfx, attacker->getPixelX(), attacker->getPixelY());
else
@@ -389,9 +388,9 @@ void Being::takeDamage(Being *attacker, int amount,
const Attack &attack = attacker->getInfo().getAttack(attackId);
if (type != CRITICAL)
- hitEffectId = attack.mHitEffectId;
+ hitEffectId = attack.hitEffectId;
else
- hitEffectId = attack.mCriticalHitEffectId;
+ hitEffectId = attack.criticalHitEffectId;
}
else
{
@@ -422,10 +421,10 @@ void Being::handleAttack(Being *victim, int damage, int attackId)
fireMissile(victim, mEquippedWeapon->missileParticleFile);
else
fireMissile(victim,
- mInfo->getAttack(attackId).mMissileParticleFilename);
+ mInfo->getAttack(attackId).missileParticleFilename);
sound.playSfx(mInfo->getSound((damage > 0) ?
- SOUND_EVENT_HIT : SOUND_EVENT_MISS),
+ SoundEvent::HIT : SoundEvent::MISS),
getPixelX(), getPixelY());
}
@@ -599,13 +598,13 @@ void Being::setAction(Action action, int attackId)
}
else
{
- currentAction = mInfo->getAttack(attackId).mAction;
+ currentAction = mInfo->getAttack(attackId).action;
reset();
// Attack particle effect
if (Particle::enabled)
{
- int effectId = mInfo->getAttack(attackId).mEffectId;
+ int effectId = mInfo->getAttack(attackId).effectId;
int rotation = 0;
switch (mSpriteDirection)
{
@@ -629,7 +628,7 @@ void Being::setAction(Action action, int attackId)
break;
case DEAD:
currentAction = SpriteAction::DEAD;
- sound.playSfx(mInfo->getSound(SOUND_EVENT_DIE),
+ sound.playSfx(mInfo->getSound(SoundEvent::DIE),
getPixelX(), getPixelY());
break;
case STAND:
diff --git a/src/map.h b/src/map.h
index ce748c08..07d15e9a 100644
--- a/src/map.h
+++ b/src/map.h
@@ -160,7 +160,8 @@ class Map : public Properties
{
BLOCKMASK_WALL = 0x80, // = bin 1000 0000
BLOCKMASK_CHARACTER = 0x01, // = bin 0000 0001
- BLOCKMASK_MONSTER = 0x02 // = bin 0000 0010
+ BLOCKMASK_MONSTER = 0x02, // = bin 0000 0010
+ BLOCKMASK_ALL = 0xFF // = bin 1111 1111
};
enum DebugFlags
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;
}