summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-03-04 02:58:12 +0300
committerAndrei Karas <akaras@inbox.ru>2013-03-04 22:00:41 +0300
commit46106e962bee32271ee644224c5ac525eb32f888 (patch)
treec098cb2aa421bff026e499b35f88b7185e995099 /src/gui
parent28e10f7225551b1dc2e1f35b8d4d145db528e4c7 (diff)
downloadmanaverse-46106e962bee32271ee644224c5ac525eb32f888.tar.gz
manaverse-46106e962bee32271ee644224c5ac525eb32f888.tar.bz2
manaverse-46106e962bee32271ee644224c5ac525eb32f888.tar.xz
manaverse-46106e962bee32271ee644224c5ac525eb32f888.zip
Add different effects to npc depend on qests status (evol only)
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/questswindow.cpp148
-rw-r--r--src/gui/questswindow.h21
2 files changed, 168 insertions, 1 deletions
diff --git a/src/gui/questswindow.cpp b/src/gui/questswindow.cpp
index 076e042f9..390c60314 100644
--- a/src/gui/questswindow.cpp
+++ b/src/gui/questswindow.cpp
@@ -20,9 +20,11 @@
#include "gui/questswindow.h"
+#include "actorspritemanager.h"
#include "configuration.h"
#include "effectmanager.h"
#include "localplayer.h"
+#include "map.h"
#include "soundmanager.h"
#include "gui/gui.h"
@@ -37,6 +39,7 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/textfield.h"
+#include "utils/dtor.h"
#include "utils/gettext.h"
#include "utils/translation/podict.h"
@@ -96,6 +99,22 @@ class QuestsModel final : public ExtendedNamesModel
{ }
};
+struct QuestEffect final
+{
+ QuestEffect() :
+ var(0),
+ id(0),
+ effectId(0)
+ {
+ }
+
+ std::string map;
+ int var;
+ int id;
+ int effectId;
+ std::set<int> values;
+};
+
QuestsWindow::QuestsWindow() :
Window(_("Quests"), false, nullptr, "quests.xml"),
gcn::ActionListener(),
@@ -112,7 +131,8 @@ QuestsWindow::QuestsWindow() :
mCompleteIcon(Theme::getImageFromThemeXml("complete_icon.xml", "")),
mIncompleteIcon(Theme::getImageFromThemeXml("incomplete_icon.xml", "")),
mNewQuestEffectId(paths.getIntValue("newQuestEffectId")),
- mCompleteQuestEffectId(paths.getIntValue("completeQuestEffectId"))
+ mCompleteQuestEffectId(paths.getIntValue("completeQuestEffectId")),
+ mMap(nullptr)
{
setWindowName("Quests");
setResizable(true);
@@ -167,6 +187,9 @@ QuestsWindow::~QuestsWindow()
delete *it2;
}
}
+ delete_all(mAllEffects);
+ mAllEffects.clear();
+
delete mItemLinkHandler;
mItemLinkHandler = nullptr;
mQuests.clear();
@@ -201,6 +224,8 @@ void QuestsWindow::loadXml()
{
if (xmlNameEqual(questNode, "quest"))
loadQuest(id, questNode);
+ else if (xmlNameEqual(questNode, "effect"))
+ loadEffect(id, questNode);
}
}
}
@@ -250,6 +275,26 @@ void QuestsWindow::loadQuest(const int var, const XmlNodePtr node)
mQuests[var].push_back(quest);
}
+void QuestsWindow::loadEffect(const int var, const XmlNodePtr node)
+{
+ QuestEffect *const effect = new QuestEffect;
+
+ effect->map = XML::getProperty(node, "map", "");
+ effect->id = XML::getProperty(node, "npc", -1);
+ effect->effectId = XML::getProperty(node, "effect", -1);
+ const std::string values = XML::getProperty(node, "value", "");
+ effect->values = splitToIntSet(values, ',');
+
+ if (effect->map.empty() || effect->id == -1
+ || effect->effectId == -1 || values.empty())
+ {
+ delete effect;
+ return;
+ }
+ effect->var = var;
+ mAllEffects.push_back(effect);
+}
+
void QuestsWindow::action(const gcn::ActionEvent &event)
{
const std::string &eventId = event.getId();
@@ -389,6 +434,7 @@ void QuestsWindow::rebuild(const bool playSound)
}
}
}
+ updateEffects();
}
void QuestsWindow::showQuest(const QuestItem *const quest)
@@ -415,3 +461,103 @@ void QuestsWindow::showQuest(const QuestItem *const quest)
}
}
}
+
+void QuestsWindow::setMap(const Map *const map)
+{
+ if (mMap != map)
+ {
+ mMap = map;
+ mMapEffects.clear();
+ if (!mMap)
+ return;
+
+ const std::string name = mMap->getProperty("shortName");
+ logger->log("current map: " + name);
+ FOR_EACH (std::vector<QuestEffect*>::const_iterator, it, mAllEffects)
+ {
+ const QuestEffect *const effect = *it;
+ if (effect && name == effect->map)
+ mMapEffects.push_back(effect);
+ }
+ updateEffects();
+ }
+}
+
+void QuestsWindow::updateEffects()
+{
+ NpcQuestEffectMap oldNpc = mNpcEffects;
+ mNpcEffects.clear();
+
+ FOR_EACH (std::vector<const QuestEffect*>::const_iterator,
+ it, mMapEffects)
+ {
+ const QuestEffect *const effect = *it;
+ if (effect)
+ {
+ const std::map<int, int>::const_iterator
+ varIt = mVars.find(effect->var);
+ if (varIt != mVars.end())
+ {
+ const std::set<int> &vals = effect->values;
+ if (vals.find(mVars[effect->var]) != vals.end())
+ mNpcEffects[effect->id] = effect;
+ }
+ }
+ }
+ if (!actorSpriteManager)
+ return;
+
+ std::set<int> removeEffects;
+ std::map<int, int> addEffects;
+
+ // for old effects
+ FOR_EACH (NpcQuestEffectMapCIter, it, oldNpc)
+ {
+ const int id = (*it).first;
+ const QuestEffect *const effect = (*it).second;
+
+ const NpcQuestEffectMapCIter itNew = mNpcEffects.find(id);
+ if (itNew == mNpcEffects.end())
+ { // in new list no effect for this npc
+ removeEffects.insert(id);
+ }
+ else
+ { // in new list exists effect for this npc
+ const QuestEffect *const newEffect = (*itNew).second;
+ if (effect != newEffect)
+ { // new effects is not equal to old effect
+ addEffects[id] = newEffect->effectId;
+ removeEffects.insert(id);
+ }
+ }
+ }
+
+ // for new effects
+ FOR_EACH (NpcQuestEffectMapCIter, it, mNpcEffects)
+ {
+ const int id = (*it).first;
+ const QuestEffect *const effect = (*it).second;
+
+ const NpcQuestEffectMapCIter itNew = oldNpc.find(id);
+ // check if old effect was not present
+ if (itNew == oldNpc.end())
+ addEffects[id] = effect->effectId;
+ }
+ if (!removeEffects.empty() || !addEffects.empty())
+ actorSpriteManager->updateEffects(addEffects, removeEffects);
+}
+
+void QuestsWindow::addEffect(Being *const being)
+{
+ if (!being)
+ return;
+ const int id = being->getSubType();
+ const std::map<int, const QuestEffect*>::const_iterator
+ it = mNpcEffects.find(id);
+ if (it != mNpcEffects.end())
+ {
+ const QuestEffect *const effect = (*it).second;
+ if (effect)
+ being->addSpecialEffect(effect->effectId);
+ }
+}
diff --git a/src/gui/questswindow.h b/src/gui/questswindow.h
index 884b488c4..ad02c5397 100644
--- a/src/gui/questswindow.h
+++ b/src/gui/questswindow.h
@@ -32,15 +32,21 @@
#include <map>
#include <vector>
+class Being;
class Button;
class BrowserBox;
class ExtendedListBox;
class ItemLinkHandler;
+class Map;
class ScrollArea;
+class QuestEffect;
class QuestsModel;
struct QuestItem;
+typedef std::map<int, const QuestEffect*> NpcQuestEffectMap;
+typedef NpcQuestEffectMap::const_iterator NpcQuestEffectMapCIter;
+
class QuestsWindow final : public Window, public gcn::ActionListener
{
public:
@@ -66,11 +72,19 @@ class QuestsWindow final : public Window, public gcn::ActionListener
void showQuest(const QuestItem *const quest);
+ void setMap(const Map *const map);
+
+ void updateEffects();
+
+ void addEffect(Being *const being);
+
private:
void loadXml();
void loadQuest(const int var, const XmlNodePtr node);
+ void loadEffect(const int var, const XmlNodePtr node);
+
QuestsModel *mQuestsModel;
ExtendedListBox *mQuestsListBox;
ScrollArea *mQuestScrollArea;
@@ -78,13 +92,20 @@ class QuestsWindow final : public Window, public gcn::ActionListener
BrowserBox *mText;
ScrollArea *mTextScrollArea;
Button *mCloseButton;
+ //quest variables: var, value
std::map<int, int> mVars;
+ //quests: var, quests
std::map<int, std::vector<QuestItem*> > mQuests;
+ std::vector<QuestEffect*> mAllEffects;
+ std::vector<const QuestEffect*> mMapEffects;
+ //npc effects for current map and values: npc, effect
+ NpcQuestEffectMap mNpcEffects;
std::vector<QuestItem*> mQuestLinks;
Image *mCompleteIcon;
Image *mIncompleteIcon;
int mNewQuestEffectId;
int mCompleteQuestEffectId;
+ const Map *mMap;
};
extern QuestsWindow *questsWindow;