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
54 #include "prototypes.h"
57 attack_val(int combat_mode, struct lndstr *lp)
63 if (((int)lp->lnd_effic) < LAND_MINEFF) {
64 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
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)
80 value = ldround(((double)men * (double)lp->lnd_att), 1);
82 value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
84 switch (combat_mode) {
88 if (!(lcp->l_flags & L_MARINE))
89 return (int)(assault_penalty * value);
92 if (!(lcp->l_flags & L_MARINE))
93 return (int)(assault_penalty * men);
100 defense_val(struct lndstr *lp)
106 if (((int)lp->lnd_effic) < LAND_MINEFF) {
107 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
109 putland(lp->lnd_uid, lp);
113 lcp = &lchr[(int)lp->lnd_type];
119 if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) &&
120 !(lcp->l_flags & L_MARINE))
123 value = men * lp->lnd_def;
126 ((double)land_mob_max + lp->lnd_harden) / (double)land_mob_max;
127 value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
128 value = (int)ldround(value, 1);
130 /* If there are military on the unit, you get at least a 1
131 man defensive unit, except for spies */
132 if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
139 total_mil(struct lndstr *lp)
144 lcp = &lchr[(int)lp->lnd_type];
146 men = lnd_getmil(lp);
147 /* men *= ((double)lp->lnd_effic)/100.0;*/
149 return ldround(men, 1);
153 lnd_print(struct llist *llp, s_char *s)
155 if (llp->land.lnd_own == player->cnum)
156 pr("%s %s\n", prland(&llp->land), s);
158 wu(0, llp->land.lnd_own, "%s %s\n", prland(&llp->land), s);
162 lnd_delete(struct llist *llp, s_char *s)
166 putland(llp->land.lnd_uid, &llp->land);
167 emp_remque((struct emp_qelem *)llp);
172 lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
173 /* attacking or assaulting or paratrooping? */
174 /* number of casualties to take */
187 int nowhere_to_go = 0;
195 taken = lnd_getmil(&(llp->land));
196 /* Spies always die */
197 if (llp->lcp->l_flags & L_SPY) {
199 llp->land.lnd_effic = 0;
202 ldround((((double)cas * 100.0) / (double)llp->lcp->l_mil), 1);
203 llp->land.lnd_effic -= eff_eq;
204 lnd_submil(&(llp->land), cas);
207 if (llp->land.lnd_effic < LAND_MINEFF) {
208 sprintf(buf, "dies %s %s!",
209 combat_mode ? att_mode[combat_mode] : (s_char *)
210 "defending", xyas(llp->land.lnd_x, llp->land.lnd_y,
212 lnd_delete(llp, buf);
213 /* Since we killed the unit, we killed all the mil on it */
216 /* Ok, now, how many did we take off? (sould be the diff) */
217 taken = taken - lnd_getmil(&(llp->land));
220 if (llp->land.lnd_effic >= llp->land.lnd_retreat)
223 /* we're being boarded */
224 if (llp->land.lnd_ship >= 0 && combat_mode == A_DEFEND)
227 /* we're being boarded */
228 if (llp->land.lnd_land >= 0 && combat_mode == A_DEFEND)
231 /* Have to make a retreat check */
233 ret_chance = llp->land.lnd_retreat - llp->land.lnd_effic;
234 if (roll(100) < ret_chance) {
236 lnd_print(llp, "fails morale check!");
237 llp->land.lnd_mission = 0;
238 llp->land.lnd_harden = 0;
239 if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0)
241 else if (combat_mode == A_DEFEND) {
243 * defending unit.. find a place to send it
244 * strategy: look for the most-populated
245 * adjacent sector that is owned by the unit
246 * player->owner. Charge mob..
250 for (n = 1; n <= 6; ++n) {
251 ret_x = llp->land.lnd_x + diroff[n][0];
252 ret_y = llp->land.lnd_y + diroff[n][1];
253 getsect(ret_x, ret_y, §);
254 if (sect.sct_own != llp->land.lnd_own)
256 if (sect.sct_type == SCT_MOUNT)
259 civs = sect.sct_item[I_CIVIL];
260 if (civs > biggest) {
269 /* retreat to bx,by */
270 llp->land.lnd_x = bx;
271 llp->land.lnd_y = by;
272 getsect(bx, by, &rsect);
273 mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD);
274 mob = llp->land.lnd_mobil - (int)mobcost;
277 orig = llp->land.lnd_mobil;
278 llp->land.lnd_mobil = (s_char)mob;
279 if (llp->land.lnd_mobil > orig)
280 llp->land.lnd_mobil = (-127);
281 sprintf(buf, "retreats at %d%% efficiency to %s!",
283 xyas(bx, by, llp->land.lnd_own));
284 lnd_delete(llp, buf);
286 } else { /* attacking from a sector */
287 sprintf(buf, "leaves the battlefield at %d%% efficiency",
288 llp->land.lnd_effic);
289 if ((llp->land.lnd_mobil - (int)llp->mobil) < -127)
290 llp->land.lnd_mobil = -127;
292 llp->land.lnd_mobil -= (int)llp->mobil;
294 lnd_delete(llp, buf);
298 /* nowhere to go.. take more casualties */
299 llp->land.lnd_effic -= 10;
300 lnd_submil(&llp->land, llp->lcp->l_mil / 10);
301 if (llp->land.lnd_effic < LAND_MINEFF)
302 lnd_delete(llp, "has nowhere to retreat, and dies!");
305 "has nowhere to retreat and takes extra losses!");
312 lnd_takemob(struct emp_qelem *list, double loss)
314 struct emp_qelem *qp, *next;
317 int mcost = ldround(combat_mob * loss, 1);
319 for (qp = list->q_forw; qp != list; qp = next) {
321 llp = (struct llist *)qp;
324 use_supply(&llp->land);
325 if (llp->land.lnd_mission == MI_RESERVE)
326 new = llp->land.lnd_mobil - mcost/2;
329 new = llp->land.lnd_mobil - mcost;
332 llp->land.lnd_mobil = (s_char)new;
336 lnd_getmil(struct lndstr *lp)
338 return lp->lnd_item[I_MILIT];
342 lnd_submil(struct lndstr *lp, int num)
344 int new = lp->lnd_item[I_MILIT] - num;
345 lp->lnd_item[I_MILIT] = new < 0 ? 0 : new;
349 lnd_spyval(struct lndstr *lp)
351 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
352 return (lp->lnd_spy * (lp->lnd_effic / 100.0)) + 2;
354 return (lp->lnd_spy * (lp->lnd_effic / 100.0));
358 intelligence_report(int destination, struct lndstr *lp, int spy,
362 s_char buf1[80], buf2[80], buf3[80];
363 double estimate = 0.0; /* estimated defense value */
365 if (destination == 0)
368 if (lp->lnd_own == 0)
371 lcp = &lchr[(int)lp->lnd_type];
373 memset(buf1, 0, sizeof(buf1));
374 memset(buf2, 0, sizeof(buf2));
375 memset(buf3, 0, sizeof(buf3));
376 if (chance((double)(spy + lp->lnd_vis) / 10.0)) {
377 if (destination == player->cnum)
378 pr("%s %s", mess, prland(lp));
380 sprintf(buf1, "%s %s", mess, prland(lp));
382 estimate = lnd_getmil(lp);
384 if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
386 if (destination == player->cnum)
387 pr(" (eff %d, mil %d", roundintby(lp->lnd_effic, 5),
388 roundintby(lnd_getmil(lp), 10));
390 sprintf(buf2, " (eff %d, mil %d",
391 roundintby(lp->lnd_effic, 5),
392 roundintby(lnd_getmil(lp), 10));
393 estimate = lnd_getmil(lp) * lp->lnd_effic / 100.0;
395 if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
397 t = lp->lnd_tech - 20 + roll(40);
399 if (destination == player->cnum)
400 pr(", tech %d)\n", t);
402 sprintf(buf3, ", tech %d)\n", t);
404 if (destination == player->cnum)
407 sprintf(buf3, ")\n");
410 if (destination == player->cnum)
417 if (destination != player->cnum) {
418 wu(0, destination, "%s%s%s", buf1, buf2, buf3);
421 if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
422 estimate *= lp->lnd_def;
424 return (int)estimate;
427 /* Used by the spy command to count land units in a sector. If used
428 for anything else, you may want to reconsider, because this doesn't
429 always count spies. :) */
431 count_sect_units(struct sctstr *sp)
437 snxtitem_all(&ni, EF_LAND);
438 while (nxtitem(&ni, (s_char *)&land)) {
441 if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y)
443 /* Don't always see spies */
444 if (lchr[(int)land.lnd_type].l_flags & L_SPY) {
445 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
448 /* Got here, report it */
456 count_units(struct shpstr *sp)
462 if (sp->shp_effic < SHIP_MINEFF)
465 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
466 while (nxtitem(&ni, (s_char *)&land)) {
467 if (land.lnd_own == 0)
469 if (land.lnd_ship == sp->shp_uid)
473 if (sp->shp_nland != nland) {
474 sp->shp_nland = nland;
475 putship(sp->shp_uid, sp);
480 lnd_count_units(struct lndstr *lp)
486 if (lp->lnd_effic < LAND_MINEFF)
489 snxtitem_xy(&ni, EF_LAND, lp->lnd_x, lp->lnd_y);
490 while (nxtitem(&ni, (s_char *)&land)) {
491 if (land.lnd_own == 0)
493 if (land.lnd_land == lp->lnd_uid)
497 if (lp->lnd_nland != nland) {
498 lp->lnd_nland = nland;
499 putland(lp->lnd_uid, lp);
504 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
516 while (nxtitem(ni, (s_char *)&land)) {
520 if (ontradingblock(EF_LAND, (int *)&land)) {
521 pr("unit #%d inelligible - it's for sale.\n",
526 lcp = &lchr[(int)land.lnd_type];
527 /* if (wantflags && (lcp->m_flags & wantflags) != wantflags)
529 if (nowantflags && lcp->m_flags & nowantflags)
532 /* This abuse is better fixed by building a unit with the normal negative
533 mobility that everything else is built with */
534 /* Just so that the player can't build a bunch of land units, and them
535 march them a few minutes later... */
537 if (opt_MOB_ACCESS) {
538 if (land.lnd_effic < 11 &&
539 land.lnd_mobil < etu_per_update) {
540 pr("Land unit #%d needs at least %d mob to march.\n",
541 land.lnd_uid, etu_per_update);
546 land.lnd_mission = 0;
549 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
550 putland(land.lnd_uid, &land);
551 llp = (struct llist *)malloc(sizeof(struct llist));
554 llp->mobil = (double)land.lnd_mobil;
555 emp_insque(&llp->queue, list);
559 /* This function assumes that the list was created by lnd_sel */
561 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
562 int *togetherp, natid actor)
564 struct emp_qelem *qp;
565 struct emp_qelem *next;
578 for (qp = list->q_back; qp != list; qp = next) {
580 llp = (struct llist *)qp;
581 getland(llp->land.lnd_uid, &land);
582 if (land.lnd_own != actor) {
583 mpr(actor, "%s was disbanded at %s\n",
584 prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
585 emp_remque((struct emp_qelem *)llp);
589 if (land.lnd_ship >= 0) {
590 lnd_mess("is on a ship", llp);
593 if (land.lnd_land >= 0) {
594 lnd_mess("is on a unit", llp);
597 if (!getsect(land.lnd_x, land.lnd_y, §)) {
598 lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
601 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
602 !(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) &&
603 lnd_getmil(&llp->land) == 0) {
604 lnd_mess("has no mil on it to guide it", llp);
607 rel = getrel(getnatp(sect.sct_own), player->cnum);
608 if (sect.sct_own != land.lnd_own && rel != ALLIED &&
609 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
611 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
620 if (land.lnd_x != allx || land.lnd_y != ally)
622 if (land.lnd_mobil + 1 < (int)llp->mobil) {
623 llp->mobil = (double)land.lnd_mobil;
625 if (llp->mobil < *minmobp)
626 *minmobp = llp->mobil;
627 if (llp->mobil > *maxmobp)
628 *maxmobp = llp->mobil;
634 lnd_put(struct emp_qelem *list, natid actor)
636 register struct emp_qelem *qp;
637 register struct emp_qelem *newqp;
642 llp = (struct llist *)qp;
644 mpr(actor, "%s stopped at %s\n", prland(&llp->land),
645 xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
646 if (llp->mobil < -127)
648 llp->land.lnd_mobil = llp->mobil;
650 putland(llp->land.lnd_uid, &llp->land);
659 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
662 struct emp_qelem *qp;
663 struct emp_qelem *next;
666 int mines, m, max, sshells, lshells;
669 for (qp = land_list->q_back; qp != land_list; qp = next) {
671 llp = (struct llist *)qp;
672 if (!(llp->lcp->l_flags & L_ENGINEER)) {
674 mpr(actor, "%s is not an engineer!\n", prland(&llp->land));
677 if (takemob && llp->mobil < 0.0) {
679 lnd_mess("is out of mobility", llp);
682 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
683 if (sect.sct_oldown == llp->land.lnd_own) {
686 "%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
690 if (sect.sct_type == SCT_BSPAN) {
692 mpr(actor, "%s is on a bridge. No mines there!\n",
697 /* mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/
698 mobcost = llp->land.lnd_spd;
699 mobcost = 480.0 / (mobcost +
700 techfact(llp->land.lnd_tech, mobcost));
701 llp->mobil -= mobcost;
702 llp->land.lnd_mobil = (int)llp->mobil;
703 llp->land.lnd_harden = 0;
705 putland(llp->land.lnd_uid, &llp->land);
706 if (!(mines = sect.sct_mines))
708 max = llp->lcp->l_item[I_SHELL];
709 lshells = llp->land.lnd_item[I_SHELL];
710 sshells = sect.sct_item[I_SHELL];
711 for (m = 0; mines > 0 && m < max * 2; m++) {
712 if (chance(0.5 * llp->lcp->l_att)) {
713 mpr(actor, "Sweep...\n");
717 else if (sshells < ITEM_MAX)
721 sect.sct_mines = mines;
722 llp->land.lnd_item[I_SHELL] = lshells;
723 sect.sct_item[I_SHELL] = sshells;
724 putland(llp->land.lnd_uid, &llp->land);
730 contains_engineer(struct emp_qelem *list)
732 struct emp_qelem *qp;
733 struct emp_qelem *next;
736 for (qp = list->q_back; qp != list; qp = next) {
738 llp = (struct llist *)qp;
739 if (llp->lcp->l_flags & L_ENGINEER)
746 lnd_check_mines(struct emp_qelem *land_list)
748 struct emp_qelem *qp;
749 struct emp_qelem *next;
753 int with_eng = contains_engineer(land_list);
755 for (qp = land_list->q_back; qp != land_list; qp = next) {
757 llp = (struct llist *)qp;
758 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
759 if (sect.sct_oldown == llp->land.lnd_own)
761 if (sect.sct_type == SCT_BSPAN)
765 if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
766 lnd_hit_mine(&llp->land, llp->lcp);
769 putland(llp->land.lnd_uid, (s_char *)&llp->land);
770 if (!llp->land.lnd_own) {
781 lnd_list(struct emp_qelem *land_list)
783 struct emp_qelem *qp;
784 struct emp_qelem *next;
788 pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
790 for (qp = land_list->q_back; qp != land_list; qp = next) {
792 llp = (struct llist *)qp;
794 pr("%4d ", lnd->lnd_uid);
795 pr("%-16.16s ", llp->lcp->l_name);
796 prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
797 pr("%1c", lnd->lnd_army);
798 pr("%4d%%", lnd->lnd_effic);
799 pr("%4d", lnd->lnd_item[I_SHELL]);
800 pr("%4d", lnd->lnd_item[I_GUN]);
801 count_land_planes(lnd);
802 pr("%3d", lnd->lnd_nxlight);
803 pr("%4d", lnd->lnd_mobil);
804 pr("%4d", lnd->lnd_tech);
805 pr("%4d%%", lnd->lnd_retreat);
806 pr("%5d\n", lnd->lnd_fuel);
811 lnd_mess(s_char *str, struct llist *llp)
813 mpr(llp->land.lnd_own, "%s %s & stays in %s\n",
815 str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
816 if (llp->mobil < -127)
818 llp->land.lnd_mobil = llp->mobil;
819 putland(llp->land.lnd_uid, &llp->land);
820 emp_remque((struct emp_qelem *)llp);
825 lnd_count(struct emp_qelem *list)
827 struct emp_qelem *qp;
828 struct emp_qelem *next;
832 for (qp = list->q_back; qp != list; qp = next) {
834 llp = (struct llist *)qp;
841 lnd_damage(struct emp_qelem *list, int totdam)
843 struct emp_qelem *qp;
844 struct emp_qelem *next;
849 if (!totdam || !(count = lnd_count(list)))
851 dam = ldround(((double)totdam / (double)count), 1);
852 for (qp = list->q_back; qp != list; qp = next) {
854 llp = (struct llist *)qp;
855 /* have to get it again because of collateral damage */
856 getland(llp->land.lnd_uid, &llp->land);
857 landdamage(&llp->land, dam);
858 putland(llp->land.lnd_uid, &llp->land);
859 if (!llp->land.lnd_own) {
868 lnd_easiest_target(struct emp_qelem *list)
870 struct emp_qelem *qp;
871 struct emp_qelem *next;
874 int easiest = 9876; /* things start great for victim */
877 for (qp = list->q_back; qp != list; qp = next) {
879 llp = (struct llist *)qp;
880 hard = lnd_hardtarget(&llp->land);
882 easiest = hard; /* things get worse for victim */
885 return easiest - count;
889 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
893 struct emp_qelem msl_list, *qp, *newqp;
895 msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
897 dam = msl_launch_mindam(&msl_list, newx, newy,
898 lnd_easiest_target(list), EF_LAND,
899 lnd_count(list) * 20, "troops", victim,
902 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
903 collateral_damage(newx, newy, dam, 0);
905 qp = msl_list.q_forw;
906 while (qp != msl_list.q_forw) {
916 /* Steve M. - commented out for now until abuse is decided upon */
917 /* risner: allow forts to interdict land units. */
919 lnd_fort_interdiction(struct emp_qelem *list,
920 coord newx, coord newy, natid victim)
925 double range, range2, guneff;
931 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
932 while (nxtsct(&ns, &fsect)) {
933 if (fsect.sct_own == 0)
935 if (fsect.sct_own == victim)
937 if (fsect.sct_type != SCT_FORTR)
939 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
941 gun = fsect.sct_item[I_GUN];
944 range = tfactfire(fsect.sct_own, (double)min(gun, 7));
945 if (fsect.sct_effic > 59)
947 range2 = roundrange(range);
948 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
951 if (fsect.sct_item[I_MILIT] < 5)
953 shell = fsect.sct_item[I_SHELL];
955 shell += supply_commod(fsect.sct_own,
956 fsect.sct_x, fsect.sct_y, I_SHELL, 1);
960 fsect.sct_item[I_SHELL] = shell;
964 guneff = landgun((int)fsect.sct_effic, gun);
967 mpr(victim, "Incoming fire does %d damage!\n", dam);
969 "%s fires at %s land units in %s for %d!\n",
970 xyas(fsect.sct_x, fsect.sct_y,
972 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
973 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
976 return lnd_damage(list, totdam);
982 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
987 if (!opt_NO_FORT_FIRE)
988 /* Steve M. - commented out for now until abuse is decided upon */
989 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
994 unit_interdict(newx, newy, victim, "land units",
995 lnd_easiest_target(list), MI_INTERDICT));
999 lnd_missile_interdiction(list, newx, newy, victim));
1003 /* high value of hardtarget is harder to hit */
1005 lnd_hardtarget(struct lndstr *lp)
1009 getsect(lp->lnd_x, lp->lnd_y, §);
1010 return (int)(((double)lp->lnd_effic / 100.0) *
1011 (10 + dchr[sect.sct_type].d_dstr * 2 +
1012 (double)lp->lnd_spd / 2.0 - lp->lnd_vis));
1016 lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
1020 mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
1021 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1023 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
1026 if (lcp->l_flags & L_ENGINEER)
1029 landdamage(lp, ldround(m, 1));
1035 lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
1040 /* supply unit's speed depends on their eff, since
1041 that is their purpose */
1042 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
1043 mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd;
1045 mobcost = lp->lnd_spd;
1049 /* sector_mcost now takes 2 different arguments, a sector pointer, and
1050 whether or not to figure in the highway bonus, rail bonus or none.
1051 bridge heads, bridges and highways have built-in highways bonus
1052 because they are a 1, and this will discount that. */
1054 smobcost = (double)sector_mcost(sp, mobtype);
1055 if (smobcost < 0.01)
1058 /* marching through 0 mobility conquered sectors takes lots of mobility,
1059 unless you are a train. Capturing railways is a good thing. */
1061 if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 &&
1062 smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL)
1063 smobcost = LND_MINMOBCOST;
1065 mobcost = smobcost * 5.0 * 480.0 /
1066 (mobcost + techfact(lp->lnd_tech, mobcost));
1072 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
1075 struct sctstr sect, osect;
1076 struct emp_qelem *qp;
1077 struct emp_qelem *qp2;
1078 struct emp_qelem *next;
1091 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
1092 lnd_put(list, actor);
1095 dx = diroff[dir][0];
1096 dy = diroff[dir][1];
1097 for (qp = list->q_back; qp != list; qp = next) {
1099 llp = (struct llist *)qp;
1100 getsect(llp->land.lnd_x, llp->land.lnd_y, &osect);
1101 oldown = osect.sct_own;
1102 newx = xnorm(llp->land.lnd_x + dx);
1103 newy = ynorm(llp->land.lnd_y + dy);
1104 getsect(newx, newy, §);
1105 rel = getrel(getnatp(sect.sct_own), player->cnum);
1106 if ((sect.sct_own != actor && rel != ALLIED &&
1107 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
1108 sect.sct_own) || (sect.sct_type == SCT_WATER ||
1109 sect.sct_type == SCT_SANCT ||
1110 sect.sct_type == SCT_WASTE)) {
1112 pr("can't go to %s\n", xyas(newx, newy, actor));
1115 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
1121 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY))
1123 if (sect.sct_rail == 0 &&
1124 lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1126 pr("no rail system in %s\n", xyas(newx, newy, actor));
1129 sprintf(dp, "has no rail system in %s",
1130 xyas(newx, newy, actor));
1135 /* Note we check would_abandon first because we don't want
1136 to always have to do these checks */
1137 if (would_abandon(&osect, I_CIVIL, 0, &(llp->land))) {
1139 if (!want_to_abandon(&osect, I_CIVIL, 0, &(llp->land))) {
1142 /* now check stuff */
1143 if (!check_sect_ok(§))
1145 if (!check_sect_ok(&osect))
1147 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
1148 if (!check_land_ok(&(((struct llist *)qp2)->land)))
1152 lnd_mess("stops", llp);
1156 if (llp->mobil <= 0.0) {
1157 lnd_mess("is out of mobility", llp);
1160 llp->land.lnd_x = newx;
1161 llp->land.lnd_y = newy;
1162 if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1163 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL);
1165 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_ROAD);
1167 llp->land.lnd_mobil = (int)llp->mobil;
1168 llp->land.lnd_harden = 0;
1169 putland(llp->land.lnd_uid, &llp->land);
1171 getsect(osect.sct_x, osect.sct_y, &osect);
1172 if (osect.sct_own != oldown && oldown == player->cnum) {
1173 /* It was your sector, now it's not. Simple :) */
1174 pr("You no longer own %s\n",
1175 xyas(osect.sct_x, osect.sct_y, player->cnum));
1177 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
1178 /* Always a 10% chance of getting caught. */
1179 if (chance(LND_SPY_DETECT_CHANCE(llp->land.lnd_effic))) {
1180 if (rel == NEUTRAL || rel == FRIENDLY) {
1182 "%s unit spotted in %s\n", cname(player->cnum),
1183 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1184 setrel(sect.sct_own, llp->land.lnd_own, HOSTILE);
1185 } else if (rel == HOSTILE || rel == AT_WAR ||
1186 rel == SITZKRIEG || rel == MOBILIZATION) {
1188 "%s spy shot in %s\n", cname(player->cnum),
1189 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1190 pr("%s was shot and killed.\n", prland(&llp->land));
1191 llp->land.lnd_effic = 0;
1192 putland(llp->land.lnd_uid, &llp->land);
1200 lnd_sweep(list, 0, 1, actor);
1201 stopping |= lnd_check_mines(list);
1205 stopping |= lnd_interdict(list, newx, newy, actor);
1210 * find all artillery units belonging
1211 * to the attacker or defender that can fire.
1212 * Each arty unit adds +1%/damage point
1216 lnd_support(natid victim, natid attacker, coord x, coord y)
1218 struct nstr_item ni;
1225 double range, range2;
1227 snxtitem_all(&ni, EF_LAND);
1228 while (nxtitem(&ni, (s_char *)&land)) {
1229 if (land.lnd_frg == 0)
1231 if ((land.lnd_x == x) && (land.lnd_y == y))
1233 if (land.lnd_ship >= 0)
1235 if (land.lnd_land >= 0)
1237 if (land.lnd_mission > 0)
1239 if (land.lnd_effic < LAND_MINFIREEFF)
1241 /* Do we have mil? */
1242 if (land.lnd_item[I_MILIT] <= 0)
1244 rel = getrel(getnatp(land.lnd_own), attacker);
1245 rel2 = getrel(getnatp(land.lnd_own), victim);
1246 if ((land.lnd_own != attacker) &&
1247 ((rel != ALLIED) || (rel2 != AT_WAR)))
1250 /* do we have supplies? */
1251 if (!has_supply(&land))
1254 /* are we in range? */
1255 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1257 range = techfact((int)land.lnd_tech, (double)land.lnd_frg / 2.0);
1259 range2 = roundrange(range);
1263 shell = land.lnd_item[I_SHELL];
1264 gun = land.lnd_item[I_GUN];
1266 if (shell == 0 || gun == 0)
1270 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1271 if (roll(100) < land.lnd_acc) {
1272 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1273 land.lnd_ammo, shell) / 2;
1275 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1276 land.lnd_ammo, shell);
1278 if (land.lnd_own != attacker)
1280 "%s supported %s at %s\n",
1281 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1287 lnd_path(int together, struct lndstr *lp, s_char *buf)
1291 struct sctstr d_sect, sect;
1295 if (!sarg_xy(buf, &destx, &desty))
1298 pr("Cannot go to a destination sector if not all starting in the same sector\n");
1301 if (!getsect(destx, desty, &d_sect)) {
1302 pr("%d,%d is not a sector\n", destx, desty);
1305 getsect(lp->lnd_x, lp->lnd_y, §);
1306 if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
1307 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_RAIL);
1309 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_ROAD);
1311 pr("No owned path from %s to %s!\n",
1312 xyas(lp->lnd_x, lp->lnd_y, player->cnum),
1313 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1316 pr("Using path '%s'\n", cp);
1321 lnd_can_attack(struct lndstr *lp)
1323 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1325 /* if (lcp->l_flags & L_SUPPLY ||
1326 lcp->l_flags & L_SECURITY ||
1327 lcp->l_flags & L_FLAK ||
1330 if (lcp->l_flags & L_SUPPLY)
1337 * Increase fortification value of LP.
1338 * Fortification costs mobility. Use up to HARD_AMT mobility.
1339 * Return actual fortification increase.
1342 lnd_fortify (struct lndstr *lp, int hard_amt)
1347 if ((lp->lnd_ship >= 0) || lp->lnd_land >= 0)
1350 hard_amt = min(lp->lnd_mobil, hard_amt);
1352 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1353 hard_amt = land_mob_max - lp->lnd_harden;
1355 eng = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own);
1358 hard_amt = ((float)hard_amt * 1.5);
1360 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1361 hard_amt = land_mob_max - lp->lnd_harden;
1363 /* Ok, set the mobility used */
1364 mob_used = hard_amt;
1366 /* Now, if an engineer helped, it's really only 2/3rds of
1369 mob_used = (int)((float)mob_used / 1.5);
1371 /* If we increased it, but not much, we gotta take at least 1
1373 if (mob_used <= 0 && hard_amt > 0)
1376 lp->lnd_mobil -= mob_used;
1377 if (lp->lnd_mobil < 0)
1380 lp->lnd_harden += hard_amt;
1381 lp->lnd_harden = min(lp->lnd_harden, land_mob_max);
1387 * Set LP's tech to TLEV along with everything else that depends on it.
1390 lnd_set_tech(struct lndstr *lp, int tlev)
1392 struct lchrstr *lcp = lchr + lp->lnd_type;
1393 int tech_diff = tlev - lcp->l_tech;
1395 if (CANT_HAPPEN(tech_diff < 0)) {
1400 lp->lnd_tech = tlev;
1401 lp->lnd_att = (float)LND_ATTDEF(lcp->l_att, tech_diff);
1402 lp->lnd_def = (float)LND_ATTDEF(lcp->l_def, tech_diff);
1403 lp->lnd_vul = (int)LND_VUL(lcp->l_vul, tech_diff);
1404 lp->lnd_spd = (int)LND_SPD(lcp->l_spd, tech_diff);
1405 lp->lnd_vis = (int)LND_VIS(lcp->l_vis, tech_diff);
1406 lp->lnd_spy = (int)LND_SPY(lcp->l_spy, tech_diff);
1407 lp->lnd_rad = (int)LND_RAD(lcp->l_rad, tech_diff);
1408 lp->lnd_frg = (int)LND_FRG(lcp->l_frg, tech_diff);
1409 lp->lnd_acc = (int)LND_ACC(lcp->l_acc, tech_diff);
1410 lp->lnd_dam = (int)LND_DAM(lcp->l_dam, tech_diff);
1411 lp->lnd_ammo = (int)LND_AMM(lcp->l_ammo, lcp->l_dam, tech_diff);
1412 lp->lnd_aaf = (int)LND_AAF(lcp->l_aaf, tech_diff);
1413 lp->lnd_fuelc = (int)LND_FC(lcp->l_fuelc, tech_diff);
1414 lp->lnd_fuelu = (int)LND_FU(lcp->l_fuelu, tech_diff);
1415 lp->lnd_maxlight = (int)LND_XPL(lcp->l_nxlight, tech_diff);
1416 lp->lnd_maxland = (int)LND_MXL(lcp->l_mxland, tech_diff);