summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Marks <nymacro@gmail.com>2005-05-09 09:47:20 +0000
committerAaron Marks <nymacro@gmail.com>2005-05-09 09:47:20 +0000
commitef30b72e8ad5379a7c7ee49b0ff680bde15daa66 (patch)
tree1fbe0f0ce2125bad89e548b1f2a1d392ee751205
parentb6f88ad42d2acf514804777e9cf0f4979566c163 (diff)
downloadmanaserv-ef30b72e8ad5379a7c7ee49b0ff680bde15daa66.tar.gz
manaserv-ef30b72e8ad5379a7c7ee49b0ff680bde15daa66.tar.xz
manaserv-ef30b72e8ad5379a7c7ee49b0ff680bde15daa66.zip
Renamed script-sq.* script-squirrel.*.
Renamed ScriptingInterface to Script (to save typing :)). Updated skill tree definition.
-rw-r--r--src/main.cpp28
-rw-r--r--src/script-squirrel.cpp (renamed from src/script-sq.cpp)9
-rw-r--r--src/script-squirrel.h (renamed from src/script-sq.h)7
-rw-r--r--src/script.cpp2
-rw-r--r--src/script.h18
-rw-r--r--src/skill.cpp25
-rw-r--r--src/skill.h37
7 files changed, 108 insertions, 18 deletions
diff --git a/src/main.cpp b/src/main.cpp
index c3b86cf..d30501b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -30,9 +30,12 @@
#include <SDL.h>
#include <SDL_net.h>
+#include "skill.h"
+
#include "log.h"
#define LOG_FILE "tmwserv.log"
+// Scripting
#ifdef SCRIPT_SUPPORT
#include "script.h"
@@ -44,8 +47,13 @@
#ifdef SCRIPT_RUBY_SUPPORT
#include "script-ruby.h"
#endif
+#ifdef SCRIPT_LUA_SUPPORT
+#include "script-lua.h"
+#endif
+
std::string scriptLanguage = "squirrel";
#endif
+//
#define TMW_WORLD_TICK SDL_USEREVENT
#define SERVER_PORT 9601
@@ -54,6 +62,8 @@ SDL_TimerID worldTimerID; /**< Timer ID of world timer */
int worldTime = 0; /**< Current world time in 100ms ticks */
bool running = true; /**< Determines if server keeps running */
+Skill skillTree("base"); /**< Skill tree */
+
/**
* SDL timer callback, sends a <code>TMW_WORLD_TICK</code> event.
*/
@@ -101,7 +111,7 @@ void initialize()
if (scriptLanguage == "squirrel")
{
- script = new ScriptSquirrel();
+ script = new ScriptSquirrel("main.nut");
script->init();
}
#endif
@@ -125,6 +135,17 @@ void deinitialize()
delete logger;
}
+
+/**
+ * Update game world
+ */
+void updateWorld()
+{
+#ifdef SCRIPT_SUPPORT
+ script->update();
+#endif
+}
+
/**
* Main function, initializes and runs server.
*/
@@ -166,9 +187,8 @@ int main(int argc, char *argv[])
// - Handle all messages that are in the message queue
// - Update all active objects/beings
-#ifdef SCRIPT_SUPPORT
- script->update();
-#endif
+ updateWorld();
+
}
else if (event.type == SDL_QUIT)
{
diff --git a/src/script-sq.cpp b/src/script-squirrel.cpp
index fc02616..d8001de 100644
--- a/src/script-sq.cpp
+++ b/src/script-squirrel.cpp
@@ -1,4 +1,4 @@
-#include "script-sq.h"
+#include "script-squirrel.h"
#include <cstring>
/*
@@ -68,6 +68,11 @@ void functionCall(HSQUIRRELVM v, char *fn, char *args, ...)
va_end(arglist);
}
+ScriptSquirrel::ScriptSquirrel(const std::string &file) :
+ Script(file)
+{
+}
+
ScriptSquirrel::~ScriptSquirrel()
{
sq_pop(vm, 1);
@@ -81,7 +86,7 @@ void ScriptSquirrel::init()
sq_setprintfunc(vm, printfunc);
sq_pushroottable(vm);
- sqstd_dofile(vm, _SC("test.nut"), 0, 1);
+ sqstd_dofile(vm, _SC(scriptName.c_str()), 0, 1);
if (SQ_SUCCEEDED(sqstd_dofile(vm, _SC("test.nut"), 0, 1)))
functionCall(vm, "init", NULL);
}
diff --git a/src/script-sq.h b/src/script-squirrel.h
index 688c623..e0413d3 100644
--- a/src/script-sq.h
+++ b/src/script-squirrel.h
@@ -21,8 +21,8 @@
* $Id$
*/
-#ifndef SCRIPT_SQ_H
-#define SCRIPT_SQ_H
+#ifndef SCRIPT_SQUIRREL_H
+#define SCRIPT_SQUIRREL_H
#include "script.h"
#include <cstdio>
@@ -32,11 +32,12 @@
#include <sqstdio.h>
#include <sqstdaux.h>
-class ScriptSquirrel : public ScriptingInterface
+class ScriptSquirrel : public Script
{
HSQUIRRELVM vm;
public:
+ ScriptSquirrel(const std::string &);
~ScriptSquirrel();
void init();
void destroy();
diff --git a/src/script.cpp b/src/script.cpp
index 0f51d6c..a614e03 100644
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -1,4 +1,4 @@
#include "script.h"
-ScriptingInterface *script;
+Script *script;
diff --git a/src/script.h b/src/script.h
index 32f675a..ea696b3 100644
--- a/src/script.h
+++ b/src/script.h
@@ -24,14 +24,24 @@
#ifndef SCRIPT_H
#define SCRIPT_H
+#include <iostream>
+
/*
- * ScriptingInterface provides a simple class which is a simple interface
+ * Script provides a simple class which is a simple interface
* for defining a scripting backend.
*/
-class ScriptingInterface
+class Script
{
+ protected:
+ std::string scriptName;
+
public:
- virtual ~ScriptingInterface() { };
+ Script(const std::string &file) :
+ scriptName(file)
+ {
+ }
+
+ virtual ~Script() { }
//Initialization
virtual void init() = 0;
//Destruction
@@ -42,6 +52,6 @@ class ScriptingInterface
virtual void message(char *) = 0;
};
-extern ScriptingInterface *script;
+extern Script *script;
#endif
diff --git a/src/skill.cpp b/src/skill.cpp
index e91c135..752d1df 100644
--- a/src/skill.cpp
+++ b/src/skill.cpp
@@ -24,6 +24,14 @@
#include "skill.h"
#include "log.h"
+Skill::Skill(const std::string &ident) :
+ id(ident),
+ light(0.0),
+ dark(0.0)
+{
+ //
+}
+
Skill::~Skill() {
//cleanup
for (int i = 0; i < children.size(); i++) {
@@ -47,11 +55,23 @@ bool Skill::addSkill(const std::string &ident, Skill *skill) {
return false;
}
+bool Skill::useSkill() {
+#ifdef SCRIPT_SUPPORT
+ //run skill script
+ logger->log("Error: Skill: Skills not implemented.");
+#else
+ logger->log("Error: Skill: Could not use skill; scripting disabled.");
+#endif
+}
+
+bool Skill::setScript(const std::string &scriptName)
+{
+}
+
bool Skill::deleteSkill(const std::string &ident, bool delTree) {
//prevent deletion of self
if (ident == id) {
- std::cerr << "Error: Skill: Attempt to delete self." << std::endl;
- logger->log("Error: Skill: Attempt to delete self.");
+ logger->log("Error: Skill: Attempt to delete self.");
return false;
}
@@ -75,3 +95,4 @@ bool Skill::deleteSkill(const std::string &ident, bool delTree) {
}
return false;
}
+
diff --git a/src/skill.h b/src/skill.h
index 4ef766f..8b90767 100644
--- a/src/skill.h
+++ b/src/skill.h
@@ -27,6 +27,10 @@
#include <iostream>
#include <vector>
+#ifdef SCRIPT_SUPPORT
+#include "script.h"
+#endif
+
class Skill
{
/*
@@ -43,9 +47,25 @@ class Skill
* Children skills
*/
std::vector<Skill*> children;
+
+ /*
+ * Skill properties/weighting
+ */
+ float light;
+ float dark;
+ float life;
+ float death;
+
+ /*
+ * Skill script
+ */
+#ifdef SCRIPT_SUPPORT
+ Script *script;
+#endif
+
public:
- Skill(const std::string &ident) : id(ident) { }
- ~Skill();
+ Skill(const std::string &ident);
+ virtual ~Skill();
/*
* addSkill
@@ -60,6 +80,19 @@ class Skill
bool deleteSkill(const std::string &, bool delTree = false);
/*
+ * useSkill
+ * Uses skill (runs skill script). Returns true upon successful
+ * skill completion, false otherwise.
+ */
+ bool useSkill();
+
+ /*
+ * setScript
+ * Set script for the skill to execute when used.
+ */
+ bool setScript(const std::string &);
+
+ /*
* printTree
* Print tree to stdout
*/