2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * lndsub.c: Land unit subroutines
29 * Known contributors to this file:
31 * Steve McClure, 1998-2000
32 * Markus Armbruster, 2004-2010
50 #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 */
170 int nowhere_to_go = 0;
171 double mobcost, bmcost;
175 taken = llp->unit.land.lnd_item[I_MILIT];
176 /* Spies always die */
177 if (((struct lchrstr *)llp->chrp)->l_flags & L_SPY)
178 llp->unit.land.lnd_effic = 0;
180 eff_eq = ldround(cas * 100.0 /
181 ((struct lchrstr *)llp->chrp)->l_item[I_MILIT], 1);
182 llp->unit.land.lnd_effic -= eff_eq;
183 lnd_submil(&llp->unit.land, cas);
186 if (llp->unit.land.lnd_effic < LAND_MINEFF) {
187 sprintf(buf, "dies %s %s!",
188 combat_mode ? att_mode[combat_mode] : "defending",
189 xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
190 llp->unit.land.lnd_own));
191 lnd_print(llp->unit.land.lnd_own, llp, buf);
193 /* Since we killed the unit, we killed all the mil on it */
196 /* Ok, now, how many did we take off? (sould be the diff) */
197 taken = taken - llp->unit.land.lnd_item[I_MILIT];
200 if (llp->unit.land.lnd_effic >= llp->unit.land.lnd_retreat)
203 /* we're being boarded */
204 if (llp->unit.land.lnd_ship >= 0 && combat_mode == A_DEFEND)
207 /* we're being boarded */
208 if (llp->unit.land.lnd_land >= 0 && combat_mode == A_DEFEND)
211 /* Have to make a retreat check */
213 ret_chance = llp->unit.land.lnd_retreat - llp->unit.land.lnd_effic;
214 if (roll(100) < ret_chance) {
216 lnd_print(llp->unit.land.lnd_own, llp, "fails morale check!");
217 llp->unit.land.lnd_mission = 0;
218 llp->unit.land.lnd_harden = 0;
219 if (llp->unit.land.lnd_ship >= 0 || llp->unit.land.lnd_land >= 0)
221 else if (combat_mode == A_DEFEND) {
223 * defending unit.. find a place to send it
224 * strategy: look for the most-populated
225 * adjacent sector that is owned by the unit
226 * owner. Charge mob..
229 for (n = 1; n <= 6; ++n) {
230 ret_x = llp->unit.land.lnd_x + diroff[n][0];
231 ret_y = llp->unit.land.lnd_y + diroff[n][1];
232 getsect(ret_x, ret_y, §);
233 if (sect.sct_own != llp->unit.land.lnd_own)
235 if (sect.sct_type == SCT_MOUNT)
237 mobcost = lnd_mobcost(&llp->unit.land, §);
240 civs = sect.sct_item[I_CIVIL];
241 if (civs > biggest) {
251 /* retreat to bx,by */
252 llp->unit.land.lnd_x = bx;
253 llp->unit.land.lnd_y = by;
254 /* FIXME landmines */
255 mob = llp->unit.land.lnd_mobil - (int)bmcost;
258 orig = llp->unit.land.lnd_mobil;
259 llp->unit.land.lnd_mobil = (signed char)mob;
260 if (llp->unit.land.lnd_mobil > orig)
261 llp->unit.land.lnd_mobil = -127;
262 sprintf(buf, "retreats at %d%% efficiency to %s!",
263 llp->unit.land.lnd_effic,
264 xyas(bx, by, llp->unit.land.lnd_own));
265 lnd_print(llp->unit.land.lnd_own, llp, buf);
268 } else { /* attacking from a sector */
269 sprintf(buf, "leaves the battlefield at %d%% efficiency",
270 llp->unit.land.lnd_effic);
271 if ((llp->unit.land.lnd_mobil - (int)llp->mobil) < -127)
272 llp->unit.land.lnd_mobil = -127;
274 llp->unit.land.lnd_mobil -= (int)llp->mobil;
276 lnd_print(llp->unit.land.lnd_own, llp, buf);
281 /* nowhere to go.. take more casualties */
282 llp->unit.land.lnd_effic -= 10;
283 lnd_submil(&llp->unit.land,
284 ((struct lchrstr *)llp->chrp)->l_item[I_MILIT] / 10);
285 if (llp->unit.land.lnd_effic < LAND_MINEFF) {
286 lnd_print(llp->unit.land.lnd_own, llp,
287 "has nowhere to retreat, and dies!");
290 lnd_print(llp->unit.land.lnd_own, llp,
291 "has nowhere to retreat and takes extra losses!");
298 lnd_takemob(struct emp_qelem *list, double loss)
300 struct emp_qelem *qp, *next;
303 int mcost = ldround(combat_mob * loss, 1);
305 for (qp = list->q_forw; qp != list; qp = next) {
307 llp = (struct ulist *)qp;
310 use_supply(&llp->unit.land);
312 new = llp->unit.land.lnd_mobil - mcost;
315 llp->unit.land.lnd_mobil = (signed char)new;
320 lnd_submil(struct lndstr *lp, int num)
322 int new = lp->lnd_item[I_MILIT] - num;
323 lp->lnd_item[I_MILIT] = new < 0 ? 0 : new;
327 lnd_spyval(struct lndstr *lp)
329 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
330 return lchr[lp->lnd_type].l_spy * (lp->lnd_effic / 100.0) + 2;
332 return lchr[lp->lnd_type].l_spy * (lp->lnd_effic / 100.0);
336 intelligence_report(int destination, struct lndstr *lp, int spy,
339 int vis = lnd_vis(lp);
340 char buf1[80], buf2[80], buf3[80];
342 if (destination == 0)
345 if (lp->lnd_own == 0)
348 memset(buf1, 0, sizeof(buf1));
349 memset(buf2, 0, sizeof(buf2));
350 memset(buf3, 0, sizeof(buf3));
351 if (chance((spy + vis) / 10.0)) {
352 if (destination == player->cnum)
353 pr("%s %s", mess, prland(lp));
355 sprintf(buf1, "%s %s", mess, prland(lp));
357 if (chance((spy + vis) / 20.0)) {
358 if (destination == player->cnum)
359 pr(" (eff %d, mil %d",
360 roundintby(lp->lnd_effic, 5),
361 roundintby(lp->lnd_item[I_MILIT], 10));
363 sprintf(buf2, " (eff %d, mil %d",
364 roundintby(lp->lnd_effic, 5),
365 roundintby(lp->lnd_item[I_MILIT], 10));
367 if (chance((spy + vis) / 20.0)) {
369 t = lp->lnd_tech - 20 + roll(40);
371 if (destination == player->cnum)
372 pr(", tech %d)\n", t);
374 sprintf(buf3, ", tech %d)\n", t);
376 if (destination == player->cnum)
379 sprintf(buf3, ")\n");
382 if (destination == player->cnum)
389 if (destination != player->cnum) {
390 wu(0, destination, "%s%s%s", buf1, buf2, buf3);
395 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
401 int mobtype = MOB_MOVE; /* indeterminate */
404 while (nxtitem(ni, &land)) {
406 * It would be nice to let deities march foreign land units,
407 * but much of the code assumes that only the land unit's
408 * owner can march it.
410 if (!land.lnd_own || land.lnd_own != player->cnum)
413 if (ontradingblock(EF_LAND, &land)) {
414 pr("unit #%d inelligible - it's for sale.\n",
420 * The marching code gets confused when trains and non-trains
421 * march together. Disallow for now.
423 this_mot = lnd_mobtype(&land);
424 if (this_mot != mobtype) {
425 if (mobtype == MOB_MOVE)
427 else if (mobtype == MOB_MARCH) {
428 pr("%s is a train and can't march with the leader.\n",
432 pr("%s can't rail-march with the leading train.\n",
438 lcp = &lchr[(int)land.lnd_type];
439 land.lnd_mission = 0;
442 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
443 putland(land.lnd_uid, &land);
444 llp = malloc(sizeof(struct ulist));
445 llp->chrp = (struct empobj_chr *)lcp;
446 llp->unit.land = land;
447 llp->mobil = land.lnd_mobil;
448 emp_insque(&llp->queue, list);
452 /* This function assumes that the list was created by lnd_sel */
454 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
455 int *togetherp, natid actor)
457 struct emp_qelem *qp;
458 struct emp_qelem *next;
470 for (qp = list->q_back; qp != list; qp = next) {
472 llp = (struct ulist *)qp;
473 lp = &llp->unit.land;
474 getland(lp->lnd_uid, lp);
475 if (lp->lnd_own != actor) {
476 mpr(actor, "%s was disbanded at %s\n",
477 prland(lp), xyas(lp->lnd_x, lp->lnd_y, actor));
478 emp_remque((struct emp_qelem *)llp);
482 if (lp->lnd_ship >= 0) {
483 lnd_stays(actor, "is on a ship", llp);
486 if (lp->lnd_land >= 0) {
487 lnd_stays(actor, "is on a unit", llp);
490 if (!getsect(lp->lnd_x, lp->lnd_y, §)) {
491 lnd_stays(actor, "was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
494 if (!(lchr[lp->lnd_type].l_flags & L_SPY) &&
495 !(lchr[lp->lnd_type].l_flags & L_TRAIN) &&
496 lp->lnd_item[I_MILIT] == 0) {
497 lnd_stays(actor, "has no mil on it to guide it", llp);
500 if (relations_with(sect.sct_own, actor) != ALLIED &&
501 !(lchr[lp->lnd_type].l_flags & L_SPY) &&
503 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
504 lnd_stays(actor, mess, llp);
512 if (lp->lnd_x != allx || lp->lnd_y != ally)
514 if (lp->lnd_mobil + 1 < (int)llp->mobil) {
515 llp->mobil = lp->lnd_mobil;
517 if (llp->mobil < *minmobp)
518 *minmobp = llp->mobil;
519 if (llp->mobil > *maxmobp)
520 *maxmobp = llp->mobil;
525 * Sweep landmines with engineers in LAND_LIST for ACTOR.
526 * If EXPLICIT is non-zero, this is for an explicit sweep command from
527 * a player. Else it's an automatic "on the move" sweep.
528 * If TAKEMOB is non-zero, require and charge mobility.
531 lnd_sweep(struct emp_qelem *land_list, int explicit, int takemob,
534 struct emp_qelem *qp;
535 struct emp_qelem *next;
538 int mines, m, max, sshells, lshells;
540 for (qp = land_list->q_back; qp != land_list; qp = next) {
542 llp = (struct ulist *)qp;
543 if (!(((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)) {
545 mpr(actor, "%s is not an engineer!\n",
546 prland(&llp->unit.land));
549 if (takemob && llp->mobil < 0.0) {
551 lnd_stays(actor, "is out of mobility", llp);
554 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
555 if (!explicit && relations_with(sect.sct_oldown, actor) == ALLIED)
557 if (SCT_MINES_ARE_SEAMINES(§)) {
559 mpr(actor, "%s is in a %s sector. No landmines there!\n",
560 prland(&llp->unit.land), dchr[sect.sct_type].d_name);
564 llp->mobil -= lnd_pathcost(&llp->unit.land, 0.2);
565 llp->unit.land.lnd_mobil = (int)llp->mobil;
566 llp->unit.land.lnd_harden = 0;
568 putland(llp->unit.land.lnd_uid, &llp->unit.land);
569 if (!(mines = sect.sct_mines))
571 max = ((struct lchrstr *)llp->chrp)->l_item[I_SHELL];
572 lshells = llp->unit.land.lnd_item[I_SHELL];
573 sshells = sect.sct_item[I_SHELL];
574 for (m = 0; mines > 0 && m < max * 2; m++) {
575 if (chance(0.5 * ((struct lchrstr *)llp->chrp)->l_att)) {
576 mpr(actor, "Sweep...\n");
580 else if (sshells < ITEM_MAX)
584 sect.sct_mines = mines;
585 llp->unit.land.lnd_item[I_SHELL] = lshells;
586 sect.sct_item[I_SHELL] = sshells;
587 putland(llp->unit.land.lnd_uid, &llp->unit.land);
593 contains_engineer(struct emp_qelem *list)
595 struct emp_qelem *qp;
596 struct emp_qelem *next;
599 for (qp = list->q_back; qp != list; qp = next) {
601 llp = (struct ulist *)qp;
602 if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
609 lnd_check_mines(struct emp_qelem *land_list)
611 struct emp_qelem *qp;
612 struct emp_qelem *next;
616 int with_eng = contains_engineer(land_list);
618 for (qp = land_list->q_back; qp != land_list; qp = next) {
620 llp = (struct ulist *)qp;
621 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
622 if (SCT_LANDMINES(§) == 0)
624 if (relations_with(sect.sct_oldown, llp->unit.land.lnd_own)
627 if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
628 lnd_hit_mine(&llp->unit.land);
631 putland(llp->unit.land.lnd_uid, &llp->unit.land);
632 if (!llp->unit.land.lnd_own) {
643 lnd_stays(natid actor, char *str, struct ulist *llp)
645 mpr(actor, "%s %s & stays in %s\n",
646 prland(&llp->unit.land), str,
647 xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y, actor));
648 if (llp->mobil < -127)
650 llp->unit.land.lnd_mobil = llp->mobil;
655 lnd_count(struct emp_qelem *list)
657 struct emp_qelem *qp;
658 struct emp_qelem *next;
661 for (qp = list->q_back; qp != list; qp = next) {
669 lnd_damage(struct emp_qelem *list, int totdam)
671 struct emp_qelem *qp;
672 struct emp_qelem *next;
677 if (!totdam || !(count = lnd_count(list)))
679 dam = ldround((double)totdam / count, 1);
680 for (qp = list->q_back; qp != list; qp = next) {
682 llp = (struct ulist *)qp;
683 /* land unit might have changed (launched SAMs, collateral dmg) */
684 getland(llp->unit.land.lnd_uid, &llp->unit.land);
685 landdamage(&llp->unit.land, dam);
686 putland(llp->unit.land.lnd_uid, &llp->unit.land);
687 if (!llp->unit.land.lnd_own) {
696 lnd_easiest_target(struct emp_qelem *list)
698 struct emp_qelem *qp;
699 struct emp_qelem *next;
702 int easiest = 9876; /* things start great for victim */
705 for (qp = list->q_back; qp != list; qp = next) {
707 llp = (struct ulist *)qp;
708 hard = lnd_hardtarget(&llp->unit.land);
710 easiest = hard; /* things get worse for victim */
713 return easiest - count;
717 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
720 int mindam = lnd_count(list) * 20;
721 int hardtarget = lnd_easiest_target(list);
722 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)
739 if (msl_hit(&plp->plane, hardtarget, EF_LAND,
740 N_LND_MISS, N_LND_SMISS, sublaunch, victim)) {
741 newdam = pln_damage(&plp->plane, 'p', 1);
744 newdam = pln_damage(&plp->plane, 'p', 0);
745 collateral_damage(newx, newy, newdam);
748 plp->plane.pln_effic = 0;
749 putplane(plp->plane.pln_uid, &plp->plane);
756 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
757 collateral_damage(newx, newy, dam);
758 lnd_damage(list, dam);
764 /* Steve M. - commented out for now until abuse is decided upon */
765 /* risner: allow forts to interdict land units. */
767 lnd_fort_interdiction(struct emp_qelem *list,
768 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 (relations_with(fsect.sct_own, victim) >= NEUTRAL)
783 range = roundrange(fortrange(&fsect));
784 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
787 dam = fort_fire(&fsect);
793 mpr(victim, "Incoming fire does %d damage!\n", dam);
795 "%s fires at %s land units in %s for %d!\n",
796 xyas(fsect.sct_x, fsect.sct_y,
798 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
799 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
802 lnd_damage(list, totdam);
808 lnd_mission_interdiction(struct emp_qelem *list, coord x, coord y,
813 dam = unit_interdict(x, y, victim, "land units",
814 lnd_easiest_target(list),
817 lnd_damage(list, dam);
822 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
827 if (!opt_NO_FORT_FIRE)
828 /* Steve M. - commented out for now until abuse is decided upon */
829 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
832 stopping |= lnd_mission_interdiction(list, newx, newy, victim);
833 stopping |= lnd_missile_interdiction(list, newx, newy, victim);
837 /* high value of hardtarget is harder to hit */
839 lnd_hardtarget(struct lndstr *lp)
843 getsect(lp->lnd_x, lp->lnd_y, §);
844 return (int)((lp->lnd_effic / 100.0) *
845 (10 + dchr[sect.sct_type].d_dstr * 2 + lnd_spd(lp) / 2.0
850 lnd_hit_mine(struct lndstr *lp)
854 mpr(lp->lnd_own, "Blammo! Landmines detected in %s!\n",
855 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
857 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
860 if (lchr[lp->lnd_type].l_flags & L_ENGINEER)
868 lnd_pathcost(struct lndstr *lp, double pathcost)
872 effspd = lnd_spd(lp);
873 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
874 effspd *= lp->lnd_effic * 0.01;
877 * The return value must be PATHCOST times a factor that depends
878 * only on the land unit. Anything else breaks path finding. In
879 * particular, you can't add or enforce a minimum cost here. Do
880 * it in sector_mcost().
882 return pathcost * 5.0 * speed_factor(effspd, lp->lnd_tech);
886 lnd_mobtype(struct lndstr *lp)
888 return (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
889 ? MOB_RAIL : MOB_MARCH;
893 lnd_mobcost(struct lndstr *lp, struct sctstr *sp)
895 return lnd_pathcost(lp, sector_mcost(sp, lnd_mobtype(lp)));
899 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
902 struct sctstr sect, osect;
903 struct emp_qelem *qp;
904 struct emp_qelem *qp2;
905 struct emp_qelem *next;
907 struct emp_qelem cur, done;
919 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
920 unit_put(list, actor);
925 for (qp = list->q_back; qp != list; qp = next) {
927 llp = (struct ulist *)qp;
928 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &osect);
929 oldown = osect.sct_own;
930 newx = xnorm(llp->unit.land.lnd_x + dx);
931 newy = ynorm(llp->unit.land.lnd_y + dy);
932 getsect(newx, newy, §);
933 rel = relations_with(sect.sct_own, actor);
934 if ((rel != ALLIED &&
935 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
936 sect.sct_own) || (sect.sct_type == SCT_WATER ||
937 sect.sct_type == SCT_SANCT ||
938 sect.sct_type == SCT_WASTE)) {
940 mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
943 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
944 lnd_stays(actor, dp, llp);
948 if (!SCT_HAS_RAIL(§)
949 && lnd_mobtype(&llp->unit.land) == MOB_RAIL) {
951 mpr(actor, "no rail system in %s\n",
952 xyas(newx, newy, actor));
955 sprintf(dp, "has no rail system in %s",
956 xyas(newx, newy, actor));
957 lnd_stays(actor, dp, llp);
961 /* Note we check would_abandon first because we don't want
962 to always have to do these checks */
963 if (would_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
965 if (!want_to_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
968 /* now check stuff */
969 if (!check_sect_ok(§))
971 if (!check_sect_ok(&osect))
973 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
974 if (!check_land_ok(&((struct ulist *)qp2)->unit.land))
978 lnd_stays(actor, "stops", llp);
982 if (llp->mobil <= 0.0) {
983 lnd_stays(actor, "is out of mobility", llp);
986 llp->unit.land.lnd_x = newx;
987 llp->unit.land.lnd_y = newy;
988 llp->mobil -= lnd_mobcost(&llp->unit.land, §);
989 llp->unit.land.lnd_mobil = (int)llp->mobil;
990 llp->unit.land.lnd_harden = 0;
991 putland(llp->unit.land.lnd_uid, &llp->unit.land);
993 getsect(osect.sct_x, osect.sct_y, &osect);
994 if (osect.sct_own != oldown && oldown == actor) {
995 /* It was your sector, now it's not. Simple :) */
996 mpr(actor, "You no longer own %s\n",
997 xyas(osect.sct_x, osect.sct_y, actor));
999 if (rel != ALLIED && sect.sct_own) { /* must be a spy */
1000 /* Always a 10% chance of getting caught. */
1001 if (chance(LND_SPY_DETECT_CHANCE(llp->unit.land.lnd_effic))) {
1002 if (rel == NEUTRAL || rel == FRIENDLY) {
1004 "%s unit spotted in %s\n", cname(actor),
1005 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1006 setrel(sect.sct_own, llp->unit.land.lnd_own, HOSTILE);
1007 } else if (rel <= HOSTILE) {
1009 "%s spy shot in %s\n", cname(actor),
1010 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1011 mpr(actor, "%s was shot and killed.\n",
1012 prland(&llp->unit.land));
1013 llp->unit.land.lnd_effic = 0;
1014 putland(llp->unit.land.lnd_uid, &llp->unit.land);
1022 lnd_sweep(list, 0, 1, actor);
1023 stopping |= lnd_check_mines(list);
1027 /* interdict land units sector by sector */
1030 while (!QEMPTY(list)) {
1031 llp = (struct ulist *)list->q_back;
1032 newx = llp->unit.land.lnd_x;
1033 newy = llp->unit.land.lnd_y;
1034 /* move units in NEWX,NEWY to cur */
1036 for (qp = list->q_back; qp != list; qp = next) {
1038 llp = (struct ulist *)qp;
1039 if (llp->unit.land.lnd_x == newx && llp->unit.land.lnd_y == newy) {
1041 emp_insque(qp, &cur);
1042 if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY))
1046 /* interdict them */
1048 stopping |= lnd_interdict(&cur, newx, newy, actor);
1049 /* move survivors to done */
1050 for (qp = cur.q_back; qp != &cur; qp = next) {
1053 emp_insque(qp, &done);
1056 /* assign surviving land units back to list */
1057 emp_insque(list, &done);
1064 * Fire land unit support against VICTIM for ATTACKER, at X,Y.
1065 * If DEFENDING, this is defensive support, else offensive support.
1066 * Return total damage.
1069 lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
1071 struct nstr_item ni;
1078 snxtitem_all(&ni, EF_LAND);
1079 while (nxtitem(&ni, &land)) {
1080 if ((land.lnd_x == x) && (land.lnd_y == y))
1082 if (!feels_like_helping(land.lnd_own, attacker, victim))
1085 /* are we in range? */
1086 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1088 range = roundrange(lnd_fire_range(&land));
1092 dam2 = lnd_fire(&land);
1093 putland(land.lnd_uid, &land);
1098 nreport(land.lnd_own, N_FIRE_BACK, victim, 1);
1100 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1101 if (roll(100) < lnd_acc(&land))
1104 if (land.lnd_own != attacker)
1106 "%s supported %s at %s\n",
1107 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1113 lnd_can_attack(struct lndstr *lp)
1115 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1117 if (lcp->l_flags & L_SUPPLY)
1124 * Increase fortification value of LP.
1125 * Fortification costs mobility. Use up to MOB mobility.
1126 * Return actual fortification increase.
1129 lnd_fortify(struct lndstr *lp, int mob)
1132 double mob_used, mult;
1134 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
1137 mob_used = MIN(lp->lnd_mobil, mob);
1141 mult = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own)
1144 hard_amt = (int)(mob_used * mult);
1145 if (lp->lnd_harden + hard_amt > land_mob_max) {
1146 hard_amt = land_mob_max - lp->lnd_harden;
1147 mob_used = ceil(hard_amt / mult);
1150 lp->lnd_mobil -= (int)mob_used;
1151 lp->lnd_harden += hard_amt;
1152 lp->lnd_harden = MIN(lp->lnd_harden, land_mob_max);
1158 * Is there a engineer unit at X,Y that can help nation CN?
1161 has_helpful_engineer(coord x, coord y, natid cn)
1163 struct nstr_item ni;
1166 snxtitem_xy(&ni, EF_LAND, x, y);
1167 while (nxtitem(&ni, &land)) {
1168 if (relations_with(land.lnd_own, cn) != ALLIED)
1170 if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER)
1178 * Set LP's tech to TLEV along with everything else that depends on it.
1181 lnd_set_tech(struct lndstr *lp, int tlev)
1183 struct lchrstr *lcp = lchr + lp->lnd_type;
1185 if (CANT_HAPPEN(tlev < lcp->l_tech))
1188 lp->lnd_tech = tlev;