diff options
author | Haru <haru@dotalux.com> | 2014-01-13 04:06:56 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2014-01-13 04:16:48 +0100 |
commit | 8eadb9fc241e1784084625e89b208d80bda9e6e2 (patch) | |
tree | 098dc5775c6dd10cb7c98b8054df09e22d3689e2 /src/map/script.c | |
parent | ff4faca9cc44e98abad50bfda849f596d7bc81c1 (diff) | |
download | hercules-8eadb9fc241e1784084625e89b208d80bda9e6e2.tar.gz hercules-8eadb9fc241e1784084625e89b208d80bda9e6e2.tar.bz2 hercules-8eadb9fc241e1784084625e89b208d80bda9e6e2.tar.xz hercules-8eadb9fc241e1784084625e89b208d80bda9e6e2.zip |
Improved overwriting priority of variables/constants/parameters
- Fixes issue 7968, thanks to Moguri
http://hercules.ws/board/tracker/issue-7968-trader-npc-not-working/
- Corrected sprite name for KO_KAGE to match latest kRO info (previouly
KO_ZANZOU, conflicting with a Kagerou/Oboro skill identifier)
- Updated self-test script to include checks for constants and for setd
and getd.
- Made possible thanks to Ind.
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/map/script.c b/src/map/script.c index 64943dd2a..09fab8131 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -2068,8 +2068,18 @@ void script_set_constant(const char* name, int value, bool isparameter) { void script_set_constant2(const char *name, int value, bool isparameter) { 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 var name '%s', prioritising the script var\n",name); + if( script->str_data[n].type == C_PARAM ) { + ShowError("script_set_constant2: Attempted to overwrite existing parameter '%s' with a constant (value=%d).\n", name, value); + return; + } + + if( script->str_data[n].type == C_NAME && script->str_data[n].val ) { + ShowWarning("script_set_constant2: Attempted to overwrite existing variable '%s' with a constant (value=%d).\n", name, value); + return; + } + + if( script->str_data[n].type == C_INT && value && value != script->str_data[n].val ) { // existing constant + ShowWarning("script_set_constant2: Attempted to overwrite existing constant '%s' (old value=%d, new value=%d).\n", name, script->str_data[n].val, value); return; } @@ -2083,21 +2093,6 @@ void script_set_constant2(const char *name, int value, bool isparameter) { script->str_data[n].val = value; } -/* 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 = 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. */ - - if( script->str_data[n].type != C_NOP ) { - script->str_data[n].type = C_NOP; - script->str_data[n].val = 0; - script->str_data[n].func = NULL; - script->str_data[n].backpatch = -1; - script->str_data[n].label = -1; - } -} /*========================================== * Reading constant databases * const.txt @@ -3603,7 +3598,7 @@ void script_check_buildin_argtype(struct script_state* st, int func) } break; case 'r': - if( !data_isreference(data) ) + if( !data_isreference(data) || reference_toconstant(data) ) {// variables ShowWarning("Unexpected type for argument %d. Expected variable, got %s.\n", idx-1,script->op2name(data->type)); script->reportdata(data); @@ -4351,7 +4346,7 @@ int script_reload(void) { mapreg->reload(); - itemdb->force_name_constants(); + itemdb->name_constants(); return 0; } @@ -5509,7 +5504,7 @@ BUILDIN(setr) { data = script_getdata(st,2); //datavalue = script_getdata(st,3); - if( !data_isreference(data) ) { + if( !data_isreference(data) || reference_toconstant(data) ) { ShowError("script:set: not a variable\n"); script->reportdata(script_getdata(st,2)); st->state = END; @@ -5596,7 +5591,7 @@ BUILDIN(setarray) TBL_PC* sd = NULL; data = script_getdata(st, 2); - if( !data_isreference(data) ) + if( !data_isreference(data) || reference_toconstant(data) ) { ShowError("script:setarray: not a variable\n"); script->reportdata(data); @@ -19136,7 +19131,6 @@ void script_defaults(void) { script->pop_stack = pop_stack; script->set_constant = script_set_constant; script->set_constant2 = script_set_constant2; - script->set_constant_force = script_set_constant_force; script->get_constant = script_get_constant; script->label_add = script_label_add; script->run = run_script; |