- fix tux not advancing on worldmap after solving a level
authorMatthias Braun <matze@braunis.de>
Sat, 20 Jan 2007 11:04:53 +0000 (11:04 +0000)
committerMatthias Braun <matze@braunis.de>
Sat, 20 Jan 2007 11:04:53 +0000 (11:04 +0000)
- 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
data/scripts/console.nut
src/scripting/functions.cpp
src/scripting/functions.hpp
src/scripting/wrapper.cpp
src/tile.hpp
src/worldmap/level.cpp
src/worldmap/level.hpp
src/worldmap/worldmap.cpp

index 76000ed..69f0103 100644 (file)
@@ -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
index 5da3775..cdb190e 100644 (file)
@@ -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");
index 236a12a..456b351 100644 (file)
@@ -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()
index 94fa88c..b42aff5 100644 (file)
@@ -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);
index 6ee9ab6..5b086eb 100644 (file)
@@ -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))) {
index e1b57f4..7351a32 100644 (file)
@@ -75,6 +75,7 @@ public:
     WORLDMAP_SOUTH = 0x0002,
     WORLDMAP_EAST  = 0x0004,
     WORLDMAP_WEST  = 0x0008,
+       WORLDMAP_DIR_MASK = 0x000f,
 
     WORLDMAP_STOP  = 0x0010,
 
index aafa660..2b61124 100644 (file)
@@ -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);
index eb577f2..67945e3 100644 (file)
@@ -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();
 
index 28e39a7..c3f71d1 100644 (file)
@@ -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);