CXX = g++
ifeq ($(TARGET_OS),linux)
- LIBS = -Llib -lgif -lentityx -lpthread -lGL -lGLEW -lfreetype \
+ LIBS = -Llib -lgif -llua -lentityx -lpthread -lGL -lGLEW -lfreetype \
-lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2main
endif
ifeq ($(TARGET_OS),win32)
- LIBS = -lgif -Llib -lentityx -lopengl32 -lglew32 -lmingw32 \
+ LIBS = -Llib -lgif -llua -lentityx -lopengl32 -lglew32 -lmingw32 \
-lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
endif
* SDL2, including SDL2_image and SDL2_mixer
* FreeType 2
* GLEW
-* libgif if not on 64-bit linux
-
-Windows builds are done with msys2, 64-bit. The compiler must support C++17. libgif for amd64 linux is currently included in the lib/ folder, so any other build set-up must supply their own copy, and change the Makefile accordingly (see what is done for win32 builds, for example).
+* giflib
+* lua (liblua linked into program)
+Windows builds are done with msys2, 64-bit. The compiler must support C++17.
Build Preparation
-----------------
#ifndef COMPONENTS_WANDER_HPP_
#define COMPONENTS_WANDER_HPP_
+#include <string>
+
+#include <systems/lua.hpp>
+
/**
* Causes the entity to wander about.
*/
struct Wander {
- Wander(float ix = 0, float r = 0)
- : initialX(ix), range(r), countdown(0) {}
+ Wander(const std::string& s = "")
+ : script(LuaSystem::makeScript(s)) {}
- float initialX;
- float range;
- int countdown;
+ LuaScript script;
};
#endif // COMPONENTS_WANDER_HPP_
titles.emplace_front(q.name);
return titles;\r
}
+
+ static void save(void);
+ static void load(void);
};
#endif // QUEST_HPP_
--- /dev/null
+#ifndef SYSTEMS_LUA_HPP_
+#define SYSTEMS_LUA_HPP_
+
+#include <string>
+#include <lua.hpp>
+
+#include <vector2.hpp>
+
+class LuaScript {
+private:
+ lua_State* state;
+ std::string script;
+
+public:
+ LuaScript(const std::string& sc = "")
+ : script(sc) {
+ state = luaL_newstate();
+ luaL_openlibs(state);
+ luaL_loadstring(state, script.c_str());
+ lua_pcall(state, 0, 0, 0);
+ }
+
+ inline auto operator()(void) {
+ lua_getglobal(state, "update");
+ lua_pcall(state, 0, LUA_MULTRET, 0);
+ if (lua_gettop(state) != 2)
+ return vec2();
+ vec2 ret (lua_tonumber(state, 1), lua_tonumber(state, 2));
+ lua_pop(state, 2);
+ return ret;
+ }
+};
+
+class LuaSystem {
+private:
+ class LuaInterpreter {
+ private:
+ lua_State* state;
+
+ public:
+ LuaInterpreter(void) {
+ state = luaL_newstate();
+ luaL_openlibs(state);
+ }
+
+ void registerFunc(const std::string& name, lua_CFunction func) {
+ lua_pushcclosure(state, func, 0);
+ lua_setglobal(state, name.c_str());
+ }
+
+ void loadFile(const std::string& name) {
+ luaL_dofile(state, name.c_str());
+ lua_pcall(state, 0, 0, 0); // 'prime' the file
+ }
+
+ void runFunc(const std::string& name) {
+ lua_getglobal(state, name.c_str());
+ lua_pcall(state, 0, 0, 0);
+ }
+ };
+
+public:
+ inline static LuaScript makeScript(const std::string& s) {
+ return LuaScript(s);
+ }
+};
+
+#endif // SYSTEMS_LUA_HPP_
+++ /dev/null
-# libgif.la - a libtool library file
-# Generated by libtool (GNU libtool) 2.4.2 Debian-2.4.2-1.11
-#
-# Please DO NOT delete this file!
-# It is necessary for linking the library.
-
-# The name that we can dlopen(3).
-dlname='libgif.so.7'
-
-# Names of this library.
-library_names='libgif.so.7.0.0 libgif.so.7 libgif.so'
-
-# The name of the static archive.
-old_library='libgif.a'
-
-# Linker flags that can not go in dependency_libs.
-inherited_linker_flags=''
-
-# Libraries that this one depends upon.
-dependency_libs=''
-
-# Names of additional weak libraries provided by this library
-weak_library_names=''
-
-# Version information for libgif.
-current=7
-age=0
-revision=0
-
-# Is this an already installed library?
-installed=yes
-
-# Should we warn about portability when linking against -modules?
-shouldnotlink=no
-
-# Files to dlopen/dlpreopen
-dlopen=''
-dlpreopen=''
-
-# Directory that this library needs to be installed in:
-libdir='/home/clyne/Downloads/giflib-5.1.4/out/lib'
#include <render.hpp>
#include <ui.hpp>
#include <inventory.hpp>
+#include <quest.hpp>
std::atomic_bool GameThread::pause;
WorldSystem::loader();
InventorySystem::load();
+ QuestSystem::load();
/////////////////////////////
// //
// save
game::briceSave();
+ QuestSystem::save();
InventorySystem::save();
WorldSystem::save();
// 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) {
#include <quest.hpp>
#include <algorithm>
+#include <iostream>
+#include <fstream>
#include <engine.hpp>
+#include <error.hpp>
+#include <fileio.hpp>
#include <inventory.hpp>
#include <tokens.hpp>
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]);
+ }
+}
--- /dev/null
+#include <systems/lua.hpp>
+
// make the entity wander
// TODO initialX and range?
if (entity.has_component<Wander>()) {
- auto& countdown = entity.component<Wander>()->countdown;
+ auto vel = entity.component<Wander>()->script();
+ direction.x = vel.x;
+ /*auto& countdown = entity.component<Wander>()->countdown;
if (countdown > 0) {
countdown--;
} else {
countdown = 5000 + randGet() % 10 * 100;
direction.x = (randGet() % 3 - 1) * 0.004f;
- }
+ }*/
}
}
});
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;
entity.assign<Dialog>(wxml, abcd);
else if (tname == "Grounded")
entity.assign<Grounded>(); // no need to pass xmls...
- else if (tname == "Wander")
- entity.assign<Wander>();
- else if (tname == "Hop")
+ else if (tname == "Wander") {
+ auto script = abcd->GetText();
+ entity.assign<Wander>(script != nullptr ? script : "");
+ } else if (tname == "Hop")
entity.assign<Hop>();
else if (tname == "Health")
entity.assign<Health>(wxml, abcd);
<Physics />
<Name value="Daddy" />
<Dialog />
- <Wander />
+ <Wander>
+ countdown = 0
+ velx = 0
+
+ update = function()
+ if (countdown == 0) then
+ countdown = 5000 + math.random(0, 2000)
+ velx = (math.random(0, 3) - 1) * 0.004
+ end
+ countdown = countdown - 1
+ return velx, 0
+ end
+ </Wander>
</npc>
<skirl>