git » fp-git.git » commit 793918c

initial commit

author ecalot
2006-01-31 23:49:31 UTC
committer ecalot
2006-01-31 23:49:31 UTC
parent 793802053c191ca4da5940a95fd9d60d04620fad

initial commit

PV4/include/endiansafestream.h +23 -0
PV4/include/guard.h +23 -0
PV4/include/level.h +90 -0
PV4/include/levelformat.h +48 -0
PV4/include/outertile.h +22 -0
PV4/include/pop1levelformat.h +63 -0
PV4/include/pop1tile.h +20 -0
PV4/include/pop2tile.h +21 -0
PV4/include/tile.h +23 -0
PV4/src/endiansafestream.cpp +46 -0
PV4/src/guard.cpp +19 -0
PV4/src/level.cpp +397 -0
PV4/src/levelformat.cpp +56 -0
PV4/src/main.cpp +11 -0
PV4/src/outertile.cpp +17 -0
PV4/src/pop1levelformat.cpp +204 -0
PV4/src/pop1tile.cpp +18 -0
PV4/src/pop2tile.cpp +20 -0
PV4/src/tile.cpp +1 -0

diff --git a/PV4/include/endiansafestream.h b/PV4/include/endiansafestream.h
new file mode 100644
index 0000000..600d7ab
--- /dev/null
+++ b/PV4/include/endiansafestream.h
@@ -0,0 +1,23 @@
+#ifndef _ENDIANSAFESTREAM_H_
+#define _ENDIANSAFESTREAM_H_
+
+#include <iostream>
+#include <fstream>
+
+using namespace std;
+
+class iesstream: public ifstream  {
+public:
+	iesstream(const char* file);
+	void read(unsigned char &c);
+	void read(char &c);
+	void read(long &l);
+	void read(unsigned long &l);
+	void read(short &s);
+	void read(unsigned short &s);
+	void read(unsigned char* c,int size);
+	void read(char* c,int size);
+};
+
+
+#endif
diff --git a/PV4/include/guard.h b/PV4/include/guard.h
new file mode 100644
index 0000000..454996f
--- /dev/null
+++ b/PV4/include/guard.h
@@ -0,0 +1,23 @@
+#ifndef _GUARD_H_
+#define _GUARD_H_
+
+typedef enum {left=0,right=-1} Direction;
+
+class Guard {
+public:
+       Guard(Direction direction,int  skill,int color); //TODO: use an abstract class for pop1 and pop2
+       int getSkill();
+       int getColour();
+       Direction getDirection();
+
+private:
+        Direction direction;
+        int skill;      
+        int color;
+      
+      
+      
+      
+};
+
+#endif
diff --git a/PV4/include/level.h b/PV4/include/level.h
new file mode 100644
index 0000000..400c99e
--- /dev/null
+++ b/PV4/include/level.h
@@ -0,0 +1,90 @@
+#ifndef _LEVEL_H_
+#define _LEVEL_H_
+
+#include <string>
+
+class Level {
+	Level(const char* file); //open
+	Level(int popVersion,int LevelNumber); // new
+
+	void save();
+	void save(const char* file);
+
+	~Level();
+
+	/*
+	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);
+
+
+	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();
+
+	/*
+	bool undo()
+	bool redo()
+	*/
+
+private:
+	string* fileName;
+#define MATRIX_HEIGHT (31+1+31)
+#define MATRIX_WIDTH (31+1+31)
+
+#define SIZE_OF_MATRIX (MATRIX_HEIGHT*MATRIX_WIDTH)
+#define matrix(x,y) this->screenMatrix[MATRIX_WIDTH*y+x]
+
+#define MATRIX_CENTER_X 32
+#define MATRIX_CENTER_Y 32
+
+	char screenMatrix[SIZE_OF_MATRIX];
+	int rs;
+	int cs;
+	int re;
+	int ce;
+
+	LevelFormat* level;
+
+	int firstFreeTarget;
+
+	int* screens;
+
+	//Functions
+	void abstractToFormat(int floor,int col, int &screen, int &location);
+	void formatToAbstract(int &floor,int &col, int screen, int location);
+
+	void floorColToXY(int floor,int col, int &x, int &y);
+
+
+	void arrangeRooms(); /* throws: roomsNotAdjacent */
+	void linkRecurse(int x, int y, int room);
+
+	int addScreen(int x, int y);
+
+};
+
+#endif
diff --git a/PV4/include/levelformat.h b/PV4/include/levelformat.h
new file mode 100644
index 0000000..65b3503
--- /dev/null
+++ b/PV4/include/levelformat.h
@@ -0,0 +1,48 @@
+#ifndef _LEVELFORMAT_H_
+#define _LEVELFORMAT_H_
+
+#include <iostream>
+#include "guard.h"
+#include "tile.h"
+#include "endiansafestream.h"
+
+using namespace std;
+
+class LevelFormat { //abstract class
+
+public:
+
+	LevelFormat::LevelFormat(iesstream& level, int blockSize); //open
+	LevelFormat(int levelNumber); // new
+	LevelFormat(); // dummy constructor (?)
+
+	~LevelFormat();
+
+
+	virtual void save(ostream* level)=0;
+	virtual void setTile(int screen, int location, Tile* t)=0;
+	virtual Tile* getTile(int screen, int location)=0;
+
+	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 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;
+
+	virtual void getStartPosition(int &screen, int &location,Direction &direction)=0;
+	virtual void setStartPosition(int screen, int location,Direction direction)=0;
+	virtual bool getDebugPosition(int &screen, int &location,Direction &direction)=0;
+	virtual bool setDebugPosition(int screen, int location,Direction direction)=0;
+	virtual void clearDebugPosition()=0;
+
+	virtual void setDoorEvent(int event, int screen,int location, int next)=0;
+	virtual void getDoorEvent(int event, int &screen,int &location, int &next)=0;
+
+	int countMax();
+
+protected:
+	int countRooms;
+
+};
+
+#endif
diff --git a/PV4/include/outertile.h b/PV4/include/outertile.h
new file mode 100644
index 0000000..84ea657
--- /dev/null
+++ b/PV4/include/outertile.h
@@ -0,0 +1,22 @@
+#ifndef _OUTERTILE_H_
+#define _OUTERTILE_H_
+
+#include "tile.h"
+
+#define DU 1
+#define DD 2
+#define DL 4
+#define DR 8
+
+class OuterTile: Tile {
+public:
+	OuterTile(int code);
+/*      string serializeCode();
+	string serializeBack();*/
+	int getDoorEvent();
+	int getAttr();
+	int getImg();
+
+};
+
+#endif
diff --git a/PV4/include/pop1levelformat.h b/PV4/include/pop1levelformat.h
new file mode 100644
index 0000000..627f640
--- /dev/null
+++ b/PV4/include/pop1levelformat.h
@@ -0,0 +1,63 @@
+#ifndef _POP1LEVELFORMAT_H_
+#define _POP1LEVELFORMAT_H_
+
+#include <iostream>
+#include "guard.h"
+#include "tile.h"
+
+using namespace std;
+
+class Pop1LevelFormat: public LevelFormat {
+
+public:
+
+ Pop1LevelFormat::Pop1LevelFormat(iesstream& level, int blockSize); //open
+ Pop1LevelFormat(int levelNumber); // new
+
+ void save(ostream* level);
+
+ ~Pop1LevelFormat();
+
+
+ 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);
+
+
+ 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 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;
+};
+
+#endif
diff --git a/PV4/include/pop1tile.h b/PV4/include/pop1tile.h
new file mode 100644
index 0000000..7282570
--- /dev/null
+++ b/PV4/include/pop1tile.h
@@ -0,0 +1,20 @@
+#ifndef _POP1TILE_H_
+#define _POP1TILE_H_
+
+#include "tile.h"
+
+class Pop1Tile: Tile { // abstract class
+public:
+	Pop1Tile(unsigned char code, unsigned char back);
+/*      string serializeCode();
+	string serializeBack();*/
+	int getDoorEvent();
+	int getAttr();
+	int getImg();
+
+private:
+	int back;
+
+};
+
+#endif
diff --git a/PV4/include/pop2tile.h b/PV4/include/pop2tile.h
new file mode 100644
index 0000000..cee8d7b
--- /dev/null
+++ b/PV4/include/pop2tile.h
@@ -0,0 +1,21 @@
+#ifndef _POP2TILE_H_
+#define _POP2TILE_H_
+
+#include "tile.h"
+
+class Pop2Tile: Tile { // abstract class
+public:
+	Pop2Tile(unsigned char code, unsigned char back[5]);
+/*      string serializeCode();
+	string serializeBack();*/
+	int getDoorEvent();
+	int getAttr();
+	int getImg();
+
+private:
+	int attr;
+	int door;
+	int img;
+};
+
+#endif
diff --git a/PV4/include/tile.h b/PV4/include/tile.h
new file mode 100644
index 0000000..ef7ee7d
--- /dev/null
+++ b/PV4/include/tile.h
@@ -0,0 +1,23 @@
+#ifndef _TILE_H_
+#define _TILE_H_
+
+#include <string>
+using namespace std;
+
+class Tile { // abstract class
+public:
+      int getDoorEvent();
+      int getAttr();
+      int getImg();
+
+      /* used to serialize self created tiles */
+      int getWalls();
+      int getBacks();
+
+protected:
+	int level; /* this is very important to know what tiles are allowed */
+	int code;
+
+};
+
+#endif
diff --git a/PV4/src/endiansafestream.cpp b/PV4/src/endiansafestream.cpp
new file mode 100644
index 0000000..6cae92e
--- /dev/null
+++ b/PV4/src/endiansafestream.cpp
@@ -0,0 +1,46 @@
+#include "endiansafestream.h"
+
+#include <iostream>
+#include <fstream>
+
+using namespace std;
+
+iesstream::iesstream(const char* file) {
+   this->open(file,ios::in|ios::binary);
+   if (!this->is_open()) throw -2;
+}
+
+void iesstream::read(unsigned char& c) {
+         this->read((char*)&c,1);
+}
+
+void iesstream::read(char &c){
+	this->read(&c,1);
+         }
+
+void iesstream::read(long &l){
+         this->read((char*)&l,4);
+         }
+
+void iesstream::read(unsigned long &l){
+	this->read((char*)&l,4);
+	}
+
+ void iesstream::read(short &s){
+	 this->read((char*)&s,2);
+	 }
+
+  void iesstream::read(unsigned short &s){
+		this->read((char*)&s,2);
+		}
+
+  void iesstream::read(unsigned char* c,int size){
+		this->read((char*)c,size);
+		}
+
+  void iesstream::read(char* c,int size){
+		this->read(c,(streamsize)size);
+		}
+
+
+
diff --git a/PV4/src/guard.cpp b/PV4/src/guard.cpp
new file mode 100644
index 0000000..c22b554
--- /dev/null
+++ b/PV4/src/guard.cpp
@@ -0,0 +1,19 @@
+#include "guard.h"
+
+
+Guard::Guard(Direction direction,int  skill,int color) {
+this->direction=direction;
+this->skill=skill;
+this->color=color;
+}
+
+       int Guard::getSkill(){
+           return this->skill;
+           }
+       int Guard::getColour(){
+           return this->color;
+           }
+       Direction Guard::getDirection(){
+                 return this->direction;
+                 
+                 }
diff --git a/PV4/src/level.cpp b/PV4/src/level.cpp
new file mode 100644
index 0000000..0e865f2
--- /dev/null
+++ b/PV4/src/level.cpp
@@ -0,0 +1,397 @@
+#include <iostream>
+#include "endiansafestream.h"
+
+#include "levelFormat.h"
+#include "pop1levelFormat.h"
+#include "level.h"
+#include "guard.h"
+#include "tile.h"
+#include "outertile.h"
+
+using namespace std;
+/*
+                   Table 6.1: PLV blocks
+                   ~~~~~~~~~~~~~~~~~~~~~
+
+   Size Offset Description                  Type   Content
+   ~~~~ ~~~~~~ ~~~~~~~~~~~                  ~~~~   ~~~~~~~
+      7      0 Magic identifier             text   "POP_LVL"
+      1      7 POP version                  UC     0x01
+      1      8 PLV version                  UC     0x01
+      1      9 Level Number                 UC
+      4     10 Number of fields             UL
+      4     14 Block 1: Level size (B1)     UL     2306/2305
+     B1     18 Block 1: Level code          -
+      4  18+B1 Block 2: User data size (B2) UL
+     B2  22+B1 Block 2: User data           -
+*/
+typedef char* fieldPointer;
+
+Level::Level(const char* file) { //open
+	//open the file
+  iesstream stream(file);
+
+	//check the magic
+	char magic[7];
+	stream.read(magic,7);
+	if (strncmp(magic,"POP_LVL",7)) throw -3;
+
+	//read pop version
+	unsigned char popVersion;
+	stream.read(popVersion);
+
+	//read plv version
+	unsigned char plvVersion;
+	stream.read(plvVersion);
+
+	//level number
+	unsigned char level;
+	stream.read(level);
+
+	//number of fields
+	unsigned long nf;
+	stream.read(nf);
+
+	//level size
+	unsigned long b1;
+	stream.read(b1);
+
+	//level code
+	switch (popVersion) {
+		case 1:
+			this->level=new Pop1LevelFormat(stream,b1);
+		case 2:
+//			this->level=new Pop2LevelFormat(stream,b1);
+		default:
+			throw -2;
+	}
+
+	//user data size
+	unsigned long b2;
+	stream.read(b2);
+
+	//alloc user data (TODO: use integrity checks here)
+	char* ud=new char[b2];
+	stream.read(ud,b2);
+
+	//process user data
+	fieldPointer* fields=new fieldPointer[nf*2];
+	int currentField=1;
+
+	fields[0]=ud;
+	for (int i=0;i<b2&&currentField<nf*2;i++) {
+		if (!ud[i]) fields[currentField++]=ud+i;
+	}
+
+	if (currentField!=nf*2-1||ud[b2-1]!=0) throw -2;
+
+	//TODO: generate a hash table with this values
+
+	//remember the file name
+	this->fileName=new string(file);
+
+	//Finally arrange the rooms
+	this->arrangeRooms();
+}
+
+Level::Level(int popVersion,int LevelNumber){} // new
+
+void Level::save(){}
+void Level::save(const char* file){}
+
+Level::~Level(){}
+
+/*
+plvInfo Level::getInfo()
+Level::setInfo(plvInfo i)
+*/
+
+void Level::linkRecurse(int x, int y, int room) {
+ if (matrix(x,y)==-1) {
+  matrix(x,y)=room;
+  if (room) {
+   int up,down,left,right;
+   this->level->getRoomLink(room,left,right,up,down);
+   linkRecurse(x+1,y,right);
+   linkRecurse(x-1,y,left);
+   linkRecurse(x,y+1,down);
+   linkRecurse(x,y-1,up);
+  }
+ } else {
+  if (matrix(x,y)!=room) throw -1;
+ }
+}
+
+void Level::arrangeRooms() {
+ //initialize matrix
+ for (int i=0;i<SIZE_OF_MATRIX;i++)
+  this->screenMatrix[i]=-1;
+
+ int startScreen,junk;
+ Direction junk2;
+
+ //Fill in the matrix with the rooms
+ getStartPosition(startScreen,junk,junk2);
+ linkRecurse(MATRIX_CENTER_X,MATRIX_CENTER_Y,startScreen);
+
+ //Get the matrix limits
+ for (int i=0;i<MATRIX_HEIGHT;i++) {
+  for (int j=0;j<MATRIX_WIDTH;j++) {
+   if (!matrix(i,j)) {
+    this->rs=i;
+    i=j=MATRIX_WIDTH;
+   }
+  }
+ }
+
+ for (int i=MATRIX_HEIGHT;i--;) {
+  for (int j=0;j<MATRIX_WIDTH;j++) {
+   if (!matrix(i,j)) {
+    this->re=i;
+    i=0;
+    j=MATRIX_WIDTH;
+   }
+  }
+ }
+
+ for (int i=0;i<MATRIX_WIDTH;i++) {
+  for (int j=0;j<MATRIX_HEIGHT;j++) {
+   if (!matrix(j,i)) {
+    this->cs=i;
+    i=j=MATRIX_WIDTH;
+   }
+  }
+ }
+
+ for (int i=MATRIX_WIDTH;i--;) {
+  for (int j=0;i<MATRIX_HEIGHT;j++) {
+   if (!matrix(j,i)) {
+    this->ce=i;
+    i=0;
+    j=MATRIX_WIDTH;
+   }
+  }
+ }
+
+	//Now it's time to add all screens in the screens array
+	this->screens=new int[this->level->countMax()];
+	for (int i=0;i<this->level->countMax();i++)
+		this->screens[i]=0;
+
+	for (int i=this->rs;i<this->re;i++) {
+		for (int j=this->cs;i<this->ce;i++) {
+			if (matrix(i,j)>0) {
+				if (matrix(i,j)>this->level->countMax()) throw -13;
+				this->screens[matrix(i,j)]=MATRIX_WIDTH*j+i;
+			}
+		}
+	}
+}
+
+int Level::getHeight(){
+ return (this->rs-this->re-2)*3+2;
+}
+
+
+int Level::getWidth(){
+ return (this->cs-this->ce-2)*10+2;
+}
+
+int Level::countRooms(){}
+
+bool Level::addGuard(int floor,int col,Guard g){}
+bool Level::delGuard(int floor,int col){}
+bool Level::moveGuard(int floor,int col,int nfloor,int ncol){}
+bool Level::getGuard(int floor,int col,Guard &g){}
+/*vector <floor,col> getGuards()*/
+
+
+void Level::setTile(int floor,int col,Tile* tile) {
+	int screen;
+	int location;
+
+	this->abstractToFormat(floor,col,screen,location);
+
+	//check if the screen exists
+	if (screen<1) {
+		if (screen==-1) throw -80; //room is too far and cannot be displayed in the level
+
+		//the screen doesn't exist, but it's near, we'll try to create it
+		int x,y;
+		this->floorColToXY(floor,col,x,y);
+
+		screen=this->addScreen(x,y);
+	}
+
+	//and now set the tile
+
+}
+
+int Level::addScreen(int x, int y) {
+	int result=-1;
+	for (int i=0;i<this->level->countMax() && result==-1;i++) {
+		if (!this->screens[i]) result=i;
+	}
+	if (result==-1) throw -87; //level full
+
+	//Link the new screen
+	int left,right,up,down;
+	int screen;
+
+	screen=matrix(x-1,y); //left
+	if (screen>0) {
+		this->level->getRoomLink(screen,left,right,up,down);
+		this->level->setRoomLink(screen,left,result,up,down);
+	}
+
+	screen=matrix(x+1,y); //right
+	if (screen>0) {
+		this->level->getRoomLink(screen,left,right,up,down);
+		this->level->setRoomLink(screen,result,right,up,down);
+	}
+
+	screen=matrix(x,y+1); //down
+	if (screen>0) {
+		this->level->getRoomLink(screen,left,right,up,down);
+		this->level->setRoomLink(screen,left,right,result,down);
+	}
+
+	screen=matrix(x,y-1); //up
+	if (screen>0) {
+		this->level->getRoomLink(screen,left,right,up,down);
+		this->level->setRoomLink(screen,left,right,up,result);
+	}
+
+	this->level->setRoomLink(result,matrix(x-1,y),matrix(x+1,y),matrix(x,y-1),matrix(x,y+1));
+
+	//recalculate
+	this->arrangeRooms();
+}
+
+//TODO: delScreen
+
+Tile* Level::getTile(int floor,int col) {
+	int screen;
+	int location;
+
+	this->abstractToFormat(floor,col,screen,location);
+
+	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;
+		}
+		return (Tile*)new OuterTile(r);
+	} else {
+		return this->level->getTile(screen,location);
+	}
+}
+
+void copyTiles(int sfloor,int scol,int efloor,int ecol) {}
+
+/*
+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 Level::getStartPosition(int &floor,int &col,Direction &direction){
+	int screen;
+	int location;
+	this->level->getStartPosition(screen,location,direction);
+	this->formatToAbstract(floor,col,screen,location);
+}
+
+void Level::setStartPosition(int floor,int col,Direction direction){
+	int screen;
+	int location;
+	this->abstractToFormat(floor,col,screen,location);
+	if (screen<1) throw -90;
+	this->level->setStartPosition(screen,location,direction);
+}
+
+bool Level::getDebugPosition(int &floor,int &col,Direction &direction){
+	int screen;
+	int location;
+	this->level->getDebugPosition(screen,location,direction);
+	this->formatToAbstract(floor,col,screen,location);
+	return screen!=0;
+}
+
+void Level::setDebugPosition(int floor,int col,Direction direction){
+	int screen;
+	int location;
+	this->abstractToFormat(floor,col,screen,location);
+	if (screen<1) throw -90;
+	this->level->setDebugPosition(screen,location,direction);
+}
+
+void Level::clearDebugPosition(){
+	this->level->clearDebugPosition();
+}
+
+void Level::switchPositions(){
+	int dscreen;
+	int dlocation;
+	Direction ddirection;
+
+	this->level->getDebugPosition(dscreen,dlocation,ddirection);
+
+	int sscreen;
+	int slocation;
+	Direction sdirection;
+
+	this->level->getStartPosition(sscreen,slocation,sdirection);
+
+	if (!dscreen) throw -91; //no debug position set
+
+	this->level->setStartPosition(dscreen,dlocation,ddirection);
+	this->level->setDebugPosition(sscreen,slocation,sdirection);
+}
+
+/*
+bool undo();
+bool redo();
+*/
+
+//Functions
+void Level::floorColToXY(int floor,int col, int &x, int &y){
+	x=this->rs+1+col/10;
+	y=this->cs+1+floor/3;
+}
+
+void Level::abstractToFormat(int floor,int col, int &screen, int &location){
+
+	//ignore the first col and row
+	col--;
+	floor--;
+
+	//calculate x and y of the screen
+	int x,y;
+	floorColToXY(floor,col,x,y);
+
+	//return values
+	screen=matrix(x,y);
+	location=col%10+(floor%3)*10;
+}
+
+void Level::formatToAbstract(int &floor,int &col, int screen, int location){
+	if (screen<1||screen>this->level->countMax()) throw -14;
+
+	int pos=this->screens[screen];
+
+	int y=pos/MATRIX_WIDTH;
+	int x=pos%MATRIX_WIDTH;
+
+	y-=this->rs;
+	x-=this->cs;
+
+	col=x*10+1;
+	floor=y*3+1;
+}
diff --git a/PV4/src/levelformat.cpp b/PV4/src/levelformat.cpp
new file mode 100644
index 0000000..42431af
--- /dev/null
+++ b/PV4/src/levelformat.cpp
@@ -0,0 +1,56 @@
+#include <iostream>
+#include "levelformat.h"
+#include "guard.h"
+#include "tile.h"
+
+using namespace std;
+
+LevelFormat::LevelFormat(iesstream& level, int blockSize){
+
+
+}
+
+LevelFormat::LevelFormat(){}
+
+LevelFormat::LevelFormat(int levelNumber) {
+
+
+
+
+}
+/*
+void LevelFormat::save(ostream* level) {
+}
+*/
+LevelFormat::~LevelFormat() {
+}
+
+int LevelFormat::countMax(){
+	return this->countRooms;
+}
+/*
+
+setTile(int screen, int location, tile t);
+getTile(int screen, int location, tile &t);
+
+bool addGuard(int screen, int location, guard g);
+bool delGuard(int screen, int location);
+bool getGuards(int screen, int number, guard &g);
+
+
+
+void LevelFormat::setRoomLink(int screen,int left,int right,int up,int down){}
+void LevelFormat::getRoomLink(int screen,int &left,int &right,int &up,int &down){}
+
+
+getStartPosition(int &screen, int &location,&direction);
+setStartPosition(int screen, int location,direction);
+bool getDebugPosition(int &screen, int &location,&direction);
+bool setDebugPosition(int screen, int location,direction);
+clearDebugPosition();
+
+
+private:
+int countRooms;
+*/
+
diff --git a/PV4/src/main.cpp b/PV4/src/main.cpp
new file mode 100644
index 0000000..fdd7fd3
--- /dev/null
+++ b/PV4/src/main.cpp
@@ -0,0 +1,11 @@
+#include <cstdlib>
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+    cout<<"hello";
+    system("PAUSE");
+    return EXIT_SUCCESS;
+}
diff --git a/PV4/src/outertile.cpp b/PV4/src/outertile.cpp
new file mode 100644
index 0000000..b8f4039
--- /dev/null
+++ b/PV4/src/outertile.cpp
@@ -0,0 +1,17 @@
+#include "outertile.h"
+
+OuterTile::OuterTile(int code) {
+ this->code=code;
+}
+
+int OuterTile::getDoorEvent() {
+	return 0;
+}
+
+int OuterTile::getAttr() {
+	return 0;
+}
+
+int OuterTile::getImg() {
+	return 0;
+}
diff --git a/PV4/src/pop1levelformat.cpp b/PV4/src/pop1levelformat.cpp
new file mode 100644
index 0000000..3f27340
--- /dev/null
+++ b/PV4/src/pop1levelformat.cpp
@@ -0,0 +1,204 @@
+#include <iostream>
+#include "levelformat.h"
+#include "pop1levelformat.h"
+#include "guard.h"
+#include "tile.h"
+#include "pop1tile.h"
+#include "endiansafestream.h"
+
+using namespace std;
+
+Pop1LevelFormat::Pop1LevelFormat(iesstream& stream, int blockSize){
+//open
+/*
+                   Table 4.1: DAT 1.0 Level blocks
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+  Length Offset  Block Name
+  ~~~~~~ ~~~~~~  ~~~~~~~~~~
+  720    0       wall
+  720    720     pop1_background
+  256    1440    door I
+  256    1696    door II
+  96     1952    links
+  64     2048    unknown I
+  3      2112    start_position
+  3      2115    unknown II
+  1      2116    unknown III
+  24     2119    guard_location
+  24     2143    guard_direction
+  24     2167    unknown VI (a)
+  24     2191    unknown VI (b)
+  24     2215    guard_skill
+  24     2239    unknown VI (c)
+  24     2263    guard_colour
+  16     2287    unknown VI (d)
+  2      2303    0F 09 (2319)
+
+*/
+
+	this->countRooms=24;
+
+	//Read walls
+	this->walls=new unsigned char[720];
+	stream.read(this->walls,720);
+
+	//Read backs
+	this->backs=new unsigned char[720];
+	stream.read(this->backs,720);
+
+	//Read door I
+	this->doorI=new unsigned char[256];
+	stream.read(this->doorI,256);
+
+	//Read door II
+	this->doorII=new unsigned char[256];
+	stream.read(this->doorII,256);
+
+	//Read links
+	this->links=new unsigned char[96];
+	stream.read(this->links,96);
+
+	//Read unknown I
+	this->uI=new unsigned char[64];
+	stream.read(this->uI,64);
+
+	//Read start_position
+	this->start_position=new unsigned char[3];
+	stream.read(this->start_position,3);
+
+	//Read unknown II
+	this->uII=new unsigned char[3];
+	stream.read(this->uII,3);
+
+	//Read unknown III
+	this->uIII=new unsigned char[1];
+	stream.read(this->uIII,1);
+
+	//Read guard_location
+	this->guard_location=new unsigned char[24];
+	stream.read(this->guard_location,24);
+
+	//Read guard_direction
+	this->guard_direction=new unsigned char[24];
+	stream.read(this->guard_direction,24);
+
+	//Read unknown IV (a)
+	this->iIVa=new unsigned char[24];
+	stream.read(this->iIVa,24);
+
+	//Read unknown IV (b)
+	this->uIVb=new unsigned char[24];
+	stream.read(this->uIVb,24);
+
+	//Read guard_skill
+	this->guard_skill=new unsigned char[24];
+	stream.read(this->guard_skill,24);
+
+	//Read unknown IV (c)
+	this->uIVc=new unsigned char[24];
+	stream.read(this->uIVc,24);
+
+	//Read guard_colour
+	this->guard_colour=new unsigned char[24];
+	stream.read(this->guard_colour,24);
+
+	//Read unknown IV (d)
+	this->uIVd=new unsigned char[16];
+	stream.read(this->uIVd,24);
+
+	//Read 0F 09 (2319)
+	this->uV=new unsigned char[2];
+	stream.read(this->uV,24);
+
+}
+
+Pop1LevelFormat::Pop1LevelFormat(int levelNumber) {
+
+}
+
+void Pop1LevelFormat::save(ostream* level) {
+}
+
+Pop1LevelFormat::~Pop1LevelFormat() {
+}
+
+void Pop1LevelFormat::setTile(int screen, int location, Tile* t) {
+	if (screen<1||screen>24||location<0||location>29) throw -10;
+	this->walls[(screen-1)*30+location]=t->getWalls();
+	this->backs[(screen-1)*30+location]=t->getBacks();
+}
+
+Tile* Pop1LevelFormat::getTile(int screen, int location) {
+	if (screen<1||screen>24||location<0||location>29) throw -10;
+	return (Tile*)new Pop1Tile(
+		this->walls[(screen-1)*30+location],
+		this->backs[(screen-1)*30+location]
+	);
+}
+
+bool Pop1LevelFormat::addGuard(int screen, int location, Guard* g) {
+	if (this->guard_location[screen-1]>29) return false;
+	this->guard_location[screen-1]=location;
+	this->guard_direction[screen-1]=g->getDirection();
+	this->guard_skill[screen-1]=g->getSkill();
+	this->guard_colour[screen-1]=g->getColour();
+
+	return true;
+}
+
+bool Pop1LevelFormat::delGuard(int screen, int location) {
+	if (!(this->guard_location[screen-1]>29)) return false;
+	this->guard_location[screen-1]=30;
+	this->guard_direction[screen-1]=0;
+	this->guard_skill[screen-1]=0;
+	this->guard_colour[screen-1]=0;
+	return true;
+}
+
+Guard* Pop1LevelFormat::getGuards(int screen, int number){
+	if (number!=0) return NULL;
+	if (this->guard_location[screen-1]>29) return NULL;
+	return new Guard(
+		(Direction)this->guard_direction[screen-1],
+		this->guard_skill[screen-1],
+		this->guard_colour[screen-1]
+	);
+}
+
+void Pop1LevelFormat::setRoomLink(int screen,int left,int right,int up,int down){
+	this->links[(screen-1)*4]=left;
+	this->links[(screen-1)*4+1]=right;
+	this->links[(screen-1)*4+2]=up;
+	this->links[(screen-1)*4+3]=down;
+}
+
+void Pop1LevelFormat::getRoomLink(int screen,int &left,int &right,int &up,int &down){
+	left=this->links[(screen-1)*4];
+	right=this->links[(screen-1)*4+1];
+	up=this->links[(screen-1)*4+2];
+	down=this->links[(screen-1)*4+3];
+}
+
+
+
+void Pop1LevelFormat::getStartPosition(int &screen, int &location,Direction &direction) {
+ screen=this->start_position[0];      
+ if (screen<0||screen>24) throw 23; //bad file format
+ location=this->start_position[1];      
+ if (location>29) throw 23; //bad file format
+ direction=(Direction)this->start_position[2];      
+      
+      
+      
+      }
+      
+/*
+setStartPosition(int screen, int location,direction);
+bool getDebugPosition(int &screen, int &location,&direction);
+bool setDebugPosition(int screen, int location,direction);
+clearDebugPosition();
+
+
+*/
+
diff --git a/PV4/src/pop1tile.cpp b/PV4/src/pop1tile.cpp
new file mode 100644
index 0000000..ec452d3
--- /dev/null
+++ b/PV4/src/pop1tile.cpp
@@ -0,0 +1,18 @@
+#include "pop1tile.h"
+
+Pop1Tile::Pop1Tile(unsigned char code, unsigned char back) {
+ this->code=code;
+ this->back=back;
+}
+
+int Pop1Tile::getDoorEvent() {
+	return this->back;
+}
+
+int Pop1Tile::getAttr() {
+	return this->back;
+}
+
+int Pop1Tile::getImg() {
+	return 0;
+}
diff --git a/PV4/src/pop2tile.cpp b/PV4/src/pop2tile.cpp
new file mode 100644
index 0000000..f86b504
--- /dev/null
+++ b/PV4/src/pop2tile.cpp
@@ -0,0 +1,20 @@
+#include "pop2tile.h"
+
+Pop2Tile::Pop2Tile(unsigned char code, unsigned char back[5]) {
+ this->code=code;
+ this->attr=back[0];
+ this->door=back[1];
+ this->img=back[2]+back[3]>>8;
+}
+
+int Pop2Tile::getDoorEvent() {
+	return this->door;
+}
+
+int Pop2Tile::getAttr() {
+	return this->attr;
+}
+
+int Pop2Tile::getImg() {
+	return this->img;
+}
diff --git a/PV4/src/tile.cpp b/PV4/src/tile.cpp
new file mode 100644
index 0000000..d8e7c04
--- /dev/null
+++ b/PV4/src/tile.cpp
@@ -0,0 +1 @@
+#include "tile.h"