Hello. I'm working on a MUD from scratch and we're designing the world map now. The map will be a csv file. I've got the csv parsing done. I don't think there are any issues in it, I can use a simple if to display it all fine, but please let me know if you do see any issues or improvements.
void LoadMap ()
int col = 0;
int row = 0;
string tile; // each actual value
string line; // to grab
stringstream linestream; //to manipulate further
while (getline(worldfile, line, ' ')) //Read each line, ends with nothing
linestream << line;
while (getline(linestream, tile, ',')) //read the stream, seperate tiles inbetween commas
worldmap[row][col] = tile;
col++; //next item after a comma
col = 0;
The real problem I'm having is when displaying the worldmap. It is not behavior properly. worldmap is 20x20, loaded into the string array above. to display I want to only display a section of it, in this case anything 5 less than and 6 more than (to center the player at all times). However when moving and looking, the 1st line is several characters off, and the code doesn't seem to be spacing out the left side correctly to center the player on the map. y centering seems okay, but X seems off. Currently player resides at 0x,0y (which in the game highlights his square red).
As you can see, the spaces in the first line mess up the alignment. Also after geting to 6x or more, the code looses the spacing between lines, and after you get to 16 is does an odd line wrap and draws incorrect data.
My initial hunch would make me dump the hex data in worldmap in a debugger.
I'm guessing some newlines are being stored in the array?
I thought about that too, but when i remove the relativity bit of the code
1 2 3
for (int i = (p->y - 6); i < (p->y + 6); i++)
for (int j = (p->x - 6); j < (p->x + 6); j++)
and just iterate 0 to 19 and write out the entire map it all seems to display fine. I don't get why iterating around the player's point rather than 0 to 19 would affect it displaying linebreaks and such.
1 2 3
for (int i = 0; i <= 19; i++)
for (int j = 0; j <= 19; j++)
EDIT: Strange. I pulled the code out, rewrote it and now its working. I'll have to run a diff on it to see what might have been typo'd or something..