]> git.pond.sub.org Git - empserver/blob - src/lib/subs/lndsub.c
Supply prototypes where possible. This uncovered type errors with
[empserver] / src / lib / subs / lndsub.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
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.
10  *
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.
15  *
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
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  lndsub.c: Land unit subroutines
29  * 
30  *  Known contributors to this file:
31  *     Ken Stevens, 1995
32  *     Steve McClure, 1998-2000
33  */
34
35 #include <math.h>
36 #include "misc.h"
37 #include "player.h"
38 #include "file.h"
39 #include "var.h"
40 #include "sect.h"
41 #include "path.h"
42 #include "news.h"
43 #include "treaty.h"
44 #include "nat.h"
45 #include "xy.h"
46 #include "land.h"
47 #include "ship.h"
48 #include "nsc.h"
49 #include "mission.h"
50 #include "plane.h"
51 #include "combat.h"
52 #include "damage.h"
53 #include "optlist.h"
54 #include "prototypes.h"
55
56 extern int etu_per_update;
57
58 int
59 attack_val(int combat_mode, struct lndstr *lp)
60 {
61     extern double assault_penalty;
62     int men;
63     int value;
64     struct lchrstr *lcp;
65
66     if (((int)lp->lnd_effic) < LAND_MINEFF) {
67         makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
68         lp->lnd_own = 0;
69         putland(lp->lnd_uid, lp);
70         return 0;
71     }
72
73     lcp = &lchr[(int)lp->lnd_type];
74
75 /* Spies always count as 1 during assaults.  If they are the only ones
76    in the assault, they get to sneak on anyway. */
77
78     if (lcp->l_flags & L_SPY && combat_mode == A_ASSAULT)
79         return 1;
80
81     men = total_mil(lp);
82
83     value = ldround(((double)men * (double)lp->lnd_att), 1);
84
85     value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
86
87     switch (combat_mode) {
88     case A_ATTACK:
89         return value;
90     case A_ASSAULT:
91         if (!(lcp->l_flags & L_MARINE))
92             return (int)(assault_penalty * value);
93         break;
94     case A_BOARD:
95         if (!(lcp->l_flags & L_MARINE))
96             return (int)(assault_penalty * men);
97     }
98
99     return value;
100 }
101
102 int
103 defense_val(struct lndstr *lp)
104 {
105     extern int land_mob_max;
106     int men;
107     double value;
108     struct lchrstr *lcp;
109
110     if (((int)lp->lnd_effic) < LAND_MINEFF) {
111         makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
112         lp->lnd_own = 0;
113         putland(lp->lnd_uid, lp);
114         return 0;
115     }
116
117     lcp = &lchr[(int)lp->lnd_type];
118
119     men = total_mil(lp);
120
121     if (men < 0)
122         men = 0;
123     if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) &&
124         !(lcp->l_flags & L_MARINE))
125         return men;
126
127     value = men * lp->lnd_def;
128
129     value *=
130         ((double)land_mob_max + lp->lnd_harden) / (double)land_mob_max;
131     value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
132     value = (int)ldround(value, 1);
133
134     /* If there are military on the unit, you get at least a 1
135        man defensive unit, except for spies */
136     if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
137         return 1;
138
139     return (int)(value);
140 }
141
142 int
143 total_mil(struct lndstr *lp)
144 {
145     struct lchrstr *lcp;
146     double men;
147
148     lcp = &lchr[(int)lp->lnd_type];
149
150     men = lnd_getmil(lp);
151 /*      men *= ((double)lp->lnd_effic)/100.0;*/
152
153     return ldround(men, 1);
154 }
155
156 void
157 lnd_print(struct llist *llp, s_char *s)
158 {
159     if (llp->land.lnd_own == player->cnum)
160         pr("%s %s\n", prland(&llp->land), s);
161     else
162         wu(0, llp->land.lnd_own, "%s %s\n", prland(&llp->land), s);
163 }
164
165 void
166 lnd_delete(struct llist *llp, s_char *s)
167 {
168     if (s)
169         lnd_print(llp, s);
170     putland(llp->land.lnd_uid, &llp->land);
171     emp_remque((struct emp_qelem *)llp);
172     free((s_char *)llp);
173 }
174
175 int
176 lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
177                         /* attacking or assaulting or paratrooping? */
178                         /* number of casualties to take */
179 {
180     int eff_eq;
181     int n;
182     int biggest;
183     int civs;
184     int nowned;
185     coord ret_x, ret_y;
186     coord bx, by;
187     struct sctstr sect;
188     int ret_chance;
189     s_char buf[1024];
190     int taken;
191     int nowhere_to_go = 0;
192     struct sctstr rsect;
193     double mobcost;
194     s_char orig;
195     int mob;
196
197
198
199     taken = lnd_getmil(&(llp->land));
200     /* Spies always die */
201     if (llp->lcp->l_flags & L_SPY) {
202         eff_eq = 100;
203         llp->land.lnd_effic = 0;
204     } else {
205         eff_eq =
206             ldround((((double)cas * 100.0) / (double)llp->lcp->l_mil), 1);
207         llp->land.lnd_effic -= eff_eq;
208         lnd_submil(&(llp->land), cas);
209     }
210
211     if (llp->land.lnd_effic < LAND_MINEFF) {
212         sprintf(buf, "dies %s %s!",
213                 combat_mode ? att_mode[combat_mode] : (s_char *)
214                 "defending", xyas(llp->land.lnd_x, llp->land.lnd_y,
215                                   llp->land.lnd_own));
216         lnd_delete(llp, buf);
217         /* Since we killed the unit, we killed all the mil on it */
218         return taken;
219     } else {
220         /* Ok, now, how many did we take off? (sould be the diff) */
221         taken = taken - lnd_getmil(&(llp->land));
222     }
223
224     if (llp->land.lnd_effic >= llp->land.lnd_retreat)
225         return taken;
226
227     /* we're being boarded */
228     if (llp->land.lnd_ship >= 0 && combat_mode == A_DEFEND)
229         return taken;
230
231     /* we're being boarded */
232     if (llp->land.lnd_land >= 0 && combat_mode == A_DEFEND)
233         return taken;
234
235     /* Have to make a retreat check */
236
237     ret_chance = llp->land.lnd_retreat - llp->land.lnd_effic;
238     if (roll(100) < ret_chance) {
239         pr("\n");
240         lnd_print(llp, "fails morale check!");
241         llp->land.lnd_mission = 0;
242         llp->land.lnd_harden = 0;
243         if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0)
244             nowhere_to_go = 1;
245         else if (combat_mode == A_DEFEND) {
246             /*
247              * defending unit.. find a place to send it
248              * strategy: look for the most-populated 
249              * adjacent sector that is owned by the unit
250              * player->owner. Charge mob..
251              */
252             biggest = -1;
253             nowned = 0;
254             for (n = 1; n <= 6; ++n) {
255                 ret_x = llp->land.lnd_x + diroff[n][0];
256                 ret_y = llp->land.lnd_y + diroff[n][1];
257                 getsect(ret_x, ret_y, &sect);
258                 if (sect.sct_own != llp->land.lnd_own)
259                     continue;
260                 if (sect.sct_type == SCT_MOUNT)
261                     continue;
262                 ++nowned;
263                 civs = getvar(V_CIVIL, (s_char *)&sect, EF_SECTOR);
264                 if (civs > biggest) {
265                     biggest = civs;
266                     bx = sect.sct_x;
267                     by = sect.sct_y;
268                 }
269             }
270             if (!nowned)
271                 nowhere_to_go = 1;
272             else {
273                 /* retreat to bx,by */
274                 llp->land.lnd_x = bx;
275                 llp->land.lnd_y = by;
276                 getsect(bx, by, &rsect);
277                 mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD);
278                 mob = llp->land.lnd_mobil - (int)mobcost;
279                 if (mob < -127)
280                     mob = -127;
281                 orig = llp->land.lnd_mobil;
282                 llp->land.lnd_mobil = (s_char)mob;
283                 if (llp->land.lnd_mobil > orig)
284                     llp->land.lnd_mobil = (-127);
285                 sprintf(buf, "retreats at %d%% efficiency to %s!",
286                         llp->land.lnd_effic,
287                         xyas(bx, by, llp->land.lnd_own));
288                 lnd_delete(llp, buf);
289             }
290         } else {                /* attacking from a sector */
291             sprintf(buf, "leaves the battlefield at %d%% efficiency",
292                     llp->land.lnd_effic);
293             if ((llp->land.lnd_mobil - (int)llp->mobil) < -127)
294                 llp->land.lnd_mobil = -127;
295             else
296                 llp->land.lnd_mobil -= (int)llp->mobil;
297             llp->mobil = 0.0;
298             lnd_delete(llp, buf);
299         }
300     }
301     if (nowhere_to_go) {
302         /* nowhere to go.. take more casualties */
303         llp->land.lnd_effic -= 10;
304         lnd_submil(&llp->land, llp->lcp->l_mil / 10);
305         if (llp->land.lnd_effic < LAND_MINEFF)
306             lnd_delete(llp, "has nowhere to retreat, and dies!");
307         else
308             lnd_print(llp,
309                       "has nowhere to retreat and takes extra losses!");
310     }
311
312     return taken;
313 }
314
315 void
316 lnd_takemob(struct emp_qelem *list, double loss)
317 {
318     struct emp_qelem *qp, *next;
319     struct llist *llp;
320     int new;
321     int mcost = ldround(combat_mob * loss, 1);
322
323     for (qp = list->q_forw; qp != list; qp = next) {
324         next = qp->q_forw;
325         llp = (struct llist *)qp;
326 /*
327                 if (chance(loss))
328                         use_supply(&llp->land);
329                 if (llp->land.lnd_mission == MI_RESERVE)
330                         new = llp->land.lnd_mobil - mcost/2;
331                 else
332  */
333         new = llp->land.lnd_mobil - mcost;
334         if (new < -127)
335             new = -127;
336         llp->land.lnd_mobil = (s_char)new;
337     }
338 }
339 int
340 lnd_getmil(struct lndstr *lp)
341 {
342     int vec[I_MAX + 1];
343
344     getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
345     return vec[I_MILIT];
346 }
347
348 void
349 lnd_submil(struct lndstr *lp, int num)
350 {
351     int vec[I_MAX + 1];
352
353     getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
354     vec[I_MILIT] -= num;
355     if (vec[I_MILIT] < 0)
356         vec[I_MILIT] = 0;
357     putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
358 }
359
360 int
361 lnd_spyval(struct lndstr *lp)
362 {
363     if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
364         return (lp->lnd_spy * (lp->lnd_effic / 100.0)) + 2;
365     else
366         return (lp->lnd_spy * (lp->lnd_effic / 100.0));
367 }
368
369 int
370 intelligence_report(int destination, struct lndstr *lp, int spy,
371                     s_char *mess)
372 {
373     struct lchrstr *lcp;
374     s_char buf1[80], buf2[80], buf3[80];
375     double estimate = 0.0;      /* estimated defense value */
376
377     if (destination == 0)
378         return 0;
379
380     if (lp->lnd_own == 0)
381         return 0;
382
383     lcp = &lchr[(int)lp->lnd_type];
384
385     memset(buf1, 0, sizeof(buf1));
386     memset(buf2, 0, sizeof(buf2));
387     memset(buf3, 0, sizeof(buf3));
388     if (chance((double)(spy + lp->lnd_vis) / 10.0)) {
389         if (destination == player->cnum)
390             pr("%s %s", mess, prland(lp));
391         else
392             sprintf(buf1, "%s %s", mess, prland(lp));
393
394         estimate = lnd_getmil(lp);
395
396         if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
397
398             if (destination == player->cnum)
399                 pr(" (eff %d, mil %d", roundintby(lp->lnd_effic, 5),
400                    roundintby(lnd_getmil(lp), 10));
401             else
402                 sprintf(buf2, " (eff %d, mil %d",
403                         roundintby(lp->lnd_effic, 5),
404                         roundintby(lnd_getmil(lp), 10));
405             estimate = lnd_getmil(lp) * lp->lnd_effic / 100.0;
406
407             if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
408                 int t;
409                 t = lp->lnd_tech - 20 + roll(40);
410                 t = max(t, 0);
411                 if (destination == player->cnum)
412                     pr(", tech %d)\n", t);
413                 else
414                     sprintf(buf3, ", tech %d)\n", t);
415             } else {
416                 if (destination == player->cnum)
417                     pr(")\n");
418                 else
419                     sprintf(buf3, ")\n");
420             }
421         } else {
422             if (destination == player->cnum)
423                 pr("\n");
424             else
425                 sprintf(buf2, "\n");
426         }
427     }
428
429     if (destination != player->cnum) {
430         wu(0, destination, "%s%s%s", buf1, buf2, buf3);
431     }
432
433     if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
434         estimate *= lp->lnd_def;
435
436     return (int)estimate;
437 }
438
439 /* Used by the spy command to count land units in a sector.  If used
440    for anything else, you may want to reconsider, because this doesn't
441    always count spies. :) */
442 int
443 count_sect_units(struct sctstr *sp)
444 {
445     int count = 0;
446     struct nstr_item ni;
447     struct lndstr land;
448
449     snxtitem_all(&ni, EF_LAND);
450     while (nxtitem(&ni, (s_char *)&land)) {
451         if (!land.lnd_own)
452             continue;
453         if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y)
454             continue;
455         /* Don't always see spies */
456         if (lchr[(int)land.lnd_type].l_flags & L_SPY) {
457             if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
458                 continue;
459         }
460         /* Got here, report it */
461         ++count;
462     }
463
464     return count;
465 }
466
467 void
468 count_units(struct shpstr *sp)
469 {
470     struct nstr_item ni;
471     struct lndstr land;
472     int nland = 0;
473
474     if (sp->shp_effic < SHIP_MINEFF)
475         return;
476
477     snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
478     while (nxtitem(&ni, (s_char *)&land)) {
479         if (land.lnd_own == 0)
480             continue;
481         if (land.lnd_ship == sp->shp_uid)
482             nland++;
483     }
484
485     if (sp->shp_nland != nland) {
486         sp->shp_nland = nland;
487         putship(sp->shp_uid, sp);
488     }
489 }
490
491 void
492 lnd_count_units(struct lndstr *lp)
493 {
494     struct nstr_item ni;
495     struct lndstr land;
496     int nland = 0;
497
498     if (lp->lnd_effic < LAND_MINEFF)
499         return;
500
501     snxtitem_xy(&ni, EF_LAND, lp->lnd_x, lp->lnd_y);
502     while (nxtitem(&ni, (s_char *)&land)) {
503         if (land.lnd_own == 0)
504             continue;
505         if (land.lnd_land == lp->lnd_uid)
506             nland++;
507     }
508
509     if (lp->lnd_nland != nland) {
510         lp->lnd_nland = nland;
511         putland(lp->lnd_uid, lp);
512     }
513 }
514
515 void
516 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
517
518
519 /*      int     wantflags;
520         int     nowantflags;
521 */
522 {
523     struct lndstr land;
524     struct lchrstr *lcp;
525     struct llist *llp;
526
527     emp_initque(list);
528     while (nxtitem(ni, (s_char *)&land)) {
529         if (!player->owner)
530             continue;
531         if (opt_MARKET) {
532             if (ontradingblock(EF_LAND, (int *)&land)) {
533                 pr("unit #%d inelligible - it's for sale.\n",
534                    land.lnd_uid);
535                 continue;
536             }
537         }
538         lcp = &lchr[(int)land.lnd_type];
539 /*              if (wantflags && (lcp->m_flags & wantflags) != wantflags)
540                         continue;
541                 if (nowantflags && lcp->m_flags & nowantflags)
542                         continue;
543 */
544         /* This abuse is better fixed by building a unit with the normal negative
545            mobility that everything else is built with */
546 /* Just so that the player can't build a bunch of land units, and them
547    march them a few minutes later... */
548 /*
549                 if (opt_MOB_ACCESS) {
550                   if (land.lnd_effic < 11 &&
551                     land.lnd_mobil < etu_per_update) {
552                     pr("Land unit #%d needs at least %d mob to march.\n",
553                         land.lnd_uid, etu_per_update);
554                     continue;
555                   }
556                 }
557 */
558         land.lnd_mission = 0;
559         land.lnd_rflags = 0;
560         land.lnd_harden = 0;
561         memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
562         putland(land.lnd_uid, &land);
563         llp = (struct llist *)malloc(sizeof(struct llist));
564         llp->lcp = lcp;
565         llp->land = land;
566         llp->mobil = (double)land.lnd_mobil;
567         emp_insque(&llp->queue, list);
568     }
569 }
570
571 /* This function assumes that the list was created by lnd_sel */
572 void
573 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
574         int *togetherp, natid actor)
575 {
576     struct emp_qelem *qp;
577     struct emp_qelem *next;
578     struct llist *llp;
579     struct sctstr sect;
580     struct lndstr land;
581     coord allx;
582     coord ally;
583     int first = 1;
584     s_char mess[128];
585     int rel;
586
587     *minmobp = 9876.0;
588     *maxmobp = -9876.0;
589     *togetherp = 1;
590     for (qp = list->q_back; qp != list; qp = next) {
591         next = qp->q_back;
592         llp = (struct llist *)qp;
593         getland(llp->land.lnd_uid, &land);
594         if (land.lnd_own != actor) {
595             mpr(actor, "%s was disbanded at %s\n",
596                 prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
597             emp_remque((struct emp_qelem *)llp);
598             free((s_char *)llp);
599             continue;
600         }
601         if (land.lnd_ship >= 0) {
602             lnd_mess("is on a ship", llp);
603             continue;
604         }
605         if (land.lnd_land >= 0) {
606             lnd_mess("is on a unit", llp);
607             continue;
608         }
609         if (!getsect(land.lnd_x, land.lnd_y, &sect)) {
610             lnd_mess("was sucked into the sky by a strange looking spaceland", llp);    /* heh -KHS */
611             continue;
612         }
613         if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
614             !(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) &&
615             lnd_getmil(&llp->land) == 0) {
616             lnd_mess("has no mil on it to guide it", llp);
617             continue;
618         }
619         rel = getrel(getnatp(sect.sct_own), player->cnum);
620         if (sect.sct_own != land.lnd_own && rel != ALLIED &&
621             !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
622             sect.sct_own) {
623             sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
624             lnd_mess(mess, llp);
625             continue;
626         }
627         if (first) {
628             allx = land.lnd_x;
629             ally = land.lnd_y;
630             first = 0;
631         }
632         if (land.lnd_x != allx || land.lnd_y != ally)
633             *togetherp = 0;
634         if (land.lnd_mobil + 1 < (int)llp->mobil) {
635             llp->mobil = (double)land.lnd_mobil;
636         }
637         if (llp->mobil < *minmobp)
638             *minmobp = llp->mobil;
639         if (llp->mobil > *maxmobp)
640             *maxmobp = llp->mobil;
641         llp->land = land;
642     }
643 }
644
645 void
646 lnd_put(struct emp_qelem *list, natid actor)
647 {
648     register struct emp_qelem *qp;
649     register struct emp_qelem *newqp;
650     struct llist *llp;
651
652     qp = list->q_back;
653     while (qp != list) {
654         llp = (struct llist *)qp;
655         if (actor) {
656             mpr(actor, "%s stopped at %s\n", prland(&llp->land),
657                 xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
658             if (llp->mobil < -127)
659                 llp->mobil = -127;
660             llp->land.lnd_mobil = llp->mobil;
661         }
662         putland(llp->land.lnd_uid, &llp->land);
663         newqp = qp->q_back;
664         emp_remque(qp);
665         free((s_char *)qp);
666         qp = newqp;
667     }
668 }
669
670 void
671 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
672           natid actor)
673 {
674     struct emp_qelem *qp;
675     struct emp_qelem *next;
676     struct llist *llp;
677     struct sctstr sect;
678     int mines, m, max, sshells, lshells;
679     double mobcost;
680
681     for (qp = land_list->q_back; qp != land_list; qp = next) {
682         next = qp->q_back;
683         llp = (struct llist *)qp;
684         if (!(llp->lcp->l_flags & L_ENGINEER)) {
685             if (verbose)
686                 mpr(actor, "%s is not an engineer!\n", prland(&llp->land));
687             continue;
688         }
689         if (takemob && llp->mobil < 0.0) {
690             if (verbose)
691                 lnd_mess("is out of mobility", llp);
692             continue;
693         }
694         getsect(llp->land.lnd_x, llp->land.lnd_y, &sect);
695         if (sect.sct_oldown == llp->land.lnd_own) {
696             if (verbose)
697                 mpr(actor,
698                     "%s is in a sector completely owned by you.  Don't bother digging up mines there!\n",
699                     prland(&llp->land));
700             continue;
701         }
702         if (sect.sct_type == SCT_BSPAN) {
703             if (verbose)
704                 mpr(actor, "%s is on a bridge.  No mines there!\n",
705                     prland(&llp->land));
706             continue;
707         }
708         if (takemob) {
709 /*                      mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/
710             mobcost = llp->land.lnd_spd;
711             mobcost = 480.0 / (mobcost +
712                                techfact(llp->land.lnd_tech, mobcost));
713             llp->mobil -= mobcost;
714             llp->land.lnd_mobil = (int)llp->mobil;
715             llp->land.lnd_harden = 0;
716         }
717         putland(llp->land.lnd_uid, &llp->land);
718         if (!(mines = getvar(V_MINE, (s_char *)&sect, EF_SECTOR)))
719             continue;
720         max = vl_find(V_SHELL, llp->lcp->l_vtype,
721                       llp->lcp->l_vamt, (int)llp->lcp->l_nv);
722         lshells = getvar(V_SHELL, (s_char *)&llp->land, EF_LAND);
723         sshells = getvar(V_SHELL, (s_char *)&sect, EF_SECTOR);
724         for (m = 0; mines > 0 && m < max * 2; m++) {
725             if (chance(0.5 * llp->lcp->l_att)) {
726                 mpr(actor, "Sweep...\n");
727                 mines--;
728                 if (lshells < max)
729                     ++lshells;
730                 else
731                     ++sshells;
732             }
733         }
734         putvar(V_MINE, mines, (s_char *)&sect, EF_SECTOR);
735         putvar(V_SHELL, lshells, (s_char *)&llp->land, EF_LAND);
736         putvar(V_SHELL, sshells, (s_char *)&sect, EF_SECTOR);
737         putland(llp->land.lnd_uid, &llp->land);
738         putsect(&sect);
739     }
740 }
741
742 static int
743 contains_engineer(struct emp_qelem *list)
744 {
745     struct emp_qelem *qp;
746     struct emp_qelem *next;
747     struct llist *llp;
748
749     for (qp = list->q_back; qp != list; qp = next) {
750         next = qp->q_back;
751         llp = (struct llist *)qp;
752         if (llp->lcp->l_flags & L_ENGINEER)
753             return 1;
754     }
755     return 0;
756 }
757
758 int
759 lnd_check_mines(struct emp_qelem *land_list)
760 {
761     struct emp_qelem *qp;
762     struct emp_qelem *next;
763     struct llist *llp;
764     struct sctstr sect;
765     int mines;
766     int stopping = 0;
767     int has_engineers = contains_engineer(land_list);
768
769     for (qp = land_list->q_back; qp != land_list; qp = next) {
770         next = qp->q_back;
771         llp = (struct llist *)qp;
772         getsect(llp->land.lnd_x, llp->land.lnd_y, &sect);
773         if (sect.sct_oldown == llp->land.lnd_own)
774             continue;
775         if (sect.sct_type == SCT_BSPAN)
776             continue;
777         if (!(mines = getvar(V_MINE, (s_char *)&sect, EF_SECTOR)))
778             continue;
779         if (chance(DMINE_LHITCHANCE(mines) / (1 + 2 * has_engineers))) {
780             lnd_hit_mine(&llp->land, llp->lcp);
781             mines--;
782             putvar(V_MINE, mines, (s_char *)&sect, EF_SECTOR);
783             putsect(&sect);
784             putland(llp->land.lnd_uid, (s_char *)&llp->land);
785             if (!llp->land.lnd_own) {
786                 stopping = 1;
787                 emp_remque(qp);
788                 free((s_char *)qp);
789             }
790         }
791     }
792     return stopping;
793 }
794
795 void
796 lnd_list(struct emp_qelem *land_list)
797 {
798     struct emp_qelem *qp;
799     struct emp_qelem *next;
800     struct llist *llp;
801     struct lndstr *lnd;
802     int vec[I_MAX + 1];
803
804     pr("lnd#     land type       x,y    a  eff  sh gun xl  mu tech retr fuel\n");
805
806     for (qp = land_list->q_back; qp != land_list; qp = next) {
807         next = qp->q_back;
808         llp = (struct llist *)qp;
809         lnd = &llp->land;
810         pr("%4d ", lnd->lnd_uid);
811         pr("%-16.16s ", llp->lcp->l_name);
812         prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
813         pr("%1c", lnd->lnd_army);
814         pr("%4d%%", lnd->lnd_effic);
815         getvec(VT_ITEM, vec, (s_char *)lnd, EF_LAND);
816         pr("%4d", vec[I_SHELL]);
817         pr("%4d", vec[I_GUN]);
818         count_land_planes(lnd);
819         pr("%3d", lnd->lnd_nxlight);
820         pr("%4d", lnd->lnd_mobil);
821         pr("%4d", lnd->lnd_tech);
822         pr("%4d%%", lnd->lnd_retreat);
823         pr("%5d\n", lnd->lnd_fuel);
824     }
825 }
826
827 void
828 lnd_mess(s_char *str, struct llist *llp)
829 {
830     mpr(llp->land.lnd_own, "%s %s & stays in %s\n",
831         prland(&llp->land),
832         str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
833     if (llp->mobil < -127)
834         llp->mobil = -127;
835     llp->land.lnd_mobil = llp->mobil;
836     putland(llp->land.lnd_uid, &llp->land);
837     emp_remque((struct emp_qelem *)llp);
838     free((s_char *)llp);
839 }
840
841 static int
842 lnd_count(struct emp_qelem *list)
843 {
844     struct emp_qelem *qp;
845     struct emp_qelem *next;
846     struct llist *llp;
847     int count = 0;
848
849     for (qp = list->q_back; qp != list; qp = next) {
850         next = qp->q_back;
851         llp = (struct llist *)qp;
852         ++count;
853     }
854     return count;
855 }
856
857 static int
858 lnd_damage(struct emp_qelem *list, int totdam)
859 {
860     struct emp_qelem *qp;
861     struct emp_qelem *next;
862     struct llist *llp;
863     int dam;
864     int count;
865
866     if (!totdam || !(count = lnd_count(list)))
867         return 0;
868     dam = ldround(((double)totdam / (double)count), 1);
869     for (qp = list->q_back; qp != list; qp = next) {
870         next = qp->q_back;
871         llp = (struct llist *)qp;
872         /* have to get it again because of collateral damage */
873         getland(llp->land.lnd_uid, &llp->land);
874         landdamage(&llp->land, dam);
875         putland(llp->land.lnd_uid, &llp->land);
876         if (!llp->land.lnd_own) {
877             emp_remque(qp);
878             free((s_char *)qp);
879         }
880     }
881     return dam;
882 }
883
884 static int
885 lnd_easiest_target(struct emp_qelem *list)
886 {
887     struct emp_qelem *qp;
888     struct emp_qelem *next;
889     struct llist *llp;
890     int hard;
891     int easiest = 9876;         /* things start great for victim */
892     int count = 0;
893
894     for (qp = list->q_back; qp != list; qp = next) {
895         next = qp->q_back;
896         llp = (struct llist *)qp;
897         hard = lnd_hardtarget(&llp->land);
898         if (hard < easiest)
899             easiest = hard;     /* things get worse for victim */
900         ++count;
901     }
902     return easiest - count;
903 }
904
905 static int
906 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
907                          natid victim)
908 {
909     int dam;
910     struct emp_qelem msl_list, *qp, *newqp;
911
912     msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
913
914     dam = msl_launch_mindam(&msl_list, newx, newy,
915                             lnd_easiest_target(list), EF_LAND,
916                             lnd_count(list) * 20, "troops", victim,
917                             MI_INTERDICT);
918     if (dam) {
919         mpr(victim, "missile interdiction mission does %d damage!\n", dam);
920         collateral_damage(newx, newy, dam, 0);
921     }
922     qp = msl_list.q_forw;
923     while (qp != msl_list.q_forw) {
924         newqp = qp->q_forw;
925         emp_remque(qp);
926         free(qp);
927         qp = newqp;
928     }
929     return dam;
930 }
931
932 #if 0
933 /* Steve M. - commented out for now until abuse is decided upon */
934 /* risner: allow forts to interdict land units. */
935 static int
936 lnd_fort_interdiction(struct emp_qelem *list,
937                       coord newx, coord newy, natid victim)
938 {
939     extern int fort_max_interdiction_range;
940     struct nstr_sect ns;
941     struct sctstr fsect;
942     int trange;
943     double range, range2, guneff;
944     int shell, gun;
945     int dam;
946     int totdam = 0;
947     int i;
948
949     snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
950     while (nxtsct(&ns, &fsect)) {
951         if (fsect.sct_own == 0)
952             continue;
953         if (fsect.sct_own == victim)
954             continue;
955         if (fsect.sct_type != SCT_FORTR)
956             continue;
957         if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
958             continue;
959         gun = getvar(V_GUN, (s_char *)&fsect, EF_SECTOR);
960         if (gun < 1)
961             continue;
962         range = tfactfire(fsect.sct_own, (double)min(gun, 7));
963         if (fsect.sct_effic > 59)
964             range++;
965         range2 = roundrange(range);
966         trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
967         if (trange > range2)
968             continue;
969         if (getvar(V_MILIT, (s_char *)&fsect, EF_SECTOR) < 5)
970             continue;
971         shell = getvar(V_SHELL, (s_char *)&fsect, EF_SECTOR);
972         if (shell < 1)
973             shell += supply_commod(fsect.sct_own,
974                                    fsect.sct_x, fsect.sct_y, I_SHELL, 1);
975         if (shell < 1)
976             continue;
977         shell--;
978         putvar(V_SHELL, shell, (s_char *)&fsect, EF_SECTOR);
979         putsect(&fsect);
980         if (gun > 7)
981             gun = 7;
982         guneff = landgun((int)fsect.sct_effic, gun);
983         dam = (int)guneff;
984         totdam += dam;
985         mpr(victim, "Incoming fire does %d damage!\n", dam);
986         wu(0, fsect.sct_own,
987            "%s fires at %s land units in %s for %d!\n",
988            xyas(fsect.sct_x, fsect.sct_y,
989                 fsect.sct_own),
990            cname(victim), xyas(newx, newy, fsect.sct_own), dam);
991         nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
992     }
993     if (totdam > 0)
994         return lnd_damage(list, totdam);
995     return 0;
996 }
997 #endif
998
999 int
1000 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
1001 {
1002     int stopping = 0;
1003
1004 #if 0
1005     if (!opt_NO_FORT_FIRE)
1006 /* Steve M. - commented out for now until abuse is decided upon */
1007         stopping |= lnd_fort_interdiction(list, newx, newy, victim);
1008 #endif
1009
1010     stopping |=
1011         lnd_damage(list,
1012                    unit_interdict(newx, newy, victim, "land units",
1013                                   lnd_easiest_target(list), MI_INTERDICT));
1014
1015     stopping |=
1016         lnd_damage(list,
1017                    lnd_missile_interdiction(list, newx, newy, victim));
1018     return stopping;
1019 }
1020
1021 /* high value of hardtarget is harder to hit */
1022 int
1023 lnd_hardtarget(struct lndstr *lp)
1024 {
1025     struct sctstr sect;
1026
1027     getsect(lp->lnd_x, lp->lnd_y, &sect);
1028     return (int)(((double)lp->lnd_effic / 100.0) *
1029                  (10 + dchr[sect.sct_type].d_dstr * 2 +
1030                   (double)lp->lnd_spd / 2.0 - lp->lnd_vis));
1031 }
1032
1033 int
1034 lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
1035 {
1036     double m;
1037
1038     mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
1039         xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1040
1041     nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
1042
1043     m = roll(20) + 10;
1044     if (lcp->l_flags & L_ENGINEER)
1045         m /= 2.0;
1046
1047     landdamage(lp, ldround(m, 1));
1048
1049     return (int)m;
1050 }
1051
1052 double
1053 lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
1054 {
1055     double mobcost;
1056     double smobcost;
1057
1058     /* supply unit's speed depends on their eff, since
1059        that is their purpose */
1060     if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
1061         mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd;
1062     else
1063         mobcost = lp->lnd_spd;
1064     if (mobcost < 0.01)
1065         mobcost = 0.01;
1066
1067 /* sector_mcost now takes 2 different arguments, a sector pointer, and
1068    whether or not to figure in the highway bonus, rail bonus or none.
1069    bridge heads, bridges and highways have built-in highways bonus
1070    because they are a 1, and this will discount that. */
1071
1072     smobcost = (double)sector_mcost(sp, mobtype);
1073     if (smobcost < 0.01)
1074         smobcost = 0.01;
1075
1076 /* marching through 0 mobility conquered sectors takes lots of mobility,
1077    unless you are a train.  Capturing railways is a good thing. */
1078
1079     if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 &&
1080         smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL)
1081         smobcost = LND_MINMOBCOST;
1082
1083     mobcost = smobcost * 5.0 * 480.0 /
1084         (mobcost + techfact(lp->lnd_tech, mobcost));
1085
1086     return mobcost;
1087 }
1088
1089 int
1090 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
1091                    int together)
1092 {
1093     struct sctstr sect, osect;
1094     struct emp_qelem *qp;
1095     struct emp_qelem *qp2;
1096     struct emp_qelem *next;
1097     struct llist *llp;
1098     coord dx;
1099     coord dy;
1100     coord newx;
1101     coord newy;
1102     int stopping = 0;
1103     int visible = 0;
1104     int stop;
1105     s_char dp[80];
1106     int rel;
1107     int oldown;
1108
1109     if (dir <= DIR_STOP || dir >= DIR_VIEW) {
1110         lnd_put(list, actor);
1111         return 1;
1112     }
1113     dx = diroff[dir][0];
1114     dy = diroff[dir][1];
1115     for (qp = list->q_back; qp != list; qp = next) {
1116         next = qp->q_back;
1117         llp = (struct llist *)qp;
1118         getsect(llp->land.lnd_x, llp->land.lnd_y, &osect);
1119         oldown = osect.sct_own;
1120         newx = xnorm(llp->land.lnd_x + dx);
1121         newy = ynorm(llp->land.lnd_y + dy);
1122         getsect(newx, newy, &sect);
1123         rel = getrel(getnatp(sect.sct_own), player->cnum);
1124         if ((sect.sct_own != actor && rel != ALLIED &&
1125              !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
1126              sect.sct_own) || (sect.sct_type == SCT_WATER ||
1127                                sect.sct_type == SCT_SANCT ||
1128                                sect.sct_type == SCT_WASTE)) {
1129             if (together) {
1130                 pr("can't go to %s\n", xyas(newx, newy, actor));
1131                 return 1;
1132             } else {
1133                 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
1134                 lnd_mess(dp, llp);
1135                 continue;
1136             }
1137         }
1138
1139         if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY))
1140             visible = 1;
1141         if (sect.sct_rail == 0 &&
1142             lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1143             if (together) {
1144                 pr("no rail system in %s\n", xyas(newx, newy, actor));
1145                 return 1;
1146             } else {
1147                 sprintf(dp, "has no rail system in %s",
1148                         xyas(newx, newy, actor));
1149                 lnd_mess(dp, llp);
1150                 continue;
1151             }
1152         }
1153         /* Note we check would_abandon first because we don't want
1154            to always have to do these checks */
1155         if (would_abandon(&osect, V_CIVIL, 0, &(llp->land))) {
1156             stop = 0;
1157             if (!want_to_abandon(&osect, V_CIVIL, 0, &(llp->land))) {
1158                 stop = 1;
1159             }
1160             /* now check stuff */
1161             if (!check_sect_ok(&sect))
1162                 return 1;
1163             if (!check_sect_ok(&osect))
1164                 return 1;
1165             for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
1166                 if (!check_land_ok(&(((struct llist *)qp2)->land)))
1167                     return 1;
1168             }
1169             if (stop) {
1170                 lnd_mess("stops", llp);
1171                 continue;
1172             }
1173         }
1174         if (llp->mobil <= 0.0) {
1175             lnd_mess("is out of mobility", llp);
1176             continue;
1177         }
1178         llp->land.lnd_x = newx;
1179         llp->land.lnd_y = newy;
1180         if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1181             llp->mobil -= lnd_mobcost(&llp->land, &sect, MOB_RAIL);
1182         } else {
1183             llp->mobil -= lnd_mobcost(&llp->land, &sect, MOB_ROAD);
1184         }
1185         llp->land.lnd_mobil = (int)llp->mobil;
1186         llp->land.lnd_harden = 0;
1187         putland(llp->land.lnd_uid, &llp->land);
1188         putsect(&osect);
1189         getsect(osect.sct_x, osect.sct_y, &osect);
1190         if (osect.sct_own != oldown && oldown == player->cnum) {
1191             /* It was your sector, now it's not.  Simple :) */
1192             pr("You no longer own %s\n",
1193                xyas(osect.sct_x, osect.sct_y, player->cnum));
1194         }
1195         if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) {   /* must be a spy */
1196             /* Always a 10% chance of getting caught. */
1197             if (chance(LND_SPY_DETECT_CHANCE(llp->land.lnd_effic))) {
1198                 if (rel == NEUTRAL || rel == FRIENDLY) {
1199                     wu(0, sect.sct_own,
1200                        "%s unit spotted in %s\n", cname(player->cnum),
1201                        xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1202                     setrel(sect.sct_own, llp->land.lnd_own, HOSTILE);
1203                 } else if (rel == HOSTILE || rel == AT_WAR ||
1204                            rel == SITZKRIEG || rel == MOBILIZATION) {
1205                     wu(0, sect.sct_own,
1206                        "%s spy shot in %s\n", cname(player->cnum),
1207                        xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1208                     pr("%s was shot and killed.\n", prland(&llp->land));
1209                     llp->land.lnd_effic = 0;
1210                     putland(llp->land.lnd_uid, &llp->land);
1211                     lnd_delete(llp, 0);
1212                 }
1213             }
1214         }
1215     }
1216     if (QEMPTY(list))
1217         return stopping;
1218     lnd_sweep(list, 0, 1, actor);
1219     stopping |= lnd_check_mines(list);
1220     if (QEMPTY(list))
1221         return stopping;
1222     if (visible)
1223         stopping |= lnd_interdict(list, newx, newy, actor);
1224     return stopping;
1225 }
1226
1227 /*
1228  * find all artillery units belonging
1229  * to the attacker or defender that can fire.
1230  * Each arty unit adds +1%/damage point
1231  *
1232  */
1233 int
1234 lnd_support(natid victim, natid attacker, coord x, coord y)
1235 {
1236     struct nstr_item ni;
1237     struct lndstr land;
1238     int rel, rel2;
1239     double dam = 0.0;
1240     int dist;
1241     int shell;
1242     int gun;
1243     double range, range2;
1244
1245     snxtitem_all(&ni, EF_LAND);
1246     while (nxtitem(&ni, (s_char *)&land)) {
1247         if (land.lnd_frg == 0)
1248             continue;
1249         if ((land.lnd_x == x) && (land.lnd_y == y))
1250             continue;
1251         if (land.lnd_ship >= 0)
1252             continue;
1253         if (land.lnd_land >= 0)
1254             continue;
1255         if (land.lnd_mission > 0)
1256             continue;
1257         if (land.lnd_effic < LAND_MINFIREEFF)
1258             continue;
1259         /* Do we have mil? */
1260         if (getvar(V_MILIT, (s_char *)&land, EF_LAND) <= 0)
1261             continue;
1262         rel = getrel(getnatp(land.lnd_own), attacker);
1263         rel2 = getrel(getnatp(land.lnd_own), victim);
1264         if ((land.lnd_own != attacker) &&
1265             ((rel != ALLIED) || (rel2 != AT_WAR)))
1266             continue;
1267
1268         /* do we have supplies? */
1269         if (!has_supply(&land))
1270             continue;
1271
1272         /* are we in range? */
1273         dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1274
1275         range = techfact((int)land.lnd_tech, (double)land.lnd_frg / 2.0);
1276
1277         range2 = roundrange(range);
1278         if (dist > range2)
1279             continue;
1280
1281         shell = getvar(V_SHELL, (s_char *)&land, EF_LAND);
1282         gun = getvar(V_GUN, (s_char *)&land, EF_LAND);
1283
1284         if (shell == 0 || gun == 0)
1285             continue;
1286
1287         use_supply(&land);
1288         nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1289         if (roll(100) < land.lnd_acc) {
1290             dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1291                                land.lnd_ammo, shell) / 2;
1292         } else {
1293             dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1294                                land.lnd_ammo, shell);
1295         }
1296         if (land.lnd_own != attacker)
1297             wu(0, land.lnd_own,
1298                "%s supported %s at %s\n",
1299                prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1300     }
1301     return (int)dam;
1302 }
1303
1304 s_char *
1305 lnd_path(int together, struct lndstr *lp, s_char *buf)
1306 {
1307     coord destx;
1308     coord desty;
1309     struct sctstr d_sect, sect;
1310     s_char *cp;
1311     double dummy;
1312
1313     if (!sarg_xy(buf, &destx, &desty))
1314         return 0;
1315     if (!together) {
1316         pr("Cannot go to a destination sector if not all starting in the same sector\n");
1317         return 0;
1318     }
1319     if (!getsect(destx, desty, &d_sect)) {
1320         pr("%d,%d is not a sector\n", destx, desty);
1321         return 0;
1322     }
1323     getsect(lp->lnd_x, lp->lnd_y, &sect);
1324     if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
1325         cp = (s_char *)BestLandPath(buf, &sect, &d_sect, &dummy, MOB_RAIL);
1326     else
1327         cp = (s_char *)BestLandPath(buf, &sect, &d_sect, &dummy, MOB_ROAD);
1328     if (!cp) {
1329         pr("No owned path from %s to %s!\n",
1330            xyas(lp->lnd_x, lp->lnd_y, player->cnum),
1331            xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1332         return 0;
1333     }
1334     pr("Using path '%s'\n", cp);
1335     return cp;
1336 }
1337
1338 int
1339 lnd_can_attack(struct lndstr *lp)
1340 {
1341     struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1342
1343 /*      if (lcp->l_flags & L_SUPPLY ||
1344             lcp->l_flags & L_SECURITY ||
1345             lcp->l_flags & L_FLAK ||
1346             lcp->l_frg)
1347                 return 0; */
1348     if (lcp->l_flags & L_SUPPLY)
1349         return 0;
1350
1351     return 1;
1352 }
1353
1354 /*
1355  * Increase fortification value of LP.
1356  * Fortification costs mobility.  Use up to HARD_AMT mobility.
1357  * Return actual fortification increase.
1358  */
1359 int
1360 lnd_fortify (struct lndstr *lp, int hard_amt)
1361 {
1362     extern int land_mob_max;
1363     int mob_used;
1364     int eng;
1365
1366     if ((lp->lnd_ship >= 0) || lp->lnd_land >= 0)
1367         return 0;
1368
1369     hard_amt = min(lp->lnd_mobil, hard_amt);
1370
1371     if ((lp->lnd_harden + hard_amt) > land_mob_max)
1372         hard_amt = land_mob_max - lp->lnd_harden;
1373
1374     eng = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own);
1375
1376     if (eng)
1377         hard_amt = ((float)hard_amt * 1.5);
1378
1379     if ((lp->lnd_harden + hard_amt) > land_mob_max)
1380         hard_amt = land_mob_max - lp->lnd_harden;
1381
1382     /* Ok, set the mobility used */
1383     mob_used = hard_amt;
1384
1385     /* Now, if an engineer helped, it's really only 2/3rds of
1386        that */
1387     if (eng)
1388         mob_used = (int)((float)mob_used / 1.5);
1389
1390     /* If we increased it, but not much, we gotta take at least 1
1391        mob point. */
1392     if (mob_used <= 0 && hard_amt > 0)
1393         mob_used = 1;
1394
1395     lp->lnd_mobil -= mob_used;
1396     if (lp->lnd_mobil < 0)
1397         lp->lnd_mobil = 0;
1398
1399     lp->lnd_harden += hard_amt;
1400     lp->lnd_harden = min(lp->lnd_harden, land_mob_max);
1401
1402     return hard_amt;
1403 }