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 <armbru@pond.sub.org>
This commit is contained in:
parent
7951e91e3f
commit
5df43a5b3f
7 changed files with 88 additions and 59 deletions
|
@ -98,6 +98,7 @@ extern int feed_people(short *, int);
|
||||||
extern double food_needed(short *, int);
|
extern double food_needed(short *, int);
|
||||||
extern int famine_victims(short *, int);
|
extern int famine_victims(short *, int);
|
||||||
/* land.c */
|
/* land.c */
|
||||||
|
extern void prep_lands(int, natid);
|
||||||
extern void prod_land(int, int, struct bp *, int);
|
extern void prod_land(int, int, struct bp *, int);
|
||||||
/* main.c */
|
/* main.c */
|
||||||
/* in server.h */
|
/* 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 int plague_people(struct natstr *, short *, int *, int *, int);
|
||||||
extern void plague_report(natid, int, int, int, int, char *, char *);
|
extern void plague_report(natid, int, int, int, int, char *, char *);
|
||||||
/* plane.c */
|
/* plane.c */
|
||||||
|
extern void prep_planes(int, natid);
|
||||||
extern void prod_plane(int, int, struct bp *, int);
|
extern void prod_plane(int, int, struct bp *, int);
|
||||||
/* populace.c */
|
/* populace.c */
|
||||||
extern void populace(struct sctstr *, int);
|
extern void populace(struct sctstr *, int);
|
||||||
|
@ -128,7 +130,6 @@ extern int total_work(int, int, int, int, int, int);
|
||||||
/* prepare.c */
|
/* prepare.c */
|
||||||
extern void prepare_sects(int);
|
extern void prepare_sects(int);
|
||||||
extern void tax(struct sctstr *, int);
|
extern void tax(struct sctstr *, int);
|
||||||
extern void upd_slmilcosts(int, natid);
|
|
||||||
extern void bank_income(struct sctstr *, int);
|
extern void bank_income(struct sctstr *, int);
|
||||||
extern void pay_reserve(struct natstr *, int);
|
extern void pay_reserve(struct natstr *, int);
|
||||||
/* produce.c */
|
/* produce.c */
|
||||||
|
@ -149,6 +150,7 @@ extern void spread_fallout(struct sctstr *, int);
|
||||||
extern void decay_fallout(struct sctstr *, int);
|
extern void decay_fallout(struct sctstr *, int);
|
||||||
extern void produce_sect(struct natstr *, int, struct bp *);
|
extern void produce_sect(struct natstr *, int, struct bp *);
|
||||||
/* ship.c */
|
/* ship.c */
|
||||||
|
extern void prep_ships(int, natid);
|
||||||
extern void prod_ship(int, int, struct bp *, int);
|
extern void prod_ship(int, int, struct bp *, int);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -163,7 +163,9 @@ calc_all(void)
|
||||||
bank_income(sp, etu);
|
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);
|
pay_reserve(np, etu);
|
||||||
|
|
||||||
/* Maintain ships, planes and land units */
|
/* Maintain ships, planes and land units */
|
||||||
|
|
|
@ -54,6 +54,32 @@ static void landrepair(struct lndstr *, struct natstr *, struct bp *,
|
||||||
int, struct budget *);
|
int, struct budget *);
|
||||||
static int feed_land(struct lndstr *, int);
|
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
|
void
|
||||||
prod_land(int etus, int natnum, struct bp *bp, int build)
|
prod_land(int etus, int natnum, struct bp *bp, int build)
|
||||||
/* build = 1, maintain = 0 */
|
/* build = 1, maintain = 0 */
|
||||||
|
@ -67,13 +93,6 @@ prod_land(int etus, int natnum, struct bp *bp, int build)
|
||||||
continue;
|
continue;
|
||||||
if (lp->lnd_own != natnum)
|
if (lp->lnd_own != natnum)
|
||||||
continue;
|
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);
|
sp = getsectp(lp->lnd_x, lp->lnd_y);
|
||||||
if (sp->sct_type == SCT_SANCT)
|
if (sp->sct_type == SCT_SANCT)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -94,6 +94,13 @@ update_main(void)
|
||||||
logerror("preparing sectors...");
|
logerror("preparing sectors...");
|
||||||
prepare_sects(etu);
|
prepare_sects(etu);
|
||||||
logerror("done preparing sectors.");
|
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...");
|
logerror("producing for countries...");
|
||||||
for (i = 0; i < MAXNOC; i++) {
|
for (i = 0; i < MAXNOC; i++) {
|
||||||
if (!(np = getnatp(i)))
|
if (!(np = getnatp(i)))
|
||||||
|
|
|
@ -49,12 +49,11 @@ static void upd_plane(struct plnstr *, int, struct bp *, int);
|
||||||
static void planerepair(struct plnstr *, struct natstr *, struct bp *,
|
static void planerepair(struct plnstr *, struct natstr *, struct bp *,
|
||||||
int, struct budget *);
|
int, struct budget *);
|
||||||
|
|
||||||
void
|
void prep_planes(int etus, natid natnum)
|
||||||
prod_plane(int etus, int natnum, struct bp *bp, int buildem)
|
|
||||||
/* Build = 1, maintain =0 */
|
|
||||||
{
|
{
|
||||||
|
int mil, i;
|
||||||
|
double mil_pay;
|
||||||
struct plnstr *pp;
|
struct plnstr *pp;
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; (pp = getplanep(i)); i++) {
|
for (i = 0; (pp = getplanep(i)); i++) {
|
||||||
if (pp->pln_own == 0)
|
if (pp->pln_own == 0)
|
||||||
|
@ -68,6 +67,26 @@ prod_plane(int etus, int natnum, struct bp *bp, int buildem)
|
||||||
continue;
|
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);
|
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->bm[BUDG_PLN_MAINT].money -= cost;
|
||||||
budget->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 (pln_is_in_orbit(pp) && !(pp->pln_flags & PLN_SYNCHRONOUS)) {
|
||||||
if (!player->simulation)
|
if (!player->simulation)
|
||||||
|
|
|
@ -38,19 +38,16 @@
|
||||||
#include "chance.h"
|
#include "chance.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "land.h"
|
|
||||||
#include "nat.h"
|
#include "nat.h"
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "ship.h"
|
|
||||||
#include "update.h"
|
#include "update.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
prepare_sects(int etu)
|
prepare_sects(int etu)
|
||||||
{
|
{
|
||||||
struct sctstr *sp;
|
struct sctstr *sp;
|
||||||
struct natstr *np;
|
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
/* Process all the fallout. */
|
/* Process all the fallout. */
|
||||||
|
@ -96,10 +93,6 @@ prepare_sects(int etu)
|
||||||
if (sp->sct_type == SCT_BANK)
|
if (sp->sct_type == SCT_BANK)
|
||||||
bank_income(sp, etu);
|
bank_income(sp, etu);
|
||||||
}
|
}
|
||||||
for (n = 0; NULL != (np = getnatp(n)); n++) {
|
|
||||||
upd_slmilcosts(etu, np->nat_cnum);
|
|
||||||
pay_reserve(np, etu);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -128,34 +121,6 @@ tax(struct sctstr *sp, int etu)
|
||||||
budget->money += mil_pay;
|
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
|
void
|
||||||
bank_income(struct sctstr *sp, int etu)
|
bank_income(struct sctstr *sp, int etu)
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,6 +57,32 @@ static void shiprepair(struct shpstr *, struct natstr *, struct bp *,
|
||||||
static void ship_produce(struct shpstr *, int, struct budget *);
|
static void ship_produce(struct shpstr *, int, struct budget *);
|
||||||
static int feed_ship(struct shpstr *, int);
|
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
|
void
|
||||||
prod_ship(int etus, int natnum, struct bp *bp, int build)
|
prod_ship(int etus, int natnum, struct bp *bp, int build)
|
||||||
/* build = 1, maintain = 0 */
|
/* build = 1, maintain = 0 */
|
||||||
|
@ -69,13 +95,6 @@ prod_ship(int etus, int natnum, struct bp *bp, int build)
|
||||||
continue;
|
continue;
|
||||||
if (sp->shp_own != natnum)
|
if (sp->shp_own != natnum)
|
||||||
continue;
|
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);
|
upd_ship(sp, etus, bp, build);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue