pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src/worldmap dot.hxx,1.5,1.6 level_dot.cx


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/worldmap dot.hxx,1.5,1.6 level_dot.cxx,1.14,1.15 level_dot.hxx,1.6,1.7 worldmap.cxx,1.36,1.37 worldmap.hxx,1.23,1.24
Date: 30 Mar 2003 22:09:35 -0000

Update of /var/lib/cvs/Games/Pingus/src/worldmap
In directory dark:/tmp/cvs-serv22712/src/worldmap

Modified Files:
        dot.hxx level_dot.cxx level_dot.hxx worldmap.cxx worldmap.hxx 
Log Message:
- added stuff to unlock finished-level's neighbours, not the fasted, but seems 
to work


Index: dot.hxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/worldmap/dot.hxx,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- dot.hxx     17 Oct 2002 16:06:21 -0000      1.5
+++ dot.hxx     30 Mar 2003 22:09:33 -0000      1.6
@@ -36,12 +36,19 @@
 
 public:
   Dot(xmlDocPtr doc, xmlNodePtr cur);
+
+  /** Draw stuff that should be displayed if the mouse is over the dot */
+  virtual void draw_hover(GraphicContext& gc) =0;
   
   Vector get_pos() { return pos; }
   float  get_z_pos() const { return pos.z; }
 
   virtual void on_click() =0;
 
+  virtual bool finished() =0;
+  virtual bool accessible() =0;
+  /** makes the node accessible */
+  virtual void unlock() =0;
 private:
   Dot (const Dot&);
   Dot& operator= (const Dot&);

Index: level_dot.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/worldmap/level_dot.cxx,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- level_dot.cxx       26 Mar 2003 12:01:17 -0000      1.14
+++ level_dot.cxx       30 Mar 2003 22:09:33 -0000      1.15
@@ -18,6 +18,10 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <iostream>
+#include "../my_gettext.hxx"
+#include "../globals.hxx"
+#include "../system.hxx"
+#include "../fonts.hxx"
 #include "../gui/graphic_context.hxx"
 #include "../gui/screen_manager.hxx"
 #include "../xml_helper.hxx"
@@ -35,10 +39,12 @@
   : Dot(doc, XMLhelper::skip_blank(cur->children)),
     green_dot_sur("misc/dot_green", "core"),
     red_dot_sur("misc/dot_red", "core"),
+    unaccessible_dot_sur("misc/dot_invalid", "core"),
     plf(0)
 {
   green_dot_sur.set_align_center();
   red_dot_sur.set_align_center();
+  unaccessible_dot_sur.set_align_center();
 
   cur = cur->children;
   // Skip dot entry
@@ -66,21 +72,19 @@
 void
 LevelDot::draw(GraphicContext& gc)
 {
-  //std::cout << "Drawing level dat: " << pos << std::endl;
   Savegame* savegame = SavegameManager::instance()->get(levelname);
   if (savegame 
       && (savegame->status == Savegame::FINISHED
           || savegame->status == Savegame::ACCESSIBLE))
     {
-      gc.draw (green_dot_sur, pos);
       if (savegame->status == Savegame::FINISHED)
-        {
-          // Draw Flag
-        }
+        gc.draw (green_dot_sur, pos);
+      else
+        gc.draw (red_dot_sur, pos);
     }
   else
     {
-      gc.draw (red_dot_sur, pos);
+      gc.draw (unaccessible_dot_sur, pos);
     }
 }
 
@@ -95,6 +99,66 @@
   std::cout << "Starting level: " << levelname << std::endl;
   ScreenManager::instance()->push_screen(new StartScreen(plf),
                                          true);
+}
+
+bool
+LevelDot::finished()
+{
+  Savegame* savegame = SavegameManager::instance()->get(levelname);
+  if (savegame && savegame->status == Savegame::FINISHED)
+    return true;
+  else
+    return false; 
+}
+
+bool
+LevelDot::accessible()
+{
+  Savegame* savegame = SavegameManager::instance()->get(levelname);
+  if (savegame && savegame->status != Savegame::NONE)
+    return true;
+  else
+    return false;
+}
+
+void
+LevelDot::draw_hover(GraphicContext& gc)
+{
+  if (accessible())
+    {
+      gc.print_center(Fonts::pingus_small,
+                      int(pos.x), int(pos.y - 30),
+                      System::translate(get_plf()->get_levelname()));
+  
+      if (maintainer_mode)
+        {
+          gc.print_center(Fonts::pingus_small,
+                          int(pos.x), int(pos.y - 56),
+                          get_plf()->get_resname());
+        }
+    }
+  else
+    {
+      gc.print_center(Fonts::pingus_small,
+                      int(pos.x), int(pos.y - 30),
+                      _("locked"));
+    }
+}
+
+void
+LevelDot::unlock()
+{
+  Savegame* savegame = SavegameManager::instance()->get(levelname);
+  if (savegame == 0 || savegame->status == Savegame::NONE)
+    {
+      Savegame savegame;
+      savegame.status = Savegame::ACCESSIBLE;
+      savegame.levelname = levelname;
+      SavegameManager::instance()->store(savegame);
+    }
+  else
+    {
+    }
 }
 
 } // namespace WorldMapNS

