r156 - in trunk: . src src/objects

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Sep 6 16:16:54 EDT 2005


Author: jonas
Date: 2005-09-06 16:16:53 -0400 (Tue, 06 Sep 2005)
New Revision: 156

Modified:
   trunk/TODO
   trunk/src/Makefile
   trunk/src/common.cpp
   trunk/src/common.h
   trunk/src/editor.cpp
   trunk/src/gfxeng.cpp
   trunk/src/gfxeng.h
   trunk/src/input.cpp
   trunk/src/lost_penguins.cpp
   trunk/src/menu.cpp
   trunk/src/objects/Makefile
   trunk/src/objects/exit.cpp
   trunk/src/physics.cpp
   trunk/src/players_common.cpp
   trunk/src/scenario.cpp
   trunk/src/scenario.h
Log:
o Updated TODO
o Added toggleShowDebug and KEY_DEBUG (F4)
o Added prelimenary Scenario support
o Introduced a bool finnished to indicate that the PhysicEngine
  should finnish the map => Fixes a bug in Exit
o Removed the -dl -rdynamic options in the Makefile
o startScreen() should always return you back to the main start screen
  with all settings reseted



Modified: trunk/TODO
===================================================================
--- trunk/TODO	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/TODO	2005-09-06 20:16:53 UTC (rev 156)
@@ -1,7 +1,6 @@
 Bugs
 ====
- o rewrite zombie (bug in movement!, attacks too often, use events, etc...)
- o memleaks, segfaults?
+ o zombie (bug in movement!, attacks too often, use events, etc...)
  o key vs. trigger in map2
  o fall event (DONE?)
  o players die event segfault (eg. olaf)
@@ -10,19 +9,17 @@
 Code
 ====
 
- o General:
+ o General / Interface:
      o (BIG) move drawing to the objects/menus/etc (create a draw() function)!
-     o pointers => references where possible
-     o Describe everything using Doxygen styles, move the documentation from
-      *.cpp to the headers...
-     o Idea: _all_ objects should have a "core" like the players (curpos thing)
-       This would help in many ways and should be a frame information and not an
-       image as done for players atm!
+     o pointers => shared_ptr/references where possible
+     o Complete the doxygen documentation and keep it up-to-date
      o Use Singletons
-     o IDEA: Introduce abstract classes for all engines and load the corresponding
-       concrete class depending on the game_mode instead of using if...
+     o Create a better class hierarchy so we don't have a class playground...
+     o Better handle the different game states and replace the current conditional model
+     o IDEA: Use boost to support better constructors (name loading)
+     o IDEA: create dynamical plugins for all objects (or compile all in)
 
- o Move/Fall/push/crash/collisions:
+ o Move/crash/collisions:
      o move should be a property of a common object
      o Hit should give either much more information or all logic should be done inside
        move (BAD)
@@ -33,35 +30,44 @@
      o movement into a movable object should just move the object
      o if the movement is "forced" the moved object should be hit hard when it collides
        otherwise a hit would stop the moving object as well...
-       -> I have no idea about how the push should look like, elevators can be pushed
-          up, even though you don't collide with them on top
-       -> characters should be "pushable", eg. a stone that falls down pushes the
-          character down or better: an elevator should push the characters up
+     o I have no idea about how the push should look like, elevators can be pushed
+       up, even though you don't collide with them on top
+     o IDEA: characters should be "pushable", eg. a stone that falls down pushes the
+             character down or better: an elevator should push the characters up
      o In case of the elevator, the players are somehow "bound" to the elevator (ie.
        it's not like: the elevator moves, the character falls, but they move together)
        Solution: The elevators move function checks all objects it would
          hit, if they are pushable (not dense) they are moved first if
          possible. If it's not possible, do sthg else (stop the elevator and hit the
          object/whatever)...
+     o IMPROVE?: cleanup set_difference stuff => targets should be updated if
+       an object dies in an intelligent way...
+     o IDEA: merge otype and ctype and make all moves/etc depend on it
+     o IDEA (old): Add attributes:
+        - crushable (ie. weapon fart, jump, run destroys them?)
+        - bombable (ie. bomb destroys them)
+        - multistates? => bridges, door, stone block
+     o REWRITE: the whole crash system!!!
 
  o Events/Animations:
+     o Replace the anim_orig by a base rectangle
      o Invent more intelligent and more robust! fallback methods for animations
      o Allow empty animation, decouple (put more logic in) these relations:
        object (pos, draw?), game(time, state, handler), gfxeng(draw), animation(empty,
        frame, update, time, draw)?, frame, global/current (public, private) properties
