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"
56 extern int etu_per_update;
59 attack_val(int combat_mode, struct lndstr *lp)
61 extern double assault_penalty;
66 if (((int)lp->lnd_effic) < LAND_MINEFF) {
67 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
69 putland(lp->lnd_uid, lp);
73 lcp = &lchr[(int)lp->lnd_type];
75 /* Spies always count as 1 during assaults. If they are the only ones
76 in the assault, they get to sneak on anyway. */
78 if (lcp->l_flags & L_SPY && combat_mode == A_ASSAULT)
83 value = ldround(((double)men * (double)lp->lnd_att), 1);
85 value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
87 switch (combat_mode) {
91 if (!(lcp->l_flags & L_MARINE))
92 return (int)(assault_penalty * value);
95 if (!(lcp->l_flags & L_MARINE))
96 return (int)(assault_penalty * men);
103 defense_val(struct lndstr *lp)
105 extern int land_mob_max;
110 if (((int)lp->lnd_effic) < LAND_MINEFF) {
111 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
113 putland(lp->lnd_uid, lp);
117 lcp = &lchr[(int)lp->lnd_type];
123 if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) &&
124 !(lcp->l_flags & L_MARINE))
127 value = men * lp->lnd_def;
130 ((double)land_mob_max + lp->lnd_harden) / (double)land_mob_max;
131 value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
132 value = (int)ldround(value, 1);
134 /* If there are military on the unit, you get at least a 1
135 man defensive unit, except for spies */
136 if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
143 total_mil(struct lndstr *lp)
148 lcp = &lchr[(int)lp->lnd_type];
150 men = lnd_getmil(lp);
151 /* men *= ((double)lp->lnd_effic)/100.0;*/
153 return ldround(men, 1);
157 lnd_print(struct llist *llp, s_char *s)
159 if (llp->land.lnd_own == player->cnum)
160 pr("%s %s\n", prland(&llp->land), s);
162 wu(0, llp->land.lnd_own, "%s %s\n", prland(&llp->land), s);
166 lnd_delete(struct llist *llp, s_char *s)
170 putland(llp->land.lnd_uid, &llp->land);
171 emp_remque((struct emp_qelem *)llp);
176 lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
177 /* attacking or assaulting or paratrooping? */
178 /* number of casualties to take */
191 int nowhere_to_go = 0;
199 taken = lnd_getmil(&(llp->land));
200 /* Spies always die */
201 if (llp->lcp->l_flags & L_SPY) {
203 llp->land.lnd_effic = 0;
206 ldround((((double)cas * 100.0) / (double)llp->lcp->l_mil), 1);
207 llp->land.lnd_effic -= eff_eq;
208 lnd_submil(&(llp->land), cas);
211 if (llp->land.lnd_effic < LAND_MINEFF) {
212 sprintf(buf, "dies %s %s!",
213 combat_mode ? att_mode[combat_mode] : (s_char *)
214 "defending", xyas(llp->land.lnd_x, llp->land.lnd_y,
216 lnd_delete(llp, buf);
217 /* Since we killed the unit, we killed all the mil on it */
220 /* Ok, now, how many did we take off? (sould be the diff) */
221 taken = taken - lnd_getmil(&(llp->land));
224 if (llp->land.lnd_effic >= llp->land.lnd_retreat)
227 /* we're being boarded */
228 if (llp->land.lnd_ship >= 0 && combat_mode == A_DEFEND)
231 /* we're being boarded */
232 if (llp->land.lnd_land >= 0 && combat_mode == A_DEFEND)
235 /* Have to make a retreat check */
237 ret_chance = llp->land.lnd_retreat - llp->land.lnd_effic;
238 if (roll(100) < ret_chance) {
240 lnd_print(llp, "fails morale check!");
241 llp->land.lnd_mission = 0;
242 llp->land.lnd_harden = 0;
243 if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0)
245 else if (combat_mode == A_DEFEND) {
247 * defending unit.. find a place to send it
248 * strategy: look for the most-populated
249 * adjacent sector that is owned by the unit
250 * player->owner. Charge mob..
254 for (n = 1; n <= 6; ++n) {
255 ret_x = llp->land.lnd_x + diroff[n][0];
256 ret_y = llp->land.lnd_y + diroff[n][1];
257 getsect(ret_x, ret_y, §);
258 if (sect.sct_own != llp->land.lnd_own)
260 if (sect.sct_type == SCT_MOUNT)
263 civs = getvar(V_CIVIL, (s_char *)§, EF_SECTOR);
264 if (civs > biggest) {
273 /* retreat to bx,by */
274 llp->land.lnd_x = bx;
275 llp->land.lnd_y = by;
276 getsect(bx, by, &rsect);
277 mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD);
278 mob = llp->land.lnd_mobil - (int)mobcost;
281 orig = llp->land.lnd_mobil;
282 llp->land.lnd_mobil = (s_char)mob;
283 if (llp->land.lnd_mobil > orig)
284 llp->land.lnd_mobil = (-127);
285 sprintf(buf, "retreats at %d%% efficiency to %s!",
287 xyas(bx, by, llp->land.lnd_own));
288 lnd_delete(llp, buf);
290 } else { /* attacking from a sector */
291 sprintf(buf, "leaves the battlefield at %d%% efficiency",
292 llp->land.lnd_effic);
293 if ((llp->land.lnd_mobil - (int)llp->mobil) < -127)
294 llp->land.lnd_mobil = -127;
296 llp->land.lnd_mobil -= (int)llp->mobil;
298 lnd_delete(llp, buf);
302 /* nowhere to go.. take more casualties */
303 llp->land.lnd_effic -= 10;
304 lnd_submil(&llp->land, llp->lcp->l_mil / 10);
305 if (llp->land.lnd_effic < LAND_MINEFF)
306 lnd_delete(llp, "has nowhere to retreat, and dies!");
309 "has nowhere to retreat and takes extra losses!");
316 lnd_takemob(struct emp_qelem *list, double loss)
318 extern double combat_mob;
319 struct emp_qelem *qp, *next;
322 int mcost = ldround(combat_mob * loss, 1);
324 for (qp = list->q_forw; qp != list; qp = next) {
326 llp = (struct llist *)qp;
329 use_supply(&llp->land);
330 if (llp->land.lnd_mission == MI_RESERVE)
331 new = llp->land.lnd_mobil - mcost/2;
334 new = llp->land.lnd_mobil - mcost;
337 llp->land.lnd_mobil = (s_char)new;
341 lnd_getmil(struct lndstr *lp)
345 getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
350 lnd_submil(struct lndstr *lp, int num)
354 getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
356 if (vec[I_MILIT] < 0)
358 putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
362 lnd_spyval(struct lndstr *lp)
364 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
365 return (lp->lnd_spy * (lp->lnd_effic / 100.0)) + 2;
367 return (lp->lnd_spy * (lp->lnd_effic / 100.0));
371 intelligence_report(int destination, struct lndstr *lp, int spy,
375 s_char buf1[80], buf2[80], buf3[80];
376 double estimate = 0.0; /* estimated defense value */
378 if (destination == 0)
381 if (lp->lnd_own == 0)
384 lcp = &lchr[(int)lp->lnd_type];
389 if (chance((double)(spy + lp->lnd_vis) / 10.0)) {
390 if (destination == player->cnum)
391 pr("%s %s", mess, prland(lp));
393 sprintf(buf1, "%s %s", mess, prland(lp));
395 estimate = lnd_getmil(lp);
397 if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
399 if (destination == player->cnum)
400 pr(" (eff %d, mil %d", roundintby(lp->lnd_effic, 5),
401 roundintby(lnd_getmil(lp), 10));
403 sprintf(buf2, " (eff %d, mil %d",
404 roundintby(lp->lnd_effic, 5),
405 roundintby(lnd_getmil(lp), 10));
406 estimate = lnd_getmil(lp) * lp->lnd_effic / 100.0;
408 if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
410 t = lp->lnd_tech - 20 + roll(40);
412 if (destination == player->cnum)
413 pr(", tech %d)\n", t);
415 sprintf(buf3, ", tech %d)\n", t);
417 if (destination == player->cnum)
420 sprintf(buf3, ")\n");
423 if (destination == player->cnum)
430 if (destination != player->cnum) {
431 wu(0, destination, "%s%s%s", buf1, buf2, buf3);
434 if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
435 estimate *= lp->lnd_def;
437 return (int)estimate;
440 /* Used by the spy command to count land units in a sector. If used
441 for anything else, you may want to reconsider, because this doesn't
442 always count spies. :) */
444 count_sect_units(struct sctstr *sp)
451 snxtitem_all(&ni, EF_LAND);
452 while (nxtitem(&ni, (s_char *)&land)) {
455 if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y)
457 /* Don't always see spies */
458 if (lchr[(int)land.lnd_type].l_flags & L_SPY) {
459 odds = (double)(100 - land.lnd_effic) + 0.10;
463 /* Got here, report it */
471 count_units(struct shpstr *sp)
477 if (sp->shp_effic < SHIP_MINEFF)
480 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
481 while (nxtitem(&ni, (s_char *)&land)) {
482 if (land.lnd_own == 0)
484 if (land.lnd_ship == sp->shp_uid)
488 if (sp->shp_nland != nland) {
489 sp->shp_nland = nland;
490 putship(sp->shp_uid, sp);
495 lnd_count_units(struct lndstr *lp)
501 if (lp->lnd_effic < LAND_MINEFF)
504 snxtitem_xy(&ni, EF_LAND, lp->lnd_x, lp->lnd_y);
505 while (nxtitem(&ni, (s_char *)&land)) {
506 if (land.lnd_own == 0)
508 if (land.lnd_land == lp->lnd_uid)
512 if (lp->lnd_nland != nland) {
513 lp->lnd_nland = nland;
514 putland(lp->lnd_uid, lp);
519 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
531 while (nxtitem(ni, (s_char *)&land)) {
535 if (ontradingblock(EF_LAND, (int *)&land)) {
536 pr("unit #%d inelligible - it's for sale.\n",
541 lcp = &lchr[(int)land.lnd_type];
542 /* if (wantflags && (lcp->m_flags & wantflags) != wantflags)
544 if (nowantflags && lcp->m_flags & nowantflags)
547 /* This abuse is better fixed by building a unit with the normal negative
548 mobility that everything else is built with */
549 /* Just so that the player can't build a bunch of land units, and them
550 march them a few minutes later... */
552 if (opt_MOB_ACCESS) {
553 if (land.lnd_effic < 11 &&
554 land.lnd_mobil < etu_per_update) {
555 pr("Land unit #%d needs at least %d mob to march.\n",
556 land.lnd_uid, etu_per_update);
561 land.lnd_mission = 0;
564 bzero(land.lnd_rpath, RET_LEN);
565 putland(land.lnd_uid, &land);
566 llp = (struct llist *)malloc(sizeof(struct llist));
568 bcopy((s_char *)&land, (s_char *)&llp->land,
569 sizeof(struct lndstr));
570 llp->mobil = (double)land.lnd_mobil;
571 emp_insque(&llp->queue, list);
575 /* This function assumes that the list was created by lnd_sel */
577 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
578 int *togetherp, natid actor)
580 struct emp_qelem *qp;
581 struct emp_qelem *next;
594 for (qp = list->q_back; qp != list; qp = next) {
596 llp = (struct llist *)qp;
597 getland(llp->land.lnd_uid, &land);
598 if (land.lnd_own != actor) {
599 mpr(actor, "%s was disbanded at %s\n",
600 prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
601 emp_remque((struct emp_qelem *)llp);
605 if (land.lnd_ship >= 0) {
606 lnd_mess("is on a ship", llp);
609 if (land.lnd_land >= 0) {
610 lnd_mess("is on a unit", llp);
613 if (!getsect(land.lnd_x, land.lnd_y, §)) {
614 lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
617 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
618 !(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) &&
619 lnd_getmil(&llp->land) == 0) {
620 lnd_mess("has no mil on it to guide it", llp);
623 rel = getrel(getnatp(sect.sct_own), player->cnum);
624 if (sect.sct_own != land.lnd_own && rel != ALLIED &&
625 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
627 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
636 if (land.lnd_x != allx || land.lnd_y != ally)
638 if (land.lnd_mobil + 1 < (int)llp->mobil) {
639 llp->mobil = (double)land.lnd_mobil;
641 if (llp->mobil < *minmobp)
642 *minmobp = llp->mobil;
643 if (llp->mobil > *maxmobp)
644 *maxmobp = llp->mobil;
645 bcopy((s_char *)&land, (s_char *)&llp->land,
646 sizeof(struct lndstr));
651 lnd_put(struct emp_qelem *list, natid actor)
653 register struct emp_qelem *qp;
654 register struct emp_qelem *newqp;
659 llp = (struct llist *)qp;
661 mpr(actor, "%s stopped at %s\n", prland(&llp->land),
662 xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
663 if (llp->mobil < -127)
665 llp->land.lnd_mobil = llp->mobil;
667 putland(llp->land.lnd_uid, &llp->land);
676 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
679 struct emp_qelem *qp;
680 struct emp_qelem *next;
683 int mines, m, max, sshells, lshells;
686 for (qp = land_list->q_back; qp != land_list; qp = next) {
688 llp = (struct llist *)qp;
689 if (!(llp->lcp->l_flags & L_ENGINEER)) {
691 mpr(actor, "%s is not an engineer!\n", prland(&llp->land));
694 if (takemob && llp->mobil < 0.0) {
696 lnd_mess("is out of mobility", llp);
699 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
700 if (sect.sct_oldown == llp->land.lnd_own) {
703 "%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
707 if (sect.sct_type == SCT_BSPAN) {
709 mpr(actor, "%s is on a bridge. No mines there!\n",
714 /* mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/
715 mobcost = llp->land.lnd_spd;
716 mobcost = 480.0 / (mobcost +
717 techfact(llp->land.lnd_tech, mobcost));
718 llp->mobil -= mobcost;
719 llp->land.lnd_mobil = (int)llp->mobil;
721 putland(llp->land.lnd_uid, &llp->land);
722 if (!(mines = getvar(V_MINE, (s_char *)§, EF_SECTOR)))
724 max = vl_find(V_SHELL, llp->lcp->l_vtype,
725 llp->lcp->l_vamt, (int)llp->lcp->l_nv);
726 lshells = getvar(V_SHELL, (s_char *)&llp->land, EF_LAND);
727 sshells = getvar(V_SHELL, (s_char *)§, EF_SECTOR);
728 for (m = 0; mines > 0 && m < max * 2; m++) {
729 if (chance(0.5 * llp->lcp->l_att)) {
730 mpr(actor, "Sweep...\n");
738 putvar(V_MINE, mines, (s_char *)§, EF_SECTOR);
739 putvar(V_SHELL, lshells, (s_char *)&llp->land, EF_LAND);
740 putvar(V_SHELL, sshells, (s_char *)§, EF_SECTOR);
741 putland(llp->land.lnd_uid, &llp->land);
747 contains_engineer(struct emp_qelem *list)
749 struct emp_qelem *qp;
750 struct emp_qelem *next;
753 for (qp = list->q_back; qp != list; qp = next) {
755 llp = (struct llist *)qp;
756 if (llp->lcp->l_flags & L_ENGINEER)
763 lnd_check_mines(struct emp_qelem *land_list)
765 struct emp_qelem *qp;
766 struct emp_qelem *next;
771 int has_engineers = contains_engineer(land_list);
773 for (qp = land_list->q_back; qp != land_list; qp = next) {
775 llp = (struct llist *)qp;
776 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
777 if (sect.sct_oldown == llp->land.lnd_own)
779 if (sect.sct_type == SCT_BSPAN)
781 if (!(mines = getvar(V_MINE, (s_char *)§, EF_SECTOR)))
783 if (chance(DMINE_LHITCHANCE(mines) / (1 + 2 * has_engineers))) {
784 lnd_hit_mine(&llp->land, llp->lcp);
786 putvar(V_MINE, mines, (s_char *)§, EF_SECTOR);
788 putland(llp->land.lnd_uid, (s_char *)&llp->land);
789 if (!llp->land.lnd_own) {
800 lnd_list(struct emp_qelem *land_list)
802 struct emp_qelem *qp;
803 struct emp_qelem *next;
808 pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
810 for (qp = land_list->q_back; qp != land_list; qp = next) {
812 llp = (struct llist *)qp;
814 pr("%4d ", lnd->lnd_uid);
815 pr("%-16.16s ", llp->lcp->l_name);
816 prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
817 pr("%1c", lnd->lnd_army);
818 pr("%4d%%", lnd->lnd_effic);
819 getvec(VT_ITEM, vec, (s_char *)lnd, EF_LAND);
820 pr("%4d", vec[I_SHELL]);
821 pr("%4d", vec[I_GUN]);
822 count_land_planes(lnd);
823 pr("%3d", lnd->lnd_nxlight);
824 pr("%4d", lnd->lnd_mobil);
825 pr("%4d", lnd->lnd_tech);
826 pr("%4d%%", lnd->lnd_retreat);
827 pr("%5d\n", lnd->lnd_fuel);
832 lnd_mess(s_char *str, struct llist *llp)
834 mpr(llp->land.lnd_own, "%s %s & stays in %s\n",
836 str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
837 if (llp->mobil < -127)
839 llp->land.lnd_mobil = llp->mobil;
840 putland(llp->land.lnd_uid, &llp->land);
841 emp_remque((struct emp_qelem *)llp);
846 lnd_count(struct emp_qelem *list)
848 struct emp_qelem *qp;
849 struct emp_qelem *next;
853 for (qp = list->q_back; qp != list; qp = next) {
855 llp = (struct llist *)qp;
862 lnd_damage(struct emp_qelem *list, int totdam)
864 struct emp_qelem *qp;
865 struct emp_qelem *next;
870 if (!totdam || !(count = lnd_count(list)))
872 dam = ldround(((double)totdam / (double)count), 1);
873 for (qp = list->q_back; qp != list; qp = next) {
875 llp = (struct llist *)qp;
876 /* have to get it again because of collateral damage */
877 getland(llp->land.lnd_uid, &llp->land);
878 landdamage(&llp->land, dam);
879 putland(llp->land.lnd_uid, &llp->land);
880 if (!llp->land.lnd_own) {
889 lnd_easiest_target(struct emp_qelem *list)
891 struct emp_qelem *qp;
892 struct emp_qelem *next;
895 int easiest = 9876; /* things start great for victim */
898 for (qp = list->q_back; qp != list; qp = next) {
900 llp = (struct llist *)qp;
901 hard = lnd_hardtarget(&llp->land);
903 easiest = hard; /* things get worse for victim */
906 return easiest - count;
910 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
914 struct emp_qelem msl_list, *qp, *newqp;
916 msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
918 dam = msl_launch_mindam(&msl_list, newx, newy,
919 lnd_easiest_target(list), EF_LAND,
920 lnd_count(list) * 20, "troops", victim,
923 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
924 collateral_damage(newx, newy, dam, 0);
926 qp = msl_list.q_forw;
927 while (qp != msl_list.q_forw) {
937 /* Steve M. - commented out for now until abuse is decided upon */
938 /* risner: allow forts to interdict land units. */
940 lnd_fort_interdiction(struct emp_qelem *list,
941 coord newx, coord newy, natid victim)
943 extern int fort_max_interdiction_range;
947 double range, range2, guneff;
953 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
954 while (nxtsct(&ns, &fsect)) {
955 if (fsect.sct_own == 0)
957 if (fsect.sct_own == victim)
959 if (fsect.sct_type != SCT_FORTR)
961 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
963 gun = getvar(V_GUN, (s_char *)&fsect, EF_SECTOR);
966 range = tfactfire(fsect.sct_own, (double)min(gun, 7));
967 if (fsect.sct_effic > 59)
969 range2 = roundrange(range);
970 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
973 if (getvar(V_MILIT, (s_char *)&fsect, EF_SECTOR) < 5)
975 shell = getvar(V_SHELL, (s_char *)&fsect, EF_SECTOR);
977 shell += supply_commod(fsect.sct_own,
978 fsect.sct_x, fsect.sct_y, I_SHELL, 1);
982 putvar(V_SHELL, shell, (s_char *)&fsect, EF_SECTOR);
986 guneff = landgun((int)fsect.sct_effic, gun);
989 mpr(victim, "Incoming fire does %d damage!\n", dam);
991 "%s fires at %s land units in %s for %d!\n",
992 xyas(fsect.sct_x, fsect.sct_y,
994 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
995 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
998 return lnd_damage(list, totdam);
1004 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
1009 if (!opt_NO_FORT_FIRE)
1010 /* Steve M. - commented out for now until abuse is decided upon */
1011 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
1016 unit_interdict(newx, newy, victim, "land units",
1017 lnd_easiest_target(list), MI_INTERDICT));
1021 lnd_missile_interdiction(list, newx, newy, victim));
1025 /* high value of hardtarget is harder to hit */
1027 lnd_hardtarget(struct lndstr *lp)
1031 getsect(lp->lnd_x, lp->lnd_y, §);
1032 return (int)(((double)lp->lnd_effic / 100.0) *
1033 (10 + dchr[sect.sct_type].d_dstr * 2 +
1034 (double)lp->lnd_spd / 2.0 - lp->lnd_vis));
1038 lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
1042 mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
1043 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1045 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
1048 if (lcp->l_flags & L_ENGINEER)
1051 landdamage(lp, ldround(m, 1));
1057 lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
1062 /* supply unit's speed depends on their eff, since
1063 that is their purpose */
1064 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
1065 mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd;
1067 mobcost = lp->lnd_spd;
1071 /* sector_mcost now takes 2 different arguments, a sector pointer, and
1072 whether or not to figure in the highway bonus, rail bonus or none.
1073 bridge heads, bridges and highways have built-in highways bonus
1074 because they are a 1, and this will discount that. */
1076 smobcost = (double)sector_mcost(sp, mobtype);
1077 if (smobcost < 0.01)
1080 /* marching through 0 mobility conquered sectors takes lots of mobility,
1081 unless you are a train. Capturing railways is a good thing. */
1083 if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 &&
1084 smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL)
1085 smobcost = LND_MINMOBCOST;
1087 mobcost = smobcost * 5.0 * 480.0 /
1088 (mobcost + techfact(lp->lnd_tech, mobcost));
1094 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
1097 struct sctstr sect, osect;
1098 struct emp_qelem *qp;
1099 struct emp_qelem *qp2;
1100 struct emp_qelem *next;
1114 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
1115 lnd_put(list, actor);
1118 dx = diroff[dir][0];
1119 dy = diroff[dir][1];
1120 for (qp = list->q_back; qp != list; qp = next) {
1122 llp = (struct llist *)qp;
1123 getsect(llp->land.lnd_x, llp->land.lnd_y, &osect);
1124 oldown = osect.sct_own;
1125 newx = xnorm(llp->land.lnd_x + dx);
1126 newy = ynorm(llp->land.lnd_y + dy);
1127 getsect(newx, newy, §);
1128 rel = getrel(getnatp(sect.sct_own), player->cnum);
1129 if ((sect.sct_own != actor && rel != ALLIED &&
1130 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
1131 sect.sct_own) || (sect.sct_type == SCT_WATER ||
1132 sect.sct_type == SCT_SANCT ||
1133 sect.sct_type == SCT_WASTE)) {
1135 pr("can't go to %s\n", xyas(newx, newy, actor));
1138 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
1144 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY))
1146 if (sect.sct_rail == 0 &&
1147 lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1149 pr("no rail system in %s\n", xyas(newx, newy, actor));
1152 sprintf(dp, "has no rail system in %s",
1153 xyas(newx, newy, actor));
1158 /* Note we check would_abandon first because we don't want
1159 to always have to do these checks */
1160 if (would_abandon(&osect, V_CIVIL, 0, &(llp->land))) {
1162 if (!want_to_abandon(&osect, V_CIVIL, 0, &(llp->land))) {
1165 /* now check stuff */
1166 if (!check_sect_ok(§))
1168 if (!check_sect_ok(&osect))
1170 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
1171 if (!check_land_ok(&(((struct llist *)qp2)->land)))
1175 lnd_mess("stops", llp);
1179 if (llp->mobil <= 0.0) {
1180 lnd_mess("is out of mobility", llp);
1183 llp->land.lnd_x = newx;
1184 llp->land.lnd_y = newy;
1185 if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1186 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL);
1188 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_ROAD);
1190 llp->land.lnd_mobil = (int)llp->mobil;
1191 putland(llp->land.lnd_uid, &llp->land);
1193 getsect(osect.sct_x, osect.sct_y, &osect);
1194 if (osect.sct_own != oldown && oldown == player->cnum) {
1195 /* It was your sector, now it's not. Simple :) */
1196 pr("You no longer own %s\n",
1197 xyas(osect.sct_x, osect.sct_y, player->cnum));
1199 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
1200 /* Always a 10% chance of getting caught. */
1201 odds = (100 - llp->land.lnd_effic) + .10;
1203 if (rel == NEUTRAL || rel == FRIENDLY) {
1205 "%s unit spotted in %s\n", cname(player->cnum),
1206 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1207 setrel(sect.sct_own, llp->land.lnd_own, HOSTILE);
1208 } else if (rel == HOSTILE || rel == AT_WAR ||
1209 rel == SITZKRIEG || rel == MOBILIZATION) {
1211 "%s spy shot in %s\n", cname(player->cnum),
1212 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1213 pr("%s was shot and killed.\n", prland(&llp->land));
1214 llp->land.lnd_effic = 0;
1215 putland(llp->land.lnd_uid, &llp->land);
1223 lnd_sweep(list, 0, 1, actor);
1224 stopping |= lnd_check_mines(list);
1228 stopping |= lnd_interdict(list, newx, newy, actor);
1233 * find all artillery units belonging
1234 * to the attacker or defender that can fire.
1235 * Each arty unit adds +1%/damage point
1239 lnd_support(natid victim, natid attacker, coord x, coord y)
1241 struct nstr_item ni;
1248 double range, range2;
1250 snxtitem_all(&ni, EF_LAND);
1251 while (nxtitem(&ni, (s_char *)&land)) {
1252 if (land.lnd_frg == 0)
1254 if ((land.lnd_x == x) && (land.lnd_y == y))
1256 if (land.lnd_ship >= 0)
1258 if (land.lnd_land >= 0)
1260 if (land.lnd_mission > 0)
1262 if (land.lnd_effic < LAND_MINFIREEFF)
1264 /* Do we have mil? */
1265 if (getvar(V_MILIT, (s_char *)&land, EF_LAND) <= 0)
1267 rel = getrel(getnatp(land.lnd_own), attacker);
1268 rel2 = getrel(getnatp(land.lnd_own), victim);
1269 if ((land.lnd_own != attacker) &&
1270 ((rel != ALLIED) || (rel2 != AT_WAR)))
1273 /* do we have supplies? */
1274 if (!has_supply(&land))
1277 /* are we in range? */
1278 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1280 range = techfact((int)land.lnd_tech, (double)land.lnd_frg / 2.0);
1282 range2 = roundrange(range);
1286 shell = getvar(V_SHELL, (s_char *)&land, EF_LAND);
1287 gun = getvar(V_GUN, (s_char *)&land, EF_LAND);
1289 if (shell == 0 || gun == 0)
1293 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1294 if (roll(100) < land.lnd_acc) {
1295 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1296 land.lnd_ammo, shell) / 2;
1298 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1299 land.lnd_ammo, shell);
1301 if (land.lnd_own != attacker)
1303 "%s supported %s at %s\n",
1304 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1310 lnd_path(int together, struct lndstr *lp, s_char *buf)
1314 struct sctstr d_sect, sect;
1318 if (!sarg_xy(buf, &destx, &desty))
1321 pr("Cannot go to a destination sector if not all starting in the same sector\n");
1324 if (!getsect(destx, desty, &d_sect)) {
1325 pr("%d,%d is not a sector\n", destx, desty);
1328 getsect(lp->lnd_x, lp->lnd_y, §);
1329 if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
1330 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_RAIL);
1332 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_ROAD);
1334 pr("No owned path from %s to %s!\n",
1335 xyas(lp->lnd_x, lp->lnd_y, player->cnum),
1336 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1339 pr("Using path '%s'\n", cp);
1344 lnd_can_attack(struct lndstr *lp)
1346 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1348 /* if (lcp->l_flags & L_SUPPLY ||
1349 lcp->l_flags & L_SECURITY ||
1350 lcp->l_flags & L_FLAK ||
1353 if (lcp->l_flags & L_SUPPLY)