From ad74c0a25d142eadcd16006ddae44219ec4fb4cd Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Mon, 7 Dec 2015 19:41:47 +0100 Subject: [PATCH] fix rare bug that created negative peasants when a region had non-standard wage, immigration could cause negative peasants --- src/laws.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/laws.c b/src/laws.c index 591e865a9..7dc6cd0af 100755 --- a/src/laws.c +++ b/src/laws.c @@ -707,23 +707,21 @@ void immigration(void) int rp = rpeasants(r) + r->land->newpeasants; rsetpeasants(r, _max(0, rp)); } - /* Genereate some (0-2 to 0-6 depending on the income) peasants out of nothing */ - /*if less then 50 are in the region and there is space and no monster or deamon units in the region */ + /* Genereate some (0-6 depending on the income) peasants out of nothing */ + /* if less than 50 are in the region and there is space and no monster or demon units in the region */ int peasants = rpeasants(r); - if (repopulate && r->land && (peasants < repopulate) && maxworkingpeasants(r) >(peasants + 30) * 2) - { + int income = wage(r, NULL, NULL, turn) - maintenance_cost(NULL); + if (repopulate && r->land && (peasants < repopulate) && maxworkingpeasants(r) > (peasants + 30) * 2 && income >= 0) { int badunit = 0; unit *u; for (u = r->units; u; u = u->next) { - if (!playerrace(u_race(u)) || u_race(u) == get_race(RC_DAEMON)) - { + if (!playerrace(u_race(u)) || u_race(u) == get_race(RC_DAEMON)) { badunit = 1; break; } } - if (badunit == 0) - { - peasants += (int)(rng_double()*(wage(r, NULL, NULL, turn) - 9)); + if (badunit == 0) { + peasants += (int)(rng_double() * (income + 1)); rsetpeasants(r, peasants); } }