Ok, I'm about to post a big honky piece of code in here. This thing has boggled me for 3 days now. The idea is to read from a Map file (100X100) and print out a 12X32 map each time "Printmap()" is called....here it is.
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "handler.h"
#include "db.h"
#include "spells.h"
#include "screen.h"
#include "maputils.h"
extern struct room_data *world;
char mainmap[99][99];
char mapchar;
void printmap(int rnum, struct char_data * ch) {
int x=0;
int y=0;
int tx = 0;
int ty = 0;
int xcord = 0;
int ycord = 0;
FILE *fopen(), *mfile;
int letter;
int loop;
char buf[512];
char colorof[50];
ty = (rnum / 100);
tx = (rnum % 100);
xcord = tx;
ycord = ty;
ty = (ty - 6);
tx = (tx - 17);
if(ty < 0)
{
ty = (ty + 100);
}
if(ty > 99)
{
ty = (ty - 100);
}
if(tx < 0)
{
tx = (tx + 100);
}
if(tx > 99)
{
tx = (tx - 100);
}
strcpy(buf, "\r\n "
;
ty = 1;
tx = 1;
for (y = (ycord - 6); y <= (ycord + 5); y++) {
for (x = (xcord - 16); x <= (xcord + 15); x++) {
if (x==xcord && y==ycord) {
sprintf(colorof, "%s", CCGRN(ch, C_NRM));
strcat(buf, colorof);
strcat(buf, "@"
;
sprintf(colorof, "%s", CCNRM(ch, C_NRM));
strcat(buf, colorof);
} else {
if( ((x - 1) % 100) == 99)
{
tx = (x - 100);
} else {
tx = x;
}
if( ((y - 1) % 100) == 99)
{
ty = (y - 100);
} else {
ty = y;
}
if (world[( (ty * 100) + tx)].people) {
if (IS_NPC(world[( (ty * 100) + tx)].people)) {
sprintf(colorof, "%s", CCRED(ch, C_NRM));
strcat(buf, colorof);
strcat(buf, "*"
;
sprintf(colorof, "%s", CCNRM(ch, C_NRM));
strcat(buf, colorof);
} else {
sprintf(colorof, "%s", CCBLU(ch, C_NRM));
strcat(buf, colorof);
strcat(buf, "*"
;
sprintf(colorof, "%s", CCNRM(ch, C_NRM));
strcat(buf, colorof);
}
} else {
loop = 0;
if ( (mfile = fopen("earth", "rt"
) == NULL)
{
log("file doesn't exist?"
;
}
while (!feof(mfile))
{
loop++;
letter = fgetc(mfile);
if (loop == ( (ty * 100) + tx) )
{
mapchar = letter;
}
}
if (mapchar != NULL)
{
strcat(buf, &mapchar);
} else {
mapchar = '.';
strcat(buf, &mapchar);
}
fclose(mfile);
}
}
}
strcat(buf, "\r\n "
;
}
strcat(buf, "\r\n"
;
strcat(buf, "TESTING\r\n\r\n"
;
send_to_char(buf, ch);
}
yes, it's extreamly sloppy, because i've been tearing it apart and rebuilding it numorous times....I've pinpointed that it's just not reading from the file...it opens it fine, and if you see where it says "If (mapchar == NULL) mapchar = '.'"...I end up getting a 12x32 map of .'s, so obviously, mapchar's not reading anything, and it has nothing to do with the loop, because i've tried reading even individual lines or characters one at a time from the file, and no luck. It's being compiled on a UNIX BSD server, and it's not stand alone, obviously. It's part of a MUD for those of you that know what that is
. Any help would be appriciated.
Thanks,
Rob
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "handler.h"
#include "db.h"
#include "spells.h"
#include "screen.h"
#include "maputils.h"
extern struct room_data *world;
char mainmap[99][99];
char mapchar;
void printmap(int rnum, struct char_data * ch) {
int x=0;
int y=0;
int tx = 0;
int ty = 0;
int xcord = 0;
int ycord = 0;
FILE *fopen(), *mfile;
int letter;
int loop;
char buf[512];
char colorof[50];
ty = (rnum / 100);
tx = (rnum % 100);
xcord = tx;
ycord = ty;
ty = (ty - 6);
tx = (tx - 17);
if(ty < 0)
{
ty = (ty + 100);
}
if(ty > 99)
{
ty = (ty - 100);
}
if(tx < 0)
{
tx = (tx + 100);
}
if(tx > 99)
{
tx = (tx - 100);
}
strcpy(buf, "\r\n "
ty = 1;
tx = 1;
for (y = (ycord - 6); y <= (ycord + 5); y++) {
for (x = (xcord - 16); x <= (xcord + 15); x++) {
if (x==xcord && y==ycord) {
sprintf(colorof, "%s", CCGRN(ch, C_NRM));
strcat(buf, colorof);
strcat(buf, "@"
sprintf(colorof, "%s", CCNRM(ch, C_NRM));
strcat(buf, colorof);
} else {
if( ((x - 1) % 100) == 99)
{
tx = (x - 100);
} else {
tx = x;
}
if( ((y - 1) % 100) == 99)
{
ty = (y - 100);
} else {
ty = y;
}
if (world[( (ty * 100) + tx)].people) {
if (IS_NPC(world[( (ty * 100) + tx)].people)) {
sprintf(colorof, "%s", CCRED(ch, C_NRM));
strcat(buf, colorof);
strcat(buf, "*"
sprintf(colorof, "%s", CCNRM(ch, C_NRM));
strcat(buf, colorof);
} else {
sprintf(colorof, "%s", CCBLU(ch, C_NRM));
strcat(buf, colorof);
strcat(buf, "*"
sprintf(colorof, "%s", CCNRM(ch, C_NRM));
strcat(buf, colorof);
}
} else {
loop = 0;
if ( (mfile = fopen("earth", "rt"
{
log("file doesn't exist?"
}
while (!feof(mfile))
{
loop++;
letter = fgetc(mfile);
if (loop == ( (ty * 100) + tx) )
{
mapchar = letter;
}
}
if (mapchar != NULL)
{
strcat(buf, &mapchar);
} else {
mapchar = '.';
strcat(buf, &mapchar);
}
fclose(mfile);
}
}
}
strcat(buf, "\r\n "
}
strcat(buf, "\r\n"
strcat(buf, "TESTING\r\n\r\n"
send_to_char(buf, ch);
}
yes, it's extreamly sloppy, because i've been tearing it apart and rebuilding it numorous times....I've pinpointed that it's just not reading from the file...it opens it fine, and if you see where it says "If (mapchar == NULL) mapchar = '.'"...I end up getting a 12x32 map of .'s, so obviously, mapchar's not reading anything, and it has nothing to do with the loop, because i've tried reading even individual lines or characters one at a time from the file, and no luck. It's being compiled on a UNIX BSD server, and it's not stand alone, obviously. It's part of a MUD for those of you that know what that is
Thanks,
Rob