/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2011, 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/>.
*
* ---
*
* ---
*
* land.c: Do production for land units
- *
+ *
* Known contributors to this file:
* Dave Pare, 1986
* Thomas Ruschak, 1992
* Steve McClure, 1996
- * Markus Armbruster, 2006-2007
+ * Markus Armbruster, 2006-2011
*/
#include <config.h>
+#include <math.h>
#include "budg.h"
#include "land.h"
#include "lost.h"
#include "player.h"
#include "ship.h"
#include "update.h"
-#include <math.h>
static void landrepair(struct lndstr *, struct natstr *, struct bp *, int);
static void upd_land(struct lndstr *, int, struct natstr *, struct bp *, int);
struct natstr *np;
int n, k = 0;
int start_money;
- int lastx = 9999, lasty = 9999;
- bp_enable_cachepath();
for (n = 0; NULL != (lp = getlandp(n)); n++) {
if (lp->lnd_own == 0)
continue;
sp = getsectp(lp->lnd_x, lp->lnd_y);
if (sp->sct_type == SCT_SANCT)
continue;
- if (lastx == 9999 || lasty == 9999) {
- lastx = lp->lnd_x;
- lasty = lp->lnd_y;
- }
- if (lastx != lp->lnd_x || lasty != lp->lnd_y) {
- /* Reset the cache */
- bp_disable_cachepath();
- bp_clear_cachepath();
- bp_enable_cachepath();
- }
np = getnatp(lp->lnd_own);
start_money = np->nat_money;
upd_land(lp, etus, np, bp, build);
if (player->simulation)
np->nat_money = start_money;
}
- bp_disable_cachepath();
- bp_clear_cachepath();
return k;
}
{
struct lchrstr *lcp;
int pstage, ptime;
- int n;
int min = morale_base - (int)np->nat_level[NAT_HLEV];
- int mult;
- int cost;
- int eff;
+ int n, mult, cost, eff_lost;
if (!player->simulation)
if (lp->lnd_retreat < min)
mult *= 3;
cost = -(mult * etus * MIN(0.0, money_land * lcp->l_cost));
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));
- makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
- lp->lnd_x, lp->lnd_y);
- lp->lnd_own = 0;
- return;
+ eff_lost = etus / 5;
+ if (lp->lnd_effic - eff_lost < LAND_MINEFF)
+ eff_lost = lp->lnd_effic - LAND_MINEFF;
+ if (eff_lost > 0) {
+ wu(0, lp->lnd_own, "%s lost %d%% to lack of maintenance\n",
+ prland(lp), eff_lost);
+ lp->lnd_effic -= eff_lost;
}
- wu(0, lp->lnd_own,
- "%s lost %d%% to lack of maintenance\n",
- prland(lp), lp->lnd_effic - eff);
- lp->lnd_effic = eff;
} else {
np->nat_money -= cost;
}
/* land is ok; no repairs needed */
return;
}
- if ((sp->sct_own != land->lnd_own) &&
- (getrel(getnatp(sp->sct_own), land->lnd_own) != ALLIED))
+ if (relations_with(sp->sct_own, land->lnd_own) != ALLIED)
return;
if (!player->simulation)
static int
feed_land(struct lndstr *lp, int etus)
{
- int needed;
-
- if (opt_NOFOOD)
- return 0;
-
- needed = (int)ceil(food_needed(lp->lnd_item, etus));
-
- /* scrounge */
- if (needed > lp->lnd_item[I_FOOD])
- resupply_commod(lp, I_FOOD);
-
return feed_people(lp->lnd_item, etus);
}