2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2009, 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 *, struct lchrstr *);
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) {
183 llp->unit.land.lnd_effic = 0;
185 eff_eq = ldround(cas * 100.0 /
186 ((struct lchrstr *)llp->chrp)->l_item[I_MILIT], 1);
187 llp->unit.land.lnd_effic -= eff_eq;
188 lnd_submil(&llp->unit.land, cas);
191 if (llp->unit.land.lnd_effic < LAND_MINEFF) {
192 sprintf(buf, "dies %s %s!",
193 combat_mode ? att_mode[combat_mode] : "defending",
194 xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
195 llp->unit.land.lnd_own));
196 lnd_delete(llp, buf);
197 /* Since we killed the unit, we killed all the mil on it */
200 /* Ok, now, how many did we take off? (sould be the diff) */
201 taken = taken - llp->unit.land.lnd_item[I_MILIT];
204 if (llp->unit.land.lnd_effic >= llp->unit.land.lnd_retreat)
207 /* we're being boarded */
208 if (llp->unit.land.lnd_ship >= 0 && combat_mode == A_DEFEND)
211 /* we're being boarded */
212 if (llp->unit.land.lnd_land >= 0 && combat_mode == A_DEFEND)
215 /* Have to make a retreat check */
217 ret_chance = llp->unit.land.lnd_retreat - llp->unit.land.lnd_effic;
218 if (roll(100) < ret_chance) {
220 lnd_print(llp, "fails morale check!");
221 llp->unit.land.lnd_mission = 0;
222 llp->unit.land.lnd_harden = 0;
223 if (llp->unit.land.lnd_ship >= 0 || llp->unit.land.lnd_land >= 0)
225 else if (combat_mode == A_DEFEND) {
227 * defending unit.. find a place to send it
228 * strategy: look for the most-populated
229 * adjacent sector that is owned by the unit
230 * owner. Charge mob..
234 for (n = 1; n <= 6; ++n) {
235 ret_x = llp->unit.land.lnd_x + diroff[n][0];
236 ret_y = llp->unit.land.lnd_y + diroff[n][1];
237 getsect(ret_x, ret_y, §);
238 if (sect.sct_own != llp->unit.land.lnd_own)
240 if (sect.sct_type == SCT_MOUNT)
242 mobcost = lnd_mobcost(&llp->unit.land, &rsect);
246 civs = sect.sct_item[I_CIVIL];
247 if (civs > biggest) {
257 /* retreat to bx,by */
258 llp->unit.land.lnd_x = bx;
259 llp->unit.land.lnd_y = by;
260 /* FIXME landmines */
261 getsect(bx, by, &rsect);
262 mob = llp->unit.land.lnd_mobil - (int)bmcost;
265 orig = llp->unit.land.lnd_mobil;
266 llp->unit.land.lnd_mobil = (signed char)mob;
267 if (llp->unit.land.lnd_mobil > orig)
268 llp->unit.land.lnd_mobil = -127;
269 sprintf(buf, "retreats at %d%% efficiency to %s!",
270 llp->unit.land.lnd_effic,
271 xyas(bx, by, llp->unit.land.lnd_own));
272 lnd_delete(llp, buf);
274 } else { /* attacking from a sector */
275 sprintf(buf, "leaves the battlefield at %d%% efficiency",
276 llp->unit.land.lnd_effic);
277 if ((llp->unit.land.lnd_mobil - (int)llp->mobil) < -127)
278 llp->unit.land.lnd_mobil = -127;
280 llp->unit.land.lnd_mobil -= (int)llp->mobil;
282 lnd_delete(llp, buf);
286 /* nowhere to go.. take more casualties */
287 llp->unit.land.lnd_effic -= 10;
288 lnd_submil(&llp->unit.land,
289 ((struct lchrstr *)llp->chrp)->l_item[I_MILIT] / 10);
290 if (llp->unit.land.lnd_effic < LAND_MINEFF)
291 lnd_delete(llp, "has nowhere to retreat, and dies!");
294 "has nowhere to retreat and takes extra losses!");
301 lnd_takemob(struct emp_qelem *list, double loss)
303 struct emp_qelem *qp, *next;
306 int mcost = ldround(combat_mob * loss, 1);
308 for (qp = list->q_forw; qp != list; qp = next) {
310 llp = (struct ulist *)qp;
313 use_supply(&llp->unit.land);
315 new = llp->unit.land.lnd_mobil - mcost;
318 llp->unit.land.lnd_mobil = (signed char)new;
323 lnd_submil(struct lndstr *lp, int num)
325 int new = lp->lnd_item[I_MILIT] - num;
326 lp->lnd_item[I_MILIT] = new < 0 ? 0 : new;
330 lnd_spyval(struct lndstr *lp)
332 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
333 return lchr[lp->lnd_type].l_spy * (lp->lnd_effic / 100.0) + 2;
335 return lchr[lp->lnd_type].l_spy * (lp->lnd_effic / 100.0);
339 intelligence_report(int destination, struct lndstr *lp, int spy,
342 int vis = lnd_vis(lp);
343 char buf1[80], buf2[80], buf3[80];
345 if (destination == 0)
348 if (lp->lnd_own == 0)
351 memset(buf1, 0, sizeof(buf1));
352 memset(buf2, 0, sizeof(buf2));
353 memset(buf3, 0, sizeof(buf3));
354 if (chance((spy + vis) / 10.0)) {
355 if (destination == player->cnum)
356 pr("%s %s", mess, prland(lp));
358 sprintf(buf1, "%s %s", mess, prland(lp));
360 if (chance((spy + vis) / 20.0)) {
361 if (destination == player->cnum)
362 pr(" (eff %d, mil %d",
363 roundintby(lp->lnd_effic, 5),
364 roundintby(lp->lnd_item[I_MILIT], 10));
366 sprintf(buf2, " (eff %d, mil %d",
367 roundintby(lp->lnd_effic, 5),
368 roundintby(lp->lnd_item[I_MILIT], 10));
370 if (chance((spy + vis) / 20.0)) {
372 t = lp->lnd_tech - 20 + roll(40);
374 if (destination == player->cnum)
375 pr(", tech %d)\n", t);
377 sprintf(buf3, ", tech %d)\n", t);
379 if (destination == player->cnum)
382 sprintf(buf3, ")\n");
385 if (destination == player->cnum)
392 if (destination != player->cnum) {
393 wu(0, destination, "%s%s%s", buf1, buf2, buf3);
398 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
404 int mobtype = MOB_MOVE; /* indeterminate */
407 while (nxtitem(ni, &land)) {
411 if (ontradingblock(EF_LAND, &land)) {
412 pr("unit #%d inelligible - it's for sale.\n",
418 * The marching code gets confused when trains and non-trains
419 * march together. Disallow for now.
421 this_mot = lnd_mobtype(&land);
422 if (this_mot != mobtype) {
423 if (mobtype == MOB_MOVE)
425 else if (mobtype == MOB_MARCH) {
426 pr("%s is a train and can't march with the leader.\n",
430 pr("%s can't rail-march with the leading train.\n",
436 lcp = &lchr[(int)land.lnd_type];
437 land.lnd_mission = 0;
440 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
441 putland(land.lnd_uid, &land);
442 llp = malloc(sizeof(struct ulist));
443 llp->chrp = (struct empobj_chr *)lcp;
444 llp->unit.land = land;
445 llp->mobil = land.lnd_mobil;
446 emp_insque(&llp->queue, list);
450 /* This function assumes that the list was created by lnd_sel */
452 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
453 int *togetherp, natid actor)
455 struct emp_qelem *qp;
456 struct emp_qelem *next;
469 for (qp = list->q_back; qp != list; qp = next) {
471 llp = (struct ulist *)qp;
472 getland(llp->unit.land.lnd_uid, &land);
473 if (land.lnd_own != actor) {
474 mpr(actor, "%s was disbanded at %s\n",
475 prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
476 emp_remque((struct emp_qelem *)llp);
480 if (land.lnd_ship >= 0) {
481 lnd_mess("is on a ship", llp);
484 if (land.lnd_land >= 0) {
485 lnd_mess("is on a unit", llp);
488 if (!getsect(land.lnd_x, land.lnd_y, §)) {
489 lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
492 if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
493 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_TRAIN) &&
494 llp->unit.land.lnd_item[I_MILIT] == 0) {
495 lnd_mess("has no mil on it to guide it", llp);
498 rel = getrel(getnatp(sect.sct_own), player->cnum);
499 if (sect.sct_own != land.lnd_own && rel != ALLIED &&
500 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
502 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
511 if (land.lnd_x != allx || land.lnd_y != ally)
513 if (land.lnd_mobil + 1 < (int)llp->mobil) {
514 llp->mobil = land.lnd_mobil;
516 if (llp->mobil < *minmobp)
517 *minmobp = llp->mobil;
518 if (llp->mobil > *maxmobp)
519 *maxmobp = llp->mobil;
520 llp->unit.land = land;
525 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
528 struct emp_qelem *qp;
529 struct emp_qelem *next;
532 int mines, m, max, sshells, lshells;
534 for (qp = land_list->q_back; qp != land_list; qp = next) {
536 llp = (struct ulist *)qp;
537 if (!(((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)) {
539 mpr(actor, "%s is not an engineer!\n",
540 prland(&llp->unit.land));
543 if (takemob && llp->mobil < 0.0) {
545 lnd_mess("is out of mobility", llp);
548 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
549 if (sect.sct_oldown == llp->unit.land.lnd_own) {
552 "%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
553 prland(&llp->unit.land));
556 if (SCT_MINES_ARE_SEAMINES(§)) {
558 mpr(actor, "%s is in a %s sector. No landmines there!\n",
559 prland(&llp->unit.land), dchr[sect.sct_type].d_name);
563 llp->mobil -= lnd_pathcost(&llp->unit.land, 0.2);
564 llp->unit.land.lnd_mobil = (int)llp->mobil;
565 llp->unit.land.lnd_harden = 0;
567 putland(llp->unit.land.lnd_uid, &llp->unit.land);
568 if (!(mines = sect.sct_mines))
570 max = ((struct lchrstr *)llp->chrp)->l_item[I_SHELL];
571 lshells = llp->unit.land.lnd_item[I_SHELL];
572 sshells = sect.sct_item[I_SHELL];
573 for (m = 0; mines > 0 && m < max * 2; m++) {
574 if (chance(0.5 * ((struct lchrstr *)llp->chrp)->l_att)) {
575 mpr(actor, "Sweep...\n");
579 else if (sshells < ITEM_MAX)
583 sect.sct_mines = mines;
584 llp->unit.land.lnd_item[I_SHELL] = lshells;
585 sect.sct_item[I_SHELL] = sshells;
586 putland(llp->unit.land.lnd_uid, &llp->unit.land);
592 contains_engineer(struct emp_qelem *list)
594 struct emp_qelem *qp;
595 struct emp_qelem *next;
598 for (qp = list->q_back; qp != list; qp = next) {
600 llp = (struct ulist *)qp;
601 if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
608 lnd_check_mines(struct emp_qelem *land_list)
610 struct emp_qelem *qp;
611 struct emp_qelem *next;
615 int with_eng = contains_engineer(land_list);
617 for (qp = land_list->q_back; qp != land_list; qp = next) {
619 llp = (struct ulist *)qp;
620 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
621 if (sect.sct_oldown == llp->unit.land.lnd_own)
623 if (SCT_LANDMINES(§) == 0)
625 if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
626 lnd_hit_mine(&llp->unit.land, ((struct lchrstr *)llp->chrp));
629 putland(llp->unit.land.lnd_uid, &llp->unit.land);
630 if (!llp->unit.land.lnd_own) {
641 lnd_mess(char *str, struct ulist *llp)
643 mpr(llp->unit.land.lnd_own, "%s %s & stays in %s\n",
644 prland(&llp->unit.land),
645 str, xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
646 llp->unit.land.lnd_own));
647 if (llp->mobil < -127)
649 llp->unit.land.lnd_mobil = llp->mobil;
650 putland(llp->unit.land.lnd_uid, &llp->unit.land);
651 emp_remque((struct emp_qelem *)llp);
656 lnd_count(struct emp_qelem *list)
658 struct emp_qelem *qp;
659 struct emp_qelem *next;
662 for (qp = list->q_back; qp != list; qp = next) {
670 lnd_damage(struct emp_qelem *list, int totdam)
672 struct emp_qelem *qp;
673 struct emp_qelem *next;
678 if (!totdam || !(count = lnd_count(list)))
680 dam = ldround((double)totdam / count, 1);
681 for (qp = list->q_back; qp != list; qp = next) {
683 llp = (struct ulist *)qp;
684 /* have to get it again because of collateral damage */
685 getland(llp->unit.land.lnd_uid, &llp->unit.land);
686 landdamage(&llp->unit.land, dam);
687 putland(llp->unit.land.lnd_uid, &llp->unit.land);
688 if (!llp->unit.land.lnd_own) {
697 lnd_easiest_target(struct emp_qelem *list)
699 struct emp_qelem *qp;
700 struct emp_qelem *next;
703 int easiest = 9876; /* things start great for victim */
706 for (qp = list->q_back; qp != list; qp = next) {
708 llp = (struct ulist *)qp;
709 hard = lnd_hardtarget(&llp->unit.land);
711 easiest = hard; /* things get worse for victim */
714 return easiest - count;
718 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
721 int mindam = lnd_count(list) * 20;
722 int hardtarget = lnd_easiest_target(list);
723 int dam, newdam, sublaunch;
725 struct emp_qelem msl_list, *qp, *newqp;
727 msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
730 for (qp = msl_list.q_back; qp != &msl_list; qp = newqp) {
732 plp = (struct plist *)qp;
734 if (dam < mindam && mission_pln_equip(plp, NULL, 'p') >= 0) {
735 if (msl_launch(&plp->plane, EF_LAND, "troops",
736 newx, newy, victim, &sublaunch) < 0)
738 if (msl_hit(&plp->plane, hardtarget, EF_LAND,
739 N_LND_MISS, N_LND_SMISS, sublaunch, victim)) {
740 newdam = pln_damage(&plp->plane, 'p', 1);
743 newdam = pln_damage(&plp->plane, 'p', 0);
744 collateral_damage(newx, newy, newdam);
747 plp->plane.pln_effic = 0;
748 putplane(plp->plane.pln_uid, &plp->plane);
755 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
756 collateral_damage(newx, newy, dam);
762 /* Steve M. - commented out for now until abuse is decided upon */
763 /* risner: allow forts to interdict land units. */
765 lnd_fort_interdiction(struct emp_qelem *list,
766 coord newx, coord newy, natid victim)
777 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
778 while (nxtsct(&ns, &fsect)) {
779 if (fsect.sct_own == 0)
781 if (fsect.sct_own == victim)
783 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
785 range = roundrange(fortrange(&fsect));
786 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
789 dam = fort_fire(&fsect);
794 mpr(victim, "Incoming fire does %d damage!\n", dam);
796 "%s fires at %s land units in %s for %d!\n",
797 xyas(fsect.sct_x, fsect.sct_y,
799 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
800 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
803 return lnd_damage(list, totdam);
809 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
814 if (!opt_NO_FORT_FIRE)
815 /* Steve M. - commented out for now until abuse is decided upon */
816 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
821 unit_interdict(newx, newy, victim, "land units",
822 lnd_easiest_target(list), MI_INTERDICT));
826 lnd_missile_interdiction(list, newx, newy, victim));
830 /* high value of hardtarget is harder to hit */
832 lnd_hardtarget(struct lndstr *lp)
836 getsect(lp->lnd_x, lp->lnd_y, §);
837 return (int)((lp->lnd_effic / 100.0) *
838 (10 + dchr[sect.sct_type].d_dstr * 2 + lnd_spd(lp) / 2.0
843 lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
847 mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
848 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
850 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
853 if (lcp->l_flags & L_ENGINEER)
861 lnd_pathcost(struct lndstr *lp, double pathcost)
865 effspd = lnd_spd(lp);
866 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
867 effspd *= lp->lnd_effic * 0.01;
870 * The return value must be PATHCOST times a factor that depends
871 * only on the land unit. Anything else breaks path finding. In
872 * particular, you can't add or enforce a minimum cost here. Do
873 * it in sector_mcost().
875 return pathcost * 5.0 * speed_factor(effspd, lp->lnd_tech);
879 lnd_mobtype(struct lndstr *lp)
881 return (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
882 ? MOB_RAIL : MOB_MARCH;
886 lnd_mobcost(struct lndstr *lp, struct sctstr *sp)
888 return lnd_pathcost(lp, sector_mcost(sp, lnd_mobtype(lp)));
892 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
895 struct sctstr sect, osect;
896 struct emp_qelem *qp;
897 struct emp_qelem *qp2;
898 struct emp_qelem *next;
900 struct emp_qelem cur, done;
912 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
913 unit_put(list, actor);
918 for (qp = list->q_back; qp != list; qp = next) {
920 llp = (struct ulist *)qp;
921 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &osect);
922 oldown = osect.sct_own;
923 newx = xnorm(llp->unit.land.lnd_x + dx);
924 newy = ynorm(llp->unit.land.lnd_y + dy);
925 getsect(newx, newy, §);
926 rel = getrel(getnatp(sect.sct_own), player->cnum);
927 if ((sect.sct_own != actor && rel != ALLIED &&
928 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
929 sect.sct_own) || (sect.sct_type == SCT_WATER ||
930 sect.sct_type == SCT_SANCT ||
931 sect.sct_type == SCT_WASTE)) {
933 pr("can't go to %s\n", xyas(newx, newy, actor));
936 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
941 if (!SCT_HAS_RAIL(§)
942 && lnd_mobtype(&llp->unit.land) == MOB_RAIL) {
944 pr("no rail system in %s\n", xyas(newx, newy, actor));
947 sprintf(dp, "has no rail system in %s",
948 xyas(newx, newy, actor));
953 /* Note we check would_abandon first because we don't want
954 to always have to do these checks */
955 if (would_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
957 if (!want_to_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
960 /* now check stuff */
961 if (!check_sect_ok(§))
963 if (!check_sect_ok(&osect))
965 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
966 if (!check_land_ok(&((struct ulist *)qp2)->unit.land))
970 lnd_mess("stops", llp);
974 if (llp->mobil <= 0.0) {
975 lnd_mess("is out of mobility", llp);
978 llp->unit.land.lnd_x = newx;
979 llp->unit.land.lnd_y = newy;
980 llp->mobil -= lnd_mobcost(&llp->unit.land, §);
981 llp->unit.land.lnd_mobil = (int)llp->mobil;
982 llp->unit.land.lnd_harden = 0;
983 putland(llp->unit.land.lnd_uid, &llp->unit.land);
985 getsect(osect.sct_x, osect.sct_y, &osect);
986 if (osect.sct_own != oldown && oldown == player->cnum) {
987 /* It was your sector, now it's not. Simple :) */
988 pr("You no longer own %s\n",
989 xyas(osect.sct_x, osect.sct_y, player->cnum));
991 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
992 /* Always a 10% chance of getting caught. */
993 if (chance(LND_SPY_DETECT_CHANCE(llp->unit.land.lnd_effic))) {
994 if (rel == NEUTRAL || rel == FRIENDLY) {
996 "%s unit spotted in %s\n", cname(player->cnum),
997 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
998 setrel(sect.sct_own, llp->unit.land.lnd_own, HOSTILE);
999 } else if (rel == HOSTILE || rel == AT_WAR ||
1000 rel == SITZKRIEG || rel == MOBILIZATION) {
1002 "%s spy shot in %s\n", cname(player->cnum),
1003 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1004 pr("%s was shot and killed.\n", prland(&llp->unit.land));
1005 llp->unit.land.lnd_effic = 0;
1006 putland(llp->unit.land.lnd_uid, &llp->unit.land);
1007 lnd_delete(llp, NULL);
1014 lnd_sweep(list, 0, 1, actor);
1015 stopping |= lnd_check_mines(list);
1019 /* interdict land units sector by sector */
1022 while (!QEMPTY(list)) {
1023 llp = (struct ulist *)list->q_back;
1024 newx = llp->unit.land.lnd_x;
1025 newy = llp->unit.land.lnd_y;
1026 /* move units in NEWX,NEWY to cur */
1028 for (qp = list->q_back; qp != list; qp = next) {
1030 llp = (struct ulist *)qp;
1031 if (llp->unit.land.lnd_x == newx && llp->unit.land.lnd_y == newy) {
1033 emp_insque(qp, &cur);
1034 if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY))
1038 /* interdict them */
1040 stopping |= lnd_interdict(&cur, newx, newy, actor);
1041 /* move survivors to done */
1042 for (qp = cur.q_back; qp != &cur; qp = next) {
1044 llp = (struct ulist *)qp;
1046 emp_insque(qp, &done);
1049 /* assign surviving land units back to list */
1050 emp_insque(list, &done);
1057 * find all artillery units belonging
1058 * to the attacker or defender that can fire.
1059 * Each arty unit adds +1%/damage point
1062 lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
1064 struct nstr_item ni;
1072 snxtitem_all(&ni, EF_LAND);
1073 while (nxtitem(&ni, &land)) {
1074 if ((land.lnd_x == x) && (land.lnd_y == y))
1076 rel = getrel(getnatp(land.lnd_own), attacker);
1077 rel2 = getrel(getnatp(land.lnd_own), victim);
1078 if ((land.lnd_own != attacker) &&
1079 ((rel != ALLIED) || (rel2 != AT_WAR)))
1082 /* are we in range? */
1083 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1085 range = roundrange(lnd_fire_range(&land));
1089 dam2 = lnd_fire(&land);
1090 putland(land.lnd_uid, &land);
1095 nreport(land.lnd_own, N_FIRE_BACK, victim, 1);
1097 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1098 if (roll(100) < lnd_acc(&land))
1101 if (land.lnd_own != attacker)
1103 "%s supported %s at %s\n",
1104 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1110 lnd_can_attack(struct lndstr *lp)
1112 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1114 if (lcp->l_flags & L_SUPPLY)
1121 * Increase fortification value of LP.
1122 * Fortification costs mobility. Use up to MOB mobility.
1123 * Return actual fortification increase.
1126 lnd_fortify(struct lndstr *lp, int mob)
1129 double mob_used, mult;
1131 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
1134 mob_used = MIN(lp->lnd_mobil, mob);
1138 mult = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own)
1141 hard_amt = (int)(mob_used * mult);
1142 if (lp->lnd_harden + hard_amt > land_mob_max) {
1143 hard_amt = land_mob_max - lp->lnd_harden;
1144 mob_used = ceil(hard_amt / mult);
1147 lp->lnd_mobil -= (int)mob_used;
1148 lp->lnd_harden += hard_amt;
1149 lp->lnd_harden = MIN(lp->lnd_harden, land_mob_max);
1155 * Is there a engineer unit at X,Y that can help nation CN?
1158 has_helpful_engineer(coord x, coord y, natid cn)
1160 struct nstr_item ni;
1163 snxtitem_xy(&ni, EF_LAND, x, y);
1164 while (nxtitem(&ni, &land)) {
1165 if (land.lnd_own != cn && getrel(getnatp(land.lnd_own), cn) != ALLIED)
1167 if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER)
1175 * Set LP's tech to TLEV along with everything else that depends on it.
1178 lnd_set_tech(struct lndstr *lp, int tlev)
1180 struct lchrstr *lcp = lchr + lp->lnd_type;
1182 if (CANT_HAPPEN(tlev < lcp->l_tech))
1185 lp->lnd_tech = tlev;