summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/map/atcommand.c14
-rw-r--r--src/map/battleground.c4
-rw-r--r--src/map/clif.c2
-rw-r--r--src/map/itemdb.c22
-rw-r--r--src/map/map.c2
-rw-r--r--src/map/mapreg_sql.c10
-rw-r--r--src/map/npc.c115
-rw-r--r--src/map/npc_chat.c4
-rw-r--r--src/map/pc.c56
-rw-r--r--src/map/pet.c14
-rw-r--r--src/map/script.c568
-rw-r--r--src/map/script.h167
-rw-r--r--src/map/skill.c66
-rw-r--r--src/map/status.c32
-rw-r--r--src/map/unit.c2
15 files changed, 551 insertions, 527 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 29bd43d16..e3cf37cf1 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -3748,7 +3748,7 @@ ACMD(reloadscript)
flush_fifos();
iMap->reloadnpc(true); // reload config files seeking for npcs
- script_reload();
+ script->reload();
npc_reload();
clif->message(fd, msg_txt(100)); // Scripts have been reloaded.
@@ -8548,9 +8548,9 @@ ACMD(set) {
if( toset >= 2 ) {/* we only set the var if there is an val, otherwise we only output the value */
if( is_str )
- set_var(sd, reg, (void*) val);
+ script->set_var(sd, reg, (void*) val);
else
- set_var(sd, reg, (void*)__64BPTRSIZE((atoi(val))));
+ script->set_var(sd, reg, (void*)__64BPTRSIZE((atoi(val))));
}
@@ -8561,10 +8561,10 @@ ACMD(set) {
switch( reg[0] ) {
case '@':
- data->u.str = pc->readregstr(sd, add_str(reg));
+ data->u.str = pc->readregstr(sd, script->add_str(reg));
break;
case '$':
- data->u.str = mapreg_readregstr(add_str(reg));
+ data->u.str = mapreg_readregstr(script->add_str(reg));
break;
case '#':
if( reg[1] == '#' )
@@ -8590,10 +8590,10 @@ ACMD(set) {
data->type = C_INT;
switch( reg[0] ) {
case '@':
- data->u.num = pc->readreg(sd, add_str(reg));
+ data->u.num = pc->readreg(sd, script->add_str(reg));
break;
case '$':
- data->u.num = mapreg_readreg(add_str(reg));
+ data->u.num = mapreg_readreg(script->add_str(reg));
break;
case '#':
if( reg[1] == '#' )
diff --git a/src/map/battleground.c b/src/map/battleground.c
index 9127c89b9..198ad6bad 100644
--- a/src/map/battleground.c
+++ b/src/map/battleground.c
@@ -508,8 +508,8 @@ void bg_begin(struct bg_arena *arena) {
bg->match_over(arena,true);
} else {
arena->ongoing = true;
- mapreg_setreg(add_str("$@bg_queue_id"),arena->queue_id);/* TODO: make this a arena-independant var? or just .@? */
- mapreg_setregstr(add_str("$@bg_delay_var$"),bg->gdelay_var);
+ mapreg_setreg(script->add_str("$@bg_queue_id"),arena->queue_id);/* TODO: make this a arena-independant var? or just .@? */
+ mapreg_setregstr(script->add_str("$@bg_delay_var$"),bg->gdelay_var);
npc_event_do(arena->npc_event);
/* we split evenly? */
/* but if a party of say 10 joins, it cant be split evenly unless by luck there are 10 soloers in the queue besides them */
diff --git a/src/map/clif.c b/src/map/clif.c
index 951969a0f..4f0f4f7bf 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -10428,7 +10428,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
sprintf(output, "@whispervar%d$", i);
- set_var(sd,output,(char *) split_data[i]);
+ script->set_var(sd,output,(char *) split_data[i]);
}
sprintf(output, "%s::OnWhisperGlobal", npc->exname);
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 139a62e06..0ea97ed47 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -1470,7 +1470,7 @@ void itemdb_read_combos() {
id->combos[idx]->nameid = aMalloc( retcount * sizeof(unsigned short) );
id->combos[idx]->count = retcount;
- id->combos[idx]->script = parse_script(str[1], path, lines, 0);
+ id->combos[idx]->script = script->parse(str[1], path, lines, 0);
id->combos[idx]->id = count;
id->combos[idx]->isRef = false;
/* populate ->nameid field */
@@ -1674,24 +1674,24 @@ int itemdb_parse_dbrow(char** str, const char* source, int line, int scriptopt)
id->sex = itemdb_gendercheck(id); //Apply gender filtering.
if (id->script) {
- script_free_code(id->script);
+ script->free_code(id->script);
id->script = NULL;
}
if (id->equip_script) {
- script_free_code(id->equip_script);
+ script->free_code(id->equip_script);
id->equip_script = NULL;
}
if (id->unequip_script) {
- script_free_code(id->unequip_script);
+ script->free_code(id->unequip_script);
id->unequip_script = NULL;
}
if (*str[19+offset])
- id->script = parse_script(str[19+offset], source, line, scriptopt);
+ id->script = script->parse(str[19+offset], source, line, scriptopt);
if (*str[20+offset])
- id->equip_script = parse_script(str[20+offset], source, line, scriptopt);
+ id->equip_script = script->parse(str[20+offset], source, line, scriptopt);
if (*str[21+offset])
- id->unequip_script = parse_script(str[21+offset], source, line, scriptopt);
+ id->unequip_script = script->parse(str[21+offset], source, line, scriptopt);
return id->nameid;
}
@@ -1956,17 +1956,17 @@ static void destroy_item_data(struct item_data* self, int free_self)
return;
// free scripts
if( self->script )
- script_free_code(self->script);
+ script->free_code(self->script);
if( self->equip_script )
- script_free_code(self->equip_script);
+ script->free_code(self->equip_script);
if( self->unequip_script )
- script_free_code(self->unequip_script);
+ script->free_code(self->unequip_script);
if( self->combos_count ) {
int i;
for( i = 0; i < self->combos_count; i++ ) {
if( !self->combos[i]->isRef ) {
aFree(self->combos[i]->nameid);
- script_free_code(self->combos[i]->script);
+ script->free_code(self->combos[i]->script);
}
aFree(self->combos[i]);
}
diff --git a/src/map/map.c b/src/map/map.c
index db3bcf001..e6a1fd73c 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -5441,7 +5441,7 @@ int do_init(int argc, char *argv[])
battle->config_read(iMap->BATTLE_CONF_FILENAME);
atcommand->msg_read(iMap->MSG_CONF_NAME);
- script_config_read(iMap->SCRIPT_CONF_NAME);
+ script->config_read(iMap->SCRIPT_CONF_NAME);
inter_config_read(iMap->INTER_CONF_NAME);
logs->config_read(iMap->LOG_CONF_NAME);
diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c
index b6865c8fd..4f9888aba 100644
--- a/src/map/mapreg_sql.c
+++ b/src/map/mapreg_sql.c
@@ -44,7 +44,7 @@ bool mapreg_setreg(int uid, int val) {
struct mapreg_save *m;
int num = (uid & 0x00ffffff);
int i = (uid & 0xff000000) >> 24;
- const char* name = get_str(num);
+ const char* name = script->get_str(num);
if( val != 0 ) {
if( (m = idb_get(mapreg_db,uid)) ) {
@@ -88,7 +88,7 @@ bool mapreg_setregstr(int uid, const char* str) {
struct mapreg_save *m;
int num = (uid & 0x00ffffff);
int i = (uid & 0xff000000) >> 24;
- const char* name = get_str(num);
+ const char* name = script->get_str(num);
if( str == NULL || *str == 0 ) {
if(name[1] != '@') {
@@ -160,7 +160,7 @@ static void script_load_mapreg(void) {
while ( SQL_SUCCESS == SQL->StmtNextRow(stmt) ) {
struct mapreg_save *m = NULL;
- int s = add_str(varname);
+ int s = script->add_str(varname);
int i = index;
if( varname[length-1] == '$' ) {
@@ -204,7 +204,7 @@ static void script_save_mapreg(void) {
if( m->save ) {
int num = (m->uid & 0x00ffffff);
int i = (m->uid & 0xff000000) >> 24;
- const char* name = get_str(num);
+ const char* name = script->get_str(num);
if( SQL_ERROR == SQL->Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg_table, m->u.i, name, i) )
Sql_ShowDebug(mmysql_handle);
@@ -221,7 +221,7 @@ static void script_save_mapreg(void) {
if( m->save ) {
int num = (m->uid & 0x00ffffff);
int i = (m->uid & 0xff000000) >> 24;
- const char* name = get_str(num);
+ const char* name = script->get_str(num);
char tmp_str2[2*255+1];
SQL->EscapeStringLen(mmysql_handle, tmp_str2, m->u.str, safestrnlen(m->u.str, 255));
diff --git a/src/map/npc.c b/src/map/npc.c
index 6aa19198f..911fbe1d4 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -148,7 +148,7 @@ int npc_ontouch_event(struct map_session_data *sd, struct npc_data *nd)
if( pc_ishiding(sd) )
return 1; // Can't trigger 'OnTouch_'. try 'OnTouch' later.
- snprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script_config.ontouch_name);
+ snprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script->config.ontouch_name);
return npc_event(sd,name,1);
}
@@ -159,7 +159,7 @@ int npc_ontouch2_event(struct map_session_data *sd, struct npc_data *nd)
if( sd->areanpc_id == nd->bl.id )
return 0;
- snprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script_config.ontouch2_name);
+ snprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script->config.ontouch2_name);
return npc_event(sd,name,2);
}
@@ -295,7 +295,7 @@ int npc_event_dequeue(struct map_session_data* sd)
sd->state.using_fake_npc = 0;
}
if (sd->st) {
- script_free_state(sd->st);
+ script->free_state(sd->st);
sd->st = NULL;
}
sd->npc_id = 0;
@@ -376,7 +376,7 @@ void npc_event_doall_sub(void *key, void *data, va_list ap)
npc_event_sub(iMap->id2sd(rid), ev, buf);
}
else {
- run_script(ev->nd->u.scr.script, ev->pos, rid, ev->nd->bl.id);
+ script->run(ev->nd->u.scr.script, ev->pos, rid, ev->nd->bl.id);
}
(*c)++;
}
@@ -391,7 +391,7 @@ int npc_event_do(const char* name)
else {
struct event_data *ev = strdb_get(ev_db, name);
if (ev) {
- run_script(ev->nd->u.scr.script, ev->pos, 0, ev->nd->bl.id);
+ script->run(ev->nd->u.scr.script, ev->pos, 0, ev->nd->bl.id);
return 1;
}
}
@@ -578,7 +578,7 @@ int npc_timerevent(int tid, unsigned int tick, int id, intptr_t data)
}
// Run the script
- run_script(nd->u.scr.script,te->pos,nd->u.scr.rid,nd->bl.id);
+ script->run(nd->u.scr.script,te->pos,nd->u.scr.rid,nd->bl.id);
nd->u.scr.rid = old_rid; // Attached-rid should be restored anyway.
if( sd )
@@ -732,7 +732,7 @@ void npc_timerevent_quit(struct map_session_data* sd)
nd->u.scr.timer = ted->time;
//Execute label
- run_script(nd->u.scr.script,ev->pos,sd->bl.id,nd->bl.id);
+ script->run(nd->u.scr.script,ev->pos,sd->bl.id,nd->bl.id);
//Restore previous data.
nd->u.scr.rid = old_rid;
@@ -810,7 +810,7 @@ int npc_event_sub(struct map_session_data* sd, struct event_data* ev, const char
npc_event_dequeue(sd);
return 2;
}
- run_script(ev->nd->u.scr.script,ev->pos,sd->bl.id,ev->nd->bl.id);
+ script->run(ev->nd->u.scr.script,ev->pos,sd->bl.id,ev->nd->bl.id);
return 0;
}
@@ -893,7 +893,7 @@ int npc_touchnext_areanpc(struct map_session_data* sd, bool leavemap)
char name[EVENT_NAME_LENGTH];
nd->touching_id = sd->touching_id = 0;
- snprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script_config.ontouch_name);
+ snprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script->config.ontouch_name);
iMap->forcountinarea(npc_touch_areanpc_sub,nd->bl.m,nd->bl.x - xs,nd->bl.y - ys,nd->bl.x + xs,nd->bl.y + ys,1,BL_PC,sd->bl.id,name);
}
return 0;
@@ -1032,7 +1032,7 @@ int npc_touch_areanpc2(struct mob_data *md)
break; // No OnTouchNPC Event
md->areanpc_id = map[m].npc[i]->bl.id;
id = md->bl.id; // Stores Unique ID
- run_script(ev->nd->u.scr.script, ev->pos, md->bl.id, ev->nd->bl.id);
+ script->run(ev->nd->u.scr.script, ev->pos, md->bl.id, ev->nd->bl.id);
if( iMap->id2md(id) == NULL ) return 1; // Not Warped, but killed
break;
}
@@ -1199,7 +1199,7 @@ int npc_click(struct map_session_data* sd, struct npc_data* nd)
clif->cashshop_show(sd,nd);
break;
case SCRIPT:
- run_script(nd->u.scr.script,0,sd->bl.id,nd->bl.id);
+ script->run(nd->u.scr.script,0,sd->bl.id,nd->bl.id);
break;
case TOMB:
run_tomb(sd,nd);
@@ -1250,7 +1250,7 @@ int npc_scriptcont(struct map_session_data* sd, int id, bool closing)
if( closing && sd->st->state == CLOSE )
sd->st->state = END;
- run_script_main(sd->st);
+ script->run_main(sd->st);
return 0;
}
@@ -1382,14 +1382,13 @@ static int npc_buylist_sub(struct map_session_data* sd, int n, unsigned short* i
int key_amount = 0;
// discard old contents
- script_cleararray_pc(sd, "@bought_nameid", (void*)0);
- script_cleararray_pc(sd, "@bought_quantity", (void*)0);
+ script->cleararray_pc(sd, "@bought_nameid", (void*)0);
+ script->cleararray_pc(sd, "@bought_quantity", (void*)0);
// save list of bought items
- for( i = 0; i < n; i++ )
- {
- script_setarray_pc(sd, "@bought_nameid", i, (void*)(intptr_t)item_list[i*2+1], &key_nameid);
- script_setarray_pc(sd, "@bought_quantity", i, (void*)(intptr_t)item_list[i*2], &key_amount);
+ for( i = 0; i < n; i++ ) {
+ script->setarray_pc(sd, "@bought_nameid", i, (void*)(intptr_t)item_list[i*2+1], &key_nameid);
+ script->setarray_pc(sd, "@bought_quantity", i, (void*)(intptr_t)item_list[i*2], &key_amount);
}
// invoke event
@@ -1611,17 +1610,17 @@ static int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short*
int key_card[MAX_SLOTS];
// discard old contents
- script_cleararray_pc(sd, "@sold_nameid", (void*)0);
- script_cleararray_pc(sd, "@sold_quantity", (void*)0);
- script_cleararray_pc(sd, "@sold_refine", (void*)0);
- script_cleararray_pc(sd, "@sold_attribute", (void*)0);
- script_cleararray_pc(sd, "@sold_identify", (void*)0);
+ script->cleararray_pc(sd, "@sold_nameid", (void*)0);
+ script->cleararray_pc(sd, "@sold_quantity", (void*)0);
+ script->cleararray_pc(sd, "@sold_refine", (void*)0);
+ script->cleararray_pc(sd, "@sold_attribute", (void*)0);
+ script->cleararray_pc(sd, "@sold_identify", (void*)0);
for( j = 0; j < MAX_SLOTS; j++ )
{// clear each of the card slot entries
key_card[j] = 0;
snprintf(card_slot, sizeof(card_slot), "@sold_card%d", j + 1);
- script_cleararray_pc(sd, card_slot, (void*)0);
+ script->cleararray_pc(sd, card_slot, (void*)0);
}
// save list of to be sold items
@@ -1629,19 +1628,19 @@ static int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short*
{
idx = item_list[i*2]-2;
- script_setarray_pc(sd, "@sold_nameid", i, (void*)(intptr_t)sd->status.inventory[idx].nameid, &key_nameid);
- script_setarray_pc(sd, "@sold_quantity", i, (void*)(intptr_t)item_list[i*2+1], &key_amount);
+ script->setarray_pc(sd, "@sold_nameid", i, (void*)(intptr_t)sd->status.inventory[idx].nameid, &key_nameid);
+ script->setarray_pc(sd, "@sold_quantity", i, (void*)(intptr_t)item_list[i*2+1], &key_amount);
if( itemdb_isequip(sd->status.inventory[idx].nameid) )
{// process equipment based information into the arrays
- script_setarray_pc(sd, "@sold_refine", i, (void*)(intptr_t)sd->status.inventory[idx].refine, &key_refine);
- script_setarray_pc(sd, "@sold_attribute", i, (void*)(intptr_t)sd->status.inventory[idx].attribute, &key_attribute);
- script_setarray_pc(sd, "@sold_identify", i, (void*)(intptr_t)sd->status.inventory[idx].identify, &key_identify);
+ script->setarray_pc(sd, "@sold_refine", i, (void*)(intptr_t)sd->status.inventory[idx].refine, &key_refine);
+ script->setarray_pc(sd, "@sold_attribute", i, (void*)(intptr_t)sd->status.inventory[idx].attribute, &key_attribute);
+ script->setarray_pc(sd, "@sold_identify", i, (void*)(intptr_t)sd->status.inventory[idx].identify, &key_identify);
for( j = 0; j < MAX_SLOTS; j++ )
{// store each of the cards from the equipment in the array
snprintf(card_slot, sizeof(card_slot), "@sold_card%d", j + 1);
- script_setarray_pc(sd, card_slot, i, (void*)(intptr_t)sd->status.inventory[idx].card[j], &key_card[j]);
+ script->setarray_pc(sd, card_slot, i, (void*)(intptr_t)sd->status.inventory[idx].card[j], &key_card[j]);
}
}
}
@@ -1875,8 +1874,8 @@ int npc_unload(struct npc_data* nd, bool single) {
aFree(nd->u.scr.timer_event);
if (nd->src_id == 0) {
if(nd->u.scr.script) {
- script_stop_instances(nd->u.scr.script);
- script_free_code(nd->u.scr.script);
+ script->stop_instances(nd->u.scr.script);
+ script->free_code(nd->u.scr.script);
nd->u.scr.script = NULL;
}
if (nd->u.scr.label_list) {
@@ -2292,7 +2291,7 @@ void npc_convertlabel_db(struct npc_label_list* label_list, const char *filepath
int i;
for( i = 0; i < script->label_count; i++ ) {
- const char* lname = get_str(script->labels[i].key);
+ const char* lname = script->get_str(script->labels[i].key);
int lpos = script->labels[i].pos;
struct npc_label_list* label;
const char *p;
@@ -2338,7 +2337,7 @@ static const char* npc_skip_script(const char* start, const char* buffer, const
// skip everything
for( curly_count = 1; curly_count > 0 ; )
{
- p = skip_space(p+1) ;
+ p = script->skip_space(p+1) ;
if( *p == '}' )
{// right curly
--curly_count;
@@ -2355,12 +2354,12 @@ static const char* npc_skip_script(const char* start, const char* buffer, const
++p;// escape sequence (not part of a multibyte character)
else if( *p == '\0' )
{
- script_error(buffer, filepath, 0, "Unexpected end of string.", p);
+ script->error(buffer, filepath, 0, "Unexpected end of string.", p);
return NULL;// can't continue
}
else if( *p == '\n' )
{
- script_error(buffer, filepath, 0, "Unexpected newline at string.", p);
+ script->error(buffer, filepath, 0, "Unexpected newline at string.", p);
return NULL;// can't continue
}
}
@@ -2421,7 +2420,7 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
if( end == NULL )
return NULL;// (simple) parse error, don't continue
- scriptroot = parse_script(script_start, filepath, strline(buffer,script_start-buffer), SCRIPT_USE_LABEL_DB);
+ scriptroot = script->parse(script_start, filepath, strline(buffer,script_start-buffer), SCRIPT_USE_LABEL_DB);
label_list = NULL;
label_list_num = 0;
if( script->label_count ) {
@@ -2498,7 +2497,7 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
if( ( ev = (struct event_data*)strdb_get(ev_db, evname) ) ) {
//Execute OnInit
- run_script(nd->u.scr.script,ev->pos,0,nd->bl.id);
+ script->run(nd->u.scr.script,ev->pos,0,nd->bl.id);
}
}
@@ -2864,8 +2863,8 @@ int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const c
return 2;
}
- st = script_alloc_state(ev->nd->u.scr.script, ev->pos, sd->bl.id, ev->nd->bl.id);
- setd_sub(st, NULL, ".@atcmd_command$", 0, (void *)command, NULL);
+ st = script->alloc_state(ev->nd->u.scr.script, ev->pos, sd->bl.id, ev->nd->bl.id);
+ script->setd_sub(st, NULL, ".@atcmd_command$", 0, (void *)command, NULL);
// split atcmd parameters based on spaces
temp = (char*)aMalloc(strlen(message) + 1);
@@ -2878,7 +2877,7 @@ int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const c
temp[k] = '\0';
k = 0;
if( temp[0] != '\0' ) {
- setd_sub( st, NULL, ".@atcmd_parameters$", j++, (void *)temp, NULL );
+ script->setd_sub( st, NULL, ".@atcmd_parameters$", j++, (void *)temp, NULL );
}
} else {
temp[k] = message[i];
@@ -2886,10 +2885,10 @@ int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const c
}
}
- setd_sub(st, NULL, ".@atcmd_numparameters", 0, (void *)__64BPTRSIZE(j), NULL);
+ script->setd_sub(st, NULL, ".@atcmd_numparameters", 0, (void *)__64BPTRSIZE(j), NULL);
aFree(temp);
- run_script_main(st);
+ script->run_main(st);
return 0;
}
@@ -2899,7 +2898,7 @@ static const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, co
{
DBMap* func_db;
DBData old_data;
- struct script_code *script;
+ struct script_code *scriptroot;
const char* end;
const char* script_start;
@@ -2916,16 +2915,16 @@ static const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, co
if( end == NULL )
return NULL;// (simple) parse error, don't continue
- script = parse_script(script_start, filepath, strline(buffer,start-buffer), SCRIPT_RETURN_EMPTY_SCRIPT);
- if( script == NULL )// parse error, continue
+ scriptroot = script->parse(script_start, filepath, strline(buffer,start-buffer), SCRIPT_RETURN_EMPTY_SCRIPT);
+ if( scriptroot == NULL )// parse error, continue
return end;
- func_db = script_get_userfunc_db();
- if (func_db->put(func_db, DB->str2key(w3), DB->ptr2data(script), &old_data))
+ func_db = script->userfunc_db;
+ if (func_db->put(func_db, DB->str2key(w3), DB->ptr2data(scriptroot), &old_data))
{
struct script_code *oldscript = (struct script_code*)DB->data2ptr(&old_data);
ShowInfo("npc_parse_function: Overwriting user function [%s] (%s:%d)\n", w3, filepath, strline(buffer,start-buffer));
- script_free_vars(oldscript->script_vars);
+ script->free_vars(oldscript->script_vars);
aFree(oldscript->script_buf);
aFree(oldscript);
}
@@ -3541,7 +3540,7 @@ void npc_parsesrcfile(const char* filepath, bool runOnInit)
fclose(fp);
// parse buffer
- for( p = skip_space(buffer); p && *p ; p = skip_space(p) )
+ for( p = script->skip_space(buffer); p && *p ; p = script->skip_space(p) )
{
int pos[9];
char w1[2048], w2[2048], w3[2048], w4[2048];
@@ -3695,14 +3694,14 @@ void npc_read_event_script(void)
char *name;
const char *event_name;
} config[] = {
- {"Login Event",script_config.login_event_name},
- {"Logout Event",script_config.logout_event_name},
- {"Load Map Event",script_config.loadmap_event_name},
- {"Base LV Up Event",script_config.baselvup_event_name},
- {"Job LV Up Event",script_config.joblvup_event_name},
- {"Die Event",script_config.die_event_name},
- {"Kill PC Event",script_config.kill_pc_event_name},
- {"Kill NPC Event",script_config.kill_mob_event_name},
+ {"Login Event",script->config.login_event_name},
+ {"Logout Event",script->config.logout_event_name},
+ {"Load Map Event",script->config.loadmap_event_name},
+ {"Base LV Up Event",script->config.baselvup_event_name},
+ {"Job LV Up Event",script->config.joblvup_event_name},
+ {"Die Event",script->config.die_event_name},
+ {"Kill PC Event",script->config.kill_pc_event_name},
+ {"Kill NPC Event",script->config.kill_mob_event_name},
};
for (i = 0; i < NPCE_MAX; i++)
diff --git a/src/map/npc_chat.c b/src/map/npc_chat.c
index c7faa2df6..f6459e1ae 100644
--- a/src/map/npc_chat.c
+++ b/src/map/npc_chat.c
@@ -383,7 +383,7 @@ int npc_chat_sub(struct block_list* bl, va_list ap)
char var[6], val[255];
snprintf(var, sizeof(var), "$@p%i$", i);
pcre_copy_substring(msg, offsets, r, i, val, sizeof(val));
- set_var(sd, var, val);
+ script->set_var(sd, var, val);
}
// find the target label.. this sucks..
@@ -395,7 +395,7 @@ int npc_chat_sub(struct block_list* bl, va_list ap)
}
// run the npc script
- run_script(nd->u.scr.script,lst[i].pos,sd->bl.id,nd->bl.id);
+ script->run(nd->u.scr.script,lst[i].pos,sd->bl.id,nd->bl.id);
return 0;
}
}
diff --git a/src/map/pc.c b/src/map/pc.c
index d58e39227..6d3f3e35b 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -1280,7 +1280,7 @@ int pc_reg_received(struct map_session_data *sd)
}
if( npc->motd ) /* [Ind/Hercules] */
- run_script(npc->motd->u.scr.script, 0, sd->bl.id, fake_nd->bl.id);
+ script->run(npc->motd->u.scr.script, 0, sd->bl.id, fake_nd->bl.id);
return 1;
}
@@ -1928,7 +1928,7 @@ int pc_delautobonus(struct map_session_data* sd, struct s_autobonus *autobonus,c
int j;
ARR_FIND( 0, EQI_MAX-1, j, sd->equip_index[j] >= 0 && sd->status.inventory[sd->equip_index[j]].equip == autobonus[i].pos );
if( j < EQI_MAX-1 )
- script_run_autobonus(autobonus[i].bonus_script,sd->bl.id,sd->equip_index[j]);
+ script->run_autobonus(autobonus[i].bonus_script,sd->bl.id,sd->equip_index[j]);
}
continue;
}
@@ -1959,7 +1959,7 @@ int pc_exeautobonus(struct map_session_data *sd,struct s_autobonus *autobonus)
int j;
ARR_FIND( 0, EQI_MAX-1, j, sd->equip_index[j] >= 0 && sd->status.inventory[sd->equip_index[j]].equip == autobonus->pos );
if( j < EQI_MAX-1 )
- script_run_autobonus(autobonus->other_script,sd->bl.id,sd->equip_index[j]);
+ script->run_autobonus(autobonus->other_script,sd->bl.id,sd->equip_index[j]);
}
autobonus->active = iTimer->add_timer(iTimer->gettick()+autobonus->duration, pc->endautobonus, sd->bl.id, (intptr_t)autobonus);
@@ -2948,7 +2948,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
ARR_FIND(0, ARRAYLENGTH(sd->skillatk), i, sd->skillatk[i].id == 0 || sd->skillatk[i].id == type2);
if (i == ARRAYLENGTH(sd->skillatk))
{ //Better mention this so the array length can be updated. [Skotlex]
- ShowDebug("run_script: bonus2 bSkillAtk reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillatk), type2, val);
+ ShowDebug("script->run: bonus2 bSkillAtk reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillatk), type2, val);
break;
}
if (sd->skillatk[i].id == type2)
@@ -2964,7 +2964,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
ARR_FIND(0, ARRAYLENGTH(sd->skillheal), i, sd->skillheal[i].id == 0 || sd->skillheal[i].id == type2);
if (i == ARRAYLENGTH(sd->skillheal))
{ // Better mention this so the array length can be updated. [Skotlex]
- ShowDebug("run_script: bonus2 bSkillHeal reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal), type2, val);
+ ShowDebug("script->run: bonus2 bSkillHeal reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal), type2, val);
break;
}
if (sd->skillheal[i].id == type2)
@@ -2980,7 +2980,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
ARR_FIND(0, ARRAYLENGTH(sd->skillheal2), i, sd->skillheal2[i].id == 0 || sd->skillheal2[i].id == type2);
if (i == ARRAYLENGTH(sd->skillheal2))
{ // Better mention this so the array length can be updated. [Skotlex]
- ShowDebug("run_script: bonus2 bSkillHeal2 reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal2), type2, val);
+ ShowDebug("script->run: bonus2 bSkillHeal2 reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillheal2), type2, val);
break;
}
if (sd->skillheal2[i].id == type2)
@@ -2996,7 +2996,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
ARR_FIND(0, ARRAYLENGTH(sd->skillblown), i, sd->skillblown[i].id == 0 || sd->skillblown[i].id == type2);
if (i == ARRAYLENGTH(sd->skillblown))
{ //Better mention this so the array length can be updated. [Skotlex]
- ShowDebug("run_script: bonus2 bSkillBlown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillblown), type2, val);
+ ShowDebug("script->run: bonus2 bSkillBlown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillblown), type2, val);
break;
}
if(sd->skillblown[i].id == type2)
@@ -3015,7 +3015,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
ARR_FIND(0, ARRAYLENGTH(sd->skillcast), i, sd->skillcast[i].id == 0 || sd->skillcast[i].id == type2);
if (i == ARRAYLENGTH(sd->skillcast))
{ //Better mention this so the array length can be updated. [Skotlex]
- ShowDebug("run_script: bonus2 %s reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n",
+ ShowDebug("script->run: bonus2 %s reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n",
#ifndef RENEWAL_CAST
"bCastRate",
@@ -3044,7 +3044,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
{
- ShowDebug("run_script: bonus2 bFixedCastrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcastrate), type2, val);
+ ShowDebug("script->run: bonus2 bFixedCastrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcastrate), type2, val);
break;
}
@@ -3161,7 +3161,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
break;
ARR_FIND(0, ARRAYLENGTH(sd->skillusesprate), i, sd->skillusesprate[i].id == 0 || sd->skillusesprate[i].id == type2);
if (i == ARRAYLENGTH(sd->skillusesprate)) {
- ShowDebug("run_script: bonus2 bSkillUseSPrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesprate), type2, val);
+ ShowDebug("script->run: bonus2 bSkillUseSPrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesprate), type2, val);
break;
}
if (sd->skillusesprate[i].id == type2)
@@ -3177,7 +3177,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
ARR_FIND(0, ARRAYLENGTH(sd->skillcooldown), i, sd->skillcooldown[i].id == 0 || sd->skillcooldown[i].id == type2);
if (i == ARRAYLENGTH(sd->skillcooldown))
{
- ShowDebug("run_script: bonus2 bSkillCoolDown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillcooldown), type2, val);
+ ShowDebug("script->run: bonus2 bSkillCoolDown reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillcooldown), type2, val);
break;
}
if (sd->skillcooldown[i].id == type2)
@@ -3193,7 +3193,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
ARR_FIND(0, ARRAYLENGTH(sd->skillfixcast), i, sd->skillfixcast[i].id == 0 || sd->skillfixcast[i].id == type2);
if (i == ARRAYLENGTH(sd->skillfixcast))
{
- ShowDebug("run_script: bonus2 bSkillFixedCast reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcast), type2, val);
+ ShowDebug("script->run: bonus2 bSkillFixedCast reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillfixcast), type2, val);
break;
}
if (sd->skillfixcast[i].id == type2)
@@ -3209,7 +3209,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
ARR_FIND(0, ARRAYLENGTH(sd->skillvarcast), i, sd->skillvarcast[i].id == 0 || sd->skillvarcast[i].id == type2);
if (i == ARRAYLENGTH(sd->skillvarcast))
{
- ShowDebug("run_script: bonus2 bSkillVariableCast reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillvarcast), type2, val);
+ ShowDebug("script->run: bonus2 bSkillVariableCast reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillvarcast), type2, val);
break;
}
if (sd->skillvarcast[i].id == type2)
@@ -3226,7 +3226,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
ARR_FIND(0, ARRAYLENGTH(sd->skillcast), i, sd->skillcast[i].id == 0 || sd->skillcast[i].id == type2);
if (i == ARRAYLENGTH(sd->skillcast))
{
- ShowDebug("run_script: bonus2 bVariableCastrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n",ARRAYLENGTH(sd->skillcast), type2, val);
+ ShowDebug("script->run: bonus2 bVariableCastrate reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n",ARRAYLENGTH(sd->skillcast), type2, val);
break;
}
if(sd->skillcast[i].id == type2)
@@ -3242,7 +3242,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
break;
ARR_FIND(0, ARRAYLENGTH(sd->skillusesp), i, sd->skillusesp[i].id == 0 || sd->skillusesp[i].id == type2);
if (i == ARRAYLENGTH(sd->skillusesp)) {
- ShowDebug("run_script: bonus2 bSkillUseSP reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesp), type2, val);
+ ShowDebug("script->run: bonus2 bSkillUseSP reached it's limit (%d skills per character), bonus skill %d (+%d%%) lost.\n", ARRAYLENGTH(sd->skillusesp), type2, val);
break;
}
if (sd->skillusesp[i].id == type2)
@@ -4392,9 +4392,9 @@ int pc_useitem(struct map_session_data *sd,int n) {
if(sd->status.inventory[n].card[0]==CARD0_CREATE &&
pc->famerank(MakeDWord(sd->status.inventory[n].card[2],sd->status.inventory[n].card[3]), MAPID_ALCHEMIST))
{
- potion_flag = 2; // Famous player's potions have 50% more efficiency
+ script->potion_flag = 2; // Famous player's potions have 50% more efficiency
if (sd->sc.data[SC_SOULLINK] && sd->sc.data[SC_SOULLINK]->val2 == SL_ROGUE)
- potion_flag = 3; //Even more effective potions.
+ script->potion_flag = 3; //Even more effective potions.
}
//Update item use time.
@@ -4404,10 +4404,10 @@ int pc_useitem(struct map_session_data *sd,int n) {
script->current_item_id = nameid;
- run_script(item_script,0,sd->bl.id,fake_nd->bl.id);
+ script->run(item_script,0,sd->bl.id,fake_nd->bl.id);
script->current_item_id = 0;
- potion_flag = 0;
+ script->potion_flag = 0;
return 1;
}
@@ -4801,7 +4801,7 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y
for( i = 0; i < sd->queues_count; i++ ) {
struct hQueue *queue;
if( (queue = script->queue(sd->queues[i])) && queue->onMapChange[0] != '\0' ) {
- pc->setregstr(sd, add_str("QMapChangeTo"), map[m].name);
+ pc->setregstr(sd, script->add_str("QMapChangeTo"), map[m].name);
npc_event(sd, queue->onMapChange, 0);
}
}
@@ -7388,8 +7388,8 @@ int pc_itemheal(struct map_session_data *sd,int itemid, int hp,int sp)
+ pc->checkskill(sd,SM_RECOVERY)*10
+ pc->checkskill(sd,AM_LEARNINGPOTION)*5;
// A potion produced by an Alchemist in the Fame Top 10 gets +50% effect [DracoRPG]
- if (potion_flag > 1)
- bonus += bonus*(potion_flag-1)*50/100;
+ if (script->potion_flag > 1)
+ bonus += bonus*(script->potion_flag-1)*50/100;
//All item bonuses.
bonus += sd->bonus.itemhealrate2;
//Individual item bonuses.
@@ -7411,8 +7411,8 @@ int pc_itemheal(struct map_session_data *sd,int itemid, int hp,int sp)
bonus = 100 + (sd->battle_status.int_<<1)
+ pc->checkskill(sd,MG_SRECOVERY)*10
+ pc->checkskill(sd,AM_LEARNINGPOTION)*5;
- if (potion_flag > 1)
- bonus += bonus*(potion_flag-1)*50/100;
+ if (script->potion_flag > 1)
+ bonus += bonus*(script->potion_flag-1)*50/100;
if(bonus != 100)
sp = sp * bonus / 100;
}
@@ -8762,7 +8762,7 @@ int pc_equipitem(struct map_session_data *sd,int n,int req_pos)
//OnEquip script [Skotlex]
if (id) {
if (id->equip_script)
- run_script(id->equip_script,0,sd->bl.id,fake_nd->bl.id);
+ script->run(id->equip_script,0,sd->bl.id,fake_nd->bl.id);
if(itemdb_isspecial(sd->status.inventory[n].card[0]))
; //No cards
else {
@@ -8772,7 +8772,7 @@ int pc_equipitem(struct map_session_data *sd,int n,int req_pos)
continue;
if ( ( data = itemdb->exists(sd->status.inventory[n].card[i]) ) != NULL ) {
if( data->equip_script )
- run_script(data->equip_script,0,sd->bl.id,fake_nd->bl.id);
+ script->run(data->equip_script,0,sd->bl.id,fake_nd->bl.id);
}
}
}
@@ -8929,7 +8929,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) {
//OnUnEquip script [Skotlex]
if (sd->inventory_data[n]) {
if (sd->inventory_data[n]->unequip_script)
- run_script(sd->inventory_data[n]->unequip_script,0,sd->bl.id,fake_nd->bl.id);
+ script->run(sd->inventory_data[n]->unequip_script,0,sd->bl.id,fake_nd->bl.id);
if(itemdb_isspecial(sd->status.inventory[n].card[0]))
; //No cards
else {
@@ -8940,7 +8940,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) {
if ( ( data = itemdb->exists(sd->status.inventory[n].card[i]) ) != NULL ) {
if( data->unequip_script )
- run_script(data->unequip_script,0,sd->bl.id,fake_nd->bl.id);
+ script->run(data->unequip_script,0,sd->bl.id,fake_nd->bl.id);
}
}
diff --git a/src/map/pet.c b/src/map/pet.c
index 2697e8128..62a884316 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -372,7 +372,7 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet)
pd->last_thinktime = iTimer->gettick();
pd->state.skillbonus = 0;
if( battle_config.pet_status_support )
- run_script(pet_db[i].pet_script,0,sd->bl.id,0);
+ script->run(pet_db[i].pet_script,0,sd->bl.id,0);
if( pd->petDB && pd->petDB->equip_script )
status_calc_pc(sd,0);
@@ -1219,12 +1219,12 @@ int read_petdb()
{
if( pet_db[j].pet_script )
{
- script_free_code(pet_db[j].pet_script);
+ script->free_code(pet_db[j].pet_script);
pet_db[j].pet_script = NULL;
}
if( pet_db[j].equip_script )
{
- script_free_code(pet_db[j].equip_script);
+ script->free_code(pet_db[j].equip_script);
pet_db[j].pet_script = NULL;
}
}
@@ -1337,9 +1337,9 @@ int read_petdb()
pet_db[j].equip_script = NULL;
if( *str[20] )
- pet_db[j].pet_script = parse_script(str[20], filename[i], lines, 0);
+ pet_db[j].pet_script = script->parse(str[20], filename[i], lines, 0);
if( *str[21] )
- pet_db[j].equip_script = parse_script(str[21], filename[i], lines, 0);
+ pet_db[j].equip_script = script->parse(str[21], filename[i], lines, 0);
j++;
entries++;
@@ -1382,12 +1382,12 @@ int do_final_pet(void)
{
if( pet_db[i].pet_script )
{
- script_free_code(pet_db[i].pet_script);
+ script->free_code(pet_db[i].pet_script);
pet_db[i].pet_script = NULL;
}
if( pet_db[i].equip_script )
{
- script_free_code(pet_db[i].equip_script);
+ script->free_code(pet_db[i].equip_script);
pet_db[i].equip_script = NULL;
}
}
diff --git a/src/map/script.c b/src/map/script.c
index 04d834f74..09c19cb3e 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -97,9 +97,7 @@ int str_hash[SCRIPT_HASH_SIZE];
//#define SCRIPT_HASH_SDBM
#define SCRIPT_HASH_ELF
-static DBMap* userfunc_db=NULL; // const char* func_name -> struct script_code*
static int parse_options=0;
-DBMap* script_get_userfunc_db(void){ return userfunc_db; }
// important buildin function references for usage in scripts
static int buildin_set_ref = 0;
@@ -107,26 +105,6 @@ static int buildin_callsub_ref = 0;
static int buildin_callfunc_ref = 0;
static int buildin_getelementofarray_ref = 0;
-// Caches compiled autoscript item code.
-// Note: This is not cleared when reloading itemdb.
-static DBMap* autobonus_db=NULL; // char* script -> char* bytecode
-
-struct Script_Config script_config = {
- 1, // warn_func_mismatch_argtypes
- 1, 65535, 2048, //warn_func_mismatch_paramnum/check_cmdcount/check_gotocount
- 0, INT_MAX, // input_min_value/input_max_value
- "OnPCDieEvent", //die_event_name
- "OnPCKillEvent", //kill_pc_event_name
- "OnNPCKillEvent", //kill_mob_event_name
- "OnPCLoginEvent", //login_event_name
- "OnPCLogoutEvent", //logout_event_name
- "OnPCLoadMapEvent", //loadmap_event_name
- "OnPCBaseLvUpEvent", //baselvup_event_name
- "OnPCJobLvUpEvent", //joblvup_event_name
- "OnTouch_", //ontouch_name (runs on first visible char to enter area, picks another char if the first char leaves)
- "OnTouch", //ontouch2_name (run whenever a char walks into the OnTouch area)
-};
-
static jmp_buf error_jump;
static char* error_msg;
static const char* error_pos;
@@ -171,21 +149,15 @@ const char* parse_syntax(const char* p);
static int parse_syntax_for_flag = 0;
extern int status_current_equip_item_index; //for New CARDS Scripts. It contains Inventory Index of the EQUIP_SCRIPT caller item. [Lupus]
-int potion_flag=0; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
-int potion_hp=0, potion_per_hp=0, potion_sp=0, potion_per_sp=0;
-int potion_target=0;
-
struct script_interface script_s;
-c_op get_com(unsigned char *script,int *pos);
-int get_num(unsigned char *script,int *pos);
+c_op get_com(unsigned char *scriptbuf,int *pos);
+int get_num(unsigned char *scriptbuf,int *pos);
/*==========================================
* (Only those needed) local declaration prototype
*------------------------------------------*/
-const char* parse_subexpr(const char* p,int limit);
-int run_func(struct script_state *st);
enum {
MF_NOMEMO, //0
@@ -431,7 +403,7 @@ static void script_reportfunc(struct script_state* st)
if( params > 0 )
{
- ShowDebug("Function: %s (%d parameter%s):\n", get_str(id), params, ( params == 1 ) ? "" : "s");
+ ShowDebug("Function: %s (%d parameter%s):\n", script->get_str(id), params, ( params == 1 ) ? "" : "s");
for( i = 2; i <= script_lastdata(st); i++ )
{
@@ -440,7 +412,7 @@ static void script_reportfunc(struct script_state* st)
}
else
{
- ShowDebug("Function: %s (no parameters)\n", get_str(id));
+ ShowDebug("Function: %s (no parameters)\n", script->get_str(id));
}
}
@@ -509,19 +481,19 @@ static unsigned int calc_hash(const char* p)
*------------------------------------------*/
/// Looks up string using the provided id.
-const char* get_str(int id)
+const char* script_get_str(int id)
{
Assert( id >= LABEL_START && id < script->str_size );
return script->str_buf+script->str_data[id].str;
}
/// Returns the uid of the string, or -1.
-static int search_str(const char* p)
+int script_search_str(const char* p)
{
int i;
for( i = str_hash[calc_hash(p)]; i != 0; i = script->str_data[i].next )
- if( strcasecmp(get_str(i),p) == 0 )
+ if( strcasecmp(script->get_str(i),p) == 0 )
return i;
return -1;
@@ -529,7 +501,7 @@ static int search_str(const char* p)
/// Stores a copy of the string and returns its id.
/// If an identical string is already present, returns its id instead.
-int add_str(const char* p)
+int script_add_str(const char* p)
{
int i, h;
int len;
@@ -540,7 +512,7 @@ int add_str(const char* p)
str_hash[h] = script->str_num;
} else {// scan for end of list, or occurence of identical string
for( i = str_hash[h]; ; i = script->str_data[i].next ) {
- if( strcasecmp(get_str(i),p) == 0 )
+ if( strcasecmp(script->get_str(i),p) == 0 )
return i; // string already in list
if( script->str_data[i].next == 0 )
break; // reached the end
@@ -687,7 +659,7 @@ void set_label(int l,int pos, const char* script_pos)
}
/// Skips spaces and/or comments.
-const char* skip_space(const char* p)
+const char* script_skip_space(const char* p)
{
if( p == NULL )
return NULL;
@@ -706,7 +678,7 @@ const char* skip_space(const char* p)
for(;;)
{
if( *p == '\0' )
- return p;//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: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;
@@ -750,7 +722,7 @@ static const char* skip_word(const char* p) {
}
/// Adds a word to script->str_data.
/// @see skip_word
-/// @see add_str
+/// @see script->add_str
static int add_word(const char* p) {
int len;
int i;
@@ -768,7 +740,7 @@ static int add_word(const char* p) {
script->word_buf[len] = 0;
// add the word
- i = add_str(script->word_buf);
+ i = script->add_str(script->word_buf);
return i;
}
@@ -803,8 +775,8 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom)
++arg; // count func as argument
} else {
#ifdef SCRIPT_CALLFUNC_CHECK
- const char* name = get_str(func);
- if( !is_custom && strdb_get(userfunc_db, name) == NULL ) {
+ const char* name = script->get_str(func);
+ if( !is_custom && strdb_get(script->userfunc_db, name) == NULL ) {
#endif
disp_error_message("parse_line: expect command, missing function name or calling undeclared function",p);
#ifdef SCRIPT_CALLFUNC_CHECK
@@ -821,13 +793,13 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom)
}
p = skip_word(p);
- p = skip_space(p);
+ p = script->skip_space(p);
syntax.curly[syntax.curly_count].type = TYPE_ARGLIST;
syntax.curly[syntax.curly_count].count = 0;
if( *p == ';' )
{// <func name> ';'
syntax.curly[syntax.curly_count].flag = ARGLIST_NO_PAREN;
- } else if( *p == '(' && *(p2=skip_space(p+1)) == ')' )
+ } else if( *p == '(' && *(p2=script->skip_space(p+1)) == ')' )
{// <func name> '(' ')'
syntax.curly[syntax.curly_count].flag = ARGLIST_PAREN;
p = p2;
@@ -849,13 +821,13 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom)
}
++syntax.curly_count;
while( *arg ) {
- p2=parse_subexpr(p,-1);
+ p2=script->parse_subexpr(p,-1);
if( p == p2 )
break; // not an argument
if( *arg != '*' )
++arg; // next argument
- p=skip_space(p2);
+ p=script->skip_space(p2);
if( *arg == 0 || *p != ',' )
break; // no more arguments
++p; // skip comma
@@ -863,7 +835,7 @@ const char* parse_callfunc(const char* p, int require_paren, int is_custom)
--syntax.curly_count;
}
if( arg && *arg && *arg != '?' && *arg != '*' )
- disp_error_message2("parse_callfunc: not enough arguments, expected ','", p, script_config.warn_func_mismatch_paramnum);
+ disp_error_message2("parse_callfunc: not enough arguments, expected ','", p, script->config.warn_func_mismatch_paramnum);
if( syntax.curly[syntax.curly_count].type != TYPE_ARGLIST )
disp_error_message("parse_callfunc: DEBUG last curly is not an argument list",p);
if( syntax.curly[syntax.curly_count].flag == ARGLIST_PAREN ){
@@ -903,7 +875,7 @@ const char* parse_variable(const char* p) {
// skip the variable where applicable
p = skip_word(p);
- p = skip_space(p);
+ p = script->skip_space(p);
if( p == NULL ) {// end of the line or invalid buffer
return NULL;
@@ -915,7 +887,7 @@ const char* parse_variable(const char* p) {
if( *p == '[' ) ++ j;
}
- if( !(p = skip_space(p)) ) {// end of line or invalid characters remaining
+ if( !(p = script->skip_space(p)) ) {// end of line or invalid characters remaining
disp_error_message("Missing right expression or closing bracket for variable.", p);
}
}
@@ -942,18 +914,18 @@ const char* parse_variable(const char* p) {
switch( type ) {
case C_EQ: {// incremental modifier
- p = skip_space( &p[1] );
+ p = script->skip_space( &p[1] );
}
break;
case C_L_SHIFT:
case C_R_SHIFT: {// left or right shift modifier
- p = skip_space( &p[3] );
+ p = script->skip_space( &p[3] );
}
break;
default: {// normal incremental command
- p = skip_space( &p[2] );
+ p = script->skip_space( &p[2] );
}
}
@@ -990,8 +962,8 @@ const char* parse_variable(const char* p) {
add_scriptl(word);
// process the sub-expression for this assignment
- p3 = parse_subexpr(p2 + 1, 1);
- p3 = skip_space(p3);
+ p3 = script->parse_subexpr(p2 + 1, 1);
+ p3 = script->skip_space(p3);
if( *p3 != ']' ) {// closing parenthesis is required for this script
disp_error_message("Missing closing ']' parenthesis for the variable assignment.", p3);
@@ -1011,7 +983,7 @@ const char* parse_variable(const char* p) {
add_scripti(1);
add_scriptc(type == C_ADD_PP ? C_ADD : C_SUB);
} else {// process the value as an expression
- p = parse_subexpr(p, -1);
+ p = script->parse_subexpr(p, -1);
if( type != C_EQ )
{// push the type of modifier onto the stack
@@ -1035,15 +1007,15 @@ const char* parse_variable(const char* p) {
const char* parse_simpleexpr(const char *p)
{
int i;
- p=skip_space(p);
+ p=script->skip_space(p);
if(*p==';' || *p==',')
disp_error_message("parse_simpleexpr: unexpected end of expression",p);
if(*p=='('){
if( (i=syntax.curly_count-1) >= 0 && syntax.curly[i].type == TYPE_ARGLIST )
++syntax.curly[i].count;
- p=parse_subexpr(p+1,-1);
- p=skip_space(p);
+ p=script->parse_subexpr(p+1,-1);
+ p=script->skip_space(p);
if( (i=syntax.curly_count-1) >= 0 && syntax.curly[i].type == TYPE_ARGLIST &&
syntax.curly[i].flag == ARGLIST_UNDEFINED && --syntax.curly[i].count == 0
){
@@ -1096,8 +1068,8 @@ const char* parse_simpleexpr(const char *p)
return parse_callfunc(p,1,0);
#ifdef SCRIPT_CALLFUNC_CHECK
else {
- const char* name = get_str(l);
- if( strdb_get(userfunc_db,name) != NULL ) {
+ const char* name = script->get_str(l);
+ if( strdb_get(script->userfunc_db,name) != NULL ) {
return parse_callfunc(p,1,1);
}
}
@@ -1115,8 +1087,8 @@ const char* parse_simpleexpr(const char *p)
add_scriptc(C_ARG);
add_scriptl(l);
- p=parse_subexpr(p+1,-1);
- p=skip_space(p);
+ p=script->parse_subexpr(p+1,-1);
+ p=script->skip_space(p);
if( *p != ']' )
disp_error_message("parse_simpleexpr: unmatched ']'",p);
++p;
@@ -1132,15 +1104,15 @@ const char* parse_simpleexpr(const char *p)
/*==========================================
* Analysis of the expression
*------------------------------------------*/
-const char* parse_subexpr(const char* p,int limit)
+const char* script_parse_subexpr(const char* p,int limit)
{
int op,opl,len;
const char* tmpp;
- p=skip_space(p);
+ p=script->skip_space(p);
if( *p == '-' ){
- tmpp = skip_space(p+1);
+ tmpp = script->skip_space(p+1);
if( *tmpp == ';' || *tmpp == ',' ){
add_scriptl(LABEL_NEXTLINE);
p++;
@@ -1149,11 +1121,11 @@ const char* parse_subexpr(const char* p,int limit)
}
if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
- p=parse_subexpr(p+1,10);
+ p=script->parse_subexpr(p+1,10);
add_scriptc(op);
} else
p=parse_simpleexpr(p);
- p=skip_space(p);
+ p=script->skip_space(p);
while((
(op=C_OP3,opl=0,len=1,*p=='?') ||
(op=C_ADD,opl=8,len=1,*p=='+') ||
@@ -1176,16 +1148,16 @@ const char* parse_subexpr(const char* p,int limit)
(op=C_LT,opl=3,len=1,*p=='<')) && opl>limit){
p+=len;
if(op == C_OP3) {
- p=parse_subexpr(p,-1);
- p=skip_space(p);
+ p=script->parse_subexpr(p,-1);
+ p=script->skip_space(p);
if( *(p++) != ':')
disp_error_message("parse_subexpr: need ':'", p-1);
- p=parse_subexpr(p,-1);
+ p=script->parse_subexpr(p,-1);
} else {
- p=parse_subexpr(p,opl);
+ p=script->parse_subexpr(p,opl);
}
add_scriptc(op);
- p=skip_space(p);
+ p=script->skip_space(p);
}
return p; /* return first untreated operator */
@@ -1201,7 +1173,7 @@ const char* parse_expr(const char *p)
case '}':
disp_error_message("parse_expr: unexpected char",p);
}
- p=parse_subexpr(p,-1);
+ p=script->parse_subexpr(p,-1);
return p;
}
@@ -1212,7 +1184,7 @@ const char* parse_line(const char* p)
{
const char* p2;
- p=skip_space(p);
+ p=script->skip_space(p);
if(*p==';') {
//Close decision for if(); for(); while();
p = parse_syntax_close(p + 1);
@@ -1221,7 +1193,7 @@ const char* parse_line(const char* p)
if(*p==')' && parse_syntax_for_flag)
return p+1;
- p = skip_space(p);
+ p = script->skip_space(p);
if(p[0] == '{') {
syntax.curly[syntax.curly_count].type = TYPE_NULL;
syntax.curly[syntax.curly_count].count = -1;
@@ -1246,7 +1218,7 @@ const char* parse_line(const char* p)
}
p = parse_callfunc(p,0,0);
- p = skip_space(p);
+ p = script->skip_space(p);
if(parse_syntax_for_flag) {
if( *p != ')' )
@@ -1292,7 +1264,7 @@ const char* parse_curly_close(const char* p)
// You are here labeled
sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos, p);
if(syntax.curly[pos].flag) {
@@ -1305,7 +1277,7 @@ const char* parse_curly_close(const char* p)
// Label end
sprintf(label,"__SW%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos, p);
linkdb_final(&syntax.curly[pos].case_label); // free the list of case label
syntax.curly_count--;
@@ -1355,7 +1327,7 @@ const char* parse_syntax(const char* p)
parse_line(label);
syntax.curly_count--;
}
- p = skip_space(p2);
+ p = script->skip_space(p2);
if(*p != ';')
disp_error_message("parse_syntax: need ';'",p);
// Closing decision if, for , while
@@ -1384,11 +1356,11 @@ const char* parse_syntax(const char* p)
// You are here labeled
sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos, p);
}
//Decision statement switch
- p = skip_space(p2);
+ p = script->skip_space(p2);
if(p == p2) {
disp_error_message("parse_syntax: expect space ' '",p);
}
@@ -1409,7 +1381,7 @@ const char* parse_syntax(const char* p)
if(np != p)
disp_error_message("parse_syntax: 'case' label is not an integer",np);
}
- p = skip_space(p);
+ p = script->skip_space(p);
if(*p != ':')
disp_error_message("parse_syntax: expect ':'",p);
sprintf(label,"if(%d != $@__SW%x_VAL) goto __SW%x_%x;",
@@ -1422,7 +1394,7 @@ const char* parse_syntax(const char* p)
if(syntax.curly[pos].count != 1) {
// Label after the completion of FALLTHRU
sprintf(label,"__SW%x_%xJ",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
}
// check duplication of case label [Rayce]
@@ -1463,7 +1435,7 @@ const char* parse_syntax(const char* p)
parse_line(label);
syntax.curly_count--;
}
- p = skip_space(p2);
+ p = script->skip_space(p2);
if(*p != ';')
disp_error_message("parse_syntax: need ';'",p);
//Closing decision if, for , while
@@ -1484,12 +1456,12 @@ const char* parse_syntax(const char* p)
char label[256];
int l;
// Put the label location
- p = skip_space(p2);
+ p = script->skip_space(p2);
if(*p != ':') {
disp_error_message("parse_syntax: need ':'",p);
}
sprintf(label,"__SW%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
// Skip to the next link w/o condition
@@ -1500,7 +1472,7 @@ const char* parse_syntax(const char* p)
// The default label
sprintf(label,"__SW%x_DEF",syntax.curly[pos].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
syntax.curly[syntax.curly_count - 1].flag = 1;
@@ -1510,7 +1482,7 @@ const char* parse_syntax(const char* p)
} else if(p2 - p == 2 && !strncasecmp(p,"do",2)) {
int l;
char label[256];
- p=skip_space(p2);
+ p=script->skip_space(p2);
syntax.curly[syntax.curly_count].type = TYPE_DO;
syntax.curly[syntax.curly_count].count = 1;
@@ -1518,7 +1490,7 @@ const char* parse_syntax(const char* p)
syntax.curly[syntax.curly_count].flag = 0;
// Label of the (do) form here
sprintf(label,"__DO%x_BGN",syntax.curly[syntax.curly_count].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
syntax.curly_count++;
return p;
@@ -1536,7 +1508,7 @@ const char* parse_syntax(const char* p)
syntax.curly[syntax.curly_count].flag = 0;
syntax.curly_count++;
- p=skip_space(p2);
+ p=script->skip_space(p2);
if(*p != '(')
disp_error_message("parse_syntax: need '('",p);
@@ -1549,21 +1521,21 @@ const char* parse_syntax(const char* p)
// Form the start of label decision
sprintf(label,"__FR%x_J",syntax.curly[pos].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
- p=skip_space(p);
+ p=script->skip_space(p);
if(*p == ';') {
// For (; Because the pattern of always true ;)
;
} else {
// Skip to the end point if the condition is false
sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
- add_scriptl(add_str("jump_zero"));
+ add_scriptl(script->add_str("jump_zero"));
add_scriptc(C_ARG);
p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
+ p=script->skip_space(p);
+ add_scriptl(script->add_str(label));
add_scriptc(C_FUNC);
}
if(*p != ';')
@@ -1578,7 +1550,7 @@ const char* parse_syntax(const char* p)
// Labels to form the next loop
sprintf(label,"__FR%x_NXT",syntax.curly[pos].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
// Process the next time you enter the loop
@@ -1597,7 +1569,7 @@ const char* parse_syntax(const char* p)
// Loop start labeling
sprintf(label,"__FR%x_BGN",syntax.curly[pos].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
return p;
}
@@ -1605,11 +1577,11 @@ const char* parse_syntax(const char* p)
{// internal script function
const char *func_name;
- func_name = skip_space(p2);
+ func_name = script->skip_space(p2);
p = skip_word(func_name);
if( p == func_name )
disp_error_message("parse_syntax:function: function name is missing or invalid", p);
- p2 = skip_space(p);
+ p2 = script->skip_space(p);
if( *p2 == ';' )
{// function <name> ;
// function declaration - just register the name
@@ -1656,7 +1628,7 @@ const char* parse_syntax(const char* p)
else
disp_error_message("parse_syntax:function: function name is invalid", func_name);
- return skip_space(p);
+ return script->skip_space(p);
}
else
{
@@ -1669,7 +1641,7 @@ const char* parse_syntax(const char* p)
if(p2 - p == 2 && !strncasecmp(p,"if",2)) {
// If process
char label[256];
- p=skip_space(p2);
+ p=script->skip_space(p2);
if(*p != '(') { //Prevent if this {} non-c syntax. from Rayce (jA)
disp_error_message("need '('",p);
}
@@ -1679,11 +1651,11 @@ const char* parse_syntax(const char* p)
syntax.curly[syntax.curly_count].flag = 0;
sprintf(label,"__IF%x_%x",syntax.curly[syntax.curly_count].index,syntax.curly[syntax.curly_count].count);
syntax.curly_count++;
- add_scriptl(add_str("jump_zero"));
+ add_scriptl(script->add_str("jump_zero"));
add_scriptc(C_ARG);
p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
+ p=script->skip_space(p);
+ add_scriptl(script->add_str(label));
add_scriptc(C_FUNC);
return p;
}
@@ -1693,7 +1665,7 @@ const char* parse_syntax(const char* p)
if(p2 - p == 6 && !strncasecmp(p,"switch",6)) {
// Processing of switch ()
char label[256];
- p=skip_space(p2);
+ p=script->skip_space(p2);
if(*p != '(') {
disp_error_message("need '('",p);
}
@@ -1703,11 +1675,11 @@ const char* parse_syntax(const char* p)
syntax.curly[syntax.curly_count].flag = 0;
sprintf(label,"$@__SW%x_VAL",syntax.curly[syntax.curly_count].index);
syntax.curly_count++;
- add_scriptl(add_str("set"));
+ add_scriptl(script->add_str("set"));
add_scriptc(C_ARG);
- add_scriptl(add_str(label));
+ add_scriptl(script->add_str(label));
p=parse_expr(p);
- p=skip_space(p);
+ p=script->skip_space(p);
if(*p != '{') {
disp_error_message("parse_syntax: need '{'",p);
}
@@ -1720,7 +1692,7 @@ const char* parse_syntax(const char* p)
if(p2 - p == 5 && !strncasecmp(p,"while",5)) {
int l;
char label[256];
- p=skip_space(p2);
+ p=script->skip_space(p2);
if(*p != '(') {
disp_error_message("need '('",p);
}
@@ -1730,17 +1702,17 @@ const char* parse_syntax(const char* p)
syntax.curly[syntax.curly_count].flag = 0;
// Form the start of label decision
sprintf(label,"__WL%x_NXT",syntax.curly[syntax.curly_count].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
// Skip to the end point if the condition is false
sprintf(label,"__WL%x_FIN",syntax.curly[syntax.curly_count].index);
syntax.curly_count++;
- add_scriptl(add_str("jump_zero"));
+ add_scriptl(script->add_str("jump_zero"));
add_scriptc(C_ARG);
p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
+ p=script->skip_space(p);
+ add_scriptl(script->add_str(label));
add_scriptc(C_FUNC);
return p;
}
@@ -1787,28 +1759,28 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
// Put the label of the location
sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
syntax.curly[pos].count++;
- p = skip_space(p);
+ p = script->skip_space(p);
p2 = skip_word(p);
if(!syntax.curly[pos].flag && p2 - p == 4 && !strncasecmp(p,"else",4)) {
// else or else - if
- p = skip_space(p2);
+ p = script->skip_space(p2);
p2 = skip_word(p);
if(p2 - p == 2 && !strncasecmp(p,"if",2)) {
// else - if
- p=skip_space(p2);
+ p=script->skip_space(p2);
if(*p != '(') {
disp_error_message("need '('",p);
}
sprintf(label,"__IF%x_%x",syntax.curly[pos].index,syntax.curly[pos].count);
- add_scriptl(add_str("jump_zero"));
+ add_scriptl(script->add_str("jump_zero"));
add_scriptc(C_ARG);
p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
+ p=script->skip_space(p);
+ add_scriptl(script->add_str(label));
add_scriptc(C_FUNC);
*flag = 0;
return p;
@@ -1825,7 +1797,7 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
syntax.curly_count--;
// Put the label of the final location
sprintf(label,"__IF%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
if(syntax.curly[pos].flag == 1) {
// Because the position of the pointer is the same if not else for this
@@ -1840,17 +1812,17 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
if(syntax.curly[pos].flag) {
// (Come here continue) to form the label here
sprintf(label,"__DO%x_NXT",syntax.curly[pos].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
}
// Skip to the end point if the condition is false
- p = skip_space(p);
+ p = script->skip_space(p);
p2 = skip_word(p);
if(p2 - p != 5 || strncasecmp(p,"while",5))
disp_error_message("parse_syntax: need 'while'",p);
- p = skip_space(p2);
+ p = script->skip_space(p2);
if(*p != '(') {
disp_error_message("need '('",p);
}
@@ -1859,11 +1831,11 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
parse_nextline(false, p);
sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
- add_scriptl(add_str("jump_zero"));
+ add_scriptl(script->add_str("jump_zero"));
add_scriptc(C_ARG);
p=parse_expr(p);
- p=skip_space(p);
- add_scriptl(add_str(label));
+ p=script->skip_space(p);
+ add_scriptl(script->add_str(label));
add_scriptc(C_FUNC);
// Skip to the starting point
@@ -1874,9 +1846,9 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
// Form label of the end point conditions
sprintf(label,"__DO%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
- p = skip_space(p);
+ p = script->skip_space(p);
if(*p != ';') {
disp_error_message("parse_syntax: need ';'",p);
return p+1;
@@ -1896,7 +1868,7 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
// End for labeling
sprintf(label,"__FR%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
syntax.curly_count--;
return p;
@@ -1912,7 +1884,7 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
// End while labeling
sprintf(label,"__WL%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
syntax.curly_count--;
return p;
@@ -1928,7 +1900,7 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
// Put the label of the location
sprintf(label,"__FN%x_FIN",syntax.curly[pos].index);
- l=add_str(label);
+ l=script->add_str(label);
set_label(l,script_pos,p);
syntax.curly_count--;
return p;
@@ -1941,7 +1913,7 @@ const char* parse_syntax_close_sub(const char* p,int* flag)
/// Retrieves the value of a constant.
bool script_get_constant(const char* name, int* value)
{
- int n = search_str(name);
+ int n = script->search_str(name);
if( n == -1 || script->str_data[n].type != C_INT )
{// not found or not a constant
@@ -1954,7 +1926,7 @@ bool script_get_constant(const char* name, int* value)
/// Creates new constant or parameter with given value.
void script_set_constant(const char* name, int value, bool isparameter) {
- int n = add_str(name);
+ int n = script->add_str(name);
if( script->str_data[n].type == C_NOP ) {// new
script->str_data[n].type = isparameter ? C_PARAM : C_INT;
@@ -1967,7 +1939,7 @@ void script_set_constant(const char* name, int value, bool isparameter) {
}
/* adds data to a existent constant in the database, inserted normally via parse */
void script_set_constant2(const char *name, int value, bool isparameter) {
- int n = add_str(name);
+ int n = script->add_str(name);
if( ( script->str_data[n].type == C_NAME || script->str_data[n].type == C_PARAM ) && ( script->str_data[n].val != 0 || script->str_data[n].backpatch != -1 ) ) { // existing parameter or constant
ShowNotice("Conflicting item/script var '%s', prioritising the script var\n",name);
@@ -1986,7 +1958,7 @@ void script_set_constant2(const char *name, int value, bool isparameter) {
}
/* same as constant2 except it will override if necessary, used to clear conflicts during reload */
void script_set_constant_force(const char *name, int value, bool isparameter) {
- int n = add_str(name);
+ int n = script->add_str(name);
if( script->str_data[n].type == C_PARAM )
return;/* the one type we don't mess with, reload doesn't affect it. */
@@ -2120,7 +2092,7 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
int i;
const int size = ARRAYLENGTH(syntax.curly);
if( error_report )
- script_error(src,file,line,error_msg,error_pos);
+ script->error(src,file,line,error_msg,error_pos);
aFree( error_msg );
aFree( script_buf );
script_pos = 0;
@@ -2135,7 +2107,7 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
parse_syntax_for_flag=0;
p=src;
- p=skip_space(p);
+ p=script->skip_space(p);
if( options&SCRIPT_IGNORE_EXTERNAL_BRACKETS )
{// does not require brackets around the script
if( *p == '\0' && !(options&SCRIPT_RETURN_EMPTY_SCRIPT) )
@@ -2152,7 +2124,7 @@ 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+1);
+ p = script->skip_space(p+1);
if( *p == '}' && !(options&SCRIPT_RETURN_EMPTY_SCRIPT) )
{// empty script and can return NULL
aFree( script_buf );
@@ -2181,20 +2153,20 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
if( *p == '\0' )
disp_error_message("unexpected end of script",p);
// Special handling only label
- tmpp=skip_space(skip_word(p));
+ tmpp=script->skip_space(skip_word(p));
if(*tmpp==':' && !(!strncasecmp(p,"default:",8) && p + 7 == tmpp)){
i=add_word(p);
set_label(i,script_pos,p);
if( parse_options&SCRIPT_USE_LABEL_DB )
script->label_add(i,script_pos);
p=tmpp+1;
- p=skip_space(p);
+ p=script->skip_space(p);
continue;
}
// All other lumped
p=parse_line(p);
- p=skip_space(p);
+ p=script->skip_space(p);
parse_nextline(false, p);
}
@@ -2255,7 +2227,7 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
break;
case C_NAME:
j = (*(int*)(script_buf+i)&0xffffff);
- ShowMessage(" %s", ( j == 0xffffff ) ? "?? unknown ??" : get_str(j));
+ ShowMessage(" %s", ( j == 0xffffff ) ? "?? unknown ??" : script->get_str(j));
i += 3;
break;
case C_STR:
@@ -2527,12 +2499,12 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam
int set_var(TBL_PC* sd, char* name, void* val)
{
- return set_reg(NULL, sd, reference_uid(add_str(name),0), name, val, NULL);
+ return set_reg(NULL, sd, reference_uid(script->add_str(name),0), name, val, NULL);
}
void setd_sub(struct script_state *st, TBL_PC *sd, const char *varname, int elem, void *value, struct DBMap **ref)
{
- set_reg(st, sd, reference_uid(add_str(varname),elem), varname, value, ref);
+ set_reg(st, sd, reference_uid(script->add_str(varname),elem), varname, value, ref);
}
/// Converts the data to a string
@@ -2720,7 +2692,7 @@ void pop_stack(struct script_state* st, int start, int end)
{
struct script_retinfo* ri = data->u.ri;
if( ri->var_function )
- script_free_vars(ri->var_function);
+ script->free_vars(ri->var_function);
if( data->ref )
aFree(data->ref);
aFree(ri);
@@ -2761,7 +2733,7 @@ void script_free_vars(struct DBMap* storage)
void script_free_code(struct script_code* code)
{
- script_free_vars( code->script_vars );
+ script->free_vars( code->script_vars );
aFree( code->script_buf );
aFree( code );
}
@@ -2812,16 +2784,16 @@ void script_free_state(struct script_state* st) {
}
if( st->sleep.timer != INVALID_TIMER )
- iTimer->delete_timer(st->sleep.timer, run_script_timer);
+ iTimer->delete_timer(st->sleep.timer, script->run_timer);
if( st->stack ) {
- script_free_vars(st->stack->var_function);
+ script->free_vars(st->stack->var_function);
script->pop_stack(st, 0, st->stack->sp);
aFree(st->stack->stack_data);
ers_free(script->stack_ers, st->stack);
st->stack = NULL;
}
if( st->script && st->script->script_vars && !db_size(st->script->script_vars) ) {
- script_free_vars(st->script->script_vars);
+ script->free_vars(st->script->script_vars);
st->script->script_vars = NULL;
}
st->pos = -1;
@@ -2839,32 +2811,32 @@ void script_free_state(struct script_state* st) {
/*==========================================
* Read command
*------------------------------------------*/
-c_op get_com(unsigned char *script,int *pos)
+c_op get_com(unsigned char *scriptbuf,int *pos)
{
int i = 0, j = 0;
- if(script[*pos]>=0x80){
+ if(scriptbuf[*pos]>=0x80){
return C_INT;
}
- while(script[*pos]>=0x40){
- i=script[(*pos)++]<<j;
+ while(scriptbuf[*pos]>=0x40){
+ i=scriptbuf[(*pos)++]<<j;
j+=6;
}
- return (c_op)(i+(script[(*pos)++]<<j));
+ return (c_op)(i+(scriptbuf[(*pos)++]<<j));
}
/*==========================================
* Income figures
*------------------------------------------*/
-int get_num(unsigned char *script,int *pos)
+int get_num(unsigned char *scriptbuf,int *pos)
{
int i,j;
i=0; j=0;
- while(script[*pos]>=0xc0){
- i+=(script[(*pos)++]&0x7f)<<j;
+ while(scriptbuf[*pos]>=0xc0){
+ i+=(scriptbuf[(*pos)++]&0x7f)<<j;
j+=6;
}
- return i+((script[(*pos)++]&0x7f)<<j);
+ return i+((scriptbuf[(*pos)++]&0x7f)<<j);
}
/*==========================================
@@ -3200,7 +3172,7 @@ static void script_check_buildin_argtype(struct script_state* st, int func)
}
if(invalid) {
- ShowDebug("Function: %s\n", get_str(func));
+ ShowDebug("Function: %s\n", script->get_str(func));
script_reportsrc(st);
}
}
@@ -3240,8 +3212,7 @@ int run_func(struct script_state *st)
return 1;
}
- if( script_config.warn_func_mismatch_argtypes )
- {
+ if( script->config.warn_func_mismatch_argtypes ) {
script_check_buildin_argtype(st, func);
}
@@ -3249,7 +3220,7 @@ int run_func(struct script_state *st)
if (!(script->str_data[func].func(st))) //Report error
script_reportsrc(st);
} else {
- ShowError("script:run_func: '%s' (id=%d type=%s) has no C function. please report this!!!\n", get_str(func), func, script_op2name(script->str_data[func].type));
+ ShowError("script:run_func: '%s' (id=%d type=%s) has no C function. please report this!!!\n", script->get_str(func), func, script_op2name(script->str_data[func].type));
script_reportsrc(st);
st->state = END;
}
@@ -3273,7 +3244,7 @@ int run_func(struct script_state *st)
st->state = END;
return 1;
}
- script_free_vars( st->stack->var_function );
+ script->free_vars( st->stack->var_function );
ri = st->stack->stack_data[st->stack->defsp-1].u.ri;
nargs = ri->nargs;
@@ -3303,9 +3274,9 @@ void run_script(struct script_code *rootscript,int pos,int rid,int oid) {
// TODO In jAthena, this function can take over the pending script in the player. [FlavioJS]
// It is unclear how that can be triggered, so it needs the be traced/checked in more detail.
// NOTE At the time of this change, this function wasn't capable of taking over the script state because st->scriptroot was never set.
- st = script_alloc_state(rootscript, pos, rid, oid);
+ st = script->alloc_state(rootscript, pos, rid, oid);
- run_script_main(st);
+ script->run_main(st);
}
void script_stop_instances(struct script_code *code) {
@@ -3319,7 +3290,7 @@ void script_stop_instances(struct script_code *code) {
for( st = dbi_first(iter); dbi_exists(iter); st = dbi_next(iter) ) {
if( st->script == code ) {
- script_free_state(st);
+ script->free_state(st);
}
}
@@ -3341,7 +3312,7 @@ int run_script_timer(int tid, unsigned int tick, int id, intptr_t data) {
st->sleep.timer = INVALID_TIMER;
if(st->state != RERUNLINE)
st->sleep.tick = 0;
- run_script_main(st);
+ script->run_main(st);
}
return 0;
}
@@ -3381,7 +3352,7 @@ static void script_detach_state(struct script_state* st, bool dequeue_event)
ShowError("script_detach_state: Found previous script state without attached player (rid=%d, oid=%d, state=%d, bk_npcid=%d)\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid);
script_reportsrc(st->bk_st);
- script_free_state(st->bk_st);
+ script->free_state(st->bk_st);
st->bk_st = NULL;
}
}
@@ -3389,8 +3360,7 @@ static void script_detach_state(struct script_state* st, bool dequeue_event)
/// Attaches script state to possibly attached character and backups it's previous script, if any.
///
/// @param st Script state to attach.
-static void script_attach_state(struct script_state* st)
-{
+void script_attach_state(struct script_state* st) {
struct map_session_data* sd;
if(st->rid && (sd = iMap->id2sd(st->rid))!=NULL)
@@ -3423,13 +3393,13 @@ static void script_attach_state(struct script_state* st)
*------------------------------------------*/
void run_script_main(struct script_state *st)
{
- int cmdcount = script_config.check_cmdcount;
- int gotocount = script_config.check_gotocount;
+ int cmdcount = script->config.check_cmdcount;
+ int gotocount = script->config.check_gotocount;
TBL_PC *sd;
struct script_stack *stack = st->stack;
struct npc_data *nd;
- script_attach_state(st);
+ script->attach_state(st);
nd = iMap->id2nd(st->oid);
if( nd && nd->bl.m >= 0 )
@@ -3538,7 +3508,7 @@ void run_script_main(struct script_state *st)
sd = iMap->id2sd(st->rid); // Get sd since script might have attached someone while running. [Inkfish]
st->sleep.charid = sd?sd->status.char_id:0;
st->sleep.timer = iTimer->add_timer(iTimer->gettick()+st->sleep.tick,
- run_script_timer, st->sleep.charid, (intptr_t)st->id);
+ script->run_timer, st->sleep.charid, (intptr_t)st->id);
} else if(st->state != END && st->rid){
//Resume later (st is already attached to player).
if(st->bk_st) {
@@ -3549,7 +3519,7 @@ void run_script_main(struct script_state *st)
ShowDebug("Current script:\n");
script_reportsrc(st);
- script_free_state(st->bk_st);
+ script->free_state(st->bk_st);
st->bk_st = NULL;
}
} else {
@@ -3566,25 +3536,22 @@ void run_script_main(struct script_state *st)
if (sd->state.reg_dirty&1)
intif_saveregistry(sd,1);
}
- script_free_state(st);
+ script->free_state(st);
st = NULL;
}
}
-int script_config_read(char *cfgName)
-{
+int script_config_read(char *cfgName) {
int i;
char line[1024],w1[1024],w2[1024];
FILE *fp;
- fp=fopen(cfgName,"r");
- if(fp==NULL){
+ if( !( fp = fopen(cfgName,"r") ) ){
ShowError("File not found: %s\n", cfgName);
return 1;
}
- while(fgets(line, sizeof(line), fp))
- {
+ while(fgets(line, sizeof(line), fp)) {
if(line[0] == '/' && line[1] == '/')
continue;
i=sscanf(line,"%[^:]: %[^\r\n]",w1,w2);
@@ -3592,25 +3559,25 @@ int script_config_read(char *cfgName)
continue;
if(strcmpi(w1,"warn_func_mismatch_paramnum")==0) {
- script_config.warn_func_mismatch_paramnum = config_switch(w2);
+ script->config.warn_func_mismatch_paramnum = config_switch(w2);
}
else if(strcmpi(w1,"check_cmdcount")==0) {
- script_config.check_cmdcount = config_switch(w2);
+ script->config.check_cmdcount = config_switch(w2);
}
else if(strcmpi(w1,"check_gotocount")==0) {
- script_config.check_gotocount = config_switch(w2);
+ script->config.check_gotocount = config_switch(w2);
}
else if(strcmpi(w1,"input_min_value")==0) {
- script_config.input_min_value = config_switch(w2);
+ script->config.input_min_value = config_switch(w2);
}
else if(strcmpi(w1,"input_max_value")==0) {
- script_config.input_max_value = config_switch(w2);
+ script->config.input_max_value = config_switch(w2);
}
else if(strcmpi(w1,"warn_func_mismatch_argtypes")==0) {
- script_config.warn_func_mismatch_argtypes = config_switch(w2);
+ script->config.warn_func_mismatch_argtypes = config_switch(w2);
}
else if(strcmpi(w1,"import")==0){
- script_config_read(w2);
+ script->config_read(w2);
}
else {
ShowWarning("Unknown setting '%s' in file %s\n", w1, cfgName);
@@ -3628,29 +3595,27 @@ static int db_script_free_code_sub(DBKey key, DBData *data, va_list ap)
{
struct script_code *code = DB->data2ptr(data);
if (code)
- script_free_code(code);
+ script->free_code(code);
return 0;
}
void script_run_autobonus(const char *autobonus, int id, int pos)
{
- struct script_code *script = (struct script_code *)strdb_get(autobonus_db, autobonus);
+ struct script_code *scriptroot = (struct script_code *)strdb_get(script->autobonus_db, autobonus);
- if( script )
- {
+ if( scriptroot ) {
iStatus->current_equip_item_index = pos;
- run_script(script,0,id,0);
+ script->run(scriptroot,0,id,0);
}
}
void script_add_autobonus(const char *autobonus)
{
- if( strdb_get(autobonus_db, autobonus) == NULL )
- {
- struct script_code *script = parse_script(autobonus, "autobonus", 0, 0);
+ if( strdb_get(script->autobonus_db, autobonus) == NULL ) {
+ struct script_code *scriptroot = script->parse(autobonus, "autobonus", 0, 0);
- if( script )
- strdb_put(autobonus_db, autobonus, script);
+ if( scriptroot )
+ strdb_put(script->autobonus_db, autobonus, scriptroot);
}
}
@@ -3667,7 +3632,7 @@ void script_cleararray_pc(struct map_session_data* sd, const char* varname, void
return;
}
- key = add_str(varname);
+ key = script->add_str(varname);
if( is_string_variable(varname) )
{
@@ -3704,7 +3669,7 @@ void script_setarray_pc(struct map_session_data* sd, const char* varname, uint8
return;
}
- key = ( refcache && refcache[0] ) ? refcache[0] : add_str(varname);
+ key = ( refcache && refcache[0] ) ? refcache[0] : script->add_str(varname);
if( is_string_variable(varname) )
{
@@ -3716,7 +3681,7 @@ void script_setarray_pc(struct map_session_data* sd, const char* varname, uint8
}
if( refcache )
- {// save to avoid repeated add_str calls
+ {// save to avoid repeated script->add_str calls
refcache[0] = key;
}
}
@@ -3745,8 +3710,8 @@ void do_final_script(void) {
fprintf(fp,"num : hash : data_name\n");
fprintf(fp,"---------------------------------------------------------------\n");
for(i=LABEL_START; i<script->str_num; i++) {
- unsigned int h = calc_hash(get_str(i));
- fprintf(fp,"%04d : %4u : %s\n",i,h, get_str(i));
+ unsigned int h = calc_hash(script->get_str(i));
+ fprintf(fp,"%04d : %4u : %s\n",i,h, script->get_str(i));
++count[h];
}
fprintf(fp,"--------------------\n\n");
@@ -3786,15 +3751,15 @@ void do_final_script(void) {
iter = db_iterator(script->st_db);
for( st = dbi_first(iter); dbi_exists(iter); st = dbi_next(iter) ) {
- script_free_state(st);
+ script->free_state(st);
}
dbi_destroy(iter);
mapreg_final();
- userfunc_db->destroy(userfunc_db, db_script_free_code_sub);
- autobonus_db->destroy(autobonus_db, db_script_free_code_sub);
+ script->userfunc_db->destroy(script->userfunc_db, db_script_free_code_sub);
+ script->autobonus_db->destroy(script->autobonus_db, db_script_free_code_sub);
if (script->str_data)
aFree(script->str_data);
@@ -3849,8 +3814,8 @@ void do_final_script(void) {
*------------------------------------------*/
void do_init_script(void) {
script->st_db = idb_alloc(DB_OPT_BASE);
- userfunc_db = strdb_alloc(DB_OPT_DUP_KEY,0);
- autobonus_db = strdb_alloc(DB_OPT_DUP_KEY,0);
+ script->userfunc_db = strdb_alloc(DB_OPT_DUP_KEY,0);
+ script->autobonus_db = strdb_alloc(DB_OPT_DUP_KEY,0);
script->st_ers = ers_new(sizeof(struct script_state), "script.c::st_ers", ERS_OPT_NONE);
script->stack_ers = ers_new(sizeof(struct script_stack), "script.c::script_stack", ERS_OPT_NONE);
@@ -3871,12 +3836,12 @@ int script_reload() {
iter = db_iterator(script->st_db);
for( st = dbi_first(iter); dbi_exists(iter); st = dbi_next(iter) ) {
- script_free_state(st);
+ script->free_state(st);
}
dbi_destroy(iter);
- userfunc_db->clear(userfunc_db, db_script_free_code_sub);
+ script->userfunc_db->clear(script->userfunc_db, db_script_free_code_sub);
script->label_count = 0;
for( i = 0; i < atcommand->binding_count; i++ ) {
@@ -4150,7 +4115,7 @@ BUILDIN(menu)
st->state = END;
return false;
}
- pc->setreg(sd, add_str("@menu"), menu);
+ pc->setreg(sd, script->add_str("@menu"), menu);
st->pos = script_getnum(st, i + 1);
st->state = GOTO;
}
@@ -4227,7 +4192,7 @@ BUILDIN(select)
if( sd->npc_menu <= 0 )
break;// entry found
}
- pc->setreg(sd, add_str("@menu"), menu);
+ pc->setreg(sd, script->add_str("@menu"), menu);
script_pushint(st, menu);
st->state = RUN;
}
@@ -4298,7 +4263,7 @@ BUILDIN(prompt)
else if( sd->npc_menu == 0xff )
{// Cancel was pressed
sd->state.menu_or_input = 0;
- pc->setreg(sd, add_str("@menu"), 0xff);
+ pc->setreg(sd, script->add_str("@menu"), 0xff);
script_pushint(st, 0xff);
st->state = RUN;
}
@@ -4314,7 +4279,7 @@ BUILDIN(prompt)
if( sd->npc_menu <= 0 )
break;// entry found
}
- pc->setreg(sd, add_str("@menu"), menu);
+ pc->setreg(sd, script->add_str("@menu"), menu);
script_pushint(st, menu);
st->state = RUN;
}
@@ -4354,7 +4319,7 @@ BUILDIN(callfunc)
const char* str = script_getstr(st,2);
DBMap **ref = NULL;
- scr = (struct script_code*)strdb_get(userfunc_db, str);
+ scr = (struct script_code*)strdb_get(script->userfunc_db, str);
if( !scr )
{
ShowError("script:callfunc: function not found! [%s]\n", str);
@@ -4891,9 +4856,9 @@ BUILDIN(itemheal)
hp=script_getnum(st,2);
sp=script_getnum(st,3);
- if(potion_flag==1) {
- potion_hp = hp;
- potion_sp = sp;
+ if(script->potion_flag==1) {
+ script->potion_hp = hp;
+ script->potion_sp = sp;
return true;
}
@@ -4913,9 +4878,9 @@ BUILDIN(percentheal)
hp=script_getnum(st,2);
sp=script_getnum(st,3);
- if(potion_flag==1) {
- potion_per_hp = hp;
- potion_per_sp = sp;
+ if(script->potion_flag==1) {
+ script->potion_per_hp = hp;
+ script->potion_per_sp = sp;
return true;
}
@@ -4994,8 +4959,8 @@ BUILDIN(input)
}
uid = reference_getuid(data);
name = reference_getname(data);
- min = (script_hasdata(st,3) ? script_getnum(st,3) : script_config.input_min_value);
- max = (script_hasdata(st,4) ? script_getnum(st,4) : script_config.input_max_value);
+ min = (script_hasdata(st,3) ? script_getnum(st,3) : script->config.input_min_value);
+ max = (script_hasdata(st,4) ? script_getnum(st,4) : script->config.input_max_value);
#ifdef SECURE_NPCTIMEOUT
sd->npc_idle_type = NPCT_WAIT;
@@ -6721,19 +6686,19 @@ BUILDIN(getpartymember)
if(p->party.member[i].account_id){
switch (type) {
case 2:
- mapreg_setreg(reference_uid(add_str("$@partymemberaid"), j),p->party.member[i].account_id);
+ mapreg_setreg(reference_uid(script->add_str("$@partymemberaid"), j),p->party.member[i].account_id);
break;
case 1:
- mapreg_setreg(reference_uid(add_str("$@partymembercid"), j),p->party.member[i].char_id);
+ mapreg_setreg(reference_uid(script->add_str("$@partymembercid"), j),p->party.member[i].char_id);
break;
default:
- mapreg_setregstr(reference_uid(add_str("$@partymembername$"), j),p->party.member[i].name);
+ mapreg_setregstr(reference_uid(script->add_str("$@partymembername$"), j),p->party.member[i].name);
}
j++;
}
}
}
- mapreg_setreg(add_str("$@partymembercount"),j);
+ mapreg_setreg(script->add_str("$@partymembercount"),j);
return true;
}
@@ -8528,13 +8493,13 @@ BUILDIN(getmobdrops)
if( itemdb->exists(mob->dropitem[i].nameid) == NULL )
continue;
- mapreg_setreg(reference_uid(add_str("$@MobDrop_item"), j), mob->dropitem[i].nameid);
- mapreg_setreg(reference_uid(add_str("$@MobDrop_rate"), j), mob->dropitem[i].p);
+ mapreg_setreg(reference_uid(script->add_str("$@MobDrop_item"), j), mob->dropitem[i].nameid);
+ mapreg_setreg(reference_uid(script->add_str("$@MobDrop_rate"), j), mob->dropitem[i].p);
j++;
}
- mapreg_setreg(add_str("$@MobDrop_count"), j);
+ mapreg_setreg(script->add_str("$@MobDrop_count"), j);
script_pushint(st, 1);
return true;
@@ -9217,7 +9182,7 @@ BUILDIN(itemeffect) {
return false;
}
- run_script( item_data->script, 0, sd->bl.id, nd->bl.id );
+ script->run( item_data->script, 0, sd->bl.id, nd->bl.id );
return true;
}
@@ -9513,9 +9478,9 @@ BUILDIN(sc_start)
tick = skill->get_time(iStatus->sc2skill(type), val1);
}
- if( potion_flag == 1 && potion_target )
+ if( script->potion_flag == 1 && script->potion_target )
{ //skill.c set the flags before running the script, this must be a potion-pitched effect.
- bl = iMap->id2bl(potion_target);
+ bl = iMap->id2bl(script->potion_target);
tick /= 2;// Thrown potions only last half.
val4 = 1;// Mark that this was a thrown sc_effect
}
@@ -9552,9 +9517,9 @@ BUILDIN(sc_start2)
tick = skill->get_time(iStatus->sc2skill(type), val1);
}
- if( potion_flag == 1 && potion_target )
+ if( script->potion_flag == 1 && script->potion_target )
{ //skill.c set the flags before running the script, this must be a potion-pitched effect.
- bl = iMap->id2bl(potion_target);
+ bl = iMap->id2bl(script->potion_target);
tick /= 2;// Thrown potions only last half.
val4 = 1;// Mark that this was a thrown sc_effect
}
@@ -9594,9 +9559,9 @@ BUILDIN(sc_start4)
tick = skill->get_time(iStatus->sc2skill(type), val1);
}
- if( potion_flag == 1 && potion_target )
+ if( script->potion_flag == 1 && script->potion_target )
{ //skill.c set the flags before running the script, this must be a potion-pitched effect.
- bl = iMap->id2bl(potion_target);
+ bl = iMap->id2bl(script->potion_target);
tick /= 2;// Thrown potions only last half.
}
@@ -9620,8 +9585,8 @@ BUILDIN(sc_end)
else
bl = iMap->id2bl(st->rid);
- if (potion_flag == 1 && potion_target) //##TODO how does this work [FlavioJS]
- bl = iMap->id2bl(potion_target);
+ if (script->potion_flag == 1 && script->potion_target) //##TODO how does this work [FlavioJS]
+ bl = iMap->id2bl(script->potion_target);
if (!bl)
return true;
@@ -10231,7 +10196,7 @@ BUILDIN(warpwaitingpc)
pc->payzeny(sd, cd->zeny, LOG_TYPE_NPC, NULL);
}
- mapreg_setreg(reference_uid(add_str("$@warpwaitingpc"), i), sd->bl.id);
+ mapreg_setreg(reference_uid(script->add_str("$@warpwaitingpc"), i), sd->bl.id);
if( strcmp(map_name,"Random") == 0 )
pc->randomwarp(sd,CLR_TELEPORT);
@@ -10240,7 +10205,7 @@ BUILDIN(warpwaitingpc)
else
pc->setpos(sd, mapindex_name2id(map_name), x, y, CLR_OUTSIGHT);
}
- mapreg_setreg(add_str("$@warpwaitingpcnum"), i);
+ mapreg_setreg(script->add_str("$@warpwaitingpcnum"), i);
return true;
}
@@ -10269,7 +10234,7 @@ BUILDIN(attachrid)
script_detach_rid(st);
st->rid = rid;
- script_attach_state(st);
+ script->attach_state(st);
script_pushint(st,1);
} else
script_pushint(st,0);
@@ -11759,22 +11724,22 @@ BUILDIN(getinventorylist)
if(!sd) return true;
for(i=0;i<MAX_INVENTORY;i++){
if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
- pc->setreg(sd,reference_uid(add_str("@inventorylist_id"), j),sd->status.inventory[i].nameid);
- pc->setreg(sd,reference_uid(add_str("@inventorylist_amount"), j),sd->status.inventory[i].amount);
- pc->setreg(sd,reference_uid(add_str("@inventorylist_equip"), j),sd->status.inventory[i].equip);
- pc->setreg(sd,reference_uid(add_str("@inventorylist_refine"), j),sd->status.inventory[i].refine);
- pc->setreg(sd,reference_uid(add_str("@inventorylist_identify"), j),sd->status.inventory[i].identify);
- pc->setreg(sd,reference_uid(add_str("@inventorylist_attribute"), j),sd->status.inventory[i].attribute);
+ pc->setreg(sd,reference_uid(script->add_str("@inventorylist_id"), j),sd->status.inventory[i].nameid);
+ pc->setreg(sd,reference_uid(script->add_str("@inventorylist_amount"), j),sd->status.inventory[i].amount);
+ pc->setreg(sd,reference_uid(script->add_str("@inventorylist_equip"), j),sd->status.inventory[i].equip);
+ pc->setreg(sd,reference_uid(script->add_str("@inventorylist_refine"), j),sd->status.inventory[i].refine);
+ pc->setreg(sd,reference_uid(script->add_str("@inventorylist_identify"), j),sd->status.inventory[i].identify);
+ pc->setreg(sd,reference_uid(script->add_str("@inventorylist_attribute"), j),sd->status.inventory[i].attribute);
for (k = 0; k < MAX_SLOTS; k++)
{
sprintf(card_var, "@inventorylist_card%d",k+1);
- pc->setreg(sd,reference_uid(add_str(card_var), j),sd->status.inventory[i].card[k]);
+ pc->setreg(sd,reference_uid(script->add_str(card_var), j),sd->status.inventory[i].card[k]);
}
- pc->setreg(sd,reference_uid(add_str("@inventorylist_expire"), j),sd->status.inventory[i].expire_time);
+ pc->setreg(sd,reference_uid(script->add_str("@inventorylist_expire"), j),sd->status.inventory[i].expire_time);
j++;
}
}
- pc->setreg(sd,add_str("@inventorylist_count"),j);
+ pc->setreg(sd,script->add_str("@inventorylist_count"),j);
return true;
}
@@ -11785,13 +11750,13 @@ BUILDIN(getskilllist)
if(!sd) return true;
for(i=0;i<MAX_SKILL;i++){
if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0){
- pc->setreg(sd,reference_uid(add_str("@skilllist_id"), j),sd->status.skill[i].id);
- pc->setreg(sd,reference_uid(add_str("@skilllist_lv"), j),sd->status.skill[i].lv);
- pc->setreg(sd,reference_uid(add_str("@skilllist_flag"), j),sd->status.skill[i].flag);
+ pc->setreg(sd,reference_uid(script->add_str("@skilllist_id"), j),sd->status.skill[i].id);
+ pc->setreg(sd,reference_uid(script->add_str("@skilllist_lv"), j),sd->status.skill[i].lv);
+ pc->setreg(sd,reference_uid(script->add_str("@skilllist_flag"), j),sd->status.skill[i].flag);
j++;
}
}
- pc->setreg(sd,add_str("@skilllist_count"),j);
+ pc->setreg(sd,script->add_str("@skilllist_count"),j);
return true;
}
@@ -12849,7 +12814,7 @@ BUILDIN(getmapxy)
//Set MapName$
num=st->stack->stack_data[st->start+2].u.num;
- name=get_str(num&0x00ffffff);
+ name=script->get_str(num&0x00ffffff);
prefix=*name;
if(not_server_variable(prefix))
@@ -12860,7 +12825,7 @@ BUILDIN(getmapxy)
//Set MapX
num=st->stack->stack_data[st->start+3].u.num;
- name=get_str(num&0x00ffffff);
+ name=script->get_str(num&0x00ffffff);
prefix=*name;
if(not_server_variable(prefix))
@@ -12871,7 +12836,7 @@ BUILDIN(getmapxy)
//Set MapY
num=st->stack->stack_data[st->start+4].u.num;
- name=get_str(num&0x00ffffff);
+ name=script->get_str(num&0x00ffffff);
prefix=*name;
if(not_server_variable(prefix))
@@ -14193,9 +14158,9 @@ BUILDIN(setd)
}
if( is_string_variable(varname) ) {
- setd_sub(st, sd, varname, elem, (void *)script_getstr(st, 3), NULL);
+ script->setd_sub(st, sd, varname, elem, (void *)script_getstr(st, 3), NULL);
} else {
- setd_sub(st, sd, varname, elem, (void *)__64BPTRSIZE(script_getnum(st, 3)), NULL);
+ script->setd_sub(st, sd, varname, elem, (void *)__64BPTRSIZE(script_getnum(st, 3)), NULL);
}
return true;
@@ -14272,9 +14237,9 @@ int buildin_query_sql_sub(struct script_state* st, Sql* handle)
data = script_getdata(st, j+3);
name = reference_getname(data);
if( is_string_variable(name) )
- setd_sub(st, sd, name, i, (void *)(str?str:""), reference_getref(data));
+ script->setd_sub(st, sd, name, i, (void *)(str?str:""), reference_getref(data));
else
- setd_sub(st, sd, name, i, (void *)__64BPTRSIZE((str?atoi(str):0)), reference_getref(data));
+ script->setd_sub(st, sd, name, i, (void *)__64BPTRSIZE((str?atoi(str):0)), reference_getref(data));
}
}
if( i == max_rows && max_rows < SQL->NumRows(handle) ) {
@@ -14328,7 +14293,7 @@ BUILDIN(getd)
elem = 0;
// Push the 'pointer' so it's more flexible [Lance]
- script->push_val(st->stack, C_NAME, reference_uid(add_str(varname), elem),NULL);
+ script->push_val(st->stack, C_NAME, reference_uid(script->add_str(varname), elem),NULL);
return true;
}
@@ -14563,9 +14528,9 @@ BUILDIN(setitemscript)
break;
}
if(*dstscript)
- script_free_code(*dstscript);
+ script->free_code(*dstscript);
- *dstscript = new_bonus_script[0] ? parse_script(new_bonus_script, "script_setitemscript", 0, 0) : NULL;
+ *dstscript = new_bonus_script[0] ? script->parse(new_bonus_script, "script_setitemscript", 0, 0) : NULL;
script_pushint(st,1);
return true;
}
@@ -15240,11 +15205,11 @@ BUILDIN(awake) {
tst->rid = 0;
}
- iTimer->delete_timer(tst->sleep.timer, run_script_timer);
+ iTimer->delete_timer(tst->sleep.timer, script->run_timer);
tst->sleep.timer = INVALID_TIMER;
if(tst->state != RERUNLINE)
tst->sleep.tick = 0;
- run_script_main(tst);
+ script->run_main(tst);
}
}
@@ -15731,12 +15696,12 @@ BUILDIN(waitingroom2bg)
for( i = 0; i < n && i < MAX_BG_MEMBERS; i++ )
{
if( (sd = cd->usersd[i]) != NULL && bg_team_join(bg_id, sd) )
- mapreg_setreg(reference_uid(add_str("$@arenamembers"), i), sd->bl.id);
+ mapreg_setreg(reference_uid(script->add_str("$@arenamembers"), i), sd->bl.id);
else
- mapreg_setreg(reference_uid(add_str("$@arenamembers"), i), 0);
+ mapreg_setreg(reference_uid(script->add_str("$@arenamembers"), i), 0);
}
- mapreg_setreg(add_str("$@arenamembersnum"), i);
+ mapreg_setreg(script->add_str("$@arenamembersnum"), i);
script_pushint(st,bg_id);
return true;
}
@@ -16697,7 +16662,7 @@ BUILDIN(getcharip)
BUILDIN(is_function) {
const char* str = script_getstr(st,2);
- if( strdb_exists(userfunc_db, str) )
+ if( strdb_exists(script->userfunc_db, str) )
script_pushint(st,1);
else
script_pushint(st,0);
@@ -17563,7 +17528,7 @@ BUILDIN(bg_match_over) {
#endif
bool script_hp_add(char *name, char *args, bool (*func)(struct script_state *st)) {
- int n = add_str(name), i = 0;
+ int n = script->add_str(name), i = 0;
if( script->str_data[n].type == C_FUNC ) {
script->str_data[n].func = func;
@@ -18101,7 +18066,7 @@ void script_parse_builtin(void) {
ShowWarning("script_parse_builtin: ignoring function with invalid name \"%s\" (must be a word).\n", BUILDIN[i].name);
} else {
int slen = strlen(BUILDIN[i].arg), offset = start + i;
- n = add_str(BUILDIN[i].name);
+ n = script->add_str(BUILDIN[i].name);
if (!strcmp(BUILDIN[i].name, "set")) buildin_set_ref = n;
else if (!strcmp(BUILDIN[i].name, "callsub")) buildin_callsub_ref = n;
@@ -18174,10 +18139,25 @@ void script_defaults(void) {
script->label_count = 0;
script->labels_size = 0;
+ memset(&script->config, 0, sizeof(script->config));
+
+ script->autobonus_db = NULL;
+ script->userfunc_db = NULL;
+
+ script->potion_flag = script->potion_hp = script->potion_per_hp =
+ script->potion_sp = script->potion_per_sp = script->potion_target = 0;
+
script->init = do_init_script;
script->final = do_final_script;
+ script->reload = script_reload;
+ /* parse */
+ script->parse = parse_script;
script->parse_builtin = script_parse_builtin;
+ script->skip_space = script_skip_space;
+ script->error = script_error;
+ script->parse_subexpr = script_parse_subexpr;
+
script->addScript = script_hp_add;
script->conv_num = conv_num;
script->conv_str = conv_str;
@@ -18194,6 +18174,24 @@ void script_defaults(void) {
script->set_constant_force = script_set_constant_force;
script->get_constant = script_get_constant;
script->label_add = script_label_add;
+ script->run = run_script;
+ script->run_main = run_script_main;
+ script->run_timer = run_script_timer;
+ script->set_var = set_var;
+ script->stop_instances = script_stop_instances;
+ script->free_code = script_free_code;
+ script->free_vars = script_free_vars;
+ script->alloc_state = script_alloc_state;
+ script->free_state = script_free_state;
+ script->run_autobonus = script_run_autobonus;
+ script->cleararray_pc = script_cleararray_pc;
+ script->setarray_pc = script_setarray_pc;
+ script->config_read = script_config_read;
+ script->add_str = script_add_str;
+ script->get_str = script_get_str;
+ script->search_str = script_search_str;
+ script->setd_sub = setd_sub;
+ script->attach_state = script_attach_state;
script->queue = script_hqueue_get;
script->queue_add = script_hqueue_add;
@@ -18201,4 +18199,22 @@ void script_defaults(void) {
script->queue_remove = script_hqueue_remove;
script->queue_create = script_hqueue_create;
script->queue_clear = script_hqueue_clear;
+
+ /* script_config base */
+ script->config.warn_func_mismatch_argtypes = 1;
+ script->config.warn_func_mismatch_paramnum = 1;
+ script->config.check_cmdcount = 65535;
+ script->config.check_gotocount = 2048;
+ script->config.input_min_value = 0;
+ script->config.input_max_value = INT_MAX;
+ script->config.die_event_name = "OnPCDieEvent";
+ script->config.kill_pc_event_name = "OnPCKillEvent";
+ script->config.kill_mob_event_name = "OnNPCKillEvent";
+ script->config.login_event_name = "OnPCLoginEvent";
+ script->config.logout_event_name = "OnPCLogoutEvent";
+ script->config.loadmap_event_name = "OnPCLoadMapEvent";
+ script->config.baselvup_event_name = "OnPCBaseLvUpEvent";
+ script->config.joblvup_event_name = "OnPCJobLvUpEvent";
+ script->config.ontouch_name = "OnTouch_";//ontouch_name (runs on first visible char to enter area, picks another char if the first char leaves)
+ script->config.ontouch2_name = "OnTouch";//ontouch2_name (run whenever a char walks into the OnTouch area)
}
diff --git a/src/map/script.h b/src/map/script.h
index 8e2c4a6f5..82224a7af 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -6,36 +6,20 @@
#include "map.h" //EVENT_NAME_LENGTH
-#define NUM_WHISPER_VAR 10
-
+/**
+ * Declarations
+ **/
struct map_session_data;
struct eri;
-extern int potion_flag; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
-extern int potion_hp, potion_per_hp, potion_sp, potion_per_sp;
-extern int potion_target;
-
-extern struct Script_Config {
- unsigned warn_func_mismatch_argtypes : 1;
- unsigned warn_func_mismatch_paramnum : 1;
- int check_cmdcount;
- int check_gotocount;
- int input_min_value;
- int input_max_value;
-
- const char *die_event_name;
- const char *kill_pc_event_name;
- const char *kill_mob_event_name;
- const char *login_event_name;
- const char *logout_event_name;
- const char *loadmap_event_name;
- const char *baselvup_event_name;
- const char *joblvup_event_name;
-
- const char* ontouch_name;
- const char* ontouch2_name;
-} script_config;
+/**
+ * Defines
+ **/
+#define NUM_WHISPER_VAR 10
+/**
+ * Enumerations
+ **/
typedef enum c_op {
C_NOP, // end of script/no value (nil)
C_POS,
@@ -51,7 +35,7 @@ typedef enum c_op {
C_USERFUNC, // internal script function
C_USERFUNC_POS, // internal script function label
C_REF, // the next call to c_op2 should push back a ref to the left operand
-
+
// operators
C_OP3, // a ? b : c
C_LOR, // a || b
@@ -79,6 +63,47 @@ typedef enum c_op {
C_SUB_PP, // --a
} c_op;
+enum hQueueOpt {
+ HQO_NONE,
+ HQO_onLogOut,
+ HQO_OnDeath,
+ HQO_OnMapChange,
+ HQO_MAX,
+};
+
+enum e_script_state { RUN,STOP,END,RERUNLINE,GOTO,RETFUNC,CLOSE };
+
+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_RETURN_EMPTY_SCRIPT = 0x4// returns the script object instead of NULL for empty scripts
+};
+
+/**
+ * Structures
+ **/
+
+struct Script_Config {
+ unsigned warn_func_mismatch_argtypes : 1;
+ unsigned warn_func_mismatch_paramnum : 1;
+ int check_cmdcount;
+ int check_gotocount;
+ int input_min_value;
+ int input_max_value;
+
+ const char *die_event_name;
+ const char *kill_pc_event_name;
+ const char *kill_mob_event_name;
+ const char *login_event_name;
+ const char *logout_event_name;
+ const char *loadmap_event_name;
+ const char *baselvup_event_name;
+ const char *joblvup_event_name;
+
+ const char* ontouch_name;
+ const char* ontouch2_name;
+};
+
struct script_retinfo {
struct DBMap* var_function;// scope variables
struct script_code* script;// script code
@@ -113,14 +138,6 @@ struct script_stack {
struct DBMap* var_function;// scope variables
};
-enum hQueueOpt {
- HQO_NONE,
- HQO_onLogOut,
- HQO_OnDeath,
- HQO_OnMapChange,
- HQO_MAX,
-};
-
/* [Ind/Hercules] */
struct hQueue {
int id;
@@ -138,11 +155,6 @@ struct hQueueIterator {
int pos;
};
-//
-// Script state
-//
-enum e_script_state { RUN,STOP,END,RERUNLINE,GOTO,RETFUNC,CLOSE };
-
struct script_state {
struct script_stack* stack;
int start,end;
@@ -174,44 +186,6 @@ struct script_regstr {
char* data;
};
-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_RETURN_EMPTY_SCRIPT = 0x4// returns the script object instead of NULL for empty scripts
-};
-
-const char* skip_space(const char* p);
-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);
-
-int set_var(struct map_session_data *sd, char *name, void *val);
-int run_script_timer(int tid, unsigned int tick, int id, intptr_t data);
-void run_script_main(struct script_state *st);
-
-void script_stop_instances(struct script_code *code);
-struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n);
-void script_free_code(struct script_code* code);
-void script_free_vars(struct DBMap *storage);
-struct script_state* script_alloc_state(struct script_code* rootscript, int pos, int rid, int oid);
-void script_free_state(struct script_state* st);
-
-struct DBMap* script_get_userfunc_db(void);
-void script_run_autobonus(const char *autobonus,int id, int pos);
-
-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);
-
-int script_config_read(char *cfgName);
-int add_str(const char* p);
-const char* get_str(int id);
-int script_reload(void);
-
-// @commands (script based)
-void setd_sub(struct script_state *st, struct map_session_data *sd, const char *varname, int elem, void *value, struct DBMap **ref);
-
struct script_function {
bool (*func)(struct script_state *st);
char *name;
@@ -366,11 +340,28 @@ struct script_interface {
struct script_label_entry *labels;
int label_count;
int labels_size;
+ /* */
+ struct Script_Config config;
+ /* */
+ /* Caches compiled autoscript item code. */
+ /* Note: This is not cleared when reloading itemdb. */
+ DBMap* autobonus_db; // char* script -> char* bytecode
+ DBMap* userfunc_db; // const char* func_name -> struct script_code*
+ /* */
+ int potion_flag; //For use on Alchemist improved potions/Potion Pitcher. [Skotlex]
+ int potion_hp, potion_per_hp, potion_sp, potion_per_sp;
+ int potion_target;
/* */
void (*init) (void);
void (*final) (void);
- /* */
+ int (*reload) (void);
+ /* parse */
+ struct script_code* (*parse) (const char* src,const char* file,int line,int options);
void (*parse_builtin) (void);
+ const char* (*parse_subexpr) (const char* p,int limit);
+ const char* (*skip_space) (const char* p);
+ void (*error) (const char* src, const char* file, int start_line, const char* error_msg, const char* error_pos);
+ /* */
bool (*addScript) (char *name, char *args, bool (*func)(struct script_state *st));
int (*conv_num) (struct script_state *st,struct script_data *data);
const char* (*conv_str) (struct script_state *st,struct script_data *data);
@@ -387,6 +378,24 @@ struct script_interface {
void (*set_constant_force) (const char *name, int value, bool isparameter);
bool (*get_constant) (const char* name, int* value);
void (*label_add)(int key, int pos);
+ void (*run) (struct script_code *rootscript,int pos,int rid,int oid);
+ void (*run_main) (struct script_state *st);
+ int (*run_timer) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*set_var) (struct map_session_data *sd, char *name, void *val);
+ void (*stop_instances) (struct script_code *code);
+ void (*free_code) (struct script_code* code);
+ void (*free_vars) (struct DBMap *storage);
+ struct script_state* (*alloc_state) (struct script_code* rootscript, int pos, int rid, int oid);
+ void (*free_state) (struct script_state* st);
+ void (*run_autobonus) (const char *autobonus,int id, int pos);
+ void (*cleararray_pc) (struct map_session_data* sd, const char* varname, void* value);
+ void (*setarray_pc) (struct map_session_data* sd, const char* varname, uint8 idx, void* value, int* refcache);
+ int (*config_read) (char *cfgName);
+ int (*add_str) (const char* p);
+ const char* (*get_str) (int id);
+ int (*search_str) (const char* p);
+ void (*setd_sub) (struct script_state *st, struct map_session_data *sd, const char *varname, int elem, void *value, struct DBMap **ref);
+ void (*attach_state) (struct script_state* st);
/* */
struct hQueue *(*queue) (int idx);
bool (*queue_add) (int idx, int var);
diff --git a/src/map/skill.c b/src/map/skill.c
index 28c5245bb..835d5cca9 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -6489,29 +6489,29 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
return 1;
}
}
- potion_flag = 1;
- potion_hp = potion_sp = potion_per_hp = potion_per_sp = 0;
- potion_target = bl->id;
- run_script(sd->inventory_data[i]->script,0,sd->bl.id,0);
- potion_flag = potion_target = 0;
+ script->potion_flag = 1;
+ script->potion_hp = script->potion_sp = script->potion_per_hp = script->potion_per_sp = 0;
+ script->potion_target = bl->id;
+ script->run(sd->inventory_data[i]->script,0,sd->bl.id,0);
+ script->potion_flag = script->potion_target = 0;
if( sd->sc.data[SC_SOULLINK] && sd->sc.data[SC_SOULLINK]->val2 == SL_ALCHEMIST )
bonus += sd->status.base_level;
- if( potion_per_hp > 0 || potion_per_sp > 0 ) {
- hp = tstatus->max_hp * potion_per_hp / 100;
+ if( script->potion_per_hp > 0 || script->potion_per_sp > 0 ) {
+ hp = tstatus->max_hp * script->potion_per_hp / 100;
hp = hp * (100 + pc->checkskill(sd,AM_POTIONPITCHER)*10 + pc->checkskill(sd,AM_LEARNINGPOTION)*5)*bonus/10000;
if( dstsd ) {
- sp = dstsd->status.max_sp * potion_per_sp / 100;
+ sp = dstsd->status.max_sp * script->potion_per_sp / 100;
sp = sp * (100 + pc->checkskill(sd,AM_POTIONPITCHER)*10 + pc->checkskill(sd,AM_LEARNINGPOTION)*5)*bonus/10000;
}
} else {
- if( potion_hp > 0 ) {
- hp = potion_hp * (100 + pc->checkskill(sd,AM_POTIONPITCHER)*10 + pc->checkskill(sd,AM_LEARNINGPOTION)*5)*bonus/10000;
+ if( script->potion_hp > 0 ) {
+ hp = script->potion_hp * (100 + pc->checkskill(sd,AM_POTIONPITCHER)*10 + pc->checkskill(sd,AM_LEARNINGPOTION)*5)*bonus/10000;
hp = hp * (100 + (tstatus->vit<<1)) / 100;
if( dstsd )
hp = hp * (100 + pc->checkskill(dstsd,SM_RECOVERY)*10) / 100;
}
- if( potion_sp > 0 ) {
- sp = potion_sp * (100 + pc->checkskill(sd,AM_POTIONPITCHER)*10 + pc->checkskill(sd,AM_LEARNINGPOTION)*5)*bonus/10000;
+ if( script->potion_sp > 0 ) {
+ sp = script->potion_sp * (100 + pc->checkskill(sd,AM_POTIONPITCHER)*10 + pc->checkskill(sd,AM_LEARNINGPOTION)*5)*bonus/10000;
sp = sp * (100 + (tstatus->int_<<1)) / 100;
if( dstsd )
sp = sp * (100 + pc->checkskill(dstsd,MG_SRECOVERY)*10) / 100;
@@ -7224,8 +7224,8 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
// Updated to block Slim Pitcher from working on barricades and guardian stones.
if( dstmd && (dstmd->class_ == MOBID_EMPERIUM || (dstmd->class_ >= MOBID_BARRICADE1 && dstmd->class_ <= MOBID_GUARIDAN_STONE2)) )
break;
- if (potion_hp || potion_sp) {
- int hp = potion_hp, sp = potion_sp;
+ if (script->potion_hp || script->potion_sp) {
+ int hp = script->potion_hp, sp = script->potion_sp;
hp = hp * (100 + (tstatus->vit<<1))/100;
sp = sp * (100 + (tstatus->int_<<1))/100;
if (dstsd) {
@@ -9015,13 +9015,13 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
} else //Otherwise, it fails, shows animation and removes items.
clif->skill_fail(sd,GN_SLINGITEM_RANGEMELEEATK,0xa,0);
} else if( itemdb_is_GNthrowable(ammo_id) ){
- struct script_code *script = sd->inventory_data[i]->script;
+ struct script_code *scriptroot = sd->inventory_data[i]->script;
if( !script )
break;
if( dstsd )
- run_script(script,0,dstsd->bl.id,fake_nd->bl.id);
+ script->run(scriptroot,0,dstsd->bl.id,fake_nd->bl.id);
else
- run_script(script,0,src->id,0);
+ script->run(scriptroot,0,src->id,0);
}
}
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
@@ -9996,21 +9996,21 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return 1;
}
- potion_flag = 1;
- potion_hp = 0;
- potion_sp = 0;
- run_script(sd->inventory_data[j]->script,0,sd->bl.id,0);
- potion_flag = 0;
+ script->potion_flag = 1;
+ script->potion_hp = 0;
+ script->potion_sp = 0;
+ script->run(sd->inventory_data[j]->script,0,sd->bl.id,0);
+ script->potion_flag = 0;
//Apply skill bonuses
i = pc->checkskill(sd,CR_SLIMPITCHER)*10
+ pc->checkskill(sd,AM_POTIONPITCHER)*10
+ pc->checkskill(sd,AM_LEARNINGPOTION)*5
+ pc->skillheal_bonus(sd, skill_id);
- potion_hp = potion_hp * (100+i)/100;
- potion_sp = potion_sp * (100+i)/100;
+ script->potion_hp = script->potion_hp * (100+i)/100;
+ script->potion_sp = script->potion_sp * (100+i)/100;
- if(potion_hp > 0 || potion_sp > 0) {
+ if(script->potion_hp > 0 || script->potion_sp > 0) {
i = skill->get_splash(skill_id, skill_lv);
iMap->foreachinarea(skill->area_sub,
src->m,x-i,y-i,x+i,y+i,BL_CHAR,
@@ -10022,17 +10022,17 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
struct item_data *item;
i = skill_db[skill_id].itemid[i];
item = itemdb->search(i);
- potion_flag = 1;
- potion_hp = 0;
- potion_sp = 0;
- run_script(item->script,0,src->id,0);
- potion_flag = 0;
+ script->potion_flag = 1;
+ script->potion_hp = 0;
+ script->potion_sp = 0;
+ script->run(item->script,0,src->id,0);
+ script->potion_flag = 0;
i = skill->get_max(CR_SLIMPITCHER)*10;
- potion_hp = potion_hp * (100+i)/100;
- potion_sp = potion_sp * (100+i)/100;
+ script->potion_hp = script->potion_hp * (100+i)/100;
+ script->potion_sp = script->potion_sp * (100+i)/100;
- if(potion_hp > 0 || potion_sp > 0) {
+ if(script->potion_hp > 0 || script->potion_sp > 0) {
i = skill->get_splash(skill_id, skill_lv);
iMap->foreachinarea(skill->area_sub,
src->m,x-i,y-i,x+i,y+i,BL_CHAR,
diff --git a/src/map/status.c b/src/map/status.c
index 58e844529..7d5676b98 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -2491,7 +2491,7 @@ int status_calc_pc_(struct map_session_data* sd, bool first)
if(first && sd->inventory_data[index]->equip_script)
{ //Execute equip-script on login
- run_script(sd->inventory_data[index]->equip_script,0,sd->bl.id,0);
+ script->run(sd->inventory_data[index]->equip_script,0,sd->bl.id,0);
if (!calculating)
return 1;
}
@@ -2532,11 +2532,11 @@ int status_calc_pc_(struct map_session_data* sd, bool first)
if(sd->inventory_data[index]->script) {
if (wd == &sd->left_weapon) {
sd->state.lr_flag = 1;
- run_script(sd->inventory_data[index]->script,0,sd->bl.id,0);
+ script->run(sd->inventory_data[index]->script,0,sd->bl.id,0);
sd->state.lr_flag = 0;
} else
- run_script(sd->inventory_data[index]->script,0,sd->bl.id,0);
- if (!calculating) //Abort, run_script retriggered this. [Skotlex]
+ script->run(sd->inventory_data[index]->script,0,sd->bl.id,0);
+ if (!calculating) //Abort, script->run retriggered this. [Skotlex]
return 1;
}
@@ -2558,10 +2558,10 @@ int status_calc_pc_(struct map_session_data* sd, bool first)
if(sd->inventory_data[index]->script) {
if( i == EQI_HAND_L ) //Shield
sd->state.lr_flag = 3;
- run_script(sd->inventory_data[index]->script,0,sd->bl.id,0);
+ script->run(sd->inventory_data[index]->script,0,sd->bl.id,0);
if( i == EQI_HAND_L ) //Shield
sd->state.lr_flag = 0;
- if (!calculating) //Abort, run_script retriggered this. [Skotlex]
+ if (!calculating) //Abort, script->run retriggered this. [Skotlex]
return 1;
}
}
@@ -2573,9 +2573,9 @@ int status_calc_pc_(struct map_session_data* sd, bool first)
sd->bonus.arrow_atk += sd->inventory_data[index]->atk;
sd->state.lr_flag = 2;
if( !itemdb_is_GNthrowable(sd->inventory_data[index]->nameid) ) //don't run scripts on throwable items
- run_script(sd->inventory_data[index]->script,0,sd->bl.id,0);
+ script->run(sd->inventory_data[index]->script,0,sd->bl.id,0);
sd->state.lr_flag = 0;
- if (!calculating) //Abort, run_script retriggered status_calc_pc. [Skotlex]
+ if (!calculating) //Abort, script->run retriggered status_calc_pc. [Skotlex]
return 1;
}
}
@@ -2583,8 +2583,8 @@ int status_calc_pc_(struct map_session_data* sd, bool first)
/* we've got combos to process */
if( sd->combos.count ) {
for( i = 0; i < sd->combos.count; i++ ) {
- run_script(sd->combos.bonus[i],0,sd->bl.id,0);
- if (!calculating) //Abort, run_script retriggered this.
+ script->run(sd->combos.bonus[i],0,sd->bl.id,0);
+ if (!calculating) //Abort, script->run retriggered this.
return 1;
}
}
@@ -2632,7 +2632,7 @@ int status_calc_pc_(struct map_session_data* sd, bool first)
continue;
if(first && data->equip_script) {//Execute equip-script on login
- run_script(data->equip_script,0,sd->bl.id,0);
+ script->run(data->equip_script,0,sd->bl.id,0);
if (!calculating)
return 1;
}
@@ -2642,11 +2642,11 @@ int status_calc_pc_(struct map_session_data* sd, bool first)
if(i == EQI_HAND_L && sd->status.inventory[index].equip == EQP_HAND_L) { //Left hand status.
sd->state.lr_flag = 1;
- run_script(data->script,0,sd->bl.id,0);
+ script->run(data->script,0,sd->bl.id,0);
sd->state.lr_flag = 0;
} else
- run_script(data->script,0,sd->bl.id,0);
- if (!calculating) //Abort, run_script his function. [Skotlex]
+ script->run(data->script,0,sd->bl.id,0);
+ if (!calculating) //Abort, script->run his function. [Skotlex]
return 1;
}
}
@@ -2655,13 +2655,13 @@ int status_calc_pc_(struct map_session_data* sd, bool first)
if( sc->count && sc->data[SC_ITEMSCRIPT] ) {
struct item_data *data = itemdb->exists(sc->data[SC_ITEMSCRIPT]->val1);
if( data && data->script )
- run_script(data->script,0,sd->bl.id,0);
+ script->run(data->script,0,sd->bl.id,0);
}
if( sd->pd ) { // Pet Bonus
struct pet_data *pd = sd->pd;
if( pd && pd->petDB && pd->petDB->equip_script && pd->pet.intimate >= battle_config.pet_equip_min_friendly )
- run_script(pd->petDB->equip_script,0,sd->bl.id,0);
+ script->run(pd->petDB->equip_script,0,sd->bl.id,0);
if( pd && pd->pet.intimate > 0 && (!battle_config.pet_equip_required || pd->pet.equip > 0) && pd->state.skillbonus == 1 && pd->bonus )
pc->bonus(sd,pd->bonus->type, pd->bonus->val);
}
diff --git a/src/map/unit.c b/src/map/unit.c
index 4a8a87920..36f3eab45 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -2367,7 +2367,7 @@ int unit_free(struct block_list *bl, clr_type clrtype)
sd->regstr_num = 0;
}
if( sd->st && sd->st->state != RUN ) {// free attached scripts that are waiting
- script_free_state(sd->st);
+ script->free_state(sd->st);
sd->st = NULL;
sd->npc_id = 0;
}