summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2014-02-24 10:21:27 +0100
committerHaru <haru@dotalux.com>2014-03-05 22:35:02 +0100
commitd25cc9b7dbc103cf1454db37159ffffeedaac149 (patch)
tree0e4af566382b946797aa9de21df70b9bdf9d88fa /src/map
parent78bf8d26567a2054bd9ff5268f9f73cb07d82b98 (diff)
downloadhercules-d25cc9b7dbc103cf1454db37159ffffeedaac149.tar.gz
hercules-d25cc9b7dbc103cf1454db37159ffffeedaac149.tar.bz2
hercules-d25cc9b7dbc103cf1454db37159ffffeedaac149.tar.xz
hercules-d25cc9b7dbc103cf1454db37159ffffeedaac149.zip
Ref redesign, part 2
- Reorganized regs var/array DBMaps into a specific reg_db structure Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/chrif.c16
-rw-r--r--src/map/instance.c14
-rw-r--r--src/map/instance.h13
-rw-r--r--src/map/intif.c4
-rw-r--r--src/map/mapreg.h5
-rw-r--r--src/map/mapreg_sql.c52
-rw-r--r--src/map/npc.c5
-rw-r--r--src/map/pc.c47
-rw-r--r--src/map/pc.h3
-rw-r--r--src/map/script.c172
-rw-r--r--src/map/script.h30
11 files changed, 189 insertions, 172 deletions
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 1b87b7b62..059255fde 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -128,11 +128,11 @@ bool chrif_auth_delete(int account_id, int char_id, enum sd_state state) {
if ( node->sd ) {
- if( node->sd->var_db )
- node->sd->var_db->destroy(node->sd->var_db,script->reg_destroy);
+ if( node->sd->regs.vars )
+ node->sd->regs.vars->destroy(node->sd->regs.vars, script->reg_destroy);
- if( node->sd->array_db )
- node->sd->array_db->destroy(node->sd->array_db,script->array_free_db);
+ if( node->sd->regs.arrays )
+ node->sd->regs.arrays->destroy(node->sd->regs.arrays, script->array_free_db);
aFree(node->sd);
}
@@ -1619,11 +1619,11 @@ int auth_db_final(DBKey key, DBData *data, va_list ap) {
if (node->sd) {
- if( node->sd->var_db )
- node->sd->var_db->destroy(node->sd->var_db,script->reg_destroy);
+ if( node->sd->regs.vars )
+ node->sd->regs.vars->destroy(node->sd->regs.vars, script->reg_destroy);
- if( node->sd->array_db )
- node->sd->array_db->destroy(node->sd->array_db,script->array_free_db);
+ if( node->sd->regs.arrays )
+ node->sd->regs.arrays->destroy(node->sd->regs.arrays, script->array_free_db);
aFree(node->sd);
}
diff --git a/src/map/instance.c b/src/map/instance.c
index a111751d0..caf622b3d 100644
--- a/src/map/instance.c
+++ b/src/map/instance.c
@@ -110,8 +110,8 @@ int instance_create(int owner_id, const char *name, enum instance_owner_type typ
instance->list[i].num_map = 0;
instance->list[i].owner_id = owner_id;
instance->list[i].owner_type = type;
- instance->list[i].vars = i64db_alloc(DB_OPT_RELEASE_DATA);
- instance->list[i].array_db = NULL;
+ instance->list[i].regs.vars = i64db_alloc(DB_OPT_RELEASE_DATA);
+ instance->list[i].regs.arrays = NULL;
instance->list[i].respawn.map = 0;
instance->list[i].respawn.y = 0;
instance->list[i].respawn.x = 0;
@@ -551,17 +551,17 @@ void instance_destroy(int instance_id) {
instance->del_map( instance->list[instance_id].map[0] );
}
- if( instance->list[instance_id].vars )
- db_destroy(instance->list[instance_id].vars);
- if( instance->list[instance_id].array_db )
- instance->list[instance_id].array_db->destroy(instance->list[instance_id].array_db,script->array_free_db);
+ if( instance->list[instance_id].regs.vars )
+ db_destroy(instance->list[instance_id].regs.vars);
+ if( instance->list[instance_id].regs.arrays )
+ instance->list[instance_id].regs.arrays->destroy(instance->list[instance_id].regs.arrays, script->array_free_db);
if( instance->list[instance_id].progress_timer != INVALID_TIMER )
timer->delete( instance->list[instance_id].progress_timer, instance->destroy_timer);
if( instance->list[instance_id].idle_timer != INVALID_TIMER )
timer->delete( instance->list[instance_id].idle_timer, instance->destroy_timer);
- instance->list[instance_id].vars = NULL;
+ instance->list[instance_id].regs.vars = NULL;
if( instance->list[instance_id].map )
aFree(instance->list[instance_id].map);
diff --git a/src/map/instance.h b/src/map/instance.h
index 66a7d0d6c..712a0f141 100644
--- a/src/map/instance.h
+++ b/src/map/instance.h
@@ -5,6 +5,10 @@
#ifndef _MAP_INSTANCE_H_
#define _MAP_INSTANCE_H_
+#include "script.h" // struct reg_db
+#include "../common/mmo.h" // struct point
+struct block_list;
+
#define INSTANCE_NAME_LENGTH (60+1)
typedef enum instance_state {
@@ -24,7 +28,7 @@ enum instance_owner_type {
struct instance_data {
unsigned short id;
- char name[INSTANCE_NAME_LENGTH]; // Instance Name - required for clif functions.
+ char name[INSTANCE_NAME_LENGTH]; ///< Instance Name - required for clif functions.
instance_state state;
enum instance_owner_type owner_type;
int owner_id;
@@ -33,8 +37,7 @@ struct instance_data {
unsigned short num_map;
unsigned short users;
- struct DBMap *vars; // Instance Variable for scripts
- struct DBMap *array_db ;
+ struct reg_db regs; ///< Instance variables for scripts
int progress_timer;
unsigned int progress_timeout;
@@ -44,9 +47,9 @@ struct instance_data {
unsigned int original_progress_timeout;
- struct point respawn;/* reload spawn */
+ struct point respawn; ///< reload spawn
- /* HPM Custom Struct */
+ /** HPM Custom Struct */
struct HPluginData **hdata;
unsigned int hdatac;
};
diff --git a/src/map/intif.c b/src/map/intif.c
index 6b39bd1a5..af1a1da6e 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -273,7 +273,7 @@ int intif_saveregistry(struct map_session_data *sd) {
int plen = 0;
size_t len;
- if (intif->CheckForCharServer() || !sd->var_db)
+ if (intif->CheckForCharServer() || !sd->regs.vars)
return -1;
WFIFOHEAD(inter_fd, 60000 + 300);
@@ -285,7 +285,7 @@ int intif_saveregistry(struct map_session_data *sd) {
plen = 14;
- iter = db_iterator(sd->var_db);
+ iter = db_iterator(sd->regs.vars);
for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) {
const char *varname = NULL;
struct script_reg_state *src = NULL;
diff --git a/src/map/mapreg.h b/src/map/mapreg.h
index 246f5b744..2aa2943a2 100644
--- a/src/map/mapreg.h
+++ b/src/map/mapreg.h
@@ -5,6 +5,7 @@
#ifndef _MAP_MAPREG_H_
#define _MAP_MAPREG_H_
+#include "script.h" // struct reg_db
#include "../common/cbasetypes.h"
#include "../common/db.h"
@@ -20,9 +21,7 @@ struct mapreg_save {
};
struct mapreg_interface {
- DBMap *db; // int var_id -> struct mapreg_save
- /* */
- DBMap *array_db;
+ struct reg_db regs;
/* */
bool skip_insert;
/* */
diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c
index 926df2994..bdda652b8 100644
--- a/src/map/mapreg_sql.c
+++ b/src/map/mapreg_sql.c
@@ -27,7 +27,7 @@ struct mapreg_interface mapreg_s;
* @return variable's integer value
*/
int mapreg_readreg(int64 uid) {
- struct mapreg_save *m = i64db_get(mapreg->db, uid);
+ struct mapreg_save *m = i64db_get(mapreg->regs.vars, uid);
return m?m->u.i:0;
}
@@ -38,7 +38,7 @@ int mapreg_readreg(int64 uid) {
* @return variable's string value
*/
char* mapreg_readregstr(int64 uid) {
- struct mapreg_save *m = i64db_get(mapreg->db, uid);
+ struct mapreg_save *m = i64db_get(mapreg->regs.vars, uid);
return m?m->u.str:NULL;
}
@@ -56,7 +56,7 @@ bool mapreg_setreg(int64 uid, int val) {
const char* name = script->get_str(num);
if( val != 0 ) {
- if( (m = i64db_get(mapreg->db,uid)) ) {
+ if( (m = i64db_get(mapreg->regs.vars, uid)) ) {
m->u.i = val;
if(name[1] != '@') {
m->save = true;
@@ -64,7 +64,7 @@ bool mapreg_setreg(int64 uid, int val) {
}
} else {
if( i )
- script->array_update(&mapreg->array_db,uid,false);
+ script->array_update(&mapreg->regs.arrays, uid, false);
m = ers_alloc(mapreg->ers, struct mapreg_save);
@@ -79,15 +79,15 @@ bool mapreg_setreg(int64 uid, int val) {
if( SQL_ERROR == SQL->Query(map->mysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg->table, tmp_str, i, val) )
Sql_ShowDebug(map->mysql_handle);
}
- i64db_put(mapreg->db, uid, m);
+ i64db_put(mapreg->regs.vars, uid, m);
}
} else { // val == 0
if( i )
- script->array_update(&mapreg->array_db,uid,true);
- if( (m = i64db_get(mapreg->db,uid)) ) {
+ script->array_update(&mapreg->regs.arrays, uid, true);
+ if( (m = i64db_get(mapreg->regs.vars, uid)) ) {
ers_free(mapreg->ers, m);
}
- i64db_remove(mapreg->db,uid);
+ i64db_remove(mapreg->regs.vars, uid);
if( name[1] != '@' ) {// Remove from database because it is unused.
if( SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg->table, name, i) )
@@ -113,19 +113,19 @@ bool mapreg_setregstr(int64 uid, const char* str) {
if( str == NULL || *str == 0 ) {
if( i )
- script->array_update(&mapreg->array_db,uid,true);
+ script->array_update(&mapreg->regs.arrays, uid, true);
if(name[1] != '@') {
if( SQL_ERROR == SQL->Query(map->mysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg->table, name, i) )
Sql_ShowDebug(map->mysql_handle);
}
- if( (m = i64db_get(mapreg->db,uid)) ) {
+ if( (m = i64db_get(mapreg->regs.vars, uid)) ) {
if( m->u.str != NULL )
aFree(m->u.str);
ers_free(mapreg->ers, m);
}
- i64db_remove(mapreg->db,uid);
+ i64db_remove(mapreg->regs.vars, uid);
} else {
- if( (m = i64db_get(mapreg->db,uid)) ) {
+ if( (m = i64db_get(mapreg->regs.vars, uid)) ) {
if( m->u.str != NULL )
aFree(m->u.str);
m->u.str = aStrdup(str);
@@ -135,7 +135,7 @@ bool mapreg_setregstr(int64 uid, const char* str) {
}
} else {
if( i )
- script->array_update(&mapreg->array_db,uid,false);
+ script->array_update(&mapreg->regs.arrays, uid, false);
m = ers_alloc(mapreg->ers, struct mapreg_save);
@@ -152,7 +152,7 @@ bool mapreg_setregstr(int64 uid, const char* str) {
if( SQL_ERROR == SQL->Query(map->mysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%s')", mapreg->table, tmp_str, i, tmp_str2) )
Sql_ShowDebug(map->mysql_handle);
}
- i64db_put(mapreg->db, uid, m);
+ i64db_put(mapreg->regs.vars, uid, m);
}
}
@@ -194,7 +194,7 @@ void script_load_mapreg(void) {
int i = index;
- if( i64db_exists(mapreg->db, reference_uid(s, i)) ) {
+ if( i64db_exists(mapreg->regs.vars, reference_uid(s, i)) ) {
ShowWarning("load_mapreg: duplicate! '%s' => '%s' skipping...\n",varname,value);
continue;
}
@@ -220,7 +220,7 @@ void script_save_mapreg(void) {
struct mapreg_save *m = NULL;
if( mapreg->dirty ) {
- iter = db_iterator(mapreg->db);
+ iter = db_iterator(mapreg->regs.vars);
for( m = dbi_first(iter); dbi_exists(iter); m = dbi_next(iter) ) {
if( m->save ) {
int num = script_getvarid(m->uid);
@@ -284,11 +284,11 @@ int mapreg_destroyreg(DBKey key, DBData *data, va_list ap) {
void mapreg_reload(void) {
mapreg->save();
- mapreg->db->clear(mapreg->db, mapreg->destroyreg);
+ mapreg->regs.vars->clear(mapreg->regs.vars, mapreg->destroyreg);
- if( mapreg->array_db ) {
- mapreg->array_db->destroy(mapreg->array_db,script->array_free_db);
- mapreg->array_db = NULL;
+ if( mapreg->regs.arrays ) {
+ mapreg->regs.arrays->destroy(mapreg->regs.arrays, script->array_free_db);
+ mapreg->regs.arrays = NULL;
}
mapreg->load();
@@ -300,19 +300,19 @@ void mapreg_reload(void) {
void mapreg_final(void) {
mapreg->save();
- mapreg->db->destroy(mapreg->db, mapreg->destroyreg);
+ mapreg->regs.vars->destroy(mapreg->regs.vars, mapreg->destroyreg);
ers_destroy(mapreg->ers);
- if( mapreg->array_db )
- mapreg->array_db->destroy(mapreg->array_db,script->array_free_db);
+ if( mapreg->regs.arrays )
+ mapreg->regs.arrays->destroy(mapreg->regs.arrays, script->array_free_db);
}
/**
* Initializer.
*/
void mapreg_init(void) {
- mapreg->db = i64db_alloc(DB_OPT_BASE);
+ mapreg->regs.vars = i64db_alloc(DB_OPT_BASE);
mapreg->ers = ers_new(sizeof(struct mapreg_save), "mapreg_sql.c::mapreg_ers", ERS_OPT_CLEAN);
mapreg->load();
@@ -340,7 +340,7 @@ void mapreg_defaults(void) {
mapreg = &mapreg_s;
/* */
- mapreg->db = NULL;
+ mapreg->regs.vars = NULL;
mapreg->ers = NULL;
mapreg->skip_insert = false;
@@ -348,7 +348,7 @@ void mapreg_defaults(void) {
mapreg->dirty = false;
/* */
- mapreg->array_db = NULL;
+ mapreg->regs.arrays = NULL;
/* */
mapreg->init = mapreg_init;
diff --git a/src/map/npc.c b/src/map/npc.c
index fa2fa1ead..7933f6d43 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -3337,11 +3337,10 @@ const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, const cha
return end;
func_db = script->userfunc_db;
- if (func_db->put(func_db, DB->str2key(w3), DB->ptr2data(scriptroot), &old_data))
- {
+ 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);
ShowWarning("npc_parse_function: Overwriting user function [%s] in file '%s', line '%d'.\n", w3, filepath, strline(buffer,start-buffer));
- script->free_vars(oldscript->script_vars);
+ script->free_vars(oldscript->local.vars);
aFree(oldscript->script_buf);
aFree(oldscript);
}
diff --git a/src/map/pc.c b/src/map/pc.c
index 31aac3445..ff152b556 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -1111,7 +1111,8 @@ bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_tim
sd->avail_quests = 0;
sd->save_quest = false;
- sd->var_db = i64db_alloc(DB_OPT_BASE);
+ sd->regs.vars = i64db_alloc(DB_OPT_BASE);
+ sd->regs.arrays = NULL;
sd->vars_dirty = false;
sd->vars_ok = false;
sd->vars_received = 0x0;
@@ -8115,7 +8116,7 @@ int pc_candrop(struct map_session_data *sd, struct item *item)
* For '@type' variables (temporary numeric char reg)
**/
int pc_readreg(struct map_session_data* sd, int64 reg) {
- return i64db_iget(sd->var_db, reg);
+ return i64db_iget(sd->regs.vars, reg);
}
/**
* For '@type' variables (temporary numeric char reg)
@@ -8124,13 +8125,13 @@ void pc_setreg(struct map_session_data* sd, int64 reg, int val) {
unsigned int index = script_getvaridx(reg);
if( val ) {
- i64db_iput(sd->var_db, reg, val);
+ i64db_iput(sd->regs.vars, reg, val);
if( index )
- script->array_update(&sd->array_db,reg,false);
+ script->array_update(&sd->regs.arrays, reg, false);
} else {
- i64db_remove(sd->var_db, reg);
+ i64db_remove(sd->regs.vars, reg);
if( index )
- script->array_update(&sd->array_db,reg,true);
+ script->array_update(&sd->regs.arrays, reg, true);
}
}
@@ -8140,7 +8141,7 @@ void pc_setreg(struct map_session_data* sd, int64 reg, int val) {
char* pc_readregstr(struct map_session_data* sd, int64 reg) {
struct script_reg_str *p = NULL;
- p = i64db_get(sd->var_db, reg);
+ p = i64db_get(sd->regs.vars, reg);
return p ? p->value : NULL;
}
@@ -8158,23 +8159,23 @@ void pc_setregstr(struct map_session_data* sd, int64 reg, const char* str) {
p->value = aStrdup(str);
p->flag.type = 1;
- if( sd->var_db->put(sd->var_db,DB->i642key(reg),DB->ptr2data(p),&prev) ) {
+ if( sd->regs.vars->put(sd->regs.vars, DB->i642key(reg), DB->ptr2data(p), &prev) ) {
p = DB->data2ptr(&prev);
if( p->value )
aFree(p->value);
ers_free(pc->str_reg_ers, p);
} else {
if( index )
- script->array_update(&sd->array_db,reg,false);
+ script->array_update(&sd->regs.arrays, reg, false);
}
} else {
- if( sd->var_db->remove(sd->var_db,DB->i642key(reg),&prev) ) {
+ if( sd->regs.vars->remove(sd->regs.vars, DB->i642key(reg), &prev) ) {
p = DB->data2ptr(&prev);
if( p->value )
aFree(p->value);
ers_free(pc->str_reg_ers, p);
if( index )
- script->array_update(&sd->array_db,reg,true);
+ script->array_update(&sd->regs.arrays, reg, true);
}
}
}
@@ -8195,7 +8196,7 @@ int pc_readregistry(struct map_session_data *sd, int64 reg) {
return 0;
}
- p = i64db_get(sd->var_db, reg);
+ p = i64db_get(sd->regs.vars, reg);
return p ? p->value : 0;
}
@@ -8216,7 +8217,7 @@ char* pc_readregistry_str(struct map_session_data *sd, int64 reg) {
return NULL;
}
- p = i64db_get(sd->var_db, reg);
+ p = i64db_get(sd->regs.vars, reg);
return p ? p->value : NULL;
}
@@ -8261,15 +8262,15 @@ int pc_setregistry(struct map_session_data *sd, int64 reg, int val) {
return 0;
}
- if( (p = i64db_get(sd->var_db, reg) ) ) {
+ if( (p = i64db_get(sd->regs.vars, reg) ) ) {
if( val ) {
if( !p->value && index ) /* its a entry that was deleted, so we reset array */
- script->array_update(&sd->array_db,reg,false);
+ script->array_update(&sd->regs.arrays, reg, false);
p->value = val;
} else {
p->value = 0;
if( index )
- script->array_update(&sd->array_db,reg,true);
+ script->array_update(&sd->regs.arrays, reg, true);
}
if( !pc->reg_load )
p->flag.update = 1;/* either way, it will require either delete or replace */
@@ -8277,7 +8278,7 @@ int pc_setregistry(struct map_session_data *sd, int64 reg, int val) {
DBData prev;
if( index )
- script->array_update(&sd->array_db,reg,false);
+ script->array_update(&sd->regs.arrays, reg, false);
p = ers_alloc(pc->num_reg_ers, struct script_reg_num);
@@ -8285,7 +8286,7 @@ int pc_setregistry(struct map_session_data *sd, int64 reg, int val) {
if( !pc->reg_load )
p->flag.update = 1;
- if( sd->var_db->put(sd->var_db,DB->i642key(reg),DB->ptr2data(p),&prev) ) {
+ if( sd->regs.vars->put(sd->regs.vars, DB->i642key(reg), DB->ptr2data(p), &prev) ) {
p = DB->data2ptr(&prev);
ers_free(pc->num_reg_ers, p);
}
@@ -8312,17 +8313,17 @@ int pc_setregistry_str(struct map_session_data *sd, int64 reg, const char *val)
return 0;
}
- if( (p = i64db_get(sd->var_db, reg) ) ) {
+ if( (p = i64db_get(sd->regs.vars, reg) ) ) {
if( val[0] ) {
if( p->value )
aFree(p->value);
else if ( index ) /* a entry that was deleted, so we reset */
- script->array_update(&sd->array_db,reg,false);
+ script->array_update(&sd->regs.arrays, reg, false);
p->value = aStrdup(val);
} else {
p->value = NULL;
if( index )
- script->array_update(&sd->array_db,reg,true);
+ script->array_update(&sd->regs.arrays, reg, true);
}
if( !pc->reg_load )
p->flag.update = 1;/* either way, it will require either delete or replace */
@@ -8330,7 +8331,7 @@ int pc_setregistry_str(struct map_session_data *sd, int64 reg, const char *val)
DBData prev;
if( index )
- script->array_update(&sd->array_db,reg,false);
+ script->array_update(&sd->regs.arrays, reg, false);
p = ers_alloc(pc->str_reg_ers, struct script_reg_str);
@@ -8339,7 +8340,7 @@ int pc_setregistry_str(struct map_session_data *sd, int64 reg, const char *val)
p->flag.update = 1;
p->flag.type = 1;
- if( sd->var_db->put(sd->var_db,DB->i642key(reg),DB->ptr2data(p),&prev) ) {
+ if( sd->regs.vars->put(sd->regs.vars, DB->i642key(reg), DB->ptr2data(p), &prev) ) {
p = DB->data2ptr(&prev);
if( p->value )
aFree(p->value);
diff --git a/src/map/pc.h b/src/map/pc.h
index 255fcdbc4..66915492a 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -533,8 +533,7 @@ struct map_session_data {
/**
* Account/Char variables & array control of those variables
**/
- DBMap *var_db;
- DBMap *array_db;
+ struct reg_db regs;
unsigned char vars_received;/* char loading is only complete when you get it all. */
bool vars_ok;
bool vars_dirty;
diff --git a/src/map/script.c b/src/map/script.c
index 54ca37e9f..c989c06a8 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -151,7 +151,7 @@ static void script_dump_stack(struct script_state* st)
case C_RETINFO:
{
struct script_retinfo* ri = data->u.ri;
- ShowMessage(" %p {var_function=%p, script=%p, pos=%d, nargs=%d, defsp=%d}\n", ri, ri->var_function, ri->script, ri->pos, ri->nargs, ri->defsp);
+ ShowMessage(" %p {scope.vars=%p, scope.arrays=%p, script=%p, pos=%d, nargs=%d, defsp=%d}\n", ri, ri->scope.vars, ri->scope.arrays, ri->script, ri->pos, ri->nargs, ri->defsp);
}
break;
default:
@@ -2434,7 +2434,8 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o
CREATE(code,struct script_code,1);
code->script_buf = script->buf;
code->script_size = script->size;
- code->script_vars = NULL;
+ code->local.vars = NULL;
+ code->local.arrays = NULL;
#ifdef ENABLE_CASE_CHECK
script->local_casecheck.clear();
script->parser_current_src = NULL;
@@ -2513,8 +2514,8 @@ struct script_data *get_val(struct script_state* st, struct script_data* data) {
{
struct DBMap* n = data->ref ?
*data->ref : name[1] == '@' ?
- st->stack->var_function : // instance/scope variable
- st->script->script_vars; // npc variable
+ st->stack->scope.vars : // instance/scope variable
+ st->script->local.vars; // npc variable
if( n )
data->u.str = (char*)i64db_get(n,reference_getuid(data));
else
@@ -2523,7 +2524,7 @@ struct script_data *get_val(struct script_state* st, struct script_data* data) {
break;
case '\'':
if ( st->instance_id >= 0 ) {
- data->u.str = (char*)i64db_get(instance->list[st->instance_id].vars,reference_getuid(data));
+ data->u.str = (char*)i64db_get(instance->list[st->instance_id].regs.vars, reference_getuid(data));
} else {
ShowWarning("script_get_val: cannot access instance variable '%s', defaulting to \"\"\n", name);
data->u.str = NULL;
@@ -2568,8 +2569,8 @@ struct script_data *get_val(struct script_state* st, struct script_data* data) {
{
struct DBMap* n = data->ref ?
*data->ref : name[1] == '@' ?
- st->stack->var_function : // instance/scope variable
- st->script->script_vars; // npc variable
+ st->stack->scope.vars : // instance/scope variable
+ st->script->local.vars; // npc variable
if( n )
data->u.num = (int)i64db_iget(n,reference_getuid(data));
else
@@ -2578,7 +2579,7 @@ struct script_data *get_val(struct script_state* st, struct script_data* data) {
break;
case '\'':
if( st->instance_id >= 0 )
- data->u.num = (int)i64db_iget(instance->list[st->instance_id].vars,reference_getuid(data));
+ data->u.num = (int)i64db_iget(instance->list[st->instance_id].regs.vars, reference_getuid(data));
else {
ShowWarning("script_get_val: cannot access instance variable '%s', defaulting to 0\n", name);
data->u.num = 0;
@@ -2749,20 +2750,20 @@ struct DBMap *script_array_src(struct script_state *st, struct map_session_data
default: /* char reg */
case '@':/* temp char reg */
case '#':/* account reg */
- src = &sd->array_db;
+ src = &sd->regs.arrays;
break;
case '$':/* map reg */
- src = &mapreg->array_db;
+ src = &mapreg->regs.arrays;
break;
case '.':/* npc/script */
if( ref )
src = (struct DBMap **)((char *)ref + sizeof(struct DBMap *));
else
- src = (name[1] == '@') ? &st->stack->array_function_db : &st->script->script_arrays_db;
+ src = (name[1] == '@') ? &st->stack->scope.arrays : &st->script->local.arrays;
break;
case '\'':/* instance */
if( st->instance_id >= 0 ) {
- src = &instance->list[st->instance_id].array_db;
+ src = &instance->list[st->instance_id].regs.arrays;
}
break;
}
@@ -2820,7 +2821,7 @@ void script_array_update(struct DBMap **src, int64 num, bool empty) {
/*==========================================
* Stores the value of a script variable
* Return value is 0 on fail, 1 on success.
- * TODO: return values are screwed up, have been for some time (reaad: years), e.g. some functions return 1 failure and success.
+ * TODO: return values are screwed up, have been for some time (reaad: years), e.g. some functions return 1 failure and success.
*------------------------------------------*/
int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, const void* value, struct DBMap** ref) {
char prefix = name[0];
@@ -2841,15 +2842,15 @@ int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, co
case '.':
{
struct DBMap* n;
- n = (ref) ? *ref : (name[1] == '@') ? st->stack->var_function : st->script->script_vars;
+ n = (ref) ? *ref : (name[1] == '@') ? st->stack->scope.vars : st->script->local.vars;
if( n ) {
if (str[0]) {
i64db_put(n, num, aStrdup(str));
if( script_getvaridx(num) )
script->array_update(
(name[1] == '@') ?
- &st->stack->array_function_db :
- &st->script->script_arrays_db,
+ &st->stack->scope.arrays :
+ &st->script->local.arrays,
num,
false);
} else {
@@ -2857,8 +2858,8 @@ int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, co
if( script_getvaridx(num) )
script->array_update(
(name[1] == '@') ?
- &st->stack->array_function_db :
- &st->script->script_arrays_db,
+ &st->stack->scope.arrays :
+ &st->script->local.arrays,
num,
true);
}
@@ -2868,13 +2869,13 @@ int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, co
case '\'':
if( st->instance_id >= 0 ) {
if( str[0] ) {
- i64db_put(instance->list[st->instance_id].vars, num, aStrdup(str));
+ i64db_put(instance->list[st->instance_id].regs.vars, num, aStrdup(str));
if( script_getvaridx(num) )
- script->array_update(&instance->list[st->instance_id].array_db,num,false);
+ script->array_update(&instance->list[st->instance_id].regs.arrays, num, false);
} else {
- i64db_remove(instance->list[st->instance_id].vars, num);
+ i64db_remove(instance->list[st->instance_id].regs.vars, num);
if( script_getvaridx(num) )
- script->array_update(&instance->list[st->instance_id].array_db,num,true);
+ script->array_update(&instance->list[st->instance_id].regs.arrays, num, true);
}
} else {
ShowError("script_set_reg: cannot write instance variable '%s', NPC not in a instance!\n", name);
@@ -2912,15 +2913,15 @@ int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, co
case '.':
{
struct DBMap* n;
- n = (ref) ? *ref : (name[1] == '@') ? st->stack->var_function : st->script->script_vars;
+ n = (ref) ? *ref : (name[1] == '@') ? st->stack->scope.vars : st->script->local.vars;
if( n ) {
if( val != 0 ) {
i64db_iput(n, num, val);
if( script_getvaridx(num) )
script->array_update(
(name[1] == '@') ?
- &st->stack->array_function_db :
- &st->script->script_arrays_db,
+ &st->stack->scope.arrays :
+ &st->script->local.arrays,
num,
false);
} else {
@@ -2928,8 +2929,8 @@ int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, co
if( script_getvaridx(num) )
script->array_update(
(name[1] == '@') ?
- &st->stack->array_function_db :
- &st->script->script_arrays_db,
+ &st->stack->scope.arrays :
+ &st->script->local.arrays,
num,
true);
}
@@ -2939,13 +2940,13 @@ int set_reg(struct script_state* st, TBL_PC* sd, int64 num, const char* name, co
case '\'':
if( st->instance_id >= 0 ) {
if( val != 0 ) {
- i64db_iput(instance->list[st->instance_id].vars, num, val);
+ i64db_iput(instance->list[st->instance_id].regs.vars, num, val);
if( script_getvaridx(num) )
- script->array_update(&instance->list[st->instance_id].array_db,num,false);
+ script->array_update(&instance->list[st->instance_id].regs.arrays, num, false);
} else {
- i64db_remove(instance->list[st->instance_id].vars, num);
+ i64db_remove(instance->list[st->instance_id].regs.vars, num);
if( script_getvaridx(num) )
- script->array_update(&instance->list[st->instance_id].array_db,num,true);
+ script->array_update(&instance->list[st->instance_id].regs.arrays, num, true);
}
} else {
ShowError("script_set_reg: cannot write instance variable '%s', NPC not in a instance!\n", name);
@@ -3151,8 +3152,14 @@ void pop_stack(struct script_state* st, int start, int end)
if( data->type == C_RETINFO )
{
struct script_retinfo* ri = data->u.ri;
- if( ri->var_function )
- script->free_vars(ri->var_function);
+ if( ri->scope.vars ) {
+ script->free_vars(ri->scope.vars);
+ ri->scope.vars = NULL;
+ }
+ if( ri->scope.arrays ) {
+ script->free_vars(ri->scope.arrays);
+ ri->scope.arrays = NULL;
+ }
if( data->ref )
aFree(data->ref);
aFree(ri);
@@ -3198,9 +3205,9 @@ void script_free_vars(struct DBMap* var_storage) {
void script_free_code(struct script_code* code)
{
- script->free_vars( code->script_vars );
- if( code->script_arrays_db )
- code->script_arrays_db->destroy(code->script_arrays_db,script->array_free_db);
+ script->free_vars(code->local.vars);
+ if( code->local.arrays )
+ code->local.arrays->destroy(code->local.arrays,script->array_free_db);
aFree( code->script_buf );
aFree( code );
}
@@ -3221,8 +3228,8 @@ struct script_state* script_alloc_state(struct script_code* rootscript, int pos,
st->stack->sp_max = 64;
CREATE(st->stack->stack_data, struct script_data, st->stack->sp_max);
st->stack->defsp = st->stack->sp;
- st->stack->var_function = i64db_alloc(DB_OPT_RELEASE_DATA);
- st->stack->array_function_db = NULL;
+ st->stack->scope.vars = i64db_alloc(DB_OPT_RELEASE_DATA);
+ st->stack->scope.arrays = NULL;
st->state = RUN;
st->script = rootscript;
st->pos = pos;
@@ -3231,8 +3238,8 @@ struct script_state* script_alloc_state(struct script_code* rootscript, int pos,
st->sleep.timer = INVALID_TIMER;
st->npc_item_flag = battle_config.item_enabled_npc;
- if( !st->script->script_vars )
- st->script->script_vars = i64db_alloc(DB_OPT_RELEASE_DATA);
+ if( !st->script->local.vars )
+ st->script->local.vars = i64db_alloc(DB_OPT_RELEASE_DATA);
st->id = script->next_id++;
script->active_scripts++;
@@ -3254,22 +3261,22 @@ void script_free_state(struct script_state* st) {
if( st->sleep.timer != INVALID_TIMER )
timer->delete(st->sleep.timer, script->run_timer);
if( st->stack ) {
- script->free_vars(st->stack->var_function);
- if( st->stack->array_function_db )
- st->stack->array_function_db->destroy(st->stack->array_function_db,script->array_free_db);
+ script->free_vars(st->stack->scope.vars);
+ if( st->stack->scope.arrays )
+ st->stack->scope.arrays->destroy(st->stack->scope.arrays,script->array_free_db);
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 ) {
- if( st->script->script_vars && !db_size(st->script->script_vars) ) {
- script->free_vars(st->script->script_vars);
- st->script->script_vars = NULL;
+ if( st->script->local.vars && !db_size(st->script->local.vars) ) {
+ script->free_vars(st->script->local.vars);
+ st->script->local.vars = NULL;
}
- if( st->script->script_arrays_db && !db_size(st->script->script_arrays_db) ) {
- script->free_vars(st->script->script_arrays_db);
- st->script->script_arrays_db = NULL;
+ if( st->script->local.arrays && !db_size(st->script->local.arrays) ) {
+ script->free_vars(st->script->local.arrays);
+ st->script->local.arrays = NULL;
}
}
st->pos = -1;
@@ -3705,13 +3712,14 @@ int run_func(struct script_state *st)
st->state = END;
return 1;
}
- script->free_vars( st->stack->var_function );
+ script->free_vars(st->stack->scope.vars);
ri = st->stack->stack_data[st->stack->defsp-1].u.ri;
nargs = ri->nargs;
st->pos = ri->pos;
st->script = ri->script;
- st->stack->var_function = ri->var_function;
+ st->stack->scope.vars = ri->scope.vars;
+ st->stack->scope.arrays = ri->scope.arrays;
st->stack->defsp = ri->defsp;
memset(ri, 0, sizeof(struct script_retinfo));
@@ -4147,7 +4155,7 @@ int script_reg_destroy(DBKey key, DBData *data, va_list ap) {
* Clears a single persistent variable
**/
void script_reg_destroy_single(struct map_session_data *sd, int64 reg, struct script_reg_state *data) {
- i64db_remove(sd->var_db, reg);
+ i64db_remove(sd->regs.vars, reg);
if( data->type ) {
struct script_reg_str *p = (struct script_reg_str*)data;
@@ -4849,15 +4857,15 @@ BUILDIN(callfunc)
if( name[0] == '.' ) {
if( !ref ) {
ref = (struct DBMap**)aCalloc(sizeof(struct DBMap*), 2);
- ref[0] = (name[1] == '@' ? st->stack->var_function : st->script->script_vars);
+ ref[0] = (name[1] == '@' ? st->stack->scope.vars : st->script->local.vars);
if( name[1] == '@' ) {
- if( !st->stack->array_function_db )
- st->stack->array_function_db = idb_alloc(DB_OPT_BASE);
- ref[1] = st->stack->array_function_db;
+ if( !st->stack->scope.arrays )
+ st->stack->scope.arrays = idb_alloc(DB_OPT_BASE);
+ ref[1] = st->stack->scope.arrays;
} else {
- if( !st->script->script_arrays_db )
- st->script->script_arrays_db = idb_alloc(DB_OPT_BASE);
- ref[1] = st->script->script_arrays_db;
+ if( !st->script->local.arrays )
+ st->script->local.arrays = idb_alloc(DB_OPT_BASE);
+ ref[1] = st->script->local.arrays;
}
}
data->ref = ref;
@@ -4866,18 +4874,19 @@ BUILDIN(callfunc)
}
CREATE(ri, struct script_retinfo, 1);
- ri->script = st->script;// script code
- ri->var_function = st->stack->var_function;// scope variables
- ri->pos = st->pos;// script location
- ri->nargs = j;// argument count
- ri->defsp = st->stack->defsp;// default stack pointer
+ ri->script = st->script; // script code
+ ri->scope.vars = st->stack->scope.vars; // scope variables
+ ri->scope.arrays = st->stack->scope.arrays; // scope arrays
+ ri->pos = st->pos; // script location
+ ri->nargs = j; // argument count
+ ri->defsp = st->stack->defsp; // default stack pointer
script->push_retinfo(st->stack, ri, ref);
st->pos = 0;
st->script = scr;
st->stack->defsp = st->stack->sp;
st->state = GOTO;
- st->stack->var_function = i64db_alloc(DB_OPT_RELEASE_DATA);
+ st->stack->scope.vars = i64db_alloc(DB_OPT_RELEASE_DATA);
return true;
}
@@ -4908,10 +4917,10 @@ BUILDIN(callsub)
if( name[0] == '.' && name[1] == '@' ) {
if ( !ref ) {
ref = (struct DBMap**)aCalloc(sizeof(struct DBMap*), 2);
- ref[0] = st->stack->var_function;
- if( !st->stack->array_function_db )
- st->stack->array_function_db = idb_alloc(DB_OPT_BASE);
- ref[1] = st->stack->array_function_db;
+ ref[0] = st->stack->scope.vars;
+ if( !st->stack->scope.arrays )
+ st->stack->scope.arrays = idb_alloc(DB_OPT_BASE);
+ ref[1] = st->stack->scope.arrays;
}
data->ref = ref;
}
@@ -4919,17 +4928,18 @@ BUILDIN(callsub)
}
CREATE(ri, struct script_retinfo, 1);
- ri->script = st->script;// script code
- ri->var_function = st->stack->var_function;// scope variables
- ri->pos = st->pos;// script location
- ri->nargs = j;// argument count
- ri->defsp = st->stack->defsp;// default stack pointer
+ ri->script = st->script; // script code
+ ri->scope.vars = st->stack->scope.vars; // scope variables
+ ri->scope.arrays = st->stack->scope.arrays; // scope arrays
+ ri->pos = st->pos; // script location
+ ri->nargs = j; // argument count
+ ri->defsp = st->stack->defsp; // default stack pointer
script->push_retinfo(st->stack, ri, ref);
st->pos = pos;
st->stack->defsp = st->stack->sp;
st->state = GOTO;
- st->stack->var_function = i64db_alloc(DB_OPT_RELEASE_DATA);
+ st->stack->scope.vars = i64db_alloc(DB_OPT_RELEASE_DATA);
return true;
}
@@ -4984,16 +4994,16 @@ BUILDIN(return)
const char* name = reference_getname(data);
if( name[0] == '.' && name[1] == '@' )
{// scope variable
- if( !data->ref || data->ref[0] == st->stack->var_function )
+ if( !data->ref || data->ref[0] == st->stack->scope.vars )
script->get_val(st, data);// current scope, convert to value
}
else if( name[0] == '.' && !data->ref )
{// script variable, link to current script
data->ref = (struct DBMap**)aCalloc(sizeof(struct DBMap*), 2);
- data->ref[0] = st->script->script_vars;
- if( !st->script->script_arrays_db )
- st->script->script_arrays_db = idb_alloc(DB_OPT_BASE);
- data->ref[1] = st->script->script_arrays_db;
+ data->ref[0] = st->script->local.vars;
+ if( !st->script->local.arrays )
+ st->script->local.arrays = idb_alloc(DB_OPT_BASE);
+ data->ref[1] = st->script->local.arrays;
}
}
}
@@ -15661,7 +15671,7 @@ BUILDIN(getvariableofnpc)
return false;
}
- script->push_val(st->stack, C_NAME, reference_getuid(data), &nd->u.scr.script->script_vars );
+ script->push_val(st->stack, C_NAME, reference_getuid(data), &nd->u.scr.script->local.vars);
return true;
}
diff --git a/src/map/script.h b/src/map/script.h
index c0160fd49..0121f39d8 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -332,12 +332,20 @@ struct Script_Config {
const char* ontouch2_name;
};
+/**
+ * Generic reg database abstraction to be used with various types of regs/script variables.
+ */
+struct reg_db {
+ struct DBMap *vars;
+ struct DBMap *arrays;
+};
+
struct script_retinfo {
- struct DBMap* var_function;// scope variables
- struct script_code* script;// script code
- int pos;// script location
- int nargs;// argument count
- int defsp;// default stack pointer
+ struct reg_db scope; ///< scope variables
+ struct script_code* script; ///< script code
+ int pos; ///< script location
+ int nargs; ///< argument count
+ int defsp; ///< default stack pointer
};
struct script_data {
@@ -355,17 +363,15 @@ struct script_data {
struct script_code {
int script_size;
unsigned char *script_buf;
- struct DBMap *script_vars;
- struct DBMap *script_arrays_db;
+ struct reg_db local; ///< Local (npc) vars
};
struct script_stack {
- int sp;// number of entries in the stack
- int sp_max;// capacity of the stack
+ int sp; ///< number of entries in the stack
+ int sp_max; ///< capacity of the stack
int defsp;
- struct script_data *stack_data;// stack
- struct DBMap *var_function;// scope variables
- struct DBMap *array_function_db;
+ struct script_data *stack_data; ///< stack
+ struct reg_db scope; ///< scope variables
};
/* [Ind/Hercules] */