Litmus test questions

Discussion of all aspects of the game engine, including development of new and existing features.

Moderators: Forum Moderators, Developers

Litmus test questions

Postby lanternglow » August 10th, 2017, 4:48 am

I am working on handling unit experience changes especially regarding percentage discounts applied because of map settings or intelligent trait.

What I have found:
percentage changes for max experience are calculated (paraphrasing a bit) via:
Code: Select all
rate * original_value / 100;

which will always truncate down. That isn't what I usually see in games. Usually if the bonus is not enough to get another point of benefit, then the excess is lost. Essentially rounding towards the original value. Rounding down during percentage increase and rounding up on percentage decrease.

So what I came up with is:
Code: Select all
int delta = original_value * (100 - rate) / 100;
return original_value - delta;

This calculates the amount changed and truncates that. Then applies the integer change to the original value.

The other thing that I did was to put the function to calculate this in src/utils/math.hpp as an inline function rather than being coded directly inline in src/units/unit.cpp

Now, I realize that this is a rather trivial adjustment as far as the game is concerned. One point of experience is probably not going to affect the outcome of a game much at all. But what do people think of the changes as a matter of principle?
lanternglow
 
Posts: 5
Joined: July 22nd, 2017, 3:53 am

Re: Litmus test questions

Postby pauxlo » August 10th, 2017, 8:41 pm

Just for judging the effects, do you have some examples with the units of the default era and the common 70% where this makes a difference?
User avatar
pauxlo
 
Posts: 1008
Joined: September 19th, 2006, 8:54 pm

Re: Litmus test questions

Postby lanternglow » August 10th, 2017, 11:29 pm

It is different by being one point higher on percentage decreases.

I have the test case that I was using for checking the calculations.
Code: Select all
Testing Percentage function
--------------------------------------
xp * rate   current   proposed
27 * 0% =    0   0
27 * 10% =   2   3
27 * 20% =   5   6
27 * 30% =   8   9
27 * 40% =   10   11
27 * 50% =   13   14
27 * 60% =   16   17
27 * 70% =   18   19
27 * 80% =   21   22
27 * 90% =   24   25
27 * 100% =   27   27
27 * 110% =   29   29
27 * 120% =   32   32
27 * 130% =   35   35
27 * 140% =   37   37


Oh. And that would only affect calculations that don't already come out even. So a 40 xp unit (I think Elven Fighters) being changed to 70% I would think would come out the same.

...

Yeah.
Code: Select all
Testing Percentage function
--------------------------------------
xp * rate   current   proposed
40 * 0% =   0   0
40 * 10% =   4   4
40 * 20% =   8   8
40 * 30% =   12   12
40 * 40% =   16   16
40 * 50% =   20   20
40 * 60% =   24   24
40 * 70% =   28   28
40 * 80% =   32   32
40 * 90% =   36   36
40 * 100% =   40   40
40 * 110% =   44   44
40 * 120% =   48   48
40 * 130% =   52   52
40 * 140% =   56   56
lanternglow
 
Posts: 5
Joined: July 22nd, 2017, 3:53 am


Return to Coder’s Corner

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest