From 48cd8419bb274345fe386d47843f9aa16910e090 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 27 Sep 2017 11:35:22 -0400 Subject: lua-scripted wandering --- src/inventory.cpp | 2 +- src/quest.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/systems/lua.cpp | 2 ++ src/systems/movement.cpp | 6 ++++-- src/ui.cpp | 4 ++-- src/world.cpp | 7 ++++--- 6 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 src/systems/lua.cpp (limited to 'src') diff --git a/src/inventory.cpp b/src/inventory.cpp index 36cc041..41fe661 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -421,7 +421,7 @@ void InventorySystem::load(void) // check signature if (std::stoi(lines[0]) != 831998) - UserError("Save file signature is invalid... (delete it)"); + UserError("Inventory save file signature is invalid... (delete it)"); for (unsigned int i = 1; i < lines.size(); i += 3) { if (lines[i].size() > 0) { diff --git a/src/quest.cpp b/src/quest.cpp index 6017247..489d71e 100644 --- a/src/quest.cpp +++ b/src/quest.cpp @@ -1,8 +1,12 @@ #include #include +#include +#include #include +#include +#include #include #include @@ -82,3 +86,37 @@ 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)); } + +void QuestSystem::save(void) +{ + std::ofstream s (game::config::xmlFolder + "quest.dat"); + + // signature? + s << "831998\n"; + + for (const auto& q : current) { + s << q.name << '\n' << q.desc << '\n'; + for (const auto& r : q.reqs) + s << r.first << ',' << std::to_string(r.second) << ','; + s << "Reward,"; + for (const auto& r : q.rewards) + s << r.first << ',' << std::to_string(r.second) << ','; + s << '\n'; + } +} + +void QuestSystem::load(void) +{ + std::ifstream sf (game::config::xmlFolder + "quest.dat"); + if (sf.good()) { + sf.close(); + auto lines = readFileA(game::config::xmlFolder + "quest.dat"); + + // check signature + if (std::stoi(lines[0]) != 831998) + UserError("Quest save file signature is invalid... (delete it)"); + + for (unsigned int i = 1; i < lines.size(); i += 3) + assign(lines[i], lines[i + 1], lines[i + 2]); + } +} diff --git a/src/systems/lua.cpp b/src/systems/lua.cpp new file mode 100644 index 0000000..b093aff --- /dev/null +++ b/src/systems/lua.cpp @@ -0,0 +1,2 @@ +#include + diff --git a/src/systems/movement.cpp b/src/systems/movement.cpp index 7ff9966..4eb574d 100644 --- a/src/systems/movement.cpp +++ b/src/systems/movement.cpp @@ -75,14 +75,16 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e // make the entity wander // TODO initialX and range? if (entity.has_component()) { - auto& countdown = entity.component()->countdown; + auto vel = entity.component()->script(); + direction.x = vel.x; + /*auto& countdown = entity.component()->countdown; if (countdown > 0) { countdown--; } else { countdown = 5000 + randGet() % 10 * 100; direction.x = (randGet() % 3 - 1) * 0.004f; - } + }*/ } } }); diff --git a/src/ui.cpp b/src/ui.cpp index dea2f8e..7af77f0 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -793,8 +793,8 @@ void UISystem::putString(const vec2& p, const std::string& s, float wrap) for (auto c : word) { switch (c) { case '\n': - //offset.y -= FontSystem::getSize() * 1.05f; - //offset.x = p.x; + offset.y -= FontSystem::getSize() * 1.05f; + offset.x = p.x; break; case '\b': //offset.x -= add.x; diff --git a/src/world.cpp b/src/world.cpp index 7904c4f..9f57b87 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -350,9 +350,10 @@ void WorldSystem::loader(void) entity.assign(wxml, abcd); else if (tname == "Grounded") entity.assign(); // no need to pass xmls... - else if (tname == "Wander") - entity.assign(); - else if (tname == "Hop") + else if (tname == "Wander") { + auto script = abcd->GetText(); + entity.assign(script != nullptr ? script : ""); + } else if (tname == "Hop") entity.assign(); else if (tname == "Health") entity.assign(wxml, abcd); -- cgit v1.2.3