2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 = vl_find(V_SHELL, llp->lcp->l_vtype,
709 llp->lcp->l_vamt, (int)llp->lcp->l_nv);
710 lshells = llp->land.lnd_item[I_SHELL];
711 sshells = sect.sct_item[I_SHELL];
712 for (m = 0; mines > 0 && m < max * 2; m++) {
713 if (chance(0.5 * llp->lcp->l_att)) {
714 mpr(actor, "Sweep...\n");
718 else if (sshells < ITEM_MAX)
722 sect.sct_mines = mines;
723 llp->land.lnd_item[I_SHELL] = lshells;
724 sect.sct_item[I_SHELL] = sshells;
725 putland(llp->land.lnd_uid, &llp->land);
731 contains_engineer(struct emp_qelem *list)
733 struct emp_qelem *qp;
734 struct emp_qelem *next;
737 for (qp = list->q_back; qp != list; qp = next) {
739 llp = (struct llist *)qp;
740 if (llp->lcp->l_flags & L_ENGINEER)
747 lnd_check_mines(struct emp_qelem *land_list)
749 struct emp_qelem *qp;
750 struct emp_qelem *next;
754 int with_eng = contains_engineer(land_list);
756 for (qp = land_list->q_back; qp != land_list; qp = next) {
758 llp = (struct llist *)qp;
759 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
760 if (sect.sct_oldown == llp->land.lnd_own)
762 if (sect.sct_type == SCT_BSPAN)
766 if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
767 lnd_hit_mine(&llp->land, llp->lcp);
770 putland(llp->land.lnd_uid, (s_char *)&llp->land);
771 if (!llp->land.lnd_own) {
782 lnd_list(struct emp_qelem *land_list)
784 struct emp_qelem *qp;
785 struct emp_qelem *next;
789 pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
791 for (qp = land_list->q_back; qp != land_list; qp = next) {
793 llp = (struct llist *)qp;
795 pr("%4d ", lnd->lnd_uid);
796 pr("%-16.16s ", llp->lcp->l_name);
797 prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
798 pr("%1c", lnd->lnd_army);
799 pr("%4d%%", lnd->lnd_effic);
800 pr("%4d", lnd->lnd_item[I_SHELL]);
801 pr("%4d", lnd->lnd_item[I_GUN]);
802 count_land_planes(lnd);
803 pr("%3d", lnd->lnd_nxlight);
804 pr("%4d", lnd->lnd_mobil);
805 pr("%4d", lnd->lnd_tech);
806 pr("%4d%%", lnd->lnd_retreat);
807 pr("%5d\n", lnd->lnd_fuel);
812 lnd_mess(s_char *str, struct llist *llp)
814 mpr(llp->land.lnd_own, "%s %s & stays in %s\n",
816 str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
817 if (llp->mobil < -127)
819 llp->land.lnd_mobil = llp->mobil;
820 putland(llp->land.lnd_uid, &llp->land);
821 emp_remque((struct emp_qelem *)llp);
826 lnd_count(struct emp_qelem *list)
828 struct emp_qelem *qp;
829 struct emp_qelem *next;
833 for (qp = list->q_back; qp != list; qp = next) {
835 llp = (struct llist *)qp;
842 lnd_damage(struct emp_qelem *list, int totdam)
844 struct emp_qelem *qp;
845 struct emp_qelem *next;
850 if (!totdam || !(count = lnd_count(list)))
852 dam = ldround(((double)totdam / (double)count), 1);
853 for (qp = list->q_back; qp != list; qp = next) {
855 llp = (struct llist *)qp;
856 /* have to get it again because of collateral damage */
857 getland(llp->land.lnd_uid, &llp->land);
858 landdamage(&llp->land, dam);
859 putland(llp->land.lnd_uid, &llp->land);
860 if (!llp->land.lnd_own) {
869 lnd_easiest_target(struct emp_qelem *list)
871 struct emp_qelem *qp;
872 struct emp_qelem *next;
875 int easiest = 9876; /* things start great for victim */
878 for (qp = list->q_back; qp != list; qp = next) {
880 llp = (struct llist *)qp;
881 hard = lnd_hardtarget(&llp->land);
883 easiest = hard; /* things get worse for victim */
886 return easiest - count;
890 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
894 struct emp_qelem msl_list, *qp, *newqp;
896 msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
898 dam = msl_launch_mindam(&msl_list, newx, newy,
899 lnd_easiest_target(list), EF_LAND,
900 lnd_count(list) * 20, "troops", victim,
903 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
904 collateral_damage(newx, newy, dam, 0);
906 qp = msl_list.q_forw;
907 while (qp != msl_list.q_forw) {
917 /* Steve M. - commented out for now until abuse is decided upon */
918 /* risner: allow forts to interdict land units. */
920 lnd_fort_interdiction(struct emp_qelem *list,
921 coord newx, coord newy, natid victim)
926 double range, range2, guneff;
932 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
933 while (nxtsct(&ns, &fsect)) {
934 if (fsect.sct_own == 0)
936 if (fsect.sct_own == victim)
938 if (fsect.sct_type != SCT_FORTR)
940 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
942 gun = fsect.sct_item[I_GUN];
945 range = tfactfire(fsect.sct_own, (double)min(gun, 7));
946 if (fsect.sct_effic > 59)
948 range2 = roundrange(range);
949 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
952 if (fsect.sct_item[I_MILIT] < 5)
954 shell = fsect.sct_item[I_SHELL];
956 shell += supply_commod(fsect.sct_own,
957 fsect.sct_x, fsect.sct_y, I_SHELL, 1);
961 fsect.sct_item[I_SHELL] = shell;
965 guneff = landgun((int)fsect.sct_effic, gun);
968 mpr(victim, "Incoming fire does %d damage!\n", dam);
970 "%s fires at %s land units in %s for %d!\n",
971 xyas(fsect.sct_x, fsect.sct_y,
973 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
974 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
977 return lnd_damage(list, totdam);
983 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
988 if (!opt_NO_FORT_FIRE)
989 /* Steve M. - commented out for now until abuse is decided upon */
990 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
995 unit_interdict(newx, newy, victim, "land units",
996 lnd_easiest_target(list), MI_INTERDICT));
1000 lnd_missile_interdiction(list, newx, newy, victim));
1004 /* high value of hardtarget is harder to hit */
1006 lnd_hardtarget(struct lndstr *lp)
1010 getsect(lp->lnd_x, lp->lnd_y, §);
1011 return (int)(((double)lp->lnd_effic / 100.0) *
1012 (10 + dchr[sect.sct_type].d_dstr * 2 +
1013 (double)lp->lnd_spd / 2.0 - lp->lnd_vis));
1017 lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
1021 mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
1022 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1024 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
1027 if (lcp->l_flags & L_ENGINEER)
1030 landdamage(lp, ldround(m, 1));
1036 lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
1041 /* supply unit's speed depends on their eff, since
1042 that is their purpose */
1043 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
1044 mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd;
1046 mobcost = lp->lnd_spd;
1050 /* sector_mcost now takes 2 different arguments, a sector pointer, and
1051 whether or not to figure in the highway bonus, rail bonus or none.
1052 bridge heads, bridges and highways have built-in highways bonus
1053 because they are a 1, and this will discount that. */
1055 smobcost = (double)sector_mcost(sp, mobtype);
1056 if (smobcost < 0.01)
1059 /* marching through 0 mobility conquered sectors takes lots of mobility,
1060 unless you are a train. Capturing railways is a good thing. */
1062 if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 &&
1063 smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL)
1064 smobcost = LND_MINMOBCOST;
1066 mobcost = smobcost * 5.0 * 480.0 /
1067 (mobcost + techfact(lp->lnd_tech, mobcost));
1073 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
1076 struct sctstr sect, osect;
1077 struct emp_qelem *qp;
1078 struct emp_qelem *qp2;
1079 struct emp_qelem *next;
1092 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
1093 lnd_put(list, actor);
1096 dx = diroff[dir][0];
1097 dy = diroff[dir][1];
1098 for (qp = list->q_back; qp != list; qp = next) {
1100 llp = (struct llist *)qp;
1101 getsect(llp->land.lnd_x, llp->land.lnd_y, &osect);
1102 oldown = osect.sct_own;
1103 newx = xnorm(llp->land.lnd_x + dx);
1104 newy = ynorm(llp->land.lnd_y + dy);
1105 getsect(newx, newy, §);
1106 rel = getrel(getnatp(sect.sct_own), player->cnum);
1107 if ((sect.sct_own != actor && rel != ALLIED &&
1108 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
1109 sect.sct_own) || (sect.sct_type == SCT_WATER ||
1110 sect.sct_type == SCT_SANCT ||
1111 sect.sct_type == SCT_WASTE)) {
1113 pr("can't go to %s\n", xyas(newx, newy, actor));
1116 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
1122 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY))
1124 if (sect.sct_rail == 0 &&
1125 lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1127 pr("no rail system in %s\n", xyas(newx, newy, actor));
1130 sprintf(dp, "has no rail system in %s",
1131 xyas(newx, newy, actor));
1136 /* Note we check would_abandon first because we don't want
1137 to always have to do these checks */
1138 if (would_abandon(&osect, V_CIVIL, 0, &(llp->land))) {
1140 if (!want_to_abandon(&osect, V_CIVIL, 0, &(llp->land))) {
1143 /* now check stuff */
1144 if (!check_sect_ok(§))
1146 if (!check_sect_ok(&osect))
1148 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
1149 if (!check_land_ok(&(((struct llist *)qp2)->land)))
1153 lnd_mess("stops", llp);
1157 if (llp->mobil <= 0.0) {
1158 lnd_mess("is out of mobility", llp);
1161 llp->land.lnd_x = newx;
1162 llp->land.lnd_y = newy;
1163 if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1164 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL);
1166 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_ROAD);
1168 llp->land.lnd_mobil = (int)llp->mobil;
1169 llp->land.lnd_harden = 0;
1170 putland(llp->land.lnd_uid, &llp->land);
1172 getsect(osect.sct_x, osect.sct_y, &osect);
1173 if (osect.sct_own != oldown && oldown == player->cnum) {
1174 /* It was your sector, now it's not. Simple :) */
1175 pr("You no longer own %s\n",
1176 xyas(osect.sct_x, osect.sct_y, player->cnum));
1178 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
1179 /* Always a 10% chance of getting caught. */
1180 if (chance(LND_SPY_DETECT_CHANCE(llp->land.lnd_effic))) {
1181 if (rel == NEUTRAL || rel == FRIENDLY) {
1183 "%s unit spotted in %s\n", cname(player->cnum),
1184 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1185 setrel(sect.sct_own, llp->land.lnd_own, HOSTILE);
1186 } else if (rel == HOSTILE || rel == AT_WAR ||
1187 rel == SITZKRIEG || rel == MOBILIZATION) {
1189 "%s spy shot in %s\n", cname(player->cnum),
1190 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1191 pr("%s was shot and killed.\n", prland(&llp->land));
1192 llp->land.lnd_effic = 0;
1193 putland(llp->land.lnd_uid, &llp->land);
1201 lnd_sweep(list, 0, 1, actor);
1202 stopping |= lnd_check_mines(list);
1206 stopping |= lnd_interdict(list, newx, newy, actor);
1211 * find all artillery units belonging
1212 * to the attacker or defender that can fire.
1213 * Each arty unit adds +1%/damage point
1217 lnd_support(natid victim, natid attacker, coord x, coord y)
1219 struct nstr_item ni;
1226 double range, range2;
1228 snxtitem_all(&ni, EF_LAND);
1229 while (nxtitem(&ni, (s_char *)&land)) {
1230 if (land.lnd_frg == 0)
1232 if ((land.lnd_x == x) && (land.lnd_y == y))
1234 if (land.lnd_ship >= 0)
1236 if (land.lnd_land >= 0)
1238 if (land.lnd_mission > 0)
1240 if (land.lnd_effic < LAND_MINFIREEFF)
1242 /* Do we have mil? */
1243 if (land.lnd_item[I_MILIT] <= 0)
1245 rel = getrel(getnatp(land.lnd_own), attacker);
1246 rel2 = getrel(getnatp(land.lnd_own), victim);
1247 if ((land.lnd_own != attacker) &&
1248 ((rel != ALLIED) || (rel2 != AT_WAR)))
1251 /* do we have supplies? */
1252 if (!has_supply(&land))
1255 /* are we in range? */
1256 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1258 range = techfact((int)land.lnd_tech, (double)land.lnd_frg / 2.0);
1260 range2 = roundrange(range);
1264 shell = land.lnd_item[I_SHELL];
1265 gun = land.lnd_item[I_GUN];
1267 if (shell == 0 || gun == 0)
1271 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1272 if (roll(100) < land.lnd_acc) {
1273 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1274 land.lnd_ammo, shell) / 2;
1276 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1277 land.lnd_ammo, shell);
1279 if (land.lnd_own != attacker)
1281 "%s supported %s at %s\n",
1282 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1288 lnd_path(int together, struct lndstr *lp, s_char *buf)
1292 struct sctstr d_sect, sect;
1296 if (!sarg_xy(buf, &destx, &desty))
1299 pr("Cannot go to a destination sector if not all starting in the same sector\n");
1302 if (!getsect(destx, desty, &d_sect)) {
1303 pr("%d,%d is not a sector\n", destx, desty);
1306 getsect(lp->lnd_x, lp->lnd_y, §);
1307 if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
1308 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_RAIL);
1310 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_ROAD);
1312 pr("No owned path from %s to %s!\n",
1313 xyas(lp->lnd_x, lp->lnd_y, player->cnum),
1314 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1317 pr("Using path '%s'\n", cp);
1322 lnd_can_attack(struct lndstr *lp)
1324 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1326 /* if (lcp->l_flags & L_SUPPLY ||
1327 lcp->l_flags & L_SECURITY ||
1328 lcp->l_flags & L_FLAK ||
1331 if (lcp->l_flags & L_SUPPLY)
1338 * Increase fortification value of LP.
1339 * Fortification costs mobility. Use up to HARD_AMT mobility.
1340 * Return actual fortification increase.
1343 lnd_fortify (struct lndstr *lp, int hard_amt)
1348 if ((lp->lnd_ship >= 0) || lp->lnd_land >= 0)
1351 hard_amt = min(lp->lnd_mobil, hard_amt);
1353 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1354 hard_amt = land_mob_max - lp->lnd_harden;
1356 eng = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own);
1359 hard_amt = ((float)hard_amt * 1.5);
1361 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1362 hard_amt = land_mob_max - lp->lnd_harden;
1364 /* Ok, set the mobility used */
1365 mob_used = hard_amt;
1367 /* Now, if an engineer helped, it's really only 2/3rds of
1370 mob_used = (int)((float)mob_used / 1.5);
1372 /* If we increased it, but not much, we gotta take at least 1
1374 if (mob_used <= 0 && hard_amt > 0)
1377 lp->lnd_mobil -= mob_used;
1378 if (lp->lnd_mobil < 0)
1381 lp->lnd_harden += hard_amt;
1382 lp->lnd_harden = min(lp->lnd_harden, land_mob_max);
1388 * Set LP's tech to TLEV along with everything else that depends on it.
1391 lnd_set_tech(struct lndstr *lp, int tlev)
1393 struct lchrstr *lcp = lchr + lp->lnd_type;
1394 int tech_diff = tlev - lcp->l_tech;
1396 if (CANT_HAPPEN(tech_diff < 0)) {
1401 lp->lnd_tech = tlev;
1402 lp->lnd_att = (float)LND_ATTDEF(lcp->l_att, tech_diff);
1403 lp->lnd_def = (float)LND_ATTDEF(lcp->l_def, tech_diff);
1404 lp->lnd_vul = (int)LND_VUL(lcp->l_vul, tech_diff);
1405 lp->lnd_spd = (int)LND_SPD(lcp->l_spd, tech_diff);
1406 lp->lnd_vis = (int)LND_VIS(lcp->l_vis, tech_diff);
1407 lp->lnd_spy = (int)LND_SPY(lcp->l_spy, tech_diff);
1408 lp->lnd_rad = (int)LND_RAD(lcp->l_rad, tech_diff);
1409 lp->lnd_frg = (int)LND_FRG(lcp->l_frg, tech_diff);
1410 lp->lnd_acc = (int)LND_ACC(lcp->l_acc, tech_diff);
1411 lp->lnd_dam = (int)LND_DAM(lcp->l_dam, tech_diff);
1412 lp->lnd_ammo = (int)LND_AMM(lcp->l_ammo, lcp->l_dam, tech_diff);
1413 lp->lnd_aaf = (int)LND_AAF(lcp->l_aaf, tech_diff);
1414 lp->lnd_fuelc = (int)LND_FC(lcp->l_fuelc, tech_diff);
1415 lp->lnd_fuelu = (int)LND_FU(lcp->l_fuelu, tech_diff);
1416 lp->lnd_maxlight = (int)LND_XPL(lcp->l_nxlight, tech_diff);
1417 lp->lnd_maxland = (int)LND_MXL(lcp->l_mxland, tech_diff);