-     o Make all events quite short, ie. almost all events become animation
-       events
      o IDEA: couple left and right animations somehow to reduce the code size
         - eg. set offsets for left, right, mleft, mright...
      o IDEA: just store one side and add some flipping logic to the image
           loading process...
-     o IDEA: change Animation* pointers to Animation (or references or auto_ptr),
-       leave only animation as a pointer and get the address each time...
-     o introduce animation events that play an animation and end when it's
-       finnished (always ESTATE_BUSY or abort animation?)
      o allow an event length depending on animation length, or: relate events more
        with animations!!!
+     o REWRITE: the whole event system!!!
 
+ o Scenario:
+     o Add some nice animation, text box, etc when a level was completed (including printing
+       the map name).
+     o Simplify the scenario class and drastically reduce the public variables!!
+
  o Placement code:
      o IDEA: allow moves from NULL and/or to NULL
      o units should be placed in a way they won't give conflicts, examples:
@@ -70,37 +76,26 @@
           illegaly placed!
         - the placement should somehow involve checkPlace...
 
- o (Plugins):
-     o move object creation code (addObjectByName) to the objects
-     o create dynamical plugins for all objects (or compile all in)
 
- o Ideas/Improvements:
-     o IMPROVE?: cleanup set_difference stuff => targets should be updated if
-       an object dies in an intelligent way...
-     o IDEA: merge otype and ctype and make all moves/etc depend on it
-     o IDEA (old): Add attributes:
-        - crushable (ie. weapon fart, jump, run destroys them?)
-        - bombable (ie. bomb destroys them)
-        - multistates? => bridges, door, stone block
-
-
 Progress
 ========
 
  o Monsters / AI: VERY BAD
  o Game functionality (): BAD
- o Events / Effects: BAD, MESS
+ o Events / Effects: BAD, MESS, NESTED
  o Object (including parameter) loading: BAD
- o Move logic: ACCEPTABLE, BUGGED
+ o Move logic: ACCEPTABLE, BUGGED, NESTED
  o Objects (players, items, etc): ACCEPTABLE
+ o Physic Handler: ACCEPTABLE, NESTED
  o Input Handler: ACCEPTABLE, WORKS
+ o Scenario: OK, MESS, WORKS
  o Collision detection: OK
  o Fall logic: GOOD
  o Animation / Image structure: VERY GOOD
 
 
-Features/Ideas/Wishlist
-=======================
+Feature Wishlist (Ideas)
+========================
 
  o Make water movements possible (eric)
  o improve the map editor even further

Modified: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/Makefile	2005-09-06 20:16:53 UTC (rev 156)
@@ -4,7 +4,7 @@
 CXX_OPT = #-O2 -march=pentium4 -ffast-math
 CXX_GAME = -DSDL_MIXER -DSDL_IMAGE -DALPHA -I ./
 SDL = `sdl-config --cflags`
-SDL_LINK = `sdl-config --libs` -lSDL_mixer -lSDL_image -ldl -rdynamic
+SDL_LINK = `sdl-config --libs` -lSDL_mixer -lSDL_image #-ldl -rdynamic
 
 OBJS  = common.o gfxeng.o input.o font.o lost_penguins.o scenario.o\
         objects_common.o sfxeng.o players_common.o monsters_common.o\

Modified: trunk/src/common.cpp
===================================================================
--- trunk/src/common.cpp	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/common.cpp	2005-09-06 20:16:53 UTC (rev 156)
@@ -1,5 +1,6 @@
 #include "common.h"
 #include "gfxeng.h"
+#include "editor.h"
 
 ImageCache* imgcache;
 SoundCache* sndcache;
@@ -51,6 +52,7 @@
         gfxeng->unsetShowDebug();
         SDL_ShowCursor(SDL_DISABLE);
     }
+    if (!editor) editor=new Editor();
 #ifdef DEBUG
     gfxeng->setShowDebug();
 #endif

Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/common.h	2005-09-06 20:16:53 UTC (rev 156)
@@ -118,7 +118,8 @@
     KEY_BAR,
     KEY_FULL,
     KEY_QUIT,
