git » fp-git.git » commit f473e22

better indentation

author ecalot
2006-05-28 18:00:00 UTC
committer ecalot
2006-05-28 18:00:00 UTC
parent 2daad6f7978853e431f3027c7c351a1cf85483d2

better indentation

PV4/include/level.h +55 -53
PV4/include/levelformat.h +3 -2
PV4/include/pop1levelformat.h +37 -37
PV4/src/level.cpp +51 -46
PV4/src/main.cpp +5 -3

diff --git a/PV4/include/level.h b/PV4/include/level.h
index a9cfd33..477329a 100644
--- a/PV4/include/level.h
+++ b/PV4/include/level.h
@@ -8,59 +8,61 @@
 #include <map>
 #include <string>
 
+typedef struct {
+	int floor;
+	int col;
+} tPos;
+
 class Level {
 public:
-	Level(const char* file); //open
-	Level(int popVersion,int LevelNumber); // new
+	Level (const char *file);	//open
+	Level (int popVersion, int LevelNumber);	// new
 
-	void save();
-	void save(const char* file);
+	void save ();
+	void save (const char *file);
 
-	~Level();
+	~Level ();
 
-	map<const char*,const char*>* getInfo();
-	/*
-	plvInfo getInfo();
-	setInfo(plvInfo i);
-	*/
-
-	int getHeight();
-	int getWidth();
-	int countRooms();
-
-	bool addGuard(int floor,int col,Guard g);
-	bool delGuard(int floor,int col);
-	bool moveGuard(int floor,int col,int nfloor,int ncol);
-	bool getGuard(int floor,int col,Guard &g);
-	/*vector <floor,col> getGuards()*/
-
-	void setTile(int floor,int col,Tile* tile);
-	Tile* getTile(int floor,int col);
-	void copyTiles(int sfloor,int scol,int efloor,int ecol,int tfloor, int tcol);
-
-
-	bool addTrigger(int triggerfloor,int triggercol,int targetfloor,int targetcol);
-	bool delTrigger(int triggerfloor,int triggercol,int targetfloor,int targetcol);
-	/*vector <floor,col> getTargets(int triggerfloor,int triggercol);
-	vector <floor,col> getTriggers(int targetfloor,int targetcol);
-	*/
-
-	void getStartPosition(int &floor,int &col,Direction &direction);
-	void setStartPosition(int floor,int col,Direction direction);
-	bool getDebugPosition(int &floor,int &col,Direction &direction);
-	void setDebugPosition(int floor,int col,Direction direction);
-	void clearDebugPosition();
-	void switchPositions();
+	map < const char *, const char *>info;
+	//map<const char*,const char*>* getInfo(); //warning: will be string in a future
+
+	int getHeight ();
+	int getWidth ();
+	int countRooms ();
+
+	bool addGuard (tPos pos, Guard g);
+	bool delGuard (tPos pos);
+	bool moveGuard (tPos spos, tPos tpos);
+	bool getGuard (tPos pos, Guard & g);
+	//vector<tPos> getGuardPositions();
+
+	void setTile (tPos pos, Tile * tile);
+	Tile *getTile (tPos pos);
+	void copyTiles (tPos ssource, tPos esource, tPos target);
 
-	/*
-	bool undo()
-	bool redo()
-	*/
 
-	map<const char*,const char*> info;
+	bool addTrigger (int triggerfloor, int triggercol, int targetfloor,
+			 int targetcol);
+	bool delTrigger (int triggerfloor, int triggercol, int targetfloor,
+			 int targetcol);
+	//vector <tPos> getTargets(tPos trigger);
+	//vector <tPos> getTriggers(tPos target);
+
+
+	void getStartPosition (tPos & pos, Direction & direction);
+	void setStartPosition (tPos pos, Direction direction);
+	bool getDebugPosition (tPos & pos, Direction & direction);
+	void setDebugPosition (tPos pos, Direction direction);
+	void clearDebugPosition ();
+	void switchPositions ();
+
+	/*
+	   bool undo()
+	   bool redo()
+	 */
 
 private:
-	string* fileName;
+	string * fileName;
 
 #define MATRIX_HEIGHT (31+1+31)
 #define MATRIX_WIDTH (31+1+31)
@@ -77,28 +79,28 @@ private:
 	int re;
 	int ce;
 
-	LevelFormat* level;
+	LevelFormat *level;
 
 	int firstFreeTarget;
 
-	int* screens;
+	int *screens;
 
 	//Functions
-	void abstractToFormat(int floor,int col, int &screen, int &location);
-	void formatToAbstract(int &floor,int &col, int screen, int location);
+	void abstractToFormat (tPos pos, int &screen, int &location);
+	void formatToAbstract (tPos & pos, int screen, int location);
 
-	void floorColToXY(int floor,int col, int &x, int &y);
+	void floorColToXY (tPos pos, int &x, int &y);
 
 
-	void arrangeRooms(); /* throws: roomsNotAdjacent */
-	void linkRecurse(int x, int y, int room);
+	void arrangeRooms ();		/* throws: roomsNotAdjacent */
+	void linkRecurse (int x, int y, int room);
 
-	int addScreen(int x, int y);
+	int addScreen (int x, int y);
 
 	//Configuration
 	bool checkIntegrity;
 	bool genericLinks;
-	
+
 };
 
 #endif
