* Random script engine clean-ups that have accumulated over time.

- Resolved unnecessary script_getnum re-evaluation in a loop in script command 'npcshopdelitem' (since r7120).
- Script commands 'menu', 'select' and 'prompt' now warn, when there are more menu options, than the client can handle correctly (TODO from r10316).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@14597 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
ai4rei 2010-12-17 12:40:38 +00:00
parent 6269cfe730
commit f964fb6ec2
2 changed files with 30 additions and 8 deletions

View File

@ -1,5 +1,9 @@
Date Added Date Added
2010/12/17
* Random script engine clean-ups that have accumulated over time. [Ai4rei]
- Resolved unnecessary script_getnum re-evaluation in a loop in script command 'npcshopdelitem' (since r7120).
- Script commands 'menu', 'select' and 'prompt' now warn, when there are more menu options, than the client can handle correctly (TODO from r10316).
2010/12/16 2010/12/16
* Reverted r14525 (introduction of SV_READDB_MAX_FIELDS) because it causes confusion to certain group of users and depends on MAX_LEVEL since r14526. [Ai4rei] * Reverted r14525 (introduction of SV_READDB_MAX_FIELDS) because it causes confusion to certain group of users and depends on MAX_LEVEL since r14526. [Ai4rei]
- Made sv_readdb be able to process any amount of columns instead. - Made sv_readdb be able to process any amount of columns instead.

View File

@ -281,13 +281,11 @@ typedef struct script_function {
extern script_function buildin_func[]; extern script_function buildin_func[];
static struct linkdb_node* sleep_db;// int oid -> struct script_state* static struct linkdb_node* sleep_db;// int oid -> struct script_state*
uint32 crctab[256];
/*========================================== /*==========================================
* () * ()
*------------------------------------------*/ *------------------------------------------*/
const char* parse_subexpr(const char* p,int limit); const char* parse_subexpr(const char* p,int limit);
void push_val(struct script_stack *stack,int type,int val);
int run_func(struct script_state *st); int run_func(struct script_state *st);
enum { enum {
@ -842,7 +840,7 @@ int add_word(const char* p)
disp_error_message("script:add_word: invalid word. A word consists of undercores and/or alfanumeric characters, and valid variable prefixes/postfixes.", p); disp_error_message("script:add_word: invalid word. A word consists of undercores and/or alfanumeric characters, and valid variable prefixes/postfixes.", p);
// Duplicate the word // Duplicate the word
CREATE(word, char, len+1); word = aMalloc(len+1);
memcpy(word, p, len); memcpy(word, p, len);
word[len] = 0; word[len] = 0;
@ -1502,7 +1500,7 @@ const char* parse_syntax(const char* p)
// function declaration - just register the name // function declaration - just register the name
int l; int l;
l = add_word(func_name); l = add_word(func_name);
if( str_data[l].type == C_NOP )//## ??? [FlavioJS] if( str_data[l].type == C_NOP )// set type only if the name did not exist before
str_data[l].type = C_USERFUNC; str_data[l].type = C_USERFUNC;
// if, for , while の閉じ判定 // if, for , while の閉じ判定
@ -1528,7 +1526,7 @@ const char* parse_syntax(const char* p)
// Set the position of the function (label) // Set the position of the function (label)
l=add_word(func_name); l=add_word(func_name);
if( str_data[l].type == C_NOP )//## ??? [FlavioJS] if( str_data[l].type == C_NOP )// set type only if the name did not exist before
str_data[l].type = C_USERFUNC; str_data[l].type = C_USERFUNC;
set_label(l, script_pos, p); set_label(l, script_pos, p);
if( parse_options&SCRIPT_USE_LABEL_DB ) if( parse_options&SCRIPT_USE_LABEL_DB )
@ -3804,7 +3802,12 @@ BUILDIN_FUNC(menu)
sd->state.menu_or_input = 1; sd->state.menu_or_input = 1;
clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf)); clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf));
StringBuf_Destroy(&buf); StringBuf_Destroy(&buf);
//TODO what's the maximum number of options that can be displayed and/or received? -> give warning
if( sd->npc_menu >= 0xff )
{// client supports only up to 254 entries; 0 is not used and 255 is reserved for cancel; excess entries are displayed but cause 'uint8' overflow
ShowWarning("buildin_menu: Too many options specified (current=%d, max=254).\n", sd->npc_menu);
script_reportsrc(st);
}
} }
else if( sd->npc_menu == 0xff ) else if( sd->npc_menu == 0xff )
{// Cancel was pressed {// Cancel was pressed
@ -3886,6 +3889,12 @@ BUILDIN_FUNC(select)
sd->state.menu_or_input = 1; sd->state.menu_or_input = 1;
clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf)); clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf));
StringBuf_Destroy(&buf); StringBuf_Destroy(&buf);
if( sd->npc_menu >= 0xff )
{
ShowWarning("buildin_select: Too many options specified (current=%d, max=254).\n", sd->npc_menu);
script_reportsrc(st);
}
} }
else if( sd->npc_menu == 0xff ) else if( sd->npc_menu == 0xff )
{// Cancel was pressed {// Cancel was pressed
@ -3948,6 +3957,12 @@ BUILDIN_FUNC(prompt)
sd->state.menu_or_input = 1; sd->state.menu_or_input = 1;
clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf)); clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf));
StringBuf_Destroy(&buf); StringBuf_Destroy(&buf);
if( sd->npc_menu >= 0xff )
{
ShowWarning("buildin_prompt: Too many options specified (current=%d, max=254).\n", sd->npc_menu);
script_reportsrc(st);
}
} }
else if( sd->npc_menu == 0xff ) else if( sd->npc_menu == 0xff )
{// Cancel was pressed {// Cancel was pressed
@ -12179,7 +12194,7 @@ BUILDIN_FUNC(setnpcdisplay)
if( newname ) if( newname )
npc_setdisplayname(nd, newname); npc_setdisplayname(nd, newname);
if( size != -1 && size != nd->size ) if( size != -1 && size != (int)nd->size )
nd->size = size; nd->size = size;
else else
size = -1; size = -1;
@ -12584,6 +12599,7 @@ BUILDIN_FUNC(npcshopdelitem)
{ {
const char* npcname = script_getstr(st,2); const char* npcname = script_getstr(st,2);
struct npc_data* nd = npc_name2id(npcname); struct npc_data* nd = npc_name2id(npcname);
unsigned int nameid;
int n, i; int n, i;
int amount; int amount;
int size; int size;
@ -12600,7 +12616,9 @@ BUILDIN_FUNC(npcshopdelitem)
// remove specified items from the shop item list // remove specified items from the shop item list
for( i = 3; i < 3 + amount; i++ ) for( i = 3; i < 3 + amount; i++ )
{ {
ARR_FIND( 0, size, n, nd->u.shop.shop_item[n].nameid == script_getnum(st,i) ); nameid = script_getnum(st,i);
ARR_FIND( 0, size, n, nd->u.shop.shop_item[n].nameid == nameid );
if( n < size ) if( n < size )
{ {
memmove(&nd->u.shop.shop_item[n], &nd->u.shop.shop_item[n+1], sizeof(nd->u.shop.shop_item[0])*(size-n)); memmove(&nd->u.shop.shop_item[n], &nd->u.shop.shop_item[n+1], sizeof(nd->u.shop.shop_item[0])*(size-n));