summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db/pre-re/mob_db.txt2
-rw-r--r--db/re/mob_db.txt2
-rw-r--r--npc/custom/test.txt26
-rw-r--r--src/map/itemdb.c11
-rw-r--r--src/map/itemdb.h1
-rw-r--r--src/map/script.c38
-rw-r--r--src/map/script.h1
7 files changed, 44 insertions, 37 deletions
diff --git a/db/pre-re/mob_db.txt b/db/pre-re/mob_db.txt
index 8d1151dda..05e564ece 100644
--- a/db/pre-re/mob_db.txt
+++ b/db/pre-re/mob_db.txt
@@ -1141,4 +1141,4 @@
2081,E_HYDRA,Suspicious Hydra,Strange Hydra,34,854,1,0,0,7,1,2,100,100,1,1,1,1,1,1,10,12,0,3,41,0x0,1000,800,432,600,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2082,G_PIRANHA,Piranha,Piranha,75,4522,0,0,0,1,182,223,2,10,69,45,30,30,66,35,10,12,1,5,61,0x3295,200,768,768,384,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-2308,KO_ZANZOU,Zanzou,Zanzou,1,50,0,0,0,1,1,1,0,0,1,1,1,1,1,1,1,1,1,7,20,0x0,400,1872,672,480,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+2308,KO_KAGE,Zanzou,Zanzou,1,50,0,0,0,1,1,1,0,0,1,1,1,1,1,1,1,1,1,7,20,0x0,400,1872,672,480,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
diff --git a/db/re/mob_db.txt b/db/re/mob_db.txt
index 7bf4cff0e..c0f905dbc 100644
--- a/db/re/mob_db.txt
+++ b/db/re/mob_db.txt
@@ -1445,7 +1445,7 @@
2305,E_UNGOLIANT,Ungoliant,Ungoliant,1,50,0,0,0,1,7,10,0,5,1,1,1,1,6,30,10,12,1,3,21,0x83,400,1872,672,480,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2306,E_GOLDEN_BUG,Golden Thief Bug,Golden Thief Bug,1,50,0,0,0,1,7,10,0,5,1,1,1,1,6,30,10,12,1,3,21,0x83,400,1872,672,480,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2307,J_MISTRESS,Mistress,Mistress,1,50,0,0,0,1,7,10,0,5,1,1,1,1,6,30,10,12,1,3,21,0x83,400,1872,672,480,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-2308,KO_ZANZOU,Zanzou,Zanzou,1,50,0,0,0,1,1,1,0,0,1,1,1,1,1,1,1,1,1,7,20,0x0,400,1872,672,480,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+2308,KO_KAGE,Zanzou,Zanzou,1,50,0,0,0,1,1,1,0,0,1,1,1,1,1,1,1,1,1,7,20,0x0,400,1872,672,480,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
// Malaya Port
2309,BUNGISNGIS,Bungisngis,Bungisngis,121,25513,0,1960,1650,1,851,1276,115,35,100,100,30,30,100,30,10,12,2,7,42,0x3795,200,1000,792,336,0,0,0,0,0,0,0,7054,2000,6510,1000,12700,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0
diff --git a/npc/custom/test.txt b/npc/custom/test.txt
index b3579d4c3..07523f008 100644
--- a/npc/custom/test.txt
+++ b/npc/custom/test.txt
@@ -494,6 +494,32 @@ OnInit:
callsub(OnCheck, "array shrink", .@x[1], 0);
callsub(OnCheck, "array shrink and getarraysize", getarraysize(.@x), 0);
+
+ // Constants
+ callsub(OnCheck, "'true' constant", true, 1);
+ callsub(OnCheck, "'false' constant", false, 0);
+ callsub(OnCheck, "'PORING' mob ID", PORING, 1002);
+ callsub(OnCheck, "'NV_BASIC' skill ID", NV_BASIC, 1);
+ callsub(OnCheck, "'Red_Potion' item ID", Red_Potion, 501);
+ callsub(OnCheck, "'Monster's_Feed' item ID", Monster's_Feed, 528);
+
+
+ // setd/getd
+ .@x = 1; .@x$ = ".@x";
+ callsub(OnCheck, "getd", getd(".@x"), 1);
+ callsub(OnCheck, "getd arguments", getd(.@x$), 1);
+ .@y = 0; .@y$ = ".@y";
+ setd(".@y", .@x);
+ callsub(OnCheck, "setd", .@y, 1);
+ setd(.@y$, 2);
+ callsub(OnCheck, "setd arguments", .@y, 2);
+ set getd(".@x"), getd(".@y");
+ callsub(OnCheck, "set getd", .@x, .@y);
+ .@y = 1;
+ setd(".@x", getd(".@y"));
+ callsub(OnCheck, "setd getd", .@x, .@y);
+
+
if (.errors) {
debugmes "Script engine self-test [ FAILED ]";
debugmes "**** The test was completed with " + .errors + " errors. ****";
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 3f7d06e36..3bed3e03d 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -2249,16 +2249,6 @@ void itemdb_name_constants(void) {
dbi_destroy(iter);
}
-/* used to clear conflicts during script reload */
-void itemdb_force_name_constants(void) {
- DBIterator *iter = db_iterator(itemdb->names);
- struct item_data *data;
-
- for( data = dbi_first(iter); dbi_exists(iter); data = dbi_next(iter) )
- script->set_constant_force(data->name,data->nameid,0);
-
- dbi_destroy(iter);
-}
void do_final_itemdb(void) {
itemdb->clear(true);
@@ -2286,7 +2276,6 @@ void itemdb_defaults(void) {
itemdb->final = do_final_itemdb;
itemdb->reload = itemdb_reload;
itemdb->name_constants = itemdb_name_constants;
- itemdb->force_name_constants = itemdb_force_name_constants;
/* */
itemdb->groups = NULL;
itemdb->group_count = 0;
diff --git a/src/map/itemdb.h b/src/map/itemdb.h
index d74b92d4b..b3ff606df 100644
--- a/src/map/itemdb.h
+++ b/src/map/itemdb.h
@@ -499,7 +499,6 @@ struct itemdb_interface {
void (*final) (void);
void (*reload) (void);
void (*name_constants) (void);
- void (*force_name_constants) (void);
/* */
struct item_group *groups;
unsigned short group_count;
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;
diff --git a/src/map/script.h b/src/map/script.h
index 7a643fa3e..97db2a775 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -575,7 +575,6 @@ struct script_interface {
void (*pop_stack) (struct script_state* st, int start, int end);
void (*set_constant) (const char* name, int value, bool isparameter);
void (*set_constant2) (const char *name, int value, bool isparameter);
- 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);