2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * 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
53 #include "prototypes.h"
56 attack_val(int combat_mode, struct lndstr *lp)
62 if (((int)lp->lnd_effic) < LAND_MINEFF) {
63 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
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)
79 value = ldround(((double)men * (double)lp->lnd_att), 1);
81 value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
83 switch (combat_mode) {
87 if (!(lcp->l_flags & L_MARINE))
88 return (int)(assault_penalty * value);
91 if (!(lcp->l_flags & L_MARINE))
92 return (int)(assault_penalty * men);
99 defense_val(struct lndstr *lp)
105 if (((int)lp->lnd_effic) < LAND_MINEFF) {
106 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
108 putland(lp->lnd_uid, lp);
112 lcp = &lchr[(int)lp->lnd_type];
118 if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) &&
119 !(lcp->l_flags & L_MARINE))
122 value = men * lp->lnd_def;
125 ((double)land_mob_max + lp->lnd_harden) / (double)land_mob_max;
126 value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
127 value = (int)ldround(value, 1);
129 /* If there are military on the unit, you get at least a 1
130 man defensive unit, except for spies */
131 if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
138 total_mil(struct lndstr *lp)
143 lcp = &lchr[(int)lp->lnd_type];
145 men = lnd_getmil(lp);
146 /* men *= ((double)lp->lnd_effic)/100.0;*/
148 return ldround(men, 1);
152 lnd_print(struct llist *llp, s_char *s)
154 if (llp->land.lnd_own == player->cnum)
155 pr("%s %s\n", prland(&llp->land), s);
157 wu(0, llp->land.lnd_own, "%s %s\n", prland(&llp->land), s);
161 lnd_delete(struct llist *llp, s_char *s)
165 putland(llp->land.lnd_uid, &llp->land);
166 emp_remque((struct emp_qelem *)llp);
171 lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
172 /* attacking or assaulting or paratrooping? */
173 /* number of casualties to take */
186 int nowhere_to_go = 0;
194 taken = lnd_getmil(&(llp->land));
195 /* Spies always die */
196 if (llp->lcp->l_flags & L_SPY) {
198 llp->land.lnd_effic = 0;
201 ldround((((double)cas * 100.0) / (double)llp->lcp->l_mil), 1);
202 llp->land.lnd_effic -= eff_eq;
203 lnd_submil(&(llp->land), cas);
206 if (llp->land.lnd_effic < LAND_MINEFF) {
207 sprintf(buf, "dies %s %s!",
208 combat_mode ? att_mode[combat_mode] : (s_char *)
209 "defending", xyas(llp->land.lnd_x, llp->land.lnd_y,
211 lnd_delete(llp, buf);
212 /* Since we killed the unit, we killed all the mil on it */
215 /* Ok, now, how many did we take off? (sould be the diff) */
216 taken = taken - lnd_getmil(&(llp->land));
219 if (llp->land.lnd_effic >= llp->land.lnd_retreat)
222 /* we're being boarded */
223 if (llp->land.lnd_ship >= 0 && combat_mode == A_DEFEND)
226 /* we're being boarded */
227 if (llp->land.lnd_land >= 0 && combat_mode == A_DEFEND)
230 /* Have to make a retreat check */
232 ret_chance = llp->land.lnd_retreat - llp->land.lnd_effic;
233 if (roll(100) < ret_chance) {
235 lnd_print(llp, "fails morale check!");
236 llp->land.lnd_mission = 0;
237 llp->land.lnd_harden = 0;
238 if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0)
240 else if (combat_mode == A_DEFEND) {
242 * defending unit.. find a place to send it
243 * strategy: look for the most-populated
244 * adjacent sector that is owned by the unit
245 * player->owner. Charge mob..
249 for (n = 1; n <= 6; ++n) {
250 ret_x = llp->land.lnd_x + diroff[n][0];
251 ret_y = llp->land.lnd_y + diroff[n][1];
252 getsect(ret_x, ret_y, §);
253 if (sect.sct_own != llp->land.lnd_own)
255 if (sect.sct_type == SCT_MOUNT)
258 civs = sect.sct_item[I_CIVIL];
259 if (civs > biggest) {
268 /* retreat to bx,by */
269 llp->land.lnd_x = bx;
270 llp->land.lnd_y = by;
271 getsect(bx, by, &rsect);
272 mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD);
273 mob = llp->land.lnd_mobil - (int)mobcost;
276 orig = llp->land.lnd_mobil;
277 llp->land.lnd_mobil = (s_char)mob;
278 if (llp->land.lnd_mobil > orig)
279 llp->land.lnd_mobil = (-127);
280 sprintf(buf, "retreats at %d%% efficiency to %s!",
282 xyas(bx, by, llp->land.lnd_own));
283 lnd_delete(llp, buf);
285 } else { /* attacking from a sector */
286 sprintf(buf, "leaves the battlefield at %d%% efficiency",
287 llp->land.lnd_effic);
288 if ((llp->land.lnd_mobil - (int)llp->mobil) < -127)
289 llp->land.lnd_mobil = -127;
291 llp->land.lnd_mobil -= (int)llp->mobil;
293 lnd_delete(llp, buf);
297 /* nowhere to go.. take more casualties */
298 llp->land.lnd_effic -= 10;
299 lnd_submil(&llp->land, llp->lcp->l_mil / 10);
300 if (llp->land.lnd_effic < LAND_MINEFF)
301 lnd_delete(llp, "has nowhere to retreat, and dies!");
304 "has nowhere to retreat and takes extra losses!");
311 lnd_takemob(struct emp_qelem *list, double loss)
313 struct emp_qelem *qp, *next;
316 int mcost = ldround(combat_mob * loss, 1);
318 for (qp = list->q_forw; qp != list; qp = next) {
320 llp = (struct llist *)qp;
323 use_supply(&llp->land);
324 if (llp->land.lnd_mission == MI_RESERVE)
325 new = llp->land.lnd_mobil - mcost/2;
328 new = llp->land.lnd_mobil - mcost;
331 llp->land.lnd_mobil = (s_char)new;
335 lnd_getmil(struct lndstr *lp)
337 return lp->lnd_item[I_MILIT];
341 lnd_submil(struct lndstr *lp, int num)
343 int new = lp->lnd_item[I_MILIT] - num;
344 lp->lnd_item[I_MILIT] = new < 0 ? 0 : new;
348 lnd_spyval(struct lndstr *lp)
350 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
351 return (lp->lnd_spy * (lp->lnd_effic / 100.0)) + 2;
353 return (lp->lnd_spy * (lp->lnd_effic / 100.0));
357 intelligence_report(int destination, struct lndstr *lp, int spy,
361 s_char buf1[80], buf2[80], buf3[80];
362 double estimate = 0.0; /* estimated defense value */
364 if (destination == 0)
367 if (lp->lnd_own == 0)
370 lcp = &lchr[(int)lp->lnd_type];
372 memset(buf1, 0, sizeof(buf1));
373 memset(buf2, 0, sizeof(buf2));
374 memset(buf3, 0, sizeof(buf3));
375 if (chance((double)(spy + lp->lnd_vis) / 10.0)) {
376 if (destination == player->cnum)
377 pr("%s %s", mess, prland(lp));
379 sprintf(buf1, "%s %s", mess, prland(lp));
381 estimate = lnd_getmil(lp);
383 if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
385 if (destination == player->cnum)
386 pr(" (eff %d, mil %d", roundintby(lp->lnd_effic, 5),
387 roundintby(lnd_getmil(lp), 10));
389 sprintf(buf2, " (eff %d, mil %d",
390 roundintby(lp->lnd_effic, 5),
391 roundintby(lnd_getmil(lp), 10));
392 estimate = lnd_getmil(lp) * lp->lnd_effic / 100.0;
394 if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
396 t = lp->lnd_tech - 20 + roll(40);
398 if (destination == player->cnum)
399 pr(", tech %d)\n", t);
401 sprintf(buf3, ", tech %d)\n", t);
403 if (destination == player->cnum)
406 sprintf(buf3, ")\n");
409 if (destination == player->cnum)
416 if (destination != player->cnum) {
417 wu(0, destination, "%s%s%s", buf1, buf2, buf3);
420 if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
421 estimate *= lp->lnd_def;
423 return (int)estimate;
426 /* Used by the spy command to count land units in a sector. If used
427 for anything else, you may want to reconsider, because this doesn't
428 always count spies. :) */
430 count_sect_units(struct sctstr *sp)
436 snxtitem_all(&ni, EF_LAND);
437 while (nxtitem(&ni, (s_char *)&land)) {
440 if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y)
442 /* Don't always see spies */
443 if (lchr[(int)land.lnd_type].l_flags & L_SPY) {
444 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
447 /* Got here, report it */
455 count_units(struct shpstr *sp)
461 if (sp->shp_effic < SHIP_MINEFF)
464 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
465 while (nxtitem(&ni, (s_char *)&land)) {
466 if (land.lnd_own == 0)
468 if (land.lnd_ship == sp->shp_uid)
472 if (sp->shp_nland != nland) {
473 sp->shp_nland = nland;
474 putship(sp->shp_uid, sp);
479 lnd_count_units(struct lndstr *lp)
485 if (lp->lnd_effic < LAND_MINEFF)
488 snxtitem_xy(&ni, EF_LAND, lp->lnd_x, lp->lnd_y);
489 while (nxtitem(&ni, (s_char *)&land)) {
490 if (land.lnd_own == 0)
492 if (land.lnd_land == lp->lnd_uid)
496 if (lp->lnd_nland != nland) {
497 lp->lnd_nland = nland;
498 putland(lp->lnd_uid, lp);
503 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
515 while (nxtitem(ni, (s_char *)&land)) {
519 if (ontradingblock(EF_LAND, (int *)&land)) {
520 pr("unit #%d inelligible - it's for sale.\n",
525 lcp = &lchr[(int)land.lnd_type];
526 /* if (wantflags && (lcp->m_flags & wantflags) != wantflags)
528 if (nowantflags && lcp->m_flags & nowantflags)
531 /* This abuse is better fixed by building a unit with the normal negative
532 mobility that everything else is built with */
533 /* Just so that the player can't build a bunch of land units, and them
534 march them a few minutes later... */
536 if (opt_MOB_ACCESS) {
537 if (land.lnd_effic < 11 &&
538 land.lnd_mobil < etu_per_update) {
539 pr("Land unit #%d needs at least %d mob to march.\n",
540 land.lnd_uid, etu_per_update);
545 land.lnd_mission = 0;
548 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
549 putland(land.lnd_uid, &land);
550 llp = (struct llist *)malloc(sizeof(struct llist));
553 llp->mobil = (double)land.lnd_mobil;
554 emp_insque(&llp->queue, list);
558 /* This function assumes that the list was created by lnd_sel */
560 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
561 int *togetherp, natid actor)
563 struct emp_qelem *qp;
564 struct emp_qelem *next;
577 for (qp = list->q_back; qp != list; qp = next) {
579 llp = (struct llist *)qp;
580 getland(llp->land.lnd_uid, &land);
581 if (land.lnd_own != actor) {
582 mpr(actor, "%s was disbanded at %s\n",
583 prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
584 emp_remque((struct emp_qelem *)llp);
588 if (land.lnd_ship >= 0) {
589 lnd_mess("is on a ship", llp);
592 if (land.lnd_land >= 0) {
593 lnd_mess("is on a unit", llp);
596 if (!getsect(land.lnd_x, land.lnd_y, §)) {
597 lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
600 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
601 !(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) &&
602 lnd_getmil(&llp->land) == 0) {
603 lnd_mess("has no mil on it to guide it", llp);
606 rel = getrel(getnatp(sect.sct_own), player->cnum);
607 if (sect.sct_own != land.lnd_own && rel != ALLIED &&
608 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
610 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
619 if (land.lnd_x != allx || land.lnd_y != ally)
621 if (land.lnd_mobil + 1 < (int)llp->mobil) {
622 llp->mobil = (double)land.lnd_mobil;
624 if (llp->mobil < *minmobp)
625 *minmobp = llp->mobil;
626 if (llp->mobil > *maxmobp)
627 *maxmobp = llp->mobil;
633 lnd_put(struct emp_qelem *list, natid actor)
635 struct emp_qelem *qp;
636 struct emp_qelem *newqp;
641 llp = (struct llist *)qp;
643 mpr(actor, "%s stopped at %s\n", prland(&llp->land),
644 xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
645 if (llp->mobil < -127)
647 llp->land.lnd_mobil = llp->mobil;
649 putland(llp->land.lnd_uid, &llp->land);
658 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
661 struct emp_qelem *qp;
662 struct emp_qelem *next;
665 int mines, m, max, sshells, lshells;
668 for (qp = land_list->q_back; qp != land_list; qp = next) {
670 llp = (struct llist *)qp;
671 if (!(llp->lcp->l_flags & L_ENGINEER)) {
673 mpr(actor, "%s is not an engineer!\n", prland(&llp->land));
676 if (takemob && llp->mobil < 0.0) {
678 lnd_mess("is out of mobility", llp);
681 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
682 if (sect.sct_oldown == llp->land.lnd_own) {
685 "%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
689 if (sect.sct_type == SCT_BSPAN) {
691 mpr(actor, "%s is on a bridge. No mines there!\n",
696 /* mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/
697 mobcost = llp->land.lnd_spd;
698 mobcost = 480.0 / (mobcost +
699 techfact(llp->land.lnd_tech, mobcost));
700 llp->mobil -= mobcost;
701 llp->land.lnd_mobil = (int)llp->mobil;
702 llp->land.lnd_harden = 0;
704 putland(llp->land.lnd_uid, &llp->land);
705 if (!(mines = sect.sct_mines))
707 max = llp->lcp->l_item[I_SHELL];
708 lshells = llp->land.lnd_item[I_SHELL];
709 sshells = sect.sct_item[I_SHELL];
710 for (m = 0; mines > 0 && m < max * 2; m++) {
711 if (chance(0.5 * llp->lcp->l_att)) {
712 mpr(actor, "Sweep...\n");
716 else if (sshells < ITEM_MAX)
720 sect.sct_mines = mines;
721 llp->land.lnd_item[I_SHELL] = lshells;
722 sect.sct_item[I_SHELL] = sshells;
723 putland(llp->land.lnd_uid, &llp->land);
729 contains_engineer(struct emp_qelem *list)
731 struct emp_qelem *qp;
732 struct emp_qelem *next;
735 for (qp = list->q_back; qp != list; qp = next) {
737 llp = (struct llist *)qp;
738 if (llp->lcp->l_flags & L_ENGINEER)
745 lnd_check_mines(struct emp_qelem *land_list)
747 struct emp_qelem *qp;
748 struct emp_qelem *next;
752 int with_eng = contains_engineer(land_list);
754 for (qp = land_list->q_back; qp != land_list; qp = next) {
756 llp = (struct llist *)qp;
757 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
758 if (sect.sct_oldown == llp->land.lnd_own)
760 if (sect.sct_type == SCT_BSPAN)
764 if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
765 lnd_hit_mine(&llp->land, llp->lcp);
768 putland(llp->land.lnd_uid, (s_char *)&llp->land);
769 if (!llp->land.lnd_own) {
780 lnd_list(struct emp_qelem *land_list)
782 struct emp_qelem *qp;
783 struct emp_qelem *next;
787 pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
789 for (qp = land_list->q_back; qp != land_list; qp = next) {
791 llp = (struct llist *)qp;
793 pr("%4d ", lnd->lnd_uid);
794 pr("%-16.16s ", llp->lcp->l_name);
795 prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
796 pr("%1c", lnd->lnd_army);
797 pr("%4d%%", lnd->lnd_effic);
798 pr("%4d", lnd->lnd_item[I_SHELL]);
799 pr("%4d", lnd->lnd_item[I_GUN]);
800 count_land_planes(lnd);
801 pr("%3d", lnd->lnd_nxlight);
802 pr("%4d", lnd->lnd_mobil);
803 pr("%4d", lnd->lnd_tech);
804 pr("%4d%%", lnd->lnd_retreat);
805 pr("%5d\n", lnd->lnd_fuel);
810 lnd_mess(s_char *str, struct llist *llp)
812 mpr(llp->land.lnd_own, "%s %s & stays in %s\n",
814 str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
815 if (llp->mobil < -127)
817 llp->land.lnd_mobil = llp->mobil;
818 putland(llp->land.lnd_uid, &llp->land);
819 emp_remque((struct emp_qelem *)llp);
824 lnd_count(struct emp_qelem *list)
826 struct emp_qelem *qp;
827 struct emp_qelem *next;
831 for (qp = list->q_back; qp != list; qp = next) {
833 llp = (struct llist *)qp;
840 lnd_damage(struct emp_qelem *list, int totdam)
842 struct emp_qelem *qp;
843 struct emp_qelem *next;
848 if (!totdam || !(count = lnd_count(list)))
850 dam = ldround(((double)totdam / (double)count), 1);
851 for (qp = list->q_back; qp != list; qp = next) {
853 llp = (struct llist *)qp;
854 /* have to get it again because of collateral damage */
855 getland(llp->land.lnd_uid, &llp->land);
856 landdamage(&llp->land, dam);
857 putland(llp->land.lnd_uid, &llp->land);
858 if (!llp->land.lnd_own) {
867 lnd_easiest_target(struct emp_qelem *list)
869 struct emp_qelem *qp;
870 struct emp_qelem *next;
873 int easiest = 9876; /* things start great for victim */
876 for (qp = list->q_back; qp != list; qp = next) {
878 llp = (struct llist *)qp;
879 hard = lnd_hardtarget(&llp->land);
881 easiest = hard; /* things get worse for victim */
884 return easiest - count;
888 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
892 struct emp_qelem msl_list, *qp, *newqp;
894 msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
896 dam = msl_launch_mindam(&msl_list, newx, newy,
897 lnd_easiest_target(list), EF_LAND,
898 lnd_count(list) * 20, "troops", victim,
901 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
902 collateral_damage(newx, newy, dam, 0);
904 qp = msl_list.q_forw;
905 while (qp != msl_list.q_forw) {
915 /* Steve M. - commented out for now until abuse is decided upon */
916 /* risner: allow forts to interdict land units. */
918 lnd_fort_interdiction(struct emp_qelem *list,
919 coord newx, coord newy, natid victim)
924 double range, range2, guneff;
930 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
931 while (nxtsct(&ns, &fsect)) {
932 if (fsect.sct_own == 0)
934 if (fsect.sct_own == victim)
936 if (fsect.sct_type != SCT_FORTR)
938 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
940 gun = fsect.sct_item[I_GUN];
943 range = tfactfire(fsect.sct_own, (double)min(gun, 7));
944 if (fsect.sct_effic > 59)
946 range2 = roundrange(range);
947 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
950 if (fsect.sct_item[I_MILIT] < 5)
952 shell = fsect.sct_item[I_SHELL];
954 shell += supply_commod(fsect.sct_own,
955 fsect.sct_x, fsect.sct_y, I_SHELL, 1);
959 fsect.sct_item[I_SHELL] = shell;
963 guneff = landgun((int)fsect.sct_effic, gun);
966 mpr(victim, "Incoming fire does %d damage!\n", dam);
968 "%s fires at %s land units in %s for %d!\n",
969 xyas(fsect.sct_x, fsect.sct_y,
971 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
972 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
975 return lnd_damage(list, totdam);
981 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
986 if (!opt_NO_FORT_FIRE)
987 /* Steve M. - commented out for now until abuse is decided upon */
988 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
993 unit_interdict(newx, newy, victim, "land units",
994 lnd_easiest_target(list), MI_INTERDICT));
998 lnd_missile_interdiction(list, newx, newy, victim));
1002 /* high value of hardtarget is harder to hit */
1004 lnd_hardtarget(struct lndstr *lp)
1008 getsect(lp->lnd_x, lp->lnd_y, §);
1009 return (int)(((double)lp->lnd_effic / 100.0) *
1010 (10 + dchr[sect.sct_type].d_dstr * 2 +
1011 (double)lp->lnd_spd / 2.0 - lp->lnd_vis));
1015 lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
1019 mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
1020 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1022 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
1025 if (lcp->l_flags & L_ENGINEER)
1028 landdamage(lp, ldround(m, 1));
1034 lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
1039 /* supply unit's speed depends on their eff, since
1040 that is their purpose */
1041 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
1042 mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd;
1044 mobcost = lp->lnd_spd;
1048 /* sector_mcost now takes 2 different arguments, a sector pointer, and
1049 whether or not to figure in the highway bonus, rail bonus or none.
1050 bridge heads, bridges and highways have built-in highways bonus
1051 because they are a 1, and this will discount that. */
1053 smobcost = (double)sector_mcost(sp, mobtype);
1054 if (smobcost < 0.01)
1057 /* marching through 0 mobility conquered sectors takes lots of mobility,
1058 unless you are a train. Capturing railways is a good thing. */
1060 if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 &&
1061 smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL)
1062 smobcost = LND_MINMOBCOST;
1064 mobcost = smobcost * 5.0 * 480.0 /
1065 (mobcost + techfact(lp->lnd_tech, mobcost));
1071 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
1074 struct sctstr sect, osect;
1075 struct emp_qelem *qp;
1076 struct emp_qelem *qp2;
1077 struct emp_qelem *next;
1090 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
1091 lnd_put(list, actor);
1094 dx = diroff[dir][0];
1095 dy = diroff[dir][1];
1096 for (qp = list->q_back; qp != list; qp = next) {
1098 llp = (struct llist *)qp;
1099 getsect(llp->land.lnd_x, llp->land.lnd_y, &osect);
1100 oldown = osect.sct_own;
1101 newx = xnorm(llp->land.lnd_x + dx);
1102 newy = ynorm(llp->land.lnd_y + dy);
1103 getsect(newx, newy, §);
1104 rel = getrel(getnatp(sect.sct_own), player->cnum);
1105 if ((sect.sct_own != actor && rel != ALLIED &&
1106 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
1107 sect.sct_own) || (sect.sct_type == SCT_WATER ||
1108 sect.sct_type == SCT_SANCT ||
1109 sect.sct_type == SCT_WASTE)) {
1111 pr("can't go to %s\n", xyas(newx, newy, actor));
1114 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
1120 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY))
1122 if (sect.sct_rail == 0 &&
1123 lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1125 pr("no rail system in %s\n", xyas(newx, newy, actor));
1128 sprintf(dp, "has no rail system in %s",
1129 xyas(newx, newy, actor));
1134 /* Note we check would_abandon first because we don't want
1135 to always have to do these checks */
1136 if (would_abandon(&osect, I_CIVIL, 0, &(llp->land))) {
1138 if (!want_to_abandon(&osect, I_CIVIL, 0, &(llp->land))) {
1141 /* now check stuff */
1142 if (!check_sect_ok(§))
1144 if (!check_sect_ok(&osect))
1146 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
1147 if (!check_land_ok(&(((struct llist *)qp2)->land)))
1151 lnd_mess("stops", llp);
1155 if (llp->mobil <= 0.0) {
1156 lnd_mess("is out of mobility", llp);
1159 llp->land.lnd_x = newx;
1160 llp->land.lnd_y = newy;
1161 if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1162 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL);
1164 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_ROAD);
1166 llp->land.lnd_mobil = (int)llp->mobil;
1167 llp->land.lnd_harden = 0;
1168 putland(llp->land.lnd_uid, &llp->land);
1170 getsect(osect.sct_x, osect.sct_y, &osect);
1171 if (osect.sct_own != oldown && oldown == player->cnum) {
1172 /* It was your sector, now it's not. Simple :) */
1173 pr("You no longer own %s\n",
1174 xyas(osect.sct_x, osect.sct_y, player->cnum));
1176 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
1177 /* Always a 10% chance of getting caught. */
1178 if (chance(LND_SPY_DETECT_CHANCE(llp->land.lnd_effic))) {
1179 if (rel == NEUTRAL || rel == FRIENDLY) {
1181 "%s unit spotted in %s\n", cname(player->cnum),
1182 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1183 setrel(sect.sct_own, llp->land.lnd_own, HOSTILE);
1184 } else if (rel == HOSTILE || rel == AT_WAR ||
1185 rel == SITZKRIEG || rel == MOBILIZATION) {
1187 "%s spy shot in %s\n", cname(player->cnum),
1188 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1189 pr("%s was shot and killed.\n", prland(&llp->land));
1190 llp->land.lnd_effic = 0;
1191 putland(llp->land.lnd_uid, &llp->land);
1199 lnd_sweep(list, 0, 1, actor);
1200 stopping |= lnd_check_mines(list);
1204 stopping |= lnd_interdict(list, newx, newy, actor);
1209 * find all artillery units belonging
1210 * to the attacker or defender that can fire.
1211 * Each arty unit adds +1%/damage point
1215 lnd_support(natid victim, natid attacker, coord x, coord y)
1217 struct nstr_item ni;
1224 double range, range2;
1226 snxtitem_all(&ni, EF_LAND);
1227 while (nxtitem(&ni, (s_char *)&land)) {
1228 if (land.lnd_frg == 0)
1230 if ((land.lnd_x == x) && (land.lnd_y == y))
1232 if (land.lnd_ship >= 0)
1234 if (land.lnd_land >= 0)
1236 if (land.lnd_mission > 0)
1238 if (land.lnd_effic < LAND_MINFIREEFF)
1240 /* Do we have mil? */
1241 if (land.lnd_item[I_MILIT] <= 0)
1243 rel = getrel(getnatp(land.lnd_own), attacker);
1244 rel2 = getrel(getnatp(land.lnd_own), victim);
1245 if ((land.lnd_own != attacker) &&
1246 ((rel != ALLIED) || (rel2 != AT_WAR)))
1249 /* do we have supplies? */
1250 if (!has_supply(&land))
1253 /* are we in range? */
1254 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1256 range = techfact((int)land.lnd_tech, (double)land.lnd_frg / 2.0);
1258 range2 = roundrange(range);
1262 shell = land.lnd_item[I_SHELL];
1263 gun = land.lnd_item[I_GUN];
1265 if (shell == 0 || gun == 0)
1269 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1270 if (roll(100) < land.lnd_acc) {
1271 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1272 land.lnd_ammo, shell) / 2;
1274 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1275 land.lnd_ammo, shell);
1277 if (land.lnd_own != attacker)
1279 "%s supported %s at %s\n",
1280 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1286 lnd_path(int together, struct lndstr *lp, s_char *buf)
1290 struct sctstr d_sect, sect;
1294 if (!sarg_xy(buf, &destx, &desty))
1297 pr("Cannot go to a destination sector if not all starting in the same sector\n");
1300 if (!getsect(destx, desty, &d_sect)) {
1301 pr("%d,%d is not a sector\n", destx, desty);
1304 getsect(lp->lnd_x, lp->lnd_y, §);
1305 if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
1306 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_RAIL);
1308 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_ROAD);
1310 pr("No owned path from %s to %s!\n",
1311 xyas(lp->lnd_x, lp->lnd_y, player->cnum),
1312 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1315 pr("Using path '%s'\n", cp);
1320 lnd_can_attack(struct lndstr *lp)
1322 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1324 /* if (lcp->l_flags & L_SUPPLY ||
1325 lcp->l_flags & L_SECURITY ||
1326 lcp->l_flags & L_FLAK ||
1329 if (lcp->l_flags & L_SUPPLY)
1336 * Increase fortification value of LP.
1337 * Fortification costs mobility. Use up to HARD_AMT mobility.
1338 * Return actual fortification increase.
1341 lnd_fortify (struct lndstr *lp, int hard_amt)
1346 if ((lp->lnd_ship >= 0) || lp->lnd_land >= 0)
1349 hard_amt = min(lp->lnd_mobil, hard_amt);
1351 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1352 hard_amt = land_mob_max - lp->lnd_harden;
1354 eng = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own);
1357 hard_amt = ((float)hard_amt * 1.5);
1359 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1360 hard_amt = land_mob_max - lp->lnd_harden;
1362 /* Ok, set the mobility used */
1363 mob_used = hard_amt;
1365 /* Now, if an engineer helped, it's really only 2/3rds of
1368 mob_used = (int)((float)mob_used / 1.5);
1370 /* If we increased it, but not much, we gotta take at least 1
1372 if (mob_used <= 0 && hard_amt > 0)
1375 lp->lnd_mobil -= mob_used;
1376 if (lp->lnd_mobil < 0)
1379 lp->lnd_harden += hard_amt;
1380 lp->lnd_harden = min(lp->lnd_harden, land_mob_max);
1386 * Set LP's tech to TLEV along with everything else that depends on it.
1389 lnd_set_tech(struct lndstr *lp, int tlev)
1391 struct lchrstr *lcp = lchr + lp->lnd_type;
1392 int tech_diff = tlev - lcp->l_tech;
1394 if (CANT_HAPPEN(tech_diff < 0)) {
1399 lp->lnd_tech = tlev;
1400 lp->lnd_att = (float)LND_ATTDEF(lcp->l_att, tech_diff);
1401 lp->lnd_def = (float)LND_ATTDEF(lcp->l_def, tech_diff);
1402 lp->lnd_vul = (int)LND_VUL(lcp->l_vul, tech_diff);
1403 lp->lnd_spd = (int)LND_SPD(lcp->l_spd, tech_diff);
1404 lp->lnd_vis = (int)LND_VIS(lcp->l_vis, tech_diff);
1405 lp->lnd_spy = (int)LND_SPY(lcp->l_spy, tech_diff);
1406 lp->lnd_rad = (int)LND_RAD(lcp->l_rad, tech_diff);
1407 lp->lnd_frg = (int)LND_FRG(lcp->l_frg, tech_diff);
1408 lp->lnd_acc = (int)LND_ACC(lcp->l_acc, tech_diff);
1409 lp->lnd_dam = (int)LND_DAM(lcp->l_dam, tech_diff);
1410 lp->lnd_ammo = (int)LND_AMM(lcp->l_ammo, lcp->l_dam, tech_diff);
1411 lp->lnd_aaf = (int)LND_AAF(lcp->l_aaf, tech_diff);
1412 lp->lnd_fuelc = (int)LND_FC(lcp->l_fuelc, tech_diff);
1413 lp->lnd_fuelu = (int)LND_FU(lcp->l_fuelu, tech_diff);
1414 lp->lnd_maxlight = (int)LND_XPL(lcp->l_nxlight, tech_diff);
1415 lp->lnd_maxland = (int)LND_MXL(lcp->l_mxland, tech_diff);