author | ecalot
<ecalot> 2006-02-01 20:12:35 UTC |
committer | ecalot
<ecalot> 2006-02-01 20:12:35 UTC |
parent | 305e858dad323bb74bccd35ffa7e0c611abdccf2 |
PV4/include/level.h | +4 | -0 |
PV4/include/outertile.h | +1 | -0 |
PV4/include/pop1tile.h | +1 | -0 |
PV4/include/pop2tile.h | +1 | -0 |
PV4/include/tile.h | +4 | -7 |
PV4/src/endiansafestream.cpp | +6 | -6 |
PV4/src/level.cpp | +19 | -6 |
PV4/src/main.cpp | +16 | -3 |
PV4/src/outertile.cpp | +4 | -0 |
PV4/src/pop1levelformat.cpp | +65 | -21 |
PV4/src/pop1tile.cpp | +4 | -0 |
PV4/src/pop2tile.cpp | +4 | -0 |
diff --git a/PV4/include/level.h b/PV4/include/level.h index 400c99e..94cbf8e 100644 --- a/PV4/include/level.h +++ b/PV4/include/level.h @@ -2,8 +2,12 @@ #define _LEVEL_H_ #include <string> +#include "levelFormat.h" +#include "guard.h" +#include "tile.h" class Level { +public: Level(const char* file); //open Level(int popVersion,int LevelNumber); // new diff --git a/PV4/include/outertile.h b/PV4/include/outertile.h index 84ea657..10c9901 100644 --- a/PV4/include/outertile.h +++ b/PV4/include/outertile.h @@ -16,6 +16,7 @@ public: int getDoorEvent(); int getAttr(); int getImg(); + int getCode(); }; diff --git a/PV4/include/pop1tile.h b/PV4/include/pop1tile.h index 7282570..61af780 100644 --- a/PV4/include/pop1tile.h +++ b/PV4/include/pop1tile.h @@ -11,6 +11,7 @@ public: int getDoorEvent(); int getAttr(); int getImg(); + int getCode(); private: int back; diff --git a/PV4/include/pop2tile.h b/PV4/include/pop2tile.h index cee8d7b..db34c18 100644 --- a/PV4/include/pop2tile.h +++ b/PV4/include/pop2tile.h @@ -11,6 +11,7 @@ public: int getDoorEvent(); int getAttr(); int getImg(); + int getCode(); private: int attr; diff --git a/PV4/include/tile.h b/PV4/include/tile.h index ef7ee7d..d2dfbc4 100644 --- a/PV4/include/tile.h +++ b/PV4/include/tile.h @@ -6,13 +6,10 @@ using namespace std; class Tile { // abstract class public: - int getDoorEvent(); - int getAttr(); - int getImg(); - - /* used to serialize self created tiles */ - int getWalls(); - int getBacks(); + virtual int getCode()=0; + virtual int getDoorEvent()=0; + virtual int getAttr()=0; + virtual int getImg()=0; protected: int level; /* this is very important to know what tiles are allowed */ diff --git a/PV4/src/endiansafestream.cpp b/PV4/src/endiansafestream.cpp index 6cae92e..f3f7e4e 100644 --- a/PV4/src/endiansafestream.cpp +++ b/PV4/src/endiansafestream.cpp @@ -34,13 +34,13 @@ void iesstream::read(unsigned long &l){ this->read((char*)&s,2); } - void iesstream::read(unsigned char* c,int size){ - this->read((char*)c,size); - } +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); - } +void iesstream::read(char* c,int size){ + ((ifstream*)this)->read(c,size); +} diff --git a/PV4/src/level.cpp b/PV4/src/level.cpp index 0e865f2..00248c9 100644 --- a/PV4/src/level.cpp +++ b/PV4/src/level.cpp @@ -30,6 +30,7 @@ typedef char* fieldPointer; Level::Level(const char* file) { //open //open the file iesstream stream(file); +cout<<"Opening level "<< file <<endl; //check the magic char magic[7]; @@ -57,13 +58,18 @@ Level::Level(const char* file) { //open stream.read(b1); //level code + unsigned char checksum; + stream.read(checksum); + switch (popVersion) { case 1: +cout<<"is pop1"<<endl; this->level=new Pop1LevelFormat(stream,b1); + break; case 2: // this->level=new Pop2LevelFormat(stream,b1); default: - throw -2; + throw -3; } //user data size @@ -73,6 +79,7 @@ Level::Level(const char* file) { //open //alloc user data (TODO: use integrity checks here) char* ud=new char[b2]; stream.read(ud,b2); +cout<<"nf "<<nf<<endl; //process user data fieldPointer* fields=new fieldPointer[nf*2]; @@ -80,15 +87,21 @@ Level::Level(const char* file) { //open fields[0]=ud; for (int i=0;i<b2&¤tField<nf*2;i++) { - if (!ud[i]) fields[currentField++]=ud+i; + if (!ud[i]) fields[currentField++]=ud+i+1; + } + + for (int i=0;i<nf;i++) { + cout<<"f['"<<fields[i*2]<<"']='"<<fields[i*2+1]<<"'"<<endl; } - if (currentField!=nf*2-1||ud[b2-1]!=0) throw -2; + if (currentField!=nf*2 || ud[b2-1]!=0) throw -2; +cout<<"cf "<<currentField<<" nf "<<nf<<" b2 "<<b2<<endl; //TODO: generate a hash table with this values //remember the file name this->fileName=new string(file); +cout<<"ok"<<endl; //Finally arrange the rooms this->arrangeRooms(); @@ -131,8 +144,8 @@ void Level::arrangeRooms() { Direction junk2; //Fill in the matrix with the rooms - getStartPosition(startScreen,junk,junk2); - linkRecurse(MATRIX_CENTER_X,MATRIX_CENTER_Y,startScreen); + this->level->getStartPosition(startScreen,junk,junk2); + this->linkRecurse(MATRIX_CENTER_X,MATRIX_CENTER_Y,startScreen); //Get the matrix limits for (int i=0;i<MATRIX_HEIGHT;i++) { @@ -164,7 +177,7 @@ void Level::arrangeRooms() { } for (int i=MATRIX_WIDTH;i--;) { - for (int j=0;i<MATRIX_HEIGHT;j++) { + for (int j=0;j<MATRIX_HEIGHT;j++) { if (!matrix(j,i)) { this->ce=i; i=0; diff --git a/PV4/src/main.cpp b/PV4/src/main.cpp index fdd7fd3..331bf29 100644 --- a/PV4/src/main.cpp +++ b/PV4/src/main.cpp @@ -1,11 +1,24 @@ #include <cstdlib> #include <iostream> +#include "level.h" + using namespace std; int main(int argc, char *argv[]) { - cout<<"hello"; - system("PAUSE"); - return EXIT_SUCCESS; + +try { + Level l("lev\\level001.plv"); + + int x,y; + + cout<<"Done"; +} catch (int error) { + cout << "error number "<<error<<endl; +} + +cout<<"bye bye"<<endl; + + } diff --git a/PV4/src/outertile.cpp b/PV4/src/outertile.cpp index b8f4039..6f8895d 100644 --- a/PV4/src/outertile.cpp +++ b/PV4/src/outertile.cpp @@ -15,3 +15,7 @@ int OuterTile::getAttr() { int OuterTile::getImg() { return 0; } + +int OuterTile::getCode() { + return this->code; //TODO: calculate the special codes +} diff --git a/PV4/src/pop1levelformat.cpp b/PV4/src/pop1levelformat.cpp index 3f27340..de589e4 100644 --- a/PV4/src/pop1levelformat.cpp +++ b/PV4/src/pop1levelformat.cpp @@ -105,11 +105,11 @@ Pop1LevelFormat::Pop1LevelFormat(iesstream& stream, int blockSize){ //Read unknown IV (d) this->uIVd=new unsigned char[16]; - stream.read(this->uIVd,24); + stream.read(this->uIVd,16); //Read 0F 09 (2319) this->uV=new unsigned char[2]; - stream.read(this->uV,24); + stream.read(this->uV,2); } @@ -123,10 +123,12 @@ void Pop1LevelFormat::save(ostream* level) { Pop1LevelFormat::~Pop1LevelFormat() { } +/* Map */ + 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(); + this->walls[(screen-1)*30+location]=t->getCode(); + this->backs[(screen-1)*30+location]=t->getAttr(); } Tile* Pop1LevelFormat::getTile(int screen, int location) { @@ -137,6 +139,8 @@ Tile* Pop1LevelFormat::getTile(int screen, int location) { ); } +/* Guards */ + bool Pop1LevelFormat::addGuard(int screen, int location, Guard* g) { if (this->guard_location[screen-1]>29) return false; this->guard_location[screen-1]=location; @@ -166,6 +170,8 @@ Guard* Pop1LevelFormat::getGuards(int screen, int number){ ); } +/* Links */ + 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; @@ -180,25 +186,63 @@ void Pop1LevelFormat::getRoomLink(int screen,int &left,int &right,int &up,int &d down=this->links[(screen-1)*4+3]; } - +/* Start Positions */ 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(); + 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]; +} -*/ +void Pop1LevelFormat::setStartPosition(int screen, int location,Direction direction) { + if (screen<0||screen>24) throw 24; + this->start_position[0]=screen; + if (location>29) throw 24; + this->start_position[1]=location; + this->start_position[2]=(unsigned char)direction; +} + +bool Pop1LevelFormat::getDebugPosition(int &screen, int &location,Direction &direction) {} +bool Pop1LevelFormat::setDebugPosition(int screen, int location,Direction direction) {} +void Pop1LevelFormat::clearDebugPosition() {} + +/* Doors */ + +void Pop1LevelFormat::setDoorEvent(int event, int S,int L, int T) { + unsigned char* b1=&this->doorI[event]; + unsigned char* b2=&this->doorII[event]; + + /* + Let's define: + Screen as S and it is a number from 1 to 24 (5 bits) + S = s1 s2 s3 s4 s5 + where sn is the bit n of the binary representation of S + Location as L and is a number from 0 to 29 (5 bits) + L = l1 l2 l3 l4 l5 + where ln is the bit n of the binary representation of L + This number is according to the location format specifications. + Trigger-next as T and is a 1 for "on" or a 0 for "off" (1 bit) + T = t1 + + Byte I has the form: t1 s4 s5 l1 l2 l3 l4 l5 + Byte II has the form: s1 s2 s3 0 0 0 0 0 + */ + + *b1=(T?1:0)<<7|((S&3)<<5)|L; + *b2=(S&0x1C)<<5; + +} + +void Pop1LevelFormat::getDoorEvent(int event, int &S,int &L, int &T) { + unsigned char b1=this->doorI[event]; + unsigned char b2=this->doorII[event]; + + T=b1>>7; + L=b1&0x1f; + S=((b1>>5)&3)|b2>>3; + +} diff --git a/PV4/src/pop1tile.cpp b/PV4/src/pop1tile.cpp index ec452d3..a16e16b 100644 --- a/PV4/src/pop1tile.cpp +++ b/PV4/src/pop1tile.cpp @@ -16,3 +16,7 @@ int Pop1Tile::getAttr() { int Pop1Tile::getImg() { return 0; } + +int Pop1Tile::getCode() { + return this->code; +} diff --git a/PV4/src/pop2tile.cpp b/PV4/src/pop2tile.cpp index f86b504..a64e24e 100644 --- a/PV4/src/pop2tile.cpp +++ b/PV4/src/pop2tile.cpp @@ -18,3 +18,7 @@ int Pop2Tile::getAttr() { int Pop2Tile::getImg() { return this->img; } + +int Pop2Tile::getCode() { + return this->code; +}