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