StoneAge/gmsv/map/map_warppoint.c
2018-08-07 00:51:35 -07:00

284 lines
7.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "version.h"
#include <string.h>
#include "common.h"
#include "char.h"
#include "char_base.h"
#include "object.h"
#include "buf.h"
#include "util.h"
#include "configfile.h"
#include "readmap.h"
#include "map_warppoint.h"
#ifdef _MAP_WARPPOINT
#define MAP_MAXWARPPOINT 5000
typedef struct _tagMAPwarpPoints{
int use;
int ofloor;
int ox;
int oy;
int floor;
int x;
int y;
int type;
}_MAPwarpPoints;
_MAPwarpPoints *MapWarppoint;
static int MapWarpPoints=0;
char PointType[3][256]={ "NONE", "FREE", "ERROR"};
char Filename[256];
int MAPPOINT_InitMapWarpPoint()
{
MapWarppoint = ( _MAPwarpPoints *)calloc( 1, sizeof( struct _tagMAPwarpPoints)*MAP_MAXWARPPOINT);
if( MapWarppoint == NULL ) return 0;
sprintf(Filename, "%s/mapwarp.txt", getMapdir());
MAPPOINT_resetMapWarpPoint( 0);
return MAP_MAXWARPPOINT;
}
/*
void MAPPOINT_checkMapWarpPoint( int floor, int x, int y)
{
OBJECT object;
for( object = MAP_getTopObj(fl,x,y) ; object ;
object = NEXT_OBJECT(object) ){
int o = GET_OBJINDEX(object);
if( OBJECT_getType(o) == OBJTYPE_WARPPOINT){
if( !MAPPOINT_CHECKINDEX( OBJECT_getIndex( o)) ) continue;
if( OBJECT_getchartype( o) != event ) continue;
MAPPOINT_MapWarpHandle( charaindex, OBJECT_getIndex( o), fl, x, y );
found = TRUE;
break;
}
}
*/
void MAPPOINT_resetMapWarpPoint( int flg)
{
int i;
if( MapWarppoint == NULL ) return;
for( i=0; i<MAP_MAXWARPPOINT; i++){
MapWarppoint[i].use = 0;
MapWarppoint[i].floor = -1;
}
if( flg == 1 ){
int objindex;
int objmaxnum = OBJECT_getNum();
for( objindex=0; objindex<objmaxnum; objindex++) {
if( CHECKOBJECT( objindex ) == FALSE ) continue;
if( OBJECT_getType( objindex) != OBJTYPE_WARPPOINT )continue;
CHAR_ObjectDelete( objindex);
}
}
}
int MAPPOINT_creatMapWarpObj( int pointindex, char *buf, int objtype)
{
int objindex;
Object obj;
char buf1[256];
obj.index= pointindex;
memset( obj.objname, 0, sizeof( obj.objname));
if( getStringFromIndexWithDelim( buf, ",", 1, buf1, sizeof(buf1)) ==FALSE ){
return -1;//ԭ<><D4AD>
}
obj.floor = atoi( buf1);
if( getStringFromIndexWithDelim( buf, ",", 2, buf1, sizeof(buf1)) ==FALSE ){
return -1;//ԭ<><D4AD>
}
obj.x = atoi( buf1);
if( getStringFromIndexWithDelim( buf, ",", 3, buf1, sizeof(buf1)) ==FALSE ){
return -1;//ԭ<><D4AD>
}
obj.y = atoi( buf1);
obj.type = OBJTYPE_WARPPOINT;
obj.chartype = objtype;
obj.dir = 0;
objindex = initObjectOne( &obj );
if( objindex == -1 ){
//andy_log
//print( " creatMapWarpObj() initObjectOne err !!\n");
return -1;
}
return objindex;
}
BOOL MAPPOINT_CHECKINDEX( int ps)
{
if( ps < 0 || ps >= MAP_MAXWARPPOINT )
return FALSE;
return MapWarppoint[ ps].use;
}
int MAPPOINT_getMPointEVType( int ps)
{
if( !MAPPOINT_CHECKINDEX( ps) )
return -1;
return MapWarppoint[ ps].type;
}
int MAPPOINT_setMapWarpFrom( int ps, char *buf)
{
char buf1[256];
if( MAPPOINT_CHECKINDEX( ps) ){
print(" <20><><EFBFBD>ô<EFBFBD><C3B4>͵<EFBFBD><CDB5><EFBFBD> %s <20><><EFBFBD><EFBFBD>!!\n", buf);
return -1;
}
memset( buf1, 0, sizeof( buf1));
if( getStringFromIndexWithDelim( buf, ",", 1, buf1, sizeof(buf1)) ==FALSE ) return -1;//ԭ<><D4AD>
MapWarppoint[ps].ofloor = atoi( buf1);
if( getStringFromIndexWithDelim( buf, ",", 2, buf1, sizeof(buf1)) ==FALSE ) return -1;//ԭ<><D4AD>
MapWarppoint[ps].ox = atoi( buf1);
if( getStringFromIndexWithDelim( buf, ",", 3, buf1, sizeof(buf1)) ==FALSE ) return -1;//ԭ<><D4AD>
MapWarppoint[ps].oy = atoi( buf1);
return 1;
}
int MAPPOINT_setMapWarpGoal( int ps, char *buf)
{
char buf1[256];
if( MAPPOINT_CHECKINDEX( ps) ){
print(" <20><><EFBFBD>ô<EFBFBD><C3B4>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD> :%s!!\n", buf);
return -1;
}
memset( buf1, 0, sizeof( buf1));
if( getStringFromIndexWithDelim( buf, ",", 1, buf1, sizeof(buf1)) ==FALSE ) return -1;//ԭ<><D4AD>
MapWarppoint[ps].floor = atoi( buf1);
if( getStringFromIndexWithDelim( buf, ",", 2, buf1, sizeof(buf1)) ==FALSE ) return -1;//ԭ<><D4AD>
MapWarppoint[ps].x = atoi( buf1);
if( getStringFromIndexWithDelim( buf, ",", 3, buf1, sizeof(buf1)) ==FALSE ) return -1;//ԭ<><D4AD>
MapWarppoint[ps].y = atoi( buf1);
return 1;
}
int MAPPOINT_getMapWarpGoal( int ps, int ofl, int ox, int oy, int *fl, int *x, int *y)
{
if( !MAPPOINT_CHECKINDEX( ps) ){
print("<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>PS:%d <20><><EFBFBD><EFBFBD>!!\n", ps);
return -1;
}
if( MapWarppoint[ps].ofloor != ofl ||
MapWarppoint[ps].ox != ox || MapWarppoint[ps].oy != oy ){
print( "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>: <20>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD> %d %d %d !!\n" , ofl,ox,oy );
return -1;
}
//<2F>ɼ<EFBFBD><C9BC>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
if( MAP_IsValidCoordinate( MapWarppoint[ps].floor, MapWarppoint[ps].x, MapWarppoint[ps].y)== FALSE ){
print( "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d %d %d !!\n" ,
MapWarppoint[ps].floor,MapWarppoint[ps].x, MapWarppoint[ps].y );
return -1;
}
*fl = MapWarppoint[ps].floor;
*x = MapWarppoint[ps].x;
*y = MapWarppoint[ps].y;
return 1;
}
int MAPPOINT_loadMapWarpPoint( )
{
int i=0, ps=0, objtype;
FILE *fp=NULL;
char buf[256], buf1[256];
if( Filename == NULL ) return -1;
fp = fopen( Filename, "r");
if( fp == NULL ){
return 0;
}
while( fgets( buf, sizeof( buf)-1, fp) != NULL ){
if( strstr( buf, "#") != 0 ) continue;
if( getStringFromIndexWithDelim( buf, ":", 1, buf1, sizeof(buf1)) ==FALSE )
continue;
for( i=0; i<arraysizeof( PointType); i++) {
if( !strcmp( buf1, PointType[i]) )break;
}
if( i >= arraysizeof( PointType) ){
print(" 1.map <20><><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD> %s \n", buf);
continue;
}
MapWarppoint[ps].type = i;
if( getStringFromIndexWithDelim( buf, ":", 2, buf1, sizeof(buf1)) ==FALSE ) continue;
objtype = CHAR_EVENT_WARP;
if( !strcmp( buf1, "NULL")){
}else if( !strcmp( buf1, "M")){
objtype = CHAR_EVENT_WARP_MORNING;
}else if( !strcmp( buf1, "N")){
objtype = CHAR_EVENT_WARP_NIGHT;
}else if( !strcmp( buf1, "A")){
objtype = CHAR_EVENT_WARP_NOON;
}
memset( buf1, 0, sizeof(buf1));
if( getStringFromIndexWithDelim( buf, ":", 3, buf1, sizeof(buf1)) ==FALSE )continue;
if( MAPPOINT_setMapWarpFrom( ps, buf1) == -1){
print(" 2-1.map <20><><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD> %s [%s] \n", buf, buf1);
continue;
}
if( MAPPOINT_creatMapWarpObj( ps, buf1, objtype) == -1 ){
print(" 2.map <20><><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD> %s [%s] \n", buf, buf1);
continue;
}
memset( buf1, 0, sizeof(buf1));
if( getStringFromIndexWithDelim( buf, ":", 4, buf1, sizeof(buf1)) ==FALSE ){
print(" 3.map <20><><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD> %s [%s] \n", buf, buf1);
continue;
}
if( MAPPOINT_setMapWarpGoal( ps, buf1) == -1 ){
print(" 4.map <20><><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD> %s \n", buf);
continue;
}
memset( buf1, 0, sizeof(buf1));
if( getStringFromIndexWithDelim( buf, ":", 5, buf1, sizeof(buf1)) ==FALSE ){
print(" 5.map <20><><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD> %s [%s] \n", buf, buf1);
continue;
}
MapWarppoint[ps].use = 1;
MapWarpPoints++;
ps++;
if( ps >= MAP_MAXWARPPOINT ){
break;
}
}
//andy_log
print("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD> %d <20><>ͼ<EFBFBD><CDBC><EFBFBD>͵<EFBFBD>...", MapWarpPoints);
fclose( fp);
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
return 1;
}
void MAPPOINT_MapWarpHandle( int charaindex, int ps, int ofl, int ox, int oy )
{
int floor, x, y;
if( MAPPOINT_getMapWarpGoal( ps, ofl, ox, oy, &floor, &x, &y) == -1 ){
//andy_log
print( "<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>( %d, %d,%d,%d)<29><><EFBFBD><EFBFBD>!!\n", ps, ofl, ox, oy);
return;
}
if( floor == 777 ) return;
CHAR_warpToSpecificPoint( charaindex, floor, x, y);
if( CHAR_getWorkInt( charaindex, CHAR_WORKPARTYMODE ) == CHAR_PARTY_LEADER ) {
int i;
for( i = 1; i < CHAR_PARTYMAX; i ++ ) {
int index = CHAR_getWorkInt( charaindex, i + CHAR_WORKPARTYINDEX1);
if( CHAR_CHECKINDEX(index) ) {
CHAR_warpToSpecificPoint( index, floor, x, y);
}
}
}
}
#endif