2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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
52 #include "prototypes.h"
55 attack_val(int combat_mode, struct lndstr *lp)
61 if (((int)lp->lnd_effic) < LAND_MINEFF) {
62 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
64 putland(lp->lnd_uid, lp);
68 lcp = &lchr[(int)lp->lnd_type];
70 /* Spies always count as 1 during assaults. If they are the only ones
71 in the assault, they get to sneak on anyway. */
73 if (lcp->l_flags & L_SPY && combat_mode == A_ASSAULT)
78 value = ldround(((double)men * (double)lp->lnd_att), 1);
80 value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
82 switch (combat_mode) {
86 if (!(lcp->l_flags & L_MARINE))
87 return (int)(assault_penalty * value);
90 if (!(lcp->l_flags & L_MARINE))
91 return (int)(assault_penalty * men);
98 defense_val(struct lndstr *lp)
104 if (((int)lp->lnd_effic) < LAND_MINEFF) {
105 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
107 putland(lp->lnd_uid, lp);
111 lcp = &lchr[(int)lp->lnd_type];
117 if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) &&
118 !(lcp->l_flags & L_MARINE))
121 value = men * lp->lnd_def;
124 ((double)land_mob_max + lp->lnd_harden) / (double)land_mob_max;
125 value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
126 value = (int)ldround(value, 1);
128 /* If there are military on the unit, you get at least a 1
129 man defensive unit, except for spies */
130 if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
137 total_mil(struct lndstr *lp)
142 lcp = &lchr[(int)lp->lnd_type];
144 men = lnd_getmil(lp);
145 /* men *= ((double)lp->lnd_effic)/100.0;*/
147 return ldround(men, 1);
151 lnd_print(struct llist *llp, s_char *s)
153 if (llp->land.lnd_own == player->cnum)
154 pr("%s %s\n", prland(&llp->land), s);
156 wu(0, llp->land.lnd_own, "%s %s\n", prland(&llp->land), s);
160 lnd_delete(struct llist *llp, s_char *s)
164 putland(llp->land.lnd_uid, &llp->land);
165 emp_remque((struct emp_qelem *)llp);
170 lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
171 /* attacking or assaulting or paratrooping? */
172 /* number of casualties to take */
185 int nowhere_to_go = 0;
193 taken = lnd_getmil(&(llp->land));
194 /* Spies always die */
195 if (llp->lcp->l_flags & L_SPY) {
197 llp->land.lnd_effic = 0;
200 ldround((((double)cas * 100.0) / (double)llp->lcp->l_mil), 1);
201 llp->land.lnd_effic -= eff_eq;
202 lnd_submil(&(llp->land), cas);
205 if (llp->land.lnd_effic < LAND_MINEFF) {
206 sprintf(buf, "dies %s %s!",
207 combat_mode ? att_mode[combat_mode] : (s_char *)
208 "defending", xyas(llp->land.lnd_x, llp->land.lnd_y,
210 lnd_delete(llp, buf);
211 /* Since we killed the unit, we killed all the mil on it */
214 /* Ok, now, how many did we take off? (sould be the diff) */
215 taken = taken - lnd_getmil(&(llp->land));
218 if (llp->land.lnd_effic >= llp->land.lnd_retreat)
221 /* we're being boarded */
222 if (llp->land.lnd_ship >= 0 && combat_mode == A_DEFEND)
225 /* we're being boarded */
226 if (llp->land.lnd_land >= 0 && combat_mode == A_DEFEND)
229 /* Have to make a retreat check */
231 ret_chance = llp->land.lnd_retreat - llp->land.lnd_effic;
232 if (roll(100) < ret_chance) {
234 lnd_print(llp, "fails morale check!");
235 llp->land.lnd_mission = 0;
236 llp->land.lnd_harden = 0;
237 if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0)
239 else if (combat_mode == A_DEFEND) {
241 * defending unit.. find a place to send it
242 * strategy: look for the most-populated
243 * adjacent sector that is owned by the unit
244 * player->owner. Charge mob..
248 for (n = 1; n <= 6; ++n) {
249 ret_x = llp->land.lnd_x + diroff[n][0];
250 ret_y = llp->land.lnd_y + diroff[n][1];
251 getsect(ret_x, ret_y, §);
252 if (sect.sct_own != llp->land.lnd_own)
254 if (sect.sct_type == SCT_MOUNT)
257 civs = sect.sct_item[I_CIVIL];
258 if (civs > biggest) {
267 /* retreat to bx,by */
268 llp->land.lnd_x = bx;
269 llp->land.lnd_y = by;
270 getsect(bx, by, &rsect);
271 mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD);
272 mob = llp->land.lnd_mobil - (int)mobcost;
275 orig = llp->land.lnd_mobil;
276 llp->land.lnd_mobil = (s_char)mob;
277 if (llp->land.lnd_mobil > orig)
278 llp->land.lnd_mobil = (-127);
279 sprintf(buf, "retreats at %d%% efficiency to %s!",
281 xyas(bx, by, llp->land.lnd_own));
282 lnd_delete(llp, buf);
284 } else { /* attacking from a sector */
285 sprintf(buf, "leaves the battlefield at %d%% efficiency",
286 llp->land.lnd_effic);
287 if ((llp->land.lnd_mobil - (int)llp->mobil) < -127)
288 llp->land.lnd_mobil = -127;
290 llp->land.lnd_mobil -= (int)llp->mobil;
292 lnd_delete(llp, buf);
296 /* nowhere to go.. take more casualties */
297 llp->land.lnd_effic -= 10;
298 lnd_submil(&llp->land, llp->lcp->l_mil / 10);
299 if (llp->land.lnd_effic < LAND_MINEFF)
300 lnd_delete(llp, "has nowhere to retreat, and dies!");
303 "has nowhere to retreat and takes extra losses!");
310 lnd_takemob(struct emp_qelem *list, double loss)
312 struct emp_qelem *qp, *next;
315 int mcost = ldround(combat_mob * loss, 1);
317 for (qp = list->q_forw; qp != list; qp = next) {
319 llp = (struct llist *)qp;
322 use_supply(&llp->land);
323 if (llp->land.lnd_mission == MI_RESERVE)
324 new = llp->land.lnd_mobil - mcost/2;
327 new = llp->land.lnd_mobil - mcost;
330 llp->land.lnd_mobil = (s_char)new;
334 lnd_getmil(struct lndstr *lp)
336 return lp->lnd_item[I_MILIT];
340 lnd_submil(struct lndstr *lp, int num)
342 int new = lp->lnd_item[I_MILIT] - num;
343 lp->lnd_item[I_MILIT] = new < 0 ? 0 : new;
347 lnd_spyval(struct lndstr *lp)
349 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
350 return (lp->lnd_spy * (lp->lnd_effic / 100.0)) + 2;
352 return (lp->lnd_spy * (lp->lnd_effic / 100.0));
356 intelligence_report(int destination, struct lndstr *lp, int spy,
360 s_char buf1[80], buf2[80], buf3[80];
361 double estimate = 0.0; /* estimated defense value */
363 if (destination == 0)
366 if (lp->lnd_own == 0)
369 lcp = &lchr[(int)lp->lnd_type];
371 memset(buf1, 0, sizeof(buf1));
372 memset(buf2, 0, sizeof(buf2));
373 memset(buf3, 0, sizeof(buf3));
374 if (chance((double)(spy + lp->lnd_vis) / 10.0)) {
375 if (destination == player->cnum)
376 pr("%s %s", mess, prland(lp));
378 sprintf(buf1, "%s %s", mess, prland(lp));
380 estimate = lnd_getmil(lp);
382 if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
384 if (destination == player->cnum)
385 pr(" (eff %d, mil %d", roundintby(lp->lnd_effic, 5),
386 roundintby(lnd_getmil(lp), 10));
388 sprintf(buf2, " (eff %d, mil %d",
389 roundintby(lp->lnd_effic, 5),
390 roundintby(lnd_getmil(lp), 10));
391 estimate = lnd_getmil(lp) * lp->lnd_effic / 100.0;
393 if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
395 t = lp->lnd_tech - 20 + roll(40);
397 if (destination == player->cnum)
398 pr(", tech %d)\n", t);
400 sprintf(buf3, ", tech %d)\n", t);
402 if (destination == player->cnum)
405 sprintf(buf3, ")\n");
408 if (destination == player->cnum)
415 if (destination != player->cnum) {
416 wu(0, destination, "%s%s%s", buf1, buf2, buf3);
419 if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
420 estimate *= lp->lnd_def;
422 return (int)estimate;
425 /* Used by the spy command to count land units in a sector. If used
426 for anything else, you may want to reconsider, because this doesn't
427 always count spies. :) */
429 count_sect_units(struct sctstr *sp)
435 snxtitem_all(&ni, EF_LAND);
436 while (nxtitem(&ni, (s_char *)&land)) {
439 if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y)
441 /* Don't always see spies */
442 if (lchr[(int)land.lnd_type].l_flags & L_SPY) {
443 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
446 /* Got here, report it */
454 count_units(struct shpstr *sp)
460 if (sp->shp_effic < SHIP_MINEFF)
463 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
464 while (nxtitem(&ni, (s_char *)&land)) {
465 if (land.lnd_own == 0)
467 if (land.lnd_ship == sp->shp_uid)
471 if (sp->shp_nland != nland) {
472 sp->shp_nland = nland;
473 putship(sp->shp_uid, sp);
478 lnd_count_units(struct lndstr *lp)
484 if (lp->lnd_effic < LAND_MINEFF)
487 snxtitem_xy(&ni, EF_LAND, lp->lnd_x, lp->lnd_y);
488 while (nxtitem(&ni, (s_char *)&land)) {
489 if (land.lnd_own == 0)
491 if (land.lnd_land == lp->lnd_uid)
495 if (lp->lnd_nland != nland) {
496 lp->lnd_nland = nland;
497 putland(lp->lnd_uid, lp);
502 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
514 while (nxtitem(ni, (s_char *)&land)) {
518 if (ontradingblock(EF_LAND, (int *)&land)) {
519 pr("unit #%d inelligible - it's for sale.\n",
524 lcp = &lchr[(int)land.lnd_type];
525 /* if (wantflags && (lcp->m_flags & wantflags) != wantflags)
527 if (nowantflags && lcp->m_flags & nowantflags)
530 /* This abuse is better fixed by building a unit with the normal negative
531 mobility that everything else is built with */
532 /* Just so that the player can't build a bunch of land units, and them
533 march them a few minutes later... */
535 if (opt_MOB_ACCESS) {
536 if (land.lnd_effic < 11 &&
537 land.lnd_mobil < etu_per_update) {
538 pr("Land unit #%d needs at least %d mob to march.\n",
539 land.lnd_uid, etu_per_update);
544 land.lnd_mission = 0;
547 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
548 putland(land.lnd_uid, &land);
549 llp = (struct llist *)malloc(sizeof(struct llist));
552 llp->mobil = (double)land.lnd_mobil;
553 emp_insque(&llp->queue, list);
557 /* This function assumes that the list was created by lnd_sel */
559 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
560 int *togetherp, natid actor)
562 struct emp_qelem *qp;
563 struct emp_qelem *next;
576 for (qp = list->q_back; qp != list; qp = next) {
578 llp = (struct llist *)qp;
579 getland(llp->land.lnd_uid, &land);
580 if (land.lnd_own != actor) {
581 mpr(actor, "%s was disbanded at %s\n",
582 prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
583 emp_remque((struct emp_qelem *)llp);
587 if (land.lnd_ship >= 0) {
588 lnd_mess("is on a ship", llp);
591 if (land.lnd_land >= 0) {
592 lnd_mess("is on a unit", llp);
595 if (!getsect(land.lnd_x, land.lnd_y, §)) {
596 lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
599 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
600 !(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) &&
601 lnd_getmil(&llp->land) == 0) {
602 lnd_mess("has no mil on it to guide it", llp);
605 rel = getrel(getnatp(sect.sct_own), player->cnum);
606 if (sect.sct_own != land.lnd_own && rel != ALLIED &&
607 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
609 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
618 if (land.lnd_x != allx || land.lnd_y != ally)
620 if (land.lnd_mobil + 1 < (int)llp->mobil) {
621 llp->mobil = (double)land.lnd_mobil;
623 if (llp->mobil < *minmobp)
624 *minmobp = llp->mobil;
625 if (llp->mobil > *maxmobp)
626 *maxmobp = llp->mobil;
632 lnd_put(struct emp_qelem *list, natid actor)
634 struct emp_qelem *qp;
635 struct emp_qelem *newqp;
640 llp = (struct llist *)qp;
642 mpr(actor, "%s stopped at %s\n", prland(&llp->land),
643 xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
644 if (llp->mobil < -127)
646 llp->land.lnd_mobil = llp->mobil;
648 putland(llp->land.lnd_uid, &llp->land);
657 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
660 struct emp_qelem *qp;
661 struct emp_qelem *next;
664 int mines, m, max, sshells, lshells;
667 for (qp = land_list->q_back; qp != land_list; qp = next) {
669 llp = (struct llist *)qp;
670 if (!(llp->lcp->l_flags & L_ENGINEER)) {
672 mpr(actor, "%s is not an engineer!\n", prland(&llp->land));
675 if (takemob && llp->mobil < 0.0) {
677 lnd_mess("is out of mobility", llp);
680 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
681 if (sect.sct_oldown == llp->land.lnd_own) {
684 "%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
688 if (sect.sct_type == SCT_BSPAN) {
690 mpr(actor, "%s is on a bridge. No mines there!\n",
695 /* mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/
696 mobcost = llp->land.lnd_spd;
697 mobcost = 480.0 / (mobcost +
698 techfact(llp->land.lnd_tech, mobcost));
699 llp->mobil -= mobcost;
700 llp->land.lnd_mobil = (int)llp->mobil;
701 llp->land.lnd_harden = 0;
703 putland(llp->land.lnd_uid, &llp->land);
704 if (!(mines = sect.sct_mines))
706 max = llp->lcp->l_item[I_SHELL];
707 lshells = llp->land.lnd_item[I_SHELL];
708 sshells = sect.sct_item[I_SHELL];
709 for (m = 0; mines > 0 && m < max * 2; m++) {
710 if (chance(0.5 * llp->lcp->l_att)) {
711 mpr(actor, "Sweep...\n");
715 else if (sshells < ITEM_MAX)
719 sect.sct_mines = mines;
720 llp->land.lnd_item[I_SHELL] = lshells;
721 sect.sct_item[I_SHELL] = sshells;
722 putland(llp->land.lnd_uid, &llp->land);
728 contains_engineer(struct emp_qelem *list)
730 struct emp_qelem *qp;
731 struct emp_qelem *next;
734 for (qp = list->q_back; qp != list; qp = next) {
736 llp = (struct llist *)qp;
737 if (llp->lcp->l_flags & L_ENGINEER)
744 lnd_check_mines(struct emp_qelem *land_list)
746 struct emp_qelem *qp;
747 struct emp_qelem *next;
751 int with_eng = contains_engineer(land_list);
753 for (qp = land_list->q_back; qp != land_list; qp = next) {
755 llp = (struct llist *)qp;
756 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
757 if (sect.sct_oldown == llp->land.lnd_own)
759 if (sect.sct_type == SCT_BSPAN)
763 if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
764 lnd_hit_mine(&llp->land, llp->lcp);
767 putland(llp->land.lnd_uid, (s_char *)&llp->land);
768 if (!llp->land.lnd_own) {
779 lnd_list(struct emp_qelem *land_list)
781 struct emp_qelem *qp;
782 struct emp_qelem *next;
786 pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
788 for (qp = land_list->q_back; qp != land_list; qp = next) {
790 llp = (struct llist *)qp;
792 pr("%4d ", lnd->lnd_uid);
793 pr("%-16.16s ", llp->lcp->l_name);
794 prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
795 pr("%1c", lnd->lnd_army);
796 pr("%4d%%", lnd->lnd_effic);
797 pr("%4d", lnd->lnd_item[I_SHELL]);
798 pr("%4d", lnd->lnd_item[I_GUN]);
799 count_land_planes(lnd);
800 pr("%3d", lnd->lnd_nxlight);
801 pr("%4d", lnd->lnd_mobil);
802 pr("%4d", lnd->lnd_tech);
803 pr("%4d%%", lnd->lnd_retreat);
804 pr("%5d\n", lnd->lnd_fuel);
809 lnd_mess(s_char *str, struct llist *llp)
811 mpr(llp->land.lnd_own, "%s %s & stays in %s\n",
813 str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
814 if (llp->mobil < -127)
816 llp->land.lnd_mobil = llp->mobil;
817 putland(llp->land.lnd_uid, &llp->land);
818 emp_remque((struct emp_qelem *)llp);
823 lnd_count(struct emp_qelem *list)
825 struct emp_qelem *qp;
826 struct emp_qelem *next;
830 for (qp = list->q_back; qp != list; qp = next) {
832 llp = (struct llist *)qp;
839 lnd_damage(struct emp_qelem *list, int totdam)
841 struct emp_qelem *qp;
842 struct emp_qelem *next;
847 if (!totdam || !(count = lnd_count(list)))
849 dam = ldround(((double)totdam / (double)count), 1);
850 for (qp = list->q_back; qp != list; qp = next) {
852 llp = (struct llist *)qp;
853 /* have to get it again because of collateral damage */
854 getland(llp->land.lnd_uid, &llp->land);
855 landdamage(&llp->land, dam);
856 putland(llp->land.lnd_uid, &llp->land);
857 if (!llp->land.lnd_own) {
866 lnd_easiest_target(struct emp_qelem *list)
868 struct emp_qelem *qp;
869 struct emp_qelem *next;
872 int easiest = 9876; /* things start great for victim */
875 for (qp = list->q_back; qp != list; qp = next) {
877 llp = (struct llist *)qp;
878 hard = lnd_hardtarget(&llp->land);
880 easiest = hard; /* things get worse for victim */
883 return easiest - count;
887 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
891 struct emp_qelem msl_list, *qp, *newqp;
893 msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
895 dam = msl_launch_mindam(&msl_list, newx, newy,
896 lnd_easiest_target(list), EF_LAND,
897 lnd_count(list) * 20, "troops", victim,
900 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
901 collateral_damage(newx, newy, dam, 0);
903 qp = msl_list.q_forw;
904 while (qp != msl_list.q_forw) {
914 /* Steve M. - commented out for now until abuse is decided upon */
915 /* risner: allow forts to interdict land units. */
917 lnd_fort_interdiction(struct emp_qelem *list,
918 coord newx, coord newy, natid victim)
923 double range, range2, guneff;
929 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
930 while (nxtsct(&ns, &fsect)) {
931 if (fsect.sct_own == 0)
933 if (fsect.sct_own == victim)
935 if (fsect.sct_type != SCT_FORTR)
937 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
939 gun = fsect.sct_item[I_GUN];
942 range = tfactfire(fsect.sct_own, (double)min(gun, 7));
943 if (fsect.sct_effic > 59)
945 range2 = roundrange(range);
946 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
949 if (fsect.sct_item[I_MILIT] < 5)
951 shell = fsect.sct_item[I_SHELL];
953 shell += supply_commod(fsect.sct_own,
954 fsect.sct_x, fsect.sct_y, I_SHELL, 1);
958 fsect.sct_item[I_SHELL] = shell;
962 guneff = landgun((int)fsect.sct_effic, gun);
965 mpr(victim, "Incoming fire does %d damage!\n", dam);
967 "%s fires at %s land units in %s for %d!\n",
968 xyas(fsect.sct_x, fsect.sct_y,
970 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
971 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
974 return lnd_damage(list, totdam);
980 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
985 if (!opt_NO_FORT_FIRE)
986 /* Steve M. - commented out for now until abuse is decided upon */
987 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
992 unit_interdict(newx, newy, victim, "land units",
993 lnd_easiest_target(list), MI_INTERDICT));
997 lnd_missile_interdiction(list, newx, newy, victim));
1001 /* high value of hardtarget is harder to hit */
1003 lnd_hardtarget(struct lndstr *lp)
1007 getsect(lp->lnd_x, lp->lnd_y, §);
1008 return (int)(((double)lp->lnd_effic / 100.0) *
1009 (10 + dchr[sect.sct_type].d_dstr * 2 +
1010 (double)lp->lnd_spd / 2.0 - lp->lnd_vis));
1014 lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
1018 mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
1019 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1021 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
1024 if (lcp->l_flags & L_ENGINEER)
1027 landdamage(lp, ldround(m, 1));
1033 lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
1038 /* supply unit's speed depends on their eff, since
1039 that is their purpose */
1040 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
1041 mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd;
1043 mobcost = lp->lnd_spd;
1047 /* sector_mcost now takes 2 different arguments, a sector pointer, and
1048 whether or not to figure in the highway bonus, rail bonus or none.
1049 bridge heads, bridges and highways have built-in highways bonus
1050 because they are a 1, and this will discount that. */
1052 smobcost = (double)sector_mcost(sp, mobtype);
1053 if (smobcost < 0.01)
1056 /* marching through 0 mobility conquered sectors takes lots of mobility,
1057 unless you are a train. Capturing railways is a good thing. */
1059 if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 &&
1060 smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL)
1061 smobcost = LND_MINMOBCOST;
1063 mobcost = smobcost * 5.0 * 480.0 /
1064 (mobcost + techfact(lp->lnd_tech, mobcost));
1070 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
1073 struct sctstr sect, osect;
1074 struct emp_qelem *qp;
1075 struct emp_qelem *qp2;
1076 struct emp_qelem *next;
1078 struct emp_qelem cur, done;
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));
1119 if (sect.sct_rail == 0 &&
1120 lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1122 pr("no rail system in %s\n", xyas(newx, newy, actor));
1125 sprintf(dp, "has no rail system in %s",
1126 xyas(newx, newy, actor));
1131 /* Note we check would_abandon first because we don't want
1132 to always have to do these checks */
1133 if (would_abandon(&osect, I_CIVIL, 0, &(llp->land))) {
1135 if (!want_to_abandon(&osect, I_CIVIL, 0, &(llp->land))) {
1138 /* now check stuff */
1139 if (!check_sect_ok(§))
1141 if (!check_sect_ok(&osect))
1143 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
1144 if (!check_land_ok(&(((struct llist *)qp2)->land)))
1148 lnd_mess("stops", llp);
1152 if (llp->mobil <= 0.0) {
1153 lnd_mess("is out of mobility", llp);
1156 llp->land.lnd_x = newx;
1157 llp->land.lnd_y = newy;
1158 if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1159 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL);
1161 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_ROAD);
1163 llp->land.lnd_mobil = (int)llp->mobil;
1164 llp->land.lnd_harden = 0;
1165 putland(llp->land.lnd_uid, &llp->land);
1167 getsect(osect.sct_x, osect.sct_y, &osect);
1168 if (osect.sct_own != oldown && oldown == player->cnum) {
1169 /* It was your sector, now it's not. Simple :) */
1170 pr("You no longer own %s\n",
1171 xyas(osect.sct_x, osect.sct_y, player->cnum));
1173 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
1174 /* Always a 10% chance of getting caught. */
1175 if (chance(LND_SPY_DETECT_CHANCE(llp->land.lnd_effic))) {
1176 if (rel == NEUTRAL || rel == FRIENDLY) {
1178 "%s unit spotted in %s\n", cname(player->cnum),
1179 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1180 setrel(sect.sct_own, llp->land.lnd_own, HOSTILE);
1181 } else if (rel == HOSTILE || rel == AT_WAR ||
1182 rel == SITZKRIEG || rel == MOBILIZATION) {
1184 "%s spy shot in %s\n", cname(player->cnum),
1185 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1186 pr("%s was shot and killed.\n", prland(&llp->land));
1187 llp->land.lnd_effic = 0;
1188 putland(llp->land.lnd_uid, &llp->land);
1196 lnd_sweep(list, 0, 1, actor);
1197 stopping |= lnd_check_mines(list);
1201 /* interdict land units sector by sector */
1204 while (!QEMPTY(list)) {
1205 llp = (struct llist *)list->q_back;
1206 newx = llp->land.lnd_x;
1207 newy = llp->land.lnd_y;
1208 /* move units in NEWX,NEWY to cur */
1210 for (qp = list->q_back; qp != list; qp = next) {
1212 llp = (struct llist *)qp;
1213 if (llp->land.lnd_x == newx && llp->land.lnd_y == newy) {
1215 emp_insque(qp, &cur);
1216 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY))
1220 /* interdict them */
1222 stopping |= lnd_interdict(&cur, newx, newy, actor);
1223 /* move survivors to done */
1224 for (qp = cur.q_back; qp != &cur; qp = next) {
1226 llp = (struct llist *)qp;
1228 emp_insque(qp, &done);
1231 /* assign surviving land units back to list */
1232 emp_insque(list, &done);
1239 * find all artillery units belonging
1240 * to the attacker or defender that can fire.
1241 * Each arty unit adds +1%/damage point
1245 lnd_support(natid victim, natid attacker, coord x, coord y)
1247 struct nstr_item ni;
1254 double range, range2;
1256 snxtitem_all(&ni, EF_LAND);
1257 while (nxtitem(&ni, (s_char *)&land)) {
1258 if (land.lnd_frg == 0)
1260 if ((land.lnd_x == x) && (land.lnd_y == y))
1262 if (land.lnd_ship >= 0)
1264 if (land.lnd_land >= 0)
1266 if (land.lnd_mission > 0)
1268 if (land.lnd_effic < LAND_MINFIREEFF)
1270 /* Do we have mil? */
1271 if (land.lnd_item[I_MILIT] <= 0)
1273 rel = getrel(getnatp(land.lnd_own), attacker);
1274 rel2 = getrel(getnatp(land.lnd_own), victim);
1275 if ((land.lnd_own != attacker) &&
1276 ((rel != ALLIED) || (rel2 != AT_WAR)))
1279 /* do we have supplies? */
1280 if (!has_supply(&land))
1283 /* are we in range? */
1284 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1286 range = techfact((int)land.lnd_tech, (double)land.lnd_frg / 2.0);
1288 range2 = roundrange(range);
1292 shell = land.lnd_item[I_SHELL];
1293 gun = land.lnd_item[I_GUN];
1295 if (shell == 0 || gun == 0)
1299 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1300 if (roll(100) < land.lnd_acc) {
1301 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1302 land.lnd_ammo, shell) / 2;
1304 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1305 land.lnd_ammo, shell);
1307 if (land.lnd_own != attacker)
1309 "%s supported %s at %s\n",
1310 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1316 lnd_path(int together, struct lndstr *lp, s_char *buf)
1320 struct sctstr d_sect, sect;
1324 if (!sarg_xy(buf, &destx, &desty))
1327 pr("Cannot go to a destination sector if not all starting in the same sector\n");
1330 if (!getsect(destx, desty, &d_sect)) {
1331 pr("%d,%d is not a sector\n", destx, desty);
1334 getsect(lp->lnd_x, lp->lnd_y, §);
1335 if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
1336 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_RAIL);
1338 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_ROAD);
1340 pr("No owned path from %s to %s!\n",
1341 xyas(lp->lnd_x, lp->lnd_y, player->cnum),
1342 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1345 pr("Using path '%s'\n", cp);
1350 lnd_can_attack(struct lndstr *lp)
1352 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1354 /* if (lcp->l_flags & L_SUPPLY ||
1355 lcp->l_flags & L_SECURITY ||
1356 lcp->l_flags & L_FLAK ||
1359 if (lcp->l_flags & L_SUPPLY)
1366 * Increase fortification value of LP.
1367 * Fortification costs mobility. Use up to HARD_AMT mobility.
1368 * Return actual fortification increase.
1371 lnd_fortify (struct lndstr *lp, int hard_amt)
1376 if ((lp->lnd_ship >= 0) || lp->lnd_land >= 0)
1379 hard_amt = min(lp->lnd_mobil, hard_amt);
1381 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1382 hard_amt = land_mob_max - lp->lnd_harden;
1384 eng = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own);
1387 hard_amt = ((float)hard_amt * 1.5);
1389 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1390 hard_amt = land_mob_max - lp->lnd_harden;
1392 /* Ok, set the mobility used */
1393 mob_used = hard_amt;
1395 /* Now, if an engineer helped, it's really only 2/3rds of
1398 mob_used = (int)((float)mob_used / 1.5);
1400 /* If we increased it, but not much, we gotta take at least 1
1402 if (mob_used <= 0 && hard_amt > 0)
1405 lp->lnd_mobil -= mob_used;
1406 if (lp->lnd_mobil < 0)
1409 lp->lnd_harden += hard_amt;
1410 lp->lnd_harden = min(lp->lnd_harden, land_mob_max);
1416 * Set LP's tech to TLEV along with everything else that depends on it.
1419 lnd_set_tech(struct lndstr *lp, int tlev)
1421 struct lchrstr *lcp = lchr + lp->lnd_type;
1422 int tech_diff = tlev - lcp->l_tech;
1424 if (CANT_HAPPEN(tech_diff < 0)) {
1429 lp->lnd_tech = tlev;
1430 lp->lnd_att = (float)LND_ATTDEF(lcp->l_att, tech_diff);
1431 lp->lnd_def = (float)LND_ATTDEF(lcp->l_def, tech_diff);
1432 lp->lnd_vul = (int)LND_VUL(lcp->l_vul, tech_diff);
1433 lp->lnd_spd = (int)LND_SPD(lcp->l_spd, tech_diff);
1434 lp->lnd_vis = (int)LND_VIS(lcp->l_vis, tech_diff);
1435 lp->lnd_spy = (int)LND_SPY(lcp->l_spy, tech_diff);
1436 lp->lnd_rad = (int)LND_RAD(lcp->l_rad, tech_diff);
1437 lp->lnd_frg = (int)LND_FRG(lcp->l_frg, tech_diff);
1438 lp->lnd_acc = (int)LND_ACC(lcp->l_acc, tech_diff);
1439 lp->lnd_dam = (int)LND_DAM(lcp->l_dam, tech_diff);
1440 lp->lnd_ammo = (int)LND_AMM(lcp->l_ammo, lcp->l_dam, tech_diff);
1441 lp->lnd_aaf = (int)LND_AAF(lcp->l_aaf, tech_diff);
1442 lp->lnd_fuelc = (int)LND_FC(lcp->l_fuelc, tech_diff);
1443 lp->lnd_fuelu = (int)LND_FU(lcp->l_fuelu, tech_diff);
1444 lp->lnd_maxlight = (int)LND_XPL(lcp->l_nxlight, tech_diff);
1445 lp->lnd_maxland = (int)LND_MXL(lcp->l_mxland, tech_diff);