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