/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2017, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
* ---
*
* prepare.c: Perform prelimiary updates of sectors
- *
+ *
* Known contributors to this file:
* Dave Pare, 1986
* Thomas Ruschak, 1992
* Steve McClure, 1997
+ * Markus Armbruster, 2016
*/
#include <config.h>
-#include "budg.h"
+#include "chance.h"
#include "item.h"
-#include "land.h"
-#include "path.h"
+#include "nat.h"
+#include "optlist.h"
#include "player.h"
-#include "ship.h"
+#include "prototypes.h"
#include "update.h"
+static void tax(struct sctstr *, int);
+static void bank_income(struct sctstr *, int);
+
void
-prepare_sects(int etu, int *bp)
+prepare_sects(int etu, struct bp *bp)
{
- struct sctstr *sp;
- struct natstr *np;
- int n, civ_tax, uw_tax, mil_pay;
+ 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;
- fill_update_array(bp, sp);
- np = getnatp(sp->sct_own);
+ bp_set_from_sect(bp, sp);
+ if (sp->sct_type == SCT_WATER || sp->sct_type == SCT_SANCT)
+ continue;
+
+ /*
+ * When running the test suite, reseed PRNG for each sector
+ * with its UID, to keep results stable even when the number
+ * of PRNs consumed changes.
+ */
+ if (running_test_suite)
+ seed_prng(sp->sct_uid);
-#ifdef DEBUG
- if (np->nat_stat == STAT_SANCT)
- logerror("Prepare.c: country in sanctuary skipped production");
-#endif /* DEBUG */
+ if (player->simulation) {
+ /* work on a copy, which will be discarded */
+ scratch_sect = *sp;
+ sp = &scratch_sect;
+ }
- if (np->nat_stat != STAT_SANCT) {
+ if (!player->simulation) {
guerrilla(sp);
- do_plague(sp, np, etu);
- tax(sp, np, etu, &pops[sp->sct_own], &civ_tax, &uw_tax,
- &mil_pay);
- np->nat_money += civ_tax + uw_tax + mil_pay;
- if (sp->sct_type == SCT_BANK)
- np->nat_money += bank_income(sp, etu);
+ populace(sp, etu);
}
- }
- for (n = 0; NULL != (np = getnatp(n)); n++) {
- np->nat_money += upd_slmilcosts(np->nat_cnum, 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, struct natstr *np, int etu, long *pop, int *civ_tax,
- int *uw_tax, int *mil_pay)
+static void
+tax(struct sctstr *sp, int etu)
{
- *civ_tax = 0;
- *uw_tax = 0;
- *mil_pay = 0;
+ struct budget *budget = &nat_budget[sp->sct_own];
+ double civ_tax, uw_tax, mil_pay;
- if (!player->simulation)
- populace(np, sp, etu);
- *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 = *civ_tax / 4;
- *uw_tax = (int)(0.5 + sp->sct_item[I_UW] * sp->sct_effic *
- etu * money_uw / 100);
- *mil_pay = sp->sct_item[I_MILIT] * etu * money_mil;
-
- /*
- * only non-captured civs add to census for nation
- */
- if (sp->sct_oldown == sp->sct_own)
- *pop += sp->sct_item[I_CIVIL];
+ 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 = 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;
+ budget->money += mil_pay;
}
-int
-upd_slmilcosts(natid n, int etu)
+static void
+bank_income(struct sctstr *sp, int etu)
{
- struct shpstr *sp;
- struct lndstr *lp;
- int mil = 0;
- int totalmil = 0;
- int mil_pay = 0;
- int i;
-
- for (i = 0; NULL != (sp = getshipp(i)); i++) {
- if (!sp->shp_own || sp->shp_own != n)
- continue;
- if ((mil = sp->shp_item[I_MILIT]) > 0)
- totalmil += mil;
- }
- for (i = 0; NULL != (lp = getlandp(i)); i++) {
- if (!lp->lnd_own || lp->lnd_own != n)
- continue;
- if ((mil = lp->lnd_item[I_MILIT]) > 0)
- totalmil += mil;
- }
- mil_pay = totalmil * etu * money_mil;
- return mil_pay;
+ double income;
+
+ if (sp->sct_type != SCT_BANK)
+ return;
+
+ 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 += income;
+ nat_budget[sp->sct_own].money += income;
}
-int
-bank_income(struct sctstr *sp, int etu)
+void
+pay_reserve(struct natstr *np, int etu)
{
- return (int)(sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100);
+ double pay = np->nat_reserve * money_res * etu;
+
+ nat_budget[np->nat_cnum].mil.money += pay;
+ nat_budget[np->nat_cnum].money += pay;
}