From f102c913b2aa093ef40c7846e25850ebb1106d71 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 12 Dec 2015 21:44:27 +0200 Subject: - Fixed #723 now it's possible to retrieve Battle Config Settings from plugins into scripts - Fixed Possible Crash when null parse function pointer passed to HPMi->addConf - Now it's possible to use same parse function for all config entries - Now Battle Config entries must have a return function --- src/map/battle.c | 20 ++++++++++++++------ src/map/battle.h | 4 ++-- src/map/script.c | 14 +++++++++++++- 3 files changed, 29 insertions(+), 9 deletions(-) (limited to 'src/map') diff --git a/src/map/battle.c b/src/map/battle.c index 7fbbcd0d5..1725d8c65 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -7329,15 +7329,23 @@ int battle_set_value(const char* w1, const char* w2) return 1; } -int battle_get_value(const char* w1) +bool battle_get_value(const char *w1, int *value) { int i; - nullpo_retr(1, w1); + + nullpo_retr(false, w1); + nullpo_retr(false, value); + ARR_FIND(0, ARRAYLENGTH(battle_data), i, strcmpi(w1, battle_data[i].str) == 0); - if (i == ARRAYLENGTH(battle_data)) - return 0; // not found - else - return *battle_data[i].val; + if (i == ARRAYLENGTH(battle_data)) { + if (HPM->getBattleConf(w1,value)) + return true; + } else { + *value = *battle_data[i].val; + return true; + } + + return false; } void battle_set_defaults(void) { diff --git a/src/map/battle.h b/src/map/battle.h index 68a427e72..595ed32bb 100644 --- a/src/map/battle.h +++ b/src/map/battle.h @@ -630,8 +630,8 @@ struct battle_interface { /* - battle_config */ int (*config_read) (const char *cfgName); void (*config_set_defaults) (void); - int (*config_set_value) (const char* w1, const char* w2); - int (*config_get_value) (const char* w1); + int (*config_set_value) (const char *w1, const char *w2); + bool (*config_get_value) (const char *w1, int *value); void (*config_adjust) (void); /* ----------------------------------------- */ /* picks a random enemy within the specified range */ diff --git a/src/map/script.c b/src/map/script.c index cfc7ed052..cc9552d60 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -14620,8 +14620,20 @@ BUILDIN(setbattleflag) BUILDIN(getbattleflag) { const char *flag; + int value; + flag = script_getstr(st,2); - script_pushint(st,battle->config_get_value(flag)); + + if (battle->config_get_value(flag, &value)) { + script_pushint(st,value); + return true; + } else { + script_pushint(st,0); + ShowWarning("buildin_getbattleflag: non-exist battle config requested %s \n", flag); + script->reportsrc(st); + return false; + } + return true; } -- cgit v1.2.3-70-g09d2