-    KEY_NOANIM
+    KEY_NOANIM,
+    KEY_DEBUG
 };
 
 enum BasePointType {
@@ -165,9 +166,11 @@
     int audio_channels;
     string datadir;
     string map;
+    string scenario;
     string anim_file;
     SDLKey keybind[30];
     double lvlscale;
+    bool onlymap;
 };
 
 /**\brief Frame format
@@ -191,6 +194,8 @@
 
 //global functions
 //@{
+/// Resets everything and shows the start screen again
+void startScreen();
 /// Quits the game with a error code
 /// \return Error code, 0 if successfull
 int quitGame(int);

Modified: trunk/src/editor.cpp
===================================================================
--- trunk/src/editor.cpp	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/editor.cpp	2005-09-06 20:16:53 UTC (rev 156)
@@ -406,12 +406,12 @@
 
 OpenMapBox::OpenMapBox(Sint16 x, Sint16 y): TextInputBox(x,y) {
     title="Open Map";
-    einput.push_back(scenario->name);
-    currententry=0;
+    einput.push_back(scenario->mapname);
     update();
 }
 
 void OpenMapBox::evaluateEntry() {
+    scenario->resetScenario();
     scenario->loadMap(einput[0]);
     editor->closeBox();
 }
@@ -426,7 +426,8 @@
 }
 
 void NewMapBox::evaluateEntry() {
-    scenario->name=einput[0];
+    scenario->resetScenario();
+    scenario->mapname=einput[0];
     scenario->newMap(einput[1]);
     scenario->reloadMap();
     editor->closeBox();

Modified: trunk/src/gfxeng.cpp
===================================================================
--- trunk/src/gfxeng.cpp	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/gfxeng.cpp	2005-09-06 20:16:53 UTC (rev 156)
@@ -278,12 +278,12 @@
     }
 }
 
-void GraphicsEngine::setShowDebug() {
-    show_debug=true;
+void GraphicsEngine::setShowDebug() { show_debug=true; }
+void GraphicsEngine::unsetShowDebug() { show_debug=false; }
+void GraphicsEngine::toggleShowDebug() {
+    if (show_debug) show_debug=false;
+    else show_debug=true;
 }
-void GraphicsEngine::unsetShowDebug() {
-    show_debug=false;
-}
 
 void GraphicsEngine::toggleFullScreen() {
     //on  -> off

Modified: trunk/src/gfxeng.h
===================================================================
--- trunk/src/gfxeng.h	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/gfxeng.h	2005-09-06 20:16:53 UTC (rev 156)
@@ -31,6 +31,7 @@
         void toggleFullScreen();
         void setShowDebug();
         void unsetShowDebug();
+        void toggleShowDebug();
         void setMenuBG(SDL_Surface* menu_background=NULL);
         const SDL_Rect& addShift(Sint16,Sint16);
         const SDL_Rect& setShift(Sint16,Sint16);

Modified: trunk/src/input.cpp
===================================================================
--- trunk/src/input.cpp	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/input.cpp	2005-09-06 20:16:53 UTC (rev 156)
@@ -164,6 +164,8 @@
                      gfxeng->toggleFPS(); 
                 } else if (key==config.keybind[KEY_FULL]) {
                      gfxeng->toggleFullScreen();
+                } else if (key==config.keybind[KEY_DEBUG]) {
+                     gfxeng->toggleShowDebug();
                 } else if (key==config.keybind[KEY_QUIT]) {
                      quitGame(0);
                 }

Modified: trunk/src/lost_penguins.cpp
===================================================================
--- trunk/src/lost_penguins.cpp	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/lost_penguins.cpp	2005-09-06 20:16:53 UTC (rev 156)
@@ -51,8 +51,7 @@
     cout << "Initializing Scenario...\n";
     scenario=new Scenario();
 
-    gfxeng->setMenuBG();
-    setMenu(new StartMenu());
+    startScreen();
 
     while (true) {
         input->update();
@@ -64,6 +63,13 @@
     quitGame(-2);
 }
 
+void startScreen() {
+    scenario->resetScenario();
+    gfxeng->setMenuBG();
+    setMenu(new StartMenu());
+    setGameMode(GAME_MENU);
+}
+
 int quitGame(int errorcode=0) {
     cout << endl << "Quitting game (exit code: " << errorcode << ")...\n";
     closeMenus();
@@ -100,8 +106,10 @@
     config.audio_channels = 2;
     config.datadir="data/";
     config.anim_file="animation_data.anim";
-    config.map="map1.cfg";
+    config.map="";
+    config.scenario="lv1.sce";
     config.lvlscale=2;
+    config.onlymap=false;
 
     //key bindings
     config.keybind[KEY_LEFT]    = SDLK_LEFT;
@@ -116,6 +124,7 @@
     config.keybind[KEY_SWITCH]  = SDLK_LCTRL;
     config.keybind[KEY_PAUSE]   = SDLK_TAB;
     config.keybind[KEY_MENU]    = SDLK_ESCAPE;
+    config.keybind[KEY_DEBUG]   = SDLK_F4;
     config.keybind[KEY_NOANIM]  = SDLK_F3;
     config.keybind[KEY_FPS]     = SDLK_F2;
     config.keybind[KEY_BAR]     = SDLK_F1;
@@ -148,6 +157,9 @@
             else config.full=false;
         } else if (option=="map") {
             config.map=arg1;
+            config.onlymap=true;
+        } else if (option=="scenario") {
+            config.scenario=arg1;
         //TODO: add keybindings
         } else {
             cout << "Unknown option: " << option << endl;
@@ -170,7 +182,12 @@
         } else if ( strcmp(argv[i], "-map") == 0 ) {
             config.map=argv[i+1];
             config.map+=".cfg";
+            config.onlymap=true;
             i++;
+        } else if ( strcmp(argv[i], "-scenario") == 0 ) {
+            config.scenario=argv[i+1];
+            config.scenario+=".sce";
+            i++;
         } else if ( strcmp(argv[i], "-datadir") == 0 ) {
             config.datadir=argv[i+1];
             if (config.datadir.substr(config.datadir.size() - 1, 1)!="/") config.datadir+="/";
@@ -191,7 +208,8 @@
     cout << "  -w, -width   Changes resolution (width) of game.    Default: 640\n";
     cout << "  -h, -height  Changes resolution (height) of game.   Default: 480\n";
     cout << "  -fs, -full   Enable fullscreen.                     Default: disabled\n";
-    cout << "  -map         Load specified map from data dir.      Default: map1\n";
+    cout << "  -map         Load specified map from data dir.      Default: disabled (map1 as a fallback)\n";
+    cout << "  -scenario    Load specified Scenario from data dir. Default: lv1\n";
     cout << "  -h, --help   Show this text \n";
     quitGame(4);
 }

Modified: trunk/src/menu.cpp
===================================================================
--- trunk/src/menu.cpp	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/menu.cpp	2005-09-06 20:16:53 UTC (rev 156)
@@ -64,24 +64,35 @@
 void StartMenu::act() {
     switch (currententry) {
     case 0: {
-        if ((config.map!="") && (scenario->loadMap(config.map)==0)) {
+        if (config.onlymap && (config.map!="") && (scenario->loadMap(config.map)==0)) {
             closeMenu();
             addGameMode(GAME_PLAY);
-            cout << "Starting game...\n" << endl;
+            cout << "Starting Scenario (1 map)...\n" << endl;
+        } else if (config.onlymap) {
+            cout << "Selected Map is invalid...\n" << endl;
+        } else if (scenario->loadScenario(config.scenario)==0 && scenario->startScenario()==0) {
+            closeMenu();
+            addGameMode(GAME_PLAY);
+            cout << "Starting Scenario...\n" << endl;
         } else {
-            cout << "Select a valid map first...\n" << endl;
+            cout << "Selected Scenario is invalid...\n" << endl;
         }
         break;
     }
     case 1: {
         //Add a proper Map creation menu, etc..., FIXME
-        if ((config.map!="") && (scenario->loadMap(config.map)==0)) {
+        if (config.onlymap && (config.map!="") && (scenario->loadMap(config.map)==0)) {
             closeMenu();
-            cout << "Starting editor...\n" << endl;
+            cout << "Starting Map Editor...\n" << endl;
             addGameMode(GAME_EDIT);
-            if (!editor) editor=new Editor();
+        } else if (config.onlymap) {
+            cout << "Selected Map is invalid...\n" << endl;
+        } else if (scenario->loadScenario(config.scenario)==0 && scenario->startScenario()==0) {
+            closeMenu();
+            addGameMode(GAME_EDIT);
+            cout << "Starting Map Editor...\n" << endl;
         } else {
-            cout << "Select a valid map first...\n" << endl;
+            cout << "Selected Scenario is invalid...\n" << endl;
         }
         break;
     }

Modified: trunk/src/objects/Makefile
===================================================================
--- trunk/src/objects/Makefile	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/objects/Makefile	2005-09-06 20:16:53 UTC (rev 156)
@@ -4,7 +4,7 @@
 CXX_OPT = #-O2 -march=pentium4 -ffast-math
 CXX_GAME = -DSDL_MIXER -DSDL_IMAGE -DALPHA -I ../
 SDL = `sdl-config --cflags`
-SDL_LINK = `sdl-config --libs` -lSDL_mixer -lSDL_image -ldl -rdynamic
+SDL_LINK = `sdl-config --libs` -lSDL_mixer -lSDL_image #-ldl -rdynamic
 AR = ar
 
 OBJS  = baleog.o bomb.o door.o erik.o exit.o fang.o geyser.o heart.o\

Modified: trunk/src/objects/exit.cpp
===================================================================
--- trunk/src/objects/exit.cpp	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/objects/exit.cpp	2005-09-06 20:16:53 UTC (rev 156)
@@ -16,8 +16,6 @@
         if (!((*it)->isIn(pos))) return false;
         ++it;
     }
-    if (scenario->failed) cout << "Again?\n"; 
-    else cout << "You won!!!!\n";
-    quitGame(0);
+    scenario->finnished=true;
     return true;
 }

Modified: trunk/src/physics.cpp
===================================================================
--- trunk/src/physics.cpp	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/physics.cpp	2005-09-06 20:16:53 UTC (rev 156)
@@ -53,6 +53,12 @@
 }
 
 inline void PhysicHandler::updateGame() {
+    if (scenario->finnished) {
+        cout << endl;
+        if (scenario->failed) cout << "Mission failed: Replay?" << endl;
+        scenario->loadNextMap();
+        return;
+    }
     object_iterator obit=scenario->pool->objectspool.begin();
     while (obit!=scenario->pool->objectspool.end()) {
         //remove marked objects

Modified: trunk/src/players_common.cpp
===================================================================
--- trunk/src/players_common.cpp	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/players_common.cpp	2005-09-06 20:16:53 UTC (rev 156)
@@ -210,10 +210,11 @@
 }
 
 void Player::in_act() {
+    Mix_Chunk* au_act_bak=au_act;
     object_iterator i=enter.begin();
     while (i!=enter.end()) {
         if ((*i)->act(this)) {
-            sfxeng->playWAV(au_act);
+            sfxeng->playWAV(au_act_bak);
             return;
         }
         ++i;
@@ -283,6 +284,7 @@
 }
 
 void Player::die() {
+    /* todo add box and ask for a continue / redo */
     scenario->failed=true;
     Character::die();
 }

