2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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-2006
49 #include "prototypes.h"
54 static void lnd_mess(char *, struct ulist *);
55 static int lnd_hit_mine(struct lndstr *, struct lchrstr *);
58 attack_val(int combat_mode, struct lndstr *lp)
64 if (lp->lnd_effic < LAND_MINEFF) {
65 putland(lp->lnd_uid, lp);
69 lcp = &lchr[(int)lp->lnd_type];
71 /* Spies always count as 1 during assaults. If they are the only ones
72 in the assault, they get to sneak on anyway. */
74 if (lcp->l_flags & L_SPY && combat_mode == A_ASSAULT)
77 men = lp->lnd_item[I_MILIT];
78 value = men * lp->lnd_att * lp->lnd_effic / 100.0;
80 switch (combat_mode) {
84 if (!(lcp->l_flags & L_MARINE))
85 return assault_penalty * value;
88 if (!(lcp->l_flags & L_MARINE))
89 return assault_penalty * men;
96 defense_val(struct lndstr *lp)
102 if (lp->lnd_effic < LAND_MINEFF) {
103 putland(lp->lnd_uid, lp);
107 lcp = &lchr[(int)lp->lnd_type];
109 men = lp->lnd_item[I_MILIT];
111 if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) &&
112 !(lcp->l_flags & L_MARINE))
115 value = men * lp->lnd_def * lp->lnd_effic / 100.0;
116 value *= ((double)land_mob_max + lp->lnd_harden) / land_mob_max;
118 /* If there are military on the unit, you get at least a 1
119 man defensive unit, except for spies */
120 if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
127 lnd_print(struct ulist *llp, char *s)
129 if (llp->unit.land.lnd_own == player->cnum)
130 pr("%s %s\n", prland(&llp->unit.land), s);
132 wu(0, llp->unit.land.lnd_own, "%s %s\n", prland(&llp->unit.land), s);
136 lnd_delete(struct ulist *llp, char *s)
140 putland(llp->unit.land.lnd_uid, &llp->unit.land);
141 emp_remque((struct emp_qelem *)llp);
146 lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
147 /* attacking or assaulting or paratrooping? */
148 /* number of casualties to take */
161 int nowhere_to_go = 0;
163 double mobcost, bmcost;
167 taken = llp->unit.land.lnd_item[I_MILIT];
168 /* Spies always die */
169 if (((struct lchrstr *)llp->chrp)->l_flags & L_SPY) {
171 llp->unit.land.lnd_effic = 0;
173 eff_eq = ldround(cas * 100.0 /
174 ((struct lchrstr *)llp->chrp)->l_mil, 1);
175 llp->unit.land.lnd_effic -= eff_eq;
176 lnd_submil(&llp->unit.land, cas);
179 if (llp->unit.land.lnd_effic < LAND_MINEFF) {
180 sprintf(buf, "dies %s %s!",
181 combat_mode ? att_mode[combat_mode] : "defending",
182 xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
183 llp->unit.land.lnd_own));
184 lnd_delete(llp, buf);
185 /* Since we killed the unit, we killed all the mil on it */
188 /* Ok, now, how many did we take off? (sould be the diff) */
189 taken = taken - llp->unit.land.lnd_item[I_MILIT];
192 if (llp->unit.land.lnd_effic >= llp->unit.land.lnd_retreat)
195 /* we're being boarded */
196 if (llp->unit.land.lnd_ship >= 0 && combat_mode == A_DEFEND)
199 /* we're being boarded */
200 if (llp->unit.land.lnd_land >= 0 && combat_mode == A_DEFEND)
203 /* Have to make a retreat check */
205 ret_chance = llp->unit.land.lnd_retreat - llp->unit.land.lnd_effic;
206 if (roll(100) < ret_chance) {
208 lnd_print(llp, "fails morale check!");
209 llp->unit.land.lnd_mission = 0;
210 llp->unit.land.lnd_harden = 0;
211 if (llp->unit.land.lnd_ship >= 0 || llp->unit.land.lnd_land >= 0)
213 else if (combat_mode == A_DEFEND) {
215 * defending unit.. find a place to send it
216 * strategy: look for the most-populated
217 * adjacent sector that is owned by the unit
218 * player->owner. Charge mob..
222 for (n = 1; n <= 6; ++n) {
223 ret_x = llp->unit.land.lnd_x + diroff[n][0];
224 ret_y = llp->unit.land.lnd_y + diroff[n][1];
225 getsect(ret_x, ret_y, §);
226 if (sect.sct_own != llp->unit.land.lnd_own)
228 if (sect.sct_type == SCT_MOUNT)
230 mobcost = lnd_mobcost(&llp->unit.land, &rsect);
234 civs = sect.sct_item[I_CIVIL];
235 if (civs > biggest) {
245 /* retreat to bx,by */
246 llp->unit.land.lnd_x = bx;
247 llp->unit.land.lnd_y = by;
248 /* FIXME landmines */
249 getsect(bx, by, &rsect);
250 mob = llp->unit.land.lnd_mobil - (int)bmcost;
253 orig = llp->unit.land.lnd_mobil;
254 llp->unit.land.lnd_mobil = (signed char)mob;
255 if (llp->unit.land.lnd_mobil > orig)
256 llp->unit.land.lnd_mobil = -127;
257 sprintf(buf, "retreats at %d%% efficiency to %s!",
258 llp->unit.land.lnd_effic,
259 xyas(bx, by, llp->unit.land.lnd_own));
260 lnd_delete(llp, buf);
262 } else { /* attacking from a sector */
263 sprintf(buf, "leaves the battlefield at %d%% efficiency",
264 llp->unit.land.lnd_effic);
265 if ((llp->unit.land.lnd_mobil - (int)llp->mobil) < -127)
266 llp->unit.land.lnd_mobil = -127;
268 llp->unit.land.lnd_mobil -= (int)llp->mobil;
270 lnd_delete(llp, buf);
274 /* nowhere to go.. take more casualties */
275 llp->unit.land.lnd_effic -= 10;
276 lnd_submil(&llp->unit.land, ((struct lchrstr *)llp->chrp)->l_mil / 10);
277 if (llp->unit.land.lnd_effic < LAND_MINEFF)
278 lnd_delete(llp, "has nowhere to retreat, and dies!");
281 "has nowhere to retreat and takes extra losses!");
288 lnd_takemob(struct emp_qelem *list, double loss)
290 struct emp_qelem *qp, *next;
293 int mcost = ldround(combat_mob * loss, 1);
295 for (qp = list->q_forw; qp != list; qp = next) {
297 llp = (struct ulist *)qp;
300 use_supply(&llp->unit.land);
301 if (llp->unit.land.lnd_mission == MI_RESERVE)
302 new = llp->unit.land.lnd_mobil - mcost/2;
305 new = llp->unit.land.lnd_mobil - mcost;
308 llp->unit.land.lnd_mobil = (signed char)new;
313 lnd_submil(struct lndstr *lp, int num)
315 int new = lp->lnd_item[I_MILIT] - num;
316 lp->lnd_item[I_MILIT] = new < 0 ? 0 : new;
320 lnd_spyval(struct lndstr *lp)
322 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
323 return lp->lnd_spy * (lp->lnd_effic / 100.0) + 2;
325 return lp->lnd_spy * (lp->lnd_effic / 100.0);
329 intelligence_report(int destination, struct lndstr *lp, int spy,
333 char buf1[80], buf2[80], buf3[80];
334 double estimate = 0.0; /* estimated defense value */
336 if (destination == 0)
339 if (lp->lnd_own == 0)
342 lcp = &lchr[(int)lp->lnd_type];
344 memset(buf1, 0, sizeof(buf1));
345 memset(buf2, 0, sizeof(buf2));
346 memset(buf3, 0, sizeof(buf3));
347 if (chance((spy + lp->lnd_vis) / 10.0)) {
348 if (destination == player->cnum)
349 pr("%s %s", mess, prland(lp));
351 sprintf(buf1, "%s %s", mess, prland(lp));
353 estimate = lp->lnd_item[I_MILIT];
355 if (chance((spy + lp->lnd_vis) / 20.0)) {
356 if (destination == player->cnum)
357 pr(" (eff %d, mil %d",
358 roundintby(lp->lnd_effic, 5),
359 roundintby(lp->lnd_item[I_MILIT], 10));
361 sprintf(buf2, " (eff %d, mil %d",
362 roundintby(lp->lnd_effic, 5),
363 roundintby(lp->lnd_item[I_MILIT], 10));
364 estimate = lp->lnd_item[I_MILIT] * lp->lnd_effic / 100.0;
366 if (chance((spy + lp->lnd_vis) / 20.0)) {
368 t = lp->lnd_tech - 20 + roll(40);
370 if (destination == player->cnum)
371 pr(", tech %d)\n", t);
373 sprintf(buf3, ", tech %d)\n", t);
375 if (destination == player->cnum)
378 sprintf(buf3, ")\n");
381 if (destination == player->cnum)
388 if (destination != player->cnum) {
389 wu(0, destination, "%s%s%s", buf1, buf2, buf3);
392 if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
393 estimate *= lp->lnd_def;
398 /* Used by the spy command to count land units in a sector. If used
399 for anything else, you may want to reconsider, because this doesn't
400 always count spies. :) */
402 count_sect_units(struct sctstr *sp)
408 snxtitem_all(&ni, EF_LAND);
409 while (nxtitem(&ni, &land)) {
412 if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y)
414 /* Don't always see spies */
415 if (lchr[(int)land.lnd_type].l_flags & L_SPY) {
416 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
419 /* Got here, report it */
427 count_units(struct shpstr *sp)
433 if (sp->shp_effic < SHIP_MINEFF)
436 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
437 while (nxtitem(&ni, &land)) {
438 if (land.lnd_own == 0)
440 if (land.lnd_ship == sp->shp_uid)
444 if (sp->shp_nland != nland) {
445 sp->shp_nland = nland;
446 putship(sp->shp_uid, sp);
451 lnd_count_units(struct lndstr *lp)
457 if (lp->lnd_effic < LAND_MINEFF)
460 snxtitem_xy(&ni, EF_LAND, lp->lnd_x, lp->lnd_y);
461 while (nxtitem(&ni, &land)) {
462 if (land.lnd_own == 0)
464 if (land.lnd_land == lp->lnd_uid)
468 if (lp->lnd_nland != nland) {
469 lp->lnd_nland = nland;
470 putland(lp->lnd_uid, lp);
475 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
481 int mobtype = MOB_MOVE; /* indeterminate */
484 while (nxtitem(ni, &land)) {
488 if (ontradingblock(EF_LAND, &land)) {
489 pr("unit #%d inelligible - it's for sale.\n",
495 * The marching code gets confused when trains and non-trains
496 * march together. Disallow for now.
498 this_mot = lnd_mobtype(&land);
499 if (this_mot != mobtype) {
500 if (mobtype == MOB_MOVE)
502 else if (mobtype == MOB_MARCH) {
503 pr("%s is a train and can't march with the leader.\n",
507 pr("%s can't rail-march with the leading train.\n",
513 lcp = &lchr[(int)land.lnd_type];
514 land.lnd_mission = 0;
517 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
518 putland(land.lnd_uid, &land);
519 llp = malloc(sizeof(struct ulist));
520 llp->chrp = (struct empobj_chr *)lcp;
521 llp->unit.land = land;
522 llp->mobil = land.lnd_mobil;
523 emp_insque(&llp->queue, list);
527 /* This function assumes that the list was created by lnd_sel */
529 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
530 int *togetherp, natid actor)
532 struct emp_qelem *qp;
533 struct emp_qelem *next;
546 for (qp = list->q_back; qp != list; qp = next) {
548 llp = (struct ulist *)qp;
549 getland(llp->unit.land.lnd_uid, &land);
550 if (land.lnd_own != actor) {
551 mpr(actor, "%s was disbanded at %s\n",
552 prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
553 emp_remque((struct emp_qelem *)llp);
557 if (land.lnd_ship >= 0) {
558 lnd_mess("is on a ship", llp);
561 if (land.lnd_land >= 0) {
562 lnd_mess("is on a unit", llp);
565 if (!getsect(land.lnd_x, land.lnd_y, §)) {
566 lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
569 if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
570 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_TRAIN) &&
571 llp->unit.land.lnd_item[I_MILIT] == 0) {
572 lnd_mess("has no mil on it to guide it", llp);
575 rel = getrel(getnatp(sect.sct_own), player->cnum);
576 if (sect.sct_own != land.lnd_own && rel != ALLIED &&
577 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
579 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
588 if (land.lnd_x != allx || land.lnd_y != ally)
590 if (land.lnd_mobil + 1 < (int)llp->mobil) {
591 llp->mobil = land.lnd_mobil;
593 if (llp->mobil < *minmobp)
594 *minmobp = llp->mobil;
595 if (llp->mobil > *maxmobp)
596 *maxmobp = llp->mobil;
597 llp->unit.land = land;
602 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
605 struct emp_qelem *qp;
606 struct emp_qelem *next;
609 int mines, m, max, sshells, lshells;
611 for (qp = land_list->q_back; qp != land_list; qp = next) {
613 llp = (struct ulist *)qp;
614 if (!(((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)) {
616 mpr(actor, "%s is not an engineer!\n",
617 prland(&llp->unit.land));
620 if (takemob && llp->mobil < 0.0) {
622 lnd_mess("is out of mobility", llp);
625 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
626 if (sect.sct_oldown == llp->unit.land.lnd_own) {
629 "%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
630 prland(&llp->unit.land));
633 if (sect.sct_type == SCT_BSPAN) {
635 mpr(actor, "%s is on a bridge. No mines there!\n",
636 prland(&llp->unit.land));
640 llp->mobil -= lnd_pathcost(&llp->unit.land, 0.2);
641 llp->unit.land.lnd_mobil = (int)llp->mobil;
642 llp->unit.land.lnd_harden = 0;
644 putland(llp->unit.land.lnd_uid, &llp->unit.land);
645 if (!(mines = sect.sct_mines))
647 max = ((struct lchrstr *)llp->chrp)->l_item[I_SHELL];
648 lshells = llp->unit.land.lnd_item[I_SHELL];
649 sshells = sect.sct_item[I_SHELL];
650 for (m = 0; mines > 0 && m < max * 2; m++) {
651 if (chance(0.5 * ((struct lchrstr *)llp->chrp)->l_att)) {
652 mpr(actor, "Sweep...\n");
656 else if (sshells < ITEM_MAX)
660 sect.sct_mines = mines;
661 llp->unit.land.lnd_item[I_SHELL] = lshells;
662 sect.sct_item[I_SHELL] = sshells;
663 putland(llp->unit.land.lnd_uid, &llp->unit.land);
669 contains_engineer(struct emp_qelem *list)
671 struct emp_qelem *qp;
672 struct emp_qelem *next;
675 for (qp = list->q_back; qp != list; qp = next) {
677 llp = (struct ulist *)qp;
678 if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
685 lnd_check_mines(struct emp_qelem *land_list)
687 struct emp_qelem *qp;
688 struct emp_qelem *next;
692 int with_eng = contains_engineer(land_list);
694 for (qp = land_list->q_back; qp != land_list; qp = next) {
696 llp = (struct ulist *)qp;
697 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
698 if (sect.sct_oldown == llp->unit.land.lnd_own)
700 if (sect.sct_type == SCT_BSPAN)
704 if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
705 lnd_hit_mine(&llp->unit.land, ((struct lchrstr *)llp->chrp));
708 putland(llp->unit.land.lnd_uid, &llp->unit.land);
709 if (!llp->unit.land.lnd_own) {
720 lnd_mess(char *str, struct ulist *llp)
722 mpr(llp->unit.land.lnd_own, "%s %s & stays in %s\n",
723 prland(&llp->unit.land),
724 str, xyas(llp->unit.land.lnd_x, llp->unit.land.lnd_y,
725 llp->unit.land.lnd_own));
726 if (llp->mobil < -127)
728 llp->unit.land.lnd_mobil = llp->mobil;
729 putland(llp->unit.land.lnd_uid, &llp->unit.land);
730 emp_remque((struct emp_qelem *)llp);
735 lnd_count(struct emp_qelem *list)
737 struct emp_qelem *qp;
738 struct emp_qelem *next;
741 for (qp = list->q_back; qp != list; qp = next) {
749 lnd_damage(struct emp_qelem *list, int totdam)
751 struct emp_qelem *qp;
752 struct emp_qelem *next;
757 if (!totdam || !(count = lnd_count(list)))
759 dam = ldround((double)totdam / count, 1);
760 for (qp = list->q_back; qp != list; qp = next) {
762 llp = (struct ulist *)qp;
763 /* have to get it again because of collateral damage */
764 getland(llp->unit.land.lnd_uid, &llp->unit.land);
765 landdamage(&llp->unit.land, dam);
766 putland(llp->unit.land.lnd_uid, &llp->unit.land);
767 if (!llp->unit.land.lnd_own) {
776 lnd_easiest_target(struct emp_qelem *list)
778 struct emp_qelem *qp;
779 struct emp_qelem *next;
782 int easiest = 9876; /* things start great for victim */
785 for (qp = list->q_back; qp != list; qp = next) {
787 llp = (struct ulist *)qp;
788 hard = lnd_hardtarget(&llp->unit.land);
790 easiest = hard; /* things get worse for victim */
793 return easiest - count;
797 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
801 struct emp_qelem msl_list, *qp, *newqp;
803 msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
805 dam = msl_launch_mindam(&msl_list, newx, newy,
806 lnd_easiest_target(list), EF_LAND,
807 lnd_count(list) * 20, "troops", victim,
810 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
811 collateral_damage(newx, newy, dam, 0);
813 qp = msl_list.q_forw;
814 while (qp != msl_list.q_forw) {
824 /* Steve M. - commented out for now until abuse is decided upon */
825 /* risner: allow forts to interdict land units. */
827 lnd_fort_interdiction(struct emp_qelem *list,
828 coord newx, coord newy, natid victim)
839 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
840 while (nxtsct(&ns, &fsect)) {
841 if (fsect.sct_own == 0)
843 if (fsect.sct_own == victim)
845 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
847 gun = fsect.sct_item[I_GUN];
850 range = roundrange(fortrange(&fsect));
851 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
854 if (fsect.sct_item[I_MILIT] < 5)
856 shell = fsect.sct_item[I_SHELL];
858 shell += supply_commod(fsect.sct_own, fsect.sct_x, fsect.sct_y,
863 fsect.sct_item[I_SHELL] = shell;
867 guneff = landgun((int)fsect.sct_effic, gun);
870 mpr(victim, "Incoming fire does %d damage!\n", dam);
872 "%s fires at %s land units in %s for %d!\n",
873 xyas(fsect.sct_x, fsect.sct_y,
875 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
876 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
879 return lnd_damage(list, totdam);
885 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
890 if (!opt_NO_FORT_FIRE)
891 /* Steve M. - commented out for now until abuse is decided upon */
892 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
897 unit_interdict(newx, newy, victim, "land units",
898 lnd_easiest_target(list), MI_INTERDICT));
902 lnd_missile_interdiction(list, newx, newy, victim));
906 /* high value of hardtarget is harder to hit */
908 lnd_hardtarget(struct lndstr *lp)
912 getsect(lp->lnd_x, lp->lnd_y, §);
913 return (int)((lp->lnd_effic / 100.0) *
914 (10 + dchr[sect.sct_type].d_dstr * 2 + lp->lnd_spd / 2.0
919 lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
923 mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
924 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
926 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
929 if (lcp->l_flags & L_ENGINEER)
937 lnd_pathcost(struct lndstr *lp, double pathcost)
941 effspd = lp->lnd_spd;
942 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
943 effspd *= lp->lnd_effic * 0.01;
946 * The return value must be PATHCOST times a factor that depends
947 * only on the land unit. Anything else breaks path finding. In
948 * particular, you can't add or enforce a minimum cost here. Do
949 * it in sector_mcost().
951 return pathcost * 5.0 * speed_factor(effspd, lp->lnd_tech);
955 lnd_mobtype(struct lndstr *lp)
957 return (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
958 ? MOB_RAIL : MOB_MARCH;
962 lnd_mobcost(struct lndstr *lp, struct sctstr *sp)
964 return lnd_pathcost(lp, sector_mcost(sp, lnd_mobtype(lp)));
968 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
971 struct sctstr sect, osect;
972 struct emp_qelem *qp;
973 struct emp_qelem *qp2;
974 struct emp_qelem *next;
976 struct emp_qelem cur, done;
988 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
989 unit_put(list, actor);
994 for (qp = list->q_back; qp != list; qp = next) {
996 llp = (struct ulist *)qp;
997 getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &osect);
998 oldown = osect.sct_own;
999 newx = xnorm(llp->unit.land.lnd_x + dx);
1000 newy = ynorm(llp->unit.land.lnd_y + dy);
1001 getsect(newx, newy, §);
1002 rel = getrel(getnatp(sect.sct_own), player->cnum);
1003 if ((sect.sct_own != actor && rel != ALLIED &&
1004 !(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) &&
1005 sect.sct_own) || (sect.sct_type == SCT_WATER ||
1006 sect.sct_type == SCT_SANCT ||
1007 sect.sct_type == SCT_WASTE)) {
1009 pr("can't go to %s\n", xyas(newx, newy, actor));
1012 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
1017 if ((!intrchr[INT_RAIL].in_enable || sect.sct_rail == 0)
1018 && lnd_mobtype(&llp->unit.land) == MOB_RAIL) {
1020 pr("no rail system in %s\n", xyas(newx, newy, actor));
1023 sprintf(dp, "has no rail system in %s",
1024 xyas(newx, newy, actor));
1029 /* Note we check would_abandon first because we don't want
1030 to always have to do these checks */
1031 if (would_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
1033 if (!want_to_abandon(&osect, I_CIVIL, 0, &llp->unit.land)) {
1036 /* now check stuff */
1037 if (!check_sect_ok(§))
1039 if (!check_sect_ok(&osect))
1041 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
1042 if (!check_land_ok(&((struct ulist *)qp2)->unit.land))
1046 lnd_mess("stops", llp);
1050 if (llp->mobil <= 0.0) {
1051 lnd_mess("is out of mobility", llp);
1054 llp->unit.land.lnd_x = newx;
1055 llp->unit.land.lnd_y = newy;
1056 llp->mobil -= lnd_mobcost(&llp->unit.land, §);
1057 llp->unit.land.lnd_mobil = (int)llp->mobil;
1058 llp->unit.land.lnd_harden = 0;
1059 putland(llp->unit.land.lnd_uid, &llp->unit.land);
1061 getsect(osect.sct_x, osect.sct_y, &osect);
1062 if (osect.sct_own != oldown && oldown == player->cnum) {
1063 /* It was your sector, now it's not. Simple :) */
1064 pr("You no longer own %s\n",
1065 xyas(osect.sct_x, osect.sct_y, player->cnum));
1067 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
1068 /* Always a 10% chance of getting caught. */
1069 if (chance(LND_SPY_DETECT_CHANCE(llp->unit.land.lnd_effic))) {
1070 if (rel == NEUTRAL || rel == FRIENDLY) {
1072 "%s unit spotted in %s\n", cname(player->cnum),
1073 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1074 setrel(sect.sct_own, llp->unit.land.lnd_own, HOSTILE);
1075 } else if (rel == HOSTILE || rel == AT_WAR ||
1076 rel == SITZKRIEG || rel == MOBILIZATION) {
1078 "%s spy shot in %s\n", cname(player->cnum),
1079 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1080 pr("%s was shot and killed.\n", prland(&llp->unit.land));
1081 llp->unit.land.lnd_effic = 0;
1082 putland(llp->unit.land.lnd_uid, &llp->unit.land);
1090 lnd_sweep(list, 0, 1, actor);
1091 stopping |= lnd_check_mines(list);
1095 /* interdict land units sector by sector */
1098 while (!QEMPTY(list)) {
1099 llp = (struct ulist *)list->q_back;
1100 newx = llp->unit.land.lnd_x;
1101 newy = llp->unit.land.lnd_y;
1102 /* move units in NEWX,NEWY to cur */
1104 for (qp = list->q_back; qp != list; qp = next) {
1106 llp = (struct ulist *)qp;
1107 if (llp->unit.land.lnd_x == newx && llp->unit.land.lnd_y == newy) {
1109 emp_insque(qp, &cur);
1110 if (!(lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY))
1114 /* interdict them */
1116 stopping |= lnd_interdict(&cur, newx, newy, actor);
1117 /* move survivors to done */
1118 for (qp = cur.q_back; qp != &cur; qp = next) {
1120 llp = (struct ulist *)qp;
1122 emp_insque(qp, &done);
1125 /* assign surviving land units back to list */
1126 emp_insque(list, &done);
1133 * find all artillery units belonging
1134 * to the attacker or defender that can fire.
1135 * Each arty unit adds +1%/damage point
1138 lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
1140 struct nstr_item ni;
1149 snxtitem_all(&ni, EF_LAND);
1150 while (nxtitem(&ni, &land)) {
1151 if (land.lnd_frg == 0)
1153 if ((land.lnd_x == x) && (land.lnd_y == y))
1155 if (land.lnd_ship >= 0)
1157 if (land.lnd_land >= 0)
1159 if (land.lnd_effic < LAND_MINFIREEFF)
1161 /* Do we have mil? */
1162 if (land.lnd_item[I_MILIT] <= 0)
1164 rel = getrel(getnatp(land.lnd_own), attacker);
1165 rel2 = getrel(getnatp(land.lnd_own), victim);
1166 if ((land.lnd_own != attacker) &&
1167 ((rel != ALLIED) || (rel2 != AT_WAR)))
1170 /* do we have supplies? */
1171 if (!has_supply(&land))
1174 /* are we in range? */
1175 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1177 range = roundrange(effrange(land.lnd_frg, land.lnd_tech));
1181 shell = land.lnd_item[I_SHELL];
1182 gun = land.lnd_item[I_GUN];
1184 if (shell == 0 || gun == 0)
1189 nreport(land.lnd_own, N_FIRE_BACK, victim, 1);
1191 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1192 if (roll(100) < land.lnd_acc) {
1193 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1194 land.lnd_ammo, shell) / 2;
1196 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1197 land.lnd_ammo, shell);
1199 if (land.lnd_own != attacker)
1201 "%s supported %s at %s\n",
1202 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1207 lnd_can_attack(struct lndstr *lp)
1209 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1211 if (lcp->l_flags & L_SUPPLY)
1218 * Increase fortification value of LP.
1219 * Fortification costs mobility. Use up to MOB mobility.
1220 * Return actual fortification increase.
1223 lnd_fortify(struct lndstr *lp, int mob)
1226 double mob_used, mult;
1228 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
1231 mob_used = MIN(lp->lnd_mobil, mob);
1235 mult = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own)
1238 hard_amt = (int)(mob_used * mult);
1239 if (lp->lnd_harden + hard_amt > land_mob_max) {
1240 hard_amt = land_mob_max - lp->lnd_harden;
1241 mob_used = ceil(hard_amt / mult);
1244 lp->lnd_mobil -= (int)mob_used;
1245 lp->lnd_harden += hard_amt;
1246 lp->lnd_harden = MIN(lp->lnd_harden, land_mob_max);
1252 * Set LP's tech to TLEV along with everything else that depends on it.
1255 lnd_set_tech(struct lndstr *lp, int tlev)
1257 struct lchrstr *lcp = lchr + lp->lnd_type;
1258 int tech_diff = tlev - lcp->l_tech;
1260 if (CANT_HAPPEN(tech_diff < 0)) {
1265 lp->lnd_tech = tlev;
1266 lp->lnd_att = (float)LND_ATTDEF(lcp->l_att, tech_diff);
1267 lp->lnd_def = (float)LND_ATTDEF(lcp->l_def, tech_diff);
1268 lp->lnd_vul = (int)LND_VUL(lcp->l_vul, tech_diff);
1269 lp->lnd_spd = (int)LND_SPD(lcp->l_spd, tech_diff);
1270 lp->lnd_vis = (int)LND_VIS(lcp->l_vis, tech_diff);
1271 lp->lnd_spy = (int)LND_SPY(lcp->l_spy, tech_diff);
1272 lp->lnd_rad = (int)LND_RAD(lcp->l_rad, tech_diff);
1273 lp->lnd_frg = (int)LND_FRG(lcp->l_frg, tech_diff);
1274 lp->lnd_acc = (int)LND_ACC(lcp->l_acc, tech_diff);
1275 lp->lnd_dam = (int)LND_DAM(lcp->l_dam, tech_diff);
1276 lp->lnd_ammo = (int)LND_AMM(lcp->l_ammo, tech_diff);
1277 lp->lnd_aaf = (int)LND_AAF(lcp->l_aaf, tech_diff);
1278 lp->lnd_fuelc = (int)LND_FC(lcp->l_fuelc, tech_diff);
1279 lp->lnd_fuelu = (int)LND_FU(lcp->l_fuelu, tech_diff);
1280 lp->lnd_maxlight = (int)LND_XPL(lcp->l_nxlight, tech_diff);
1281 lp->lnd_maxland = (int)LND_MXL(lcp->l_nland, tech_diff);