diff --git a/PV4/include/levelformat.h b/PV4/include/levelformat.h
index 9aed179..97dce94 100644
--- a/PV4/include/levelformat.h
+++ b/PV4/include/levelformat.h
@@ -12,7 +12,7 @@ class LevelFormat { //abstract class
 
 public:
 
-	LevelFormat::LevelFormat(iesstream& level, int blockSize); //open
+	LevelFormat(iesstream& level, int blockSize); //open
 	LevelFormat(int levelNumber); // new
 	LevelFormat(); // dummy constructor (?)
 
@@ -24,7 +24,7 @@ public:
 
 	virtual bool addGuard(int screen, int location, Guard* g)=0;
 	virtual bool delGuard(int screen, int location)=0;
-virtual Guard* getGuards(int screen, int number)=0;
+	virtual Guard* getGuards(int screen, int number)=0;
 	virtual void setRoomLink(int screen,int left,int right,int up,int down)=0;
 	virtual void getRoomLink(int screen,int &left,int &right,int &up,int &down)=0;
 
@@ -45,3 +45,4 @@ protected:
 };
 
 #endif
+
diff --git a/PV4/include/pop1levelformat.h b/PV4/include/pop1levelformat.h
index 627f640..c1b79b9 100644
--- a/PV4/include/pop1levelformat.h
+++ b/PV4/include/pop1levelformat.h
@@ -7,57 +7,57 @@
 
 using namespace std;
 
-class Pop1LevelFormat: public LevelFormat {
+class Pop1LevelFormat:public LevelFormat {
 
 public:
 
- Pop1LevelFormat::Pop1LevelFormat(iesstream& level, int blockSize); //open
- Pop1LevelFormat(int levelNumber); // new
+	Pop1LevelFormat::Pop1LevelFormat (iesstream & level, int blockSize);	//open
+	Pop1LevelFormat (int levelNumber);	// new
 
- void save(ostream* level);
+	void save (ostream * level);
 
- ~Pop1LevelFormat();
+	~Pop1LevelFormat ();
 
 
- void setTile(int screen, int location, Tile* t);
- Tile* getTile(int screen, int location);
+	void setTile (int screen, int location, Tile * t);
+	Tile *getTile (int screen, int location);
 
- bool addGuard(int screen, int location, Guard* g);
- bool delGuard(int screen, int location);
- Guard* getGuards(int screen, int number);
+	bool addGuard (int screen, int location, Guard * g);
+	bool delGuard (int screen, int location);
+	Guard *getGuards (int screen, int number);
 
 
- void setRoomLink(int screen,int left,int right,int up,int down);
- void getRoomLink(int screen,int &left,int &right,int &up,int &down);
+	void setRoomLink (int screen, int left, int right, int up, int down);
+	void getRoomLink (int screen, int &left, int &right, int &up, int &down);
 
- void getStartPosition(int &screen, int &location,Direction &direction);
- void setStartPosition(int screen, int location,Direction direction);
- bool getDebugPosition(int &screen, int &location,Direction &direction);
- bool setDebugPosition(int screen, int location,Direction direction);
- void clearDebugPosition();
+	void getStartPosition (int &screen, int &location, Direction & direction);
+	void setStartPosition (int screen, int location, Direction direction);
+	bool getDebugPosition (int &screen, int &location, Direction & direction);
+	bool setDebugPosition (int screen, int location, Direction direction);
+	void clearDebugPosition ();
 
-	void setDoorEvent(int event, int screen,int location, int next);
-	void getDoorEvent(int event, int &screen,int &location, int &next);
+	void setDoorEvent (int event, int screen, int location, int next);
+	void getDoorEvent (int event, int &screen, int &location, int &next);
 
 private:
-	unsigned char* walls;
-	unsigned char* backs;
-	unsigned char* doorI;
-	unsigned char* doorII;
-	unsigned char* links;
-	unsigned char* uI;
-	unsigned char* start_position;
-	unsigned char* uII;
-	unsigned char* uIII;
-	unsigned char* guard_location;
-	unsigned char* guard_direction;
-	unsigned char* iIVa;
-	unsigned char* uIVb;
-	unsigned char* guard_skill;
-	unsigned char* uIVc;
-	unsigned char* guard_colour;
-	unsigned char* uIVd;
-	unsigned char* uV;
+	unsigned char *walls;
+	unsigned char *backs;
+	unsigned char *doorI;
+	unsigned char *doorII;
+	unsigned char *links;
+	unsigned char *uI;
+	unsigned char *start_position;
+	unsigned char *uII;
+	unsigned char *uIII;
+	unsigned char *guard_location;
+	unsigned char *guard_direction;
+	unsigned char *iIVa;
+	unsigned char *uIVb;
+	unsigned char *guard_skill;
+	unsigned char *uIVc;
+	unsigned char *guard_colour;
+	unsigned char *uIVd;
+	unsigned char *uV;
 };
 
 #endif
diff --git a/PV4/src/level.cpp b/PV4/src/level.cpp
index 0c8a9b1..339be71 100644
--- a/PV4/src/level.cpp
+++ b/PV4/src/level.cpp
@@ -119,9 +119,9 @@ void Level::save(const char* file){}
 
 Level::~Level(){}
 
-map<const char*,const char*>* Level::getInfo() { //TODO: decide if let map as public and forget about this
+/*map<const char*,const char*>* Level::getInfo() { //TODO: decide if let map as public and forget about this
 	return &(this->info);
-}
+}*/
 
 void Level::linkRecurse(int x, int y, int room) {
  if (matrix(x,y)==-1) {
@@ -222,18 +222,18 @@ int Level::getWidth(){
  return (this->ce-this->cs-1)*10+2;
 }
 
-bool Level::addGuard(int floor,int col,Guard g){return false;}
-bool Level::delGuard(int floor,int col){return false;}
-bool Level::moveGuard(int floor,int col,int nfloor,int ncol){return false;}
-bool Level::getGuard(int floor,int col,Guard &g){return false;}
+bool Level::addGuard(tPos pos,Guard g){return false;}
+bool Level::delGuard(tPos pos){return false;}
+bool Level::moveGuard(tPos spos,tPos tpos){return false;}
+bool Level::getGuard(tPos pos,Guard &g){return false;}
 /*vector <floor,col> getGuards()*/
 
 
-void Level::setTile(int floor,int col,Tile* tile) {
+void Level::setTile(tPos pos,Tile* tile) {
 	int screen;
 	int location;
 
-	this->abstractToFormat(floor,col,screen,location);
+	this->abstractToFormat(pos,screen,location);
 
 	//check if the screen exists
 	if (screen<1) {
@@ -241,7 +241,7 @@ void Level::setTile(int floor,int col,Tile* tile) {
 
 		//the screen doesn't exist, but it's near, we'll try to create it
 		int x,y;
-		this->floorColToXY(floor,col,x,y);
+		this->floorColToXY(pos,x,y);
 
 		screen=this->addScreen(x,y);
 	}
@@ -294,22 +294,22 @@ int Level::addScreen(int x, int y) {
 
 //TODO: delScreen
 
-Tile* Level::getTile(int floor,int col) {
+Tile* Level::getTile(tPos pos) {
 	int screen;
 	int location;
 
-	this->abstractToFormat(floor,col,screen,location);
+	this->abstractToFormat(pos,screen,location);
 //cout<<"f("<<floor<<","<<col<<")=("<<screen<<","<<location<<")"<<endl;
 	if (screen<1) {
 		int r=0;
 		if (!screen) { //only screens 0 (means near to a level)
 			//calculate x and y of the screen
 			int x,y;
-			this->floorColToXY(floor,col,x,y);
-			if (col%10==0  && matrix(x-1,y)>0) r|=DL;
-			if (col%10==9  && matrix(x+1,y)>0) r|=DR;
-			if (floor%3==0 && matrix(x,y-1)>0) r|=DU;
-			if (floor%3==2 && matrix(x,y+1)>0) r|=DD;
+			this->floorColToXY(pos,x,y);
+			if (pos.col%10==0  && matrix(x-1,y)>0) r|=DL;
+			if (pos.col%10==9  && matrix(x+1,y)>0) r|=DR;
+			if (pos.floor%3==0 && matrix(x,y-1)>0) r|=DU;
+			if (pos.floor%3==2 && matrix(x,y+1)>0) r|=DD;
 		}
 		return (Tile*)new OuterTile(r);
 	} else {
@@ -317,22 +317,27 @@ Tile* Level::getTile(int floor,int col) {
 	}
 }
 
-void Level::copyTiles(int sfloor,int scol,int efloor,int ecol,int tfloor, int tcol) {
+void Level::copyTiles(tPos spos, tPos epos, tPos tpos) {
 	
-	//equal col and floor are done
-	if (sfloor==efloor) return;
-	if (scol==ecol) return;
+	//equal col and floor are done spos==epos
+	if (spos.floor==epos.floor) return;
+	if (spos.col==epos.col) return;
 	
 	//order col and floor in case the selection is in other order
-	if (sfloor<efloor) {int aux=efloor;efloor=sfloor;sfloor=aux;}
-	if (scol<ecol)     {int aux=ecol;ecol=scol;scol=aux;}
+	if (spos.floor<epos.floor) {int aux=epos.floor;epos.floor=spos.floor;spos.floor=aux;}
+	if (spos.col<epos.col)     {int aux=epos.col;epos.col=spos.col;spos.col=aux;}
 	
 	Tile* t;
 	
-	for (int i=0;i<efloor-sfloor;i++) {
-		for (int j=0;j<ecol-scol;j++) {
-			t=this->getTile(sfloor+i,scol+j);
-			this->setTile(tfloor+i,tcol+j,t); //TODO: handle sollapations
+	for (int i=0;i<epos.floor-spos.floor;i++) { //TODO: run over eux.floor and col
+		for (int j=0;j<epos.col-spos.col;j++) {
+			tPos aux;
+			aux.floor=spos.floor+i;
+			aux.col=spos.col+j;
+			t=this->getTile(aux);
+			aux.floor=tpos.floor+i;
+			aux.col=tpos.col+j;
+			this->setTile(aux,t); //TODO: handle sollapations
 		}
 	}
 }
@@ -343,33 +348,33 @@ bool delTrigger(int triggerfloor,int triggercol,int targetfloor,int targetcol)
 vector <floor,col> getTargets(int triggerfloor,int triggercol)
 vector <floor,col> getTriggers(int targetfloor,int targetcol)
 */
-void Level::getStartPosition(int &floor,int &col,Direction &direction){
+void Level::getStartPosition(tPos &pos,Direction &direction){
 	int screen;
 	int location;
 	this->level->getStartPosition(screen,location,direction);
-	this->formatToAbstract(floor,col,screen,location);
+	this->formatToAbstract(pos,screen,location);
 }
 
-void Level::setStartPosition(int floor,int col,Direction direction){
+void Level::setStartPosition(tPos pos,Direction direction){
 	int screen;
 	int location;
-	this->abstractToFormat(floor,col,screen,location);
+	this->abstractToFormat(pos,screen,location);
 	if (screen<1) throw -90;
 	this->level->setStartPosition(screen,location,direction);
 }
 
-bool Level::getDebugPosition(int &floor,int &col,Direction &direction){
+bool Level::getDebugPosition(tPos &pos,Direction &direction){
 	int screen;
 	int location;
 	this->level->getDebugPosition(screen,location,direction);
-	this->formatToAbstract(floor,col,screen,location);
+	this->formatToAbstract(pos,screen,location);
 	return screen!=0;
 }
 
-void Level::setDebugPosition(int floor,int col,Direction direction){
+void Level::setDebugPosition(tPos pos,Direction direction){
 	int screen;
 	int location;
-	this->abstractToFormat(floor,col,screen,location);
+	this->abstractToFormat(pos,screen,location);
 	if (screen<1) throw -90;
 	this->level->setDebugPosition(screen,location,direction);
 }
@@ -403,32 +408,32 @@ bool redo();
 */
 
 //Functions
-void Level::floorColToXY(int floor,int col, int &x, int &y){
-	x=this->rs+(floor+2)/3;
-	y=this->cs+(col+9)/10;
+void Level::floorColToXY(tPos pos, int &x, int &y){
+	x=this->rs+(pos.floor+2)/3;
+	y=this->cs+(pos.col+9)/10;
 }
 
-void Level::abstractToFormat(int floor,int col, int &screen, int &location){
+void Level::abstractToFormat(tPos pos, int &screen, int &location){
 	//calculate x and y of the screen
 	int x,y;
-	floorColToXY(floor,col,x,y);
+	floorColToXY(pos,x,y);
 
 	//return values
 	screen=matrix(y,x);
-	location=(col-1)%10+((floor-1)%3)*10;
+	location=(pos.col-1)%10+((pos.floor-1)%3)*10;
 }
 
-void Level::formatToAbstract(int &floor,int &col, int screen, int location){
+void Level::formatToAbstract(tPos &pos, int screen, int location){
 	if (screen<1||screen>this->level->countMax()) throw -14;
 
-	int pos=this->screens[screen];
+	int posaux=this->screens[screen];
 
-	int y=pos/MATRIX_WIDTH;
-	int x=pos%MATRIX_WIDTH;
+	int y=posaux/MATRIX_WIDTH;
+	int x=posaux%MATRIX_WIDTH;
 
 	y-=this->rs;
 	x-=this->cs;
 
-	col=x*10+1;
-	floor=y*3+1;
+	pos.col=x*10+1;
+	pos.floor=y*3+1;
 }
diff --git a/PV4/src/main.cpp b/PV4/src/main.cpp
index 05e3378..69f3ef7 100644
--- a/PV4/src/main.cpp
+++ b/PV4/src/main.cpp
@@ -21,9 +21,11 @@ try {
 
 	Tile* t;
 
-	for (int i=0;i<h;i++) {
-		for (int j=0;j<w;j++) {
-			t=l.getTile(i,j);
+	tPos pos;
+	
+	for (pos.floor=0;pos.floor<h;pos.floor++) {
+		for (pos.col=0;pos.col<w;pos.col++) {
+			t=l.getTile(pos);
 			printf("%02X ",t->getCode()&0x1f);
 		}
 		cout<<endl;