static int MAP_readMapOne(char *filename, char *no_exit) { FILE *f; char buf[16]; short data[1024]; int ret; int i; int mapindex; int id = 0, xsiz = 0, ysiz = 0; short *tile = NULL; short *obj = NULL; MAP_Objlink **olink = NULL; char showstring[32]; struct stat filestat; int invaliddata = FALSE; if(MAP_mapnum_index >= MAP_mapnum) { fprint("这里没有足够空间装载地图数组.\n"); return FALSE; } mapindex = MAP_mapnum_index; f = fopen(filename, "r"); if(f == NULL) { return FALSE; } if(fstat(fileno(f), &filestat) != 0) { goto FCLOSERETURNFALSE; } ret = fread(buf, sizeof(char), 6, f); if(ret != 6) { goto FCLOSERETURNFALSE; } buf[ret] = '\0'; if(strcmp(buf, MAP_MAGIC) != 0) goto FCLOSERETURNFALSE; ret = fread(data, sizeof(short), 1, f); if(ret != 1) { goto FCLOSERETURNFALSE; } id = ntohs(data[0]); ret = fread(showstring, sizeof(char), arraysizeof(showstring), f); if(ret != arraysizeof(showstring)) { goto FCLOSERETURNFALSE; } showstring[arraysizeof(showstring) - 1] = '\0'; ret = fread(data, sizeof(short), 1, f); if(ret != 1) { goto FCLOSERETURNFALSE; } xsiz = ntohs(data[0]); ret = fread(data, sizeof(short), 1, f); if(ret != 1) { goto FCLOSERETURNFALSE; } ysiz = ntohs(data[0]); tile = allocateMemory(sizeof(short) * xsiz * ysiz); if(tile == NULL) { fprint("无法分配内存给地图名称:%s xsiz:%d ysiz:%d\n", filename, xsiz, ysiz); goto FREEOBJHP; } obj = allocateMemory(sizeof(short) * xsiz * ysiz); if(obj == NULL) { fprint("无法分配内存给对象\n"); goto FREETILE; } olink = allocateMemory(sizeof(MAP_Objlink *) * xsiz * ysiz); if(olink == NULL) { fprint("无法分配内存给链接\n"); goto FREEOBJ; } ret = fread(tile, sizeof(short) * xsiz * ysiz, 1, f); if(ret != 1) { goto FREELINK; } // for( i = 0 ; i < xsiz * ysiz ; i ++ ) // tile[i] = ntohs( tile[i] ); for(i = 0; i < xsiz * ysiz; i++) { tile[i] = ntohs(tile[i]); if(!IsValidImagenumber(tile[i])) { fprint("地图的图片有问题:%d x:%d y:%d 数量:%d\n", id, i % xsiz, (int) (i / xsiz), tile[i]); invaliddata = TRUE; } } ret = fread(obj, sizeof(short) * xsiz * ysiz, 1, f); if(ret != 1) { goto FREELINK; } // for( i = 0 ; i < xsiz * ysiz ; i ++ ) // obj[i] = ntohs( obj[i] ); for(i = 0; i < xsiz * ysiz; i++) { obj[i] = ntohs(obj[i]); if(!IsValidImagenumber(obj[i])) { fprint( "地图的图片有问题:%d x:%d y:%d 数量:%d\n", id, i % xsiz, (int) (i / xsiz), obj[i]); invaliddata = TRUE; } } if(invaliddata) goto FREELINK; for(i = 0; i < xsiz * ysiz; i++) olink[i] = NULL; MAP_map[mapindex].id = id; MAP_map[mapindex].xsiz = xsiz; MAP_map[mapindex].ysiz = ysiz; strcpysafe(MAP_map[mapindex].string, sizeof(MAP_map[mapindex].string), showstring); MAP_map[mapindex].tile = tile; MAP_map[mapindex].obj = obj; MAP_map[mapindex].olink = olink; #ifdef _MAP_NOEXIT { FILE *fp; char mpexit[128]; int floorID = 0, exfloor = 0, ex_X = 0, ex_Y = 0; int map_type = 0; MAP_map[mapindex].startpoint = 0; fp = fopen(no_exit, "r"); if(fp != NULL) { while(fgets(mpexit, 128, fp) != NULL) { sscanf(mpexit, "%d %d %d %d %d", &floorID, &exfloor, &ex_X, &ex_Y, &map_type); if(strstr(mpexit, "#") != NULL) continue; if(floorID == id) { MAP_map[mapindex].startpoint = (exfloor << 16) + (ex_X << 8) + (ex_Y << 0); MAP_map[mapindex].MapType = map_type; } } fclose(fp); } else { print("\n **错误** 找不到 map_noexit.txt 文件!!!"); } } #endif goto FCLOSERETURNTRUE; FCLOSERETURNTRUE: MAP_mapnum_index++; fclose(f); return TRUE; FREELINK: freeMemory(olink); FREEOBJ: freeMemory(obj); FREETILE: freeMemory(tile); FREEOBJHP: FCLOSERETURNFALSE: fclose(f); return FALSE; }
int MAP_readBattleMapConfFile(char *filename) { FILE *file; char line[512]; int i, j; int linenum = 0; int BattleMapNo[3], iRet, iWork, iPre[3], iFirst, iLast; file = fopen(filename, "r"); if(file == NULL) { fprint("无法打开 %s\n", filename); return FALSE; } BattleMapNo[0] = 0; BattleMapNo[1] = 0; BattleMapNo[2] = 0; while(fgets(line, sizeof(line), file)) { char *p; linenum++; pohcd(line, " \t"); dchop(line, " \t"); if(line[0] == '#')continue; if(line[0] == '\n')continue; chomp(line); if(line[0] == '$') { iRet = sscanf(line + 1, "%d %d %d", &iPre[0], &iPre[1], &iPre[2]); BattleMapNo[0] = BattleMapNo[1] = BattleMapNo[2] = iPre[0]; if(iRet < 1) { print("!!!!!错误 无法读取战斗地图(%s)( line %d )\n", filename, linenum); } for(i = 0; i < iRet; i++) { BattleMapNo[i] = iPre[i]; if(BattleMapNo[i] < 0) { print("!!!!!错误 战斗地图号码为负值 (%s)( line %d )\n", filename, linenum); } } continue; } if(sscanf(line, "%d", &iWork) != 1) { continue; } if(iWork < 0) { print("!!!!!错误 金钱号码为负值 (%s)( line %d )\n", filename, linenum); continue; } iFirst = iWork; p = strstr(line, "to"); if(p != NULL) { if(sscanf(p + 2, "%d", &iWork) != 1) { iLast = iFirst; } else { iLast = iWork; } if(iWork < 0) { print("!!!!!错误 金钱号码为负值 (%s)( line %d )\n", filename, linenum); continue; } } else { iLast = iFirst; } for(i = iFirst; i <= iLast; i++) { if(MAP_getImageInt(i, MAP_SETED_BATTLEMAP) > 0) { print("!!!!!错误 相同金钱重复设定了两次(%s)( line %d )(%d)(%d & %d)\n", filename, linenum, i, MAP_getImageInt(i, MAP_BATTLEMAP), BattleMapNo[0]); } if(IsValidImagenumber(i) == FALSE) { continue; } MAP_setImageInt(i, MAP_BATTLEMAP, BattleMapNo[0]); MAP_setImageInt(i, MAP_BATTLEMAP2, BattleMapNo[1]); MAP_setImageInt(i, MAP_BATTLEMAP3, BattleMapNo[2]); MAP_setImageInt(i, MAP_SETED_BATTLEMAP, 1); } } fclose(file); for(j = 0; j < arraysizeof(MAP_imgfilt); j++) { if(MAP_imgfilt[j] == -1)continue; if(MAP_getImageInt(j, MAP_SETED_BATTLEMAP) == 0) { print("!!!!!错误 金钱(%d)尚未设定 (%s)\n", j, filename); } } return TRUE; }
BOOL MAP_readBattleMapConfFile( char* filename ) { FILE* file; char line[512]; int i, j; int linenum=0; int BattleMapNo[3], iRet, iWork, iPre[3],iFirst, iLast; file = fopen( filename , "r" ); if( file == NULL ){ fprint( "Can't open %s\n", filename ); return FALSE; } BattleMapNo[0] = 0; BattleMapNo[1] = 0; BattleMapNo[2] = 0; while( fgets( line , sizeof( line ) , file ) ){ char *p; linenum++; pohcd( line, " \t" ); dchop(line, " \t"); if( line[0] == '#' )continue; if( line[0] == '\n' )continue; chomp( line ); if( line[0] == '$' ){ iRet = sscanf( line+1, "%d %d %d", &iPre[0], &iPre[1], &iPre[2] ); BattleMapNo[0] = BattleMapNo[1] = BattleMapNo[2] = iPre[0]; if( iRet < 1 ){ print( "!!!!!ERROR µLªkŪ¨ú¾Ô°«¦a¹Ï(%s)( line %d )\n", filename, linenum ); } for( i = 0; i < iRet; i ++ ){ BattleMapNo[i] = iPre[i]; if( BattleMapNo[i] < 0 ){ print( "!!!!!ERROR ¾Ô°«¦a¹Ï¸¹½X¬°tÈ (%s)( line %d )\n", filename, linenum ); } } continue; } if( sscanf( line, "%d", &iWork ) != 1 ){ continue; } if( iWork < 0 ){ print( "!!!!!ERROR ª÷¿ú¸¹½X¬°tÈ (%s)( line %d )\n", filename, linenum ); continue; } iFirst = iWork; p = strstr( line, "to" ); if( p != NULL ){ if( sscanf( p+2, "%d", &iWork ) != 1 ){ iLast = iFirst; }else{ iLast = iWork; } if( iWork < 0 ){ print( "!!!!!ERROR ª÷¿ú¸¹½X¬°tÈ (%s)( line %d )\n", filename, linenum ); continue; } }else{ iLast = iFirst; } for( i = iFirst; i <= iLast; i ++ ){ if( MAP_getImageInt( i, MAP_SETED_BATTLEMAP ) > 0 ){ print( "!!!!!Warning ¬Û¦Pª÷¿ú«½Æ³]©w¤F¨â¦¸(%s)( line %d )(%d)(%d & %d)\n", filename, linenum, i, MAP_getImageInt( i, MAP_BATTLEMAP ), BattleMapNo[0] ); } // Áü ¹æÀµ¤·¤¤¤«¡ª if( IsValidImagenumber( i ) == FALSE ){ continue; } MAP_setImageInt( i, MAP_BATTLEMAP, BattleMapNo[0] ); MAP_setImageInt( i, MAP_BATTLEMAP2, BattleMapNo[1] ); MAP_setImageInt( i, MAP_BATTLEMAP3, BattleMapNo[2] ); MAP_setImageInt( i, MAP_SETED_BATTLEMAP, 1 ); } } fclose( file ); for( j = 0; j < arraysizeof( MAP_imgfilt ); j ++ ){ if( MAP_imgfilt[j] == -1 )continue; if( MAP_getImageInt( j, MAP_SETED_BATTLEMAP ) == 0 ){ print( "!!!!!Error ª÷¿ú(%d)©|¥¼³]©w (%s)\n", j, filename ); } } return TRUE; }
static BOOL MAP_readMapOne( char* filename ) { FILE* f; /* ¥Õ¥¡¥¤¥ë */ char buf[16]; /* ¥Þ¥¸¥Ã¥¯¥Ê¥ó¥Ð¡¼ ¤ßÍÑ */ short data[1024]; /* ¼³¥ç¡¼¥È ¤ßÍѥХåե¡ */ int ret; /* ÊÖ¤êÃͼõ¤±¼è¤êÍÑ */ int i; /* ¥ë¡¼¥× ¿ô */ int mapindex; int id=0,xsiz=0,ysiz=0; /* ¥Þ¥Ã¥×¥Ç¡¼¥¿¤Î°ì»þ³Ê ¾ì½ê */ short *tile=NULL; short *obj=NULL; MAP_Objlink** olink=NULL; char showstring[32]; /* ¥Þ¥Ã¥×¥Ç¡¼¥¿¤Î°ì»þ³Ê ¾ì½ê */ struct stat filestat; /* ¥Á¥§¥Ã¥¯ÍѤ˻Ȥ¦ */ BOOL invaliddata=FALSE; if( MAP_mapnum_index >= MAP_mapnum ){ fprint( "There is no space left on MapArray.\n" ); return FALSE; } mapindex=MAP_mapnum_index; f = fopen(filename, "r"); if( f == NULL ){ errorprint; return FALSE; } if( fstat( fileno(f) , &filestat ) != 0 ){ errorprint; goto FCLOSERETURNFALSE; } ret = fread( buf , sizeof( char ) , 6 , f); if( ret != 6 ){ errorprint; goto FCLOSERETURNFALSE; } buf[ret] = '\0'; if( strcmp( buf , MAP_MAGIC ) != 0 ) goto FCLOSERETURNFALSE; ret = fread( data , sizeof( short ) , 1 , f); if( ret != 1 ){ errorprint; goto FCLOSERETURNFALSE; } id = ntohs( data[0] ); ret = fread( showstring , sizeof(char), arraysizeof(showstring), f); if( ret != arraysizeof(showstring) ){ errorprint; goto FCLOSERETURNFALSE; } showstring[arraysizeof(showstring)-1] = '\0'; ret = fread( data, sizeof( short ) , 1 , f); if( ret != 1 ){ errorprint; goto FCLOSERETURNFALSE; } xsiz = ntohs( data[0] ); ret = fread( data, sizeof( short ) , 1 , f); if( ret != 1 ){ errorprint; goto FCLOSERETURNFALSE; } ysiz = ntohs( data[0] ); tile = allocateMemory( sizeof( short ) * xsiz * ysiz ); if( tile == NULL ){ fprint( "Can't Allocate Memory for tile name:%s xsiz:%d ysiz:%d\n", filename, xsiz, ysiz); goto FREEOBJHP; } obj = allocateMemory( sizeof( short ) * xsiz * ysiz ); if( obj == NULL ){ fprint( "Can't Allocate Memory for object\n"); goto FREETILE; } olink = allocateMemory( sizeof(MAP_Objlink*) * xsiz * ysiz ); if( olink == NULL ){ fprint( "Can't Allocate Memory for link\n"); goto FREEOBJ; } ret = fread( tile , sizeof( short )*xsiz*ysiz,1,f ); if( ret != 1 ){ errorprint; goto FREELINK; } for( i = 0 ; i < xsiz * ysiz ; i ++ ) tile[i] = ntohs( tile[i] ); for( i = 0 ; i < xsiz * ysiz ; i ++ ){ if( !IsValidImagenumber( tile[i] ) ){ fprint( "Invalid tile imagenumber floor:%d x:%d y:%d number:%d\n", id, i % xsiz, (int)(i / xsiz) , tile[i]); invaliddata = TRUE; } } ret = fread( obj , sizeof( short )*xsiz*ysiz,1,f ); if( ret != 1 ){ errorprint; goto FREELINK; } for( i = 0 ; i < xsiz * ysiz ; i ++ ) obj[i] = ntohs( obj[i] ); for( i = 0 ; i < xsiz * ysiz ; i ++ ){ if( !IsValidImagenumber( obj[i] ) ){ fprint( "Invalid obj imagenumber floor:%d x:%d y:%d number:%d\n", id, i % xsiz, (int)(i / xsiz) , obj[i]); invaliddata = TRUE; } } if( invaliddata )goto FREELINK; if( ftell(f) != filestat.st_size) fprintf(stderr,"size of file(%s) is strange. realsize:%" #ifdef linux "l" #elif __FreeBSD__ "ll" #endif "d readsize:%ld\n", filename, filestat.st_size,ftell(f)); for( i=0 ; i< xsiz*ysiz ; i ++ ) olink[i] = NULL; MAP_map[mapindex].id = id; MAP_map[mapindex].xsiz = xsiz; MAP_map[mapindex].ysiz = ysiz; strcpysafe( MAP_map[mapindex].string , sizeof(MAP_map[mapindex].string), showstring ); MAP_map[mapindex].tile = tile; MAP_map[mapindex].obj = obj; MAP_map[mapindex].olink = olink; #ifdef _MAP_NOEXIT { FILE *fp; char mpexit[128]; int floorID=0,exfloor=0,ex_X=0,ex_Y=0; int map_type=0; MAP_map[mapindex].startpoint = 0; fp = fopen( "./data/map/map_noexit.txt","r"); if( fp != NULL ){ while( fgets(mpexit, 128, fp) != NULL ) { sscanf( mpexit,"%d %d %d %d %d", &floorID, &exfloor, &ex_X, &ex_Y, &map_type); if( strstr( mpexit, "#" ) != NULL) continue; if( floorID == id) { MAP_map[mapindex].startpoint = (exfloor<<16)+(ex_X << 8)+(ex_Y<<0); MAP_map[mapindex].MapType = map_type; } } // Nuke 1204: Bug fix fclose(fp); }else { print("\n **ERROR** Can not find map_noexit.txt !!!"); } } #endif goto FCLOSERETURNTRUE; FCLOSERETURNTRUE: MAP_mapnum_index++; fclose(f); return TRUE; FREELINK: freeMemory( olink ); FREEOBJ: freeMemory( obj ); FREETILE: freeMemory( tile ); FREEOBJHP: FCLOSERETURNFALSE: fclose(f); return FALSE; }
static BOOL MAP_readMapOne( char* filename ) { FILE* f; /* 白央奶伙 */ char buf[16]; /* 穴斥永弁瓜件田□ 心迕 */ short data[1024]; /* 扑亦□玄 心迕田永白央 */ int ret; /* 忒曰袄熬仃潸曰迕 */ int i; /* 伙□皿 醒 */ int mapindex; int id=0,xsiz=0,ysiz=0; /* 穴永皿犯□正及域凛伞 桦赭 */ short *tile=NULL; short *obj=NULL; MAP_Objlink** olink=NULL; char showstring[32]; /* 穴永皿犯□正及域凛伞 桦赭 */ struct stat filestat; /* 民尼永弁迕卞银丹 */ BOOL invaliddata=FALSE; if( MAP_mapnum_index >= MAP_mapnum ){ fprint( "这里没有足够空间装载地图数组.\n" ); return FALSE; } mapindex=MAP_mapnum_index; f = fopen(filename, "r"); if( f == NULL ){ errorprint; return FALSE; } if( fstat( fileno(f) , &filestat ) != 0 ){ errorprint; goto FCLOSERETURNFALSE; } ret = fread( buf , sizeof( char ) , 6 , f); if( ret != 6 ){ errorprint; goto FCLOSERETURNFALSE; } buf[ret] = '\0'; if( strcmp( buf , MAP_MAGIC ) != 0 ) goto FCLOSERETURNFALSE; ret = fread( data , sizeof( short ) , 1 , f); if( ret != 1 ){ errorprint; goto FCLOSERETURNFALSE; } id = ntohs( data[0] ); ret = fread( showstring , sizeof(char), arraysizeof(showstring), f); if( ret != arraysizeof(showstring) ){ errorprint; goto FCLOSERETURNFALSE; } showstring[arraysizeof(showstring)-1] = '\0'; ret = fread( data, sizeof( short ) , 1 , f); if( ret != 1 ){ errorprint; goto FCLOSERETURNFALSE; } xsiz = ntohs( data[0] ); ret = fread( data, sizeof( short ) , 1 , f); if( ret != 1 ){ errorprint; goto FCLOSERETURNFALSE; } ysiz = ntohs( data[0] ); tile = allocateMemory( sizeof( short ) * xsiz * ysiz ); if( tile == NULL ){ fprint( "无法分配内存给地图名称:%s xsiz:%d ysiz:%d\n", filename, xsiz, ysiz); goto FREEOBJHP; } obj = allocateMemory( sizeof( short ) * xsiz * ysiz ); if( obj == NULL ){ fprint( "无法分配内存给对象\n"); goto FREETILE; } olink = allocateMemory( sizeof(MAP_Objlink*) * xsiz * ysiz ); if( olink == NULL ){ fprint( "无法分配内存给链接\n"); goto FREEOBJ; } ret = fread( tile , sizeof( short )*xsiz*ysiz,1,f ); if( ret != 1 ){ errorprint; goto FREELINK; } // for( i = 0 ; i < xsiz * ysiz ; i ++ ) // tile[i] = ntohs( tile[i] ); for( i = 0 ; i < xsiz * ysiz ; i ++ ){ tile[i] = ntohs( tile[i] ); if( !IsValidImagenumber( tile[i] ) ){ fprint("地图的图片有问题:%d x:%d y:%d 数量:%d\n", id, i % xsiz, (int)(i / xsiz) , tile[i]); invaliddata = TRUE; } } ret = fread( obj , sizeof( short )*xsiz*ysiz,1,f ); if( ret != 1 ){ errorprint; goto FREELINK; } // for( i = 0 ; i < xsiz * ysiz ; i ++ ) // obj[i] = ntohs( obj[i] ); for( i = 0 ; i < xsiz * ysiz ; i ++ ){ obj[i] = ntohs( obj[i] ); if( !IsValidImagenumber( obj[i] ) ){ fprint( "地图的图片有问题:%d x:%d y:%d 数量:%d\n", id, i % xsiz, (int)(i / xsiz) , obj[i]); invaliddata = TRUE; } } if( invaliddata )goto FREELINK; /* if( ftell(f) != filestat.st_size) fprintf(stderr,"文件大小不正确(%s). 目标文件大小:%" #ifdef linux "l" #elif __FreeBSD__ "ll" #endif "d 实际大小:%ld\n", filename, filestat.st_size,ftell(f)); */ for( i=0 ; i< xsiz*ysiz ; i ++ ) olink[i] = NULL; MAP_map[mapindex].id = id; MAP_map[mapindex].xsiz = xsiz; MAP_map[mapindex].ysiz = ysiz; strcpysafe( MAP_map[mapindex].string , sizeof(MAP_map[mapindex].string), showstring ); MAP_map[mapindex].tile = tile; MAP_map[mapindex].obj = obj; MAP_map[mapindex].olink = olink; #ifdef _MAP_NOEXIT { FILE *fp; char mpexit[128]; int floorID=0,exfloor=0,ex_X=0,ex_Y=0; int map_type=0; MAP_map[mapindex].startpoint = 0; fp = fopen( "./data/map/map_noexit.txt","r"); if( fp != NULL ){ while( fgets(mpexit, 128, fp) != NULL ) { sscanf( mpexit,"%d %d %d %d %d", &floorID, &exfloor, &ex_X, &ex_Y, &map_type); if( strstr( mpexit, "#" ) != NULL) continue; if( floorID == id) { MAP_map[mapindex].startpoint = (exfloor<<16)+(ex_X << 8)+(ex_Y<<0); MAP_map[mapindex].MapType = map_type; } } // Nuke 1204: Bug fix fclose(fp); }else { print("\n **错误** 找不到 map_noexit.txt 文件!!!"); } } #endif goto FCLOSERETURNTRUE; FCLOSERETURNTRUE: MAP_mapnum_index++; fclose(f); return TRUE; FREELINK: freeMemory( olink ); FREEOBJ: freeMemory( obj ); FREETILE: freeMemory( tile ); FREEOBJHP: FCLOSERETURNFALSE: fclose(f); return FALSE; }