budget: Track ship, plane, land unit expenses in nat_budget[]
Extend struct budget member bm[] to cover ships, planes and land units, too. Plane maintenance changes because pilot pay is now consistently rounded down. Before it was rounded down for broke countries, else up. The stock game's pilots earn a little less than $25, and solvent countries save $1 per plane. The rounding doesn't make much sense either way. To be be addressed in a later commit. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
16f9a393c4
commit
2eb08f40c7
10 changed files with 148 additions and 143 deletions
|
@ -48,21 +48,22 @@
|
|||
#include "prototypes.h"
|
||||
#include "update.h"
|
||||
|
||||
static void landrepair(struct lndstr *, struct natstr *, struct bp *, int);
|
||||
static void upd_land(struct lndstr *, int, struct natstr *, struct bp *, int);
|
||||
static void landrepair(struct lndstr *, struct natstr *, struct bp *,
|
||||
int, struct budget *);
|
||||
static int feed_land(struct lndstr *, int);
|
||||
|
||||
int
|
||||
void
|
||||
prod_land(int etus, int natnum, struct bp *bp, int build)
|
||||
/* build = 1, maintain = 0 */
|
||||
{
|
||||
struct lndstr *lp;
|
||||
struct sctstr *sp;
|
||||
struct natstr *np;
|
||||
int n, k = 0;
|
||||
int i;
|
||||
int start_money;
|
||||
|
||||
for (n = 0; NULL != (lp = getlandp(n)); n++) {
|
||||
for (i = 0; (lp = getlandp(i)); i++) {
|
||||
if (lp->lnd_own == 0)
|
||||
continue;
|
||||
if (lp->lnd_own != natnum)
|
||||
|
@ -80,14 +81,9 @@ prod_land(int etus, int natnum, struct bp *bp, int build)
|
|||
np = getnatp(lp->lnd_own);
|
||||
start_money = np->nat_money;
|
||||
upd_land(lp, etus, np, bp, build);
|
||||
lnd_money[lp->lnd_own] += np->nat_money - start_money;
|
||||
if (!build || np->nat_money != start_money)
|
||||
k++;
|
||||
if (player->simulation)
|
||||
np->nat_money = start_money;
|
||||
}
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -95,6 +91,7 @@ upd_land(struct lndstr *lp, int etus,
|
|||
struct natstr *np, struct bp *bp, int build)
|
||||
/* build = 1, maintain = 0 */
|
||||
{
|
||||
struct budget *budget = &nat_budget[lp->lnd_own];
|
||||
struct lchrstr *lcp;
|
||||
int pstage, ptime;
|
||||
int min = morale_base - (int)np->nat_level[NAT_HLEV];
|
||||
|
@ -107,7 +104,7 @@ upd_land(struct lndstr *lp, int etus,
|
|||
lcp = &lchr[(int)lp->lnd_type];
|
||||
if (build == 1) {
|
||||
if (!lp->lnd_off && np->nat_money >= 0)
|
||||
landrepair(lp, np, bp, etus);
|
||||
landrepair(lp, np, bp, etus, budget);
|
||||
if (!player->simulation)
|
||||
lp->lnd_off = 0;
|
||||
} else {
|
||||
|
@ -116,6 +113,7 @@ upd_land(struct lndstr *lp, int etus,
|
|||
mult = 2;
|
||||
if (lcp->l_flags & L_ENGINEER)
|
||||
mult *= 3;
|
||||
budget->bm[BUDG_LND_MAINT].count++;
|
||||
cost = -(mult * etus * MIN(0.0, money_land * lcp->l_cost));
|
||||
if (np->nat_money < cost && !player->simulation) {
|
||||
eff_lost = etus / 5;
|
||||
|
@ -127,6 +125,7 @@ upd_land(struct lndstr *lp, int etus,
|
|||
lp->lnd_effic -= eff_lost;
|
||||
}
|
||||
} else {
|
||||
budget->bm[BUDG_LND_MAINT].money -= cost;
|
||||
np->nat_money -= cost;
|
||||
}
|
||||
|
||||
|
@ -195,7 +194,8 @@ upd_land(struct lndstr *lp, int etus,
|
|||
}
|
||||
|
||||
static void
|
||||
landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
|
||||
landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus,
|
||||
struct budget *budget)
|
||||
{
|
||||
struct lchrstr *lp = &lchr[(int)land->lnd_type];
|
||||
int delta;
|
||||
|
@ -203,6 +203,7 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
|
|||
int build;
|
||||
int avail;
|
||||
int mult;
|
||||
int cost;
|
||||
|
||||
if (land->lnd_effic == 100)
|
||||
return;
|
||||
|
@ -245,10 +246,12 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
|
|||
sp->sct_avail = avail;
|
||||
|
||||
bp_set_from_sect(bp, sp);
|
||||
np->nat_money -= roundavg(mult * lp->l_cost * build / 100.0);
|
||||
if (!player->simulation) {
|
||||
cost = roundavg(mult * lp->l_cost * build / 100.0);
|
||||
budget->bm[BUDG_LND_BUILD].count += !!build;
|
||||
budget->bm[BUDG_LND_BUILD].money -= cost;
|
||||
np->nat_money -= cost;
|
||||
if (!player->simulation)
|
||||
land->lnd_effic += (signed char)build;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -123,6 +123,12 @@ update_main(void)
|
|||
prod_ship(etu, i, NULL, 1);
|
||||
prod_plane(etu, i, NULL, 1);
|
||||
prod_land(etu, i, NULL, 1);
|
||||
sea_money[i] += nat_budget[i].bm[BUDG_SHP_MAINT].money
|
||||
+ nat_budget[i].bm[BUDG_SHP_BUILD].money;
|
||||
air_money[i] += nat_budget[i].bm[BUDG_PLN_MAINT].money
|
||||
+ nat_budget[i].bm[BUDG_PLN_BUILD].money;
|
||||
lnd_money[i] += nat_budget[i].bm[BUDG_LND_MAINT].money
|
||||
+ nat_budget[i].bm[BUDG_LND_BUILD].money;
|
||||
}
|
||||
logerror("done producing for countries.");
|
||||
|
||||
|
|
|
@ -45,19 +45,20 @@
|
|||
#include "ship.h"
|
||||
#include "update.h"
|
||||
|
||||
static void planerepair(struct plnstr *, struct natstr *, struct bp *, int);
|
||||
static void upd_plane(struct plnstr *, int, struct natstr *, struct bp *, int);
|
||||
static void planerepair(struct plnstr *, struct natstr *, struct bp *,
|
||||
int, struct budget *);
|
||||
|
||||
int
|
||||
void
|
||||
prod_plane(int etus, int natnum, struct bp *bp, int buildem)
|
||||
/* Build = 1, maintain =0 */
|
||||
{
|
||||
struct plnstr *pp;
|
||||
struct natstr *np;
|
||||
int n, k = 0;
|
||||
int i;
|
||||
int start_money;
|
||||
|
||||
for (n = 0; NULL != (pp = getplanep(n)); n++) {
|
||||
for (i = 0; (pp = getplanep(i)); i++) {
|
||||
if (pp->pln_own == 0)
|
||||
continue;
|
||||
if (pp->pln_own != natnum)
|
||||
|
@ -79,32 +80,29 @@ prod_plane(int etus, int natnum, struct bp *bp, int buildem)
|
|||
np = getnatp(pp->pln_own);
|
||||
start_money = np->nat_money;
|
||||
upd_plane(pp, etus, np, bp, buildem);
|
||||
air_money[pp->pln_own] += np->nat_money - start_money;
|
||||
if (buildem == 0 || np->nat_money != start_money)
|
||||
k++;
|
||||
if (player->simulation)
|
||||
np->nat_money = start_money;
|
||||
}
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
static void
|
||||
upd_plane(struct plnstr *pp, int etus,
|
||||
struct natstr *np, struct bp *bp, int build)
|
||||
{
|
||||
struct budget *budget = &nat_budget[pp->pln_own];
|
||||
struct plchrstr *pcp = &plchr[(int)pp->pln_type];
|
||||
int mult, cost, eff_lost;
|
||||
|
||||
if (build == 1) {
|
||||
if (!pp->pln_off && np->nat_money >= 0)
|
||||
planerepair(pp, np, bp, etus);
|
||||
planerepair(pp, np, bp, etus, budget);
|
||||
if (!player->simulation)
|
||||
pp->pln_off = 0;
|
||||
} else {
|
||||
mult = 1;
|
||||
if (np->nat_level[NAT_TLEV] < pp->pln_tech * 0.85)
|
||||
mult = 2;
|
||||
budget->bm[BUDG_PLN_MAINT].count++;
|
||||
cost = -(mult * etus * MIN(0.0, pcp->pl_cost * money_plane));
|
||||
if (np->nat_money < cost && !player->simulation) {
|
||||
eff_lost = etus / 5;
|
||||
|
@ -116,15 +114,19 @@ upd_plane(struct plnstr *pp, int etus,
|
|||
pp->pln_effic -= eff_lost;
|
||||
}
|
||||
} else {
|
||||
budget->bm[BUDG_PLN_MAINT].money -= cost;
|
||||
np->nat_money -= cost;
|
||||
}
|
||||
/* flight pay is 5x the pay received by other military */
|
||||
np->nat_money += etus * pcp->pl_mat[I_MILIT] * money_mil * 5;
|
||||
cost = etus * pcp->pl_mat[I_MILIT] * -money_mil * 5;
|
||||
budget->bm[BUDG_PLN_MAINT].money -= cost;
|
||||
np->nat_money -= cost;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus)
|
||||
planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus,
|
||||
struct budget *budget)
|
||||
{
|
||||
struct plchrstr *pcp = &plchr[(int)pp->pln_type];
|
||||
int build;
|
||||
|
@ -134,6 +136,7 @@ planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus)
|
|||
int mult;
|
||||
int avail;
|
||||
int used;
|
||||
int cost;
|
||||
|
||||
if (pp->pln_effic == 100)
|
||||
return;
|
||||
|
@ -199,8 +202,11 @@ planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus)
|
|||
}
|
||||
|
||||
bp_set_from_sect(bp, sp);
|
||||
np->nat_money -= roundavg(mult * build * pcp->pl_cost / 100.0);
|
||||
|
||||
if (!player->simulation)
|
||||
cost = roundavg(mult * build * pcp->pl_cost / 100.0);
|
||||
budget->bm[BUDG_PLN_BUILD].count += !!build;
|
||||
budget->bm[BUDG_PLN_BUILD].money -= cost;
|
||||
np->nat_money -= cost;
|
||||
if (!player->simulation) {
|
||||
pp->pln_effic += (signed char)build;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,20 +50,21 @@
|
|||
#include "ship.h"
|
||||
#include "update.h"
|
||||
|
||||
static void shiprepair(struct shpstr *, struct natstr *, struct bp *, int);
|
||||
static void upd_ship(struct shpstr *, int, struct natstr *, struct bp *, int);
|
||||
static void shiprepair(struct shpstr *, struct natstr *, struct bp *,
|
||||
int, struct budget *);
|
||||
static int feed_ship(struct shpstr *, int);
|
||||
|
||||
int
|
||||
void
|
||||
prod_ship(int etus, int natnum, struct bp *bp, int build)
|
||||
/* build = 1, maintain = 0 */
|
||||
{
|
||||
struct shpstr *sp;
|
||||
struct natstr *np;
|
||||
int n, k = 0;
|
||||
int i;
|
||||
int start_money;
|
||||
|
||||
for (n = 0; NULL != (sp = getshipp(n)); n++) {
|
||||
for (i = 0; (sp = getshipp(i)); i++) {
|
||||
if (sp->shp_own == 0)
|
||||
continue;
|
||||
if (sp->shp_own != natnum)
|
||||
|
@ -78,14 +79,9 @@ prod_ship(int etus, int natnum, struct bp *bp, int build)
|
|||
np = getnatp(sp->shp_own);
|
||||
start_money = np->nat_money;
|
||||
upd_ship(sp, etus, np, bp, build);
|
||||
sea_money[sp->shp_own] += np->nat_money - start_money;
|
||||
if (!build || np->nat_money != start_money)
|
||||
k++;
|
||||
if (player->simulation)
|
||||
np->nat_money = start_money;
|
||||
}
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -93,6 +89,7 @@ upd_ship(struct shpstr *sp, int etus,
|
|||
struct natstr *np, struct bp *bp, int build)
|
||||
/* build = 1, maintain = 0 */
|
||||
{
|
||||
struct budget *budget = &nat_budget[sp->shp_own];
|
||||
struct sctstr *sectp;
|
||||
struct mchrstr *mp;
|
||||
int pstage, ptime;
|
||||
|
@ -107,13 +104,14 @@ upd_ship(struct shpstr *sp, int etus,
|
|||
mp = &mchr[(int)sp->shp_type];
|
||||
if (build == 1) {
|
||||
if (!sp->shp_off && np->nat_money >= 0)
|
||||
shiprepair(sp, np, bp, etus);
|
||||
shiprepair(sp, np, bp, etus, budget);
|
||||
if (!player->simulation)
|
||||
sp->shp_off = 0;
|
||||
} else {
|
||||
mult = 1;
|
||||
if (np->nat_level[NAT_TLEV] < sp->shp_tech * 0.85)
|
||||
mult = 2;
|
||||
budget->bm[BUDG_SHP_MAINT].count++;
|
||||
cost = -(mult * etus * MIN(0.0, money_ship * mp->m_cost));
|
||||
if (np->nat_money < cost && !player->simulation) {
|
||||
eff_lost = etus / 5;
|
||||
|
@ -125,6 +123,7 @@ upd_ship(struct shpstr *sp, int etus,
|
|||
sp->shp_effic -= eff_lost;
|
||||
}
|
||||
} else {
|
||||
budget->bm[BUDG_SHP_MAINT].money -= cost;
|
||||
np->nat_money -= cost;
|
||||
}
|
||||
|
||||
|
@ -242,7 +241,8 @@ upd_ship(struct shpstr *sp, int etus,
|
|||
* 8 * 8 * $40 = $2560!
|
||||
*/
|
||||
static void
|
||||
shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
|
||||
shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus,
|
||||
struct budget *budget)
|
||||
{
|
||||
struct mchrstr *mp = &mchr[(int)ship->shp_type];
|
||||
int delta;
|
||||
|
@ -251,6 +251,7 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
|
|||
int wf;
|
||||
int avail;
|
||||
int mult;
|
||||
int cost;
|
||||
|
||||
if (ship->shp_effic == 100)
|
||||
return;
|
||||
|
@ -313,7 +314,10 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
|
|||
}
|
||||
|
||||
bp_set_from_sect(bp, sp);
|
||||
np->nat_money -= roundavg(mult * mp->m_cost * build / 100.0);
|
||||
cost = roundavg(mult * mp->m_cost * build / 100.0);
|
||||
budget->bm[BUDG_SHP_BUILD].count += !!build;
|
||||
budget->bm[BUDG_SHP_BUILD].money -= cost;
|
||||
np->nat_money -= cost;
|
||||
if (!player->simulation)
|
||||
ship->shp_effic += (signed char)build;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue