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