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_stays(natid, 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(natid actor, struct ulist *llp, char *s)
141 if (actor == player->cnum)
142 pr("%s %s\n", prland(&llp->unit.land), s);
144 wu(0, actor, "%s %s\n", prland(&llp->unit.land), s);
148 lnd_delete(struct ulist *llp)
150 putland(llp->unit.land.lnd_uid, &llp->unit.land);
151 emp_remque((struct emp_qelem *)llp);
156 lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
157 /* attacking or assaulting or paratrooping? */
158 /* number of casualties to take */
171 int nowhere_to_go = 0;
173 double mobcost, bmcost;
177 taken = llp->unit.land.lnd_item[I_MILIT];
178 /* Spies always die */
179 if (((struct lchrstr *)llp->chrp)->l_flags & L_SPY)
180 llp->unit.land.lnd_effic = 0;
182 eff_eq = ldround(cas * 100.0 /
183 ((struct lchrstr *)llp->chrp)->l_item[I_MILIT], 1);
184 llp->unit.land.lnd_effic -= eff_eq;
185 lnd_submil(&llp->unit.land, cas);
188 if (llp->unit.land.lnd_effic < LAND_MINEFF) {
189 sprintf(buf, "dies %s %s!",
190 combat_mode ? att_mode[combat_mode] : "defending",
191 xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
192 llp->unit.land.lnd_own));
193 lnd_print(llp->unit.land.lnd_own, llp, buf);
195 /* Since we killed the unit, we killed all the mil on it */
198 /* Ok, now, how many did we take off? (sould be the diff) */
199 taken = taken - llp->unit.land.lnd_item[I_MILIT];
202 if (llp->unit.land.lnd_effic >= llp->unit.land.lnd_retreat)
205 /* we're being boarded */
206 if (llp->unit.land.lnd_ship >= 0 && combat_mode == A_DEFEND)
209 /* we're being boarded */
210 if (llp->unit.land.lnd_land >= 0 && combat_mode == A_DEFEND)
213 /* Have to make a retreat check */
215 ret_chance = llp->unit.land.lnd_retreat - llp->unit.land.lnd_effic;
216 if (roll(100) < ret_chance) {
218 lnd_print(llp->unit.land.lnd_own, llp, "fails morale check!");
219 llp->unit.land.lnd_mission = 0;
220 llp->unit.land.lnd_harden = 0;
221 if (llp->unit.land.lnd_ship >= 0 || llp->unit.land.lnd_land >= 0)
223 else if (combat_mode == A_DEFEND) {
225 * defending unit.. find a place to send it
226 * strategy: look for the most-populated
227 * adjacent sector that is owned by the unit
228 * owner. Charge mob..
232 for (n = 1; n <= 6; ++n) {
233 ret_x = llp->unit.land.lnd_x + diroff[n][0];
234 ret_y = llp->unit.land.lnd_y + diroff[n][1];
235 getsect(ret_x, ret_y, §);
236 if (sect.sct_own != llp->unit.land.lnd_own)
238 if (sect.sct_type == SCT_MOUNT)
240 mobcost = lnd_mobcost(&llp->unit.land, &rsect);
244 civs = sect.sct_item[I_CIVIL];
245 if (civs > biggest) {
255 /* retreat to bx,by */
256 llp->unit.land.lnd_x = bx;
257 llp->unit.land.lnd_y = by;
258 /* FIXME landmines */
259 getsect(bx, by, &rsect);
260 mob = llp->unit.land.lnd_mobil - (int)bmcost;
263 orig = llp->unit.land.lnd_mobil;
264 llp->unit.land.lnd_mobil = (signed char)mob;
265 if (llp->unit.land.lnd_mobil > orig)
266 llp->unit.land.lnd_mobil = -127;
267 sprintf(buf, "retreats at %d%% efficiency to %s!",
268 llp->unit.land.lnd_effic,
269 xyas(bx, by, llp->unit.land.lnd_own));
270 lnd_print(llp->unit.land.lnd_own, 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_print(llp->unit.land.lnd_own, 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_print(llp->unit.land.lnd_own, llp,
292 "has nowhere to retreat, and dies!");
295 lnd_print(llp->unit.land.lnd_own, llp,
296 "has nowhere to retreat and takes extra losses!");
303 lnd_takemob(struct emp_qelem *list, double loss)
305 struct emp_qelem *qp, *next;
308 int mcost = ldround(combat_mob * loss, 1);
310 for (qp = list->q_forw; qp != list; qp = next) {
312 llp = (struct ulist *)qp;
315 use_supply(&llp->unit.land);
317 new = llp->unit.land.lnd_mobil - mcost;
320 llp->unit.land.lnd_mobil = (signed char)new;
325 lnd_submil(struct lndstr *lp, int num)
327 int new = lp->lnd_item[I_MILIT] - num;
328 lp->lnd_item[I_MILIT] = new < 0 ? 0 : new;
332 lnd_spyval(struct lndstr *lp)
334 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
335 return lchr[lp->lnd_type].l_spy * (lp->lnd_effic / 100.0) + 2;
337 return lchr[lp->lnd_type].l_spy * (lp->lnd_effic / 100.0);
341 intelligence_report(int destination, struct lndstr *lp, int spy,
344 int vis = lnd_vis(lp);
345 char buf1[80], buf2[80], buf3[80];
347 if (destination == 0)
350 if (lp->lnd_own == 0)
353 memset(buf1, 0, sizeof(buf1));
354 memset(buf2, 0, sizeof(buf2));
355 memset(buf3, 0, sizeof(buf3));
356 if (chance((spy + vis) / 10.0)) {
357 if (destination == player->cnum)
358 pr("%s %s", mess, prland(lp));
360 sprintf(buf1, "%s %s", mess, prland(lp));
362 if (chance((spy + vis) / 20.0)) {
363 if (destination == player->cnum)
364 pr(" (eff %d, mil %d",
365 roundintby(lp->lnd_effic, 5),
366 roundintby(lp->lnd_item[I_MILIT], 10));
368 sprintf(buf2, " (eff %d, mil %d",
369 roundintby(lp->lnd_effic, 5),
370 roundintby(lp->lnd_item[I_MILIT], 10));
372 if (chance((spy + vis) / 20.0)) {
374 t = lp->lnd_tech - 20 + roll(40);
376 if (destination == player->cnum)
377 pr(", tech %d)\n", t);
379 sprintf(buf3, ", tech %d)\n", t);
381 if (destination == player->cnum)
384 sprintf(buf3, ")\n");
387 if (destination == player->cnum)
394 if (destination != player->cnum) {
395 wu(0, destination, "%s%s%s", buf1, buf2, buf3);
400 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
406 int mobtype = MOB_MOVE; /* indeterminate */
409 while (nxtitem(ni, &land)) {
411 * It would be nice to let deities march foreign land units,
412 * but much of the code assumes that only the land unit's
413 * owner can march it.
415 if (land.lnd_own != player->cnum)
418 if (ontradingblock(EF_LAND, &land)) {
419 pr("unit #%d inelligible - it's for sale.\n",
425 * The marching code gets confused when trains and non-trains
426 * march together. Disallow for now.
428 this_mot = lnd_mobtype(&land);
429 if (this_mot != mobtype) {
430 if (mobtype == MOB_MOVE)
432 else if (mobtype == MOB_MARCH) {
433 pr("%s is a train and can't march with the leader.\n",
437 pr("%s can't rail-march with the leading train.\n",
443 lcp = &lchr[(int)land.lnd_type];
444 land.lnd_mission = 0;
447 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
448 putland(land.lnd_uid, &land);
449 llp = malloc(sizeof(struct ulist));
450 llp->chrp = (struct empobj_chr *)lcp;
451 llp->unit.land = land;
452 llp->mobil = land.lnd_mobil;
453 emp_insque(&llp->queue, list);
457 /* This function assumes that the list was created by lnd_sel */
459 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
460 int *togetherp, natid actor)
462 struct emp_qelem *qp;
463 struct emp_qelem *next;
476 for (qp = list->q_back; qp != list; qp = next) {
478 llp = (struct ulist *)qp;
479 getland(llp->unit.land.lnd_uid, &land);
480 if (land.lnd_own != actor) {
481 mpr(actor, "%s was disbanded at %s\n",
482 prland(&land), xyas(land.lnd_x, land.lnd_y, actor));
483 emp_remque((struct emp_qelem *)llp);
487 if (land.lnd_ship >= 0) {
488 lnd_stays(actor, "is on a ship", llp);
491 if (land.lnd_land >= 0) {
492 lnd_stays(actor, "is on a unit", llp);
495 if (!getsect(land.lnd_x, land.lnd_y, §)) {
496 lnd_stays(actor, "was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
499 if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
500 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_TRAIN) &&
501 llp->unit.land.lnd_item[I_MILIT] == 0) {
502 lnd_stays(actor, "has no mil on it to guide it", llp);
505 rel = getrel(getnatp(sect.sct_own), player->cnum);
506 if (sect.sct_own != land.lnd_own && rel != ALLIED &&
507 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
509 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
510 lnd_stays(actor, mess, llp);
518 if (land.lnd_x != allx || land.lnd_y != ally)
520 if (land.lnd_mobil + 1 < (int)llp->mobil) {
521 llp->mobil = land.lnd_mobil;
523 if (llp->mobil < *minmobp)
524 *minmobp = llp->mobil;
525 if (llp->mobil > *maxmobp)
526 *maxmobp = llp->mobil;
527 llp->unit.land = land;
532 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
535 struct emp_qelem *qp;
536 struct emp_qelem *next;
539 int mines, m, max, sshells, lshells;
541 for (qp = land_list->q_back; qp != land_list; qp = next) {
543 llp = (struct ulist *)qp;
544 if (!(((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)) {
546 mpr(actor, "%s is not an engineer!\n",
547 prland(&llp->unit.land));
550 if (takemob && llp->mobil < 0.0) {
552 lnd_stays(actor, "is out of mobility", llp);
555 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
556 if (sect.sct_oldown == llp->unit.land.lnd_own) {
559 "%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
560 prland(&llp->unit.land));
563 if (SCT_MINES_ARE_SEAMINES(§)) {
565 mpr(actor, "%s is in a %s sector. No landmines there!\n",
566 prland(&llp->unit.land), dchr[sect.sct_type].d_name);
570 llp->mobil -= lnd_pathcost(&llp->unit.land, 0.2);
571 llp->unit.land.lnd_mobil = (int)llp->mobil;
572 llp->unit.land.lnd_harden = 0;
574 putland(llp->unit.land.lnd_uid, &llp->unit.land);
575 if (!(mines = sect.sct_mines))
577 max = ((struct lchrstr *)llp->chrp)->l_item[I_SHELL];
578 lshells = llp->unit.land.lnd_item[I_SHELL];
579 sshells = sect.sct_item[I_SHELL];
580 for (m = 0; mines > 0 && m < max * 2; m++) {
581 if (chance(0.5 * ((struct lchrstr *)llp->chrp)->l_att)) {
582 mpr(actor, "Sweep...\n");
586 else if (sshells < ITEM_MAX)
590 sect.sct_mines = mines;
591 llp->unit.land.lnd_item[I_SHELL] = lshells;
592 sect.sct_item[I_SHELL] = sshells;
593 putland(llp->unit.land.lnd_uid, &llp->unit.land);
599 contains_engineer(struct emp_qelem *list)
601 struct emp_qelem *qp;
602 struct emp_qelem *next;
605 for (qp = list->q_back; qp != list; qp = next) {
607 llp = (struct ulist *)qp;
608 if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
615 lnd_check_mines(struct emp_qelem *land_list)
617 struct emp_qelem *qp;
618 struct emp_qelem *next;
622 int with_eng = contains_engineer(land_list);
624 for (qp = land_list->q_back; qp != land_list; qp = next) {
626 llp = (struct ulist *)qp;
627 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
628 if (sect.sct_oldown == llp->unit.land.lnd_own)
630 if (SCT_LANDMINES(§) == 0)
632 if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
633 lnd_hit_mine(&llp->unit.land);
636 putland(llp->unit.land.lnd_uid, &llp->unit.land);
637 if (!llp->unit.land.lnd_own) {
648 lnd_stays(natid actor, char *str, struct ulist *llp)
650 mpr(actor, "%s %s & stays in %s\n",
651 prland(&llp->unit.land), str,
652 xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y, actor));
653 if (llp->mobil < -127)
655 llp->unit.land.lnd_mobil = llp->mobil;
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)
782 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
783 while (nxtsct(&ns, &fsect)) {
784 if (fsect.sct_own == 0)
786 if (fsect.sct_own == victim)
788 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
790 range = roundrange(fortrange(&fsect));
791 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
794 dam = fort_fire(&fsect);
800 mpr(victim, "Incoming fire does %d damage!\n", dam);
802 "%s fires at %s land units in %s for %d!\n",
803 xyas(fsect.sct_x, fsect.sct_y,
805 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
806 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
809 lnd_damage(list, totdam);
815 lnd_mission_interdiction(struct emp_qelem *list, coord x, coord y,
820 dam = unit_interdict(x, y, victim, "land units",
821 lnd_easiest_target(list),
824 lnd_damage(list, dam);
829 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
834 if (!opt_NO_FORT_FIRE)
835 /* Steve M. - commented out for now until abuse is decided upon */
836 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
839 stopping |= lnd_mission_interdiction(list, newx, newy, victim);
840 stopping |= lnd_missile_interdiction(list, newx, newy, victim);
844 /* high value of hardtarget is harder to hit */
846 lnd_hardtarget(struct lndstr *lp)
850 getsect(lp->lnd_x, lp->lnd_y, §);
851 return (int)((lp->lnd_effic / 100.0) *
852 (10 + dchr[sect.sct_type].d_dstr * 2 + lnd_spd(lp) / 2.0
857 lnd_hit_mine(struct lndstr *lp)
861 mpr(lp->lnd_own, "Blammo! Landmines detected in %s!\n",
862 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
864 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
867 if (lchr[lp->lnd_type].l_flags & L_ENGINEER)
875 lnd_pathcost(struct lndstr *lp, double pathcost)
879 effspd = lnd_spd(lp);
880 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
881 effspd *= lp->lnd_effic * 0.01;
884 * The return value must be PATHCOST times a factor that depends
885 * only on the land unit. Anything else breaks path finding. In
886 * particular, you can't add or enforce a minimum cost here. Do
887 * it in sector_mcost().
889 return pathcost * 5.0 * speed_factor(effspd, lp->lnd_tech);
893 lnd_mobtype(struct lndstr *lp)
895 return (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
896 ? MOB_RAIL : MOB_MARCH;
900 lnd_mobcost(struct lndstr *lp, struct sctstr *sp)
902 return lnd_pathcost(lp, sector_mcost(sp, lnd_mobtype(lp)));
906 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
909 struct sctstr sect, osect;
910 struct emp_qelem *qp;
911 struct emp_qelem *qp2;
912 struct emp_qelem *next;
914 struct emp_qelem cur, done;
926 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
927 unit_put(list, actor);
932 for (qp = list->q_back; qp != list; qp = next) {
934 llp = (struct ulist *)qp;
935 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &osect);
936 oldown = osect.sct_own;
937 newx = xnorm(llp->unit.land.lnd_x + dx);
938 newy = ynorm(llp->unit.land.lnd_y + dy);
939 getsect(newx, newy, §);
940 rel = getrel(getnatp(sect.sct_own), player->cnum);
941 if ((sect.sct_own != actor && rel != ALLIED &&
942 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
943 sect.sct_own) || (sect.sct_type == SCT_WATER ||
944 sect.sct_type == SCT_SANCT ||
945 sect.sct_type == SCT_WASTE)) {
947 mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
950 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
951 lnd_stays(actor, dp, llp);
955 if (!SCT_HAS_RAIL(§)
956 && lnd_mobtype(&llp->unit.land) == MOB_RAIL) {
958 mpr(actor, "no rail system in %s\n",
959 xyas(newx, newy, actor));
962 sprintf(dp, "has no rail system in %s",
963 xyas(newx, newy, actor));
964 lnd_stays(actor, dp, llp);
968 /* Note we check would_abandon first because we don't want
969 to always have to do these checks */
970 if (would_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
972 if (!want_to_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
975 /* now check stuff */
976 if (!check_sect_ok(§))
978 if (!check_sect_ok(&osect))
980 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
981 if (!check_land_ok(&((struct ulist *)qp2)->unit.land))
985 lnd_stays(actor, "stops", llp);
989 if (llp->mobil <= 0.0) {
990 lnd_stays(actor, "is out of mobility", llp);
993 llp->unit.land.lnd_x = newx;
994 llp->unit.land.lnd_y = newy;
995 llp->mobil -= lnd_mobcost(&llp->unit.land, §);
996 llp->unit.land.lnd_mobil = (int)llp->mobil;
997 llp->unit.land.lnd_harden = 0;
998 putland(llp->unit.land.lnd_uid, &llp->unit.land);
1000 getsect(osect.sct_x, osect.sct_y, &osect);
1001 if (osect.sct_own != oldown && oldown == player->cnum) {
1002 /* It was your sector, now it's not. Simple :) */
1003 mpr(actor, "You no longer own %s\n",
1004 xyas(osect.sct_x, osect.sct_y, actor));
1006 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
1007 /* Always a 10% chance of getting caught. */
1008 if (chance(LND_SPY_DETECT_CHANCE(llp->unit.land.lnd_effic))) {
1009 if (rel == NEUTRAL || rel == FRIENDLY) {
1011 "%s unit spotted in %s\n", cname(player->cnum),
1012 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1013 setrel(sect.sct_own, llp->unit.land.lnd_own, HOSTILE);
1014 } else if (rel == HOSTILE || rel == AT_WAR ||
1015 rel == SITZKRIEG || rel == MOBILIZATION) {
1017 "%s spy shot in %s\n", cname(player->cnum),
1018 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1019 mpr(actor, "%s was shot and killed.\n",
1020 prland(&llp->unit.land));
1021 llp->unit.land.lnd_effic = 0;
1022 putland(llp->unit.land.lnd_uid, &llp->unit.land);
1030 lnd_sweep(list, 0, 1, actor);
1031 stopping |= lnd_check_mines(list);
1035 /* interdict land units sector by sector */
1038 while (!QEMPTY(list)) {
1039 llp = (struct ulist *)list->q_back;
1040 newx = llp->unit.land.lnd_x;
1041 newy = llp->unit.land.lnd_y;
1042 /* move units in NEWX,NEWY to cur */
1044 for (qp = list->q_back; qp != list; qp = next) {
1046 llp = (struct ulist *)qp;
1047 if (llp->unit.land.lnd_x == newx && llp->unit.land.lnd_y == newy) {
1049 emp_insque(qp, &cur);
1050 if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY))
1054 /* interdict them */
1056 stopping |= lnd_interdict(&cur, newx, newy, actor);
1057 /* move survivors to done */
1058 for (qp = cur.q_back; qp != &cur; qp = next) {
1061 emp_insque(qp, &done);
1064 /* assign surviving land units back to list */
1065 emp_insque(list, &done);
1072 * find all artillery units belonging
1073 * to the attacker or defender that can fire.
1074 * Each arty unit adds +1%/damage point
1077 lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
1079 struct nstr_item ni;
1087 snxtitem_all(&ni, EF_LAND);
1088 while (nxtitem(&ni, &land)) {
1089 if ((land.lnd_x == x) && (land.lnd_y == y))
1091 rel = getrel(getnatp(land.lnd_own), attacker);
1092 rel2 = getrel(getnatp(land.lnd_own), victim);
1093 if ((land.lnd_own != attacker) &&
1094 ((rel != ALLIED) || (rel2 != AT_WAR)))
1097 /* are we in range? */
1098 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1100 range = roundrange(lnd_fire_range(&land));
1104 dam2 = lnd_fire(&land);
1105 putland(land.lnd_uid, &land);
1110 nreport(land.lnd_own, N_FIRE_BACK, victim, 1);
1112 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1113 if (roll(100) < lnd_acc(&land))
1116 if (land.lnd_own != attacker)
1118 "%s supported %s at %s\n",
1119 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1125 lnd_can_attack(struct lndstr *lp)
1127 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1129 if (lcp->l_flags & L_SUPPLY)
1136 * Increase fortification value of LP.
1137 * Fortification costs mobility. Use up to MOB mobility.
1138 * Return actual fortification increase.
1141 lnd_fortify(struct lndstr *lp, int mob)
1144 double mob_used, mult;
1146 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
1149 mob_used = MIN(lp->lnd_mobil, mob);
1153 mult = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own)
1156 hard_amt = (int)(mob_used * mult);
1157 if (lp->lnd_harden + hard_amt > land_mob_max) {
1158 hard_amt = land_mob_max - lp->lnd_harden;
1159 mob_used = ceil(hard_amt / mult);
1162 lp->lnd_mobil -= (int)mob_used;
1163 lp->lnd_harden += hard_amt;
1164 lp->lnd_harden = MIN(lp->lnd_harden, land_mob_max);
1170 * Is there a engineer unit at X,Y that can help nation CN?
1173 has_helpful_engineer(coord x, coord y, natid cn)
1175 struct nstr_item ni;
1178 snxtitem_xy(&ni, EF_LAND, x, y);
1179 while (nxtitem(&ni, &land)) {
1180 if (land.lnd_own != cn && getrel(getnatp(land.lnd_own), cn) != ALLIED)
1182 if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER)
1190 * Set LP's tech to TLEV along with everything else that depends on it.
1193 lnd_set_tech(struct lndstr *lp, int tlev)
1195 struct lchrstr *lcp = lchr + lp->lnd_type;
1197 if (CANT_HAPPEN(tlev < lcp->l_tech))
1200 lp->lnd_tech = tlev;