(mirror-action "right")
)
)
+
+ (sprite
+ (name "red-potion")
+ (action
+ (name "default")
+ (images "powerups/potions/red-potion.png")
+ )
+ )
+
+ (sprite
+ (name "blue-potion")
+ (action
+ (name "default")
+ (images "powerups/potions/blue-potion.png")
+ )
+ )
)
+
(name "main")
(music "theme.ogg")
(gravity 10.000000)
- (background (image "arctis.jpg")
- (speed 0.5))
(tilemap
(layer "background")
(solid #f)
(tiles
61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61
61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 0 0 0 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 62 0 0 0 0 0 0 0 62 0 0 61
+ 61 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
61 0 0 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 0 0 61
61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 62 0 0 0 0 61
61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 62 0 61
+ 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 62 0 0 0 0 0 61
+ 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 0 0 0 0 0 0 0 0 62 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 62 0 0 0 0 0 0 0 61
+ 61 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 0 0 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
- 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
+ 61 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
61 0 0 0 0 0 0 26 0 83 0 0 0 102 0 102 0 0 0 128 0 0 0 103 0 0 0 0 0 61
61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61
(image "arctis.jpg")
(speed 0.500000)
)
- (spawnpoint (name "main") (x 96) (y 160))
- (secretarea (x 133.000015258789)
- (y 58.9999771118164)
- (width 730.504028320312)
- (height 127.476585388184)
- (message "This is a Secret Area Test"))
+ (background
+ (image "arctis.jpg")
+ (speed 0.500000)
+ )
+ (spawnpoint (name "main") (x 33) (y 160))
(infoblock (x 128) (y 800)
(message (_ "-Info
-#This is an info block
-#(WOW GREAT)
-#This rocks"))
+#Beware of these crazy
+#red potions.
+#Better seek for blue
+#potions."))
+ )
+ (bonusblock (x 96) (y 800)
+ (contents "custom")
+ (powerup
+ (sprite "red-potion")
+ (script "
+function wait(time) {
+ set_wakeup_time(time);
+ suspend();
+}
+
+DisplayEffect.set_black(true);
+wait(0.1);
+DisplayEffect.set_black(false);
+wait(0.07);
+DisplayEffect.set_black(true);
+wait(0.11);
+DisplayEffect.set_black(false);
+wait(0.09);
+DisplayEffect.set_black(true);
+wait(0.6);
+Level.flip_vertically();
+DisplayEffect.fade_in(1);
+")
+ )
+ )
+ (bonusblock (x 470) (y 96)
+ (contents "custom")
+ (powerup
+ (sprite "blue-potion")
+ (script "
+function wait(time) {
+ set_wakeup_time(time);
+ suspend();
+}
+DisplayEffect.fade_out(1);
+wait(1);
+Level.flip_vertically();
+DisplayEffect.fade_in(1);
+")
+ )
)
)
)
(mriceblock (x 439) (y 159) (stay-on-platform #t))
(mriceblock (x 479) (y 159) (stay-on-platform #f))
(zeekling (x 1000) (y 140))
- (powerup (x 900) (y 140) (type "star"))
- (powerup (x 940) (y 140) (type "fireflower"))
- (powerup (x 980) (y 140) (type "egg"))
- (powerup (x 1020) (y 140) (type "1up"))
+ (powerup (x 900) (y 140) (sprite "star"))
+ (powerup (x 940) (y 140) (sprite "fireflower"))
+ (powerup (x 980) (y 140) (sprite "egg"))
+ (powerup (x 1020) (y 140) (sprite "1up"))
+ (powerup (x 1400) (y 140)
+ (sprite "red-potion")
+ (contents "custom")
+ (script "Level.flip_vertically();")
+ )
+
(trampoline (x 250) (y 150) (power 7.5))
(dispenser (x 700) (y 100) (badguy "random") (cycle 1))
)
#include <float.h>
#include <sstream>
+#include <memory>
#include "yeti.h"
#include "object/camera.h"
#include "yeti_stalactite.h"
// start script
if(dead_script != "") {
- try {
- ScriptInterpreter* interpreter
- = new ScriptInterpreter(GameSession::current()->get_working_directory());
- interpreter->register_sector(Sector::current());
- std::istringstream in(dead_script);
- interpreter->load_script(in, "Yeti - dead-script");
- interpreter->start_script();
- Sector::current()->add_object(interpreter);
- } catch(std::exception& e) {
- std::cerr << "Couldn't execute yeti dead script: " << e.what() << "\n";
- }
+ ScriptInterpreter::add_script_object(Sector::current(),
+ "Yeti - dead-script", dead_script);
}
} else {
safe_timer.start(SAFE_TIME);
#include "flip_level_transformer.h"
#include "object/tilemap.h"
+#include "object/camera.h"
#include "badguy/badguy.h"
#include "sector.h"
#include "tile_manager.h"
if(tilemap) {
transform_tilemap(tilemap);
}
+ Player* player = dynamic_cast<Player*> (object);
+ if(player) {
+ Vector pos = player->get_pos();
+ pos.y = height - pos.y;
+ player->move(pos);
+ continue;
+ }
BadGuy* badguy = dynamic_cast<BadGuy*> (object);
if(badguy) {
transform_badguy(height, badguy);
- } else {
- MovingObject* mobject = dynamic_cast<MovingObject*> (object);
- if(mobject) {
- transform_moving_object(height, mobject);
- }
+ continue;
+ }
+
+ MovingObject* mobject = dynamic_cast<MovingObject*> (object);
+ if(mobject) {
+ transform_moving_object(height, mobject);
}
}
for(Sector::SpawnPoints::iterator i = sector->spawnpoints.begin();
i != sector->spawnpoints.end(); ++i) {
transform_spawnpoint(height, *i);
}
+
+ if(sector->camera != 0 && sector->player != 0)
+ sector->camera->reset(sector->player->get_pos());
}
void
tilemap->change(x, y2, t1->getID());
}
}
- tilemap->set_drawing_effect(VERTICAL_FLIP);
+ if(tilemap->get_drawing_effect() != 0) {
+ tilemap->set_drawing_effect(0);
+ } else {
+ tilemap->set_drawing_effect(VERTICAL_FLIP);
+ }
}
void
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
-
#include <config.h>
#include "block.h"
+
+#include <stdexcept>
+
#include "resources.h"
#include "player.h"
#include "sector.h"
#include "badguy/badguy.h"
#include "coin.h"
#include "object_factory.h"
+#include "lisp/list_iterator.h"
+#include "object_factory.h"
static const float BOUNCY_BRICK_MAX_OFFSET=8;
static const float BOUNCY_BRICK_SPEED=90;
//---------------------------------------------------------------------------
BonusBlock::BonusBlock(const Vector& pos, int data)
- : Block(sprite_manager->create("bonusblock"))
+ : Block(sprite_manager->create("bonusblock")), object(0)
{
bbox.set_pos(pos);
sprite->set_action("normal");
: Block(sprite_manager->create("bonusblock"))
{
Vector pos;
- lisp.get("x", pos.x);
- lisp.get("y", pos.y);
- bbox.set_pos(pos);
- std::string contentstring;
contents = CONTENT_COIN;
- if(lisp.get("contents", contentstring)) {
- if(contentstring == "coin") {
- contents = CONTENT_COIN;
- } else if(contentstring == "firegrow") {
- contents = CONTENT_FIREGROW;
- } else if(contentstring == "icegrow") {
- contents = CONTENT_ICEGROW;
- } else if(contentstring == "star") {
- contents = CONTENT_STAR;
- } else if(contentstring == "1up") {
- contents = CONTENT_1UP;
+ lisp::ListIterator iter(&lisp);
+ while(iter.next()) {
+ const std::string& token = iter.item();
+ if(token == "x") {
+ iter.value()->get(pos.x);
+ } else if(token == "y") {
+ iter.value()->get(pos.y);
+ } else if(token == "contents") {
+ std::string contentstring;
+ iter.value()->get(contentstring);
+ if(contentstring == "coin") {
+ contents = CONTENT_COIN;
+ } else if(contentstring == "firegrow") {
+ contents = CONTENT_FIREGROW;
+ } else if(contentstring == "icegrow") {
+ contents = CONTENT_ICEGROW;
+ } else if(contentstring == "star") {
+ contents = CONTENT_STAR;
+ } else if(contentstring == "1up") {
+ contents = CONTENT_1UP;
+ } else if(contentstring == "custom") {
+ contents = CONTENT_CUSTOM;
+ } else {
+ std::cerr << "Invalid box contents '" << contentstring << "'.\n";
+ }
} else {
- std::cerr << "Invalid box contents '" << contentstring << "'.\n";
- }
+ if(contents == CONTENT_CUSTOM) {
+ GameObject* game_object = create_object(token, *(iter.lisp()));
+ object = dynamic_cast<MovingObject*> (game_object);
+ if(object == 0)
+ throw std::runtime_error(
+ "Only MovingObjects are allowed inside BonusBlocks");
+ } else {
+ std::cerr << "Invalid element '" << token << "' in bonusblock.\n";
+ }
+ }
}
+
+ if(contents == CONTENT_CUSTOM && object == 0)
+ throw std::runtime_error("Need to specify content object for custom block");
+
+ bbox.set_pos(pos);
+}
+
+BonusBlock::~BonusBlock()
+{
+ delete object;
}
void
case CONTENT_FIREGROW:
if(player.get_status()->bonus == NO_BONUS) {
- SpecialRiser* riser = new SpecialRiser(
- new GrowUp(get_pos() + Vector(0, -32)));
+ SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp());
sector->add_object(riser);
} else {
SpecialRiser* riser = new SpecialRiser(
- new Flower(get_pos() + Vector(0, -32), Flower::FIREFLOWER));
+ get_pos(), new Flower(Flower::FIREFLOWER));
sector->add_object(riser);
}
sound_manager->play_sound("upgrade");
case CONTENT_ICEGROW:
if(player.get_status()->bonus == NO_BONUS) {
- SpecialRiser* riser = new SpecialRiser(
- new GrowUp(get_pos() + Vector(0, -32)));
+ SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp());
sector->add_object(riser);
} else {
- SpecialRiser* riser = new SpecialRiser(
- new Flower(get_pos() + Vector(0, -32), Flower::ICEFLOWER));
+ SpecialRiser* riser = new SpecialRiser(
+ get_pos(), new Flower(Flower::ICEFLOWER));
sector->add_object(riser);
}
sound_manager->play_sound("upgrade");
sector->add_object(new OneUp(get_pos()));
break;
+ case CONTENT_CUSTOM:
+ SpecialRiser* riser = new SpecialRiser(get_pos(), object);
+ object = 0;
+ sector->add_object(riser);
+ sound_manager->play_sound("upgrade");
+ break;
+
default:
assert(false);
}
sprite->set_action("empty");
}
-IMPLEMENT_FACTORY(BonusBlock, "bonusblock")
+IMPLEMENT_FACTORY(BonusBlock, "bonusblock");
//---------------------------------------------------------------------------
}
}
-//IMPLEMENT_FACTORY(Brick, "brick")
+//IMPLEMENT_FACTORY(Brick, "brick");
+
public:
BonusBlock(const Vector& pos, int data);
BonusBlock(const lisp::Lisp& lisp);
+ virtual ~BonusBlock();
void try_open();
CONTENT_FIREGROW,
CONTENT_ICEGROW,
CONTENT_STAR,
- CONTENT_1UP
+ CONTENT_1UP,
+ CONTENT_CUSTOM
};
Contents contents;
+ MovingObject* object;
};
class Brick : public Block
#include "player.h"
#include "sprite/sprite_manager.h"
-Flower::Flower(const Vector& pos, Type _type)
+Flower::Flower(Type _type)
: type(_type)
{
- bbox.set_pos(pos);
bbox.set_size(32, 32);
if(_type == FIREFLOWER)
enum Type {
FIREFLOWER, ICEFLOWER
};
- Flower(const Vector& pos, Type type);
+ Flower(Type type);
~Flower();
virtual void update(float elapsed_time);
#include "player.h"
#include "sprite/sprite_manager.h"
-GrowUp::GrowUp(const Vector& pos)
+GrowUp::GrowUp()
{
- bbox.set_pos(pos);
bbox.set_size(32, 32);
sprite = sprite_manager->create("egg");
class GrowUp : public MovingObject
{
public:
- GrowUp(const Vector& pos);
+ GrowUp();
~GrowUp();
virtual void update(float elapsed_time);
#include "sprite/sprite_manager.h"
#include "object_factory.h"
#include "sector.h"
+#include "scripting/script_interpreter.h"
PowerUp::PowerUp(const lisp::Lisp& lisp)
{
+ std::string sprite_name;
lisp.get("x", bbox.p1.x);
lisp.get("y", bbox.p1.y);
- lisp.get("type", type);
+ lisp.get("sprite", sprite_name);
+ lisp.get("script", script);
bbox.set_size(32, 32);
- sprite = sprite_manager->create(type);
+ sprite = sprite_manager->create(sprite_name);
physic.enable_gravity(true);
}
}
Player* player = dynamic_cast<Player*>(&other);
- if(player != 0) {
- if (type == "egg") {
- player->set_bonus(GROWUP_BONUS, true);
- sound_manager->play_sound("grow");
- }
- else if (type == "fireflower") {
- player->set_bonus(FIRE_BONUS, true);
- sound_manager->play_sound("fire-flower");
- }
- else if (type == "star") {
- player->make_invincible();
- }
- else if (type == "1up") {
- player->get_status()->incLives();
- }
- remove_me();
-
+ if(player == 0)
+ return FORCE_MOVE;
+
+ remove_me();
+
+ if (script != "") {
+ ScriptInterpreter::add_script_object(Sector::current(), "powerup-script",
+ script);
return ABORT_MOVE;
}
-
- return FORCE_MOVE;
+
+ // some defaults if no script has been set
+ if (sprite->get_name() == "egg") {
+ player->set_bonus(GROWUP_BONUS, true);
+ sound_manager->play_sound("grow");
+ } else if (sprite->get_name() == "fireflower") {
+ player->set_bonus(FIRE_BONUS, true);
+ sound_manager->play_sound("fire-flower");
+ } else if (sprite->get_name() == "star") {
+ player->make_invincible();
+ } else if (sprite->get_name() == "1up") {
+ player->get_status()->incLives();
+ }
+ return ABORT_MOVE;
}
void
-// $Id: growup.h 2458 2005-05-10 11:29:58Z matzebraun $
+// $Id$
//
// SuperTux
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
private:
Sprite* sprite;
Physic physic;
- std::string type;
+ std::string script;
};
#endif
#include "sector.h"
#include "sprite/sprite_manager.h"
-SpecialRiser::SpecialRiser(MovingObject* _child)
+SpecialRiser::SpecialRiser(Vector pos, MovingObject* _child)
: child(_child)
{
+ _child->set_pos(pos - Vector(0, 32));
offset = 0;
}
class SpecialRiser : public GameObject
{
public:
- SpecialRiser(MovingObject* child);
+ SpecialRiser(Vector pos, MovingObject* child);
~SpecialRiser();
virtual void update(float elapsed_time);
drawing_effect = effect;
}
+ int get_drawing_effect()
+ {
+ return drawing_effect;
+ }
+
private:
typedef std::vector<uint32_t> Tiles;
Tiles tiles;
ScriptInterpreter::draw(DrawingContext& )
{
}
+
+void
+ScriptInterpreter::add_script_object(Sector* sector, const std::string& name,
+ const std::string& script)
+{
+ try {
+ std::auto_ptr<ScriptInterpreter> interpreter
+ (new ScriptInterpreter(GameSession::current()->get_working_directory()));
+ interpreter->register_sector(sector);
+ std::istringstream in(script);
+ interpreter->load_script(in, name);
+ interpreter->start_script();
+ sector->add_object(interpreter.release());
+ } catch(std::exception& e) {
+ std::cerr << "Couldn't start '" << name << "' script: " << e.what() << "\n";
+ }
+}
+
void set_wakeup_time(float seconds);
+ /** helper function that parses a script, starts it and adds it to the sector
+ * specified
+ */
+ static void add_script_object(Sector* sector, const std::string& scriptname,
+ const std::string& script);
+
static ScriptInterpreter* current()
{
return _current;
{
public:
void play_music(const std::string& musicfile);
+ /**
+ * Play a sound effect. The name should be without path or .wav extension
+ */
void play_sound(const std::string& soundfile);
#ifndef SCRIPTING_API
return 0;
}
+static int Player_set_bonus_wrapper(HSQUIRRELVM v)
+{
+ Scripting::Player* _this;
+ sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0);
+ const char* arg0;
+ sq_getstring(v, 2, &arg0);
+
+ _this->set_bonus(arg0);
+
+ return 0;
+}
+
+static int Player_make_invincible_wrapper(HSQUIRRELVM v)
+{
+ Scripting::Player* _this;
+ sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0);
+
+ _this->make_invincible();
+
+ return 0;
+}
+
+static int Player_add_life_wrapper(HSQUIRRELVM v)
+{
+ Scripting::Player* _this;
+ sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0);
+
+ _this->add_life();
+
+ return 0;
+}
+
+static int Player_add_coins_wrapper(HSQUIRRELVM v)
+{
+ Scripting::Player* _this;
+ sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0);
+ int arg0;
+ sq_getinteger(v, 2, &arg0);
+
+ _this->add_coins(arg0);
+
+ return 0;
+}
+
static int display_text_file_wrapper(HSQUIRRELVM v)
{
const char* arg0;
{ "set_visible", &Text_set_visible_wrapper },
};
+static WrappedFunction supertux_Player_methods[] = {
+ { "set_bonus", &Player_set_bonus_wrapper },
+ { "make_invincible", &Player_make_invincible_wrapper },
+ { "add_life", &Player_add_life_wrapper },
+ { "add_coins", &Player_add_coins_wrapper },
+};
+
WrappedClass supertux_classes[] = {
{ "DisplayEffect", supertux_DisplayEffect_methods },
{ "Camera", supertux_Camera_methods },
{ "ScriptedObject", supertux_ScriptedObject_methods },
{ "Sound", supertux_Sound_methods },
{ "Text", supertux_Text_methods },
+ { "Player", supertux_Player_methods },
{ 0, 0 }
};
#include "sound.h"
#include "text.h"
#include "functions.h"
-
+#include "player.h"
// Run init script
if(init_script != "") {
- try {
- ScriptInterpreter* interpreter
- = new ScriptInterpreter(GameSession::current()->get_working_directory());
- interpreter->register_sector(this);
- std::string sourcename = std::string("Sector(") + name + ") - init";
- std::istringstream in(init_script);
- interpreter->load_script(in, sourcename);
- interpreter->start_script();
- add_object(interpreter);
- init_script = "";
- } catch(std::exception& e) {
- std::cerr << "Couldn't execute init script: " << e.what() << "\n";
- }
+ ScriptInterpreter::add_script_object(this,
+ std::string("Sector(") + name + ") - init", init_script);
}
}
#include <config.h>\r
\r
#include <sstream>\r
+#include <stdexcept>\r
+#include <memory>\r
\r
#include "scripttrigger.h"\r
#include "game_session.h"\r
bbox.set_size(w, h);\r
reader.get("script", script);\r
reader.get("button", must_activate);\r
+ if(script == "") {\r
+ throw std::runtime_error("Need to specify a script for trigger object");\r
+ }\r
\r
if (must_activate)\r
triggerevent = EVENT_ACTIVATE;\r
void\r
ScriptTrigger::event(Player& , EventType type)\r
{\r
- if(type == triggerevent)\r
- {\r
- if (script != "")\r
- {\r
- try\r
- {\r
- ScriptInterpreter* interpreter \r
- = new ScriptInterpreter(GameSession::current()->get_working_directory());\r
- interpreter->register_sector(Sector::current());\r
- std::istringstream in(script);\r
- interpreter->load_script(in, "trigger-script");\r
- interpreter->start_script();\r
- Sector::current()->add_object(interpreter);\r
- }\r
- catch(std::exception& e)\r
- {\r
- std::cerr << "Couldn't execute trigger script: " << e.what() << "\n";\r
- }\r
- }\r
- else\r
- {\r
- std::cerr << "Couldn't find trigger script.\n";\r
- }\r
- }\r
+ if(type != triggerevent)\r
+ return;\r
+\r
+ ScriptInterpreter::add_script_object(Sector::current(), "trigger - scritp",\r
+ script);\r
}\r
\r
IMPLEMENT_FACTORY(ScriptTrigger, "scripttrigger");\r
the level (in case there is one), don't show anything */
if(level_finished) {
if (level->extro_script != "") {
- ScriptInterpreter* interpreter = new ScriptInterpreter(levels_path);
- std::istringstream in(level->extro_script);
- interpreter->load_script(in, "level-extro-script");
- interpreter->start_script();
- add_object(interpreter);
+ try {
+ std::auto_ptr<ScriptInterpreter> interpreter
+ (new ScriptInterpreter(levels_path));
+ std::istringstream in(level->extro_script);
+ interpreter->load_script(in, "level-extro-script");
+ interpreter->start_script();
+ add_object(interpreter.release());
+ } catch(std::exception& e) {
+ std::cerr << "Couldn't run level-extro-script:" << e.what() << "\n";
+ }
}
if (!level->next_worldmap.empty())
sound_manager->play_music(song);
if(!intro_displayed && intro_script != "") {
- ScriptInterpreter* interpreter = new ScriptInterpreter(levels_path);
- std::istringstream in(intro_script);
- interpreter->load_script(in, "worldmap-intro-script");
- interpreter->start_script();
- add_object(interpreter);
+ try {
+ std::auto_ptr<ScriptInterpreter> interpreter
+ (new ScriptInterpreter(levels_path));
+ std::istringstream in(intro_script);
+ interpreter->load_script(in, "worldmap-intro-script");
+ interpreter->start_script();
+ add_object(interpreter.release());
+ } catch(std::exception& e) {
+ std::cerr << "Couldn't execute worldmap-intro-script: "
+ << e.what() << "\n";
+ }
intro_displayed = true;
}