summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-12-20 02:24:07 +0100
committerHaru <haru@dotalux.com>2016-01-29 10:58:57 +0100
commit8121e1d12dca0c85892ad45f0bb765e7eba770aa (patch)
treee2a322db5989a8c657dbd3fd9b697c14eb48d291 /src/map/script.c
parentb7c5b53cccac17765fd7445b390853f5a0eb1a4d (diff)
downloadhercules-8121e1d12dca0c85892ad45f0bb765e7eba770aa.tar.gz
hercules-8121e1d12dca0c85892ad45f0bb765e7eba770aa.tar.bz2
hercules-8121e1d12dca0c85892ad45f0bb765e7eba770aa.tar.xz
hercules-8121e1d12dca0c85892ad45f0bb765e7eba770aa.zip
Replaced several floating-point operations with integer operations
This fixes several rounding errors happening in various places (i.e. the base exp for HORONG being calculated as 819 instead of 820 when the server rates are set to 1x) Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/map/script.c b/src/map/script.c
index ca53b6f6d..9e113a6f9 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -3851,7 +3851,7 @@ void op_2str(struct script_state* st, int op, const char* s1, const char* s2)
void op_2num(struct script_state* st, int op, int i1, int i2)
{
int ret;
- double ret_double;
+ int64 ret64;
switch( op ) {
case C_AND: ret = i1 & i2; break;
@@ -3883,25 +3883,21 @@ void op_2num(struct script_state* st, int op, int i1, int i2)
ret = i1 % i2;
break;
default:
- switch( op )
- {// operators that can overflow/underflow
- case C_ADD: ret = i1 + i2; ret_double = (double)i1 + (double)i2; break;
- case C_SUB: ret = i1 - i2; ret_double = (double)i1 - (double)i2; break;
- case C_MUL: ret = i1 * i2; ret_double = (double)i1 * (double)i2; break;
+ switch (op) { // operators that can overflow/underflow
+ case C_ADD: ret = i1 + i2; ret64 = (int64)i1 + i2; break;
+ case C_SUB: ret = i1 - i2; ret64 = (int64)i1 - i2; break;
+ case C_MUL: ret = i1 * i2; ret64 = (int64)i1 * i2; break;
default:
ShowError("script:op_2num: unexpected number operator %s i1=%d i2=%d\n", script->op2name(op), i1, i2);
script->reportsrc(st);
script_pushnil(st);
return;
}
- if( ret_double < (double)INT_MIN )
- {
+ if (ret64 < INT_MIN) {
ShowWarning("script:op_2num: underflow detected op=%s i1=%d i2=%d\n", script->op2name(op), i1, i2);
script->reportsrc(st);
ret = INT_MIN;
- }
- else if( ret_double > (double)INT_MAX )
- {
+ } else if (ret64 > INT_MAX) {
ShowWarning("script:op_2num: overflow detected op=%s i1=%d i2=%d\n", script->op2name(op), i1, i2);
script->reportsrc(st);
ret = INT_MAX;
@@ -9710,20 +9706,18 @@ BUILDIN(makepet)
BUILDIN(getexp)
{
int base=0,job=0;
- double bonus;
struct map_session_data *sd = script->rid2sd(st);
if (sd == NULL)
return true;
- base=script_getnum(st,2);
- job =script_getnum(st,3);
- if(base<0 || job<0)
+ base = script_getnum(st,2);
+ job = script_getnum(st,3);
+ if (base < 0 || job < 0)
return true;
// bonus for npc-given exp
- bonus = battle_config.quest_exp_rate / 100.;
- base = (int) cap_value(base * bonus, 0, INT_MAX);
- job = (int) cap_value(job * bonus, 0, INT_MAX);
+ base = cap_value(apply_percentrate(base, battle_config.quest_exp_rate, 100), 0, INT_MAX);
+ job = cap_value(apply_percentrate(job, battle_config.quest_exp_rate, 100), 0, INT_MAX);
pc->gainexp(sd, &sd->bl, base, job, true);