]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/land.c
Update copyright notice
[empserver] / src / lib / update / land.c
index 0bb5c00ebea11630d1b9ab7b9fc9534f07ce327c..96b309770fe1491d689ad9b57cc8f9684b7d9f32 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 <math.h>
-#include "budg.h"
 #include "chance.h"
-#include "file.h"
 #include "land.h"
 #include "lost.h"
 #include "nat.h"
 #include "plague.h"
 #include "player.h"
 #include "prototypes.h"
-#include "sect.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 int feed_land(struct lndstr *, int);
+static void upd_land(struct lndstr *, int, struct bp *, int);
+static void plague_land(struct lndstr *, int);
+static void landrepair(struct lndstr *, struct natstr *, struct bp *,
+                      int, struct budget *);
 
-int
-prod_land(int etus, int natnum, struct bp *bp, int build)
-               /* build = 1, maintain = 0 */
+void prep_lands(int etus, struct bp *bp)
 {
+    int mil, i, n;
+    double mil_pay;
     struct lndstr *lp;
-    struct sctstr *sp;
-    struct natstr *np;
-    int n, k = 0;
-    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)
-           continue;
-       if (lp->lnd_effic < LAND_MINEFF) {
+       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;
        }
 
-       sp = getsectp(lp->lnd_x, lp->lnd_y);
-       if (sp->sct_type == SCT_SANCT)
-           continue;
-       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;
+       bp_consider_unit(bp, (struct empobj *)lp);
+       mil = lp->lnd_item[I_MILIT];
+       mil_pay = mil * etus * money_mil;
+       nat_budget[lp->lnd_own].mil.count += mil;
+       nat_budget[lp->lnd_own].mil.money += mil_pay;
+       nat_budget[lp->lnd_own].money += mil_pay;
+
+       if (!player->simulation) {
+           if ((n = feed_people(lp->lnd_item, etus)) > 0) {
+               wu(0, lp->lnd_own, "%d starved in %s\n", n, prland(lp));
+               if (n > 10)
+                   nreport(lp->lnd_own, N_DIE_FAMINE, 0, 1);
+           }
+           plague_land(lp, etus);
+       }
     }
+}
+
+void
+prod_land(int etus, struct bp *bp, int build)
+               /* build = 1, maintain = 0 */
+{
+    struct lndstr *lp;
+    int i;
 
-    return k;
+    for (i = 0; (lp = getlandp(i)); i++) {
+       if (lp->lnd_own == 0)
+           continue;
+       if (bp_skip_unit(bp, (struct empobj *)lp))
+           continue;
+       upd_land(lp, etus, bp, build);
+    }
 }
 
 static void
