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