WillOWisp::WillOWisp(const lisp::Lisp& reader)
: BadGuy(reader, "images/creatures/willowisp/willowisp.sprite", LAYER_FLOATINGOBJECTS), mystate(STATE_IDLE), target_sector("main"), target_spawnpoint("main")
{
+ bool running = false;
flyspeed = FLYSPEED;
track_range = TRACK_RANGE;
vanish_range = VANISH_RANGE;
reader.get("track-range", track_range);
reader.get("vanish-range", vanish_range);
reader.get("hit-script", hit_script);
+ reader.get("running", running);
const lisp::Lisp* pathLisp = reader.get_lisp("path");
if(pathLisp != NULL) {
path.reset(new Path());
- path->read(*pathLisp);
- walker.reset(new PathWalker(path.get(), false));
+ path->read(*pathLisp);
+ walker.reset(new PathWalker(path.get(), running));
+ if(running)
+ mystate = STATE_PATHMOVING_TRACK;
}
countMe = false;
walker->goto_node(node_no);
if(mystate != STATE_PATHMOVING && mystate != STATE_PATHMOVING_TRACK) {
mystate = STATE_PATHMOVING;
- walker->start_moving();
}
}
void
+WillOWisp::start_moving()
+{
+ walker->start_moving();
+}
+
+void
+WillOWisp::stop_moving()
+{
+ walker->stop_moving();
+}
+
+void
WillOWisp::set_state(const std::string& new_state)
{
if(new_state == "stopped") {
walker->start_moving();
} else if(new_state == "normal") {
mystate = STATE_IDLE;
+ } else if(new_state == "vanish") {
+ vanish();
} else {
std::ostringstream msg;
msg << "Can't set unknown willowisp state '" << new_state << "', should "
virtual void goto_node(int node_no);
virtual void set_state(const std::string& state);
+ virtual void start_moving();
+ virtual void stop_moving();
virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
* -move_path willowisp moves along the path (call goto_node)
* -move_path_track willowisp moves along path but catchs tux when he is near
* -normal "normal" mode starts tracking tux when he is near enough
+ * -vanish vanish
*/
virtual void set_state(const std::string& state) = 0;
+
+ virtual void start_moving() = 0;
+ virtual void stop_moving() = 0;
};
}
}
+static SQInteger WillOWisp_start_moving_wrapper(HSQUIRRELVM vm)
+{
+ SQUserPointer data;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0))) {
+ sq_throwerror(vm, _SC("'start_moving' called without instance"));
+ return SQ_ERROR;
+ }
+ Scripting::WillOWisp* _this = reinterpret_cast<Scripting::WillOWisp*> (data);
+
+ try {
+ _this->start_moving();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'start_moving'"));
+ return SQ_ERROR;
+ }
+
+}
+
+static SQInteger WillOWisp_stop_moving_wrapper(HSQUIRRELVM vm)
+{
+ SQUserPointer data;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0))) {
+ sq_throwerror(vm, _SC("'stop_moving' called without instance"));
+ return SQ_ERROR;
+ }
+ Scripting::WillOWisp* _this = reinterpret_cast<Scripting::WillOWisp*> (data);
+
+ try {
+ _this->stop_moving();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'stop_moving'"));
+ return SQ_ERROR;
+ }
+
+}
+
static SQInteger display_wrapper(HSQUIRRELVM vm)
{
return Scripting::display(vm);
throw SquirrelError(v, "Couldn't register function 'set_state'");
}
+ sq_pushstring(v, "start_moving", -1);
+ sq_newclosure(v, &WillOWisp_start_moving_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'start_moving'");
+ }
+
+ sq_pushstring(v, "stop_moving", -1);
+ sq_newclosure(v, &WillOWisp_stop_moving_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'stop_moving'");
+ }
+
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register class 'WillOWisp'");
}