r165 - trunk/src

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Fri Sep 9 11:49:26 EDT 2005


Author: jonas
Date: 2005-09-09 11:49:26 -0400 (Fri, 09 Sep 2005)
New Revision: 165

Modified:
   trunk/src/common.h
   trunk/src/editor.cpp
   trunk/src/editor.h
   trunk/src/objectpools.cpp
   trunk/src/scenario.cpp
   trunk/src/scenario.h
Log:
o Added a Object* getObjectAt(Sint16 x, Sint16 y, Uint16 mask=ALL) function
  that returns the first (top most) object at the specified position;
o Added a remove object action to the editor
o Changed the file reading (to buffer) function to check for the parameter
  name and add it if it isn't found: This is used to find a map buffer entry
  corresponding to an object in play over obj->getName()...


Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2005-09-08 22:04:26 UTC (rev 164)
+++ trunk/src/common.h	2005-09-09 15:49:26 UTC (rev 165)
@@ -49,6 +49,8 @@
 typedef std::set<Character *>::iterator character_iterator;
 typedef std::set<Player *>::iterator player_iterator;
 typedef std::set<Monster *>::iterator monster_iterator;
+typedef std::set<Object *>::reverse_iterator object_riterator;
+typedef std::set<Character *>::reverse_iterator character_riterator;
 typedef boost::shared_ptr<EmptyAnimation> EmptyAnimationPtr;
 typedef std::map<string,string> ParameterMap;
 

Modified: trunk/src/editor.cpp
===================================================================
--- trunk/src/editor.cpp	2005-09-08 22:04:26 UTC (rev 164)
+++ trunk/src/editor.cpp	2005-09-09 15:49:26 UTC (rev 165)
@@ -4,6 +4,7 @@
 #include "menu.h"
 #include "font.h"
 #include "gfxeng.h"
+#include "objects_common.h"
 #include "editor.h"
 
 
