コード例 #1
0
ファイル: readmap.c プロジェクト: beijunyi/custom-sa
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;
}
コード例 #2
0
ファイル: readmap.c プロジェクト: beijunyi/custom-sa
int MAP_readMapConfFile(char *filename) {
  FILE *file;
  char line[512];
  int maximagenumber = 0;
  int i;
  int linenum = 0;
  int imgdataindex = 0;

  file = fopen(filename, "r");
  if(file == NULL) {
    fprint("无法打开文件 %s\n", filename);
    return FALSE;
  }
  while(fgets(line, sizeof(line), file)) {
    char imgnum[16];
    int ret;
    int imgnumber;
    deleteSequentChar(line, " \t");
    pohcd(line, " \t");
    dchop(line, " \t");

    if(line[0] == '#')continue;
    if(line[0] == '\n')continue;
    chomp(line);
    ret = getStringFromIndexWithDelim(line, " ", 1, imgnum, sizeof(imgnum));
    if(ret == FALSE)continue;
    imgnumber = atoi(imgnum);
    maximagenumber = max(maximagenumber, imgnumber);
  }

  MAP_imagedatanum = maximagenumber + 1;
  MAP_imagedata = allocateMemory(sizeof(MAP_ImageData) * MAP_imagedatanum);
  if(MAP_imagedata == NULL) {
    fprint("无法分配地图数据大小=%d\n", MAP_imagedatanum);
    return FALSE;
  }

  for(i = 0; i < arraysizeof(MAP_imgfilt); i++)
    MAP_imgfilt[i] = -1;
  if(fseek(file, 0, SEEK_SET) != 0) {
    fprint("无法查找 SEEK_SET %s\n", strerror(errno));
    return FALSE;
  }
  while(fgets(line, sizeof(line), file)) {
    char token[64];
    int imagenumber;
    int ret;
    int i;
    MAP_ImageData *one;
    int offset;
    linenum++;

    deleteSequentChar(line, " \t");
    pohcd(line, " \t");
    chomp(line);
    if(line[0] == '#')continue;
    if(line[0] == '\n')continue;
    chomp(line);

    ret = getStringFromIndexWithDelim(line, " ", 1, token, sizeof(token));
    if(ret == FALSE)continue;
    imagenumber = atoi(token);
    MAP_imgfilt[imagenumber] = imgdataindex;
    one = &MAP_imagedata[imgdataindex];
    imgdataindex++;

    MAP_makeDefaultImageData(one);
    offset = 4;
    for(i = 0; i < MAP_DATAINT_NUM + MAP_DATACHAR_NUM; i++) {
      int ret = getStringFromIndexWithDelim(line, " ", i + offset, token, sizeof(token));
      if(ret == FALSE)continue;
      switch(MAP_confentries[i].type) {
        case MAP_INTENTRY:
          one->data[MAP_confentries[i].index]
              = atoi(token);
          break;
        case MAP_CHARENTRY:
          strcpysafe(one->string[MAP_confentries[i].index].string,
                     sizeof(one->string[MAP_confentries[i].index].
                         string),
                     token);
          break;
        case MAP_INTFUNC: {
          int (*intfunction)(char *);
          intfunction = MAP_confentries[i].func;
          one->data[MAP_confentries[i].index]
              = intfunction(token);
          break;
        }
        case MAP_CHARFUNC: {
          char *(*charfunction)(char *);
          charfunction = MAP_confentries[i].func;

          strcpysafe(one->string[MAP_confentries[i].index].string,
                     sizeof(one->string[MAP_confentries[i].index].
                         string),
                     charfunction(token));
          break;
        }
        default:
          break;
      }
    }
  }

  fclose(file);
  return TRUE;
}
コード例 #3
0
ファイル: readmap.c プロジェクト: ChowZenki/SMO-Sa-Source
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;
}