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
48 #include "prototypes.h"
51 static void upd_land(struct lndstr *, int, struct bp *, int);
52 static void landrepair(struct lndstr *, struct natstr *, struct bp *,
53 int, struct budget *);
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 */
64 for (i = 0; (lp = getlandp(i)); i++) {
67 if (lp->lnd_own != natnum)
69 if (lp->lnd_effic < LAND_MINEFF) {
70 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
71 lp->lnd_x, lp->lnd_y);
76 sp = getsectp(lp->lnd_x, lp->lnd_y);
77 if (sp->sct_type == SCT_SANCT)
79 upd_land(lp, etus, bp, build);
84 upd_land(struct lndstr *lp, int etus, struct bp *bp, int build)
85 /* build = 1, maintain = 0 */
87 struct budget *budget = &nat_budget[lp->lnd_own];
88 struct lchrstr *lcp = &lchr[lp->lnd_type];
89 struct natstr *np = getnatp(lp->lnd_own);
91 int min = morale_base - (int)np->nat_level[NAT_HLEV];
92 int n, mult, eff_lost;
95 if (!player->simulation)
96 if (lp->lnd_retreat < min)
97 lp->lnd_retreat = min;
100 if (!lp->lnd_off && budget->money >= 0)
101 landrepair(lp, np, bp, etus, budget);
102 if (!player->simulation)
105 budget->oldowned_civs += lp->lnd_item[I_CIVIL];
107 if (np->nat_level[NAT_TLEV] < lp->lnd_tech * 0.85)
109 if (lcp->l_flags & L_ENGINEER)
111 budget->bm[BUDG_LND_MAINT].count++;
112 cost = mult * etus * -money_land * lcp->l_cost;
113 if (budget->money < cost && !player->simulation) {
115 if (lp->lnd_effic - eff_lost < LAND_MINEFF)
116 eff_lost = lp->lnd_effic - LAND_MINEFF;
118 wu(0, lp->lnd_own, "%s lost %d%% to lack of maintenance\n",
119 prland(lp), eff_lost);
120 lp->lnd_effic -= eff_lost;
123 budget->bm[BUDG_LND_MAINT].money -= cost;
124 budget->money -= cost;
127 if (!player->simulation) {
129 if ((n = feed_land(lp, etus)) > 0) {
130 wu(0, lp->lnd_own, "%d starved in %s%s\n",
132 (lp->lnd_effic < LAND_MINEFF ? ", killing it" : ""));
134 nreport(lp->lnd_own, N_DIE_FAMINE, 0, 1);
137 * do plague stuff. plague can't break out on land units,
138 * but it can still kill people on them.
140 pstage = lp->lnd_pstage;
141 ptime = lp->lnd_ptime;
142 if (pstage != PLG_HEALTHY) {
143 n = plague_people(np, lp->lnd_item, &pstage, &ptime, etus);
147 "PLAGUE deaths reported on %s\n", prland(lp));
148 nreport(lp->lnd_own, N_DIE_PLAGUE, 0, 1);
151 wu(0, lp->lnd_own, "%s battling PLAGUE\n", prland(lp));
154 /* Are we still incubating? */
156 /* Yes. Will it turn "infectious" next time? */
158 /* Yes. Report an outbreak. */
160 "Outbreak of PLAGUE on %s!\n", prland(lp));
161 nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1);
164 /* It has already moved on to "infectious" */
166 "%s battling PLAGUE\n", prland(lp));
170 /* Has the plague moved to "incubation" yet? */
172 /* Yes. Will it turn "infectious" next time? */
174 /* Yes. Report an outbreak. */
176 "Outbreak of PLAGUE on %s!\n", prland(lp));
177 nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1);
184 lp->lnd_pstage = pstage;
185 lp->lnd_ptime = ptime;
187 } /* end !player->simulation */
192 landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus,
193 struct budget *budget)
195 struct lchrstr *lp = &lchr[(int)land->lnd_type];
197 struct sctstr *sp, scratch_sect;
203 if (land->lnd_effic == 100)
206 sp = getsectp(land->lnd_x, land->lnd_y);
210 if (relations_with(sp->sct_own, land->lnd_own) != ALLIED)
213 if (player->simulation) {
215 bp_to_sect(bp, &scratch_sect);
220 if (np->nat_level[NAT_TLEV] < land->lnd_tech * 0.85)
223 avail = sp->sct_avail * 100;
225 delta = avail / lp->l_bwork;
228 if (delta > (int)((float)etus * land_grow_scale))
229 delta = (int)((float)etus * land_grow_scale);
230 if (delta > 100 - land->lnd_effic)
231 delta = 100 - land->lnd_effic;
233 build = get_materials(sp, lp->l_mat, delta);
235 if ((sp->sct_type != SCT_HEADQ) && (sp->sct_type != SCT_FORTR))
238 avail = roundavg((avail - build * lp->l_bwork) / 100.0);
241 sp->sct_avail = avail;
243 bp_set_from_sect(bp, sp);
244 cost = mult * lp->l_cost * build / 100.0;
245 budget->bm[BUDG_LND_BUILD].count += !!build;
246 budget->bm[BUDG_LND_BUILD].money -= cost;
247 budget->money -= cost;
248 if (!player->simulation)
249 land->lnd_effic += (signed char)build;
253 * returns the number who starved, if any.
256 feed_land(struct lndstr *lp, int etus)
258 return feed_people(lp->lnd_item, etus);