update: Enforce sector population limit only right after growth

The update kills people to enforce sector population limits, right
after growing people.

However, the population limit may decrease between that killing and
the end of the update:

* Research declines (only with RES_POP), but the lower population
  limit isn't enforced.  Even with an insanely fast decline of 60%
  (level_age_rate = 1, etu_per_update = 60), the population limit
  decreases by less than 10%.

  Not applying the new level to this update is consistent with how we
  use levels elsewhere.

* upd_buildeff() changes sector type and efficiency, but a lower new
  population limit is enforced only when this changes the sector type
  from big city to not big city (since option BIG_CITY was added in
  Empire 2).

  It isn't enforced on other sector type changes.  Might change the
  population limit since the type's limit became configurable in
  commit 153527a (v4.2.20).  Sane configurations don't let players
  redesignate sectors to a type with different maximum population.
  The server doesn't enforce this, though.

  It isn't enforced when a big city's efficiency decreases, but sector
  type change isn't achieved.  Having population exceed the new limit
  without having produced enough work to change the type seems
  unlikely, as 25 will do even in the worst case, but should be
  possible with a sufficiently low work percentage.

  None of this is documented in info Update-sequence.  Inconsistent
  mess.  Drop it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-06-01 22:05:41 +02:00
parent b80fd4e982
commit 3bcad4c0dc
2 changed files with 3 additions and 13 deletions

View file

@ -50,13 +50,12 @@
* Return amount of work used.
*/
static int
upd_buildeff(struct natstr *np, struct sctstr *sp, int *workp,
short *vec, int etu, int *desig, int *cost)
upd_buildeff(struct sctstr *sp, int *workp, short vec[], int *desig,
int *cost)
{
int work_cost = 0;
int buildeff_work = *workp / 2;
int n, hcms, lcms, neweff;
unsigned char old_type = *desig;
*cost = 0;
neweff = sp->sct_effic;
@ -77,14 +76,6 @@ upd_buildeff(struct natstr *np, struct sctstr *sp, int *workp,
}
neweff = n;
*cost += work_cost;
if (!n && IS_BIG_CITY(old_type) && !IS_BIG_CITY(*desig)) {
/* FIXME use trunc_people() */
int maxpop = max_population(np->nat_level[NAT_RLEV], *desig, n);
if (vec[I_CIVIL] > maxpop)
vec[I_CIVIL] = maxpop;
if (vec[I_UW] > maxpop)
vec[I_UW] = maxpop;
}
}
if (*desig == sp->sct_newtype) {
work_cost = 100 - neweff;
@ -324,7 +315,7 @@ produce_sect(int natnum, int etu, struct bp *bp, int p_sect[][2])
if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) &&
np->nat_money >= 0) {
neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, &cost);
neweff = upd_buildeff(sp, &work, vec, &desig, &cost);
bp_put_items(bp, sp, vec);
p_sect[SCT_EFFIC][0]++;
p_sect[SCT_EFFIC][1] += cost;

View file

@ -283,7 +283,6 @@ give h 10,2 10
edit l 12,2 s c S c e 1
give l 12,2 10
give h 12,2 50
| TODO pop truncation on big city teardown
|| ship building
| #0 100%
| #60 stopped