From 5df43a5b3f3203d87c86c394934dea9059aafc80 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 22 Jun 2016 20:49:57 +0200 Subject: [PATCH] update: Rearrange code to pay non-sector military Split upd_slmilcosts() into prep_ships() and prep_lands(). Move the sanity check for dead ships and land units from prod_ships() and prod_lands() there. Move their call from prepare_sects() to its caller, along with pay_reserve(). Create prep_planes() for symmetry. Pilots are now paid at the same time as other military. Can matter only when the country goes broke during the update. Signed-off-by: Markus Armbruster --- include/update.h | 4 +++- src/lib/commands/budg.c | 4 +++- src/lib/update/land.c | 33 ++++++++++++++++++++++++++------- src/lib/update/main.c | 7 +++++++ src/lib/update/plane.c | 31 +++++++++++++++++++++++-------- src/lib/update/prepare.c | 35 ----------------------------------- src/lib/update/ship.c | 33 ++++++++++++++++++++++++++------- 7 files changed, 88 insertions(+), 59 deletions(-) diff --git a/include/update.h b/include/update.h index 387ca769..c7b61619 100644 --- a/include/update.h +++ b/include/update.h @@ -98,6 +98,7 @@ extern int feed_people(short *, int); extern double food_needed(short *, int); extern int famine_victims(short *, int); /* land.c */ +extern void prep_lands(int, natid); extern void prod_land(int, int, struct bp *, int); /* main.c */ /* in server.h */ @@ -121,6 +122,7 @@ extern void do_plague(struct sctstr *, int); extern int plague_people(struct natstr *, short *, int *, int *, int); extern void plague_report(natid, int, int, int, int, char *, char *); /* plane.c */ +extern void prep_planes(int, natid); extern void prod_plane(int, int, struct bp *, int); /* populace.c */ extern void populace(struct sctstr *, int); @@ -128,7 +130,6 @@ extern int total_work(int, int, int, int, int, int); /* prepare.c */ extern void prepare_sects(int); extern void tax(struct sctstr *, int); -extern void upd_slmilcosts(int, natid); extern void bank_income(struct sctstr *, int); extern void pay_reserve(struct natstr *, int); /* produce.c */ @@ -149,6 +150,7 @@ extern void spread_fallout(struct sctstr *, int); extern void decay_fallout(struct sctstr *, int); extern void produce_sect(struct natstr *, int, struct bp *); /* ship.c */ +extern void prep_ships(int, natid); extern void prod_ship(int, int, struct bp *, int); #endif diff --git a/src/lib/commands/budg.c b/src/lib/commands/budg.c index 10f04331..d9cecf2c 100644 --- a/src/lib/commands/budg.c +++ b/src/lib/commands/budg.c @@ -163,7 +163,9 @@ calc_all(void) bank_income(sp, etu); } } - upd_slmilcosts(etu, player->cnum); + prep_ships(etu, player->cnum); + prep_planes(etu, player->cnum); + prep_lands(etu, player->cnum); pay_reserve(np, etu); /* Maintain ships, planes and land units */ diff --git a/src/lib/update/land.c b/src/lib/update/land.c index ea2e7d08..23d3f228 100644 --- a/src/lib/update/land.c +++ b/src/lib/update/land.c @@ -54,6 +54,32 @@ static void landrepair(struct lndstr *, struct natstr *, struct bp *, int, struct budget *); static int feed_land(struct lndstr *, int); +void prep_lands(int etus, natid natnum) +{ + int mil, i; + double mil_pay; + struct lndstr *lp; + + for (i = 0; (lp = getlandp(i)); i++) { + if (lp->lnd_own == 0) + continue; + if (lp->lnd_own != natnum) + continue; + if (CANT_HAPPEN(lp->lnd_effic < LAND_MINEFF)) { + makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, + lp->lnd_x, lp->lnd_y); + lp->lnd_own = 0; + continue; + } + + mil = lp->lnd_item[I_MILIT]; + mil_pay = mil * etus * money_mil; + nat_budget[natnum].mil.count += mil; + nat_budget[natnum].mil.money += mil_pay; + nat_budget[natnum].money += mil_pay; + } +} + void prod_land(int etus, int natnum, struct bp *bp, int build) /* build = 1, maintain = 0 */ @@ -67,13 +93,6 @@ prod_land(int etus, int natnum, struct bp *bp, int build) continue; if (lp->lnd_own != natnum) continue; - if (lp->lnd_effic < LAND_MINEFF) { - makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, - lp->lnd_x, lp->lnd_y); - lp->lnd_own = 0; - continue; - } - sp = getsectp(lp->lnd_x, lp->lnd_y); if (sp->sct_type == SCT_SANCT) continue; diff --git a/src/lib/update/main.c b/src/lib/update/main.c index 459232c8..7ece6dab 100644 --- a/src/lib/update/main.c +++ b/src/lib/update/main.c @@ -94,6 +94,13 @@ update_main(void) logerror("preparing sectors..."); prepare_sects(etu); logerror("done preparing sectors."); + for (i = 0; i < MAXNOC; i++) { + prep_ships(etu, i); + prep_planes(etu, i); + prep_lands(etu, i); + pay_reserve(getnatp(i), etu); + } + logerror("producing for countries..."); for (i = 0; i < MAXNOC; i++) { if (!(np = getnatp(i))) diff --git a/src/lib/update/plane.c b/src/lib/update/plane.c index 16210437..689fd8f2 100644 --- a/src/lib/update/plane.c +++ b/src/lib/update/plane.c @@ -49,12 +49,11 @@ static void upd_plane(struct plnstr *, int, struct bp *, int); static void planerepair(struct plnstr *, struct natstr *, struct bp *, int, struct budget *); -void -prod_plane(int etus, int natnum, struct bp *bp, int buildem) - /* Build = 1, maintain =0 */ +void prep_planes(int etus, natid natnum) { + int mil, i; + double mil_pay; struct plnstr *pp; - int i; for (i = 0; (pp = getplanep(i)); i++) { if (pp->pln_own == 0) @@ -68,6 +67,26 @@ prod_plane(int etus, int natnum, struct bp *bp, int buildem) continue; } + mil = plchr[pp->pln_type].pl_mat[I_MILIT]; + /* flight pay is 5x the pay received by other military */ + mil_pay = mil * etus * money_mil * 5; + nat_budget[natnum].bm[BUDG_PLN_MAINT].money += mil_pay; + nat_budget[natnum].money += mil_pay; + } +} + +void +prod_plane(int etus, int natnum, struct bp *bp, int buildem) + /* Build = 1, maintain =0 */ +{ + struct plnstr *pp; + int i; + + for (i = 0; (pp = getplanep(i)); i++) { + if (pp->pln_own == 0) + continue; + if (pp->pln_own != natnum) + continue; upd_plane(pp, etus, bp, buildem); } } @@ -105,10 +124,6 @@ upd_plane(struct plnstr *pp, int etus, struct bp *bp, int build) budget->bm[BUDG_PLN_MAINT].money -= cost; budget->money -= cost; } - /* flight pay is 5x the pay received by other military */ - cost = etus * pcp->pl_mat[I_MILIT] * -money_mil * 5; - budget->bm[BUDG_PLN_MAINT].money -= cost; - budget->money -= cost; if (pln_is_in_orbit(pp) && !(pp->pln_flags & PLN_SYNCHRONOUS)) { if (!player->simulation) diff --git a/src/lib/update/prepare.c b/src/lib/update/prepare.c index 3ce126c3..e7c6603e 100644 --- a/src/lib/update/prepare.c +++ b/src/lib/update/prepare.c @@ -38,19 +38,16 @@ #include "chance.h" #include "file.h" #include "item.h" -#include "land.h" #include "nat.h" #include "optlist.h" #include "player.h" #include "prototypes.h" -#include "ship.h" #include "update.h" void prepare_sects(int etu) { struct sctstr *sp; - struct natstr *np; int n; /* Process all the fallout. */ @@ -96,10 +93,6 @@ prepare_sects(int etu) if (sp->sct_type == SCT_BANK) bank_income(sp, etu); } - for (n = 0; NULL != (np = getnatp(n)); n++) { - upd_slmilcosts(etu, np->nat_cnum); - pay_reserve(np, etu); - } } void @@ -128,34 +121,6 @@ tax(struct sctstr *sp, int etu) budget->money += mil_pay; } -void -upd_slmilcosts(int etu, natid n) -{ - struct shpstr *sp; - struct lndstr *lp; - int mil, i; - double mil_pay; - - mil = 0; - - for (i = 0; (sp = getshipp(i)); i++) { - if (!sp->shp_own || sp->shp_own != n) - continue; - mil += sp->shp_item[I_MILIT]; - } - - for (i = 0; (lp = getlandp(i)); i++) { - if (!lp->lnd_own || lp->lnd_own != n) - continue; - mil += lp->lnd_item[I_MILIT]; - } - - mil_pay = mil * etu * money_mil; - nat_budget[n].mil.count += mil; - nat_budget[n].mil.money += mil_pay; - nat_budget[n].money += mil_pay; -} - void bank_income(struct sctstr *sp, int etu) { diff --git a/src/lib/update/ship.c b/src/lib/update/ship.c index 54bb5fb8..2315c761 100644 --- a/src/lib/update/ship.c +++ b/src/lib/update/ship.c @@ -57,6 +57,32 @@ static void shiprepair(struct shpstr *, struct natstr *, struct bp *, static void ship_produce(struct shpstr *, int, struct budget *); static int feed_ship(struct shpstr *, int); +void prep_ships(int etus, natid natnum) +{ + int mil, i; + double mil_pay; + struct shpstr *sp; + + for (i = 0; (sp = getshipp(i)); i++) { + if (sp->shp_own == 0) + continue; + if (sp->shp_own != natnum) + continue; + if (CANT_HAPPEN(sp->shp_effic < SHIP_MINEFF)) { + makelost(EF_SHIP, sp->shp_own, sp->shp_uid, + sp->shp_x, sp->shp_y); + sp->shp_own = 0; + continue; + } + + mil = sp->shp_item[I_MILIT]; + mil_pay = mil * etus * money_mil; + nat_budget[natnum].mil.count += mil; + nat_budget[natnum].mil.money += mil_pay; + nat_budget[natnum].money += mil_pay; + } +} + void prod_ship(int etus, int natnum, struct bp *bp, int build) /* build = 1, maintain = 0 */ @@ -69,13 +95,6 @@ prod_ship(int etus, int natnum, struct bp *bp, int build) continue; if (sp->shp_own != natnum) continue; - if (sp->shp_effic < SHIP_MINEFF) { - makelost(EF_SHIP, sp->shp_own, sp->shp_uid, - sp->shp_x, sp->shp_y); - sp->shp_own = 0; - continue; - } - upd_ship(sp, etus, bp, build); } }