2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program 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 2 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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * land.c: Do production for land units
30 * Known contributors to this file:
32 * Thomas Ruschak, 1992
34 * Markus Armbruster, 2006-2009
49 static void landrepair(struct lndstr *, struct natstr *, struct bp *, int);
50 static void upd_land(struct lndstr *, int, struct natstr *, struct bp *, int);
51 static int feed_land(struct lndstr *, int);
54 prod_land(int etus, int natnum, struct bp *bp, int build)
55 /* build = 1, maintain = 0 */
63 for (n = 0; NULL != (lp = getlandp(n)); n++) {
66 if (lp->lnd_own != natnum)
68 if (lp->lnd_effic < LAND_MINEFF) {
69 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
70 lp->lnd_x, lp->lnd_y);
75 sp = getsectp(lp->lnd_x, lp->lnd_y);
76 if (sp->sct_type == SCT_SANCT)
78 np = getnatp(lp->lnd_own);
79 start_money = np->nat_money;
80 upd_land(lp, etus, np, bp, build);
81 lnd_money[lp->lnd_own] += np->nat_money - start_money;
82 if (!build || np->nat_money != start_money)
84 if (player->simulation)
85 np->nat_money = start_money;
92 upd_land(struct lndstr *lp, int etus,
93 struct natstr *np, struct bp *bp, int build)
94 /* build = 1, maintain = 0 */
99 int min = morale_base - (int)np->nat_level[NAT_HLEV];
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) {
122 if ((eff = lp->lnd_effic - etus / 5) < LAND_MINEFF) {
124 "%s lost to lack of maintenance\n", prland(lp));
125 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
126 lp->lnd_x, lp->lnd_y);
128 lp->lnd_ship = lp->lnd_land = -1;
132 "%s lost %d%% to lack of maintenance\n",
133 prland(lp), lp->lnd_effic - eff);
136 np->nat_money -= cost;
139 if (!player->simulation) {
141 if ((n = feed_land(lp, etus)) > 0) {
142 wu(0, lp->lnd_own, "%d starved in %s%s\n",
144 (lp->lnd_effic < LAND_MINEFF ? ", killing it" : ""));
146 nreport(lp->lnd_own, N_DIE_FAMINE, 0, 1);
149 * do plague stuff. plague can't break out on land units,
150 * but it can still kill people on them.
152 pstage = lp->lnd_pstage;
153 ptime = lp->lnd_ptime;
154 if (pstage != PLG_HEALTHY) {
155 n = plague_people(np, lp->lnd_item, &pstage, &ptime, etus);
159 "PLAGUE deaths reported on %s\n", prland(lp));
160 nreport(lp->lnd_own, N_DIE_PLAGUE, 0, 1);
163 wu(0, lp->lnd_own, "%s battling PLAGUE\n", prland(lp));
166 /* Are we still incubating? */
168 /* Yes. Will it turn "infectious" next time? */
170 /* Yes. Report an outbreak. */
172 "Outbreak of PLAGUE on %s!\n", prland(lp));
173 nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1);
176 /* It has already moved on to "infectious" */
178 "%s battling PLAGUE\n", prland(lp));
182 /* Has the plague moved to "incubation" yet? */
184 /* Yes. Will it turn "infectious" next time? */
186 /* Yes. Report an outbreak. */
188 "Outbreak of PLAGUE on %s!\n", prland(lp));
189 nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1);
196 lp->lnd_pstage = pstage;
197 lp->lnd_ptime = ptime;
199 } /* end !player->simulation */
204 landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
215 lp = &lchr[(int)land->lnd_type];
216 sp = getsectp(land->lnd_x, land->lnd_y);
220 if (np->nat_level[NAT_TLEV] < land->lnd_tech * 0.85)
223 if (land->lnd_effic == 100) {
224 /* land is ok; no repairs needed */
227 if (relations_with(sp->sct_own, land->lnd_own) != ALLIED)
230 if (!player->simulation)
231 avail = sp->sct_avail * 100;
233 avail = bp_get_avail(bp, sp) * 100;
235 w_p_eff = LND_BLD_WORK(lp->l_lcm, lp->l_hcm);
236 delta = roundavg((double)avail / w_p_eff);
239 if (delta > (int)((float)etus * land_grow_scale))
240 delta = (int)((float)etus * land_grow_scale);
241 if (delta > 100 - land->lnd_effic)
242 delta = 100 - land->lnd_effic;
244 memset(mvec, 0, sizeof(mvec));
245 mvec[I_LCM] = lp->l_lcm;
246 mvec[I_HCM] = lp->l_hcm;
247 build = get_materials(sp, bp, mvec, delta);
249 if ((sp->sct_type != SCT_HEADQ) && (sp->sct_type != SCT_FORTR))
252 avail -= build * w_p_eff;
255 if (!player->simulation)
256 sp->sct_avail = avail / 100;
258 bp_put_avail(bp, sp, avail / 100);
261 logerror("land unit %d building %d ! \n", land->lnd_uid, build);
262 np->nat_money -= mult * lp->l_cost * build / 100.0;
263 if (!player->simulation) {
264 land->lnd_effic += (signed char)build;
269 * returns the number who starved, if any.
272 feed_land(struct lndstr *lp, int etus)
274 return feed_people(lp->lnd_item, etus);