* Dave Pare, 1986
* Thomas Ruschak, 1992
* Steve McClure, 1996
+ * Markus Armbruster, 2006
*/
#include <config.h>
+#include <math.h>
#include "misc.h"
#include "plague.h"
#include "sect.h"
static void landrepair(struct lndstr *, struct natstr *, int *, int);
static void upd_land(struct lndstr *, int, struct natstr *, int *, int);
+static int feed_land(struct lndstr *, int);
int
prod_land(int etus, int natnum, int *bp, int build)
int n;
int min = morale_base - (int)np->nat_level[NAT_HLEV];
int mult;
- int needed;
int cost;
int eff;
lcp = &lchr[(int)lp->lnd_type];
if (build == 1) {
- if (np->nat_priorities[PRI_LBUILD] == 0 || np->nat_money < 0)
- return;
- landrepair(lp, np, bp, etus);
+ if (np->nat_money >= 0)
+ landrepair(lp, np, bp, etus);
} else {
mult = 1;
if (np->nat_level[NAT_TLEV] < lp->lnd_tech * 0.85)
if (lcp->l_flags & L_ENGINEER)
mult *= 3;
cost = -(mult * etus * MIN(0.0, money_land * lcp->l_cost));
- if ((np->nat_priorities[PRI_LMAINT] == 0 || np->nat_money < cost)
- && !player->simulation) {
+ if (np->nat_money < cost && !player->simulation) {
if ((eff = lp->lnd_effic - etus / 5) < LAND_MINEFF) {
wu(0, lp->lnd_own,
"%s lost to lack of maintenance\n", prland(lp));
if (!player->simulation) {
/* feed */
- if ((n = feed_land(lp, etus, &needed, 1)) > 0) {
+ 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" : ""));
build /= 3;
avail -= build * w_p_eff;
- if (!player->simulation) {
+ if (avail < 0)
+ avail = 0;
+ if (!player->simulation)
sp->sct_avail = avail / 100;
- if (sp->sct_avail < 0)
- sp->sct_avail = 0;
- } else {
+ else
pt_bg_nmbr(bp, sp, I_MAX + 1, avail / 100);
- if (gt_bg_nmbr(bp, sp, I_MAX + 1) < 0)
- pt_bg_nmbr(bp, sp, I_MAX + 1, 0);
- }
if (build < 0)
logerror("land unit %d building %d ! \n", land->lnd_uid, build);
/*
* returns the number who starved, if any.
*/
-int
-feed_land(struct lndstr *lp, int etus, int *needed, int doit)
+static int
+feed_land(struct lndstr *lp, int etus)
{
- double food_eaten, ship_eaten;
- int ifood_eaten;
- double people_left;
- int need;
- int total_people;
- int starved;
+ int needed, give, take;
struct shpstr *sp;
if (opt_NOFOOD)
- return 0; /* no food no work to be done */
+ return 0;
- total_people = lp->lnd_item[I_MILIT];
- food_eaten = etus * eatrate * total_people;
- ifood_eaten = (int)food_eaten;
- if (food_eaten - ifood_eaten > 0)
- ifood_eaten++;
- starved = 0;
- *needed = 0;
+ needed = (int)ceil(food_needed(lp->lnd_item, etus));
- if (doit)
+ /* scrounge */
+ if (needed > lp->lnd_item[I_FOOD])
resupply_commod(lp, I_FOOD);
- /*
- * If we're on a ship, and we don't have enough food,
- * get some food off the carrying ship. (Don't starve
- * the ship, tho...
- */
-/* doit - Only try to take food off the ship during the update */
- if (ifood_eaten > lp->lnd_item[I_FOOD] && lp->lnd_ship >= 0 && doit) {
- need = ifood_eaten - lp->lnd_item[I_FOOD];
- sp = getshipp(lp->lnd_ship);
- ship_eaten = etus * eatrate * (sp->shp_item[I_CIVIL]
- + sp->shp_item[I_MILIT]
- + sp->shp_item[I_UW]);
- if (sp->shp_item[I_FOOD] - need > ship_eaten) {
- lp->lnd_item[I_FOOD] += need;
- sp->shp_item[I_FOOD] -= need;
- } else if (sp->shp_item[I_FOOD] - ship_eaten > 0) {
- lp->lnd_item[I_FOOD] += sp->shp_item[I_FOOD] - ship_eaten;
- sp->shp_item[I_FOOD] -= sp->shp_item[I_FOOD] - ship_eaten;
- }
- }
- if (ifood_eaten > lp->lnd_item[I_FOOD]) {
- *needed = ifood_eaten - lp->lnd_item[I_FOOD];
- people_left = (lp->lnd_item[I_FOOD] + 0.01) / (food_eaten + 0.01);
- /* only want to starve off at most 1/2 the populace. */
- if (people_left < 0.5)
- people_left = 0.5;
- starved = total_people * (1 - people_left);
- lp->lnd_item[I_MILIT] -= starved;
- lp->lnd_item[I_FOOD] = 0;
- } else {
- lp->lnd_item[I_FOOD] -= (int)food_eaten;
- }
- return starved;
+ return feed_people(lp->lnd_item, etus);
}