2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2018, 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
46 #include "prototypes.h"
49 static void upd_land(struct lndstr *, int, struct bp *, int);
50 static void plague_land(struct lndstr *, int);
51 static void landrepair(struct lndstr *, struct natstr *, struct bp *,
52 int, struct budget *);
54 void prep_lands(int etus, struct bp *bp)
60 for (i = 0; (lp = getlandp(i)); i++) {
63 if (CANT_HAPPEN(lp->lnd_effic < LAND_MINEFF)) {
64 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
65 lp->lnd_x, lp->lnd_y);
70 bp_consider_unit(bp, (struct empobj *)lp);
71 mil = lp->lnd_item[I_MILIT];
72 mil_pay = mil * etus * money_mil;
73 nat_budget[lp->lnd_own].mil.count += mil;
74 nat_budget[lp->lnd_own].mil.money += mil_pay;
75 nat_budget[lp->lnd_own].money += mil_pay;
77 if (!player->simulation) {
78 if ((n = feed_people(lp->lnd_item, etus)) > 0) {
79 wu(0, lp->lnd_own, "%d starved in %s\n", n, prland(lp));
81 nreport(lp->lnd_own, N_DIE_FAMINE, 0, 1);
83 plague_land(lp, etus);
89 prod_land(int etus, struct bp *bp, int build)
90 /* build = 1, maintain = 0 */
95 for (i = 0; (lp = getlandp(i)); i++) {
98 if (bp_skip_unit(bp, (struct empobj *)lp))
100 upd_land(lp, etus, bp, build);
105 upd_land(struct lndstr *lp, int etus, struct bp *bp, int build)
106 /* build = 1, maintain = 0 */
108 struct budget *budget = &nat_budget[lp->lnd_own];
109 struct lchrstr *lcp = &lchr[lp->lnd_type];
110 struct natstr *np = getnatp(lp->lnd_own);
111 int min = morale_base - (int)np->nat_level[NAT_HLEV];
115 if (!player->simulation)
116 if (lp->lnd_retreat < min)
117 lp->lnd_retreat = min;
120 if (!lp->lnd_off && budget->money >= 0)
121 landrepair(lp, np, bp, etus, budget);
122 if (!player->simulation)
125 budget->oldowned_civs += lp->lnd_item[I_CIVIL];
127 if (np->nat_level[NAT_TLEV] < lp->lnd_tech * 0.85)
129 if (lcp->l_flags & L_ENGINEER)
131 budget->bm[BUDG_LND_MAINT].count++;
132 cost = mult * etus * -money_land * lcp->l_cost;
133 if (budget->money < cost && !player->simulation) {
135 if (lp->lnd_effic - eff_lost < LAND_MINEFF)
136 eff_lost = lp->lnd_effic - LAND_MINEFF;
138 wu(0, lp->lnd_own, "%s lost %d%% to lack of maintenance\n",
139 prland(lp), eff_lost);
140 lp->lnd_effic -= eff_lost;
143 budget->bm[BUDG_LND_MAINT].money -= cost;
144 budget->money -= cost;
150 plague_land(struct lndstr *lp, int etus)
152 struct natstr *np = getnatp(lp->lnd_own);
156 /* Plague can't break out on land units, but it can still kill people */
157 pstage = lp->lnd_pstage;
158 ptime = lp->lnd_ptime;
159 if (pstage != PLG_HEALTHY) {
160 n = plague_people(np, lp->lnd_item, &pstage, &ptime, etus);
161 if (n != PLG_HEALTHY)
162 plague_report(lp->lnd_own, n, pstage, ptime, etus,
164 lp->lnd_pstage = pstage;
165 lp->lnd_ptime = ptime;
170 landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus,
171 struct budget *budget)
173 struct lchrstr *lp = &lchr[(int)land->lnd_type];
175 struct sctstr *sp, scratch_sect;
181 if (land->lnd_effic == 100)
184 sp = getsectp(land->lnd_x, land->lnd_y);
188 if (relations_with(sp->sct_own, land->lnd_own) != ALLIED)
191 if (player->simulation) {
193 bp_to_sect(bp, &scratch_sect);
198 if (np->nat_level[NAT_TLEV] < land->lnd_tech * 0.85)
201 avail = sp->sct_avail * 100;
203 delta = avail / lp->l_bwork;
206 if (delta > (int)((float)etus * land_grow_scale))
207 delta = (int)((float)etus * land_grow_scale);
208 if (delta > 100 - land->lnd_effic)
209 delta = 100 - land->lnd_effic;
211 build = get_materials(sp, lp->l_mat, delta);
213 if ((sp->sct_type != SCT_HEADQ) && (sp->sct_type != SCT_FORTR))
216 avail = roundavg((avail - build * lp->l_bwork) / 100.0);
219 sp->sct_avail = avail;
221 bp_set_from_sect(bp, sp);
222 cost = mult * lp->l_cost * build / 100.0;
223 budget->bm[BUDG_LND_BUILD].count += !!build;
224 budget->bm[BUDG_LND_BUILD].money -= cost;
225 budget->money -= cost;
226 if (!player->simulation)
227 land->lnd_effic += (signed char)build;