if(World::current() == NULL)
throw std::runtime_error("Can't save state without active World");
- if(WorldMap::current() != NULL)
- WorldMap::current()->save_state();
+ WorldMap::current()->save_state();
World::current()->save_state();
}
+void update_worldmap()
+{
+ using namespace WorldMapNS;
+
+ if(World::current() == NULL)
+ throw std::runtime_error("Can't save state without active World");
+
+ WorldMap::current()->load_state();
+}
+
// not added to header, function to only be used by others
// in this file
bool validate_sector_player()
}
+static SQInteger update_worldmap_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::update_worldmap();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'update_worldmap'"));
+ return SQ_ERROR;
+ }
+
+}
+
static SQInteger debug_collrects_wrapper(HSQUIRRELVM vm)
{
SQBool arg0;
throw SquirrelError(v, "Couldn't register function 'save_state'");
}
+ sq_pushstring(v, "update_worldmap", -1);
+ sq_newclosure(v, &update_worldmap_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'update_worldmap'");
+ }
+
sq_pushstring(v, "debug_collrects", -1);
sq_newclosure(v, &debug_collrects_wrapper, 0);
if(SQ_FAILED(sq_createslot(v, -3))) {
{
using namespace Scripting;
+ save_state();
+
for(ScriptList::iterator i = scripts.begin();
i != scripts.end(); ++i) {
HSQOBJECT& object = *i;
save_state();
- if (old_level_state != level->solved && level->auto_path) {
+ if (old_level_state != level->solved) {
// Try to detect the next direction to which we should walk
// FIXME: Mostly a hack
Direction dir = D_NONE;
const Tile* tile = at(tux->get_tile_pos());
+ int dirdata = tile->getData() & Tile::WORLDMAP_DIR_MASK;
// first, test for crossroads
- if (tile->getData() & Tile::WORLDMAP_CNSE || tile->getData() && Tile::WORLDMAP_CNSW
- || tile->getData() & Tile::WORLDMAP_CNEW || tile->getData() && Tile::WORLDMAP_CSEW
- || tile->getData() & Tile::WORLDMAP_CNSEW)
+ if (dirdata == Tile::WORLDMAP_CNSE ||
+ dirdata == Tile::WORLDMAP_CNSW ||
+ dirdata == Tile::WORLDMAP_CNEW ||
+ dirdata == Tile::WORLDMAP_CSEW ||
+ dirdata == Tile::WORLDMAP_CNSEW)
dir = D_NONE;
- else if (tile->getData() & Tile::WORLDMAP_NORTH
+ else if (dirdata & Tile::WORLDMAP_NORTH
&& tux->back_direction != D_NORTH)
dir = D_NORTH;
- else if (tile->getData() & Tile::WORLDMAP_SOUTH
+ else if (dirdata & Tile::WORLDMAP_SOUTH
&& tux->back_direction != D_SOUTH)
dir = D_SOUTH;
- else if (tile->getData() & Tile::WORLDMAP_EAST
+ else if (dirdata & Tile::WORLDMAP_EAST
&& tux->back_direction != D_EAST)
dir = D_EAST;
- else if (tile->getData() & Tile::WORLDMAP_WEST
+ else if (dirdata & Tile::WORLDMAP_WEST
&& tux->back_direction != D_WEST)
dir = D_WEST;
bool enter_level = false;
if(main_controller->pressed(Controller::ACTION)
|| main_controller->pressed(Controller::JUMP)
- || main_controller->pressed(Controller::MENU_SELECT))
- enter_level = true;
+ || main_controller->pressed(Controller::MENU_SELECT)) {
+ /* some people define UP and JUMP on the same key... */
+ if(!main_controller->pressed(Controller::UP))
+ enter_level = true;
+ }
if(main_controller->pressed(Controller::PAUSE_MENU))
on_escape_press();
LevelTile* level = at_level();
if (level && (level->auto_play) && (!level->solved) && (!tux->is_moving())) {
enter_level = true;
- level->solved = true;
}
if (enter_level && !tux->is_moving())
for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
LevelTile* level = *i;
- if (level->solved) {
- sq_pushstring(vm, level->get_name().c_str(), -1);
- sq_newtable(vm);
+ sq_pushstring(vm, level->get_name().c_str(), -1);
+ sq_newtable(vm);
- store_bool(vm, "solved", true);
- // TODO write statistics
- // i->statistics.write(writer);
+ store_bool(vm, "solved", level->solved);
+ // TODO write statistics
+ // i->statistics.write(writer);
- sq_createslot(vm, -3);
- }
+ sq_createslot(vm, -3);
}
sq_createslot(vm, -3);