aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-11-30 17:54:13 -0500
committerClyne Sullivan <tullivan99@gmail.com>2016-11-30 17:54:13 -0500
commit1024fe8305e5b0a7bb1f660a1cee077172d84534 (patch)
tree3153bc45fe98809c3d7e81f14710c0a0c6e0a6a2 /src
parent8c80ad1431512979e364e540a239e806851e4ada (diff)
quest system
Diffstat (limited to 'src')
-rw-r--r--src/components.cpp36
-rw-r--r--src/engine.cpp7
-rw-r--r--src/quest.cpp46
-rw-r--r--src/ui.cpp17
-rw-r--r--src/ui_menu.cpp10
5 files changed, 103 insertions, 13 deletions
diff --git a/src/components.cpp b/src/components.cpp
index 38fd7a6..eb9fb0e 100644
--- a/src/components.cpp
+++ b/src/components.cpp
@@ -8,6 +8,7 @@
#include <engine.hpp>
#include <world.hpp>
#include <brice.hpp>
+#include <quest.hpp>
static std::vector<std::string> randomDialog (readFileA("assets/dialog_en-us"));
@@ -158,9 +159,11 @@ void DialogSystem::receive(const MouseClickEvent &mce)
((mce.position.y > pos.y) & (mce.position.y < pos.y + dim.height))) {
std::thread([&] {
- auto exml = game::engine.getSystem<WorldSystem>()->getXML()->FirstChildElement("Dialog");
+ std::string questAssignedText;
int newIndex;
+ auto exml = game::engine.getSystem<WorldSystem>()->getXML()->FirstChildElement("Dialog");
+
if (e.has_component<Direction>())
d.talking = true;
@@ -182,6 +185,34 @@ void DialogSystem::receive(const MouseClickEvent &mce)
game::briceUpdate();
}
+ auto qxml = exml->FirstChildElement("quest");
+ if (qxml != nullptr) {
+ std::string qname;
+ auto qsys = game::engine.getSystem<QuestSystem>();
+
+ do {
+ // assign quest
+ qname = qxml->StrAttribute("assign");
+ if (!qname.empty()) {
+ questAssignedText = qname;
+ qsys->assign(qname, qxml->StrAttribute("desc"), "req"); // gettext() for req
+ }
+
+ // check / finish quest
+ else {
+ qname = qxml->StrAttribute("check");
+ if (!(qname.empty() && qsys->hasQuest(qname) && qsys->finish(qname))) {
+ ui::dialogBox(name.name, "", false, "Finish my quest u nug");
+ ui::waitForDialog();
+ return;
+ // oldidx = d.index;
+ // d.index = qxml->UnsignedAttribute("fail");
+ // goto COMMONAIFUNC;
+ }
+ }
+ } while((qxml = qxml->NextSiblingElement()));
+ }
+
auto cxml = exml->FirstChildElement("content");
const char *content;
if (cxml == nullptr) {
@@ -194,6 +225,9 @@ void DialogSystem::receive(const MouseClickEvent &mce)
ui::dialogBox(name.name, "", false, content);
ui::waitForDialog();
+ if (!questAssignedText.empty())
+ ui::passiveImportantText(4000, ("Quest assigned:\n\"" + questAssignedText + "\"").c_str());
+
if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR)
d.index = newIndex;
}
diff --git a/src/engine.cpp b/src/engine.cpp
index 7c9a404..e5b2b36 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -7,6 +7,7 @@
#include <inventory.hpp>
#include <components.hpp>
#include <player.hpp>
+#include <quest.hpp>
Engine::Engine(void)
: shouldRun(true), systems(game::entities, game::events)
@@ -23,6 +24,7 @@ void Engine::init(void) {
//systems.add<InventorySystem>();
systems.add<WorldSystem>();
systems.add<PlayerSystem>();
+ systems.add<QuestSystem>();
systems.add<PhysicsSystem>();
systems.add<MovementSystem>();
@@ -39,7 +41,7 @@ void Engine::render(entityx::TimeDelta dt)
{
systems.update<RenderSystem>(dt);
systems.update<WindowSystem>(dt);
- //systems.update<InventorySystem>(dt);
+ //systems.update<InventorySystem>(dt); // doesn't do anything...
ui::fadeUpdate();
}
@@ -48,9 +50,10 @@ void Engine::update(entityx::TimeDelta dt)
{
systems.update<InputSystem>(dt);
systems.update<MovementSystem>(dt);
- systems.update<DialogSystem>(dt);
+ //systems.update<DialogSystem>(dt); // doesn't do anything
systems.update<WorldSystem>(dt);
systems.update<PlayerSystem>(dt);
+ //systems.update<QuestSystem>(dt); // doesn't do anything
}
diff --git a/src/quest.cpp b/src/quest.cpp
new file mode 100644
index 0000000..f7548d2
--- /dev/null
+++ b/src/quest.cpp
@@ -0,0 +1,46 @@
+#include <quest.hpp>
+
+#include <algorithm>
+
+void QuestSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
+{
+ (void)en;
+ (void)ev;
+ (void)dt;
+}
+
+int QuestSystem::assign(std::string title, std::string desc, std::string req)
+{
+ (void)req;
+ current.emplace_back(title, desc);
+ return 0;
+}
+
+int QuestSystem::drop(std::string title)
+{
+ current.erase(std::remove_if(std::begin(current), std::end(current),
+ [&title](const Quest& q) { return (q.name == title); }));
+ return 0;
+}
+
+int QuestSystem::finish(std::string title)
+{
+ auto quest = std::find_if(std::begin(current), std::end(current),
+ [&title](const Quest& q) { return (q.name == title); });
+
+ if (quest == std::end(current))
+ return -1;
+
+ // TODO requirements
+
+ drop(title);
+
+ return 0;
+}
+
+bool QuestSystem::hasQuest(std::string title)
+{
+ return (std::find_if(std::begin(current), std::end(current),
+ [&title](const Quest& q) { return (q.name == title); }) != std::end(current));
+}
+
diff --git a/src/ui.cpp b/src/ui.cpp
index bc1f28c..1652f10 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -411,13 +411,16 @@ namespace ui {
}
float putStringCentered(const float x, const float y, std::string s) {
- unsigned int i = 0;
- float width = 0;
+ unsigned int i = 0, lastnl = 0;
+ float width = 0, yy = y;
do {
switch (s[i]) {
case '\n':
- // TODO
+ putString(floor(x - width / 2), yy, s.substr(0, i));
+ lastnl = 1 + i;
+ width = 0;
+ yy -= fontSize * 1.15f;
break;
case '\b':
break;
@@ -429,7 +432,8 @@ namespace ui {
break;
}
} while(s[++i]);
- putString(floor(x-width/2),y,s);
+
+ putString(floor(x - width / 2), yy, s.substr(lastnl));
return width;
}
@@ -478,17 +482,20 @@ namespace ui {
case '!':
case '?':
case '.':
+ case ':':
tadv = 10;
break;
case ',':
+ case ';':
tadv = 5;
break;
default:
tadv = 1;
break;
}
- } else
+ } else {
typeOutDone = true;
+ }
}
return ret; // The buffered string.
diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp
index f6f962d..59b44e6 100644
--- a/src/ui_menu.cpp
+++ b/src/ui_menu.cpp
@@ -159,11 +159,11 @@ namespace ui {
void init(void) {
// Create the main pause menu
- pauseMenu.items.push_back(ui::menu::createParentButton({-128,0},{256,75},{0.0f,0.0f,0.0f}, "Resume"));
- pauseMenu.items.push_back(ui::menu::createChildButton({-128,-100},{256,75},{0.0f,0.0f,0.0f}, "Options", &optionsMenu));
- pauseMenu.items.push_back(ui::menu::createChildButton({-128,-200},{256,75},{0.0f,0.0f,0.0f}, "Controls", &controlsMenu));
- pauseMenu.items.push_back(ui::menu::createButton({-128,-300},{256,75},{0.0f,0.0f,0.0f}, "Save and Quit", ui::quitGame));
- pauseMenu.items.push_back(ui::menu::createButton({-128,-400},{256,75},{0.0f,0.0f,0.0f}, "Segfault", segFault));
+ pauseMenu.items.push_back(ui::menu::createParentButton({-128,100},{256,75},{0.0f,0.0f,0.0f}, "Resume"));
+ pauseMenu.items.push_back(ui::menu::createChildButton({-128, 0},{256,75},{0.0f,0.0f,0.0f}, "Options", &optionsMenu));
+ pauseMenu.items.push_back(ui::menu::createChildButton({-128,-100},{256,75},{0.0f,0.0f,0.0f}, "Controls", &controlsMenu));
+ pauseMenu.items.push_back(ui::menu::createButton({-128,-200},{256,75},{0.0f,0.0f,0.0f}, "Save and Quit", ui::quitGame));
+ pauseMenu.items.push_back(ui::menu::createButton({-128,-300},{256,75},{0.0f,0.0f,0.0f}, "Segfault", segFault));
// Create the options (sound) menu
optionsMenu.items.push_back(ui::menu::createSlider({0-static_cast<float>(game::SCREEN_WIDTH)/4,0-(512/2)}, {50,512}, {0.0f, 0.0f, 0.0f}, 0, 100, "Master", &game::config::VOLUME_MASTER));