summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/beinginfo.cpp11
-rw-r--r--src/resources/beinginfo.h10
-rw-r--r--src/resources/itemdb.cpp5
-rw-r--r--src/resources/iteminfo.cpp17
-rw-r--r--src/resources/iteminfo.h20
-rw-r--r--src/resources/monsterdb.cpp18
-rw-r--r--src/resources/sounddb.cpp2
-rw-r--r--src/resources/sounddb.h2
-rw-r--r--src/resources/soundinfo.h43
9 files changed, 87 insertions, 41 deletions
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index fc6139e83..99ce2ff6f 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -92,18 +92,19 @@ void BeingInfo::setTargetCursorSize(const std::string &size)
}
}
-void BeingInfo::addSound(const SoundEvent event, const std::string &filename)
+void BeingInfo::addSound(const SoundEvent event, const std::string &filename,
+ const int delay)
{
if (mSounds.find(event) == mSounds.end())
- mSounds[event] = new StringVect;
+ mSounds[event] = new SoundInfoVect;
if (mSounds[event])
- mSounds[event]->push_back("sfx/" + filename);
+ mSounds[event]->push_back(SoundInfo("sfx/" + filename, delay));
}
-const std::string &BeingInfo::getSound(const SoundEvent event) const
+const SoundInfo &BeingInfo::getSound(const SoundEvent event) const
{
- static std::string emptySound("");
+ static SoundInfo emptySound("", 0);
const SoundEvents::const_iterator i = mSounds.find(event);
return (i == mSounds.end() || !i->second) ? emptySound :
diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h
index b5ca37bf7..9bf5417fa 100644
--- a/src/resources/beinginfo.h
+++ b/src/resources/beinginfo.h
@@ -26,6 +26,7 @@
#include "actorsprite.h"
#include "resources/cursor.h"
+#include "resources/soundinfo.h"
#include <list>
#include <map>
@@ -68,7 +69,7 @@ enum SoundEvent
SOUND_EVENT_SPAWN
};
-typedef std::map<SoundEvent, StringVect*> SoundEvents;
+typedef std::map<SoundEvent, SoundInfoVect*> SoundEvents;
/**
* Holds information about a certain type of monster. This includes the name
@@ -118,10 +119,11 @@ class BeingInfo final
ActorSprite::TargetCursorSize getTargetCursorSize() const A_WARN_UNUSED
{ return mTargetCursorSize; }
- void addSound(const SoundEvent event, const std::string &filename);
+ void addSound(const SoundEvent event, const std::string &filename,
+ const int delay);
- const std::string &getSound(const SoundEvent event)
- const A_WARN_UNUSED;
+ const SoundInfo &getSound(const SoundEvent event)
+ const A_WARN_UNUSED;
void addAttack(const int id, std::string action, const int effectId,
const int hitEffectId, const int criticalHitEffectId,
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 400c42d4f..f5d6e54ce 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -672,14 +672,15 @@ void loadSoundRef(ItemInfo *const itemInfo, const XmlNodePtr node)
const std::string event = XML::getProperty(node, "event", "");
const std::string filename = reinterpret_cast<const char*>(
node->xmlChildrenNode->content);
+ const int delay = XML::getProperty(node, "delay", 0);
if (event == "hit")
{
- itemInfo->addSound(EQUIP_EVENT_HIT, filename);
+ itemInfo->addSound(SOUND_EVENT_HIT, filename, delay);
}
else if (event == "strike" || event == "miss")
{
- itemInfo->addSound(EQUIP_EVENT_STRIKE, filename);
+ itemInfo->addSound(SOUND_EVENT_MISS, filename, delay);
}
else
{
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
index 4ec5d81f9..a6372ca93 100644
--- a/src/resources/iteminfo.cpp
+++ b/src/resources/iteminfo.cpp
@@ -23,6 +23,7 @@
#include "resources/iteminfo.h"
#include "resources/itemdb.h"
+
#include "configuration.h"
#include "utils/dtor.h"
@@ -105,22 +106,24 @@ void ItemInfo::setAttackAction(const std::string &attackAction)
mAttackAction = attackAction;
}
-void ItemInfo::addSound(const EquipmentSoundEvent event,
- const std::string &filename)
+void ItemInfo::addSound(const SoundEvent event,
+ const std::string &filename, const int delay)
{
- mSounds[event].push_back(paths.getStringValue("sfx").append(filename));
+ mSounds[event].push_back(SoundInfo(
+ paths.getStringValue("sfx").append(filename), delay));
}
-const std::string &ItemInfo::getSound(const EquipmentSoundEvent event) const
+const SoundInfo &ItemInfo::getSound(const SoundEvent event) const
{
- static const std::string empty;
- std::map<EquipmentSoundEvent, StringVect>::const_iterator i;
+ static const SoundInfo empty("", 0);
+ std::map<SoundEvent, SoundInfoVect>::const_iterator i;
i = mSounds.find(event);
if (i == mSounds.end())
return empty;
- return (!i->second.empty()) ? i->second[rand() % i->second.size()] : empty;
+ return (!i->second.empty()) ? i->second[rand()
+ % i->second.size()] : empty;
}
std::map<int, int> *ItemInfo::addReplaceSprite(const int sprite,
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index e5b6f96b8..12dbb3c03 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -26,18 +26,11 @@
#include "being.h"
#include "resources/colordb.h"
+#include "resources/soundinfo.h"
#include <map>
#include <set>
-enum EquipmentSoundEvent
-{
- // miss
- EQUIP_EVENT_STRIKE = 0,
- // hit
- EQUIP_EVENT_HIT
-};
-
enum EquipmentSlot
{
// Equipment rules:
@@ -215,11 +208,12 @@ class ItemInfo final
void setAttackRange(const int r)
{ mAttackRange = r; }
- void addSound(const EquipmentSoundEvent event,
- const std::string &filename);
+ void addSound(const SoundEvent event,
+ const std::string &filename,
+ const int delay);
- const std::string &getSound(const EquipmentSoundEvent event)
- const A_WARN_UNUSED;
+ const SoundInfo &getSound(const SoundEvent event)
+ const A_WARN_UNUSED;
int getDrawBefore(const int direction) const A_WARN_UNUSED;
@@ -328,7 +322,7 @@ class ItemInfo final
std::map <int, std::string> mAnimationFiles;
/** Stores the names of sounds to be played at certain event. */
- std::map <EquipmentSoundEvent, StringVect> mSounds;
+ std::map <SoundEvent, SoundInfoVect> mSounds;
std::map <int, int> mTags;
const std::map <int, ColorDB::ItemColor> *mColors;
std::string mColorList;
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index 2fe6596b0..269cd59cd 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -147,41 +147,43 @@ void MonsterDB::load()
const std::string event = XML::getProperty(
spriteNode, "event", "");
+ const int delay = XML::getProperty(
+ spriteNode, "delay", 0);
const char *filename;
filename = reinterpret_cast<const char*>(
spriteNode->xmlChildrenNode->content);
if (event == "hit")
{
- currentInfo->addSound(SOUND_EVENT_HIT, filename);
+ currentInfo->addSound(SOUND_EVENT_HIT, filename, delay);
}
else if (event == "miss")
{
- currentInfo->addSound(SOUND_EVENT_MISS, filename);
+ currentInfo->addSound(SOUND_EVENT_MISS, filename, delay);
}
else if (event == "hurt")
{
- currentInfo->addSound(SOUND_EVENT_HURT, filename);
+ currentInfo->addSound(SOUND_EVENT_HURT, filename, delay);
}
else if (event == "die")
{
- currentInfo->addSound(SOUND_EVENT_DIE, filename);
+ currentInfo->addSound(SOUND_EVENT_DIE, filename, delay);
}
else if (event == "move")
{
- currentInfo->addSound(SOUND_EVENT_MOVE, filename);
+ currentInfo->addSound(SOUND_EVENT_MOVE, filename, delay);
}
else if (event == "sit")
{
- currentInfo->addSound(SOUND_EVENT_SIT, filename);
+ currentInfo->addSound(SOUND_EVENT_SIT, filename, delay);
}
else if (event == "sittop")
{
- currentInfo->addSound(SOUND_EVENT_SITTOP, filename);
+ currentInfo->addSound(SOUND_EVENT_SITTOP, filename, delay);
}
else if (event == "spawn")
{
- currentInfo->addSound(SOUND_EVENT_SPAWN, filename);
+ currentInfo->addSound(SOUND_EVENT_SPAWN, filename, delay);
}
else
{
diff --git a/src/resources/sounddb.cpp b/src/resources/sounddb.cpp
index 28ab3509c..9cf303322 100644
--- a/src/resources/sounddb.cpp
+++ b/src/resources/sounddb.cpp
@@ -1,5 +1,5 @@
/*
- * Color database
+ * The ManaPlus Client
* Copyright (C) 2013 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
diff --git a/src/resources/sounddb.h b/src/resources/sounddb.h
index fc1a71229..560cdb4be 100644
--- a/src/resources/sounddb.h
+++ b/src/resources/sounddb.h
@@ -1,5 +1,5 @@
/*
- * Color database
+ * The ManaPlus Client
* Copyright (C) 2013 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
diff --git a/src/resources/soundinfo.h b/src/resources/soundinfo.h
new file mode 100644
index 000000000..f60892e1c
--- /dev/null
+++ b/src/resources/soundinfo.h
@@ -0,0 +1,43 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SOUNDINFO_H
+#define SOUNDINFO_H
+
+#include <string>
+#include <vector>
+
+#include "localconsts.h"
+
+struct SoundInfo final
+{
+ SoundInfo(const std::string &sound0, const int delay0) :
+ sound(sound0),
+ delay(delay0)
+ {
+ }
+
+ std::string sound;
+ int delay;
+};
+
+typedef std::vector<SoundInfo> SoundInfoVect;
+
+#endif