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