diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 78cd0961d7..d11ccb06b6 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -565,8 +565,7 @@ setting it will make the character own this number of Zeny.
If you try to set Zeny to a negative number, the script will be terminated with an error.
Some source-end constants can also be accessed in scripts. This list is located in
-'src/map/script.c' in the 'script_hardcoded_constants' function, which contains
-constants such as server defines and status options:
+'src/map/script_constants.h', which contains constants such as server defines and status options:
PACKETVER, MAX_LEVEL, MAX_STORAGE, MAX_INVENTORY, MAX_CART, MAX_ZENY, MAX_PARTY,
MAX_GUILD, MAX_GUILDLEVEL, MAX_GUILD_STORAGE, MAX_BG_MEMBERS, MAX_CHAT_USERS,
diff --git a/src/common/ers.h b/src/common/ers.h
index c54d5999f4..51a45d951d 100644
--- a/src/common/ers.h
+++ b/src/common/ers.h
@@ -84,6 +84,7 @@ enum ERSOptions {
/* Compound, is used to determine whether it should be looking for a cache of matching options */
ERS_CACHE_OPTIONS = ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK,
+ ERS_CLEAN_OPTIONS = ERS_OPT_CLEAN|ERS_OPT_CLEAR,
};
/**
diff --git a/src/map/achievement.c b/src/map/achievement.c
index 177e7aff3a..96b584403d 100644
--- a/src/map/achievement.c
+++ b/src/map/achievement.c
@@ -32,6 +32,7 @@ static int av_error_report;
static DBMap *achievement_db = NULL; // int achievement_id -> struct achievement_db *
static DBMap *achievementmobs_db = NULL; // Avoids checking achievements on every mob killed
static void achievement_db_free_sub(struct achievement_db *achievement, bool free);
+struct achievement_db achievement_dummy;
/**
* Searches an achievement by ID
diff --git a/src/map/achievement.h b/src/map/achievement.h
index e1e6caeaf2..40ce13a9bc 100644
--- a/src/map/achievement.h
+++ b/src/map/achievement.h
@@ -100,7 +100,7 @@ struct achievement_db {
struct map_session_data;
struct block_list;
-struct achievement_db achievement_dummy; ///< Dummy entry for invalid achievement lookups
+extern struct achievement_db achievement_dummy; ///< Dummy entry for invalid achievement lookups
struct achievement_db *achievement_search(int achievement_id);
bool achievement_mobexists(int mob_id);
diff --git a/src/map/channel.h b/src/map/channel.h
index 2ac96c7b4d..a0587af623 100644
--- a/src/map/channel.h
+++ b/src/map/channel.h
@@ -52,7 +52,7 @@ struct Channel {
unsigned short *groups; ///< List of group id, only these groups can join the channel
};
-struct chan_banentry {
+extern struct chan_banentry {
uint32 char_id;
char char_name[NAME_LENGTH];
} chan_banentry;
diff --git a/src/map/map-server.vcxproj b/src/map/map-server.vcxproj
index bbc87e1c7a..0c681feebe 100644
--- a/src/map/map-server.vcxproj
+++ b/src/map/map-server.vcxproj
@@ -240,7 +240,7 @@
-
+
diff --git a/src/map/map-server.vcxproj.filters b/src/map/map-server.vcxproj.filters
index 11f732c4b8..f1ac1a1d17 100644
--- a/src/map/map-server.vcxproj.filters
+++ b/src/map/map-server.vcxproj.filters
@@ -244,7 +244,7 @@
Source Files
-
+
Source Files
diff --git a/src/map/quest.c b/src/map/quest.c
index cbbd0c5709..df73d862b0 100644
--- a/src/map/quest.c
+++ b/src/map/quest.c
@@ -21,6 +21,7 @@
static DBMap *questdb;
static void questdb_free_sub(struct quest_db *quest, bool free);
+struct quest_db quest_dummy;
/**
* Searches a quest by ID.
diff --git a/src/map/quest.h b/src/map/quest.h
index 89ed516277..e44a7746ef 100644
--- a/src/map/quest.h
+++ b/src/map/quest.h
@@ -35,7 +35,7 @@ struct quest_db {
StringBuf name;
};
-struct quest_db quest_dummy; ///< Dummy entry for invalid quest lookups
+extern struct quest_db quest_dummy; ///< Dummy entry for invalid quest lookups
// Questlog check types
enum quest_check_type {
diff --git a/src/map/script.c b/src/map/script.cpp
similarity index 99%
rename from src/map/script.c
rename to src/map/script.cpp
index 6a588cb6db..bc526576e6 100644
--- a/src/map/script.c
+++ b/src/map/script.cpp
@@ -57,6 +57,9 @@
#include
#include
+#ifdef __cplusplus
+extern "C" {
+#endif
struct eri *array_ers;
DBMap *st_db;
@@ -605,7 +608,7 @@ static void script_reportdata(struct script_data* data)
ShowDebug("Data: nothing (nil)\n");
break;
case C_INT:// number
- ShowDebug("Data: number value=%"PRId64"\n", data->u.num);
+ ShowDebug("Data: number value=%" PRId64 "\n", data->u.num);
break;
case C_STR:
case C_CONSTSTR:// string
@@ -629,7 +632,7 @@ static void script_reportdata(struct script_data* data)
}
break;
case C_POS:// label
- ShowDebug("Data: label pos=%"PRId64"\n", data->u.num);
+ ShowDebug("Data: label pos=%" PRId64 "\n", data->u.num);
break;
default:
ShowDebug("Data: %s\n", script_op2name(data->type));
@@ -945,7 +948,7 @@ const char* skip_space(const char* p)
for(;;)
{
if( *p == '\0' ) {
- disp_warning_message("script:script->skip_space: end of file while parsing block comment. expected "CL_BOLD"*/"CL_NORM, p);
+ disp_warning_message("script:script->skip_space: end of file while parsing block comment. expected " CL_BOLD "*/" CL_NORM, p);
return p;
}
if( *p == '*' && p[1] == '/' )
@@ -2389,13 +2392,13 @@ static void read_constdb(void)
}
else {
skipped++;
- ShowWarning("Skipping line '"CL_WHITE"%d"CL_RESET"', invalid constant definition\n",linenum);
+ ShowWarning("Skipping line '" CL_WHITE "%d" CL_RESET "', invalid constant definition\n",linenum);
}
}
fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s/const.txt"CL_RESET"'.\n", entries, db_path);
+ ShowStatus("Done reading '" CL_WHITE "%d" CL_RESET "' entries in '" CL_WHITE "%s/const.txt" CL_RESET "'.\n", entries, db_path);
if(skipped){
- ShowWarning("Skipped '"CL_WHITE"%d"CL_RESET"', entries\n",skipped);
+ ShowWarning("Skipped '" CL_WHITE "%d" CL_RESET "', entries\n",skipped);
}
}
@@ -2889,7 +2892,7 @@ void script_array_ensure_zero(struct script_state *st, struct map_session_data *
}
if (src && src->arrays) {
- struct script_array *sa = idb_get(src->arrays, script_getvarid(uid));
+ struct script_array *sa = static_cast(idb_get(src->arrays, script_getvarid(uid)));
if (sa) {
unsigned int i;
@@ -2916,7 +2919,7 @@ unsigned int script_array_size(struct script_state *st, struct map_session_data
struct reg_db *src = script_array_src(st, sd, name, ref);
if (src && src->arrays)
- sa = idb_get(src->arrays, search_str(name));
+ sa = static_cast(idb_get(src->arrays, search_str(name)));
return sa ? sa->size : 0;
}
@@ -2934,7 +2937,7 @@ unsigned int script_array_highest_key(struct script_state *st, struct map_sessio
script_array_ensure_zero(st,sd,reference_uid(key, 0), ref);
- if( ( sa = idb_get(src->arrays, key) ) ) {
+ if( ( sa = static_cast(idb_get(src->arrays, key)) ) ) {
unsigned int i, highest_key = 0;
for(i = 0; i < sa->size; i++) {
@@ -2951,7 +2954,7 @@ unsigned int script_array_highest_key(struct script_state *st, struct map_sessio
int script_free_array_db(DBKey key, DBData *data, va_list ap)
{
- struct script_array *sa = db_data2ptr(data);
+ struct script_array *sa = static_cast(db_data2ptr(data));
aFree(sa->members);
ers_free(array_ers, sa);
return SCRIPT_CMD_SUCCESS;
@@ -3067,7 +3070,7 @@ void script_array_update(struct reg_db *src, int64 num, bool empty)
if (!src->arrays) {
src->arrays = idb_alloc(DB_OPT_BASE);
} else {
- sa = idb_get(src->arrays, id);
+ sa = static_cast(idb_get(src->arrays, id));
}
if( sa ) {
@@ -3260,7 +3263,7 @@ const char* conv_str_(struct script_state* st, struct script_data* data, struct
else if( data_isint(data) )
{// int -> string
CREATE(p, char, ITEM_NAME_LENGTH);
- snprintf(p, ITEM_NAME_LENGTH, "%"PRId64"", data->u.num);
+ snprintf(p, ITEM_NAME_LENGTH, "%" PRId64 "", data->u.num);
p[ITEM_NAME_LENGTH-1] = '\0';
data->type = C_STR;
data->u.str = p;
@@ -4106,7 +4109,7 @@ void script_stop_scriptinstances(struct script_code *code) {
iter = db_iterator(st_db);
- for( st = dbi_first(iter); dbi_exists(iter); st = dbi_next(iter) ) {
+ for( st = static_cast(dbi_first(iter)); dbi_exists(iter); st = static_cast(dbi_next(iter)) ) {
if( st->script == code )
script_free_state(st);
}
@@ -4462,7 +4465,7 @@ int script_config_read(const char *cfgName)
*/
static int db_script_free_code_sub(DBKey key, DBData *data, va_list ap)
{
- struct script_code *code = db_data2ptr(data);
+ struct script_code *code = static_cast(db_data2ptr(data));
if (code)
script_free_code(code);
return 0;
@@ -4517,7 +4520,7 @@ void script_cleararray_pc(struct map_session_data* sd, const char* varname, void
if( value )
script_array_ensure_zero(NULL,sd,reference_uid(key,0), NULL);
- if( !(sa = idb_get(src->arrays, key)) ) /* non-existent array, nothing to empty */
+ if( !(sa = static_cast(idb_get(src->arrays, key))) ) /* non-existent array, nothing to empty */
return;
size = sa->size;
@@ -4560,7 +4563,7 @@ int script_reg_destroy(DBKey key, DBData *data, va_list ap)
if( data->type != DB_DATA_PTR ) // got no need for those!
return 0;
- src = db_data2ptr(data);
+ src = static_cast(db_data2ptr(data));
if( src->type ) {
struct script_reg_str *p = (struct script_reg_str *)src;
@@ -4862,7 +4865,7 @@ void do_final_script() {
aFree(generic_ui_array);
iter = db_iterator(st_db);
- for(st = dbi_first(iter); dbi_exists(iter); st = dbi_next(iter))
+ for( st = static_cast(dbi_first(iter)); dbi_exists(iter); st = static_cast(dbi_next(iter)) )
script_free_state(st);
dbi_destroy(iter);
@@ -4915,9 +4918,9 @@ void do_init_script(void) {
scriptlabel_db = strdb_alloc(DB_OPT_DUP_KEY,50);
autobonus_db = strdb_alloc(DB_OPT_DUP_KEY,0);
- st_ers = ers_new(sizeof(struct script_state), "script.c::st_ers", ERS_CACHE_OPTIONS);
- stack_ers = ers_new(sizeof(struct script_stack), "script.c::script_stack", ERS_OPT_FLEX_CHUNK);
- array_ers = ers_new(sizeof(struct script_array), "script.c:array_ers", ERS_OPT_CLEAN|ERS_OPT_CLEAR); // TODO: This value is not yet in the enum
+ st_ers = ers_new(sizeof(struct script_state), "script.cpp::st_ers", ERS_CACHE_OPTIONS);
+ stack_ers = ers_new(sizeof(struct script_stack), "script.cpp::script_stack", ERS_OPT_FLEX_CHUNK);
+ array_ers = ers_new(sizeof(struct script_array), "script.cpp:array_ers", ERS_CLEAN_OPTIONS);
ers_chunk_size(st_ers, 10);
ers_chunk_size(stack_ers, 10);
@@ -4988,7 +4991,7 @@ void script_reload(void) {
atcmd_binding_count = 0;
iter = db_iterator(st_db);
- for(st = dbi_first(iter); dbi_exists(iter); st = dbi_next(iter))
+ for( st = static_cast(dbi_first(iter)); dbi_exists(iter); st = static_cast(dbi_next(iter)) )
script_free_state(st);
dbi_destroy(iter);
db_clear(st_db);
@@ -6510,7 +6513,7 @@ BUILDIN_FUNC(deletearray)
script_array_ensure_zero(st, NULL, data->u.num, reference_getref(data));
- if ( !(sa = idb_get(src->arrays, id)) ) { // non-existent array, nothing to empty
+ if ( !(sa = static_cast(idb_get(src->arrays, id))) ) { // non-existent array, nothing to empty
return SCRIPT_CMD_SUCCESS;// not a variable
}
@@ -6604,7 +6607,7 @@ BUILDIN_FUNC(getelementofarray)
i = script_getnum(st, 3);
if (i < 0 || i >= SCRIPT_MAX_ARRAYSIZE) {
- ShowWarning("script:getelementofarray: index out of range (%"PRId64")\n", i);
+ ShowWarning("script:getelementofarray: index out of range (%" PRId64 ")\n", i);
script_reportdata(data);
script_pushnil(st);
st->state = END;
@@ -6757,11 +6760,11 @@ static int script_getitem_randomoption(struct script_state *st, struct item *it,
opt_param_idx = reference_getindex(opt_param);
for (i = 0; i < opt_id_n && i < MAX_ITEM_RDM_OPT; i++) {
- it->option[i].id = (short)__64BPRTSIZE(get_val2(st,reference_uid(opt_id_id,opt_id_idx+i),opt_id_ref));
+ it->option[i].id = *reinterpret_cast(__64BPRTSIZE(get_val2(st,reference_uid(opt_id_id,opt_id_idx+i),opt_id_ref)));
script_removetop(st, -1, 0);
- it->option[i].value = (short)__64BPRTSIZE(get_val2(st,reference_uid(opt_val_id,opt_val_idx+i),opt_val_ref));
+ it->option[i].value = *reinterpret_cast(__64BPRTSIZE(get_val2(st,reference_uid(opt_val_id,opt_val_idx+i),opt_val_ref)));
script_removetop(st, -1, 0);
- it->option[i].param = (char)__64BPRTSIZE(get_val2(st,reference_uid(opt_param_id,opt_param_idx+i),opt_param_ref));
+ it->option[i].param = *reinterpret_cast(__64BPRTSIZE(get_val2(st,reference_uid(opt_param_id,opt_param_idx+i),opt_param_ref)));
script_removetop(st, -1, 0);
}
return SCRIPT_CMD_SUCCESS;
@@ -10431,7 +10434,7 @@ BUILDIN_FUNC(clone)
TBL_PC *sd, *msd=NULL;
uint32 char_id, master_id = 0, x, y, flag = 0;
int16 m;
- enum e_mode mode = 0;
+ enum e_mode mode = MD_NONE;
unsigned int duration = 0;
const char *mapname,*event;
@@ -10446,7 +10449,7 @@ BUILDIN_FUNC(clone)
master_id=script_getnum(st,7);
if( script_hasdata(st,8) )
- mode=script_getnum(st,8);
+ mode=static_cast(script_getnum(st,8));
if( script_hasdata(st,9) )
flag=script_getnum(st,9);
@@ -11380,7 +11383,7 @@ BUILDIN_FUNC(getstatus)
if( id <= SC_NONE || id >= SC_MAX )
{// invalid status type given
- ShowWarning("script.c:getstatus: Invalid status type given (%d).\n", id);
+ ShowWarning("script.cpp:getstatus: Invalid status type given (%d).\n", id);
return SCRIPT_CMD_SUCCESS;
}
@@ -17856,7 +17859,7 @@ BUILDIN_FUNC(setunitdata)
md->state.copy_master_mode = 0;
calc_status = true;
break;
- case UMOB_DMGIMMUNE: md->ud.immune_attack = (bool)value > 0 ? 1 : 0; break;
+ case UMOB_DMGIMMUNE: md->ud.immune_attack = value > 0; break;
case UMOB_ATKRANGE: md->base_status->rhw.range = (unsigned short)value; calc_status = true; break;
case UMOB_ATKMIN: md->base_status->rhw.atk = (unsigned short)value; calc_status = true; break;
case UMOB_ATKMAX: md->base_status->rhw.atk2 = (unsigned short)value; calc_status = true; break;
@@ -17909,7 +17912,7 @@ BUILDIN_FUNC(setunitdata)
case UHOM_INT: hd->base_status.int_ = (unsigned short)value; status_calc_misc(bl, &hd->base_status, hd->homunculus.level); calc_status = true; break;
case UHOM_DEX: hd->base_status.dex = (unsigned short)value; status_calc_misc(bl, &hd->base_status, hd->homunculus.level); calc_status = true; break;
case UHOM_LUK: hd->base_status.luk = (unsigned short)value; status_calc_misc(bl, &hd->base_status, hd->homunculus.level); calc_status = true; break;
- case UHOM_DMGIMMUNE: hd->ud.immune_attack = (bool)value > 0 ? 1 : 0; break;
+ case UHOM_DMGIMMUNE: hd->ud.immune_attack = value > 0; break;
case UHOM_ATKRANGE: hd->base_status.rhw.range = (unsigned short)value; calc_status = true; break;
case UHOM_ATKMIN: hd->base_status.rhw.atk = (unsigned short)value; calc_status = true; break;
case UHOM_ATKMAX: hd->base_status.rhw.atk2 = (unsigned short)value; calc_status = true; break;
@@ -17960,7 +17963,7 @@ BUILDIN_FUNC(setunitdata)
case UPET_INT: pd->status.int_ = (unsigned short)value; status_calc_misc(bl, &pd->status, pd->pet.level); break;
case UPET_DEX: pd->status.dex = (unsigned short)value; status_calc_misc(bl, &pd->status, pd->pet.level); break;
case UPET_LUK: pd->status.luk = (unsigned short)value; status_calc_misc(bl, &pd->status, pd->pet.level); break;
- case UPET_DMGIMMUNE: pd->ud.immune_attack = (bool)value > 0 ? 1 : 0; break;
+ case UPET_DMGIMMUNE: pd->ud.immune_attack = value > 0; break;
case UPET_ATKRANGE: pd->status.rhw.range = (unsigned short)value; break;
case UPET_ATKMIN: pd->status.rhw.atk = (unsigned short)value; break;
case UPET_ATKMAX: pd->status.rhw.atk2 = (unsigned short)value; break;
@@ -18008,7 +18011,7 @@ BUILDIN_FUNC(setunitdata)
case UMER_INT: mc->base_status.int_ = (unsigned short)value; status_calc_misc(bl, &mc->base_status, mc->db->lv); calc_status = true; break;
case UMER_DEX: mc->base_status.dex = (unsigned short)value; status_calc_misc(bl, &mc->base_status, mc->db->lv); calc_status = true; break;
case UMER_LUK: mc->base_status.luk = (unsigned short)value; status_calc_misc(bl, &mc->base_status, mc->db->lv); calc_status = true; break;
- case UMER_DMGIMMUNE: mc->ud.immune_attack = (bool)value > 0 ? 1 : 0; break;
+ case UMER_DMGIMMUNE: mc->ud.immune_attack = value > 0; break;
case UMER_ATKRANGE: mc->base_status.rhw.range = (unsigned short)value; calc_status = true; break;
case UMER_ATKMIN: mc->base_status.rhw.atk = (unsigned short)value; calc_status = true; break;
case UMER_ATKMAX: mc->base_status.rhw.atk2 = (unsigned short)value; calc_status = true; break;
@@ -18060,7 +18063,7 @@ BUILDIN_FUNC(setunitdata)
case UELE_INT: ed->base_status.int_ = (unsigned short)value; status_calc_misc(bl, &ed->base_status, ed->db->lv); calc_status = true; break;
case UELE_DEX: ed->base_status.dex = (unsigned short)value; status_calc_misc(bl, &ed->base_status, ed->db->lv); calc_status = true; break;
case UELE_LUK: ed->base_status.luk = (unsigned short)value; status_calc_misc(bl, &ed->base_status, ed->db->lv); calc_status = true; break;
- case UELE_DMGIMMUNE: ed->ud.immune_attack = (bool)value > 0 ? 1 : 0; break;
+ case UELE_DMGIMMUNE: ed->ud.immune_attack = value > 0; break;
case UELE_ATKRANGE: ed->base_status.rhw.range = (unsigned short)value; calc_status = true; break;
case UELE_ATKMIN: ed->base_status.rhw.atk = (unsigned short)value; calc_status = true; break;
case UELE_ATKMAX: ed->base_status.rhw.atk2 = (unsigned short)value; calc_status = true; break;
@@ -18633,7 +18636,7 @@ BUILDIN_FUNC(awake)
iter = db_iterator(st_db);
- for (tst = dbi_first(iter); dbi_exists(iter); tst = dbi_next(iter)) {
+ for (tst = static_cast(dbi_first(iter)); dbi_exists(iter); tst = static_cast(dbi_next(iter))) {
if (tst->oid == nd->bl.id) {
if (tst->sleep.timer == INVALID_TIMER) { // already awake ???
continue;
@@ -19733,7 +19736,7 @@ BUILDIN_FUNC(instance_create)
int owner_id = 0;
if (script_hasdata(st, 3)) {
- mode = script_getnum(st, 3);
+ mode = static_cast(script_getnum(st, 3));
if (mode < IM_NONE || mode >= IM_MAX) {
ShowError("buildin_instance_create: Unknown instance mode %d for '%s'\n", mode, script_getstr(st, 2));
@@ -20466,7 +20469,7 @@ BUILDIN_FUNC(pushpc)
dx = dirx[dir];
dy = diry[dir];
- unit_blown(&sd->bl, dx, dy, cells, 0);
+ unit_blown(&sd->bl, dx, dy, cells, BLOWN_NONE);
return SCRIPT_CMD_SUCCESS;
}
@@ -24196,3 +24199,7 @@ struct script_function buildin_func[] = {
{NULL,NULL,NULL},
};
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/map/status.h b/src/map/status.h
index d8d7f761e9..a981cb890a 100644
--- a/src/map/status.h
+++ b/src/map/status.h
@@ -1810,6 +1810,7 @@ extern short current_equip_opt_index;
/// Mode definitions to clear up code reading. [Skotlex]
enum e_mode {
+ MD_NONE = 0x0000000,
MD_CANMOVE = 0x0000001,
MD_LOOTER = 0x0000002,
MD_AGGRESSIVE = 0x0000004,