?? encount.c
字號:
#include "version.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#ifdef _REDHAT_V9
#include <errno.h>
#endif
#include "common.h"
#include "util.h"
#include "buf.h"
#include "char_base.h"
#include "char.h"
#include "configfile.h"
#include "encount.h"
#include "enemy.h"
#ifdef _ADD_ENCOUNT // WON ADD 增加敵遭遇觸發修件
#include "encount.h"
#endif
/* 巨件市它件玄楮 及末□旦 */
#ifndef _ADD_ENCOUNT // WON ADD 增加敵遭遇觸發修件
typedef struct tagENCOUNT_Table
{
int index;
int floor;
int encountprob_min; /* 巨件市它件玄割 */
int encountprob_max; /* 巨件市它件玄割 */
int enemymaxnum; /* 升木分仃襯毛綜月井 */
int zorder;
int groupid[ENCOUNT_GROUPMAXNUM]; /* 弘伙□皿No */
int createprob[ENCOUNT_GROUPMAXNUM]; /* 公及弘伙□皿及請蜇 */
RECT rect;
}ENCOUNT_Table;
ENCOUNT_Table *ENCOUNT_table;
#endif
int ENCOUNT_encountnum;
#define ENCOUNT_ENEMYMAXCREATENUM 10
static INLINE BOOL ENCOUNT_CHECKENCOUNTTABLEARRAY( int array)
{
if( array < 0 || array > ENCOUNT_encountnum-1) return FALSE;
return TRUE;
}
/*------------------------------------------------------------
* 巨件市它件玄澀爛及賡渝祭毛允月[
* 婁醒
* filename char* 澀爛白央奶伙
* 忒曰襖
* 岳 TRUE(1)
* 撩 FALSE(0)
*------------------------------------------------------------*/
BOOL ENCOUNT_initEncount( char* filename )
{
FILE* f;
char line[256];
int linenum=0;
int encount_readlen=0;
f = fopen(filename,"r");
if( f == NULL ){
errorprint;
return FALSE;
}
ENCOUNT_encountnum=0;
/* 引內 躲卅墊互窒墊丐月井升丹井譬屯月 */
while( fgets( line, sizeof( line ), f ) ){
linenum ++;
if( line[0] == '#' )continue; /* comment */
if( line[0] == '\n' )continue; /* none */
chomp( line );
ENCOUNT_encountnum++;
}
if( fseek( f, 0, SEEK_SET ) == -1 ){
fprint( "尋找錯誤\n" );
fclose(f);
return FALSE;
}
ENCOUNT_table = allocateMemory( sizeof(struct tagENCOUNT_Table)
* ENCOUNT_encountnum );
if( ENCOUNT_table == NULL ){
fprint( "無法分配內存 %d\n" ,
sizeof(ENCOUNT_table)*ENCOUNT_encountnum);
fclose( f );
return FALSE;
}
/* 賡渝祭 */
{
int i,j;
for( i = 0; i < ENCOUNT_encountnum; i ++ ) {
ENCOUNT_table[i].index = -1;
ENCOUNT_table[i].floor = 0;
ENCOUNT_table[i].encountprob_min = 1;
ENCOUNT_table[i].encountprob_min = 50;
ENCOUNT_table[i].enemymaxnum = 4;
ENCOUNT_table[i].rect.x = 0;
ENCOUNT_table[i].rect.y = 0;
ENCOUNT_table[i].rect.height = 0;
ENCOUNT_table[i].rect.width = 0;
ENCOUNT_table[i].zorder = 0;
for( j = 0; j < ENCOUNT_GROUPMAXNUM; j ++ ) {
ENCOUNT_table[i].groupid[j] = -1;
ENCOUNT_table[i].createprob[j] = -1;
}
#ifdef _ADD_ENCOUNT // WON ADD 增加敵遭遇觸發修件
ENCOUNT_table[i].event_now = -1;
ENCOUNT_table[i].event_end = -1;
ENCOUNT_table[i].enemy_group = -1;
#endif
}
}
/* 引兇 心 允 */
linenum = 0;
while( fgets( line, sizeof( line ), f ) ){
linenum ++;
if( line[0] == '#' )continue; /* comment */
if( line[0] == '\n' )continue; /* none */
chomp( line );
/* 墊毛幫溥允月 */
/* 引內 tab 毛 " " 卞 五晶尹月 */
replaceString( line, '\t' , ' ' );
/* 燮 及旦矢□旦毛潸月[*/
{
int i;
char buf[256];
for( i = 0; i < strlen( line); i ++) {
if( line[i] != ' ' ) {
break;
}
strcpy( buf, &line[i]);
}
if( i != 0 ) {
strcpy( line, buf);
}
}
{
char token[256];
int ret;
int x1,x2,y1,y2;
int j;
/* 蘸戶及伙□皿卞 勻兇凜及啃及賡渝祭 */
ENCOUNT_table[encount_readlen].index = -1;
ENCOUNT_table[encount_readlen].floor = 0;
ENCOUNT_table[encount_readlen].encountprob_min = 1;
ENCOUNT_table[encount_readlen].encountprob_min = 50;
ENCOUNT_table[encount_readlen].enemymaxnum = 4;
ENCOUNT_table[encount_readlen].rect.x = 0;
ENCOUNT_table[encount_readlen].rect.y = 0;
ENCOUNT_table[encount_readlen].rect.height = 0;
ENCOUNT_table[encount_readlen].rect.width = 0;
ENCOUNT_table[encount_readlen].zorder = 0;
for( j = 0; j < ENCOUNT_GROUPMAXNUM; j ++ ) {
ENCOUNT_table[encount_readlen].groupid[j] = -1;
ENCOUNT_table[encount_readlen].createprob[j] = -1;
}
#ifdef _ADD_ENCOUNT // WON ADD 增加敵遭遇觸發修件
ENCOUNT_table[encount_readlen].event_now = -1;
ENCOUNT_table[encount_readlen].event_end = -1;
ENCOUNT_table[encount_readlen].enemy_group = -1;
#endif
/* 夫午勾戶及玄□弁件毛葦月 */
ret = getStringFromIndexWithDelim( line,",",1,token,
sizeof(token));
if( ret==FALSE ){
fprint("文件語法錯誤:%s 第%d行\n",filename,linenum);
continue;
}
ENCOUNT_table[encount_readlen].index = atoi(token);
/* 2勾戶及玄□弁件毛葦月 */
ret = getStringFromIndexWithDelim( line,",",2,token,
sizeof(token));
if( ret==FALSE ){
fprint("文件語法錯誤:%s 第%d行\n",filename,linenum);
continue;
}
ENCOUNT_table[encount_readlen].floor = atoi(token);
/* 3勾戶及玄□弁件毛葦月 */
ret = getStringFromIndexWithDelim( line,",",3,token,
sizeof(token));
if( ret==FALSE ){
fprint("文件語法錯誤:%s 第%d行\n",filename,linenum);
continue;
}
x1 = atoi(token);
/* 4勾戶及玄□弁件毛葦月 */
ret = getStringFromIndexWithDelim( line,",",4,token,
sizeof(token));
if( ret==FALSE ){
fprint("文件語法錯誤:%s 第%d行\n",filename,linenum);
continue;
}
y1= atoi(token);
/* 5勾戶及玄□弁件毛葦月 */
ret = getStringFromIndexWithDelim( line,",",5,token,
sizeof(token));
if( ret==FALSE ){
fprint("文件語法錯誤:%s 第%d行\n",filename,linenum);
continue;
}
x2 = atoi(token);
/* 6勾戶及玄□弁件毛葦月 */
ret = getStringFromIndexWithDelim( line,",",6,token,
sizeof(token));
if( ret==FALSE ){
fprint("文件語法錯誤:%s 第%d行\n",filename,linenum);
continue;
}
y2= atoi(token);
ENCOUNT_table[encount_readlen].rect.x = min(x1,x2);
ENCOUNT_table[encount_readlen].rect.width = max(x1,x2) - min(x1,x2);
ENCOUNT_table[encount_readlen].rect.y = min(y1,y2);
ENCOUNT_table[encount_readlen].rect.height = max(y1,y2) - min(y1,y2);
/* 7戶及玄□弁件毛葦月 */
ret = getStringFromIndexWithDelim( line,",",7,token,
sizeof(token));
if( ret==FALSE ){
fprint("文件語法錯誤:%s 第%d行\n",filename,linenum);
continue;
}
ENCOUNT_table[encount_readlen].encountprob_min = atoi(token);
/* 8戶及玄□弁件毛葦月 */
ret = getStringFromIndexWithDelim( line,",",8,token,
sizeof(token));
if( ret==FALSE ){
fprint("文件語法錯誤:%s 第%d行\n",filename,linenum);
continue;
}
ENCOUNT_table[encount_readlen].encountprob_max = atoi(token);
{
int a,b;
a = ENCOUNT_table[encount_readlen].encountprob_min;
b = ENCOUNT_table[encount_readlen].encountprob_max;
/* 凝及譬幫 */
ENCOUNT_table[encount_readlen].encountprob_min
= min( a,b);
ENCOUNT_table[encount_readlen].encountprob_max
= max( a,b);
}
/* 9勾戶及玄□弁件毛葦月 */
ret = getStringFromIndexWithDelim( line,",",9,token,
sizeof(token));
if( ret==FALSE ){
fprint("文件語法錯誤:%s 第%d行\n",filename,linenum);
continue;
}
{
int maxnum = atoi( token);
/* 醒及懇癲嶺及民尼永弁 */
if( maxnum < 1 || maxnum > ENCOUNT_ENEMYMAXCREATENUM ) {
fprint("文件語法錯誤:%s 第%d行\n",filename,linenum);
continue;
}
ENCOUNT_table[encount_readlen].enemymaxnum = maxnum;
}
/* 10戶及玄□弁件毛葦月 */
ret = getStringFromIndexWithDelim( line,",",10,token,
sizeof(token));
if( ret==FALSE ){
fprint("文件語法錯誤:%s 第%d行\n",filename,linenum);
continue;
}
ENCOUNT_table[encount_readlen].zorder = atoi(token);
#define CREATEPROB_TOKEN 11
/* 11 31戶及玄□弁件毛葦月 */
{
int i;
for( i = CREATEPROB_TOKEN; i < CREATEPROB_TOKEN +ENCOUNT_GROUPMAXNUM*2; i ++) {
ret = getStringFromIndexWithDelim( line,",",i,token,
sizeof(token));
if( ret==FALSE ){
fprint("文件語法錯誤:%s 第%d行\n",filename,linenum);
continue;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -