From c87aa7be71247c14fd9653286b9bc79a75420fca Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Sun, 27 May 2007 10:46:08 +0000 Subject: [PATCH] more willo changes SVN-Revision: 5060 --- src/badguy/willowisp.cpp | 23 ++++++++++++++--- src/badguy/willowisp.hpp | 2 ++ src/scripting/willowisp.hpp | 4 +++ src/scripting/wrapper.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 3 deletions(-) diff --git a/src/badguy/willowisp.cpp b/src/badguy/willowisp.cpp index 22ec6171b..cc50d6bcd 100644 --- a/src/badguy/willowisp.cpp +++ b/src/badguy/willowisp.cpp @@ -34,6 +34,7 @@ static const std::string SOUNDFILE = "sounds/willowisp.wav"; 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; @@ -45,12 +46,15 @@ WillOWisp::WillOWisp(const lisp::Lisp& reader) 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; @@ -211,11 +215,22 @@ WillOWisp::goto_node(int node_no) 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") { @@ -230,6 +245,8 @@ WillOWisp::set_state(const std::string& new_state) 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 " diff --git a/src/badguy/willowisp.hpp b/src/badguy/willowisp.hpp index d9401c8a0..2ccbc685b 100644 --- a/src/badguy/willowisp.hpp +++ b/src/badguy/willowisp.hpp @@ -50,6 +50,8 @@ public: 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); diff --git a/src/scripting/willowisp.hpp b/src/scripting/willowisp.hpp index fb1be1256..33049faee 100644 --- a/src/scripting/willowisp.hpp +++ b/src/scripting/willowisp.hpp @@ -39,8 +39,12 @@ public: * -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; }; } diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index a47c84ec2..29e61974c 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -2960,6 +2960,54 @@ static SQInteger WillOWisp_set_state_wrapper(HSQUIRRELVM vm) } +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 (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 (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); @@ -5037,6 +5085,18 @@ void register_supertux_wrapper(HSQUIRRELVM v) 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'"); } -- 2.11.0