Пример #1
0
static BOOL ADDRESSBOOK_makeEntryFromCharaindex( int charaindex,
												 ADDRESSBOOK_entry* ae)
{
	char *cdkey;

	if( !CHAR_CHECKINDEX(charaindex) ) return FALSE;

	memset( ae,0,sizeof(ADDRESSBOOK_entry) );
	cdkey = CHAR_getChar( charaindex, CHAR_CDKEY);
	if( cdkey == NULL ){
		print( "ADDRESSBOOK_makeEntryFromCharaindex:"
			   " strange! getcdkeyFromCharaIndex returns NULL!"
			   " charaindex: %d\n" , charaindex );
		return FALSE;
	}
	strcpysafe( ae->cdkey , sizeof( ae->cdkey ),cdkey);

	strcpysafe( ae->charname,sizeof( ae->charname),
				CHAR_getChar(charaindex,CHAR_NAME) );
	ae->level       = CHAR_getInt( charaindex , CHAR_LV );
	ae->duelpoint   = CHAR_getInt( charaindex, CHAR_DUELPOINT);
	ae->graphicsno  = CHAR_getInt( charaindex , CHAR_FACEIMAGENUMBER );
	ae->online = getServernumber();
	ae->use = TRUE;
	ae->transmigration = CHAR_getInt( charaindex, CHAR_TRANSMIGRATION);

	return TRUE;
}
Пример #2
0
BOOL ADDRESSBOOK_sendAddressbookTable( int cindex )
{
	int stringlen=0;
	int i;

	if( !CHAR_CHECKINDEX( cindex ) )return FALSE;
	
	for( i=0 ; i<ADDRESSBOOK_MAX ; i++){
		ADDRESSBOOK_entry *ae;
		ae = CHAR_getAddressbookEntry( cindex , i );
		if( ae && ae->use ){
			char tmp[CHARNAMELEN+32];
			char charname_escaped[CHARNAMELEN*2];
			makeEscapeString( ae->charname, charname_escaped ,
							  sizeof(charname_escaped  ));
			/*  »ÈÍѥե饰|  Á°|¥ì¥Ù¥ë|¥é¥¤¥Õ|¥Õ¥é¥°   */
			snprintf( tmp , sizeof( tmp ),
					  "%d|%s|%d|%d|%d|%d|%d|" ,
					  ae->use,
					  charname_escaped , ae->level , 
					  ae->duelpoint,ae->online,ae->graphicsno,
					  ae->transmigration);
			strcpysafe  ( ADDRESSBOOK_returnstring + stringlen ,
						  sizeof(ADDRESSBOOK_returnstring) - stringlen,
						  tmp );
			stringlen += strlen( tmp );
			if( stringlen >= sizeof(ADDRESSBOOK_returnstring) ) {
				break;
			}
		}else{
			/*»È¤Ã¤Æ¤Ê¤¤¥Ç¡¼¥¿¤â¨R«à¤Î¤ß¤ÇÁ÷¤ë  */
			char    tmp[32];
			snprintf( tmp , sizeof( tmp ), "|||||||"  );
			strcpysafe  ( ADDRESSBOOK_returnstring + stringlen ,
						  sizeof(ADDRESSBOOK_returnstring) - stringlen,
						  tmp );
			stringlen += strlen( tmp );
			if( stringlen >= sizeof(ADDRESSBOOK_returnstring)) {
				break;
			}
		}
	}
	
	dchop( ADDRESSBOOK_returnstring, "|" );

	{
		int fd;
		fd = getfdFromCharaIndex( cindex );
		if( fd == -1 ) return FALSE;
		lssproto_AB_send( fd, ADDRESSBOOK_returnstring );
	}
	return TRUE;
}
Пример #3
0
static char *NPC_PoolItemShop_getMsg_noarg( int tablenum, 
								char *argstr, char *retstring, int retstringlen)
{
	char	buf[1024];
	if( tablenum < 0 || tablenum >= arraysizeof( poolshopmsg)) return NULL;
	
	if( NPC_Util_GetStrFromStrWithDelim( argstr, poolshopmsg[tablenum].option, buf, sizeof( buf)) != NULL ) {
		strcpysafe( retstring, retstringlen, buf);
	}else {
		strcpysafe( retstring, retstringlen, poolshopmsg[tablenum].defaultmsg);
	}
	return retstring;
}
Пример #4
0
BOOL ADDRESSBOOK_sendAddressbookTableOne( int cindex, int num )
{
	int stringlen=0;
	ADDRESSBOOK_entry *ae;

	if( !CHAR_CHECKINDEX( cindex ) )return FALSE;
	if( num < 0 || num > ADDRESSBOOK_MAX) return FALSE;
	
	ae = CHAR_getAddressbookEntry( cindex , num );
	
	if( ae && ae->use ){
		char tmp[CHARNAMELEN+32];
		char charname_escaped[CHARNAMELEN*2];
		makeEscapeString( ae->charname, charname_escaped ,
						  sizeof(charname_escaped  ));
		snprintf( tmp , sizeof( tmp ),
				  "%d|%s|%d|%d|%d|%d|%d|" ,
				  ae->use,
				  charname_escaped , ae->level , 
				  ae->duelpoint,ae->online,ae->graphicsno,
				  ae->transmigration);
		strcpysafe  ( ADDRESSBOOK_returnstring + stringlen ,
					  sizeof(ADDRESSBOOK_returnstring) - stringlen,
					  tmp );
		stringlen += strlen( tmp );
		if( stringlen >= sizeof(ADDRESSBOOK_returnstring) ) {
			return FALSE;
		}
	}else{
		char    tmp[32];
		snprintf( tmp , sizeof( tmp ), "|||||||"  );
		strcpysafe  ( ADDRESSBOOK_returnstring + stringlen ,
					  sizeof(ADDRESSBOOK_returnstring) - stringlen,
					  tmp );
		stringlen += strlen( tmp );
		if( stringlen >= sizeof(ADDRESSBOOK_returnstring)) {
			return FALSE;
		}
	}

	{
		int fd;
		fd = getfdFromCharaIndex( cindex );
		if( fd == -1 ) return FALSE;
		lssproto_ABI_send( fd, num, ADDRESSBOOK_returnstring );
	}
	return TRUE;
}
Пример #5
0
char *NPC_Util_GetStrFromStrWithDelim( char *srcstr, char *srhstr,
                                       char *buf, int buflen)
{
	BOOL    rc;
	char	*cret = NULL;
	int     i;
	char    outstr[1024];
	char    outstr2[1024];

	memset( outstr, 0, sizeof( outstr));
	memset( outstr2, 0, sizeof( outstr2));
	buf[0] = '\0';
	for( i = 1; ; i++ ) {
		rc = getStringFromIndexWithDelim( srcstr, "|", i, outstr, sizeof(outstr));
		if( rc == FALSE) break;
		if( strstr( outstr, srhstr) != NULL) {
			rc = getStringFromIndexWithDelim( outstr, ":", 2, outstr2, sizeof(outstr2));
			if( rc != FALSE ) {
				strcpysafe( buf, buflen, outstr2 );
				cret = buf;
				break;
			}
		}
	}
	return cret;
}
Пример #6
0
int NPC_DoorGetPasswd( int meindex, char *out , int len )
{
    char *m = CHAR_getWorkChar( meindex , CHAR_WORKDOORPASSWD );
    if( m == NULL )return -1;
    strcpysafe( out ,len , m );
    return 0;
}
Пример #7
0
void backslash_n_to_linefeed(char *s0, char *s, int max_len)
{
	char *tmp;

	strcpysafe(s, s0, max_len);

	while (strstr(s, "\\n") != NULL) {
		tmp = strstr(s, "\\n");
		strcpy(tmp, tmp+1);
		*tmp = '\n';
	}

}
Пример #8
0
/*------------------------------------------------------------
 *   »ú  ²½¤µ¤ì¤Æ¤¤¤ë¥¢¥É¥ì¥¹¥Ö¥Ã¥¯¥¨¥ó¥È¥ê¤ò¡b¹½Â¤  ¤Ë¤Ê¶³¤¹¡e
 * ¤³¤Î·ë²Ì¹½Â¤  ¤Îuse°Ê³°¤Î¾ð  ¤Ï´°àú¤Ë¤Ê¤ë¡e
 * °ú¿ô
 *  in      char*                     »ú  
 *  a       ADDRESSBOOK_entry*      ¥Ç¡¼¥¿¤ò¼ý¤á¤ë½ê
 * ÊÖ¤êÃÍ
 * ¤Ä¤Í¤ËTRUE
 ------------------------------------------------------------*/
BOOL ADDRESSBOOK_makeAddressbookEntry( char *in , ADDRESSBOOK_entry *a )
{
	char work1[256], work2[256] , work3[256] , work4[256],work5[256],work6[256];
	int ret;
	if( strlen( in ) == 0 ){
		memset( a,0,sizeof(ADDRESSBOOK_entry) );
		a->use = 0;
		return TRUE;
	}
	
	getStringFromIndexWithDelim( in, "|" , 1 , work1 , sizeof( work1 ));
	getStringFromIndexWithDelim( in, "|" , 2 , work2 , sizeof( work2 ));
	getStringFromIndexWithDelim( in, "|" , 3 , work3 , sizeof( work3 ));
	getStringFromIndexWithDelim( in, "|" , 4 , work4 , sizeof( work4 ));
	getStringFromIndexWithDelim( in, "|" , 5 , work5 , sizeof( work5 ));
	work6[0] = '\0';
	ret = getStringFromIndexWithDelim( in, "|" , 6 , work6 , sizeof( work6 ));
	if( ret == FALSE ) {
		a->transmigration = 0;
	}
	else {
		a->transmigration = atoi( work6);
	}
	a->use = 1;

	makeStringFromEscaped( work1 );
	makeStringFromEscaped( work2 );

	strcpysafe( a->cdkey , sizeof(a->cdkey) , work1 );
	strcpysafe( a->charname , sizeof(a->charname), work2 );

	a->level = atoi( work3 );
	a->duelpoint = atoi( work4 );
	a->graphicsno = atoi( work5 );
		
	return FALSE;
}
Пример #9
0
/*------------------------------------------------------------
 * �ͷ���ʧ������έ���±�į��  ٯ  ë����
 * ¦��
 *  title       Title*      ��ƽ��
 *  charaindex  int         �𼰱�įë  �Ȼ�����ƽ�ҷ¼��̼������͵�
 * ߯Ի��
 *  char*
 ------------------------------------------------------------*/
