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)
65 if (((int)lp->lnd_effic) < LAND_MINEFF) {
66 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
68 putland(lp->lnd_uid, lp);
72 lcp = &lchr[(int)lp->lnd_type];
74 /* Spies always count as 1 during assaults. If they are the only ones
75 in the assault, they get to sneak on anyway. */
77 if (lcp->l_flags & L_SPY && combat_mode == A_ASSAULT)
82 value = ldround(((double)men * (double)lp->lnd_att), 1);
84 value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
86 switch (combat_mode) {
90 if (!(lcp->l_flags & L_MARINE))
91 return (int)(assault_penalty * value);
94 if (!(lcp->l_flags & L_MARINE))
95 return (int)(assault_penalty * men);
102 defense_val(struct lndstr *lp)
108 if (((int)lp->lnd_effic) < LAND_MINEFF) {
109 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
111 putland(lp->lnd_uid, lp);
115 lcp = &lchr[(int)lp->lnd_type];
121 if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) &&
122 !(lcp->l_flags & L_MARINE))
125 value = men * lp->lnd_def;
128 ((double)land_mob_max + lp->lnd_harden) / (double)land_mob_max;
129 value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
130 value = (int)ldround(value, 1);
132 /* If there are military on the unit, you get at least a 1
133 man defensive unit, except for spies */
134 if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
141 total_mil(struct lndstr *lp)
146 lcp = &lchr[(int)lp->lnd_type];
148 men = lnd_getmil(lp);
149 /* men *= ((double)lp->lnd_effic)/100.0;*/
151 return ldround(men, 1);
155 lnd_print(struct llist *llp, s_char *s)
157 if (llp->land.lnd_own == player->cnum)
158 pr("%s %s\n", prland(&llp->land), s);
160 wu(0, llp->land.lnd_own, "%s %s\n", prland(&llp->land), s);
164 lnd_delete(struct llist *llp, s_char *s)
168 putland(llp->land.lnd_uid, &llp->land);
169 emp_remque((struct emp_qelem *)llp);
174 lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
175 /* attacking or assaulting or paratrooping? */
176 /* number of casualties to take */
189 int nowhere_to_go = 0;
197 taken = lnd_getmil(&(llp->land));
198 /* Spies always die */
199 if (llp->lcp->l_flags & L_SPY) {
201 llp->land.lnd_effic = 0;
204 ldround((((double)cas * 100.0) / (double)llp->lcp->l_mil), 1);
205 llp->land.lnd_effic -= eff_eq;
206 lnd_submil(&(llp->land), cas);
209 if (llp->land.lnd_effic < LAND_MINEFF) {
210 sprintf(buf, "dies %s %s!",
211 combat_mode ? att_mode[combat_mode] : (s_char *)
212 "defending", xyas(llp->land.lnd_x, llp->land.lnd_y,
214 lnd_delete(llp, buf);
215 /* Since we killed the unit, we killed all the mil on it */
218 /* Ok, now, how many did we take off? (sould be the diff) */
219 taken = taken - lnd_getmil(&(llp->land));
222 if (llp->land.lnd_effic >= llp->land.lnd_retreat)
225 /* we're being boarded */
226 if (llp->land.lnd_ship >= 0 && combat_mode == A_DEFEND)
229 /* we're being boarded */
230 if (llp->land.lnd_land >= 0 && combat_mode == A_DEFEND)
233 /* Have to make a retreat check */
235 ret_chance = llp->land.lnd_retreat - llp->land.lnd_effic;
236 if (roll(100) < ret_chance) {
238 lnd_print(llp, "fails morale check!");
239 llp->land.lnd_mission = 0;
240 llp->land.lnd_harden = 0;
241 if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0)
243 else if (combat_mode == A_DEFEND) {
245 * defending unit.. find a place to send it
246 * strategy: look for the most-populated
247 * adjacent sector that is owned by the unit
248 * player->owner. Charge mob..
252 for (n = 1; n <= 6; ++n) {
253 ret_x = llp->land.lnd_x + diroff[n][0];
254 ret_y = llp->land.lnd_y + diroff[n][1];
255 getsect(ret_x, ret_y, §);
256 if (sect.sct_own != llp->land.lnd_own)
258 if (sect.sct_type == SCT_MOUNT)
261 civs = getvar(V_CIVIL, (s_char *)§, EF_SECTOR);
262 if (civs > biggest) {
271 /* retreat to bx,by */
272 llp->land.lnd_x = bx;
273 llp->land.lnd_y = by;
274 getsect(bx, by, &rsect);
275 mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD);
276 mob = llp->land.lnd_mobil - (int)mobcost;
279 orig = llp->land.lnd_mobil;
280 llp->land.lnd_mobil = (s_char)mob;
281 if (llp->land.lnd_mobil > orig)
282 llp->land.lnd_mobil = (-127);
283 sprintf(buf, "retreats at %d%% efficiency to %s!",
285 xyas(bx, by, llp->land.lnd_own));
286 lnd_delete(llp, buf);
288 } else { /* attacking from a sector */
289 sprintf(buf, "leaves the battlefield at %d%% efficiency",
290 llp->land.lnd_effic);
291 if ((llp->land.lnd_mobil - (int)llp->mobil) < -127)
292 llp->land.lnd_mobil = -127;
294 llp->land.lnd_mobil -= (int)llp->mobil;
296 lnd_delete(llp, buf);
300 /* nowhere to go.. take more casualties */
301 llp->land.lnd_effic -= 10;
302 lnd_submil(&llp->land, llp->lcp->l_mil / 10);
303 if (llp->land.lnd_effic < LAND_MINEFF)
304 lnd_delete(llp, "has nowhere to retreat, and dies!");
307 "has nowhere to retreat and takes extra losses!");
314 lnd_takemob(struct emp_qelem *list, double loss)
316 struct emp_qelem *qp, *next;
319 int mcost = ldround(combat_mob * loss, 1);
321 for (qp = list->q_forw; qp != list; qp = next) {
323 llp = (struct llist *)qp;
326 use_supply(&llp->land);
327 if (llp->land.lnd_mission == MI_RESERVE)
328 new = llp->land.lnd_mobil - mcost/2;
331 new = llp->land.lnd_mobil - mcost;
334 llp->land.lnd_mobil = (s_char)new;
338 lnd_getmil(struct lndstr *lp)
342 getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
347 lnd_submil(struct lndstr *lp, int num)
351 getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
353 if (vec[I_MILIT] < 0)
355 putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
359 lnd_spyval(struct lndstr *lp)
361 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
362 return (lp->lnd_spy * (lp->lnd_effic / 100.0)) + 2;
364 return (lp->lnd_spy * (lp->lnd_effic / 100.0));
368 intelligence_report(int destination, struct lndstr *lp, int spy,
372 s_char buf1[80], buf2[80], buf3[80];
373 double estimate = 0.0; /* estimated defense value */
375 if (destination == 0)
378 if (lp->lnd_own == 0)
381 lcp = &lchr[(int)lp->lnd_type];
383 memset(buf1, 0, sizeof(buf1));
384 memset(buf2, 0, sizeof(buf2));
385 memset(buf3, 0, sizeof(buf3));
386 if (chance((double)(spy + lp->lnd_vis) / 10.0)) {
387 if (destination == player->cnum)
388 pr("%s %s", mess, prland(lp));
390 sprintf(buf1, "%s %s", mess, prland(lp));
392 estimate = lnd_getmil(lp);
394 if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
396 if (destination == player->cnum)
397 pr(" (eff %d, mil %d", roundintby(lp->lnd_effic, 5),
398 roundintby(lnd_getmil(lp), 10));
400 sprintf(buf2, " (eff %d, mil %d",
401 roundintby(lp->lnd_effic, 5),
402 roundintby(lnd_getmil(lp), 10));
403 estimate = lnd_getmil(lp) * lp->lnd_effic / 100.0;
405 if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
407 t = lp->lnd_tech - 20 + roll(40);
409 if (destination == player->cnum)
410 pr(", tech %d)\n", t);
412 sprintf(buf3, ", tech %d)\n", t);
414 if (destination == player->cnum)
417 sprintf(buf3, ")\n");
420 if (destination == player->cnum)
427 if (destination != player->cnum) {
428 wu(0, destination, "%s%s%s", buf1, buf2, buf3);
431 if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
432 estimate *= lp->lnd_def;
434 return (int)estimate;
437 /* Used by the spy command to count land units in a sector. If used
438 for anything else, you may want to reconsider, because this doesn't
439 always count spies. :) */
441 count_sect_units(struct sctstr *sp)
447 snxtitem_all(&ni, EF_LAND);
448 while (nxtitem(&ni, (s_char *)&land)) {
451 if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y)
453 /* Don't always see spies */
454 if (lchr[(int)land.lnd_type].l_flags & L_SPY) {
455 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
458 /* Got here, report it */
466 count_units(struct shpstr *sp)
472 if (sp->shp_effic < SHIP_MINEFF)
475 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
476 while (nxtitem(&ni, (s_char *)&land)) {
477 if (land.lnd_own == 0)
479 if (land.lnd_ship == sp->shp_uid)
483 if (sp->shp_nland != nland) {
484 sp->shp_nland = nland;
485 putship(sp->shp_uid, sp);
490 lnd_count_units(struct lndstr *lp)
496 if (lp->lnd_effic < LAND_MINEFF)
499 snxtitem_xy(&ni, EF_LAND, lp->lnd_x, lp->lnd_y);
500 while (nxtitem(&ni, (s_char *)&land)) {
501 if (land.lnd_own == 0)
503 if (land.lnd_land == lp->lnd_uid)
507 if (lp->lnd_nland != nland) {
508 lp->lnd_nland = nland;
509 putland(lp->lnd_uid, lp);
514 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
526 while (nxtitem(ni, (s_char *)&land)) {
530 if (ontradingblock(EF_LAND, (int *)&land)) {
531 pr("unit #%d inelligible - it's for sale.\n",
536 lcp = &lchr[(int)land.lnd_type];
537 /* if (wantflags && (lcp->m_flags & wantflags) != wantflags)
539 if (nowantflags && lcp->m_flags & nowantflags)
542 /* This abuse is better fixed by building a unit with the normal negative
543 mobility that everything else is built with */
544 /* Just so that the player can't build a bunch of land units, and them
545 march them a few minutes later... */
547 if (opt_MOB_ACCESS) {
548 if (land.lnd_effic < 11 &&
549 land.lnd_mobil < etu_per_update) {
550 pr("Land unit #%d needs at least %d mob to march.\n",
551 land.lnd_uid, etu_per_update);
556 land.lnd_mission = 0;
559 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
560 putland(land.lnd_uid, &land);
561 llp = (struct llist *)malloc(sizeof(struct llist));
564 llp->mobil = (double)land.lnd_mobil;
565 emp_insque(&llp->queue, list);
569 /* This function assumes that the list was created by lnd_sel */
571 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
572 int *togetherp, natid actor)
574 struct emp_qelem *qp;
575 struct emp_qelem *next;
588 for (qp = list->q_back; qp != list; qp = next) {
590 llp = (struct llist *)qp;
591 getland(llp->land.lnd_uid, &land);
592 if (land.lnd_own != actor) {
593 mpr(actor, "%s was disbanded at %s\n",
594 prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
595 emp_remque((struct emp_qelem *)llp);
599 if (land.lnd_ship >= 0) {
600 lnd_mess("is on a ship", llp);
603 if (land.lnd_land >= 0) {
604 lnd_mess("is on a unit", llp);
607 if (!getsect(land.lnd_x, land.lnd_y, §)) {
608 lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
611 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
612 !(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) &&
613 lnd_getmil(&llp->land) == 0) {
614 lnd_mess("has no mil on it to guide it", llp);
617 rel = getrel(getnatp(sect.sct_own), player->cnum);
618 if (sect.sct_own != land.lnd_own && rel != ALLIED &&
619 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
621 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
630 if (land.lnd_x != allx || land.lnd_y != ally)
632 if (land.lnd_mobil + 1 < (int)llp->mobil) {
633 llp->mobil = (double)land.lnd_mobil;
635 if (llp->mobil < *minmobp)
636 *minmobp = llp->mobil;
637 if (llp->mobil > *maxmobp)
638 *maxmobp = llp->mobil;
644 lnd_put(struct emp_qelem *list, natid actor)
646 register struct emp_qelem *qp;
647 register struct emp_qelem *newqp;
652 llp = (struct llist *)qp;
654 mpr(actor, "%s stopped at %s\n", prland(&llp->land),
655 xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
656 if (llp->mobil < -127)
658 llp->land.lnd_mobil = llp->mobil;
660 putland(llp->land.lnd_uid, &llp->land);
669 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
672 struct emp_qelem *qp;
673 struct emp_qelem *next;
676 int mines, m, max, sshells, lshells;
679 for (qp = land_list->q_back; qp != land_list; qp = next) {
681 llp = (struct llist *)qp;
682 if (!(llp->lcp->l_flags & L_ENGINEER)) {
684 mpr(actor, "%s is not an engineer!\n", prland(&llp->land));
687 if (takemob && llp->mobil < 0.0) {
689 lnd_mess("is out of mobility", llp);
692 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
693 if (sect.sct_oldown == llp->land.lnd_own) {
696 "%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
700 if (sect.sct_type == SCT_BSPAN) {
702 mpr(actor, "%s is on a bridge. No mines there!\n",
707 /* mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/
708 mobcost = llp->land.lnd_spd;
709 mobcost = 480.0 / (mobcost +
710 techfact(llp->land.lnd_tech, mobcost));
711 llp->mobil -= mobcost;
712 llp->land.lnd_mobil = (int)llp->mobil;
713 llp->land.lnd_harden = 0;
715 putland(llp->land.lnd_uid, &llp->land);
716 if (!(mines = getvar(V_MINE, (s_char *)§, EF_SECTOR)))
718 max = vl_find(V_SHELL, llp->lcp->l_vtype,
719 llp->lcp->l_vamt, (int)llp->lcp->l_nv);
720 lshells = getvar(V_SHELL, (s_char *)&llp->land, EF_LAND);
721 sshells = getvar(V_SHELL, (s_char *)§, EF_SECTOR);
722 for (m = 0; mines > 0 && m < max * 2; m++) {
723 if (chance(0.5 * llp->lcp->l_att)) {
724 mpr(actor, "Sweep...\n");
732 putvar(V_MINE, mines, (s_char *)§, EF_SECTOR);
733 putvar(V_SHELL, lshells, (s_char *)&llp->land, EF_LAND);
734 putvar(V_SHELL, sshells, (s_char *)§, EF_SECTOR);
735 putland(llp->land.lnd_uid, &llp->land);
741 contains_engineer(struct emp_qelem *list)
743 struct emp_qelem *qp;
744 struct emp_qelem *next;
747 for (qp = list->q_back; qp != list; qp = next) {
749 llp = (struct llist *)qp;
750 if (llp->lcp->l_flags & L_ENGINEER)
757 lnd_check_mines(struct emp_qelem *land_list)
759 struct emp_qelem *qp;
760 struct emp_qelem *next;
765 int has_engineers = contains_engineer(land_list);
767 for (qp = land_list->q_back; qp != land_list; qp = next) {
769 llp = (struct llist *)qp;
770 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
771 if (sect.sct_oldown == llp->land.lnd_own)
773 if (sect.sct_type == SCT_BSPAN)
775 if (!(mines = getvar(V_MINE, (s_char *)§, EF_SECTOR)))
777 if (chance(DMINE_LHITCHANCE(mines) / (1 + 2 * has_engineers))) {
778 lnd_hit_mine(&llp->land, llp->lcp);
780 putvar(V_MINE, mines, (s_char *)§, EF_SECTOR);
782 putland(llp->land.lnd_uid, (s_char *)&llp->land);
783 if (!llp->land.lnd_own) {
794 lnd_list(struct emp_qelem *land_list)
796 struct emp_qelem *qp;
797 struct emp_qelem *next;
802 pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
804 for (qp = land_list->q_back; qp != land_list; qp = next) {
806 llp = (struct llist *)qp;
808 pr("%4d ", lnd->lnd_uid);
809 pr("%-16.16s ", llp->lcp->l_name);
810 prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
811 pr("%1c", lnd->lnd_army);
812 pr("%4d%%", lnd->lnd_effic);
813 getvec(VT_ITEM, vec, (s_char *)lnd, EF_LAND);
814 pr("%4d", vec[I_SHELL]);
815 pr("%4d", vec[I_GUN]);
816 count_land_planes(lnd);
817 pr("%3d", lnd->lnd_nxlight);
818 pr("%4d", lnd->lnd_mobil);
819 pr("%4d", lnd->lnd_tech);
820 pr("%4d%%", lnd->lnd_retreat);
821 pr("%5d\n", lnd->lnd_fuel);
826 lnd_mess(s_char *str, struct llist *llp)
828 mpr(llp->land.lnd_own, "%s %s & stays in %s\n",
830 str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
831 if (llp->mobil < -127)
833 llp->land.lnd_mobil = llp->mobil;
834 putland(llp->land.lnd_uid, &llp->land);
835 emp_remque((struct emp_qelem *)llp);
840 lnd_count(struct emp_qelem *list)
842 struct emp_qelem *qp;
843 struct emp_qelem *next;
847 for (qp = list->q_back; qp != list; qp = next) {
849 llp = (struct llist *)qp;
856 lnd_damage(struct emp_qelem *list, int totdam)
858 struct emp_qelem *qp;
859 struct emp_qelem *next;
864 if (!totdam || !(count = lnd_count(list)))
866 dam = ldround(((double)totdam / (double)count), 1);
867 for (qp = list->q_back; qp != list; qp = next) {
869 llp = (struct llist *)qp;
870 /* have to get it again because of collateral damage */
871 getland(llp->land.lnd_uid, &llp->land);
872 landdamage(&llp->land, dam);
873 putland(llp->land.lnd_uid, &llp->land);
874 if (!llp->land.lnd_own) {
883 lnd_easiest_target(struct emp_qelem *list)
885 struct emp_qelem *qp;
886 struct emp_qelem *next;
889 int easiest = 9876; /* things start great for victim */
892 for (qp = list->q_back; qp != list; qp = next) {
894 llp = (struct llist *)qp;
895 hard = lnd_hardtarget(&llp->land);
897 easiest = hard; /* things get worse for victim */
900 return easiest - count;
904 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
908 struct emp_qelem msl_list, *qp, *newqp;
910 msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
912 dam = msl_launch_mindam(&msl_list, newx, newy,
913 lnd_easiest_target(list), EF_LAND,
914 lnd_count(list) * 20, "troops", victim,
917 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
918 collateral_damage(newx, newy, dam, 0);
920 qp = msl_list.q_forw;
921 while (qp != msl_list.q_forw) {
931 /* Steve M. - commented out for now until abuse is decided upon */
932 /* risner: allow forts to interdict land units. */
934 lnd_fort_interdiction(struct emp_qelem *list,
935 coord newx, coord newy, natid victim)
937 extern int fort_max_interdiction_range;
941 double range, range2, guneff;
947 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
948 while (nxtsct(&ns, &fsect)) {
949 if (fsect.sct_own == 0)
951 if (fsect.sct_own == victim)
953 if (fsect.sct_type != SCT_FORTR)
955 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
957 gun = getvar(V_GUN, (s_char *)&fsect, EF_SECTOR);
960 range = tfactfire(fsect.sct_own, (double)min(gun, 7));
961 if (fsect.sct_effic > 59)
963 range2 = roundrange(range);
964 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
967 if (getvar(V_MILIT, (s_char *)&fsect, EF_SECTOR) < 5)
969 shell = getvar(V_SHELL, (s_char *)&fsect, EF_SECTOR);
971 shell += supply_commod(fsect.sct_own,
972 fsect.sct_x, fsect.sct_y, I_SHELL, 1);
976 putvar(V_SHELL, shell, (s_char *)&fsect, EF_SECTOR);
980 guneff = landgun((int)fsect.sct_effic, gun);
983 mpr(victim, "Incoming fire does %d damage!\n", dam);
985 "%s fires at %s land units in %s for %d!\n",
986 xyas(fsect.sct_x, fsect.sct_y,
988 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
989 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
992 return lnd_damage(list, totdam);
998 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
1003 if (!opt_NO_FORT_FIRE)
1004 /* Steve M. - commented out for now until abuse is decided upon */
1005 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
1010 unit_interdict(newx, newy, victim, "land units",
1011 lnd_easiest_target(list), MI_INTERDICT));
1015 lnd_missile_interdiction(list, newx, newy, victim));
1019 /* high value of hardtarget is harder to hit */
1021 lnd_hardtarget(struct lndstr *lp)
1025 getsect(lp->lnd_x, lp->lnd_y, §);
1026 return (int)(((double)lp->lnd_effic / 100.0) *
1027 (10 + dchr[sect.sct_type].d_dstr * 2 +
1028 (double)lp->lnd_spd / 2.0 - lp->lnd_vis));
1032 lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
1036 mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
1037 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1039 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
1042 if (lcp->l_flags & L_ENGINEER)
1045 landdamage(lp, ldround(m, 1));
1051 lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
1056 /* supply unit's speed depends on their eff, since
1057 that is their purpose */
1058 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
1059 mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd;
1061 mobcost = lp->lnd_spd;
1065 /* sector_mcost now takes 2 different arguments, a sector pointer, and
1066 whether or not to figure in the highway bonus, rail bonus or none.
1067 bridge heads, bridges and highways have built-in highways bonus
1068 because they are a 1, and this will discount that. */
1070 smobcost = (double)sector_mcost(sp, mobtype);
1071 if (smobcost < 0.01)
1074 /* marching through 0 mobility conquered sectors takes lots of mobility,
1075 unless you are a train. Capturing railways is a good thing. */
1077 if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 &&
1078 smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL)
1079 smobcost = LND_MINMOBCOST;
1081 mobcost = smobcost * 5.0 * 480.0 /
1082 (mobcost + techfact(lp->lnd_tech, mobcost));
1088 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
1091 struct sctstr sect, osect;
1092 struct emp_qelem *qp;
1093 struct emp_qelem *qp2;
1094 struct emp_qelem *next;
1107 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
1108 lnd_put(list, actor);
1111 dx = diroff[dir][0];
1112 dy = diroff[dir][1];
1113 for (qp = list->q_back; qp != list; qp = next) {
1115 llp = (struct llist *)qp;
1116 getsect(llp->land.lnd_x, llp->land.lnd_y, &osect);
1117 oldown = osect.sct_own;
1118 newx = xnorm(llp->land.lnd_x + dx);
1119 newy = ynorm(llp->land.lnd_y + dy);
1120 getsect(newx, newy, §);
1121 rel = getrel(getnatp(sect.sct_own), player->cnum);
1122 if ((sect.sct_own != actor && rel != ALLIED &&
1123 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
1124 sect.sct_own) || (sect.sct_type == SCT_WATER ||
1125 sect.sct_type == SCT_SANCT ||
1126 sect.sct_type == SCT_WASTE)) {
1128 pr("can't go to %s\n", xyas(newx, newy, actor));
1131 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
1137 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY))
1139 if (sect.sct_rail == 0 &&
1140 lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1142 pr("no rail system in %s\n", xyas(newx, newy, actor));
1145 sprintf(dp, "has no rail system in %s",
1146 xyas(newx, newy, actor));
1151 /* Note we check would_abandon first because we don't want
1152 to always have to do these checks */
1153 if (would_abandon(&osect, V_CIVIL, 0, &(llp->land))) {
1155 if (!want_to_abandon(&osect, V_CIVIL, 0, &(llp->land))) {
1158 /* now check stuff */
1159 if (!check_sect_ok(§))
1161 if (!check_sect_ok(&osect))
1163 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
1164 if (!check_land_ok(&(((struct llist *)qp2)->land)))
1168 lnd_mess("stops", llp);
1172 if (llp->mobil <= 0.0) {
1173 lnd_mess("is out of mobility", llp);
1176 llp->land.lnd_x = newx;
1177 llp->land.lnd_y = newy;
1178 if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1179 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL);
1181 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_ROAD);
1183 llp->land.lnd_mobil = (int)llp->mobil;
1184 llp->land.lnd_harden = 0;
1185 putland(llp->land.lnd_uid, &llp->land);
1187 getsect(osect.sct_x, osect.sct_y, &osect);
1188 if (osect.sct_own != oldown && oldown == player->cnum) {
1189 /* It was your sector, now it's not. Simple :) */
1190 pr("You no longer own %s\n",
1191 xyas(osect.sct_x, osect.sct_y, player->cnum));
1193 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
1194 /* Always a 10% chance of getting caught. */
1195 if (chance(LND_SPY_DETECT_CHANCE(llp->land.lnd_effic))) {
1196 if (rel == NEUTRAL || rel == FRIENDLY) {
1198 "%s unit spotted in %s\n", cname(player->cnum),
1199 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1200 setrel(sect.sct_own, llp->land.lnd_own, HOSTILE);
1201 } else if (rel == HOSTILE || rel == AT_WAR ||
1202 rel == SITZKRIEG || rel == MOBILIZATION) {
1204 "%s spy shot in %s\n", cname(player->cnum),
1205 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1206 pr("%s was shot and killed.\n", prland(&llp->land));
1207 llp->land.lnd_effic = 0;
1208 putland(llp->land.lnd_uid, &llp->land);
1216 lnd_sweep(list, 0, 1, actor);
1217 stopping |= lnd_check_mines(list);
1221 stopping |= lnd_interdict(list, newx, newy, actor);
1226 * find all artillery units belonging
1227 * to the attacker or defender that can fire.
1228 * Each arty unit adds +1%/damage point
1232 lnd_support(natid victim, natid attacker, coord x, coord y)
1234 struct nstr_item ni;
1241 double range, range2;
1243 snxtitem_all(&ni, EF_LAND);
1244 while (nxtitem(&ni, (s_char *)&land)) {
1245 if (land.lnd_frg == 0)
1247 if ((land.lnd_x == x) && (land.lnd_y == y))
1249 if (land.lnd_ship >= 0)
1251 if (land.lnd_land >= 0)
1253 if (land.lnd_mission > 0)
1255 if (land.lnd_effic < LAND_MINFIREEFF)
1257 /* Do we have mil? */
1258 if (getvar(V_MILIT, (s_char *)&land, EF_LAND) <= 0)
1260 rel = getrel(getnatp(land.lnd_own), attacker);
1261 rel2 = getrel(getnatp(land.lnd_own), victim);
1262 if ((land.lnd_own != attacker) &&
1263 ((rel != ALLIED) || (rel2 != AT_WAR)))
1266 /* do we have supplies? */
1267 if (!has_supply(&land))
1270 /* are we in range? */
1271 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1273 range = techfact((int)land.lnd_tech, (double)land.lnd_frg / 2.0);
1275 range2 = roundrange(range);
1279 shell = getvar(V_SHELL, (s_char *)&land, EF_LAND);
1280 gun = getvar(V_GUN, (s_char *)&land, EF_LAND);
1282 if (shell == 0 || gun == 0)
1286 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1287 if (roll(100) < land.lnd_acc) {
1288 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1289 land.lnd_ammo, shell) / 2;
1291 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1292 land.lnd_ammo, shell);
1294 if (land.lnd_own != attacker)
1296 "%s supported %s at %s\n",
1297 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1303 lnd_path(int together, struct lndstr *lp, s_char *buf)
1307 struct sctstr d_sect, sect;
1311 if (!sarg_xy(buf, &destx, &desty))
1314 pr("Cannot go to a destination sector if not all starting in the same sector\n");
1317 if (!getsect(destx, desty, &d_sect)) {
1318 pr("%d,%d is not a sector\n", destx, desty);
1321 getsect(lp->lnd_x, lp->lnd_y, §);
1322 if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
1323 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_RAIL);
1325 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_ROAD);
1327 pr("No owned path from %s to %s!\n",
1328 xyas(lp->lnd_x, lp->lnd_y, player->cnum),
1329 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1332 pr("Using path '%s'\n", cp);
1337 lnd_can_attack(struct lndstr *lp)
1339 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1341 /* if (lcp->l_flags & L_SUPPLY ||
1342 lcp->l_flags & L_SECURITY ||
1343 lcp->l_flags & L_FLAK ||
1346 if (lcp->l_flags & L_SUPPLY)
1353 * Increase fortification value of LP.
1354 * Fortification costs mobility. Use up to HARD_AMT mobility.
1355 * Return actual fortification increase.
1358 lnd_fortify (struct lndstr *lp, int hard_amt)
1363 if ((lp->lnd_ship >= 0) || lp->lnd_land >= 0)
1366 hard_amt = min(lp->lnd_mobil, hard_amt);
1368 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1369 hard_amt = land_mob_max - lp->lnd_harden;
1371 eng = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own);
1374 hard_amt = ((float)hard_amt * 1.5);
1376 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1377 hard_amt = land_mob_max - lp->lnd_harden;
1379 /* Ok, set the mobility used */
1380 mob_used = hard_amt;
1382 /* Now, if an engineer helped, it's really only 2/3rds of
1385 mob_used = (int)((float)mob_used / 1.5);
1387 /* If we increased it, but not much, we gotta take at least 1
1389 if (mob_used <= 0 && hard_amt > 0)
1392 lp->lnd_mobil -= mob_used;
1393 if (lp->lnd_mobil < 0)
1396 lp->lnd_harden += hard_amt;
1397 lp->lnd_harden = min(lp->lnd_harden, land_mob_max);