@@ -36,6 +37,13 @@
         setBox(new EditBox(x,y));
     } else if (action&EDIT_ACT_BOX) {
         if (box) box->act(box->getCurrentEntry(x,y));
+    } else if (action&EDIT_REMOVE_OBJECT) {
+        Object* obj=scenario->getObjectAt(xs,ys);
+        if (obj) {
+            if (removefromBuf(obj->getName()).empty()) {
+                cout << "Unable to remove object " << obj->getName() << ": Name identifier not found!" << endl;
+            } else scenario->reloadMap();
+        }
     } else if (action&EDIT_PLACE_OBJECT) {
         scenario->reloadMap();
         if (scenario->pool->addObjectbyName(place_name,xs,ys,place_parameters)) {
@@ -228,6 +236,7 @@
     } else if (entries[curentry]=="Place Object") {
         editor->setBox(new PlaceBox(area.x,area.y));
     } else if (entries[curentry]=="Remove Object") {
+        editor->action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_REMOVE_OBJECT;
         editor->closeBox();
     } else if (entries[curentry]=="Move Object") {
         editor->closeBox();

Modified: trunk/src/editor.h
===================================================================
--- trunk/src/editor.h	2005-09-08 22:04:26 UTC (rev 164)
+++ trunk/src/editor.h	2005-09-09 15:49:26 UTC (rev 165)
@@ -5,6 +5,7 @@
 #define EDIT_BOX            0x00000004
 #define EDIT_ACT_BOX        0x00000008
 #define EDIT_PLACE_OBJECT   0x00000010
+#define EDIT_REMOVE_OBJECT  0x00000020
 
 /** \brief abstract Box base class
 

Modified: trunk/src/objectpools.cpp
===================================================================
--- trunk/src/objectpools.cpp	2005-09-08 22:04:26 UTC (rev 164)
+++ trunk/src/objectpools.cpp	2005-09-09 15:49:26 UTC (rev 165)
@@ -166,6 +166,7 @@
     Player::default_parameters["audio_heal"]="usefood1.wav";
 
     Erik::default_parameters=Player::default_parameters;
+    Erik::default_parameters["file"]="erik.inf";
     Erik::default_parameters["audio_jump"]="rboots.wav";
     Erik::default_parameters["audio_run"]="";
     Olaf::default_parameters=Player::default_parameters;

Modified: trunk/src/scenario.cpp
===================================================================
--- trunk/src/scenario.cpp	2005-09-08 22:04:26 UTC (rev 164)
+++ trunk/src/scenario.cpp	2005-09-09 15:49:26 UTC (rev 165)
@@ -30,7 +30,7 @@
 }
 
 Scenario::~Scenario() {
-    cout << endl << "Closing map...\n";
+    cout << "Closing map...\n";
     delete pool;
     cout << "Map: Deleted Pools...\n";
     if (background) delete background;
@@ -80,8 +80,45 @@
     }
 
     mapbuf.clear();
+
+    /* We parse the parameters to add a name if it was missing
+       This whole file reading looks much more complicated because
+       of this (otherwise there would only be mapbuf.push_back(tmpline) */
+    string cname;
+    Uint16 x,y;
+    ParameterMap parameters;
+    bool header=true;
+    std::map<string,Uint16> namecount;
     while (getline(mapfile,tmpline)) {
-        mapbuf.push_back(tmpline);
+        if (header) {
+            mapbuf.push_back(tmpline);
+            std::istringstream tmpstream(tmpline);
+            tmpstream >> cname;
+            if (cname[0]=='#') {
+                if (cname=="#ENDHEADER") header=false;
+                continue;
+            }
+        } else {
+            cname.erase();
+            x=y=0;
+            std::istringstream tmpstream(tmpline);
+            tmpstream >> cname >> x >> y;
+
+            if (cname.empty() || cname[0]=='#') {
+                mapbuf.push_back(tmpline);
+                continue;
+            } else {
+                namecount[cname]++;
+            }
+
+            string parameterlist((istreambuf_iterator<char>(tmpstream)), istreambuf_iterator<char>());
+            parameters=getParameters(parameterlist);
+            if (!hasParam(parameters,"name")) {
+                if (parameters.empty()) tmpline+=" name="+cname+itos(namecount[cname]);
+                else tmpline+=", name="+cname+itos(namecount[cname]);
+            }
+            mapbuf.push_back(tmpline);
+        }
     }
 
     mapfile.close();
@@ -295,3 +332,16 @@
     }
     return tmpset;
 }
+
+Object* Scenario::getObjectAt(Sint16 x, Sint16 y, Uint16 mask) const {
+    SDL_Rect tmprect;
+    tmprect.x=x;
+    tmprect.y=y;
+    tmprect.w=tmprect.h=1;
+    object_riterator obit=pool->objectspool.rbegin();
+    while (obit != pool->objectspool.rend()) {
+        if ((((*obit)->getType())&mask) && ((*obit)->isIn(tmprect,true))) return (*obit);
+        ++obit;
+    }
+    return NULL;
+}

Modified: trunk/src/scenario.h
===================================================================
--- trunk/src/scenario.h	2005-09-08 22:04:26 UTC (rev 164)
+++ trunk/src/scenario.h	2005-09-09 15:49:26 UTC (rev 165)
@@ -46,6 +46,8 @@
         /// \return A set of characters that are inside the enlarged source rectangle
         ///   and that match the specified mask.
         std::set<Character *> getCharactersIn(Uint16 mask, const SDL_Rect& rect, bool touch=false, Uint16 radius=0, Uint16 dir=DIR_ALL) const;
+        /// Returns the first found object at the given position
+        Object* getObjectAt(Sint16 x, Sint16 y, Uint16 mask=ALL) const;
         /// Returns the directions from the source rectangle to the destination rectangle
         /// \remark This may include an enlargment (eg. Olaf)
         /// \param src Source rectangle




More information about the lostpenguins-commits mailing list