char* TITLE_makeTitleStatusString( int charaindex,int havetitleindex )
{
	int     attach;
	int     index;
	/*  ����  �߼��̼������͵����շ�����ë��������  */
	index = CHAR_getCharHaveTitle( charaindex,havetitleindex );

	attach = TITLE_getTitleIndex( index);
	if( attach == -1 ) {
		TITLE_statusStringBuffer[0] = '\0';
		return TITLE_statusStringBuffer;
	}
	switch( TITLE_table[attach].functype ){
	case TITLE_FUNCTYPENONE:
		snprintf( TITLE_statusStringBuffer,
				  sizeof(TITLE_statusStringBuffer ),"%s" ,
				  TITLE_table[attach].name );
		break;
	
	case TITLE_FUNCTYPEUSERFUNC:
	{
		char    string[256]={""};
		void    (*function)(int,char* buf,int buflen);
		function = TITLE_table[attach].definefunction;
		if( function )
			function( charaindex,string,sizeof(string) );

		strcpysafe( TITLE_statusStringBuffer,
					sizeof(TITLE_statusStringBuffer ),string );
	}
	break;
	default:
		TITLE_statusStringBuffer[0] = '\0';
		return TITLE_statusStringBuffer;
		break;
	}
	return TITLE_statusStringBuffer;
}
Пример #10
0
void NPC_NPCEnemyLoop( int meindex )
{

	if( NowTime.tv_sec > CHAR_getWorkInt( meindex, CHAR_WORK_DIETIME) +
						 CHAR_getWorkInt( meindex, CHAR_WORK_REVIVALTIME)){
		Char	*ch;
		CHAR_setInt( meindex, CHAR_BASEIMAGENUMBER,	CHAR_getWorkInt( meindex, CHAR_WORK_BASEIMGBAK));
		print("bbi---->bi11");

		CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX));
		CHAR_setWorkInt( meindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_ENEMY);
		MAP_sendAroundMapdata( CHAR_getInt( meindex, CHAR_FLOOR),
								CHAR_getInt( meindex, CHAR_X),
								CHAR_getInt( meindex, CHAR_Y));
	    ch  = CHAR_getCharPointer( meindex);
	    if( ch != NULL ) {
			strcpysafe( ch->charfunctable[CHAR_LOOPFUNC].string,
						sizeof( ch->charfunctable[CHAR_LOOPFUNC]),	"");
			CHAR_constructFunctable( meindex);
//			CHAR_setInt( meindex, CHAR_LOOPINTERVAL, 0);
		}
	}
}
Пример #11
0
int NPC_NPCEnemy_Dying( int battleindex, int meindex )
{
	char	argstr1[NPC_UTIL_GETARGSTR_BUFSIZE];
	char *argstr;
	char	buf[64];
	int	i,toindex=-1;
	int tmp=-1;

	if( !CHAR_CHECKINDEX( meindex)) {
		return FALSE;
	}
	argstr = NPC_Util_GetArgStr( meindex, argstr1, sizeof( argstr1));

#ifdef _NEW_WARPMAN
	if( strstr( argstr, "NEWNPCENEMY") )    {
	}else	{
#endif
	/* 蠅    及陲太 */
	if( NPC_Util_GetStrFromStrWithDelim( argstr, "endmsg", buf, sizeof( buf)) != NULL ) {
		for( i = 0; i < 5; i ++ ) {
			/* 爵  卞輔笛仄化中月蟈夠卞丟永本□斥 */
			int toindex = BattleArray[battleindex].Side[0].Entry[i].charaindex;
			if( CHAR_CHECKINDEX( toindex) )	{
				CHAR_talkToCli( toindex, meindex ,buf , CHAR_COLORYELLOW );
			}
		}

	}
#ifdef _NEW_WARPMAN
	}
#endif
	if( NPC_Util_GetStrFromStrWithDelim( argstr, "steal", buf, sizeof( buf)) != NULL ) {
		print("\n steal TRUE !!");
		if( atoi( buf) == 1 ) {
			int charaindex = BattleArray[battleindex].Side[0].Entry[0].charaindex;
			NPC_NPCEnemy_StealItem( argstr, meindex, charaindex);
		}
		
	}
#ifdef _ALLDOMAN // (不可開) Syu ADD 排行榜NPC
	if( NPC_Util_GetStrFromStrWithDelim( argstr, "herobattlefield", buf, sizeof( buf)) != NULL ) {
			int charaindex = BattleArray[battleindex].Side[0].Entry[0].charaindex;
			CHAR_setWorkInt ( charaindex , CHAR_WORKHEROFLOOR , atoi ( buf ) ) ;
			// Syu ADD 
			if ( atoi ( buf ) > CHAR_getInt ( charaindex , CHAR_HEROFLOOR ) )
				CHAR_setInt ( charaindex , CHAR_HEROFLOOR , atoi( buf ) ) ; 
	}

#endif
	tmp = NPC_Util_GetNumFromStrWithDelim( argstr, "dieact");
	if( tmp != 1 ) 
		tmp = 0;
	CHAR_setWorkInt( meindex, CHAR_WORK_DIEACT, tmp);
	if( CHAR_getWorkInt( meindex, CHAR_WORK_DIEACT) == 0 ) {
	    Char 	*ch;
		CHAR_setInt( meindex, CHAR_BASEIMAGENUMBER, 0);
		print("bbi---->bi10");
		CHAR_sendCToArroundCharacter( CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX));

		CHAR_setWorkInt( meindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_ALTERRATIVE);
		MAP_sendAroundMapdata( CHAR_getInt( meindex, CHAR_FLOOR),
								CHAR_getInt( meindex, CHAR_X),
								CHAR_getInt( meindex, CHAR_Y));
	    ch  = CHAR_getCharPointer( meindex);
	    if( ch != NULL ) {
			strcpysafe( ch->charfunctable[CHAR_LOOPFUNC].string,
						sizeof( ch->charfunctable[CHAR_LOOPFUNC]),
						"NPCEnemyLoop");
			CHAR_constructFunctable( meindex);
			CHAR_setInt( meindex, CHAR_LOOPINTERVAL, 5000);
			CHAR_setWorkInt( meindex, CHAR_WORK_DIETIME, NowTime.tv_sec);
		}else {
			print( "NPCENEMY:err\n");
		}
	}else {
		for( i = 0; i < 5; i ++ ) {
			toindex = BattleArray[battleindex].Side[0].Entry[i].charaindex;
			if( CHAR_CHECKINDEX( toindex) ) {
#ifdef _NEW_WARPMAN
				if( strstr( argstr, "NEWNPCENEMY") )    {
					BOOL Party=TRUE;
					if( NPC_NPCEnemy_CheckFree( meindex, toindex , &Party) == FALSE )       {
						continue;
					}
					if( Party == TRUE )	{
					}else	{
						if( CHAR_getWorkInt( toindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER )	{
							if( NPC_WarpAllMsg( meindex, toindex ) == TRUE )	{
								return TRUE;
							}
						}
						continue;
					}
				}
				CHAR_DischargeParty( toindex, 0); // 拆隊
				CHAR_warpToSpecificPoint( toindex,
					CHAR_getWorkInt( meindex, CHAR_WORK_WARP_FLOOR),
					CHAR_getWorkInt( meindex, CHAR_WORK_WARP_X),
					CHAR_getWorkInt( meindex, CHAR_WORK_WARP_Y)
					);

#else
				CHAR_warpToSpecificPoint( toindex,
								CHAR_getWorkInt( meindex, CHAR_WORK_WARP_FLOOR),
								CHAR_getWorkInt( meindex, CHAR_WORK_WARP_X),
								CHAR_getWorkInt( meindex, CHAR_WORK_WARP_Y)
								);
#endif
#ifdef _NPC_REPLACEMENT
				Check_EnemyWarpMe( meindex, argstr);
#endif
			}
		}
	}
	return TRUE;
}
Пример #12
0
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;
}
Пример #13
0
BOOL NPC_copyFunctionSetToChar( int id, Char* ch )
{
    if( id<0 || id>=arraysizeof(functionSet) )return FALSE;

    strcpysafe( ch->charfunctable[CHAR_INITFUNC].string,
                sizeof( ch->charfunctable[CHAR_INITFUNC].string ),
                functionSet[id].initfunc);

    strcpysafe( ch->charfunctable[CHAR_WALKPREFUNC].string,
                sizeof(ch->charfunctable[CHAR_WALKPREFUNC].string),
                functionSet[id].walkprefunc);

    strcpysafe( ch->charfunctable[CHAR_WALKPOSTFUNC].string,
                sizeof(ch->charfunctable[CHAR_WALKPOSTFUNC].string),
                functionSet[id].walkpostfunc);

    strcpysafe( ch->charfunctable[CHAR_PREOVERFUNC].string,
                sizeof(ch->charfunctable[CHAR_PREOVERFUNC].string),
                functionSet[id].preoverfunc);

    strcpysafe( ch->charfunctable[CHAR_POSTOVERFUNC].string,
                sizeof(ch->charfunctable[CHAR_POSTOVERFUNC].string),
                functionSet[id].postoverfunc);

    strcpysafe( ch->charfunctable[CHAR_WATCHFUNC].string,
                sizeof(ch->charfunctable[CHAR_WATCHFUNC].string),
                functionSet[id].watchfunc);

    strcpysafe( ch->charfunctable[CHAR_LOOPFUNC].string,
                sizeof(ch->charfunctable[CHAR_LOOPFUNC].string),
                functionSet[id].loopfunc);

    strcpysafe( ch->charfunctable[CHAR_TALKEDFUNC].string,
                sizeof(ch->charfunctable[CHAR_TALKEDFUNC].string),
                functionSet[id].talkedfunc);

    strcpysafe( ch->charfunctable[CHAR_DYINGFUNC].string,
                sizeof(ch->charfunctable[CHAR_DYINGFUNC].string),
                functionSet[id].dyingfunc);

    strcpysafe( ch->charfunctable[CHAR_PREATTACKEDFUNC].string,
                sizeof(ch->charfunctable[CHAR_PREATTACKEDFUNC].string),
                functionSet[id].preattackedfunc);
    strcpysafe( ch->charfunctable[CHAR_POSTATTACKEDFUNC].string,
                sizeof(ch->charfunctable[CHAR_POSTATTACKEDFUNC].string),
                functionSet[id].postattackedfunc);

    strcpysafe( ch->charfunctable[CHAR_OFFFUNC].string,
                sizeof(ch->charfunctable[CHAR_OFFFUNC].string),
                functionSet[id].offfunc );

    strcpysafe( ch->charfunctable[CHAR_LOOKEDFUNC].string,
                sizeof(ch->charfunctable[CHAR_LOOKEDFUNC].string),
                functionSet[id].lookedfunc );

    strcpysafe( ch->charfunctable[CHAR_ITEMPUTFUNC].string,
                sizeof(ch->charfunctable[CHAR_ITEMPUTFUNC].string),
                functionSet[id].itemputfunc );

    strcpysafe( ch->charfunctable[CHAR_SPECIALTALKEDFUNC].string,
                sizeof(ch->charfunctable[CHAR_SPECIALTALKEDFUNC].string),
                functionSet[id].specialtalkedfunc );

    strcpysafe( ch->charfunctable[CHAR_WINDOWTALKEDFUNC].string,
                sizeof(ch->charfunctable[CHAR_WINDOWTALKEDFUNC].string),
                functionSet[id].windowtalkedfunc );

#ifdef _USER_CHARLOOPS
    strcpysafe( ch->charfunctable[CHAR_LOOPFUNCTEMP1].string,
                sizeof(ch->charfunctable[CHAR_LOOPFUNCTEMP1].string), "");

    strcpysafe( ch->charfunctable[CHAR_LOOPFUNCTEMP2].string,
                sizeof(ch->charfunctable[CHAR_LOOPFUNCTEMP2].string), "");
#endif
    return TRUE;
}
Пример #14
0
int NPC_NPCEnemy_Encount( int meindex, int charaindex, int mode)
{

	char	argstr1[NPC_UTIL_GETARGSTR_BUFSIZE];
	char *argstr;
	char	buf[512];
	BOOL	flg = TRUE;
	int		battlemax = getBattlenum();
	int		i;
	if( CHAR_getInt( meindex, CHAR_BASEIMAGENUMBER) == 0 ) {
		return FALSE;
	}
	if( mode == 0 ) {
		if( CHAR_getWorkInt( meindex, CHAR_WORK_ENCOUNTTYPE) == 1 ) {
			flg = FALSE;
		}
	}else if( mode == 1 ) {
		if( CHAR_getWorkInt( meindex, CHAR_WORK_ENCOUNTTYPE) == 0 ) {
			flg = FALSE;
		}
	}

	argstr = NPC_Util_GetArgStr( meindex, argstr1, sizeof( argstr1));

	if( !flg) {
		if( NPC_Util_GetStrFromStrWithDelim( argstr, "deniedmsg", buf, sizeof( buf)) != NULL )	{
			CHAR_talkToCliAndParty( charaindex, meindex ,buf , CHAR_COLORYELLOW );
		}
		return FALSE;
	}
	flg = FALSE;
	while( 1 ) {
		char	buf[1024];
		if( NPC_Util_GetStrFromStrWithDelim( argstr, "item", buf, sizeof( buf)) != NULL ) {
			char	data[128];
			BOOL	found = FALSE;

			for( i = 0; i < CHAR_MAXITEMHAVE; i ++ ) {
				int		j;
				int		itemid;
				int ret = getStringFromIndexWithDelim( buf,",", i + 1,data, sizeof(data));
				if( ret == FALSE)
					break;
				found = FALSE;
				itemid = atoi( data);
				for( j = 0; j < CHAR_MAXITEMHAVE; j ++ ) {
					int itemindex = CHAR_getItemIndex( charaindex, j);
					if( ITEM_CHECKINDEX( itemindex)) {
						if( ITEM_getInt( itemindex, ITEM_ID) == itemid ) {
							found = TRUE;
							break;
						}
					}
				}
				if( !found )
					break;
			}
			if( !found )
				break;
		}
#ifdef _ADD_NOITEM_BATTLE
		if(NPC_Util_GetStrFromStrWithDelim(argstr,"noitem",buf,sizeof(buf)) != NULL){
			char data[128];
			BOOL found = FALSE;

			for(i=0;i<CHAR_MAXITEMHAVE;i++){
				int j;
				int itemid;
				int ret = getStringFromIndexWithDelim(buf,",",i + 1,data,sizeof(data));
				if(ret == FALSE) break;
				found = TRUE;
				itemid = atoi(data);
				for(j=0;j<CHAR_MAXITEMHAVE;j++){
					int itemindex = CHAR_getItemIndex(charaindex,j);
					if(ITEM_CHECKINDEX( itemindex)){
						if(ITEM_getInt(itemindex,ITEM_ID) == itemid){
							found = FALSE;
							break;
						}
					}
				}
				if(!found) break;
			}
			if(!found) break;
		}
#endif

		{
			char data[256];

			BOOL Evflg=TRUE;
			if( NPC_Util_GetStrFromStrWithDelim( argstr, "B_evend", buf, sizeof( buf)) != NULL ) {
				int i=1, event=-1;;
				while( getStringFromIndexWithDelim( buf,",", i, data, sizeof( data)) ){
					i++;
					event=atoi( data);
					if( NPC_EventCheckFlg( charaindex, event) == FALSE )	{
						Evflg = FALSE;
						break;
					}
				}
			}
			if( Evflg == FALSE )
				break;
			i=1;
			if( NPC_Util_GetStrFromStrWithDelim( argstr, "B_evnow", buf, sizeof( buf)) != NULL ) {
				int i=1, event=-1;;
				while( getStringFromIndexWithDelim( buf,",", i, data, sizeof( data)) ){
					i++;
					event=atoi( data);
					if( NPC_NowEventCheckFlg( charaindex, event) == FALSE )	{
						Evflg = FALSE;
						break;
					}
				}
			}
			if( Evflg == FALSE )
				break;
		}

		if( CHAR_getWorkInt( meindex, CHAR_WORK_ONEBATTLE ) == 1 ) {
			for( i = 0; i < battlemax; i ++ ) {
				if( BattleArray[i].use ) {
					if( BattleArray[i].createindex == meindex ) {
						break;
					}
				}
			}
			if( i != battlemax ) {
				if( NPC_Util_GetStrFromStrWithDelim( argstr, "alreadymsg", buf, sizeof( buf))
					!= NULL )
				{
					CHAR_talkToCliAndParty( charaindex, meindex ,buf , CHAR_COLORYELLOW );
				}
				return FALSE;
			}
		}
		flg = TRUE;
		break;
	}

	if( flg ) {
		/* 閡及凜反  骰允月 */
		if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE) != CHAR_PARTY_CLIENT) {
			char	config[32];
			snprintf( config, sizeof( config), "askbattlemsg1");
			/* 爵  互銨引月蟆卞撙  丟永本□斥 */
			
			
			if( NPC_Util_GetStrFromStrWithDelim( argstr, config,  buf, sizeof( buf))
				!= NULL )
			{
				int	len = strlen( buf);
				char	escapebuf[1024];
				int fd = getfdFromCharaIndex( charaindex);
				char	buf2[256];
				/* askbattlemsg? 互丐木壬  醒墊卞允月  "\n"戊□玉毛  木月)*/
				for( i = 2; i < 7; i ++ ) {
					snprintf( config, sizeof( config), "askbattlemsg%d", i);
					if( NPC_Util_GetStrFromStrWithDelim( argstr, config, buf2, sizeof( buf2))
						!= NULL )
					{
						strcpysafe( &buf[len], sizeof( buf)-len, "\n" );
						len++;
						strcpysafe( &buf[len], sizeof( buf)-len, buf2 );
						len += strlen( buf2);
						if( len >= sizeof( buf) ) {
							print( "buffer over\n");
							return FALSE;
						}
					}
					else {
						strcpysafe( &buf[len], sizeof( buf)-len, "\n" );
						len++;
						if( len >= sizeof( buf) ) {
							print( "buffer over\n");
							return FALSE;
						}
					}
				}

				if( fd != -1 ) {
					lssproto_WN_send( fd, WINDOW_MESSAGETYPE_MESSAGE,
									WINDOW_BUTTONTYPE_YESNO,
									CHAR_WINDOWTYPE_NPCENEMY_START,
									CHAR_getWorkInt( meindex, CHAR_WORKOBJINDEX),
									makeEscapeString( buf, escapebuf,sizeof(escapebuf)));
				}
				/* 仇仇分仃    卞伉正□件 */
				return FALSE;
			}else {
				/* 爵  卞  日六月 */
				flg = NPC_NPCEnemy_BattleIn( meindex, charaindex);
			}
		}
	}
	if( !flg) {
		if( NPC_Util_GetStrFromStrWithDelim( argstr, "deniedmsg", buf, sizeof( buf))
			!= NULL )
		{
			CHAR_talkToCliAndParty( charaindex, meindex ,buf , CHAR_COLORYELLOW );
		}
	}
	return flg;
}
Пример #15
0
/*------------------------------------------------------------
 * NPCTemplate °×ÑëÄÌ»ïë·òÎç¹´  ¸ê£Û
 * ¦ÐÑ
 *  filename   char*       ɬÀð×ÑëÄÌ»ïë  ÐÄ炙§ÔÂÐþÓÀÃó·¸Å«ÒÁÛÍÐþØø
 * ߯Ի°À
 *  ÔÀ      TRUE(1)
 *  ·Ö»§(³ðľ¶¯Ïþ°×ÑëÄÌ»ïë  ÊÏÆ¥·´ÖÐØêئÖÐ)
 *  ÁÃ      FALSE(0)
 ------------------------------------------------------------*/
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("Template Exceed configured buffer\n" );
        print("configured template number is %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( "This file is not a template file.\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 {. But already START state. %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( "There is no name %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("Template Exceed configured buffer\n" );
                        print("configured template number is %d\n",
                              NPC_templatenum);
                        goto FCLOSERETURNFALSE;
                    }
                }
                NPC_setDefaultNPCTemplate( &temp );
                itmreadindex=0;
                start=OFF;
            }else{
                fprint( "Unresolved '}' 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;
}
Пример #16
0
/*------------------------------------------------------------
 * ��į�������ë���£�
 * ¦��
 *  filename        char*       ɬ�ð����̻�  
 * ߯Ի��
 *  ��      TRUE(1)
 *  ��      FALSE(0)
 *------------------------------------------------------------*/
BOOL TITLE_initTitleName( char* filename )
{
	FILE*   f;
	char    line[256];
	int     linenum=0;
	int     title_readlen=0;

	f = fopen(filename,"r");
	if( f == NULL ){
		errorprint;
		return FALSE;
	}

	TITLE_titlenum=0;

	/*  ����  ��ئ�滥�ϵ�ؤ�¾�������Ʃ����    */
	while( fgets( line, sizeof( line ), f ) ){
		linenum ++;
		if( line[0] == '#' )continue;        /* comment */
		if( line[0] == '\n' )continue;       /* none    */
		chomp( line );

		TITLE_titlenum++;
	}

	if( fseek( f, 0, SEEK_SET ) == -1 ){
		fprint( "Ѱ�Ҵ���\n" );
		fclose(f);
		return FALSE;
	}

	TITLE_table = allocateMemory( sizeof(struct tagTITLE_Table)
								   * TITLE_titlenum );
	if( TITLE_table == NULL ){
		fprint( "�޷������ڴ� %d\n" ,
				sizeof(TITLE_table)*TITLE_titlenum);
		fclose( f );
		return FALSE;
	}
	/* ����� */
{
	int     i;
	for( i = 0; i < TITLE_titlenum; i ++ ) {
		TITLE_table[i].index = -1;
		TITLE_table[i].name[0] = '\0';
		TITLE_table[i].functype = TITLE_FUNCTYPENONE;
		TITLE_table[i].definefunction = NULL;
	}
	
}

	/*  ����  ��  ��    */
	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;

		/*  ���繴���������ͼ�ëέ��    */
		ret = getStringFromIndexWithDelim( line,",",1,token,
										   sizeof(token));
		if( ret==FALSE ){
			fprint("�ļ��﷨����:%s ��%d��\n",filename,linenum);
			continue;
		}
		TITLE_table[title_readlen].index = atoi(token);

		/*  2�����������ͼ�ëέ��    */
		ret = getStringFromIndexWithDelim( line,",",2,token,
										   sizeof(token));
		if( ret==FALSE ){
			fprint("�ļ��﷨����:%s ��%d��\n",filename,linenum);
			continue;
		}
		if( strlen( token) > sizeof( TITLE_table[title_readlen].name)-1) {
			fprint("����! ͷ�����ƽ����ļ�:%s ��%d��\n",
					filename, linenum);
		}
		strcpysafe( TITLE_table[title_readlen].name, 
					sizeof( TITLE_table[title_readlen].name),
					token);

		title_readlen ++;
}
	}
	fclose(f);

	TITLE_titlenum = title_readlen;

	print( "��Чͷ���������� %d...", TITLE_titlenum );

