Patch for multiple joysticks from const86 <const@mimas.ru>
[supertux.git] / src / worldmap / worldmap.cpp
index 0f91b0a..dc57331 100644 (file)
@@ -37,6 +37,7 @@
 #include "lisp/list_iterator.hpp"
 #include "lisp/parser.hpp"
 #include "object/background.hpp"
+#include "object/decal.hpp"
 #include "object/tilemap.hpp"
 #include "physfs/ifile_stream.hpp"
 #include "scripting/squirrel_error.hpp"
 
 static const float CAMERA_PAN_SPEED = 5.0;
 
-namespace WorldMapNS {
+namespace worldmap {
 
 WorldMap* WorldMap::current_ = NULL;
 
-WorldMap::WorldMap(const std::string& filename, const std::string& force_spawnpoint) :
+WorldMap::WorldMap(const std::string& filename, PlayerStatus* player_status, const std::string& force_spawnpoint) :
   tux(0),
+  player_status(player_status),
   tileset(NULL), 
   free_tileset(false),
   worldmap_menu(),
@@ -116,17 +118,17 @@ WorldMap::WorldMap(const std::string& filename, const std::string& force_spawnpo
   worldmap_menu.reset(new WorldmapMenu());
 
   // create a new squirrel table for the worldmap
-  using namespace Scripting;
+  using namespace scripting;
 
   sq_collectgarbage(global_vm);
   sq_newtable(global_vm);
   sq_pushroottable(global_vm);
   if(SQ_FAILED(sq_setdelegate(global_vm, -2)))
-    throw Scripting::SquirrelError(global_vm, "Couldn't set worldmap_table delegate");
+    throw scripting::SquirrelError(global_vm, "Couldn't set worldmap_table delegate");
 
   sq_resetobject(&worldmap_table);
   if(SQ_FAILED(sq_getstackobj(global_vm, -1, &worldmap_table)))
-    throw Scripting::SquirrelError(global_vm, "Couldn't get table from stack");
+    throw scripting::SquirrelError(global_vm, "Couldn't get table from stack");
 
   sq_addref(global_vm, &worldmap_table);
   sq_pop(global_vm, 1);
@@ -139,7 +141,7 @@ WorldMap::WorldMap(const std::string& filename, const std::string& force_spawnpo
 
 WorldMap::~WorldMap()
 {
-  using namespace Scripting;
+  using namespace scripting;
 
   if(free_tileset)
     delete tileset;
@@ -185,11 +187,11 @@ WorldMap::add_object(GameObject* object)
 void
 WorldMap::try_expose(GameObject* object)
 {
-  ScriptInterface* interface = dynamic_cast<ScriptInterface*> (object);
-  if(interface != NULL) {
-    HSQUIRRELVM vm = Scripting::global_vm;
+  ScriptInterface* object_ = dynamic_cast<ScriptInterface*> (object);
+  if(object_ != NULL) {
+    HSQUIRRELVM vm = scripting::global_vm;
     sq_pushobject(vm, worldmap_table);
-    interface->expose(vm, -1);
+    object_->expose(vm, -1);
     sq_pop(vm, 1);
   }
 }
@@ -197,13 +199,13 @@ WorldMap::try_expose(GameObject* object)
 void
 WorldMap::try_unexpose(GameObject* object)
 {
-  ScriptInterface* interface = dynamic_cast<ScriptInterface*> (object);
-  if(interface != NULL) {
-    HSQUIRRELVM vm = Scripting::global_vm;
+  ScriptInterface* object_ = dynamic_cast<ScriptInterface*> (object);
+  if(object_ != NULL) {
+    HSQUIRRELVM vm = scripting::global_vm;
     SQInteger oldtop = sq_gettop(vm);
     sq_pushobject(vm, worldmap_table);
     try {
-      interface->unexpose(vm, -1);
+      object_->unexpose(vm, -1);
     } catch(std::exception& e) {
       log_warning << "Couldn't unregister object: " << e.what() << std::endl;
     }
@@ -238,7 +240,7 @@ void
 WorldMap::change(const std::string& filename, const std::string& force_spawnpoint)
 {
   g_screen_manager->exit_screen();
-  g_screen_manager->push_screen(new WorldMap(filename, force_spawnpoint));
+  g_screen_manager->push_screen(new WorldMap(filename, player_status, force_spawnpoint));
 }
 
 void
@@ -309,6 +311,9 @@ WorldMap::load(const std::string& filename)
         Teleporter* teleporter = new Teleporter(*iter.lisp());
         teleporters.push_back(teleporter);
         add_object(teleporter);
+      } else if(iter.item() == "decal") {
+        Decal* decal = new Decal(*iter.lisp());
+        add_object(decal);
       } else if(iter.item() == "ambient-light") {
         std::vector<float> vColor;
         sector->get( "ambient-light", vColor );
@@ -610,15 +615,16 @@ WorldMap::update(float delta)
     }
 
     // handle input
+    Controller *controller = g_jk_controller->get_main_controller();
     bool enter_level = false;
-    if(g_main_controller->pressed(Controller::ACTION)
-       || g_main_controller->pressed(Controller::JUMP)
-       || g_main_controller->pressed(Controller::MENU_SELECT)) {
+    if(controller->pressed(Controller::ACTION)
+       || controller->pressed(Controller::JUMP)
+       || controller->pressed(Controller::MENU_SELECT)) {
       /* some people define UP and JUMP on the same key... */
-      if(!g_main_controller->pressed(Controller::UP))
+      if(!controller->pressed(Controller::UP))
         enter_level = true;
     }
-    if(g_main_controller->pressed(Controller::PAUSE_MENU))
+    if(controller->pressed(Controller::PAUSE_MENU))
       on_escape_press();
 
     // check for teleporters
@@ -666,7 +672,7 @@ WorldMap::update(float delta)
           // update state and savegame
           save_state();
 
-          g_screen_manager->push_screen(new GameSession(levelfile, &level->statistics),
+          g_screen_manager->push_screen(new GameSession(levelfile, player_status, &level->statistics),
                                    new ShrinkFade(shrinkpos, 1.0f));
           in_level = true;
         } catch(std::exception& e) {
@@ -885,7 +891,7 @@ WorldMap::setup()
   tux->setup();
 
   // register worldmap_table as worldmap in scripting
-  using namespace Scripting;
+  using namespace scripting;
 
   sq_pushroottable(global_vm);
   sq_pushstring(global_vm, "worldmap", -1);
@@ -911,7 +917,7 @@ WorldMap::setup()
 void
 WorldMap::leave()
 {
-  using namespace Scripting;
+  using namespace scripting;
 
   // save state of world and player
   save_state();
@@ -927,7 +933,7 @@ WorldMap::leave()
 void
 WorldMap::save_state()
 {
-  using namespace Scripting;
+  using namespace scripting;
 
   HSQUIRRELVM vm = global_vm;
   int oldtop = sq_gettop(vm);
@@ -937,7 +943,7 @@ WorldMap::save_state()
     sq_pushroottable(vm);
     sq_pushstring(vm, "state", -1);
     if(SQ_FAILED(sq_get(vm, -2)))
-      throw Scripting::SquirrelError(vm, "Couldn't get state table");
+      throw scripting::SquirrelError(vm, "Couldn't get state table");
 
     // get or create worlds table
     sq_pushstring(vm, "worlds", -1);
@@ -945,11 +951,11 @@ WorldMap::save_state()
       sq_pushstring(vm, "worlds", -1);
       sq_newtable(vm);
       if(SQ_FAILED(sq_createslot(vm, -3)))
-        throw Scripting::SquirrelError(vm, "Couldn't create state.worlds");
+        throw scripting::SquirrelError(vm, "Couldn't create state.worlds");
 
       sq_pushstring(vm, "worlds", -1);
       if(SQ_FAILED(sq_get(vm, -2)))
-        throw Scripting::SquirrelError(vm, "Couldn't create.get state.worlds");
+        throw scripting::SquirrelError(vm, "Couldn't create.get state.worlds");
     }
 
     sq_pushstring(vm, map_filename.c_str(), map_filename.length());
@@ -1006,7 +1012,7 @@ WorldMap::save_state()
 void
 WorldMap::load_state()
 {
-  using namespace Scripting;
+  using namespace scripting;
 
   HSQUIRRELVM vm = global_vm;
   int oldtop = sq_gettop(vm);
@@ -1016,22 +1022,22 @@ WorldMap::load_state()
     sq_pushroottable(vm);
     sq_pushstring(vm, "state", -1);
     if(SQ_FAILED(sq_get(vm, -2)))
-      throw Scripting::SquirrelError(vm, "Couldn't get state table");
+      throw scripting::SquirrelError(vm, "Couldn't get state table");
 
     // get worlds table
     sq_pushstring(vm, "worlds", -1);
     if(SQ_FAILED(sq_get(vm, -2)))
-      throw Scripting::SquirrelError(vm, "Couldn't get state.worlds");
+      throw scripting::SquirrelError(vm, "Couldn't get state.worlds");
 
     // get table for our world
     sq_pushstring(vm, map_filename.c_str(), map_filename.length());
     if(SQ_FAILED(sq_get(vm, -2)))
-      throw Scripting::SquirrelError(vm, "Couldn't get state.worlds.mapfilename");
+      throw scripting::SquirrelError(vm, "Couldn't get state.worlds.mapfilename");
 
     // load tux
     sq_pushstring(vm, "tux", -1);
     if(SQ_FAILED(sq_get(vm, -2)))
-      throw Scripting::SquirrelError(vm, "Couldn't get tux");
+      throw scripting::SquirrelError(vm, "Couldn't get tux");
 
     Vector p;
     p.x = read_float(vm, "x");
@@ -1045,7 +1051,7 @@ WorldMap::load_state()
     // load levels
     sq_pushstring(vm, "levels", -1);
     if(SQ_FAILED(sq_get(vm, -2)))
-      throw Scripting::SquirrelError(vm, "Couldn't get levels");
+      throw scripting::SquirrelError(vm, "Couldn't get levels");
 
     for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
       LevelTile* level = *i;
@@ -1095,7 +1101,7 @@ WorldMap::solved_level_count()
 HSQUIRRELVM
 WorldMap::run_script(std::istream& in, const std::string& sourcename)
 {
-  using namespace Scripting;
+  using namespace scripting;
 
   // garbage collect thread list
   for(ScriptList::iterator i = scripts.begin();
@@ -1148,6 +1154,6 @@ WorldMap::get_height() const
   return height;
 }
 
-} // namespace WorldMapNS
+} // namespace worldmap
 
 /* EOF */