4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
\r
6 // This program is free software; you can redistribute it and/or
\r
7 // modify it under the terms of the GNU General Public License
\r
8 // as published by the Free Software Foundation; either version 2
\r
9 // of the License, or (at your option) any later version.
\r
11 // This program is distributed in the hope that it will be useful,
\r
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 // GNU General Public License for more details.
\r
16 // You should have received a copy of the GNU General Public License
\r
17 // along with this program; if not, write to the Free Software
\r
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
23 #include <stdexcept>
\r
26 #include "scripttrigger.hpp"
\r
27 #include "game_session.hpp"
\r
28 #include "lisp/lisp.hpp"
\r
29 #include "lisp/writer.hpp"
\r
30 #include "object_factory.hpp"
\r
31 #include "sector.hpp"
\r
33 ScriptTrigger::ScriptTrigger(const lisp::Lisp& reader)
\r
35 bool must_activate = false;
\r
37 reader.get("x", bbox.p1.x);
\r
38 reader.get("y", bbox.p1.y);
\r
40 reader.get("width", w);
\r
41 reader.get("height", h);
\r
42 bbox.set_size(w, h);
\r
43 reader.get("script", script);
\r
44 reader.get("button", must_activate);
\r
46 throw std::runtime_error("Need to specify a script for trigger object");
\r
50 triggerevent = EVENT_ACTIVATE;
\r
52 triggerevent = EVENT_TOUCH;
\r
55 ScriptTrigger::ScriptTrigger(const Vector& pos, const std::string& script)
\r
58 bbox.set_size(32, 32);
\r
59 this->script = script;
\r
60 triggerevent = EVENT_TOUCH;
\r
63 ScriptTrigger::~ScriptTrigger()
\r
68 ScriptTrigger::write(lisp::Writer& writer)
\r
70 writer.start_list("scripttrigger");
\r
72 writer.write_float("x", bbox.p1.x);
\r
73 writer.write_float("y", bbox.p1.y);
\r
74 writer.write_float("width", bbox.get_width());
\r
75 writer.write_float("height", bbox.get_height());
\r
76 writer.write_string("script", script);
\r
77 writer.write_bool("button", (triggerevent == EVENT_ACTIVATE) ? true : false);
\r
79 writer.end_list("scripttrigger");
\r
83 ScriptTrigger::event(Player& , EventType type)
\r
85 if(type != triggerevent)
\r
88 std::istringstream stream(script);
\r
89 Sector::current()->run_script(stream, "ScriptTrigger");
\r
92 IMPLEMENT_FACTORY(ScriptTrigger, "scripttrigger");
\r