r86 - in trunk/src: . objects
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Wed Feb 9 17:08:47 EST 2005
Author: jonas
Date: 2005-02-09 17:08:47 -0500 (Wed, 09 Feb 2005)
New Revision: 86
Added:
trunk/src/scenario.cpp
trunk/src/scenario.h
Removed:
trunk/src/map.cpp
trunk/src/map.h
Modified:
trunk/src/Makefile
trunk/src/anim.cpp
trunk/src/characters_common.cpp
trunk/src/events.cpp
trunk/src/gfxeng.cpp
trunk/src/input.cpp
trunk/src/lost_penguins.cpp
trunk/src/monsters_common.cpp
trunk/src/objectpools.cpp
trunk/src/objects/baleog.cpp
trunk/src/objects/bomb.cpp
trunk/src/objects/door.cpp
trunk/src/objects/erik.cpp
trunk/src/objects/exit.cpp
trunk/src/objects/fang.cpp
trunk/src/objects/geyser.cpp
trunk/src/objects/olaf.cpp
trunk/src/objects/plant.cpp
trunk/src/objects/scorch.cpp
trunk/src/objects/spike.cpp
trunk/src/objects/teleport.cpp
trunk/src/objects/trigger.cpp
trunk/src/objects/triggered_bomb.cpp
trunk/src/objects/water.cpp
trunk/src/objects/zombie.cpp
trunk/src/objects_common.cpp
trunk/src/players_common.cpp
Log:
renamed map.* to scenario.*
Modified: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/Makefile 2005-02-09 22:08:47 UTC (rev 86)
@@ -6,7 +6,7 @@
SDL = `sdl-config --cflags`
SDL_LINK = `sdl-config --libs` -lSDL_mixer -lSDL_image -ldl -rdynamic
-OBJS = common.o anim.o gfxeng.o input.o font.o lost_penguins.o map.o\
+OBJS = common.o anim.o gfxeng.o input.o font.o lost_penguins.o scenario.o\
objects_common.o sfxeng.o players_common.o monsters_common.o\
characters_common.o objectpools.o weapons.o events.o imgcache.o\
sndcache.o
Modified: trunk/src/anim.cpp
===================================================================
--- trunk/src/anim.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/anim.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -3,7 +3,7 @@
#include "gfxeng.h"
#include "objectpools.h"
#include "players_common.h"
-#include "map.h"
+#include "scenario.h"
#include "anim.h"
Modified: trunk/src/characters_common.cpp
===================================================================
--- trunk/src/characters_common.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/characters_common.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -1,7 +1,7 @@
#include "common.h"
#include "anim.h"
#include "events.h"
-#include "map.h"
+#include "scenario.h"
#include "weapons.h"
#include "objectpools.h"
#include "characters_common.h"
Modified: trunk/src/events.cpp
===================================================================
--- trunk/src/events.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/events.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -2,7 +2,7 @@
#include "events.h"
#include "anim.h"
#include "weapons.h"
-#include "map.h"
+#include "scenario.h"
#include "sfxeng.h"
#include "characters_common.h"
Modified: trunk/src/gfxeng.cpp
===================================================================
--- trunk/src/gfxeng.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/gfxeng.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -4,7 +4,7 @@
#include "objectpools.h"
#include "players_common.h"
#include "imgcache.h"
-#include "map.h"
+#include "scenario.h"
#include "gfxeng.h"
Modified: trunk/src/input.cpp
===================================================================
--- trunk/src/input.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/input.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -5,7 +5,7 @@
#include "sndcache.h"
#include "gfxeng.h"
#include "sfxeng.h"
-#include "map.h"
+#include "scenario.h"
#include "objectpools.h"
#include "objects_common.h"
Modified: trunk/src/lost_penguins.cpp
===================================================================
--- trunk/src/lost_penguins.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/lost_penguins.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -3,7 +3,7 @@
#include "anim.h"
#include "input.h"
#include "font.h"
-#include "map.h"
+#include "scenario.h"
#include "imgcache.h"
#include "sndcache.h"
#include "gfxeng.h"
Deleted: trunk/src/map.cpp
===================================================================
--- trunk/src/map.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/map.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -1,183 +0,0 @@
-#include "common.h"
-#include "objectpools.h"
-#include "players_common.h"
-#include "imgcache.h"
-#include "sndcache.h"
-#include "anim.h"
-#include "map.h"
-
-
-Scenario::Scenario():
- background(NULL),
- area(NULL),
- player(NULL),
- failed(false),
- name("") {
- cout << "Scenario: ImageCache...\n";
- imgcache=new ImageCache();
- cout << "Scenario: SoundCache...\n";
- sndcache=new SoundCache();
- cout << "Scenario: AnimHandler...\n";
- anim=new AnimHandler();
- cout << "Map: ObjectsPool...\n";
- pool=new ObjectsPool();
-}
-
-Scenario::~Scenario() {
- cout << endl << "Closing map...\n";
- delete pool;
- cout << "Map: Deleted Pools...\n";
- if (background) delete background;
- cout << "Map: Deleted Background...\n";
- delete anim;
- cout << "Scenario: Deleted Animhandler...\n";
- delete sndcache;
- cout << "Scenario: Deleted SoundCache...\n";
- delete imgcache;
- cout << "Scenario: Deleted ImageCache... (Scenario closed)\n";
-}
-
-inline void Scenario::reinitMap() {
- if (pool && !(pool->empty())) {
- delete pool;
- pool=new ObjectsPool();
- } else if (!pool) pool=new ObjectsPool();
- if (background) delete background;
- background=NULL;
- area=NULL;
- player=NULL;
- name="";
-}
-
-int Scenario::loadMap(string mapname) {
- reinitMap();
- cout << "Loading Map data...\n";
- name=mapname;
- ifstream mapfile;
- string tmpline;
- string image;
- string arg1,arg2,arg3;
- Uint16 x,y;
- background=NULL;
- area=NULL;
- string loadfile=config.datadir+name;
- bool header=false;
-
- mapfile.open(loadfile.c_str());
- if (mapfile) {
- cout << "Loading map configuration file...\n";
- } else {
- cout << "Map loading failed: " << (config.datadir+name) << " not found!\n";
- return -2;
- }
-
- //check every line
- while (getline(mapfile,tmpline)) {
- //parse the header, always start a header with #HEADER and end it with #ENDHEADER!
- if (header) {
- name.erase();
- arg1.erase();
- arg2.erase();
- arg3.erase();
- std::istringstream tmpstream(tmpline);
- tmpstream >> name >> arg1 >> arg2 >> arg3;
- if (name[0]=='#') {
- if (name=="#ENDHEADER") header=false;
- continue;
- }
- continue;
- }
- name.erase();
- image.erase();
- x=0;
- y=0;
- arg1=arg2="0";
- arg3="";
- std::istringstream tmpstream(tmpline);
- tmpstream >> name >> image >> x >> y >> arg1 >> arg2 >> arg3;
-
- //Skip empty lines
- if (name.empty()) continue;
- //Skip comments
- if (name[0]=='#') {
- if (name=="#HEADER") header=true;
- continue;
- }
-
- if (name=="Background" && (!background)) {
- background=new Background(image);
- if (background) area=background->getPos();
- //Background has to be first!
- } else if (background) {
- pool->addObjectbyName(name,image,x,y,arg1,arg2,arg3);
- } else {
- cout << "No background found yet, skipping " << name << " ...\n";
- }
- }
-
- mapfile.close();
- mapfile.clear();
-
- //Has a background been found?
- if (background) {
- if (pool->playerspool.size()>0) player=*pool->playerspool.begin();
- else player=NULL;
- if (player==NULL) cout << "No player found!\n";
- return 0;
- } else {
- cout << "Map loading failed: No background found!\n";
- 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;
- if (src.x > dest.x) dir|=DIR_LEFT;
- if ((src.y+src.h) < (dest.y+dest.h)) dir|=DIR_DOWN;
- if (src.y > dest.y) dir|=DIR_UP;
- return dir;
-}
-
-Hit Scenario::checkPlace(const SDL_Rect& src, const SDL_Rect& dest) const {
- Hit hit;
- hit.enter=NOTHING;
- hit.touch=NOTHING;
- if (src.x < dest.x) hit.enter|=DIR_LEFT;
- if (src.x==dest.x) hit.touch|=DIR_LEFT;
- if (src.y < dest.y) hit.enter|=DIR_UP;
- if (src.y==dest.y) hit.touch|=DIR_UP;
- if ((src.x+src.w) > (dest.x+dest.w)) hit.enter|=DIR_RIGHT;
- if ((src.x+src.w)==(dest.x+dest.w)) hit.touch|=DIR_RIGHT;
- if ((src.y+src.h) > (dest.y+dest.h)) hit.enter|=DIR_DOWN;
- if ((src.y+src.h)==(dest.y+dest.h)) hit.touch|=DIR_DOWN;
- return hit;
-}
-
-
-std::set<Character *> Scenario::getCharactersIn(Uint16 mask, const SDL_Rect& rect, bool touch, Uint16 distance, Uint16 dir) const {
- SDL_Rect tmprect=rect;
- if (dir&DIR_LEFT) {
- tmprect.x-=distance;
- tmprect.w+=distance;
- }
- if (dir&DIR_RIGHT) {
- tmprect.x+=distance;
- tmprect.w+=distance;
- }
- if (dir&DIR_UP) {
- tmprect.y-=distance;
- tmprect.h+=distance;
- }
- if (dir&DIR_DOWN) {
- tmprect.y+=distance;
- tmprect.h+=distance;
- }
- std::set<Character *> tmpset;
- character_iterator cit=pool->characterspool.begin();
- while (cit != pool->characterspool.end()) {
- if ((((*cit)->getType())&mask) && ((*cit)->isIn(tmprect,touch))) tmpset.insert(*cit);
- ++cit;
- }
- return tmpset;
-}
Deleted: trunk/src/map.h
===================================================================
--- trunk/src/map.h 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/map.h 2005-02-09 22:08:47 UTC (rev 86)
@@ -1,78 +0,0 @@
-#ifndef _MAP_H
-#define _MAP_H 1
-
-/** \brief Scenario organization
-
- Loads the corresponding map data (objects) and performs location checks.
- \remarks MAP FORMAT:
- \remarks "Object class name" "Base image name" "x position" "y position"
- "Arg1" "Arg2" "Arg3"
- \remarks Each Object handels the arguments for itself, usually "Arg1"
- specifies the object name (if the object has no further parameters)
- \remarks Defaults:
- \remarks x and y default to 0
- \remarks Example:
- \remarks Background background.bmp
- \remarks Teleporter teleporter.bmp 0 0 20 100 teleporter1
- \todo Improve the map format (eg. support headers)
- \todo Move the Caches into the current map as well?
- \todo Create a map class inside Scenario?
-*/
-class Scenario {
- public:
- /// Creates a new scenario. To load a specific map, use loadMap(mapname).
- Scenario();
- ~Scenario();
- /// Checks where the source rectangle overlaps the destination rectangle.
- /// \param src Source rectangle
- /// \param dest Destination rectangle
- /// \return Hit Directions of overlapping. DIR_ALL if the destination rectangle is inside
- /// the source rectangle, NOTHING if the source rectangle is inside the destionation
- /// rectangle.
- Hit checkPlace(const SDL_Rect& src, const SDL_Rect& dest) const;
- /// \param mask Mask for the object types that this function should match
- /// (default: all Characters).
- /// \param rect Base region of the target area that should be checked.
- /// \param touch If true an touch (overlapping of area) is enough for a match, otherwise
- /// the center of the specified rectangle has to be inside the target.
- /// \param radius This enlarges the base area by this amount into all specified directions
- /// (default: 0)
- /// \param dir Search directions (default: all)
- /// \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 directions from the source rectangle to the destination rectangle
- /// \remark This may include an enlargment (eg. Olaf)
- /// \param src Source rectangle
- /// \param dest Destination rectangle
- Uint16 getDirection(const SDL_Rect& src, const SDL_Rect& dest) const;
-
- /// Background
- Background* background;
- /// Size of the background (map area)
- SDL_Rect* area;
- /// Current player
- Player* player;
- /// Image Cache
- ImageCache* imgcache;
- /// Sound Cache
- SoundCache* sndcache;
- /// Object pool
- ObjectsPool* pool;
- /// Animation Handler
- AnimHandler* anim;
- /// True if the mission failed
- bool failed;
- ///\brief Loads and initializes the map data
- ///
- /// Parses the map file and tries to add the objects by using addObjectByName()
- /// \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);
- /// Name of the map file
- string name;
- private:
- inline void reinitMap();
-};
-
-#endif
Modified: trunk/src/monsters_common.cpp
===================================================================
--- trunk/src/monsters_common.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/monsters_common.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -6,7 +6,7 @@
#include "sndcache.h"
#include "monsters_common.h"
//shouldn't be here...
-#include "map.h"
+#include "scenario.h"
#include "players_common.h"
Modified: trunk/src/objectpools.cpp
===================================================================
--- trunk/src/objectpools.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objectpools.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -1,5 +1,5 @@
#include "common.h"
-#include "map.h"
+#include "scenario.h"
#include "sfxeng.h"
#include "sndcache.h"
#include "objectpools.h"
Modified: trunk/src/objects/baleog.cpp
===================================================================
--- trunk/src/objects/baleog.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/baleog.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -4,7 +4,7 @@
#include "imgcache.h"
#include "sndcache.h"
#include "input.h"
-#include "map.h"
+#include "scenario.h"
#include "baleog.h"
Modified: trunk/src/objects/bomb.cpp
===================================================================
--- trunk/src/objects/bomb.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/bomb.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -1,7 +1,7 @@
#include "common.h"
//shouldn't be here...
#include "objectpools.h"
-#include "map.h"
+#include "scenario.h"
#include "players_common.h"
#include "triggered_bomb.h"
#include "bomb.h"
Modified: trunk/src/objects/door.cpp
===================================================================
--- trunk/src/objects/door.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/door.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -2,7 +2,7 @@
#include "sndcache.h"
#include "sfxeng.h"
#include "objects_common.h"
-#include "map.h"
+#include "scenario.h"
#include "door.h"
Modified: trunk/src/objects/erik.cpp
===================================================================
--- trunk/src/objects/erik.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/erik.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -2,7 +2,7 @@
#include "events.h"
#include "anim.h"
#include "input.h"
-#include "map.h"
+#include "scenario.h"
#include "weapons.h"
#include "imgcache.h"
#include "sndcache.h"
Modified: trunk/src/objects/exit.cpp
===================================================================
--- trunk/src/objects/exit.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/exit.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -1,7 +1,7 @@
#include "common.h"
#include "objectpools.h"
//shouldn't be here...
-#include "map.h"
+#include "scenario.h"
#include "players_common.h"
#include "exit.h"
Modified: trunk/src/objects/fang.cpp
===================================================================
--- trunk/src/objects/fang.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/fang.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -4,7 +4,7 @@
#include "input.h"
#include "imgcache.h"
#include "sndcache.h"
-#include "map.h"
+#include "scenario.h"
#include "fang.h"
Modified: trunk/src/objects/geyser.cpp
===================================================================
--- trunk/src/objects/geyser.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/geyser.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -4,7 +4,7 @@
#include "objects_common.h"
//shouldn't be here...
#include "players_common.h"
-#include "map.h"
+#include "scenario.h"
#include "geyser.h"
Modified: trunk/src/objects/olaf.cpp
===================================================================
--- trunk/src/objects/olaf.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/olaf.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -4,7 +4,7 @@
#include "input.h"
#include "imgcache.h"
#include "sndcache.h"
-#include "map.h"
+#include "scenario.h"
#include "sfxeng.h"
#include "olaf.h"
Modified: trunk/src/objects/plant.cpp
===================================================================
--- trunk/src/objects/plant.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/plant.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -4,7 +4,7 @@
#include "weapons.h"
#include "players_common.h"
#include "monsters_common.h"
-#include "map.h"
+#include "scenario.h"
#include "plant.h"
Plant::Plant(string imagename, Sint16 xcord, Sint16 ycord, Uint16 trecover, string cname):
Modified: trunk/src/objects/scorch.cpp
===================================================================
--- trunk/src/objects/scorch.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/scorch.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -3,7 +3,7 @@
#include "anim.h"
#include "input.h"
#include "imgcache.h"
-#include "map.h"
+#include "scenario.h"
#include "sndcache.h"
#include "scorch.h"
Modified: trunk/src/objects/spike.cpp
===================================================================
--- trunk/src/objects/spike.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/spike.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -4,7 +4,7 @@
#include "weapons.h"
#include "players_common.h"
#include "monsters_common.h"
-#include "map.h"
+#include "scenario.h"
#include "spike.h"
Spike::Spike(string imagename, Sint16 xcord, Sint16 ycord, Uint16 sdir, string oname):
Modified: trunk/src/objects/teleport.cpp
===================================================================
--- trunk/src/objects/teleport.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/teleport.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -4,7 +4,7 @@
#include "objects_common.h"
//shouldn't be here...
#include "players_common.h"
-#include "map.h"
+#include "scenario.h"
#include "teleport.h"
Modified: trunk/src/objects/trigger.cpp
===================================================================
--- trunk/src/objects/trigger.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/trigger.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -1,6 +1,6 @@
#include "common.h"
#include "objectpools.h"
-#include "map.h"
+#include "scenario.h"
#include "objects_common.h"
#include "trigger.h"
Modified: trunk/src/objects/triggered_bomb.cpp
===================================================================
--- trunk/src/objects/triggered_bomb.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/triggered_bomb.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -3,7 +3,7 @@
#include "sfxeng.h"
#include "weapons.h"
#include "characters_common.h"
-#include "map.h"
+#include "scenario.h"
#include "triggered_bomb.h"
TriggeredBomb::TriggeredBomb(string imagename, Sint16 xcord, Sint16 ycord, Uint16 tleft, string cname):
Modified: trunk/src/objects/water.cpp
===================================================================
--- trunk/src/objects/water.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/water.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -4,7 +4,7 @@
#include "sndcache.h"
#include "weapons.h"
//shouldn't be here...
-#include "map.h"
+#include "scenario.h"
#include "characters_common.h"
#include "water.h"
Modified: trunk/src/objects/zombie.cpp
===================================================================
--- trunk/src/objects/zombie.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects/zombie.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -6,7 +6,7 @@
#include "sndcache.h"
#include "sfxeng.h"
#include "players_common.h"
-#include "map.h"
+#include "scenario.h"
#include "zombie.h"
Modified: trunk/src/objects_common.cpp
===================================================================
--- trunk/src/objects_common.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/objects_common.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -4,7 +4,7 @@
#include "events.h"
#include "objects_common.h"
//HACK!
-#include "map.h"
+#include "scenario.h"
Object::Object(string imagename, Sint16 xcord, Sint16 ycord, string oname):
Modified: trunk/src/players_common.cpp
===================================================================
--- trunk/src/players_common.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/players_common.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -7,7 +7,7 @@
#include "imgcache.h"
#include "sndcache.h"
#include "objectpools.h"
-#include "map.h"
+#include "scenario.h"
#include "players_common.h"
Copied: trunk/src/scenario.cpp (from rev 85, trunk/src/map.cpp)
===================================================================
--- trunk/src/map.cpp 2005-02-09 21:41:07 UTC (rev 85)
+++ trunk/src/scenario.cpp 2005-02-09 22:08:47 UTC (rev 86)
@@ -0,0 +1,183 @@
+#include "common.h"
+#include "objectpools.h"
+#include "players_common.h"
+#include "imgcache.h"
+#include "sndcache.h"
+#include "anim.h"
+#include "scenario.h"
+
+
+Scenario::Scenario():
+ background(NULL),
+ area(NULL),
+ player(NULL),
+ failed(false),
+ name("") {
+ cout << "Scenario: ImageCache...\n";
+ imgcache=new ImageCache();
+ cout << "Scenario: SoundCache...\n";
+ sndcache=new SoundCache();
+ cout << "Scenario: AnimHandler...\n";
+ anim=new AnimHandler();
+ cout << "Map: ObjectsPool...\n";
+ pool=new ObjectsPool();
+}
+
+Scenario::~Scenario() {
+ cout << endl << "Closing map...\n";
+ delete pool;
+ cout << "Map: Deleted Pools...\n";
+ if (background) delete background;
+ cout << "Map: Deleted Background...\n";
+ delete anim;
+ cout << "Scenario: Deleted Animhandler...\n";
+ delete sndcache;
+ cout << "Scenario: Deleted SoundCache...\n";
+ delete imgcache;
+ cout << "Scenario: Deleted ImageCache... (Scenario closed)\n";
+}
+
+inline void Scenario::reinitMap() {
+ if (pool && !(pool->empty())) {
+ delete pool;
+ pool=new ObjectsPool();
+ } else if (!pool) pool=new ObjectsPool();
+ if (background) delete background;
+ background=NULL;
+ area=NULL;
+ player=NULL;
+ name="";
+}
+
+int Scenario::loadMap(string mapname) {
+ reinitMap();
+ cout << "Loading Map data...\n";
+ name=mapname;
+ ifstream mapfile;
+ string tmpline;
+ string image;
+ string arg1,arg2,arg3;
+ Uint16 x,y;
+ background=NULL;
+ area=NULL;
+ string loadfile=config.datadir+name;
+ bool header=false;
+
+ mapfile.open(loadfile.c_str());
+ if (mapfile) {
+ cout << "Loading map configuration file...\n";
+ } else {
+ cout << "Map loading failed: " << (config.datadir+name) << " not found!\n";
+ return -2;
+ }
+
+ //check every line
+ while (getline(mapfile,tmpline)) {
+ //parse the header, always start a header with #HEADER and end it with #ENDHEADER!
+ if (header) {
+ name.erase();
+ arg1.erase();
+ arg2.erase();
+ arg3.erase();
+ std::istringstream tmpstream(tmpline);
+ tmpstream >> name >> arg1 >> arg2 >> arg3;
+ if (name[0]=='#') {
+ if (name=="#ENDHEADER") header=false;
+ continue;
+ }
+ continue;
+ }
+ name.erase();
+ image.erase();
+ x=0;
+ y=0;
+ arg1=arg2="0";
+ arg3="";
+ std::istringstream tmpstream(tmpline);
+ tmpstream >> name >> image >> x >> y >> arg1 >> arg2 >> arg3;
+
+ //Skip empty lines
+ if (name.empty()) continue;
+ //Skip comments
+ if (name[0]=='#') {
+ if (name=="#HEADER") header=true;
+ continue;
+ }
+
+ if (name=="Background" && (!background)) {
+ background=new Background(image);
+ if (background) area=background->getPos();
+ //Background has to be first!
+ } else if (background) {
+ pool->addObjectbyName(name,image,x,y,arg1,arg2,arg3);
+ } else {
+ cout << "No background found yet, skipping " << name << " ...\n";
+ }
+ }
+
+ mapfile.close();
+ mapfile.clear();
+
+ //Has a background been found?
+ if (background) {
+ if (pool->playerspool.size()>0) player=*pool->playerspool.begin();
+ else player=NULL;
+ if (player==NULL) cout << "No player found!\n";
+ return 0;
+ } else {
+ cout << "Map loading failed: No background found!\n";
+ 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;
+ if (src.x > dest.x) dir|=DIR_LEFT;
+ if ((src.y+src.h) < (dest.y+dest.h)) dir|=DIR_DOWN;
+ if (src.y > dest.y) dir|=DIR_UP;
+ return dir;
+}
+
+Hit Scenario::checkPlace(const SDL_Rect& src, const SDL_Rect& dest) const {
+ Hit hit;
+ hit.enter=NOTHING;
+ hit.touch=NOTHING;
+ if (src.x < dest.x) hit.enter|=DIR_LEFT;
+ if (src.x==dest.x) hit.touch|=DIR_LEFT;
+ if (src.y < dest.y) hit.enter|=DIR_UP;
+ if (src.y==dest.y) hit.touch|=DIR_UP;
+ if ((src.x+src.w) > (dest.x+dest.w)) hit.enter|=DIR_RIGHT;
+ if ((src.x+src.w)==(dest.x+dest.w)) hit.touch|=DIR_RIGHT;
+ if ((src.y+src.h) > (dest.y+dest.h)) hit.enter|=DIR_DOWN;
+ if ((src.y+src.h)==(dest.y+dest.h)) hit.touch|=DIR_DOWN;
+ return hit;
+}
+
+
+std::set<Character *> Scenario::getCharactersIn(Uint16 mask, const SDL_Rect& rect, bool touch, Uint16 distance, Uint16 dir) const {
+ SDL_Rect tmprect=rect;
+ if (dir&DIR_LEFT) {
+ tmprect.x-=distance;
+ tmprect.w+=distance;
+ }
+ if (dir&DIR_RIGHT) {
+ tmprect.x+=distance;
+ tmprect.w+=distance;
+ }
+ if (dir&DIR_UP) {
+ tmprect.y-=distance;
+ tmprect.h+=distance;
+ }
+ if (dir&DIR_DOWN) {
+ tmprect.y+=distance;
+ tmprect.h+=distance;
+ }
+ std::set<Character *> tmpset;
+ character_iterator cit=pool->characterspool.begin();
+ while (cit != pool->characterspool.end()) {
+ if ((((*cit)->getType())&mask) && ((*cit)->isIn(tmprect,touch))) tmpset.insert(*cit);
+ ++cit;
+ }
+ return tmpset;
+}
Copied: trunk/src/scenario.h (from rev 85, trunk/src/map.h)
More information about the lostpenguins-commits
mailing list