📄 npctemplate.c
字号:
/* 切扎氏午仄凶涩烂分 */ *randomwidth = ABS(maxvalue - minvalue); return min(minvalue,maxvalue); } *randomwidth = 0; return minvalue;}/*------------------------------------------------------------ * 娄醒 * 忒曰袄 ------------------------------------------------------------*/BOOL NPC_readTemplateFile( char* filename ){ FILE* f; char line[512]; int linenum=0; int start=OFF; NPC_Template temp; int itmreadindex=0; char* ret; int randomdata[NPC_TEMPLATEINTNUM]; int i; if( NPC_template_readindex >= NPC_templatenum ){ print("模块超过配置数目\n" ); print("配置模块数目 %d\n", NPC_templatenum); return FALSE; } for( i=0; i<NPC_TEMPLATEINTNUM ; i++ ) randomdata[i] = 0; NPC_setDefaultNPCTemplate( &temp ); f= fopen( filename ,"r"); if( f == NULL )return FALSE; ret = fgets( line, sizeof( line ), f ); if( ret == NULL )goto FCLOSERETURNFALSE; if( strcmp( NPC_TEMPLATEFILEMAGIC, line ) != 0 ){ print( "这不是模块文件.\n" ); goto FCLOSERETURNFALSE ; } linenum = 1; while( fgets( line , sizeof( line ) , f ) ){ linenum++; if( line[0] == '#' )continue; /* comment */ if( line[0] == '\n' )continue; /* none */ chomp( line ); switch( line[0] ){ case '{': if( start == ON ){ fprint( "Find {. 已经开始声明. %s:%d\n", filename, linenum); goto FCLOSERETURNFALSE; }else start = ON; break; case '}': if( start == ON ){ int err=FALSE; if( strcmp(temp.chardata[NPC_TEMPLATENAME].string ,"") == 0 ){ fprint( "这些没有名字 %s:%d\n", filename, linenum ); err = TRUE; }else if( temp.intdata[NPC_TEMPLATETYPE] == -1 ){ temp.intdata[NPC_TEMPLATETYPE] = SPR_pet001; } if( err ){ if( temp.intdata[NPC_TEMPLATEITEMNUM] != 0 ) freeMemory( temp.haveitem ); }else{ temp.hash = hashpjw(temp.chardata[NPC_TEMPLATENAME].string); temp.intdata[NPC_TEMPLATEITEMNUM] = itmreadindex; for( i=0 ; i<NPC_TEMPLATEINTNUM ; i++ ){ temp.randomdata[i] = randomdata[i]; randomdata[i]=0; } memcpy( &NPC_template[NPC_template_readindex], &temp, sizeof( NPC_Template ) ); NPC_template_readindex++; if( NPC_template_readindex >= NPC_templatenum ){ print("模块超过配置数目\n" ); print("配置模块数目是 %d\n", NPC_templatenum); goto FCLOSERETURNFALSE; } } NPC_setDefaultNPCTemplate( &temp ); itmreadindex=0; start=OFF; }else{ fprint( "未解决 '}' at %s:%d\n",filename,linenum); goto FCLOSERETURNFALSE; } break; default: { typedef struct tagNPC_Readtemplate { char* keyword; NPC_TYPECATEGORYATREADFILE type; int index; void* func; }NPC_Readtemplate; static NPC_Readtemplate NPC_readtemplate[NPC_TEMPLATECHARNUM+NPC_TEMPLATEINTNUM]= { {"templatename" , NPC_CHARENTRY, NPC_TEMPLATENAME,NULL}, {"name" , NPC_CHARENTRY, NPC_TEMPLATECHARNAME, NULL}, {"makeatnobody", NPC_INTENTRY, NPC_TEMPLATEMAKEATNOBODY, NULL}, {"makeatnosee" , NPC_INTENTRY, NPC_TEMPLATEMAKEATNOSEE, NULL}, {"graphicname", NPC_INTFUNC, NPC_TEMPLATEIMAGENUMBER, NPC_seekGraphicNumberFromString}, {"type", NPC_INTFUNC, NPC_TEMPLATETYPE, NPC_seekGraphicNumberFromString}, {"hp", NPC_INTFUNC, NPC_TEMPLATEMINHP, NPC_getRandomValue}, {"mp", NPC_INTFUNC, NPC_TEMPLATEMINMP, NPC_getRandomValue}, {"str", NPC_INTFUNC, NPC_TEMPLATEMINSTR, NPC_getRandomValue}, {"tough", NPC_INTFUNC, NPC_TEMPLATEMINTOUGH, NPC_getRandomValue}, {"fly", NPC_INTENTRY,NPC_TEMPLATEISFLYING,NULL}, {"itemnum", NPC_INTENTRY, NPC_TEMPLATEITEMNUM, NULL,}, {"functionset",NPC_INTFUNC, NPC_TEMPLATEFUNCTIONINDEX, NPC_searchFunctionSet,}, {"initfunc", NPC_CHARENTRY, NPC_TEMPLATEINITFUNC,NULL,}, {"walkprefunc", NPC_CHARENTRY, NPC_TEMPLATEWALKPREFUNC, NULL,}, {"walkpostfunc",NPC_CHARENTRY, NPC_TEMPLATEWALKPOSTFUNC, NULL,}, {"preoverfunc", NPC_CHARENTRY, NPC_TEMPLATEPREOVERFUNC, NULL,}, {"postoverfunc",NPC_CHARENTRY, NPC_TEMPLATEPOSTOVERFUNC, NULL,}, {"watchfunc", NPC_CHARENTRY, NPC_TEMPLATEWATCHFUNC, NULL,}, {"loopfunc", NPC_CHARENTRY, NPC_TEMPLATELOOPFUNC, NULL,}, {"talkedfunc",NPC_CHARENTRY,NPC_TEMPLATETALKEDFUNC,NULL,}, {"dyingfunc",NPC_CHARENTRY,NPC_TEMPLATEDYINGFUNC,NULL,}, {"preattackedfunc",NPC_CHARENTRY, NPC_TEMPLATEPREATTACKEDFUNC,NULL,}, {"postattackedfunc",NPC_CHARENTRY, NPC_TEMPLATEPOSTATTACKEDFUNC,NULL,}, {"offfunc",NPC_CHARENTRY,NPC_TEMPLATEOFFFUNC,NULL,}, {"lookedfunc",NPC_CHARENTRY,NPC_TEMPLATELOOKEDFUNC,NULL,}, {"itemputfunc",NPC_CHARENTRY,NPC_TEMPLATEITEMPUTFUNC, NULL,}, {"specialtalkedfunc",NPC_CHARENTRY, NPC_TEMPLATESPECIALTALKEDFUNC, NULL,}, {"windowtalkedfunc",NPC_CHARENTRY, NPC_TEMPLATEWINDOWTALKEDFUNC, NULL,}, {"loopfunctime",NPC_INTENTRY,NPC_TEMPLATELOOPFUNCTIME, NULL,}, }; char firstToken[256]; int ret,i; ret = getStringFromIndexWithDelim( line, "=", 1, firstToken, sizeof( firstToken ) ); if( ret == FALSE ){ print( "Find error at %s in line %d. Ignore\n", filename , linenum); break; } if( strcasecmp(firstToken,"itm") == 0 ){ char one[128]; char two[128]; char three[128]; int itemnumber=0,rate=0,amount=1; char secondToken[256]={""}; if( itmreadindex < temp.intdata[NPC_TEMPLATEITEMNUM] && temp.haveitem != NULL ) ; else continue; ret = getStringFromIndexWithDelim( line, "=", 2, secondToken, sizeof(secondToken ) ); if( ret == FALSE ){ print( "Find error at %s in line %d. Ignore\n", filename , linenum); secondToken[0] = '\0'; } ret = getStringFromIndexWithDelim( secondToken, "|", 1, one,sizeof( one ) ); if( ret != FALSE )itemnumber=atoi(one); ret = getStringFromIndexWithDelim( secondToken, "|", 2, two,sizeof(two)); if( ret != FALSE )rate=atoi(two); ret = getStringFromIndexWithDelim( secondToken, "|", 3, three,sizeof(three)); if( ret != FALSE )amount=atoi(three); if( rate > 0 && amount > 0 ){ if( itemnumber == -1 ){ temp.haveitem[itmreadindex].itemnumber = -1; temp.haveitem[itmreadindex].haverate = rate; temp.haveitem[itmreadindex].havenum = amount; itmreadindex++; }else if( ITEM_CHECKITEMTABLE( itemnumber ) == TRUE ){ temp.haveitem[itmreadindex].itemnumber=itemnumber; temp.haveitem[itmreadindex].haverate = rate; temp.haveitem[itmreadindex].havenum = amount; itmreadindex++; }else print("this item is not item %s:%d\n", filename , linenum); }else print("rate or amount is odd setting. rate=%d " "amount=%d %s:%d\n", rate,amount, filename, linenum); goto NEXT; }else{ for( i = 0 ; i < arraysizeof(NPC_readtemplate) ; i ++ ){ if( strcasecmp( NPC_readtemplate[i].keyword, firstToken ) == 0 ){ char secondToken[256]={""}; ret = getStringFromIndexWithDelim( line, "=", 2, secondToken, sizeof(secondToken) ); if( ret == FALSE ) print( "Find error at %s in line %d. Ignore\n" ,filename , linenum); switch( NPC_readtemplate[i].type ){ case NPC_INTENTRY: temp.intdata[NPC_readtemplate[i].index]=atoi(secondToken); if( NPC_readtemplate[i].index == NPC_TEMPLATEITEMNUM ) NPC_templateallocitemdata( &temp ); break; case NPC_CHARENTRY: strcpysafe( temp.chardata[NPC_readtemplate[i].index].string, sizeof(temp.chardata[NPC_readtemplate[i].index].string), secondToken); break; case NPC_INTFUNC: { int (*intfunction)(char*,int* ); intfunction = NPC_readtemplate[i].func; temp.intdata[NPC_readtemplate[i].index] = intfunction( secondToken, &randomdata[NPC_readtemplate[i].index]); break; } case NPC_CHARFUNC: { char* (*charfunction)(char* ); charfunction = NPC_readtemplate[i].func; strcpysafe( temp.chardata[NPC_readtemplate[i].index].string, sizeof(temp.chardata[NPC_readtemplate[i].index].string), charfunction(secondToken)); break; } default: break; } goto NEXT; } } } fprint("%s:%d There is no such entry %s\n" , filename, linenum, firstToken ); NEXT: break; } break; } } fclose(f); return TRUE;FCLOSERETURNFALSE: fclose(f); return FALSE;}BOOL NPC_readNPCTemplateFiles( char* topdirectory ,int templatesize){ STRING64 *filenames; int filenum; int i; filenames = (STRING64 *)allocateMemory( sizeof( STRING64 ) * (int)getFilesearchnum( ) ); if( filenames == NULL ){ print( "读取NPC创建文件... 内存出错\n" ); return FALSE; } filenum = rgetFileName( topdirectory ,filenames ,getFilesearchnum( ) ); if( filenum == -1 ){ fprint("无法从 %s 递归获取文件名\n",topdirectory); freeMemory( filenames ); return FALSE; } if( filenum >= getFilesearchnum( ) ){ print( "文件搜索数目失败 %d\n", getFilesearchnum( ) ); while( 1 ); }else{ print( "搜索到文件 = %d\n", filenum ); } if( !NPC_initTemplateArray( templatesize ) ){ fprint( "开启模块数组错误\n" ); freeMemory( filenames ); return FALSE; } print( "读取文件模块数组错误...." ); for( i = 0 ; i < filenum ; i ++ ) if( NPC_IsNPCTemplateFile( filenames[i].string )) NPC_readTemplateFile( filenames[i].string ); print( "正确模块 %d ...\n" , NPC_template_readindex ); NPC_templatenum=NPC_template_readindex; freeMemory( filenames ); return TRUE;}/*------------------------------------------------------------ * 娄醒 * 忒曰袄 * -1 及凛巨仿□ ------------------------------------------------------------*/int NPC_templateGetTemplateIndex( char* templatename ){ int i; int hash=hashpjw( templatename ); for( i = 0 ; i < NPC_templatenum ; i ++ ) if( hash == NPC_template[i].hash && strcasecmp( templatename , NPC_template[i].chardata[NPC_TEMPLATENAME].string) == 0 ) return i; return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -