From 62816f56a485fa91b3d157a75c1d0cf568e394cf Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Sat, 20 Jan 2007 11:04:53 +0000 Subject: [PATCH 1/1] - fix tux not advancing on worldmap after solving a level - fix some instances where worldmap wasn't saved - added a worldmapfinish() console command - svn:ignore cmake temporary files SVN-Revision: 4609 --- data/levels/world1/worldmap.stwm | 6 +++--- data/scripts/console.nut | 9 +++++++++ src/scripting/functions.cpp | 13 ++++++++++-- src/scripting/functions.hpp | 5 +++++ src/scripting/wrapper.cpp | 25 +++++++++++++++++++++++ src/tile.hpp | 1 + src/worldmap/level.cpp | 2 +- src/worldmap/level.hpp | 3 --- src/worldmap/worldmap.cpp | 43 ++++++++++++++++++++++------------------ 9 files changed, 79 insertions(+), 28 deletions(-) diff --git a/data/levels/world1/worldmap.stwm b/data/levels/world1/worldmap.stwm index 76000ed45..69f0103f1 100644 --- a/data/levels/world1/worldmap.stwm +++ b/data/levels/world1/worldmap.stwm @@ -19,8 +19,8 @@ (invisible-tile #t) (script "fadeout_screen( 2 ); state.world <- \"levels/world2/worldmap.stwm\";") - (x 54) - (y 21) + (x 37) + (y 20) ) (sprite-change (change-on-touch #t) @@ -51,7 +51,7 @@ state.world <- \"levels/world2/worldmap.stwm\";") (worldmap "levels/world2/worldmap.stwm") (spawnpoint "world1") (automatic #t) - (x 66) + (x 54) (y 21) ) (teleporter diff --git a/data/scripts/console.nut b/data/scripts/console.nut index 5da37752f..cdb190eb0 100644 --- a/data/scripts/console.nut +++ b/data/scripts/console.nut @@ -14,6 +14,15 @@ function finish() Level.finish(true); } +function worldmapfinish() +{ + save_state(); + foreach(levelname, level in state.worlds[state.world].levels) { + level.solved = true; + } + update_worldmap(); +} + function grow() { sector.Tux.add_bonus("grow"); diff --git a/src/scripting/functions.cpp b/src/scripting/functions.cpp index 236a12ad2..456b351fc 100644 --- a/src/scripting/functions.cpp +++ b/src/scripting/functions.cpp @@ -166,11 +166,20 @@ void save_state() 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() diff --git a/src/scripting/functions.hpp b/src/scripting/functions.hpp index 94fa88c07..b42aff5bb 100644 --- a/src/scripting/functions.hpp +++ b/src/scripting/functions.hpp @@ -105,6 +105,11 @@ void import(HSQUIRRELVM v, const std::string& filename); void save_state(); /** + * Update worldmap from worldmap state (state.world variable) + */ +void update_worldmap(); + +/** * enable/disable drawing of collision rectangles */ void debug_collrects(bool enable); diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 6ee9ab6f8..5b086ebb7 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -2928,6 +2928,25 @@ static SQInteger save_state_wrapper(HSQUIRRELVM vm) } +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; @@ -3767,6 +3786,12 @@ void register_supertux_wrapper(HSQUIRRELVM v) 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))) { diff --git a/src/tile.hpp b/src/tile.hpp index e1b57f4b3..7351a328f 100644 --- a/src/tile.hpp +++ b/src/tile.hpp @@ -75,6 +75,7 @@ public: WORLDMAP_SOUTH = 0x0002, WORLDMAP_EAST = 0x0004, WORLDMAP_WEST = 0x0008, + WORLDMAP_DIR_MASK = 0x000f, WORLDMAP_STOP = 0x0010, diff --git a/src/worldmap/level.cpp b/src/worldmap/level.cpp index aafa66035..2b61124c6 100644 --- a/src/worldmap/level.cpp +++ b/src/worldmap/level.cpp @@ -32,7 +32,7 @@ namespace WorldMapNS { LevelTile::LevelTile(const std::string& basedir, const lisp::Lisp* lisp) - : solved(false), auto_play(false), auto_path(true), basedir(basedir), picture_cached(false), + : solved(false), auto_play(false), basedir(basedir), picture_cached(false), picture(0) { lisp->get("name", name); diff --git a/src/worldmap/level.hpp b/src/worldmap/level.hpp index eb577f226..67945e32f 100644 --- a/src/worldmap/level.hpp +++ b/src/worldmap/level.hpp @@ -54,9 +54,6 @@ public: /** Script that is run when the level is successfully finished */ std::string extro_script; - /** If false, disables the auto walking after finishing a level */ - bool auto_path; - /** return Surface of level picture or 0 if no picture is available */ const Surface* get_picture(); diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index 28e39a7bb..c3f71d143 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -176,6 +176,8 @@ WorldMap::~WorldMap() { using namespace Scripting; + save_state(); + for(ScriptList::iterator i = scripts.begin(); i != scripts.end(); ++i) { HSQOBJECT& object = *i; @@ -432,28 +434,31 @@ WorldMap::finished_level(Level* gamelevel) 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; @@ -532,8 +537,11 @@ WorldMap::update(float delta) 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(); @@ -555,7 +563,6 @@ WorldMap::update(float delta) 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()) @@ -935,16 +942,14 @@ WorldMap::save_state() 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); -- 2.11.0