2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, 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-2011
48 static void landrepair(struct lndstr *, struct natstr *, struct bp *, int);
49 static void upd_land(struct lndstr *, int, struct natstr *, struct bp *, int);
50 static int feed_land(struct lndstr *, int);
53 prod_land(int etus, int natnum, struct bp *bp, int build)
54 /* build = 1, maintain = 0 */
62 for (n = 0; NULL != (lp = getlandp(n)); n++) {
65 if (lp->lnd_own != natnum)
67 if (lp->lnd_effic < LAND_MINEFF) {
68 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
69 lp->lnd_x, lp->lnd_y);
74 sp = getsectp(lp->lnd_x, lp->lnd_y);
75 if (sp->sct_type == SCT_SANCT)
77 np = getnatp(lp->lnd_own);
78 start_money = np->nat_money;
79 upd_land(lp, etus, np, bp, build);
80 lnd_money[lp->lnd_own] += np->nat_money - start_money;
81 if (!build || np->nat_money != start_money)
83 if (player->simulation)
84 np->nat_money = start_money;
91 upd_land(struct lndstr *lp, int etus,
92 struct natstr *np, struct bp *bp, int build)
93 /* build = 1, maintain = 0 */
98 int min = morale_base - (int)np->nat_level[NAT_HLEV];
103 if (!player->simulation)
104 if (lp->lnd_retreat < min)
105 lp->lnd_retreat = min;
107 lcp = &lchr[(int)lp->lnd_type];
109 if (!lp->lnd_off && np->nat_money >= 0)
110 landrepair(lp, np, bp, etus);
111 if (!player->simulation)
115 if (np->nat_level[NAT_TLEV] < lp->lnd_tech * 0.85)
117 if (lcp->l_flags & L_ENGINEER)
119 cost = -(mult * etus * MIN(0.0, money_land * lcp->l_cost));
120 if (np->nat_money < cost && !player->simulation) {
121 if ((eff = lp->lnd_effic - etus / 5) < LAND_MINEFF) {
123 "%s lost to lack of maintenance\n", prland(lp));
124 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
125 lp->lnd_x, lp->lnd_y);
127 lp->lnd_ship = lp->lnd_land = -1;
131 "%s lost %d%% to lack of maintenance\n",
132 prland(lp), lp->lnd_effic - eff);
135 np->nat_money -= cost;
138 if (!player->simulation) {
140 if ((n = feed_land(lp, etus)) > 0) {
141 wu(0, lp->lnd_own, "%d starved in %s%s\n",
143 (lp->lnd_effic < LAND_MINEFF ? ", killing it" : ""));
145 nreport(lp->lnd_own, N_DIE_FAMINE, 0, 1);
148 * do plague stuff. plague can't break out on land units,
149 * but it can still kill people on them.
151 pstage = lp->lnd_pstage;
152 ptime = lp->lnd_ptime;
153 if (pstage != PLG_HEALTHY) {
154 n = plague_people(np, lp->lnd_item, &pstage, &ptime, etus);
158 "PLAGUE deaths reported on %s\n", prland(lp));
159 nreport(lp->lnd_own, N_DIE_PLAGUE, 0, 1);
162 wu(0, lp->lnd_own, "%s battling PLAGUE\n", prland(lp));
165 /* Are we still incubating? */
167 /* Yes. Will it turn "infectious" next time? */
169 /* Yes. Report an outbreak. */
171 "Outbreak of PLAGUE on %s!\n", prland(lp));
172 nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1);
175 /* It has already moved on to "infectious" */
177 "%s battling PLAGUE\n", prland(lp));
181 /* Has the plague moved to "incubation" yet? */
183 /* Yes. Will it turn "infectious" next time? */
185 /* Yes. Report an outbreak. */
187 "Outbreak of PLAGUE on %s!\n", prland(lp));
188 nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1);
195 lp->lnd_pstage = pstage;
196 lp->lnd_ptime = ptime;
198 } /* end !player->simulation */
203 landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
214 lp = &lchr[(int)land->lnd_type];
215 sp = getsectp(land->lnd_x, land->lnd_y);
219 if (np->nat_level[NAT_TLEV] < land->lnd_tech * 0.85)
222 if (land->lnd_effic == 100) {
223 /* land is ok; no repairs needed */
226 if (relations_with(sp->sct_own, land->lnd_own) != ALLIED)
229 if (!player->simulation)
230 avail = sp->sct_avail * 100;
232 avail = bp_get_avail(bp, sp) * 100;
234 w_p_eff = LND_BLD_WORK(lp->l_lcm, lp->l_hcm);
235 delta = roundavg((double)avail / w_p_eff);
238 if (delta > (int)((float)etus * land_grow_scale))
239 delta = (int)((float)etus * land_grow_scale);
240 if (delta > 100 - land->lnd_effic)
241 delta = 100 - land->lnd_effic;
243 memset(mvec, 0, sizeof(mvec));
244 mvec[I_LCM] = lp->l_lcm;
245 mvec[I_HCM] = lp->l_hcm;
246 build = get_materials(sp, bp, mvec, delta);
248 if ((sp->sct_type != SCT_HEADQ) && (sp->sct_type != SCT_FORTR))
251 avail -= build * w_p_eff;
254 if (!player->simulation)
255 sp->sct_avail = avail / 100;
257 bp_put_avail(bp, sp, avail / 100);
260 logerror("land unit %d building %d ! \n", land->lnd_uid, build);
261 np->nat_money -= mult * lp->l_cost * build / 100.0;
262 if (!player->simulation) {
263 land->lnd_effic += (signed char)build;
268 * returns the number who starved, if any.
271 feed_land(struct lndstr *lp, int etus)
273 return feed_people(lp->lnd_item, etus);