#ifdef DEBUG

	{
		int i;
		for( i=0; i <TITLE_titlenum ; i++ )
			print( "ͷ������[%d] ����[%s] \n",
				   TITLE_table[i].index,
				   TITLE_table[i].name);
	}
#endif
	return TRUE;
}
Пример #17
0
void CHAR_Talk(int fd, int index, char *message, int color, int area) {
  char firstToken[64];
  char messageeraseescape[512];
  char *messagebody;
  int mesgvolume = 0;
  int lastvolume = 0;
  int fl, x, y;
  int stringlen;
  int micflg = 0;

  int fmindexi = CHAR_getWorkInt(index, CHAR_WORKFMINDEXI);
  int channel = CHAR_getWorkInt(index, CHAR_WORKFMCHANNEL);
  int quickchannel = CHAR_getWorkInt(index, CHAR_WORKFMCHANNELQUICK);
  {
    char *cdkey = CHAR_getChar(index, CHAR_CDKEY);
    char *charname = CHAR_getChar(index, CHAR_NAME);
    if(strlen(message) > 3) {
      if(CHAR_getWorkInt(index, CHAR_WORKFLG) & WORKFLG_DEBUGMODE) {
        // shan begin
        if(strstr(message, "[") && strstr(message, "]")) {
        } else {
          // original
          LogTalk(charname, cdkey, CHAR_getInt(index, CHAR_FLOOR),
                  CHAR_getInt(index, CHAR_X), CHAR_getInt(index, CHAR_Y),
                  message);
        }
        // end
      }
    }
  }
  //bg|0|r0|fc|d4B8|p0|bn|10|bt|10|
  // Nuke +1 08/27: For invalid message attack
  if(*message == 0)
    return;
  CHAR_getMessageBody(message, firstToken, sizeof(firstToken),
                      &messagebody);
  // Nuke +1: For invalid message attack
  if(!messagebody)
    return;

  strcpysafe(messageeraseescape, sizeof(messageeraseescape),
             messagebody);
  makeStringFromEscaped(messageeraseescape);
  stringlen = strlen(messageeraseescape);
  if(stringlen <= 0)
    return;

  if(messageeraseescape[0] == '['
     && messageeraseescape[stringlen - 1] == ']') {
    char gm[128];
    char *pass = strstr(messageeraseescape + 1, getChatMagicPasswd());
    // Arminius: limit ip +2
    char* ip = CONNECT_get_userip(fd);
    messageeraseescape[stringlen - 1] = '\0';
    // Arminius: limit ip
    if(pass == messageeraseescape + 1) {
      if(CHAR_useChatMagic(index, messageeraseescape + 1 + strlen(getChatMagicPasswd()) + 1, TRUE)) {
        print("\n账号:%s 名字:%s\n来自ip:%s\n使用GM命令%s]\n", CHAR_getChar(index, CHAR_CDKEY), CHAR_getChar(index, CHAR_NAME), ip, messageeraseescape);
        sprintf(gm, "您使用GM命令%s]已成功", messageeraseescape);
        CHAR_talkToCli(index, -1, gm, CHAR_COLORYELLOW);
      }
    } else {
      if(CHAR_getWorkInt(index, CHAR_WORKFLG) & WORKFLG_DEBUGMODE) {
        if(CHAR_useChatMagic(index, messageeraseescape + 1, TRUE)) {
          print("\n账号:%s 名字:%s\n来自ip:%s\n使用GM命令%s]\n", CHAR_getChar(index, CHAR_CDKEY), CHAR_getChar(index, CHAR_NAME), ip, messageeraseescape);
          sprintf(gm, "您使用GM命令%s]已成功", messageeraseescape);
          CHAR_talkToCli(index, -1, gm, CHAR_COLORYELLOW);
        }
      } else {
#ifdef _GM_ITEM
        if(CHAR_getInt( index, CHAR_GMTIME)>0){
          char magicname[32];
          char token[64];
          getStringFromIndexWithDelim( messageeraseescape + 1, " ", 1, magicname,  sizeof( magicname));
          if(!strcmp( CHAR_getChar( index, CHAR_GMFUNCTION), magicname)){
            player_useChatMagic( index,messageeraseescape + 1,TRUE);
            print( "\n账号:%s 名字:%s\n来自ip:%d.%d.%d.%d\n使用物品命令%s]次数剩下%d\n", CHAR_getChar( index, CHAR_CDKEY),
                              CHAR_getChar( index, CHAR_NAME), a, b, c, d,messageeraseescape, CHAR_getInt( index, CHAR_GMTIME) - 1);
            CHAR_setInt( index , CHAR_GMTIME, CHAR_getInt( index, CHAR_GMTIME) - 1 );
            if(CHAR_getInt( index, CHAR_GMTIME) > 0){
              sprintf( token, "你还能使用%s权限%d次!", CHAR_getChar( index, CHAR_GMFUNCTION),CHAR_getInt( index, CHAR_GMTIME));
              CHAR_talkToCli( index, -1,token, CHAR_COLORRED );
            }else{
              sprintf( token, "你已经没有使用%s权限了!", CHAR_getChar( index, CHAR_GMFUNCTION));
              CHAR_talkToCli( index, -1,token, CHAR_COLORRED );
            }
          }else if(!strcmp( "help", magicname) || !strcmp( "帮助", magicname)){
            getStringFromIndexWithDelim( messageeraseescape + 1, " ", 2, magicname,  sizeof( magicname));
            if(!strcmp( CHAR_getChar( index, CHAR_GMFUNCTION), magicname)){
              player_useChatMagic( index,messageeraseescape + 1,TRUE);
              print( "\n账号:%s 名字:%s\n来自ip:%d.%d.%d.%d\n使用帮助命令%s]\n", CHAR_getChar( index, CHAR_CDKEY),
                              CHAR_getChar( index, CHAR_NAME), a, b, c, d,messageeraseescape);
            }
          }
        }else
#endif
        CHAR_useChatMagic(index, messageeraseescape + 1, FALSE);
      }
    }
    messageeraseescape[stringlen - 1] = ']';
    return;
  } else {
    if(CHAR_getWorkInt(index, CHAR_WORKFLG) & WORKFLG_DEBUGMODE) {
      if(strstr(messageeraseescape, "[") != NULL ||
         strstr(messageeraseescape, "]") != NULL) {
        return;
      }
    }
  }

#ifdef _PLAYER_MOVE
  if(getPMove() != -1) {
    if(messageeraseescape[0] == '/' && messageeraseescape[1] == 'g' && messageeraseescape[2] == 'o') {
      int point = CHAR_getInt(index, CHAR_AMPOINT);
      if(point > getPMove() || getPMove() == 0) {
        char x[4], y[4];
        easyGetTokenFromString(messageeraseescape, 2, x, sizeof(x));
        easyGetTokenFromString(messageeraseescape, 3, y, sizeof(y));
        CHAR_warpToSpecificPoint(index, CHAR_getInt(index, CHAR_FLOOR), atoi(x), atoi(y));
        CHAR_setInt(index, CHAR_AMPOINT, point - getPMove());
      } else
        CHAR_talkToCli(index, -1, "你已经没有足够的会员点数顺移了!", CHAR_COLORRED);
      return;
    }
  }
#endif

#ifdef _PLAYER_ANNOUNCE
  if(getPAnnounce() != -1) {
    if(messageeraseescape[0] == '/' && messageeraseescape[1] == 'g' && messageeraseescape[2] == 'g') {

      int point = CHAR_getInt(index, CHAR_AMPOINT);
      if(point > getPAnnounce() || getPAnnounce() == 0) {
        int i;
        int playernum = CHAR_getPlayerMaxNum();
        char buff[255];
        char xlbmsg[255];
        char *MyName = CHAR_getChar(index, CHAR_NAME);

        easyGetTokenFromString(messageeraseescape, 2, buff, sizeof(buff));
        for(i = 0; i < playernum; i++) {
          if(CHAR_getCharUse(i) != FALSE)
            sprintf(xlbmsg, "<小喇叭>%s说:%s", MyName, buff);
          CHAR_talkToCli(i, -1, xlbmsg, CHAR_COLORGREEN);
        }
        CHAR_setInt(index, CHAR_AMPOINT, point - getPAnnounce());
      } else
        CHAR_talkToCli(index, -1, "你已经没有足够的会员点数小喇叭了!", CHAR_COLORRED);
      return;
    }
  }
#endif

#ifdef _TALK_ACTION
  TalkAction(index, messageeraseescape);
#endif

  mesgvolume = CHAR_getVolume(messageeraseescape);
  if(area == 0) area = 3;
  if(mesgvolume == -1) lastvolume = -1;
  else lastvolume = area - 1 + mesgvolume;
  if(CHAR_getWorkInt(index, CHAR_WORKFLG) & WORKFLG_MICMODE) {
    lastvolume = 15;
    micflg = 1;
  }
  fl = CHAR_getInt(index, CHAR_FLOOR);
  x = CHAR_getInt(index, CHAR_X);
  y = CHAR_getInt(index, CHAR_Y);
  // Robin 0705 channel
  if(messageeraseescape[0] == ':') {
    if((channel == -1) && (quickchannel != -1))
      channel = quickchannel;
    else if(channel != -1)
      channel = -1;
  }
  {
    typedef void (*TALKF)(int, int, char *, int, int);
    TALKF talkedfunc = NULL;
    talkedfunc = (TALKF) CHAR_getFunctionPointer(index, CHAR_TALKEDFUNC);
    if(talkedfunc) {
      talkedfunc(index, index, messageeraseescape, color, channel);
    }

  }
  if(lastvolume == -1) {
    int j;
    int xx[2] = {x, x + CHAR_getDX(CHAR_getInt(index, CHAR_DIR))};
    int yy[2] = {y, y + CHAR_getDY(CHAR_getInt(index, CHAR_DIR))};
    int talk = FALSE;
    for(j = 0; j < 2; j++) {
      OBJECT object;
      for(object = MAP_getTopObj(fl, xx[j], yy[j]); object; object = NEXT_OBJECT(object)) {
        int objindex = GET_OBJINDEX(object);
        int toindex = OBJECT_getIndex(objindex);
        if(OBJECT_getType(objindex) == OBJTYPE_CHARA && toindex != index) {
          if(CHAR_Talk_check(index, toindex, 0)) {
            typedef void (*TALKF)(int, int, char *, int, int);
            TALKF talkedfunc = NULL;
            talkedfunc = (TALKF) CHAR_getFunctionPointer(toindex, CHAR_TALKEDFUNC);
            if(talkedfunc) {
              talkedfunc(toindex, index, messageeraseescape, color, -1);
            }
            if(CHAR_getInt(toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) {
              talk = TRUE;
            }
          }
        }
      }
    }
    if(talk)CHAR_setInt(index, CHAR_TALKCOUNT, CHAR_getInt(index, CHAR_TALKCOUNT) + 1);
  } else {
    int range = CHAR_getRangeFromVolume(lastvolume);
    int i, j;
    int talk = FALSE;
    int channelTalk = FALSE;
    int partyindex[CHAR_PARTYMAX];
    for(i = 0; i < CHAR_PARTYMAX; i++) {
      partyindex[i] = -1;
    }
    if(CHAR_getWorkInt(index, CHAR_WORKPARTYMODE) != CHAR_PARTY_NONE) {
      for(i = 0; i < CHAR_PARTYMAX; i++) {
        int toindex = CHAR_getPartyIndex(index, i);
        if(CHAR_CHECKINDEX(toindex) && toindex != index) {
          typedef void (*TALKF)(int, int, char *, int, int);
          TALKF talkedfunc = NULL;
          talkedfunc = (TALKF) CHAR_getFunctionPointer(toindex, CHAR_TALKEDFUNC);
          if(talkedfunc)
            talkedfunc(toindex, index, messageeraseescape, color, -1);
          talk = TRUE;
          partyindex[i] = toindex;
        }
      }
    }
    if(channel > -1 && fmindexi >= 0) {
      int i, tindex;

      channelTalk = TRUE;
      i = 0;
#ifdef _FMVER21
      if(channel == FAMILY_MAXCHANNEL && CHAR_getInt(index, CHAR_FMLEADERFLAG) == FMMEMBER_LEADER)
#else
        if( channel == FAMILY_MAXCHANNEL && CHAR_getInt( index, CHAR_FMLEADERFLAG ) == 1)
#endif
      {
        char buf[512];
        sprintf(buf, "[族长广播]%s: %s", CHAR_getChar(index, CHAR_NAME), messageeraseescape);
        saacproto_ACFMAnnounce_send(acfd,
                                    CHAR_getChar(index, CHAR_FMNAME),
                                    CHAR_getInt(index, CHAR_FMINDEX),
                                    CHAR_getWorkInt(index, CHAR_WORKFMINDEXI),
                                    buf,
                                    color
        );
        return;
      }
      else

        for(i = 0; i < FAMILY_MAXMEMBER; i++) {
          tindex = channelMember[fmindexi][channel][i];
          if(!CHAR_CHECKINDEX(tindex))
            continue;
          if(tindex >= 0 && tindex != index) {
            typedef void (*TALKF)(int, int, char *, int, int);
            TALKF talkedfunc = NULL;

            talkedfunc = (TALKF) CHAR_getFunctionPointer(tindex, CHAR_TALKEDFUNC);

            if(talkedfunc)
              talkedfunc(tindex, index, messageeraseescape, color, channel);
          }
        }

      talk = TRUE;

    } else {
      for(i = x - range / 2; i <= x + range / 2; i++) {
        for(j = y - range / 2; j <= y + range / 2; j++) {
          OBJECT object;
          for(object = MAP_getTopObj(fl, i, j); object; object = NEXT_OBJECT(object)) {
            int objindex = GET_OBJINDEX(object);
            int toindex = OBJECT_getIndex(objindex);
            if(OBJECT_getType(objindex) == OBJTYPE_CHARA && toindex != index) {
              int k;
              for(k = 0; k < CHAR_PARTYMAX; k++) {
                if(toindex == partyindex[k]) {
                  break;
                }
              }
              if(k != CHAR_PARTYMAX)
                continue;
              if(CHAR_Talk_check(index, toindex, micflg)) {
                typedef void (*TALKF)(int, int, char *, int, int);
                TALKF talkedfunc = NULL;
                talkedfunc = (TALKF) CHAR_getFunctionPointer(toindex, CHAR_TALKEDFUNC);
                if(talkedfunc) {
                  talkedfunc(toindex, index, messageeraseescape, color, -1);
                }
                if(CHAR_getInt(toindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER) {
                  talk = TRUE;
                }
              }
            }
          }
        }
      }
    }
    if(talk) {
      CHAR_setInt(index, CHAR_TALKCOUNT, CHAR_getInt(index, CHAR_TALKCOUNT) + 1);
    }
    if(CHAR_getInt(index, CHAR_POPUPNAMECOLOR) != color) {
      CHAR_setInt(index, CHAR_POPUPNAMECOLOR, color);
      if(talk) {
        int opt[1];
        opt[0] = color;
        CHAR_sendWatchEvent(CHAR_getWorkInt(index, CHAR_WORKOBJINDEX),
                            CHAR_ACTPOPUPNAME, opt, 1, FALSE);
      }
    }
  }
}
Пример #18
0
// 将 profession.txt 载入
BOOL PROFESSION_initSkill( char *filename)
{

	FILE*   f;
    char    line[256];
    int     linenum=-1;
	int     skill_readlen=0;
	int		i, j;

	int max_skillid = 0;

    f = fopen(filename,"r");
    if( f == NULL ){
        print( "file open error\n");
        return FALSE;
    }

    profession_skill_num=0;

    while( fgets( line, sizeof( line ), f ) ){
		char    token[256];

        linenum ++;
        if( line[0] == '#' )continue;
        if( line[0] == '\n' )continue;
        chomp( line );
        profession_skill_num++;
#ifdef _PROSKILL_OPTIMUM // Robin 取出最大职技ID
		if( getStringFromIndexWithDelim( line, ",", 
				PROFESSION_SKILL_DATACHARNUM+PROFESSION_SKILL_ID+1,
				token, sizeof(token)) == FALSE )
			continue;
		max_skillid = max( atoi( token), max_skillid);
#endif
    }

    if( fseek( f, 0, SEEK_SET ) == -1 ){
        fprint( "Seek Error\n" );
        fclose(f);
        return FALSE;
    }

#ifdef _PROSKILL_OPTIMUM // 职技Table数为 最大技能ID +1
	profession_skill_num = max_skillid +1;
	print("最大职技ID = %d ...", max_skillid);
#endif

	PROFESSION_skill = allocateMemory( sizeof(struct tagProfessionkill) * profession_skill_num + 1 );


	if( PROFESSION_skill == NULL ){
        fprint( "无法分配内存 %d\n", sizeof(struct tagProfessionkill)*profession_skill_num);
        fclose( f );
        return FALSE;
    }

	// init skill
    for( i = 0; i < profession_skill_num; i ++ ) {
    	for( j = 0; j < PROFESSION_SKILL_DATAINTNUM; j ++ )
    		PROFESSION_SKILL_setInt( i,j,-1);
    
    	for( j = 0; j < PROFESSION_SKILL_DATACHARNUM; j ++ ) 
    		PROFESSION_SKILL_setChar( i,j,"");    
    }

    linenum = -1;
    while( fgets( line, sizeof( line ), f ) ){
        linenum ++;
        if( line[0] == '#' )continue;
        if( line[0] == '\n' )continue;             
                
        chomp( line );

        replaceString( line, '\t' , ' ' );

		{
		    char    buf[256];
			for( i = 0; i < strlen( line); i ++) {
				if( line[i] != ' ' ) {
					break;
				}
				strcpysafe( buf,sizeof(buf), &line[i]);
			}
			
			if( i != 0 ) {
				strcpysafe( line,sizeof(line), buf);
			}
		}  
		{
			char    token[256];
			int     ret;

#ifdef _PROSKILL_OPTIMUM // 读取本行职技的ID, 直接以职技ID当Table index
			ret = getStringFromIndexWithDelim( line, ",", PROFESSION_SKILL_DATACHARNUM+PROFESSION_SKILL_ID+1, token, sizeof(token));
			if( ret==FALSE ){
				//fprint("Syntax Error file:%s line:%d\n",filename,linenum);
				break;
			}
			skill_readlen = atoi( token);
#endif
			for( i = 0; i < PROFESSION_SKILL_DATACHARNUM; i ++ ) {

			    ret = getStringFromIndexWithDelim( line,",", i + 1, token,sizeof(token));
				if( ret==FALSE ){
					//fprint("Syntax Error file:%s line:%d\n",filename,linenum);
					break;
				} 
				PROFESSION_SKILL_setChar( skill_readlen, i, token);
			} 

			for( i = 0; i < PROFESSION_SKILL_DATAINTNUM; i ++ ) {
				ret = getStringFromIndexWithDelim( line, ",", i+PROFESSION_SKILL_DATACHARNUM+1, token, sizeof(token));
				
				if( ret==FALSE ){
					//fprint("文件语法错误:%s 第%d行\n",filename,linenum);
					break;
				} 
				if( strlen( token) != 0 ) {
					PROFESSION_SKILL_setInt( skill_readlen, i , atoi( token ));
				} 
			}         		
			skill_readlen ++;
		} 		
    } 
    fclose(f);

    profession_skill_num = skill_readlen;

	for( i = 0; i < arraysizeof( PROFESSION_SKILL_functbl); i ++ ){
		PROFESSION_SKILL_functbl[i].hash = hashpjw( PROFESSION_SKILL_functbl[i].functionname );
	}

    return TRUE;

}
Пример #19
0
/*
 * This function was borrowed from cdialog-0.9a "util.c" (and sligthly changed)...
 *
 * Change embedded "\n" substrings to '\n' characters and tabs to single
 * spaces.  If there are no "\n"s, it will strip all extra spaces, for
 * justification.  If it has "\n"'s, it will preserve extra spaces.  If cr_wrap
 * is set, it will preserve '\n's.
 */
void trim_string(char *s0, char *s, int max_len)
{
	char *p1;
	char *p = s;
	int has_newlines = 0;

	strcpysafe(s, s0, max_len);

	if (strstr(s, "\\n"))
		has_newlines = 1;

	while (*p != '\0') {
		if (*p == '\t')
			*p = ' ';

		if (*p == '\\' && *(p + 1) == 'n') {
			*s++ = '\n';
			p += 2;
			p1 = p;
			/*
			 * Handle end of lines intelligently.  If '\n' follows "\n" then
			 * ignore the '\n'.  This eliminates the need escape the '\n'
			 * character (no need to use "\n\").
			 */
			while (*p1 == ' ')
				p1++;
			if (*p1 == '\n')
				p = p1 + 1;
		} else {
			if (has_newlines) {	/* If prompt contains "\n" strings */
				if (*p == '\n') {
					if (Xdialog.cr_wrap)
						*s++ = *p++;
					else {
						/* Replace the '\n' with a space if cr_wrap is not set */
						if (*(s - 1) != ' ')
							*s++ = ' ';
						p++;
					}
				} else		/* If *p != '\n' */
					*s++ = *p++;
			} else {		/* If there are no "\n" strings */
				if (*p == ' ') {
					if (*(s - 1) != ' ') {
						*s++ = ' ';
						p++;
					} else
						p++;
				} else if (*p == '\n') {
					if (Xdialog.cr_wrap)
						*s++ = *p++;
					else if (*(s - 1) != ' ') {
						/* Strip '\n's if cr_wrap is not set. */
						*s++ = ' ';
						p++;
					} else
						p++;
				} else
					*s++ = *p++;
			}
		}
	}

	*s = '\0';
}
Пример #20
0
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;
}
Пример #21
0
static void CHAR_clairvoyance( int charaindex )
{
    char    onebuf[128];
    int     stringlen=0;
    int     clairvoyancelevel;
    int     centerx,centery,fl;
    int     i,j;
    BOOL    sendclairvoyance=FALSE;

#define CHAR_CLAIRVOYANCEWIDTH  81
    BOOL (*clairvoyancefunc[])(int,char*) = {
        CHAR_clairvoyance_gold,
        CHAR_clairvoyance_item,
        CHAR_clairvoyance_player,
        CHAR_clairvoyance_enemy,
    };
    if( CHAR_getWorkInt( charaindex, CHAR_WORKLOOPSTARTSEC)%10 != 0 )
        return;

    clairvoyancelevel = CHAR_getInt(charaindex,CHAR_RADARSTRENGTH );

    if( clairvoyancelevel <= 0 )return;
    if( clairvoyancelevel > arraysizeof( clairvoyancefunc ) )
        clairvoyancelevel = arraysizeof( clairvoyancefunc );

    centerx = CHAR_getInt(charaindex,CHAR_X);
    centery = CHAR_getInt(charaindex,CHAR_Y);
    fl = CHAR_getInt(charaindex,CHAR_FLOOR);


    for( i = centerx - CHAR_CLAIRVOYANCEWIDTH/2 ;
            i < centerx + CHAR_CLAIRVOYANCEWIDTH/2 ; i ++ ) {
        for( j = centery - CHAR_CLAIRVOYANCEWIDTH/2 ;
                j < centery + CHAR_CLAIRVOYANCEWIDTH/2 ; j ++ ) {
            OBJECT  object;
            for( object = MAP_getTopObj(fl,i,j) ; object ;
                    object = NEXT_OBJECT( object ) ) {
                int     objindex = GET_OBJINDEX(object);
                int     loop;

                if( OBJECT_getType(objindex) == OBJTYPE_NOUSE )continue;
                if( OBJECT_getType(objindex) == OBJTYPE_CHARA
                        && OBJECT_getIndex(objindex) == charaindex) continue;
                for( loop = 0 ; loop < clairvoyancelevel ; loop ++ ) {
                    BOOL    ret;
                    char    id;
                    ret = clairvoyancefunc[loop](objindex,&id);
                    if( ret == TRUE ) {
                        sendclairvoyance=TRUE;
                        snprintf( onebuf,sizeof(onebuf),
                                  "%d|%d|%c|",i,j,id );
                        strcpysafe( CHAR_clairvoyanceString + stringlen,
                                    sizeof(CHAR_clairvoyanceString)
                                    - stringlen,   onebuf);
                        stringlen += strlen(onebuf);
                        if( stringlen > sizeof(CHAR_clairvoyanceString) )
                            goto RETURN;
                    }
                }
            }
        }
    }

RETURN:
    if( stringlen >= 1 ) {
        int fd;
        fd = getfdFromCharaIndex( charaindex );
        dchop( CHAR_clairvoyanceString, "|" );
        if( fd != -1 )
            lssproto_R_send( fd, CHAR_clairvoyanceString );
    } else if( !sendclairvoyance ) {
        int fd;
        fd = getfdFromCharaIndex( charaindex );
        if( fd != -1 )
            lssproto_R_send( fd, "" );
    }
}
Пример #22
0
/*
 * 玉失日仄中涩烂毛允月卞反}仇仇匹
 * maxhp , maxmp , level , str , tough 毛0卞允月午方中[
 *
 */
int NPC_DoorInit( int meindex )
{
    char arg[NPC_UTIL_GETARGSTR_BUFSIZE];
    char settingdir[1024];
    char buf[256];

    NPC_Util_GetArgStr( meindex, arg, sizeof( arg));
    CHAR_setWorkInt( meindex, CHAR_WORKEVENTTYPE,CHAR_EVENT_NPC);

    getStringFromIndexWithDelim(arg, "|" , 1 , buf,sizeof(buf) );
    CHAR_setWorkInt( meindex , CHAR_WORKDOOROPENG , atoi( buf ));
    getStringFromIndexWithDelim(arg, "|" , 2 , buf,sizeof(buf) );
    CHAR_setWorkInt( meindex , CHAR_WORKDOORCLOSEG , atoi( buf ));
    getStringFromIndexWithDelim(arg, "|" , 3 , buf,sizeof(buf) );
    CHAR_setWorkChar( meindex , CHAR_WORKDOORNAME , buf );
    strcpysafe( settingdir,sizeof( settingdir) , buf );
    getStringFromIndexWithDelim(arg, "|" , 4 , buf,sizeof(buf) );
    CHAR_setWorkInt( meindex , CHAR_WORKDOORSWITCHCOUNT , atoi( buf ));
    getStringFromIndexWithDelim(arg, "|" , 5 , buf,sizeof(buf) );
    CHAR_setWorkInt( meindex , CHAR_WORKDOORCLOSETIME , atoi( buf ));

    CHAR_setInt( meindex , CHAR_MERCHANTLEVEL , atoi( buf ));
    getStringFromIndexWithDelim(arg, "|" , 6 , buf,sizeof(buf) );
    CHAR_setWorkInt( meindex , CHAR_WORKDOORSOONFLG , atoi( buf ));

    getStringFromIndexWithDelim(arg, "|" , 7 , buf,sizeof(buf) );
    CHAR_setWorkInt( meindex , CHAR_WORKDOORPASSFLG , atoi( buf ));
    CHAR_setWorkInt( meindex , CHAR_WORKDOORORIGINALGRAPHIC,
                     CHAR_getInt( meindex,CHAR_BASEIMAGENUMBER ));
    CHAR_setInt( meindex, CHAR_LV, 0 );
    if( getStringFromIndexWithDelim( arg , "|" , 8 , buf ,sizeof( buf ))){
        if( strncmp( buf , "title" ,5 ) == 0 ){
            print( "This is a title door:'%s'\n" , buf );
            CHAR_setWorkInt( meindex , CHAR_WORKDOORPASSFLG ,0 );
            CHAR_setWorkChar( meindex , CHAR_WORKDOORTITLE , buf );
            CHAR_setInt( meindex, CHAR_LV, 1 );
        } else if( isdigit( buf[0] )){
            if( getStringFromIndexWithDelim(arg, "|" , 8 , buf,sizeof(buf) ))
                CHAR_setWorkChar( meindex, CHAR_WORKDOORGOLDLIMIT, buf);
            if( getStringFromIndexWithDelim(arg, "|" , 10 , buf,sizeof(buf) ))
                CHAR_setWorkChar( meindex, CHAR_WORKDOORWEEK, buf);
            if( getStringFromIndexWithDelim(arg, "|" , 11 , buf,sizeof(buf) ))
                CHAR_setWorkChar( meindex, CHAR_WORKDOORHOUR, buf);
            if( getStringFromIndexWithDelim(arg, "|" , 12 , buf,sizeof(buf) ))
                CHAR_setWorkChar( meindex, CHAR_WORKDOORMINUTE, buf);
        }
    }

    CHAR_setInt( meindex , CHAR_HP , 0 );
    CHAR_setInt( meindex , CHAR_MP , 0 );
    CHAR_setInt( meindex , CHAR_MAXMP , 0 );
    CHAR_setInt( meindex , CHAR_STR , 0 );
    CHAR_setInt( meindex , CHAR_TOUGH, 0 );
    {
        int g = CHAR_getWorkInt( meindex , CHAR_WORKDOOROPENG );
        if( g >= 11900 && g <= 11915 ){
            CHAR_setWorkInt( meindex , CHAR_WORKDOORKEYITEMID , 15 );
        } else if( g >= 11916 && g <= 11931 ){

            CHAR_setWorkInt( meindex , CHAR_WORKDOORKEYITEMID , 16 );
        } else {
            CHAR_setWorkInt( meindex , CHAR_WORKDOORKEYITEMID , -1 );
        }
        if(CHAR_getWorkInt( meindex , CHAR_WORKDOORPASSFLG )==2){
            CHAR_setWorkInt( meindex , CHAR_WORKDOORKEYITEMID , -2 );
        }
        if( CHAR_getInt( meindex , CHAR_BASEIMAGENUMBER ) ==
            ROPEGRAPHIC ){
            CHAR_setWorkInt( meindex , CHAR_WORKDOORKEYITEMID,-2 );
        }
    }

    {
        int closeg = CHAR_getWorkInt( meindex , CHAR_WORKDOORCLOSEG );
        int dir = -1;
        switch( closeg ){
            case 11900: dir = 6; break;  /* 霁及玉失 夫分曰仄凶 */
            case 11902: dir = 0; break;  /*          夫分曰丹尹 */
            case 11904: dir = 2; break;  /*          心亢丹尹 */
            case 11906: dir = 4; break;  /*          心亢仄凶 */

            case 11908: dir = 6; break;  /* 赢中霁及玉失 夫分曰仄凶 */
            case 11910: dir = 0; break;  /*              夫分曰丹尹 */
            case 11912: dir = 2; break;  /*              心亢丹尹 */
            case 11914: dir = 4; break;  /*              心亢仄凶 */

            case 11916: dir = 6; break;  /* 嗡及玉失 夫分曰仄凶 */
            case 11918: dir = 0; break;  /*          夫分曰丹尹 */
            case 11920: dir = 2; break;  /*          心亢丹尹 */
            case 11922: dir = 4; break;  /*          心亢仄凶 */

            case 11924: dir = 6; break;  /* 赢中嗡及玉失 夫分曰仄凶 */
            case 11926: dir = 0; break;  /*              夫分曰丹尹 */
            case 11928: dir = 2; break;  /*              心亢丹尹 */
            case 11930: dir = 4; break;  /*              心亢仄凶 */

            case 11958: dir = 2; break;  /* 赢中  及玉失 心亢丹尹 */
            case 11960: dir = 4; break;  /*              心亢仄凶 */
            case 11962: dir = 6; break;  /*              夫分曰仄凶 */
            case 11964: dir = 0; break;  /*              夫分曰丹尹 */

            case 11966: dir = 2; break;  /*   及玉失 心亢丹尹 */
            case 11968: dir = 4; break;  /*          心亢仄凶 */
            case 11970: dir = 6; break;  /*          夫分曰仄凶 */
            case 11972: dir = 0; break;  /*          夫分曰丹尹 */

            case 11978: dir = 2; break;  /* 赢中嗯及玉失 心亢丹尹 */
            case 11980: dir = 4; break;  /*              心亢仄凶 */
            case 11982: dir = 6; break;  /*              夫分曰仄凶 */
            case 11984: dir = 0; break;  /*              夫分曰丹尹 */

            case 11986: dir = 2; break;  /* 嗯及玉失 心亢丹尹 */
            case 11988: dir = 4; break;  /*          心亢仄凶 */
            case 11990: dir = 6; break;  /*          夫分曰仄凶 */
            case 11992: dir = 0; break;  /*          夫分曰丹尹 */

            default: break;
        }
        if( dir >= 0 )CHAR_setInt(meindex,CHAR_DIR,dir);
    }

    CHAR_setInt( meindex , CHAR_WHICHTYPE , CHAR_TYPEDOOR );
    CHAR_setFlg( meindex , CHAR_ISATTACKED , 0 );
    CHAR_setInt( meindex , CHAR_WORKDOORSWITCHCURRENT , 0 );
    CHAR_setWorkInt( meindex, CHAR_WORKDOOREXPIRETIME, 0xffffffff);
    if( CHAR_getWorkInt( meindex , CHAR_WORKDOORPASSFLG ) == 1){
        NPC_ROOMINFO roominfo;
        if( NPC_RoomAdminNew_ReadFile( CHAR_getWorkChar( meindex, CHAR_WORKDOORNAME), &roominfo) == TRUE ){
            NPC_DoorSetPasswd( meindex, roominfo.passwd);
            CHAR_setWorkInt( meindex, CHAR_WORKDOOREXPIRETIME, roominfo.expire);
        }else {
            NPC_DoorSetPasswd( meindex, "8hda8iauia90494jasd9asodfasdf89" );
            if( getStringFromIndexWithDelim(arg, "|" , 13 , buf,sizeof(buf) ))
            if( strlen( buf) != 0 )
                NPC_DoorSetPasswd( meindex, buf );
        }
    }

    CHAR_setInt( meindex, CHAR_BASEIMAGENUMBER , CHAR_getWorkInt(meindex, CHAR_WORKDOORCLOSEG));
    NPC_DoorRefreshOverFlg( meindex );
    CHAR_setWorkInt( meindex, CHAR_WORKEVENTTYPE, CHAR_EVENT_NPC);
    return TRUE;
}
Пример #23
0
static int NPC_readCreateFile( char* filename )
{
    FILE*   f;
    char    line[512];
    int     linenum=0;
    int     start=OFF;
    NPC_Create  cr;
    int     enemyreadindex=0;

    typedef struct tagPOINT
    {
        int x,y;
    }POINT;
    typedef struct tagREC
    {
        int w,h;
    }REC;
    POINT   center[2]={{0,0},{0,0}};     /*  born が 0 で move が 1 */
    REC     wh[2]    ={{0,0},{0,0}};      /*  born が 0 で move が 1 */

    POINT   lu[2]    ={{0,0},{0,0}};     /*  born が 0 で move が 1 */
    POINT   rd[2]    ={{0,0},{0,0}};     /*  born が 0 で move が 1 */

    int     defborn=FALSE;              /*  born を設定したかどうか */
    int     defmove=FALSE;              /*  move を設定したかどうか */
    int     deflurd[2]={FALSE,FALSE};   /*  lu,rd で設定したかどうか */
    char*   ret;


    if( NPC_create_readindex >= NPC_createnum ){
        print("Create Exceed configured buffer\n" );
        print("configured createnumber is %d\n",NPC_createnum);
        print("Unread File:%s\n",filename);
        return FALSE;
    }

    NPC_setDefaultNPCCreate( &cr );

    f= fopen( filename ,"r");
    if( f == NULL )return FALSE;

    ret = fgets( line, sizeof( line ), f );
    if( ret == NULL )goto FCLOSERETURNFALSE;
    if( strcmp( NPC_CREATEFILEMAGIC, line ) != 0 ){
        print( "This file is not a create file.\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 {. But already START state. %s:%d\n",
                        filename, linenum);
                fprint( "exit\n" );
                goto FCLOSERETURNFALSE;

            }else{
                NPC_setDefaultNPCCreate( &cr );
                start = ON;
            }
            break;
        case '}':
            if( start == ON ){
                int     err = FALSE;
                if( enemyreadindex == 0 ){
                    err = TRUE;
                    print( "There is no enemydata  %s:%d\n",
                           filename,linenum);
                }else if( MAP_IsThereSpecificFloorid(
                    cr.intdata[NPC_CREATEFLOORID]) == FALSE ){
                    err = TRUE;
                    print( "Invalid Floor ID arround %s:%d-floor:%d\n",
                           filename,linenum, cr.intdata[NPC_CREATEFLOORID]);
                }else if( defborn == FALSE ){
                    err = TRUE;
                    print( "There is no born setting %s:%d\n",
                           filename,linenum);
                }

                if( err == FALSE ){
                    cr.intdata[NPC_CREATEENEMYNUM] = enemyreadindex;

                    if( deflurd[0] ){
                        cr.intdata[NPC_CREATEBORNLEFTUPX] =
                            min(lu[0].x,rd[0].x);
                        cr.intdata[NPC_CREATEBORNRIGHTDOWNX] =
                            max(lu[0].x,rd[0].x);
                        cr.intdata[NPC_CREATEBORNLEFTUPY] =
                            min(lu[0].y,rd[0].y);
                        cr.intdata[NPC_CREATEBORNRIGHTDOWNY] =
                            max(lu[0].y,rd[0].y);
                    }else{
                        cr.intdata[NPC_CREATEBORNLEFTUPX] =
                            center[0].x-wh[0].w/2;
                        cr.intdata[NPC_CREATEBORNRIGHTDOWNX] =
                            center[0].x+wh[0].w/2;
                        cr.intdata[NPC_CREATEBORNLEFTUPY] =
                            center[0].y-wh[0].h/2;
                        cr.intdata[NPC_CREATEBORNRIGHTDOWNY] =
                            center[0].y+wh[0].h/2;
                    }
					/* 99/01/21 河田 [0]-->[1]に修正 */
                    if( defmove ){
                        if( deflurd[0] ){
                            cr.intdata[NPC_CREATEMOVELEFTUPX] =
                                min(lu[1].x,rd[1].x);
                            cr.intdata[NPC_CREATEMOVERIGHTDOWNX] =
                                max(lu[1].x,rd[1].x);
                            cr.intdata[NPC_CREATEMOVELEFTUPY] =
                                min(lu[1].y,rd[1].y);
                            cr.intdata[NPC_CREATEMOVERIGHTDOWNY] =
                                max(lu[1].y,rd[1].y);
                        }else{
                            cr.intdata[NPC_CREATEMOVELEFTUPX] =
                                center[1].x-wh[1].w/2;
                            cr.intdata[NPC_CREATEMOVERIGHTDOWNX] =
                                center[1].x+wh[1].w/2;
                            cr.intdata[NPC_CREATEMOVELEFTUPY] =
                                center[1].y-wh[1].h/2;
                            cr.intdata[NPC_CREATEMOVERIGHTDOWNY] =
                                center[1].y+wh[1].h/2;
                        }

                    }else{
                        /*  born をコピーする */
                        cr.intdata[NPC_CREATEMOVELEFTUPX] =
                            cr.intdata[NPC_CREATEBORNLEFTUPX];
                        cr.intdata[NPC_CREATEMOVERIGHTDOWNX] =
                            cr.intdata[NPC_CREATEBORNRIGHTDOWNX];
                        cr.intdata[NPC_CREATEMOVELEFTUPY] =
                            cr.intdata[NPC_CREATEBORNLEFTUPY];
                        cr.intdata[NPC_CREATEMOVERIGHTDOWNY] =
                            cr.intdata[NPC_CREATEBORNRIGHTDOWNY];
                    }

                    memcpy( &NPC_create[NPC_create_readindex], &cr,
                            sizeof( NPC_Create ) );


                    NPC_create_readindex++;

                    if( NPC_create_readindex >= NPC_createnum ){
                        print("Create Exceed configured buffer\n" );
                        print("configured createnumber is %d\n",
                              NPC_createnum);
                        print("Unread File:%s\n",filename);
                        goto FCLOSERETURNFALSE;
                    }

                }
                /*  初期値に戻しておく  */
                NPC_setDefaultNPCCreate( &cr );
                enemyreadindex=0;
                defborn=FALSE;
                defmove=FALSE;
                deflurd[0]=FALSE;
                deflurd[1]=FALSE;

                start = OFF;
            }else{
                fprint( "Unresolved '}' at %s:%d\n",filename,linenum);
                goto FCLOSERETURNFALSE;
            }
            break;
        default:
        {
 
            char    firstToken[256];
            char    secondToken[256];
            int     ret;
            ret = getStringFromIndexWithDelim( line, "=",  1, firstToken,
                                               sizeof( firstToken ) );
            if( ret == FALSE ){
                print( "Find error at %s in line %d. Ignore\n",
                       filename , linenum);
                break;
            }
            ret = getStringFromIndexWithDelim( line, "=", 2, secondToken,
                                               sizeof( secondToken ) );
            if( ret == FALSE ){
                print( "Find error at %s in line %d. Ignore\n",
                       filename , linenum);
                break;
            }

            if( strcasecmp("floorid",firstToken) == 0 ){
                cr.intdata[NPC_CREATEFLOORID] = atoi(secondToken);

            }else if( strcasecmp("borncenter", firstToken) == 0 ){
                getFourIntsFromString(secondToken,&center[0].x,
                            &center[0].y,&wh[0].w,&wh[0].h );
                defborn = TRUE;
            }else if( strcasecmp("borncorner", firstToken) == 0 ){
                getFourIntsFromString(secondToken,&lu[0].x,&lu[0].y,
                            &rd[0].x,&rd[0].y );
                defborn = TRUE;
                deflurd[0]=TRUE;

            }else if( strcasecmp("movecenter", firstToken) == 0 ){
                getFourIntsFromString(secondToken,&center[1].x,
                            &center[1].y,&wh[1].w,&wh[1].h );
                defmove = TRUE;
            }else if( strcasecmp("movecorner", firstToken) == 0 ){
                getFourIntsFromString(secondToken,&lu[1].x,&lu[1].y,
                            &rd[1].x,&rd[1].y );
                defmove = TRUE;
                deflurd[1]=TRUE;

            }else if( strcasecmp("dir",firstToken) == 0 ){
                cr.intdata[NPC_CREATEDIR] = atoi( secondToken );

            }else if( strcasecmp("graphicname",firstToken) == 0 ){
                cr.intdata[NPC_CREATEBASEIMAGENUMBER]
                    = CHAR_seekGraphicNumberFromString(secondToken);

            }else if( strcasecmp("name",firstToken) == 0 ){
                strcpysafe( cr.chardata[NPC_CREATENAME].string,
                            sizeof(cr.chardata[NPC_CREATENAME].string),
                            secondToken );

            }else if( strcasecmp("time",firstToken) == 0 ){
                cr.intdata[NPC_CREATETIME] = atoi( secondToken );

            }else if( strcasecmp("date",firstToken) == 0 ){
                cr.intdata[NPC_CREATEDATE] = atoi( secondToken );

            }else if( strcasecmp("createnum",firstToken) == 0 ){
                cr.intdata[NPC_CREATEBORNNUM] = atoi( secondToken );

            }else if( strcasecmp( "boundary", firstToken) == 0 ){
                cr.intdata[NPC_CREATEBOUNDARY] = atoi( secondToken );

            }else if( strcasecmp( "ignoreinvincible", firstToken) == 0 ){
                cr.intdata[NPC_CREATEIGNOREINVINCIBLE] = atoi( secondToken );

		//jeffrey 1231
#ifdef _ADD_ACTION
			}else if( strcasecmp( "action", firstToken) == 0 ){
				cr.intdata[NPC_CREATEACTION] = atoi( secondToken );
#endif		
	    // Robin 0731
            }else if( strcasecmp( "family", firstToken) == 0 ){
                cr.intdata[NPC_CREATEFAMILY] = atoi( secondToken );

            }else if( strcasecmp("enemy", firstToken) == 0 ){
                /*  引数を渡せるようにする  */
                int     templateindex;
                char    enemyname[64];

                /*  境界線チェック  */
                if( enemyreadindex <= arraysizeof(cr.templateindex) )
                    /* OK */
                    ;
                else
                    break;

                /*  secondToken を文字列に分解する    */
                getStringFromIndexWithDelim(secondToken,"|",1,enemyname,
                                            sizeof(enemyname) );
                templateindex= NPC_templateGetTemplateIndex(enemyname);
                if( templateindex != -1 ){
                    cr.templateindex[enemyreadindex] = templateindex;
                    {
                        /*  引数を処理する  */
                        char    tmp[2];
                        int     ret;
                        ret = getStringFromIndexWithDelim( secondToken,
                                                           "|",2,tmp,
                                                           sizeof(tmp) );
                        if( ret == FALSE )
                            cr.arg[enemyreadindex].string[0] = '\0';
                        else
                            strcpysafe( cr.arg[enemyreadindex].string,
                                        sizeof( cr.arg[enemyreadindex].
                                                string ),
                                        secondToken+strlen(enemyname)+1 );
                    }
                    enemyreadindex++;
                }else
                    fprint( "No such template:\n[%s(%d)%s] enemy:%s\n",
                            filename ,linenum,secondToken, enemyname);
            }else{
                fprint( "No such entry %s %s:%d\n",firstToken,filename,
                        linenum );
            }
        }
        }
    }

    fclose(f);
    return TRUE;

FCLOSERETURNFALSE:
    fclose(f);
    return FALSE;
}
Пример #24
0
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;
}
Пример #25
0
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;
}