Merge pull request #467 from ennorehling/develop

prevent negative parents: manual merge, code cleanup
This commit is contained in:
Enno Rehling 2016-01-31 22:26:11 +01:00
commit 665a271972
1 changed files with 13 additions and 15 deletions

View File

@ -710,9 +710,10 @@ void immigration(void)
} }
/* Genereate some (0-6 depending on the income) peasants out of nothing */ /* 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 */ /* if less than 50 are in the region and there is space and no monster or demon units in the region */
if (repopulate) {
int peasants = rpeasants(r); int peasants = rpeasants(r);
int income = wage(r, NULL, NULL, turn) - maintenance_cost(NULL); int income = wage(r, NULL, NULL, turn) - maintenance_cost(NULL) + 1;
if (repopulate && r->land && (peasants < repopulate) && maxworkingpeasants(r) > (peasants + 30) * 2 && income >= 0) { if (income >= 0 && r->land && (peasants < repopulate) && maxworkingpeasants(r) >(peasants + 30) * 2) {
int badunit = 0; int badunit = 0;
unit *u; unit *u;
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
@ -721,11 +722,8 @@ void immigration(void)
break; break;
} }
} }
if (badunit == 0) if (badunit == 0) {
{ peasants += (int)(rng_double()*income);
int x = wage(r, NULL, NULL, turn) - 9;
if (x>0) {
peasants += (int)(rng_double()*x);
rsetpeasants(r, peasants); rsetpeasants(r, peasants);
} }
} }