Original Post
I just cant seem to get this to work, ive been looking at it for a while and I'm not sure what the problem is. Here is what the map file looks like:
I think the problem might have to do with my manipulation of strings, especially the use of substr(), but im not sure. Sorry just to dump code, but im really having difficulty figuring this out, ive been scanning through it for quite a while now and im just note sure what the problem is.
[edited by - laroche on December 20, 2002 8:48:26 PM]
nick
C:\Nick\Projects\HSLevelEditor\Debug\TileSet.bmp
5
5
C:\Nick\Projects\HSLevelEditor\Debug\Desc.txt
C:\Nick\Projects\HSLevelEditor\Debug\Psy.txt
C:\Nick\Projects\HSLevelEditor\Debug\Mob.txt
25
0:0,1:1,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:0,16:0,17:0,18:0,19:0,20:0,21:0,22:0,23:0,24:0,1:24,0:24,E,
and this is the level loading code
CMap * Load(char* Filename, CTileset *pTileset) // Uses RLE Compression
{
using namespace std;
CMap * Temp;
string Title;
string TilesetPath;
string Height, Width, D, P, M, TS, buf;
int W, H, TilesetSize;
CTile * Struct;
int * StateMap;
int * TileIDMap;
ifstream File;
File.open(Filename, ios::in);
Title = GetNextWord(File, '\n');
TilesetPath = GetNextWord(File, '\n');
Width = GetNextWord(File, '\n');
Height = GetNextWord(File, '\n');
D = GetNextWord(File, '\n');
P = GetNextWord(File, '\n');
M = GetNextWord(File, '\n');
TS = GetNextWord(File, '\n');
MessageBox(NULL, TS.c_str(), TS.c_str(), MB_OK);
TilesetSize = atoi(TS.c_str());
W = atoi(Width.c_str());
H = atoi(Height.c_str());
StateMap = new int[TilesetSize];
TileIDMap = new int[TilesetSize];
for (int h = 0; h < TilesetSize; ++h)
{
TileIDMap[h] = h;
}
for (int q = 0; q < TilesetSize; ++q)
{
StateMap[q] = 0;
}
//////////// START OF TILE-STATE LOADING CODE ///////////
// Set All Effects for the tiles
for (int m = 0; m < TilesetSize; ++m)
{
buf = GetNextWord(File, ',');
int Ps = buf.find(':',0);
if (Ps != std::string::npos)
{
int Test, Pest;
std::string before, after;
before = buf.substr(Ps);
after = buf.substr(0, Ps);
Test = atoi(before.c_str());
Pest = atoi(after.c_str());
StateMap[Test] = Pest;
}
}
////////////END OF TILE-STATE LOADING CODE ///////////
if (pMap)
{
delete pMap;
pMap = NULL;
MapExist = FALSE;
}
if (pTileset)
{
delete pTileset;
pTileset = NULL;
TilesetExist = FALSE;
}
Temp = new CMap(W, H, Title.c_str());
Temp->SetDescription(D);
Temp->SetMob(M);
Temp->SetPhysics(P);
Struct = new CTile[W * H * 2];
int * Effect = new int[TilesetSize];
string Buf, buft;
int Size = W*H*2;
bool HandleReps = FALSE;
int Rep = 0;
//////////// START OF TILE LOADING CODE ///////////
// decompress with RLE , set it to temporary structure
for (int X = 0; X < Size; ++X)
{
if (!HandleReps)
{
Buf = GetNextWord(File, ',');
}
int test = Buf.find('E',0);
if (test != std::string::npos)
{
// End of File, E is terminating Char.
break;
}
int Pos = Buf.find(':',0);
if (Pos != std::string::npos)
{
buft = Buf.substr(0, Pos);
int ID = atoi(buft.c_str());
buft = Buf.substr(Pos);
if (!HandleReps)
{
Rep = atoi(buft.c_str());
}
CTile t;
t.TileID = ID;
t.Layer = 1;
if (X > W*H)
t.Layer = 2;
Struct[X] = t;
Rep--;
HandleReps = TRUE;
if (Rep < 0)
{
HandleReps = FALSE;
Rep = 0;
}
continue;
}
if (Pos == std::string::npos)
{
CTile Goo;
Goo.TileID = atoi(Buf.c_str());
Goo.Layer = 1;
if (X > W*H)
Goo.Layer = 2;
Struct[X] = Goo;
}
}
//////////// END OF TILE LOADING CODE ///////////
// Copy temp structure to real class
for (int i = 0; i < Size; ++i)
{
Temp->SetTile(i, Struct[i]);
}
//Set the effects for the tiles
for (int l = 0; l < TilesetSize; ++l)
{
Temp->SetTileEffect(TileIDMap[l], StateMap[l]);
}
delete [] Struct;
delete [] StateMap;
delete [] TileIDMap;
File.close();
return Temp;
}