Modified: trunk/src/scenario.cpp
===================================================================
--- trunk/src/scenario.cpp	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/scenario.cpp	2005-09-06 20:16:53 UTC (rev 156)
@@ -13,8 +13,11 @@
   area(NULL),
   player(NULL),
   failed(false),
-  name(""),
-  bgimage("") {
+  finnished(false),
+  mapname(""),
+  scenarioname(""),
+  bgimage(""),
+  currentmap(0) {
     cout << "Scenario: ImageCache...\n";
     imgcache=new ImageCache();
     cout << "Scenario: SoundCache...\n";
@@ -48,28 +51,31 @@
     if (background) delete background;
     if (physic) delete physic;
     physic=new PhysicHandler();
+    sfxeng->stopMusic();
     background=NULL;
     area=NULL;
     player=NULL;
     max_obj_num=0;
+    finnished=false;
+    failed=false;
 }
 
 void Scenario::newMap(string bgimage) {
     mapbuf.clear();
     mapbuf.push_back("Background "+bgimage);
 }
-int Scenario::loadMapBuf(string mapname) {
-    name=mapname;
+int Scenario::loadMapBuf(string mapn) {
+    mapname=mapn;
     ifstream mapfile;
     string tmpline;
-    string loadfile=config.datadir+name;
+    string loadfile=config.datadir+mapname;
 
     mapfile.open(loadfile.c_str());
     if (mapfile) {
         cout << "Loading new map: " << loadfile << endl;
     } else {
         cout << "Map loading failed: " << loadfile << " not found!\n";
-        return -2;
+        return 2;
     }
 
     mapbuf.clear();
@@ -144,16 +150,113 @@
         if (player==NULL) cout << "No player found!\n";
         return 0;
     } else {
-       cout << "Map loading failed: No background found!\n";
-       return -1;
+        cout << "Map loading failed: No background found!\n";
+        return 1;
     }
 }
 
-int Scenario::loadMap(string mapname) {
-    if (!loadMapBuf(mapname) && !reloadMap()) return 0;
-    else return -1;
+int Scenario::loadMap(string mapn) {
+    if (loadMapBuf(mapn)==0 && reloadMap()==0) return 0;
+    else return 1;
 }
 
+int Scenario::loadMap(Uint8 level) {
+    if (level<maps.size()) return loadMap(maps[level]+".cfg");
+    else return 3;
+}
+
+void Scenario::loadNextMap() {
+    if (failed) {
+        cout << "Reloading current map" << endl;
+        if (reloadMap()!=0) {
+            cout << "Reloading failed!" << endl;
+        }
+    } else if ((++currentmap)<maps.size()) {
+        cout << "Loading next map" << endl;
+        if (loadMap(maps[currentmap]+".cfg")!=0) {
+            cout << "Map loading failed!" << endl;
+        }
+    } else {
+        winScenario();
+    }
+}
+
+int Scenario::startScenario() {
+    currentmap=0;
+    return loadMap();
+}
+
+void Scenario::winScenario() {
+    cout << "You won the scenario!" << endl;
+    startScreen();
+}
+
+void Scenario::resetScenario() {
+    reinitMap();
+    currentmap=0;
+    maps.clear();
+    playlist.clear();
+}
+
+int Scenario::loadScenario(string scenarion) {
+    reinitMap();
+    maps.clear();
+    currentmap=0;
+
+    scenarioname=scenarion;
+    ifstream scenariofile;
+    string tmpline;
+    string loadfile=config.datadir+scenarioname;
+
+    scenariofile.open(loadfile.c_str());
+    if (scenariofile) {
+        cout << "Loading new scenario file: " << loadfile << endl;
+    } else {
+        cout << "Scenario file loading failed: " << loadfile << " not found!\n";
+        return 2;
+    }
+
+    string mname, arg1, arg2;
+    bool header=false;
+
+    //check every line
+    while (getline(scenariofile,tmpline)) {
+        //parse the header, always start a header with #HEADER and end it with #ENDHEADER!
+        if (header) {
+            mname.erase();
+            arg1.erase();
+            arg2.erase();
+            std::istringstream tmpstream(tmpline);
+            tmpstream >> mname >> arg1 >> arg2;
+            if (mname[0]=='#') {
+                if (mname=="#ENDHEADER") header=false;
+                continue;
+            }
+            continue;
+        }
+        mname.erase();
+        arg1=arg2="";
+        std::istringstream tmpstream(tmpline);
+        tmpstream >> mname >> arg1 >> arg2;
+
+        //Skip empty lines
+        if (mname.empty()) continue;
+        //Skip comments
+        if (mname[0]=='#') {
+            if (mname=="#HEADER") header=true;
+            continue;
+        }
+
+        maps.push_back(mname);
+    }
+
+    scenariofile.close();
+    scenariofile.clear();
+
+    if (maps.size()>0) return 0;
+    else return 1;
+}
+
 Uint16 Scenario::getDirection(const SDL_Rect& src, const SDL_Rect& dest) const {
     Uint16 dir=NOTHING;
     if ((src.x+src.w) < (dest.x+dest.w)) dir|=DIR_RIGHT;

Modified: trunk/src/scenario.h
===================================================================
--- trunk/src/scenario.h	2005-09-06 14:46:56 UTC (rev 155)
+++ trunk/src/scenario.h	2005-09-06 20:16:53 UTC (rev 156)
@@ -46,6 +46,8 @@
         /// \param src Source rectangle
         /// \param dest Destination rectangle
         Uint16 getDirection(const SDL_Rect& src, const SDL_Rect& dest) const;
+        /// Load a new scenario
+        int loadScenario(string scenarioname);
 
         /// Background
         Background* background;
@@ -73,15 +75,27 @@
         /// \param mapname Map file name without the data directory in it
         /// \return 0 if a Background was found, -1 if not, -2 if the loading failed
         int loadMap(string mapname);
+        int loadMap(Uint8 level=0);
+        void loadNextMap();
+        int startScenario();
+        void winScenario();
+        void resetScenario();
         /// True if the mission failed
         bool failed;
-        /// Name of the map file
-        string name;
+        /// True if the mission is finnished (suceeded or failed)
+        bool finnished;
+        /// Name of the current map file
+        string mapname;
+        /// Name of the scenario
+        string scenarioname;
         /// Name of the map background image
         string bgimage;
         std::vector<string> mapbuf;
         /// The number of created objects
         Uint32 max_obj_num;
+        std::vector<string> maps;
+        std::vector<string> playlist;
+        Uint8 currentmap;
     private:
         inline void reinitMap();
 };




More information about the lostpenguins-commits mailing list