/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2017, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
#include <config.h>
#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"
+static void tax(struct sctstr *, int);
+static void bank_income(struct sctstr *, int);
+
void
-prepare_sects(int etu)
+prepare_sects(int etu, struct bp *bp)
{
- struct sctstr *sp;
- struct natstr *np;
+ struct sctstr *sp, scratch_sect;
int n;
- memset(levels, 0, sizeof(levels));
+ if (!player->simulation)
+ fallout(etu);
-/* Process all the fallout. */
- if (opt_FALLOUT) {
- if (!player->simulation) {
- /* First, we determine which sectors to process fallout in */
- for (n = 0; NULL != (sp = getsectid(n)); n++)
- sp->sct_updated = sp->sct_fallout != 0;
- /* Next, we process the fallout there */
- for (n = 0; NULL != (sp = getsectid(n)); n++)
- if (sp->sct_updated)
- do_fallout(sp, etu);
- /* Next, we spread the fallout */
- for (n = 0; NULL != (sp = getsectid(n)); n++)
- if (sp->sct_updated)
- spread_fallout(sp, etu);
- /* Next, we decay the fallout */
- for (n = 0; NULL != (sp = getsectid(n)); n++)
- if (sp->sct_fallout)
- decay_fallout(sp, etu);
- }
- }
for (n = 0; NULL != (sp = getsectid(n)); n++) {
- sp->sct_updated = 0;
-
- if (sp->sct_type == SCT_WATER)
+ if (bp_skip_sect(bp, sp))
continue;
- if (getnatp(sp->sct_own)->nat_stat == STAT_SANCT)
+ bp_set_from_sect(bp, sp);
+ if (sp->sct_type == SCT_WATER || sp->sct_type == SCT_SANCT)
continue;
/*
if (running_test_suite)
seed_prng(sp->sct_uid);
- guerrilla(sp);
- do_plague(sp, etu);
- populace(sp, etu);
- tax(sp, etu, &pops[sp->sct_own]);
- 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);
- np->nat_money += nat_budget[n].mil.money;
- np->nat_money += nat_budget[n].civ.money;
- np->nat_money += nat_budget[n].uw.money;
- np->nat_money += nat_budget[n].bars.money;
+ if (player->simulation) {
+ /* work on a copy, which will be discarded */
+ scratch_sect = *sp;
+ sp = &scratch_sect;
+ }
+
+ if (!player->simulation) {
+ guerrilla(sp);
+ populace(sp, etu);
+ }
+ tax(sp, etu);
+ 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);
}
}
-void
-tax(struct sctstr *sp, int etu, int *pop)
+static void
+tax(struct sctstr *sp, int etu)
{
struct budget *budget = &nat_budget[sp->sct_own];
- int civ_tax, uw_tax, mil_pay;
-
- civ_tax = (int)(0.5 + sp->sct_item[I_CIVIL] * sp->sct_effic *
- etu * money_civ / 100);
- /*
- * captured civs only pay 1/4 taxes
- */
- if (sp->sct_own != sp->sct_oldown)
- civ_tax /= 4;
+ double civ_tax, uw_tax, mil_pay;
+
+ civ_tax = sp->sct_item[I_CIVIL] * etu * money_civ * sp->sct_effic / 100;
+ if (sp->sct_own == sp->sct_oldown)
+ budget->oldowned_civs += sp->sct_item[I_CIVIL];
+ else
+ civ_tax /= 4; /* captured civs pay less */
budget->civ.count += sp->sct_item[I_CIVIL];
budget->civ.money += civ_tax;
+ budget->money += civ_tax;
- uw_tax = (int)(0.5 + sp->sct_item[I_UW] * sp->sct_effic *
- etu * money_uw / 100);
+ uw_tax = sp->sct_item[I_UW] * etu * money_uw * sp->sct_effic / 100;
budget->uw.count += sp->sct_item[I_UW];
budget->uw.money += uw_tax;
+ budget->money += uw_tax;
mil_pay = sp->sct_item[I_MILIT] * etu * money_mil;
budget->mil.count += sp->sct_item[I_MILIT];
budget->mil.money += mil_pay;
-
- /*
- * only non-captured civs add to census for nation
- */
- if (sp->sct_oldown == sp->sct_own)
- *pop += sp->sct_item[I_CIVIL];
-}
-
-void
-upd_slmilcosts(int etu, natid n)
-{
- struct shpstr *sp;
- struct lndstr *lp;
- int mil, i;
-
- 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];
- }
-
- nat_budget[n].mil.count += mil;
- nat_budget[n].mil.money += mil * etu * money_mil;
+ budget->money += mil_pay;
}
-void
+static void
bank_income(struct sctstr *sp, int etu)
{
- int inc;
+ double income;
+
+ if (sp->sct_type != SCT_BANK)
+ return;
- inc = (int)(sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100);
+ income = sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100;
nat_budget[sp->sct_own].bars.count += sp->sct_item[I_BAR];
- nat_budget[sp->sct_own].bars.money += inc;
+ nat_budget[sp->sct_own].bars.money += income;
+ nat_budget[sp->sct_own].money += income;
}
void
pay_reserve(struct natstr *np, int etu)
{
- nat_budget[np->nat_cnum].mil.money
- += (int)(np->nat_reserve * money_res * etu);
+ double pay = np->nat_reserve * money_res * etu;
+
+ nat_budget[np->nat_cnum].mil.money += pay;
+ nat_budget[np->nat_cnum].money += pay;
}