2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
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.
28 * lndsub.c: Land unit subroutines
30 * Known contributors to this file:
32 * Steve McClure, 1998-2000
33 * Markus Armbruster, 2004-2009
49 #include "prototypes.h"
54 static void lnd_mess(char *, struct ulist *);
55 static int lnd_hit_mine(struct lndstr *);
56 static int has_helpful_engineer(coord, coord, natid);
59 attack_val(int combat_mode, struct lndstr *lp)
65 if (lp->lnd_effic < LAND_MINEFF) {
66 putland(lp->lnd_uid, lp);
70 lcp = &lchr[(int)lp->lnd_type];
72 /* Spies always count as 1 during assaults. If they are the only ones
73 in the assault, they get to sneak on anyway. */
75 if (lcp->l_flags & L_SPY && combat_mode == A_ASSAULT)
78 men = lp->lnd_item[I_MILIT];
79 value = men * lnd_att(lp) * lp->lnd_effic / 100.0;
81 switch (combat_mode) {
85 if (!(lcp->l_flags & L_MARINE))
86 return assault_penalty * value;
89 if (!(lcp->l_flags & L_MARINE))
90 return assault_penalty * men;
97 defense_val(struct lndstr *lp)
103 if (lp->lnd_effic < LAND_MINEFF) {
104 putland(lp->lnd_uid, lp);
108 lcp = &lchr[(int)lp->lnd_type];
110 men = lp->lnd_item[I_MILIT];
112 if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) &&
113 !(lcp->l_flags & L_MARINE))
116 value = men * lnd_def(lp) * lp->lnd_effic / 100.0;
117 value *= ((double)land_mob_max + lp->lnd_harden) / land_mob_max;
119 /* If there are military on the unit, you get at least a 1
120 man defensive unit, except for spies */
121 if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
128 lnd_reaction_range(struct lndstr *lp)
132 getsect(lp->lnd_x, lp->lnd_y, §);
133 if (sect.sct_type == SCT_HEADQ && sect.sct_effic >= 60)
134 return lchr[lp->lnd_type].l_rad + 1;
135 return lchr[lp->lnd_type].l_rad;
139 lnd_print(struct ulist *llp, char *s)
141 if (llp->unit.land.lnd_own == player->cnum)
142 pr("%s %s\n", prland(&llp->unit.land), s);
144 wu(0, llp->unit.land.lnd_own, "%s %s\n", prland(&llp->unit.land), s);
148 lnd_delete(struct ulist *llp, char *s)
152 putland(llp->unit.land.lnd_uid, &llp->unit.land);
153 emp_remque((struct emp_qelem *)llp);
158 lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
159 /* attacking or assaulting or paratrooping? */
160 /* number of casualties to take */
173 int nowhere_to_go = 0;
175 double mobcost, bmcost;
179 taken = llp->unit.land.lnd_item[I_MILIT];
180 /* Spies always die */
181 if (((struct lchrstr *)llp->chrp)->l_flags & L_SPY)
182 llp->unit.land.lnd_effic = 0;
184 eff_eq = ldround(cas * 100.0 /
185 ((struct lchrstr *)llp->chrp)->l_item[I_MILIT], 1);
186 llp->unit.land.lnd_effic -= eff_eq;
187 lnd_submil(&llp->unit.land, cas);
190 if (llp->unit.land.lnd_effic < LAND_MINEFF) {
191 sprintf(buf, "dies %s %s!",
192 combat_mode ? att_mode[combat_mode] : "defending",
193 xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
194 llp->unit.land.lnd_own));
195 lnd_delete(llp, buf);
196 /* Since we killed the unit, we killed all the mil on it */
199 /* Ok, now, how many did we take off? (sould be the diff) */
200 taken = taken - llp->unit.land.lnd_item[I_MILIT];
203 if (llp->unit.land.lnd_effic >= llp->unit.land.lnd_retreat)
206 /* we're being boarded */
207 if (llp->unit.land.lnd_ship >= 0 && combat_mode == A_DEFEND)
210 /* we're being boarded */
211 if (llp->unit.land.lnd_land >= 0 && combat_mode == A_DEFEND)
214 /* Have to make a retreat check */
216 ret_chance = llp->unit.land.lnd_retreat - llp->unit.land.lnd_effic;
217 if (roll(100) < ret_chance) {
219 lnd_print(llp, "fails morale check!");
220 llp->unit.land.lnd_mission = 0;
221 llp->unit.land.lnd_harden = 0;
222 if (llp->unit.land.lnd_ship >= 0 || llp->unit.land.lnd_land >= 0)
224 else if (combat_mode == A_DEFEND) {
226 * defending unit.. find a place to send it
227 * strategy: look for the most-populated
228 * adjacent sector that is owned by the unit
229 * owner. Charge mob..
233 for (n = 1; n <= 6; ++n) {
234 ret_x = llp->unit.land.lnd_x + diroff[n][0];
235 ret_y = llp->unit.land.lnd_y + diroff[n][1];
236 getsect(ret_x, ret_y, §);
237 if (sect.sct_own != llp->unit.land.lnd_own)
239 if (sect.sct_type == SCT_MOUNT)
241 mobcost = lnd_mobcost(&llp->unit.land, &rsect);
245 civs = sect.sct_item[I_CIVIL];
246 if (civs > biggest) {
256 /* retreat to bx,by */
257 llp->unit.land.lnd_x = bx;
258 llp->unit.land.lnd_y = by;
259 /* FIXME landmines */
260 getsect(bx, by, &rsect);
261 mob = llp->unit.land.lnd_mobil - (int)bmcost;
264 orig = llp->unit.land.lnd_mobil;
265 llp->unit.land.lnd_mobil = (signed char)mob;
266 if (llp->unit.land.lnd_mobil > orig)
267 llp->unit.land.lnd_mobil = -127;
268 sprintf(buf, "retreats at %d%% efficiency to %s!",
269 llp->unit.land.lnd_effic,
270 xyas(bx, by, llp->unit.land.lnd_own));
271 lnd_delete(llp, buf);
273 } else { /* attacking from a sector */
274 sprintf(buf, "leaves the battlefield at %d%% efficiency",
275 llp->unit.land.lnd_effic);
276 if ((llp->unit.land.lnd_mobil - (int)llp->mobil) < -127)
277 llp->unit.land.lnd_mobil = -127;
279 llp->unit.land.lnd_mobil -= (int)llp->mobil;
281 lnd_delete(llp, buf);
285 /* nowhere to go.. take more casualties */
286 llp->unit.land.lnd_effic -= 10;
287 lnd_submil(&llp->unit.land,
288 ((struct lchrstr *)llp->chrp)->l_item[I_MILIT] / 10);
289 if (llp->unit.land.lnd_effic < LAND_MINEFF)
290 lnd_delete(llp, "has nowhere to retreat, and dies!");
293 "has nowhere to retreat and takes extra losses!");
300 lnd_takemob(struct emp_qelem *list, double loss)
302 struct emp_qelem *qp, *next;
305 int mcost = ldround(combat_mob * loss, 1);
307 for (qp = list->q_forw; qp != list; qp = next) {
309 llp = (struct ulist *)qp;
312 use_supply(&llp->unit.land);
314 new = llp->unit.land.lnd_mobil - mcost;
317 llp->unit.land.lnd_mobil = (signed char)new;
322 lnd_submil(struct lndstr *lp, int num)
324 int new = lp->lnd_item[I_MILIT] - num;
325 lp->lnd_item[I_MILIT] = new < 0 ? 0 : new;
329 lnd_spyval(struct lndstr *lp)
331 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
332 return lchr[lp->lnd_type].l_spy * (lp->lnd_effic / 100.0) + 2;
334 return lchr[lp->lnd_type].l_spy * (lp->lnd_effic / 100.0);
338 intelligence_report(int destination, struct lndstr *lp, int spy,
341 int vis = lnd_vis(lp);
342 char buf1[80], buf2[80], buf3[80];
344 if (destination == 0)
347 if (lp->lnd_own == 0)
350 memset(buf1, 0, sizeof(buf1));
351 memset(buf2, 0, sizeof(buf2));
352 memset(buf3, 0, sizeof(buf3));
353 if (chance((spy + vis) / 10.0)) {
354 if (destination == player->cnum)
355 pr("%s %s", mess, prland(lp));
357 sprintf(buf1, "%s %s", mess, prland(lp));
359 if (chance((spy + vis) / 20.0)) {
360 if (destination == player->cnum)
361 pr(" (eff %d, mil %d",
362 roundintby(lp->lnd_effic, 5),
363 roundintby(lp->lnd_item[I_MILIT], 10));
365 sprintf(buf2, " (eff %d, mil %d",
366 roundintby(lp->lnd_effic, 5),
367 roundintby(lp->lnd_item[I_MILIT], 10));
369 if (chance((spy + vis) / 20.0)) {
371 t = lp->lnd_tech - 20 + roll(40);
373 if (destination == player->cnum)
374 pr(", tech %d)\n", t);
376 sprintf(buf3, ", tech %d)\n", t);
378 if (destination == player->cnum)
381 sprintf(buf3, ")\n");
384 if (destination == player->cnum)
391 if (destination != player->cnum) {
392 wu(0, destination, "%s%s%s", buf1, buf2, buf3);
397 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
403 int mobtype = MOB_MOVE; /* indeterminate */
406 while (nxtitem(ni, &land)) {
408 * It would be nice to let deities march foreign land units,
409 * but much of the code assumes that only the land unit's
410 * owner can march it.
412 if (land.lnd_own != player->cnum)
415 if (ontradingblock(EF_LAND, &land)) {
416 pr("unit #%d inelligible - it's for sale.\n",
422 * The marching code gets confused when trains and non-trains
423 * march together. Disallow for now.
425 this_mot = lnd_mobtype(&land);
426 if (this_mot != mobtype) {
427 if (mobtype == MOB_MOVE)
429 else if (mobtype == MOB_MARCH) {
430 pr("%s is a train and can't march with the leader.\n",
434 pr("%s can't rail-march with the leading train.\n",
440 lcp = &lchr[(int)land.lnd_type];
441 land.lnd_mission = 0;
444 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
445 putland(land.lnd_uid, &land);
446 llp = malloc(sizeof(struct ulist));
447 llp->chrp = (struct empobj_chr *)lcp;
448 llp->unit.land = land;
449 llp->mobil = land.lnd_mobil;
450 emp_insque(&llp->queue, list);
454 /* This function assumes that the list was created by lnd_sel */
456 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
457 int *togetherp, natid actor)
459 struct emp_qelem *qp;
460 struct emp_qelem *next;
473 for (qp = list->q_back; qp != list; qp = next) {
475 llp = (struct ulist *)qp;
476 getland(llp->unit.land.lnd_uid, &land);
477 if (land.lnd_own != actor) {
478 mpr(actor, "%s was disbanded at %s\n",
479 prland(&land), xyas(land.lnd_x, land.lnd_y, actor));
480 emp_remque((struct emp_qelem *)llp);
484 if (land.lnd_ship >= 0) {
485 lnd_mess("is on a ship", llp);
488 if (land.lnd_land >= 0) {
489 lnd_mess("is on a unit", llp);
492 if (!getsect(land.lnd_x, land.lnd_y, §)) {
493 lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
496 if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
497 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_TRAIN) &&
498 llp->unit.land.lnd_item[I_MILIT] == 0) {
499 lnd_mess("has no mil on it to guide it", llp);
502 rel = getrel(getnatp(sect.sct_own), player->cnum);
503 if (sect.sct_own != land.lnd_own && rel != ALLIED &&
504 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
506 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
515 if (land.lnd_x != allx || land.lnd_y != ally)
517 if (land.lnd_mobil + 1 < (int)llp->mobil) {
518 llp->mobil = land.lnd_mobil;
520 if (llp->mobil < *minmobp)
521 *minmobp = llp->mobil;
522 if (llp->mobil > *maxmobp)
523 *maxmobp = llp->mobil;
524 llp->unit.land = land;
529 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
532 struct emp_qelem *qp;
533 struct emp_qelem *next;
536 int mines, m, max, sshells, lshells;
538 for (qp = land_list->q_back; qp != land_list; qp = next) {
540 llp = (struct ulist *)qp;
541 if (!(((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)) {
543 mpr(actor, "%s is not an engineer!\n",
544 prland(&llp->unit.land));
547 if (takemob && llp->mobil < 0.0) {
549 lnd_mess("is out of mobility", llp);
552 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
553 if (sect.sct_oldown == llp->unit.land.lnd_own) {
556 "%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
557 prland(&llp->unit.land));
560 if (SCT_MINES_ARE_SEAMINES(§)) {
562 mpr(actor, "%s is in a %s sector. No landmines there!\n",
563 prland(&llp->unit.land), dchr[sect.sct_type].d_name);
567 llp->mobil -= lnd_pathcost(&llp->unit.land, 0.2);
568 llp->unit.land.lnd_mobil = (int)llp->mobil;
569 llp->unit.land.lnd_harden = 0;
571 putland(llp->unit.land.lnd_uid, &llp->unit.land);
572 if (!(mines = sect.sct_mines))
574 max = ((struct lchrstr *)llp->chrp)->l_item[I_SHELL];
575 lshells = llp->unit.land.lnd_item[I_SHELL];
576 sshells = sect.sct_item[I_SHELL];
577 for (m = 0; mines > 0 && m < max * 2; m++) {
578 if (chance(0.5 * ((struct lchrstr *)llp->chrp)->l_att)) {
579 mpr(actor, "Sweep...\n");
583 else if (sshells < ITEM_MAX)
587 sect.sct_mines = mines;
588 llp->unit.land.lnd_item[I_SHELL] = lshells;
589 sect.sct_item[I_SHELL] = sshells;
590 putland(llp->unit.land.lnd_uid, &llp->unit.land);
596 contains_engineer(struct emp_qelem *list)
598 struct emp_qelem *qp;
599 struct emp_qelem *next;
602 for (qp = list->q_back; qp != list; qp = next) {
604 llp = (struct ulist *)qp;
605 if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
612 lnd_check_mines(struct emp_qelem *land_list)
614 struct emp_qelem *qp;
615 struct emp_qelem *next;
619 int with_eng = contains_engineer(land_list);
621 for (qp = land_list->q_back; qp != land_list; qp = next) {
623 llp = (struct ulist *)qp;
624 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
625 if (sect.sct_oldown == llp->unit.land.lnd_own)
627 if (SCT_LANDMINES(§) == 0)
629 if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
630 lnd_hit_mine(&llp->unit.land);
633 putland(llp->unit.land.lnd_uid, &llp->unit.land);
634 if (!llp->unit.land.lnd_own) {
645 lnd_mess(char *str, struct ulist *llp)
647 mpr(llp->unit.land.lnd_own, "%s %s & stays in %s\n",
648 prland(&llp->unit.land),
649 str, xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
650 llp->unit.land.lnd_own));
651 if (llp->mobil < -127)
653 llp->unit.land.lnd_mobil = llp->mobil;
654 putland(llp->unit.land.lnd_uid, &llp->unit.land);
655 emp_remque((struct emp_qelem *)llp);
660 lnd_count(struct emp_qelem *list)
662 struct emp_qelem *qp;
663 struct emp_qelem *next;
666 for (qp = list->q_back; qp != list; qp = next) {
674 lnd_damage(struct emp_qelem *list, int totdam)
676 struct emp_qelem *qp;
677 struct emp_qelem *next;
682 if (!totdam || !(count = lnd_count(list)))
684 dam = ldround((double)totdam / count, 1);
685 for (qp = list->q_back; qp != list; qp = next) {
687 llp = (struct ulist *)qp;
688 /* land unit might have changed (launched SAMs, collateral dmg) */
689 getland(llp->unit.land.lnd_uid, &llp->unit.land);
690 landdamage(&llp->unit.land, dam);
691 putland(llp->unit.land.lnd_uid, &llp->unit.land);
692 if (!llp->unit.land.lnd_own) {
701 lnd_easiest_target(struct emp_qelem *list)
703 struct emp_qelem *qp;
704 struct emp_qelem *next;
707 int easiest = 9876; /* things start great for victim */
710 for (qp = list->q_back; qp != list; qp = next) {
712 llp = (struct ulist *)qp;
713 hard = lnd_hardtarget(&llp->unit.land);
715 easiest = hard; /* things get worse for victim */
718 return easiest - count;
722 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
725 int mindam = lnd_count(list) * 20;
726 int hardtarget = lnd_easiest_target(list);
727 int dam, newdam, sublaunch;
730 struct emp_qelem msl_list, *qp, *newqp;
732 msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
735 for (qp = msl_list.q_back; qp != &msl_list; qp = newqp) {
737 plp = (struct plist *)qp;
739 if (dam < mindam && mission_pln_equip(plp, NULL, 'p') >= 0) {
740 if (msl_launch(&plp->plane, EF_LAND, "troops",
741 newx, newy, victim, &sublaunch) < 0)
744 if (msl_hit(&plp->plane, hardtarget, EF_LAND,
745 N_LND_MISS, N_LND_SMISS, sublaunch, victim)) {
746 newdam = pln_damage(&plp->plane, 'p', 1);
749 newdam = pln_damage(&plp->plane, 'p', 0);
750 collateral_damage(newx, newy, newdam);
753 plp->plane.pln_effic = 0;
754 putplane(plp->plane.pln_uid, &plp->plane);
761 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
762 collateral_damage(newx, newy, dam);
763 lnd_damage(list, dam);
769 /* Steve M. - commented out for now until abuse is decided upon */
770 /* risner: allow forts to interdict land units. */
772 lnd_fort_interdiction(struct emp_qelem *list,
773 coord newx, coord newy, natid victim)
785 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
786 while (nxtsct(&ns, &fsect)) {
787 if (fsect.sct_own == 0)
789 if (fsect.sct_own == victim)
791 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
793 range = roundrange(fortrange(&fsect));
794 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
797 dam = fort_fire(&fsect);
803 mpr(victim, "Incoming fire does %d damage!\n", dam);
805 "%s fires at %s land units in %s for %d!\n",
806 xyas(fsect.sct_x, fsect.sct_y,
808 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
809 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
812 lnd_damage(list, totdam);
818 lnd_mission_interdiction(struct emp_qelem *list, coord x, coord y,
823 dam = unit_interdict(x, y, victim, "land units",
824 lnd_easiest_target(list),
827 lnd_damage(list, dam);
832 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
837 if (!opt_NO_FORT_FIRE)
838 /* Steve M. - commented out for now until abuse is decided upon */
839 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
842 stopping |= lnd_mission_interdiction(list, newx, newy, victim);
843 stopping |= lnd_missile_interdiction(list, newx, newy, victim);
847 /* high value of hardtarget is harder to hit */
849 lnd_hardtarget(struct lndstr *lp)
853 getsect(lp->lnd_x, lp->lnd_y, §);
854 return (int)((lp->lnd_effic / 100.0) *
855 (10 + dchr[sect.sct_type].d_dstr * 2 + lnd_spd(lp) / 2.0
860 lnd_hit_mine(struct lndstr *lp)
864 mpr(lp->lnd_own, "Blammo! Landmines detected in %s!\n",
865 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
867 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
870 if (lchr[lp->lnd_type].l_flags & L_ENGINEER)
878 lnd_pathcost(struct lndstr *lp, double pathcost)
882 effspd = lnd_spd(lp);
883 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
884 effspd *= lp->lnd_effic * 0.01;
887 * The return value must be PATHCOST times a factor that depends
888 * only on the land unit. Anything else breaks path finding. In
889 * particular, you can't add or enforce a minimum cost here. Do
890 * it in sector_mcost().
892 return pathcost * 5.0 * speed_factor(effspd, lp->lnd_tech);
896 lnd_mobtype(struct lndstr *lp)
898 return (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
899 ? MOB_RAIL : MOB_MARCH;
903 lnd_mobcost(struct lndstr *lp, struct sctstr *sp)
905 return lnd_pathcost(lp, sector_mcost(sp, lnd_mobtype(lp)));
909 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
912 struct sctstr sect, osect;
913 struct emp_qelem *qp;
914 struct emp_qelem *qp2;
915 struct emp_qelem *next;
917 struct emp_qelem cur, done;
929 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
930 unit_put(list, actor);
935 for (qp = list->q_back; qp != list; qp = next) {
937 llp = (struct ulist *)qp;
938 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &osect);
939 oldown = osect.sct_own;
940 newx = xnorm(llp->unit.land.lnd_x + dx);
941 newy = ynorm(llp->unit.land.lnd_y + dy);
942 getsect(newx, newy, §);
943 rel = getrel(getnatp(sect.sct_own), player->cnum);
944 if ((sect.sct_own != actor && rel != ALLIED &&
945 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
946 sect.sct_own) || (sect.sct_type == SCT_WATER ||
947 sect.sct_type == SCT_SANCT ||
948 sect.sct_type == SCT_WASTE)) {
950 pr("can't go to %s\n", xyas(newx, newy, actor));
953 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
958 if (!SCT_HAS_RAIL(§)
959 && lnd_mobtype(&llp->unit.land) == MOB_RAIL) {
961 pr("no rail system in %s\n", xyas(newx, newy, actor));
964 sprintf(dp, "has no rail system in %s",
965 xyas(newx, newy, actor));
970 /* Note we check would_abandon first because we don't want
971 to always have to do these checks */
972 if (would_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
974 if (!want_to_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
977 /* now check stuff */
978 if (!check_sect_ok(§))
980 if (!check_sect_ok(&osect))
982 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
983 if (!check_land_ok(&((struct ulist *)qp2)->unit.land))
987 lnd_mess("stops", llp);
991 if (llp->mobil <= 0.0) {
992 lnd_mess("is out of mobility", llp);
995 llp->unit.land.lnd_x = newx;
996 llp->unit.land.lnd_y = newy;
997 llp->mobil -= lnd_mobcost(&llp->unit.land, §);
998 llp->unit.land.lnd_mobil = (int)llp->mobil;
999 llp->unit.land.lnd_harden = 0;
1000 putland(llp->unit.land.lnd_uid, &llp->unit.land);
1002 getsect(osect.sct_x, osect.sct_y, &osect);
1003 if (osect.sct_own != oldown && oldown == player->cnum) {
1004 /* It was your sector, now it's not. Simple :) */
1005 pr("You no longer own %s\n",
1006 xyas(osect.sct_x, osect.sct_y, player->cnum));
1008 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
1009 /* Always a 10% chance of getting caught. */
1010 if (chance(LND_SPY_DETECT_CHANCE(llp->unit.land.lnd_effic))) {
1011 if (rel == NEUTRAL || rel == FRIENDLY) {
1013 "%s unit spotted in %s\n", cname(player->cnum),
1014 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1015 setrel(sect.sct_own, llp->unit.land.lnd_own, HOSTILE);
1016 } else if (rel == HOSTILE || rel == AT_WAR ||
1017 rel == SITZKRIEG || rel == MOBILIZATION) {
1019 "%s spy shot in %s\n", cname(player->cnum),
1020 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1021 pr("%s was shot and killed.\n", prland(&llp->unit.land));
1022 llp->unit.land.lnd_effic = 0;
1023 putland(llp->unit.land.lnd_uid, &llp->unit.land);
1024 lnd_delete(llp, NULL);
1031 lnd_sweep(list, 0, 1, actor);
1032 stopping |= lnd_check_mines(list);
1036 /* interdict land units sector by sector */
1039 while (!QEMPTY(list)) {
1040 llp = (struct ulist *)list->q_back;
1041 newx = llp->unit.land.lnd_x;
1042 newy = llp->unit.land.lnd_y;
1043 /* move units in NEWX,NEWY to cur */
1045 for (qp = list->q_back; qp != list; qp = next) {
1047 llp = (struct ulist *)qp;
1048 if (llp->unit.land.lnd_x == newx && llp->unit.land.lnd_y == newy) {
1050 emp_insque(qp, &cur);
1051 if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY))
1055 /* interdict them */
1057 stopping |= lnd_interdict(&cur, newx, newy, actor);
1058 /* move survivors to done */
1059 for (qp = cur.q_back; qp != &cur; qp = next) {
1062 emp_insque(qp, &done);
1065 /* assign surviving land units back to list */
1066 emp_insque(list, &done);
1073 * find all artillery units belonging
1074 * to the attacker or defender that can fire.
1075 * Each arty unit adds +1%/damage point
1078 lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
1080 struct nstr_item ni;
1088 snxtitem_all(&ni, EF_LAND);
1089 while (nxtitem(&ni, &land)) {
1090 if ((land.lnd_x == x) && (land.lnd_y == y))
1092 rel = getrel(getnatp(land.lnd_own), attacker);
1093 rel2 = getrel(getnatp(land.lnd_own), victim);
1094 if ((land.lnd_own != attacker) &&
1095 ((rel != ALLIED) || (rel2 != AT_WAR)))
1098 /* are we in range? */
1099 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1101 range = roundrange(lnd_fire_range(&land));
1105 dam2 = lnd_fire(&land);
1106 putland(land.lnd_uid, &land);
1111 nreport(land.lnd_own, N_FIRE_BACK, victim, 1);
1113 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1114 if (roll(100) < lnd_acc(&land))
1117 if (land.lnd_own != attacker)
1119 "%s supported %s at %s\n",
1120 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1126 lnd_can_attack(struct lndstr *lp)
1128 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1130 if (lcp->l_flags & L_SUPPLY)
1137 * Increase fortification value of LP.
1138 * Fortification costs mobility. Use up to MOB mobility.
1139 * Return actual fortification increase.
1142 lnd_fortify(struct lndstr *lp, int mob)
1145 double mob_used, mult;
1147 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
1150 mob_used = MIN(lp->lnd_mobil, mob);
1154 mult = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own)
1157 hard_amt = (int)(mob_used * mult);
1158 if (lp->lnd_harden + hard_amt > land_mob_max) {
1159 hard_amt = land_mob_max - lp->lnd_harden;
1160 mob_used = ceil(hard_amt / mult);
1163 lp->lnd_mobil -= (int)mob_used;
1164 lp->lnd_harden += hard_amt;
1165 lp->lnd_harden = MIN(lp->lnd_harden, land_mob_max);
1171 * Is there a engineer unit at X,Y that can help nation CN?
1174 has_helpful_engineer(coord x, coord y, natid cn)
1176 struct nstr_item ni;
1179 snxtitem_xy(&ni, EF_LAND, x, y);
1180 while (nxtitem(&ni, &land)) {
1181 if (land.lnd_own != cn && getrel(getnatp(land.lnd_own), cn) != ALLIED)
1183 if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER)
1191 * Set LP's tech to TLEV along with everything else that depends on it.
1194 lnd_set_tech(struct lndstr *lp, int tlev)
1196 struct lchrstr *lcp = lchr + lp->lnd_type;
1198 if (CANT_HAPPEN(tlev < lcp->l_tech))
1201 lp->lnd_tech = tlev;