* Reworked the parsing at npc.c.
- Fixes npc.c discarding the '}' at the end of file, when there is no newline. (uncovered as a side-effect of r11487) * Empty script functions always have code now (won't report as missing when you try to call them). * Changed userfunc_db to not limit the name to 50 characters. git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@11502 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
parent
3d7a129b90
commit
05134f3dcc
@ -4,6 +4,12 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
|
||||
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
|
||||
|
||||
2007/10/17
|
||||
* Reworked the parsing at npc.c.
|
||||
- Fixes npc.c discarding the '}' at the end of file, when there is no
|
||||
newline. (uncovered as a side-effect of r11487)
|
||||
* Empty script functions always have code now (won't report as missing
|
||||
when you try to call them).
|
||||
* Changed userfunc_db to not limit the name to 50 characters. [FlavioJS]
|
||||
* Ground skill now can trigger every 20ms [Playtester]
|
||||
- Firewall, Fire Formation and Heat now can do 50 hits a second
|
||||
- this was proven to be official behavior, but it will raise CPU usage
|
||||
|
@ -316,6 +316,26 @@ size_t safestrnlen(const char* string, size_t maxlen)
|
||||
return ( string != NULL ) ? strnlen(string, maxlen) : 0;
|
||||
}
|
||||
|
||||
/// Returns the line of the target position in the string.
|
||||
/// Lines start at 1.
|
||||
int strline(const char* str, size_t pos)
|
||||
{
|
||||
const char* target;
|
||||
int line;
|
||||
|
||||
if( str == NULL || pos == 0 )
|
||||
return 1;
|
||||
|
||||
target = str+pos;
|
||||
for( line = 1; ; ++line )
|
||||
{
|
||||
str = strchr(str, '\n');
|
||||
if( str == NULL || target <= str )
|
||||
break;// found target line
|
||||
++str;// skip newline
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// StringBuf - dynamic string
|
||||
|
@ -37,6 +37,10 @@ char* safestrncpy(char* dst, const char* src, size_t n);
|
||||
/// doesn't crash on null pointer
|
||||
size_t safestrnlen(const char* string, size_t maxlen);
|
||||
|
||||
/// Returns the line of the target position in the string.
|
||||
/// Lines start at 1.
|
||||
int strline(const char* str, size_t pos);
|
||||
|
||||
/// StringBuf - dynamic string
|
||||
struct StringBuf
|
||||
{
|
||||
|
@ -6321,7 +6321,7 @@ int atcommand_npcmove(const int fd, struct map_session_data* sd, const char* com
|
||||
int atcommand_addwarp(const int fd, struct map_session_data* sd, const char* command, const char* message)
|
||||
{
|
||||
char w1[64], w3[64], w4[64];
|
||||
int x,y,ret;
|
||||
int x,y,ret=0;
|
||||
nullpo_retr(-1, sd);
|
||||
|
||||
if (!message || !*message || sscanf(message, "%23s %d %d[^\n]", atcmd_player_name, &x, &y) < 3) {
|
||||
@ -6333,7 +6333,8 @@ int atcommand_addwarp(const int fd, struct map_session_data* sd, const char* com
|
||||
sprintf(w3,"%s%d%d%d%d", atcmd_player_name,sd->bl.x, sd->bl.y, x, y);
|
||||
sprintf(w4,"1,1,%s.gat,%d,%d", atcmd_player_name, x, y);
|
||||
|
||||
ret = npc_parse_warp(w1, "warp", w3, w4);
|
||||
// FIXME check if it failed [FlavioJS]
|
||||
npc_parse_warp(w1, "warp", w3, w4, NULL, NULL, "console");
|
||||
|
||||
sprintf(atcmd_output, "New warp NPC => %s",w3);
|
||||
|
||||
|
@ -5492,10 +5492,15 @@ void clif_vendingreport(struct map_session_data* sd, int index, int amount)
|
||||
WFIFOW(fd,4) = amount;
|
||||
WFIFOSET(fd,packet_len(0x137));
|
||||
}
|
||||
/*==========================================
|
||||
* パーティ作成完了
|
||||
*------------------------------------------*/
|
||||
int clif_party_created(struct map_session_data *sd,int flag)
|
||||
|
||||
/// Result of organizing a party.
|
||||
/// S 00FA <result>.B
|
||||
///
|
||||
/// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
|
||||
/// result=1 : MsgStringTable[78]="party name already exists"
|
||||
/// result=2 : MsgStringTable[79]="already in a party"
|
||||
/// result=other : nothing
|
||||
int clif_party_created(struct map_session_data *sd,int result)
|
||||
{
|
||||
int fd;
|
||||
|
||||
@ -5504,7 +5509,7 @@ int clif_party_created(struct map_session_data *sd,int flag)
|
||||
fd=sd->fd;
|
||||
WFIFOHEAD(fd,packet_len(0xfa));
|
||||
WFIFOW(fd,0)=0xfa;
|
||||
WFIFOB(fd,2)=flag;
|
||||
WFIFOB(fd,2)=result;
|
||||
WFIFOSET(fd,packet_len(0xfa));
|
||||
return 0;
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ void clif_vendingreport(struct map_session_data* sd, int index, int amount);
|
||||
int clif_movetoattack(struct map_session_data *sd,struct block_list *bl);
|
||||
|
||||
// party
|
||||
int clif_party_created(struct map_session_data *sd,int flag);
|
||||
int clif_party_created(struct map_session_data *sd,int result);
|
||||
int clif_party_member_info(struct party_data *p, struct map_session_data *sd);
|
||||
int clif_party_info(struct party_data *p, struct map_session_data *sd);
|
||||
int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd);
|
||||
|
@ -850,7 +850,7 @@ struct npc_data {
|
||||
struct npc_label_list *label_list;
|
||||
int src_id;
|
||||
} scr;
|
||||
struct npc_item_list shop_item[1];
|
||||
struct npc_item_list shop_item[1];// dynamic array, allocated with extra entries (last one has nameid 0)
|
||||
struct {
|
||||
short xs,ys;
|
||||
short x,y;
|
||||
|
908
src/map/npc.c
908
src/map/npc.c
File diff suppressed because it is too large
Load Diff
@ -52,9 +52,8 @@ int npc_checknear2(struct map_session_data* sd, struct block_list* bl);
|
||||
int npc_buysellsel(struct map_session_data* sd, int id, int type);
|
||||
int npc_buylist(struct map_session_data* sd,int n, unsigned short* item_list);
|
||||
int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list);
|
||||
int npc_parse_mob(char* w1, char* w2, char* w3, char* w4);
|
||||
int npc_parse_mob2(struct spawn_data* mob, int index); // [Wizputer]
|
||||
int npc_parse_warp(char* w1,char* w2,char* w3,char* w4);
|
||||
const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath);
|
||||
int npc_globalmessage(const char* name,const char* mes);
|
||||
|
||||
void npc_setcells(struct npc_data* nd);
|
||||
@ -67,7 +66,7 @@ int npc_get_new_npc_id(void);
|
||||
|
||||
void npc_addsrcfile(const char* name);
|
||||
void npc_delsrcfile(const char* name);
|
||||
void npc_parsesrcfile(const char* name);
|
||||
void npc_parsesrcfile(const char* filepath);
|
||||
int do_final_npc(void);
|
||||
int do_init_npc(void);
|
||||
int npc_event_do_oninit(void);
|
||||
|
@ -722,9 +722,10 @@ void set_label(int l,int pos, const char* script_pos)
|
||||
}
|
||||
|
||||
/// Skips spaces and/or comments.
|
||||
static
|
||||
const char* skip_space(const char* p)
|
||||
{
|
||||
if( p == NULL )
|
||||
return NULL;
|
||||
for(;;)
|
||||
{
|
||||
while( ISSPACE(*p) )
|
||||
@ -740,7 +741,7 @@ const char* skip_space(const char* p)
|
||||
for(;;)
|
||||
{
|
||||
if( *p == '\0' )
|
||||
disp_error_message("script:skip_space: end of file while parsing block comment. expected "CL_BOLD"*/"CL_NORM, p);
|
||||
return p;//disp_error_message("script:skip_space: end of file while parsing block comment. expected "CL_BOLD"*/"CL_NORM, p);
|
||||
if( *p == '*' && p[1] == '/' )
|
||||
{// end of block comment
|
||||
p += 2;
|
||||
@ -1896,7 +1897,7 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
|
||||
{
|
||||
const char *p,*tmpp;
|
||||
int i;
|
||||
struct script_code *code;
|
||||
struct script_code* code = NULL;
|
||||
static int first=1;
|
||||
char end;
|
||||
|
||||
@ -1955,8 +1956,8 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
|
||||
p=skip_space(p);
|
||||
if( options&SCRIPT_IGNORE_EXTERNAL_BRACKETS )
|
||||
{// does not require brackets around the script
|
||||
if( *p == '\0' )
|
||||
{// empty script
|
||||
if( *p == '\0' && !(options&SCRIPT_RETURN_EMPTY_SCRIPT) )
|
||||
{// empty script and can return NULL
|
||||
aFree( script_buf );
|
||||
script_pos = 0;
|
||||
script_size = 0;
|
||||
@ -1969,9 +1970,9 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
|
||||
{// requires brackets around the script
|
||||
if( *p != '{' )
|
||||
disp_error_message("not found '{'",p);
|
||||
p = skip_space(++p);
|
||||
if( *p == '}' )
|
||||
{// empty script
|
||||
p = skip_space(p+1);
|
||||
if( *p == '}' && !(options&SCRIPT_RETURN_EMPTY_SCRIPT) )
|
||||
{// empty script and can return NULL
|
||||
aFree( script_buf );
|
||||
script_pos = 0;
|
||||
script_size = 0;
|
||||
@ -3586,6 +3587,7 @@ static int do_final_userfunc_sub (DBKey key,void *data,va_list ap)
|
||||
if(code){
|
||||
script_free_vars( &code->script_vars );
|
||||
aFree( code->script_buf );
|
||||
aFree( code );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -3683,7 +3685,7 @@ int do_init_script()
|
||||
{
|
||||
mapreg_db= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
|
||||
mapregstr_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
|
||||
userfunc_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_RELEASE_BOTH,50);
|
||||
userfunc_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_DUP_KEY,0);
|
||||
scriptlabel_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_DUP_KEY|DB_OPT_ALLOW_NULL_DATA,50);
|
||||
|
||||
script_load_mapreg();
|
||||
|
@ -63,9 +63,14 @@ struct script_state {
|
||||
|
||||
enum script_parse_options {
|
||||
SCRIPT_USE_LABEL_DB = 0x1,// records labels in scriptlabel_db
|
||||
SCRIPT_IGNORE_EXTERNAL_BRACKETS = 0x2// ignores the check for {} brackets around the script
|
||||
SCRIPT_IGNORE_EXTERNAL_BRACKETS = 0x2,// ignores the check for {} brackets around the script
|
||||
SCRIPT_RETURN_EMPTY_SCRIPT = 0x4// returns the script object instead of NULL for empty scripts
|
||||
};
|
||||
|
||||
const char* skip_space(const char* p);
|
||||
const char* script_print_line(const char* p, const char* mark, int line);
|
||||
void script_error(const char *src,const char *file,int start_line, const char *error_msg, const char *error_pos);
|
||||
|
||||
struct script_code* parse_script(const char* src,const char* file,int line,int options);
|
||||
void run_script_sub(struct script_code *rootscript,int pos,int rid,int oid, char* file, int lineno);
|
||||
void run_script(struct script_code*,int,int,int);
|
||||
|
Loading…
x
Reference in New Issue
Block a user