2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * land.c: Do production for land units
29 * Known contributors to this file:
31 * Thomas Ruschak, 1992
33 * Markus Armbruster, 2006-2016
49 #include "prototypes.h"
52 static void landrepair(struct lndstr *, struct natstr *, struct bp *, int);
53 static void upd_land(struct lndstr *, int, struct natstr *, struct bp *, int);
54 static int feed_land(struct lndstr *, int);
57 prod_land(int etus, int natnum, struct bp *bp, int build)
58 /* build = 1, maintain = 0 */
66 for (n = 0; NULL != (lp = getlandp(n)); n++) {
69 if (lp->lnd_own != natnum)
71 if (lp->lnd_effic < LAND_MINEFF) {
72 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
73 lp->lnd_x, lp->lnd_y);
78 sp = getsectp(lp->lnd_x, lp->lnd_y);
79 if (sp->sct_type == SCT_SANCT)
81 np = getnatp(lp->lnd_own);
82 start_money = np->nat_money;
83 upd_land(lp, etus, np, bp, build);
84 lnd_money[lp->lnd_own] += np->nat_money - start_money;
85 if (!build || np->nat_money != start_money)
87 if (player->simulation)
88 np->nat_money = start_money;
95 upd_land(struct lndstr *lp, int etus,
96 struct natstr *np, struct bp *bp, int build)
97 /* build = 1, maintain = 0 */
101 int min = morale_base - (int)np->nat_level[NAT_HLEV];
102 int n, mult, cost, eff_lost;
104 if (!player->simulation)
105 if (lp->lnd_retreat < min)
106 lp->lnd_retreat = min;
108 lcp = &lchr[(int)lp->lnd_type];
110 if (!lp->lnd_off && np->nat_money >= 0)
111 landrepair(lp, np, bp, etus);
112 if (!player->simulation)
116 if (np->nat_level[NAT_TLEV] < lp->lnd_tech * 0.85)
118 if (lcp->l_flags & L_ENGINEER)
120 cost = -(mult * etus * MIN(0.0, money_land * lcp->l_cost));
121 if (np->nat_money < cost && !player->simulation) {
123 if (lp->lnd_effic - eff_lost < LAND_MINEFF)
124 eff_lost = lp->lnd_effic - LAND_MINEFF;
126 wu(0, lp->lnd_own, "%s lost %d%% to lack of maintenance\n",
127 prland(lp), eff_lost);
128 lp->lnd_effic -= eff_lost;
131 np->nat_money -= cost;
134 if (!player->simulation) {
136 if ((n = feed_land(lp, etus)) > 0) {
137 wu(0, lp->lnd_own, "%d starved in %s%s\n",
139 (lp->lnd_effic < LAND_MINEFF ? ", killing it" : ""));
141 nreport(lp->lnd_own, N_DIE_FAMINE, 0, 1);
144 * do plague stuff. plague can't break out on land units,
145 * but it can still kill people on them.
147 pstage = lp->lnd_pstage;
148 ptime = lp->lnd_ptime;
149 if (pstage != PLG_HEALTHY) {
150 n = plague_people(np, lp->lnd_item, &pstage, &ptime, etus);
154 "PLAGUE deaths reported on %s\n", prland(lp));
155 nreport(lp->lnd_own, N_DIE_PLAGUE, 0, 1);
158 wu(0, lp->lnd_own, "%s battling PLAGUE\n", prland(lp));
161 /* Are we still incubating? */
163 /* Yes. Will it turn "infectious" next time? */
165 /* Yes. Report an outbreak. */
167 "Outbreak of PLAGUE on %s!\n", prland(lp));
168 nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1);
171 /* It has already moved on to "infectious" */
173 "%s battling PLAGUE\n", prland(lp));
177 /* Has the plague moved to "incubation" yet? */
179 /* Yes. Will it turn "infectious" next time? */
181 /* Yes. Report an outbreak. */
183 "Outbreak of PLAGUE on %s!\n", prland(lp));
184 nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1);
191 lp->lnd_pstage = pstage;
192 lp->lnd_ptime = ptime;
194 } /* end !player->simulation */
199 landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
201 struct lchrstr *lp = &lchr[(int)land->lnd_type];
203 struct sctstr *sp, scratch_sect;
208 if (land->lnd_effic == 100)
211 sp = getsectp(land->lnd_x, land->lnd_y);
215 if (relations_with(sp->sct_own, land->lnd_own) != ALLIED)
218 if (player->simulation) {
220 bp_to_sect(bp, &scratch_sect);
225 if (np->nat_level[NAT_TLEV] < land->lnd_tech * 0.85)
228 avail = sp->sct_avail * 100;
230 delta = avail / lp->l_bwork;
233 if (delta > (int)((float)etus * land_grow_scale))
234 delta = (int)((float)etus * land_grow_scale);
235 if (delta > 100 - land->lnd_effic)
236 delta = 100 - land->lnd_effic;
238 build = get_materials(sp, lp->l_mat, delta);
240 if ((sp->sct_type != SCT_HEADQ) && (sp->sct_type != SCT_FORTR))
243 avail = roundavg((avail - build * lp->l_bwork) / 100.0);
246 sp->sct_avail = avail;
248 bp_set_from_sect(bp, sp);
249 np->nat_money -= roundavg(mult * lp->l_cost * build / 100.0);
250 if (!player->simulation) {
251 land->lnd_effic += (signed char)build;
256 * returns the number who starved, if any.
259 feed_land(struct lndstr *lp, int etus)
261 return feed_people(lp->lnd_item, etus);