* Moved script constant manipulation code into separate functions script_get_constant / script_set_constant. [Ai4rei]
- Added protection against overwriting existing names in script constant creation code. git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@14701 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
parent
da989bb356
commit
63321f205e
@ -1,5 +1,8 @@
|
|||||||
Date Added
|
Date Added
|
||||||
|
|
||||||
|
2011/02/08
|
||||||
|
* Moved script constant manipulation code into separate functions script_get_constant / script_set_constant. [Ai4rei]
|
||||||
|
- Added protection against overwriting existing names in script constant creation code.
|
||||||
2011/02/07
|
2011/02/07
|
||||||
* Added support for new delayed character deletion. [Ai4rei]
|
* Added support for new delayed character deletion. [Ai4rei]
|
||||||
- Asks for birth date associated with the account and has a waiting time of 24 hours by default (setting).
|
- Asks for birth date associated with the account and has a waiting time of 24 hours by default (setting).
|
||||||
|
@ -1343,10 +1343,8 @@ const char* parse_syntax(const char* p)
|
|||||||
v = p2-p; // length of word at p2
|
v = p2-p; // length of word at p2
|
||||||
memcpy(label,p,v);
|
memcpy(label,p,v);
|
||||||
label[v]='\0';
|
label[v]='\0';
|
||||||
v = search_str(label);
|
if( !script_get_constant(label, &v) )
|
||||||
if (v < 0 || str_data[v].type != C_INT)
|
|
||||||
disp_error_message("parse_syntax: 'case' label not integer",p);
|
disp_error_message("parse_syntax: 'case' label not integer",p);
|
||||||
v = str_data[v].val;
|
|
||||||
p = skip_word(p);
|
p = skip_word(p);
|
||||||
} else { //Numeric value
|
} else { //Numeric value
|
||||||
if((*p == '-' || *p == '+') && ISDIGIT(p[1])) // pre-skip because '-' can not skip_word
|
if((*p == '-' || *p == '+') && ISDIGIT(p[1])) // pre-skip because '-' can not skip_word
|
||||||
@ -1918,6 +1916,40 @@ static void add_buildin_func(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieves the value of a constant.
|
||||||
|
bool script_get_constant(const char* name, int* value)
|
||||||
|
{
|
||||||
|
int n = search_str(name);
|
||||||
|
|
||||||
|
if( n == -1 || str_data[n].type != C_INT )
|
||||||
|
{// not found or not a constant
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
value[0] = str_data[n].val;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates new constant or parameter with given value.
|
||||||
|
void script_set_constant(const char* name, int value, bool isparameter)
|
||||||
|
{
|
||||||
|
int n = add_str(name);
|
||||||
|
|
||||||
|
if( str_data[n].type == C_NOP )
|
||||||
|
{// new
|
||||||
|
str_data[n].type = isparameter ? C_PARAM : C_INT;
|
||||||
|
str_data[n].val = value;
|
||||||
|
}
|
||||||
|
else if( str_data[n].type == C_PARAM || str_data[n].type == C_INT )
|
||||||
|
{// existing parameter or constant
|
||||||
|
ShowError("script_set_constant: Attempted to overwrite existing %s '%s' (old value=%d, new value=%d).\n", ( str_data[n].type == C_PARAM ) ? "parameter" : "constant", name, str_data[n].val, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{// existing name
|
||||||
|
ShowError("script_set_constant: Invalid name for %s '%s' (already defined as %s).\n", isparameter ? "parameter" : "constant", name, script_op2name(str_data[n].type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* 定数データベースの読み込み
|
* 定数データベースの読み込み
|
||||||
*------------------------------------------*/
|
*------------------------------------------*/
|
||||||
@ -1925,7 +1957,7 @@ static void read_constdb(void)
|
|||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char line[1024],name[1024],val[1024];
|
char line[1024],name[1024],val[1024];
|
||||||
int n,type;
|
int type;
|
||||||
|
|
||||||
sprintf(line, "%s/const.txt", db_path);
|
sprintf(line, "%s/const.txt", db_path);
|
||||||
fp=fopen(line, "r");
|
fp=fopen(line, "r");
|
||||||
@ -1940,12 +1972,7 @@ static void read_constdb(void)
|
|||||||
type=0;
|
type=0;
|
||||||
if(sscanf(line,"%[A-Za-z0-9_],%[-0-9xXA-Fa-f],%d",name,val,&type)>=2 ||
|
if(sscanf(line,"%[A-Za-z0-9_],%[-0-9xXA-Fa-f],%d",name,val,&type)>=2 ||
|
||||||
sscanf(line,"%[A-Za-z0-9_] %[-0-9xXA-Fa-f] %d",name,val,&type)>=2){
|
sscanf(line,"%[A-Za-z0-9_] %[-0-9xXA-Fa-f] %d",name,val,&type)>=2){
|
||||||
n=add_str(name);
|
script_set_constant(name, (int)strtol(val, NULL, 0), (bool)type);
|
||||||
if(type==0)
|
|
||||||
str_data[n].type=C_INT;
|
|
||||||
else
|
|
||||||
str_data[n].type=C_PARAM;
|
|
||||||
str_data[n].val= (int)strtol(val,NULL,0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -167,6 +167,9 @@ struct DBMap* script_get_label_db(void);
|
|||||||
struct DBMap* script_get_userfunc_db(void);
|
struct DBMap* script_get_userfunc_db(void);
|
||||||
void script_run_autobonus(const char *autobonus,int id, int pos);
|
void script_run_autobonus(const char *autobonus,int id, int pos);
|
||||||
|
|
||||||
|
bool script_get_constant(const char* name, int* value);
|
||||||
|
void script_set_constant(const char* name, int value, bool isparameter);
|
||||||
|
|
||||||
void script_cleararray_pc(struct map_session_data* sd, const char* varname, void* value);
|
void script_cleararray_pc(struct map_session_data* sd, const char* varname, void* value);
|
||||||
void script_setarray_pc(struct map_session_data* sd, const char* varname, uint8 idx, void* value, int* refcache);
|
void script_setarray_pc(struct map_session_data* sd, const char* varname, uint8 idx, void* value, int* refcache);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user