forked from github/server
remove the weird rounding macro from peasant growth
This commit is contained in:
parent
9c8df88525
commit
38fd655af9
3 changed files with 9 additions and 18 deletions
|
@ -334,7 +334,7 @@ int peasant_luck_effect(int peasants, int luck, int maxp, double variance)
|
|||
mean *= peasant_luck_factor() * peasant_growth_factor();
|
||||
mean *= ((peasants / (double)maxp < .9) ? 1 : PEASANTFORCE);
|
||||
|
||||
births = RAND_ROUND(normalvariate(mean, variance * mean));
|
||||
births = (int)ceil(normalvariate(mean, variance * mean));
|
||||
if (births <= 0)
|
||||
births = 1;
|
||||
if (births > peasants / 2)
|
||||
|
@ -353,7 +353,7 @@ static void peasants(region * r, int rule)
|
|||
if (peasants > 0 && rule > 0) {
|
||||
int luck = 0;
|
||||
double fraction = peasants * peasant_growth_factor();
|
||||
int births = RAND_ROUND(fraction);
|
||||
int births = (int)ceil(fraction);
|
||||
attrib *a = a_find(r->attribs, &at_peasantluck);
|
||||
|
||||
if (a != NULL) {
|
||||
|
|
|
@ -25,7 +25,6 @@ extern "C" {
|
|||
# define rng_double ((rand()%RAND_MAX)/(double)RAND_MAX)
|
||||
# define RNG_RAND_MAX RAND_MAX
|
||||
#endif
|
||||
#define RAND_ROUND(fractional) ((rng_double() < fractional-(int)fractional)?((int)fractional+1):((int)fractional))
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -5,22 +5,15 @@
|
|||
#include <CuTest.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static void test_rng_round(CuTest * tc)
|
||||
{
|
||||
double f, r;
|
||||
|
||||
test_setup();
|
||||
f = rng_double();
|
||||
r = RAND_ROUND(f);
|
||||
CuAssertTrue(tc, f >= 0);
|
||||
CuAssertTrue(tc, r <= f + 1);
|
||||
CuAssertTrue(tc, r >= f);
|
||||
CuAssertTrue(tc, r == r);
|
||||
CuAssertTrue(tc, r == RAND_ROUND(r));
|
||||
}
|
||||
|
||||
static void test_dice_rand(CuTest* tc)
|
||||
{
|
||||
test_setup();
|
||||
|
||||
random_source_inject_constants(0.0, 0);
|
||||
CuAssertIntEquals(tc, 1, dice_rand("1d10"));
|
||||
CuAssertIntEquals(tc, 1, dice_rand("d20"));
|
||||
CuAssertIntEquals(tc, 2, dice_rand("2d4"));
|
||||
|
||||
CuAssertIntEquals(tc, 9, dice_rand("3*(2+1)"));
|
||||
CuAssertIntEquals(tc, 0, dice_rand("0"));
|
||||
CuAssertIntEquals(tc, -5, dice_rand("-5"));
|
||||
|
@ -34,7 +27,6 @@ static void test_dice_rand(CuTest* tc)
|
|||
CuSuite *get_rng_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_rng_round);
|
||||
SUITE_ADD_TEST(suite, test_dice_rand);
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue