/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2020, 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 "chance.h"
-#include "file.h"
#include "land.h"
#include "lost.h"
#include "nat.h"
#include "prototypes.h"
#include "update.h"
-static void upd_land(struct lndstr *, int, struct natstr *, struct bp *, 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 *);
-static int feed_land(struct lndstr *, int);
-void
-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 i;
- int start_money;
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)
+ 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;
+
+ for (i = 0; (lp = getlandp(i)); i++) {
+ if (lp->lnd_own == 0)
+ continue;
+ if (bp_skip_unit(bp, (struct empobj *)lp))
continue;
- 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;
+ 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 budget *budget = &nat_budget[lp->lnd_own];
- struct lchrstr *lcp;
- int pstage, ptime;
+ 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)
+ 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;
budget->bm[BUDG_LND_MAINT].count++;
- cost = -(mult * etus * MIN(0.0, money_land * lcp->l_cost));
- if (np->nat_money < cost && !player->simulation) {
+ 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;
}
} else {
budget->bm[BUDG_LND_MAINT].money -= cost;
- np->nat_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;
}
}
int build;
int avail;
int mult;
- int cost;
+ double cost;
if (land->lnd_effic == 100)
return;
sp->sct_avail = avail;
bp_set_from_sect(bp, sp);
- cost = roundavg(mult * lp->l_cost * build / 100.0);
+ cost = mult * lp->l_cost * build / 100.0;
budget->bm[BUDG_LND_BUILD].count += !!build;
budget->bm[BUDG_LND_BUILD].money -= cost;
- np->nat_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);
-}