Index: level_dot.hxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/worldmap/level_dot.hxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- level_dot.hxx       3 Mar 2003 20:32:18 -0000       1.6
+++ level_dot.hxx       30 Mar 2003 22:09:33 -0000      1.7
@@ -32,6 +32,8 @@
 private:
   Sprite green_dot_sur;
   Sprite red_dot_sur;
+  Sprite unaccessible_dot_sur;
+
   std::string levelname;
   PLFHandle plf;
 
@@ -39,10 +41,15 @@
   LevelDot(xmlDocPtr doc, xmlNodePtr cur);
 
   void draw(GraphicContext& gc);
+  void draw_hover(GraphicContext& gc);
+
   void update();
   PLFHandle get_plf () const { return plf; }
   void on_click(); 
 
+  bool finished();
+  bool accessible();
+  void unlock();
 private:
   LevelDot (const LevelDot&);
   LevelDot& operator= (const LevelDot&);

Index: worldmap.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/worldmap/worldmap.cxx,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- worldmap.cxx        30 Mar 2003 20:43:52 -0000      1.36
+++ worldmap.cxx        30 Mar 2003 22:09:33 -0000      1.37
@@ -207,21 +207,7 @@
   Dot* dot = path_graph->get_dot(mpos.x, mpos.y);
   if (dot)
     {
-      LevelDot* leveldot = dynamic_cast<LevelDot*>(dot);
-
-      if (leveldot)
-        {
-          gc.print_center(Fonts::pingus_small,
-                          mouse_x, mouse_y - 30,
-                          
System::translate(leveldot->get_plf()->get_levelname()));
-
-          if (maintainer_mode)
-            {
-              gc.print_center(Fonts::pingus_small,
-                              mouse_x, mouse_y - 56,
-                              leveldot->get_plf()->get_resname());
-            }
-        }
+      dot->draw_hover(display_gc);
     }
 }
 
@@ -232,6 +218,7 @@
     {
       (*i)->update ();
     }
+  update_locked_nodes();
 }
 
 void
@@ -294,10 +281,17 @@
         }
       else
         {
-          if (!pingus->walk_to_node(path_graph->lookup_node(dot->get_name())))
+          if (dot->accessible())
             {
-              if (maintainer_mode)
-                std::cout << "WorldMap: NO PATH TO NODE FOUND!" << std::endl;
+              if 
(!pingus->walk_to_node(path_graph->lookup_node(dot->get_name())))
+                {
+                  if (maintainer_mode)
+                    std::cout << "WorldMap: NO PATH TO NODE FOUND!" << 
std::endl;
+                }
+            }
+          else
+            {
+              PingusSound::play_sound("chink");
             }
         }
     }
@@ -306,12 +300,15 @@
 void
 WorldMap::on_secondary_button_press(int x, int y)
 {
-  const Vector& click_pos = display_gc.screen_to_world(Vector(x, y));
-  Dot* dot = path_graph->get_dot(click_pos.x, click_pos.y);
-  if (dot)
-    { // FIXME: Dot NodeID missmatch...
-      NodeId id = path_graph->get_id(dot);
-      pingus->set_position(id);
+  if (maintainer_mode)
+    {
+      const Vector& click_pos = display_gc.screen_to_world(Vector(x, y));
+      Dot* dot = path_graph->get_dot(click_pos.x, click_pos.y);
+      if (dot)
+        { // FIXME: Dot NodeID missmatch...
+          NodeId id = path_graph->get_id(dot);
+          pingus->set_position(id);
+        }
     }
 }
 
@@ -328,6 +325,37 @@
       if (maintainer_mode)
         std::cout << "WorldMap: Pingus not on level" << std::endl;
     }
+}
+
+struct unlock_nodes
+{
+  PathGraph* path_graph;
+  unlock_nodes(PathGraph* g)
+  {
+    path_graph = g;
+  }
+  
+  void operator()(Node<Dot*>& node) 
+  {
+    if (node.data->finished())
+      {
+        //std::cout << "Unlocking neightbours of: " << node.data << std::endl;
+        for (std::vector<EdgeId>::iterator i = node.next.begin(); i != 
node.next.end(); ++i)
+          {
+            Edge<Path*>& edge = path_graph->graph.resolve_edge(*i);
+
+            // FIXME: This should be identical to node.data->unlock(), but not 
sure
+            path_graph->graph.resolve_node(edge.source).data->unlock();
+            path_graph->graph.resolve_node(edge.destination).data->unlock();
+          }
+      }
+  }
+};
+
+void
+WorldMap::update_locked_nodes()
+{
+  path_graph->graph.for_each_node(unlock_nodes(path_graph));
 }
 
 } // namespace WorldMapNS

Index: worldmap.hxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/worldmap/worldmap.hxx,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- worldmap.hxx        21 Mar 2003 22:08:06 -0000      1.23
+++ worldmap.hxx        30 Mar 2003 22:09:33 -0000      1.24
@@ -123,6 +123,9 @@
   /** Parse the propertie section of a WorldMap XML file, it contains
       meta data such as the author or the name of the Worldmap */
   void parse_properties(xmlDocPtr doc, xmlNodePtr cur);
+  
+  /** Unlock nodes according to the finished ones */
+  void update_locked_nodes();
 };
 
 } // namespace WorldMapNS





reply via email to

[Prev in Thread] Current Thread [Next in Thread]