]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/strv.c
Update copyright notice
[empserver] / src / lib / commands / strv.c
index 75e6bff431c298ee6bc8e0062cfb9043f3ff776e..2248f4f7c3c42a8e72746fd75eda2b51355b2d36 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  star.c: Do a starvation report
- * 
+ *
  *  Known contributors to this file:
- *     
+ *
  */
 
 #include <config.h>
 
-#include "misc.h"
-#include "player.h"
-#include "xy.h"
-#include "sect.h"
-#include "nsc.h"
-#include "nat.h"
-#include "path.h"
-#include "file.h"
+#include <math.h>
+#include "commands.h"
 #include "item.h"
-#include "ship.h"
-#include "optlist.h"
 #include "land.h"
-#include "commands.h"
+#include "optlist.h"
+#include "path.h"
+#include "ship.h"
 
 static void starv_sects(char *range);
 static void starv_ships(char *range);
@@ -94,13 +88,20 @@ starve(void)
     return RET_OK;
 }
 
+static void
+starv_people(short *vec, int victims)
+{
+    pr(" will starve %d people. %.0f more food needed\n", victims,
+       ceil(food_needed(vec, etu_per_update) - vec[I_FOOD]));
+}
+
 static void
 starv_sects(char *range)
 {
     struct nstr_sect nstr;
     struct sctstr sect;
     int nsect = 0;
-    int s, needed;
+    int s, save;
 
     if (!snxtsct(&nstr, range))
        return;
@@ -110,13 +111,20 @@ starv_sects(char *range)
        if (sect.sct_type == SCT_SANCT)
            continue;
 
-/* This next 2 lines were added to overcompensate for the needy */
-       if (sect.sct_item[I_FOOD])
-           sect.sct_item[I_FOOD]--;
-       s = feed_people(sect.sct_item, etu_per_update, &needed);
-
+       /*
+        * Check for starvation.  Suppress complaints about tiny
+        * population without food by adding 1f just for the check.
+        * That's okay because growfood() will grow at least that much
+        * anyway.
+        */
+       save = sect.sct_item[I_FOOD];
+       if (sect.sct_item[I_FOOD] == 0)
+           sect.sct_item[I_FOOD] = 1;
+       s = famine_victims(sect.sct_item, etu_per_update);
+       sect.sct_item[I_FOOD] = save;
        if (s == 0)
            continue;
+
        if (nsect++ == 0)
            sect_hdr();
        if (player->god)
@@ -129,7 +137,7 @@ starv_sects(char *range)
        else
            pr(" ");
        pr("%4d%%", sect.sct_effic);
-       pr(" will starve %d people. %d more food needed\n", s, needed);
+       starv_people(sect.sct_item, s);
     }
     if (nsect == 0) {
        if (player->argp[1])
@@ -160,16 +168,16 @@ starv_ships(char *range)
     struct nstr_item ni;
     struct shpstr ship;
     int nship = 0;
-    int s, needed;
+    int s;
 
-    if (!snxtitem(&ni, EF_SHIP, range))
+    if (!snxtitem(&ni, EF_SHIP, range, NULL))
        return;
 
     while (nxtitem(&ni, &ship)) {
        if (!player->owner || !ship.shp_own)
            continue;
 
-       s = feed_ship(&ship, etu_per_update, &needed, 0);
+       s = famine_victims(ship.shp_item, etu_per_update);
        if (s == 0)
            continue;
        if (nship++ == 0)
@@ -178,7 +186,7 @@ starv_ships(char *range)
            pr("%3d ", ship.shp_own);
        pr("%5d ", ship.shp_uid);
        pr("%-16.16s ", mchr[(int)ship.shp_type].m_name);
-       pr(" will starve %d people. %d more food needed\n", s, needed);
+       starv_people(ship.shp_item, s);
     }
     if (nship == 0) {
        if (range)
@@ -208,16 +216,16 @@ starv_units(char *range)
     struct nstr_item ni;
     struct lndstr land;
     int nunit = 0;
-    int s, needed;
+    int s;
 
-    if (!snxtitem(&ni, EF_LAND, range))
+    if (!snxtitem(&ni, EF_LAND, range, NULL))
        return;
 
     while (nxtitem(&ni, &land)) {
        if (!player->owner || !land.lnd_own)
            continue;
 
-       s = feed_land(&land, etu_per_update, &needed, 0);
+       s = famine_victims(land.lnd_item, etu_per_update);
        if (s == 0)
            continue;
        if (nunit++ == 0)
@@ -226,7 +234,7 @@ starv_units(char *range)
            pr("%3d ", land.lnd_own);
        pr("%5d ", land.lnd_uid);
        pr("%-16.16s ", lchr[(int)land.lnd_type].l_name);
-       pr(" will starve %d mil. %d more food needed\n", s, needed);
+       starv_people(land.lnd_item, s);
     }
     if (nunit == 0) {
        if (range)