]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/prepare.c
Update copyright notice
[empserver] / src / lib / update / prepare.c
index 06a2bd9976dea031fd59b2ada28749f8ab42554c..9f88a62f034983af539c7e45b5cf9786c77bd108 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  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;
 
        /*
@@ -91,31 +70,37 @@ prepare_sects(int etu)
        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);
+       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];
     double civ_tax, uw_tax, mil_pay;
 
     civ_tax = sp->sct_item[I_CIVIL] * etu * money_civ * sp->sct_effic / 100;
-    /*
-     * captured civs only pay 1/4 taxes
-     */
-    if (sp->sct_own != sp->sct_oldown)
-       civ_tax /= 4;
+    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;
@@ -129,47 +114,16 @@ tax(struct sctstr *sp, int etu, int *pop)
     budget->mil.count += sp->sct_item[I_MILIT];
     budget->mil.money += mil_pay;
     budget->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;
-    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
+static void
 bank_income(struct sctstr *sp, int etu)
 {
     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;