update: Reorder feeding, tax & plague for consistency

People in sectors get plagued, then taxed or paid, then fed.  People
on ships and land units get paid, then fed, then plagued.  Sectors
were messed up when Empire 3 made the update code work for budget.

Change sectors back to how they worked before Empire 3: move do_feed()
from produce_sect() to prepare_sects(), and delay do_plague() until
after do_feed().  People in sectors now get taxed, paid and fed even
when they die of the plague, just like they do on ships and land
units.

Because do_plague() now runs after populace(), the latter's handling
of people dying off doesn't cover plague anymore.  Delay it to the
very end of prepare_sects().

Additionally, move feeding and plaguing from upd_ship(), upd_land() to
prep_ship(), prep_land(), for consistency with sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-07-17 10:04:34 +02:00
parent 2fea2a7cb8
commit 43a0a4a451
14 changed files with 1686 additions and 1691 deletions

View file

@ -35,7 +35,6 @@
#include <config.h>
#include <math.h>
#include "chance.h"
#include "land.h"
#include "lost.h"
@ -51,11 +50,10 @@ static void upd_land(struct lndstr *, int, struct bp *, int);
static void plague_land(struct lndstr *, int);
static void landrepair(struct lndstr *, struct natstr *, struct bp *,
int, struct budget *);
static int feed_land(struct lndstr *, int);
void prep_lands(int etus, struct bp *bp)
{
int mil, i;
int mil, i, n;
double mil_pay;
struct lndstr *lp;
@ -75,6 +73,15 @@ void prep_lands(int etus, struct bp *bp)
nat_budget[lp->lnd_own].mil.count += mil;
nat_budget[lp->lnd_own].mil.money += mil_pay;
nat_budget[lp->lnd_own].money += mil_pay;
if (!player->simulation) {
if ((n = feed_people(lp->lnd_item, etus)) > 0) {
wu(0, lp->lnd_own, "%d starved in %s\n", n, prland(lp));
if (n > 10)
nreport(lp->lnd_own, N_DIE_FAMINE, 0, 1);
}
plague_land(lp, etus);
}
}
}
@ -102,7 +109,7 @@ upd_land(struct lndstr *lp, int etus, struct bp *bp, int build)
struct lchrstr *lcp = &lchr[lp->lnd_type];
struct natstr *np = getnatp(lp->lnd_own);
int min = morale_base - (int)np->nat_level[NAT_HLEV];
int n, mult, eff_lost;
int mult, eff_lost;
double cost;
if (!player->simulation)
@ -136,16 +143,6 @@ upd_land(struct lndstr *lp, int etus, struct bp *bp, int build)
budget->bm[BUDG_LND_MAINT].money -= cost;
budget->money -= cost;
}
if (!player->simulation) {
/* feed */
if ((n = feed_land(lp, etus)) > 0) {
wu(0, lp->lnd_own, "%d starved in %s\n", n, prland(lp));
if (n > 10)
nreport(lp->lnd_own, N_DIE_FAMINE, 0, 1);
}
plague_land(lp, etus);
} /* end !player->simulation */
}
}
@ -229,12 +226,3 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus,
if (!player->simulation)
land->lnd_effic += (signed char)build;
}
/*
* returns the number who starved, if any.
*/
static int
feed_land(struct lndstr *lp, int etus)
{
return feed_people(lp->lnd_item, etus);
}

View file

@ -68,6 +68,7 @@ do_plague(struct sctstr *sp, int etu)
plague_report(sp->sct_own, n, pstage, ptime, etu,
"in", ownxy(sp));
}
sp->sct_pstage = pstage;
sp->sct_ptime = ptime;
}

View file

@ -42,11 +42,8 @@
#include "update.h"
void
populace(struct sctstr *sp, int etu)
check_pop_loss(struct sctstr *sp)
{
struct natstr *np = getnatp(sp->sct_own);
double hap, pct;
int n;
int civ = sp->sct_item[I_CIVIL];
int mil = sp->sct_item[I_MILIT];
@ -62,6 +59,17 @@ populace(struct sctstr *sp, int etu)
sp->sct_oldown = 0;
sp->sct_mobil = 0;
}
}
void
populace(struct sctstr *sp, int etu)
{
struct natstr *np = getnatp(sp->sct_own);
double hap, pct;
int n;
int civ = sp->sct_item[I_CIVIL];
int mil = sp->sct_item[I_MILIT];
if (!civ && !mil && !sp->sct_item[I_UW])
return;

View file

@ -78,12 +78,15 @@ prepare_sects(int etu, struct bp *bp)
if (!player->simulation) {
guerrilla(sp);
do_plague(sp, etu);
populace(sp, etu);
}
tax(sp, etu);
if (sp->sct_type == SCT_BANK)
bank_income(sp, etu);
do_feed(sp, getnatp(sp->sct_own), etu, 0);
if (!player->simulation)
do_plague(sp, etu);
check_pop_loss(sp);
bp_set_from_sect(bp, sp);
}
}

View file

@ -148,8 +148,6 @@ produce_sect(int etu, struct bp *bp)
budget = &nat_budget[sp->sct_own];
np = getnatp(sp->sct_own);
do_feed(sp, np, etu, 0);
if (dchr[sp->sct_type].d_maint) {
cost = etu * dchr[sp->sct_type].d_maint;
budget->bm[BUDG_SCT_MAINT].count++;

View file

@ -58,7 +58,7 @@ static int feed_ship(struct shpstr *, int);
void prep_ships(int etus, struct bp *bp)
{
int mil, i;
int mil, i, n;
double mil_pay;
struct shpstr *sp;
@ -78,6 +78,15 @@ void prep_ships(int etus, struct bp *bp)
nat_budget[sp->shp_own].mil.count += mil;
nat_budget[sp->shp_own].mil.money += mil_pay;
nat_budget[sp->shp_own].money += mil_pay;
if (!player->simulation) {
if ((n = feed_ship(sp, etus)) > 0) {
wu(0, sp->shp_own, "%d starved on %s\n", n, prship(sp));
if (n > 10)
nreport(sp->shp_own, N_DIE_FAMINE, 0, 1);
}
plague_ship(sp, etus);
}
}
}
@ -104,7 +113,7 @@ upd_ship(struct shpstr *sp, int etus, struct bp *bp, int build)
struct budget *budget = &nat_budget[sp->shp_own];
struct mchrstr *mp = &mchr[sp->shp_type];
struct natstr *np = getnatp(sp->shp_own);
int n, mult, eff_lost;
int mult, eff_lost;
double cost;
if (build == 1) {
@ -133,16 +142,6 @@ upd_ship(struct shpstr *sp, int etus, struct bp *bp, int build)
budget->bm[BUDG_SHP_MAINT].money -= cost;
budget->money -= cost;
}
if (!player->simulation) {
/* feed */
if ((n = feed_ship(sp, etus)) > 0) {
wu(0, sp->shp_own, "%d starved on %s\n", n, prship(sp));
if (n > 10)
nreport(sp->shp_own, N_DIE_FAMINE, 0, 1);
}
plague_ship(sp, etus);
}
}
}