-upd_land(struct lndstr *lp, int etus,
-        struct natstr *np, struct bp *bp, int build)
+upd_land(struct lndstr *lp, int etus, struct bp *bp, int build)
               /* build = 1, maintain = 0 */
 {
-    struct lchrstr *lcp;
-    int pstage, ptime;
+    struct budget *budget = &nat_budget[lp->lnd_own];
+    struct lchrstr *lcp = &lchr[lp->lnd_type];
+    struct natstr *np = getnatp(lp->lnd_own);
     int min = morale_base - (int)np->nat_level[NAT_HLEV];
-    int n, mult, cost, eff_lost;
+    int mult, eff_lost;
+    double cost;
 
     if (!player->simulation)
        if (lp->lnd_retreat < min)
            lp->lnd_retreat = min;
 
-    lcp = &lchr[(int)lp->lnd_type];
     if (build == 1) {
-       if (!lp->lnd_off && np->nat_money >= 0)
-           landrepair(lp, np, bp, etus);
+       if (!lp->lnd_off && budget->money >= 0)
+           landrepair(lp, np, bp, etus, budget);
        if (!player->simulation)
            lp->lnd_off = 0;
     } else {
+       budget->oldowned_civs += lp->lnd_item[I_CIVIL];
        mult = 1;
        if (np->nat_level[NAT_TLEV] < lp->lnd_tech * 0.85)
            mult = 2;
        if (lcp->l_flags & L_ENGINEER)
            mult *= 3;
-       cost = -(mult * etus * MIN(0.0, money_land * lcp->l_cost));
-       if (np->nat_money < cost && !player->simulation) {
+       budget->bm[BUDG_LND_MAINT].count++;
+       cost = mult * etus * -money_land * lcp->l_cost;
+       if (budget->money < cost && !player->simulation) {
            eff_lost = etus / 5;
            if (lp->lnd_effic - eff_lost < LAND_MINEFF)
                eff_lost = lp->lnd_effic - LAND_MINEFF;
@@ -128,75 +140,35 @@ upd_land(struct lndstr *lp, int etus,
                lp->lnd_effic -= eff_lost;
            }
        } else {
-           np->nat_money -= cost;
+           budget->bm[BUDG_LND_MAINT].money -= cost;
+           budget->money -= cost;
        }
+    }
+}
 
-       if (!player->simulation) {
-           /* feed */
-           if ((n = feed_land(lp, etus)) > 0) {
-               wu(0, lp->lnd_own, "%d starved in %s%s\n",
-                  n, prland(lp),
-                  (lp->lnd_effic < LAND_MINEFF ? ", killing it" : ""));
-               if (n > 10)
-                   nreport(lp->lnd_own, N_DIE_FAMINE, 0, 1);
-           }
-           /*
-            * do plague stuff.  plague can't break out on land units,
-            * but it can still kill people on them.
-            */
-           pstage = lp->lnd_pstage;
-           ptime = lp->lnd_ptime;
-           if (pstage != PLG_HEALTHY) {
-               n = plague_people(np, lp->lnd_item, &pstage, &ptime, etus);
-               switch (n) {
-               case PLG_DYING:
-                   wu(0, lp->lnd_own,
-                      "PLAGUE deaths reported on %s\n", prland(lp));
-                   nreport(lp->lnd_own, N_DIE_PLAGUE, 0, 1);
-                   break;
-               case PLG_INFECT:
-                   wu(0, lp->lnd_own, "%s battling PLAGUE\n", prland(lp));
-                   break;
-               case PLG_INCUBATE:
-                   /* Are we still incubating? */
-                   if (n == pstage) {
-                       /* Yes. Will it turn "infectious" next time? */
-                       if (ptime <= etus) {
-                           /* Yes.  Report an outbreak. */
-                           wu(0, lp->lnd_own,
-                              "Outbreak of PLAGUE on %s!\n", prland(lp));
-                           nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1);
-                       }
-                   } else {
-                       /* It has already moved on to "infectious" */
-                       wu(0, lp->lnd_own,
-                          "%s battling PLAGUE\n", prland(lp));
-                   }
-                   break;
-               case PLG_EXPOSED:
-                   /* Has the plague moved to "incubation" yet? */
-                   if (n != pstage) {
-                       /* Yes. Will it turn "infectious" next time? */
-                       if (ptime <= etus) {
-                           /* Yes.  Report an outbreak. */
-                           wu(0, lp->lnd_own,
-                              "Outbreak of PLAGUE on %s!\n", prland(lp));
-                           nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1);
-                       }
-                   }
-                   break;
-               default:
-                   break;
-               }
-               lp->lnd_pstage = pstage;
-               lp->lnd_ptime = ptime;
-           }
-       }                       /* end !player->simulation */
+void
+plague_land(struct lndstr *lp, int etus)
+{
+    struct natstr *np = getnatp(lp->lnd_own);
+    int pstage, ptime;
+    int n;
+
+    /* Plague can't break out on land units, but it can still kill people */
+    pstage = lp->lnd_pstage;
+    ptime = lp->lnd_ptime;
+    if (pstage != PLG_HEALTHY) {
+       n = plague_people(np, lp->lnd_item, &pstage, &ptime, etus);
+       if (n != PLG_HEALTHY)
+           plague_report(lp->lnd_own, n, pstage, ptime, etus,
+                         "on", prland(lp));
+       lp->lnd_pstage = pstage;
+       lp->lnd_ptime = ptime;
     }
 }
 
 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;
@@ -204,6 +176,7 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
     int build;
     int avail;
     int mult;
+    double cost;
 
     if (land->lnd_effic == 100)
        return;
@@ -246,17 +219,10 @@ 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 = mult * lp->l_cost * build / 100.0;
+    budget->bm[BUDG_LND_BUILD].count += !!build;
+    budget->bm[BUDG_LND_BUILD].money -= cost;
+    budget->money -= cost;
+    if (!player->simulation)
        land->lnd_effic += (signed char)build;
-    }
-}
-
-/*
- * returns the number who starved, if any.
- */
-static int
-feed_land(struct lndstr *lp, int etus)
-{
-    return feed_people(lp->lnd_item, etus);
 }