2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future 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 static void lnd_mess(char *, struct llist *);
57 static int lnd_hit_mine(struct lndstr *, struct lchrstr *);
60 attack_val(int combat_mode, struct lndstr *lp)
66 if (lp->lnd_effic < LAND_MINEFF) {
67 putland(lp->lnd_uid, lp);
71 lcp = &lchr[(int)lp->lnd_type];
73 /* Spies always count as 1 during assaults. If they are the only ones
74 in the assault, they get to sneak on anyway. */
76 if (lcp->l_flags & L_SPY && combat_mode == A_ASSAULT)
79 men = lp->lnd_item[I_MILIT];
80 value = men * lp->lnd_att * lp->lnd_effic / 100.0;
82 switch (combat_mode) {
86 if (!(lcp->l_flags & L_MARINE))
87 return (int)(assault_penalty * value);
90 if (!(lcp->l_flags & L_MARINE))
91 return (int)(assault_penalty * men);
98 defense_val(struct lndstr *lp)
104 if (lp->lnd_effic < LAND_MINEFF) {
105 putland(lp->lnd_uid, lp);
109 lcp = &lchr[(int)lp->lnd_type];
111 men = lp->lnd_item[I_MILIT];
113 if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) &&
114 !(lcp->l_flags & L_MARINE))
117 value = men * lp->lnd_def * lp->lnd_effic / 100.0;
118 value *= ((double)land_mob_max + lp->lnd_harden) / land_mob_max;
120 /* If there are military on the unit, you get at least a 1
121 man defensive unit, except for spies */
122 if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
129 lnd_print(struct llist *llp, char *s)
131 if (llp->land.lnd_own == player->cnum)
132 pr("%s %s\n", prland(&llp->land), s);
134 wu(0, llp->land.lnd_own, "%s %s\n", prland(&llp->land), s);
138 lnd_delete(struct llist *llp, char *s)
142 putland(llp->land.lnd_uid, &llp->land);
143 emp_remque((struct emp_qelem *)llp);
148 lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
149 /* attacking or assaulting or paratrooping? */
150 /* number of casualties to take */
163 int nowhere_to_go = 0;
169 taken = llp->land.lnd_item[I_MILIT];
170 /* Spies always die */
171 if (llp->lcp->l_flags & L_SPY) {
173 llp->land.lnd_effic = 0;
175 eff_eq = ldround(cas * 100.0 / llp->lcp->l_mil, 1);
176 llp->land.lnd_effic -= eff_eq;
177 lnd_submil(&llp->land, cas);
180 if (llp->land.lnd_effic < LAND_MINEFF) {
181 sprintf(buf, "dies %s %s!",
182 combat_mode ? att_mode[combat_mode] : "defending",
183 xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
184 lnd_delete(llp, buf);
185 /* Since we killed the unit, we killed all the mil on it */
188 /* Ok, now, how many did we take off? (sould be the diff) */
189 taken = taken - llp->land.lnd_item[I_MILIT];
192 if (llp->land.lnd_effic >= llp->land.lnd_retreat)
195 /* we're being boarded */
196 if (llp->land.lnd_ship >= 0 && combat_mode == A_DEFEND)
199 /* we're being boarded */
200 if (llp->land.lnd_land >= 0 && combat_mode == A_DEFEND)
203 /* Have to make a retreat check */
205 ret_chance = llp->land.lnd_retreat - llp->land.lnd_effic;
206 if (roll(100) < ret_chance) {
208 lnd_print(llp, "fails morale check!");
209 llp->land.lnd_mission = 0;
210 llp->land.lnd_harden = 0;
211 if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0)
213 else if (combat_mode == A_DEFEND) {
215 * defending unit.. find a place to send it
216 * strategy: look for the most-populated
217 * adjacent sector that is owned by the unit
218 * player->owner. Charge mob..
222 for (n = 1; n <= 6; ++n) {
223 ret_x = llp->land.lnd_x + diroff[n][0];
224 ret_y = llp->land.lnd_y + diroff[n][1];
225 getsect(ret_x, ret_y, §);
226 if (sect.sct_own != llp->land.lnd_own)
228 if (sect.sct_type == SCT_MOUNT)
231 civs = sect.sct_item[I_CIVIL];
232 if (civs > biggest) {
241 /* retreat to bx,by */
242 llp->land.lnd_x = bx;
243 llp->land.lnd_y = by;
244 getsect(bx, by, &rsect);
245 mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD);
246 mob = llp->land.lnd_mobil - (int)mobcost;
249 orig = llp->land.lnd_mobil;
250 llp->land.lnd_mobil = (signed char)mob;
251 if (llp->land.lnd_mobil > orig)
252 llp->land.lnd_mobil = -127;
253 sprintf(buf, "retreats at %d%% efficiency to %s!",
255 xyas(bx, by, llp->land.lnd_own));
256 lnd_delete(llp, buf);
258 } else { /* attacking from a sector */
259 sprintf(buf, "leaves the battlefield at %d%% efficiency",
260 llp->land.lnd_effic);
261 if ((llp->land.lnd_mobil - (int)llp->mobil) < -127)
262 llp->land.lnd_mobil = -127;
264 llp->land.lnd_mobil -= (int)llp->mobil;
266 lnd_delete(llp, buf);
270 /* nowhere to go.. take more casualties */
271 llp->land.lnd_effic -= 10;
272 lnd_submil(&llp->land, llp->lcp->l_mil / 10);
273 if (llp->land.lnd_effic < LAND_MINEFF)
274 lnd_delete(llp, "has nowhere to retreat, and dies!");
277 "has nowhere to retreat and takes extra losses!");
284 lnd_takemob(struct emp_qelem *list, double loss)
286 struct emp_qelem *qp, *next;
289 int mcost = ldround(combat_mob * loss, 1);
291 for (qp = list->q_forw; qp != list; qp = next) {
293 llp = (struct llist *)qp;
296 use_supply(&llp->land);
297 if (llp->land.lnd_mission == MI_RESERVE)
298 new = llp->land.lnd_mobil - mcost/2;
301 new = llp->land.lnd_mobil - mcost;
304 llp->land.lnd_mobil = (signed char)new;
309 lnd_submil(struct lndstr *lp, int num)
311 int new = lp->lnd_item[I_MILIT] - num;
312 lp->lnd_item[I_MILIT] = new < 0 ? 0 : new;
316 lnd_spyval(struct lndstr *lp)
318 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
319 return lp->lnd_spy * (lp->lnd_effic / 100.0) + 2;
321 return lp->lnd_spy * (lp->lnd_effic / 100.0);
325 intelligence_report(int destination, struct lndstr *lp, int spy,
329 char buf1[80], buf2[80], buf3[80];
330 double estimate = 0.0; /* estimated defense value */
332 if (destination == 0)
335 if (lp->lnd_own == 0)
338 lcp = &lchr[(int)lp->lnd_type];
340 memset(buf1, 0, sizeof(buf1));
341 memset(buf2, 0, sizeof(buf2));
342 memset(buf3, 0, sizeof(buf3));
343 if (chance((spy + lp->lnd_vis) / 10.0)) {
344 if (destination == player->cnum)
345 pr("%s %s", mess, prland(lp));
347 sprintf(buf1, "%s %s", mess, prland(lp));
349 estimate = lp->lnd_item[I_MILIT];
351 if (chance((spy + lp->lnd_vis) / 20.0)) {
352 if (destination == player->cnum)
353 pr(" (eff %d, mil %d",
354 roundintby(lp->lnd_effic, 5),
355 roundintby(lp->lnd_item[I_MILIT], 10));
357 sprintf(buf2, " (eff %d, mil %d",
358 roundintby(lp->lnd_effic, 5),
359 roundintby(lp->lnd_item[I_MILIT], 10));
360 estimate = lp->lnd_item[I_MILIT] * lp->lnd_effic / 100.0;
362 if (chance((spy + lp->lnd_vis) / 20.0)) {
364 t = lp->lnd_tech - 20 + roll(40);
366 if (destination == player->cnum)
367 pr(", tech %d)\n", t);
369 sprintf(buf3, ", tech %d)\n", t);
371 if (destination == player->cnum)
374 sprintf(buf3, ")\n");
377 if (destination == player->cnum)
384 if (destination != player->cnum) {
385 wu(0, destination, "%s%s%s", buf1, buf2, buf3);
388 if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
389 estimate *= lp->lnd_def;
391 return (int)estimate;
394 /* Used by the spy command to count land units in a sector. If used
395 for anything else, you may want to reconsider, because this doesn't
396 always count spies. :) */
398 count_sect_units(struct sctstr *sp)
404 snxtitem_all(&ni, EF_LAND);
405 while (nxtitem(&ni, &land)) {
408 if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y)
410 /* Don't always see spies */
411 if (lchr[(int)land.lnd_type].l_flags & L_SPY) {
412 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
415 /* Got here, report it */
423 count_units(struct shpstr *sp)
429 if (sp->shp_effic < SHIP_MINEFF)
432 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
433 while (nxtitem(&ni, &land)) {
434 if (land.lnd_own == 0)
436 if (land.lnd_ship == sp->shp_uid)
440 if (sp->shp_nland != nland) {
441 sp->shp_nland = nland;
442 putship(sp->shp_uid, sp);
447 lnd_count_units(struct lndstr *lp)
453 if (lp->lnd_effic < LAND_MINEFF)
456 snxtitem_xy(&ni, EF_LAND, lp->lnd_x, lp->lnd_y);
457 while (nxtitem(&ni, &land)) {
458 if (land.lnd_own == 0)
460 if (land.lnd_land == lp->lnd_uid)
464 if (lp->lnd_nland != nland) {
465 lp->lnd_nland = nland;
466 putland(lp->lnd_uid, lp);
471 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
483 while (nxtitem(ni, &land)) {
487 if (ontradingblock(EF_LAND, &land)) {
488 pr("unit #%d inelligible - it's for sale.\n",
493 lcp = &lchr[(int)land.lnd_type];
494 /* if (wantflags && (lcp->m_flags & wantflags) != wantflags)
496 if (nowantflags && lcp->m_flags & nowantflags)
499 /* This abuse is better fixed by building a unit with the normal negative
500 mobility that everything else is built with */
501 /* Just so that the player can't build a bunch of land units, and them
502 march them a few minutes later... */
504 if (opt_MOB_ACCESS) {
505 if (land.lnd_effic < 11 &&
506 land.lnd_mobil < etu_per_update) {
507 pr("Land unit #%d needs at least %d mob to march.\n",
508 land.lnd_uid, etu_per_update);
513 land.lnd_mission = 0;
516 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
517 putland(land.lnd_uid, &land);
518 llp = malloc(sizeof(struct llist));
521 llp->mobil = land.lnd_mobil;
522 emp_insque(&llp->queue, list);
526 /* This function assumes that the list was created by lnd_sel */
528 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
529 int *togetherp, natid actor)
531 struct emp_qelem *qp;
532 struct emp_qelem *next;
545 for (qp = list->q_back; qp != list; qp = next) {
547 llp = (struct llist *)qp;
548 getland(llp->land.lnd_uid, &land);
549 if (land.lnd_own != actor) {
550 mpr(actor, "%s was disbanded at %s\n",
551 prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
552 emp_remque((struct emp_qelem *)llp);
556 if (land.lnd_ship >= 0) {
557 lnd_mess("is on a ship", llp);
560 if (land.lnd_land >= 0) {
561 lnd_mess("is on a unit", llp);
564 if (!getsect(land.lnd_x, land.lnd_y, §)) {
565 lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
568 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
569 !(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) &&
570 llp->land.lnd_item[I_MILIT] == 0) {
571 lnd_mess("has no mil on it to guide it", llp);
574 rel = getrel(getnatp(sect.sct_own), player->cnum);
575 if (sect.sct_own != land.lnd_own && rel != ALLIED &&
576 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
578 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
587 if (land.lnd_x != allx || land.lnd_y != ally)
589 if (land.lnd_mobil + 1 < (int)llp->mobil) {
590 llp->mobil = land.lnd_mobil;
592 if (llp->mobil < *minmobp)
593 *minmobp = llp->mobil;
594 if (llp->mobil > *maxmobp)
595 *maxmobp = llp->mobil;
601 lnd_put(struct emp_qelem *list, natid actor)
603 struct emp_qelem *qp;
604 struct emp_qelem *newqp;
609 llp = (struct llist *)qp;
611 mpr(actor, "%s stopped at %s\n", prland(&llp->land),
612 xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
613 if (llp->mobil < -127)
615 llp->land.lnd_mobil = llp->mobil;
617 putland(llp->land.lnd_uid, &llp->land);
626 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
629 struct emp_qelem *qp;
630 struct emp_qelem *next;
633 int mines, m, max, sshells, lshells;
636 for (qp = land_list->q_back; qp != land_list; qp = next) {
638 llp = (struct llist *)qp;
639 if (!(llp->lcp->l_flags & L_ENGINEER)) {
641 mpr(actor, "%s is not an engineer!\n", prland(&llp->land));
644 if (takemob && llp->mobil < 0.0) {
646 lnd_mess("is out of mobility", llp);
649 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
650 if (sect.sct_oldown == llp->land.lnd_own) {
653 "%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
657 if (sect.sct_type == SCT_BSPAN) {
659 mpr(actor, "%s is on a bridge. No mines there!\n",
664 /* mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/
665 mobcost = llp->land.lnd_spd;
666 mobcost = 480.0 / (mobcost +
667 techfact(llp->land.lnd_tech, mobcost));
668 llp->mobil -= mobcost;
669 llp->land.lnd_mobil = (int)llp->mobil;
670 llp->land.lnd_harden = 0;
672 putland(llp->land.lnd_uid, &llp->land);
673 if (!(mines = sect.sct_mines))
675 max = llp->lcp->l_item[I_SHELL];
676 lshells = llp->land.lnd_item[I_SHELL];
677 sshells = sect.sct_item[I_SHELL];
678 for (m = 0; mines > 0 && m < max * 2; m++) {
679 if (chance(0.5 * llp->lcp->l_att)) {
680 mpr(actor, "Sweep...\n");
684 else if (sshells < ITEM_MAX)
688 sect.sct_mines = mines;
689 llp->land.lnd_item[I_SHELL] = lshells;
690 sect.sct_item[I_SHELL] = sshells;
691 putland(llp->land.lnd_uid, &llp->land);
697 contains_engineer(struct emp_qelem *list)
699 struct emp_qelem *qp;
700 struct emp_qelem *next;
703 for (qp = list->q_back; qp != list; qp = next) {
705 llp = (struct llist *)qp;
706 if (llp->lcp->l_flags & L_ENGINEER)
713 lnd_check_mines(struct emp_qelem *land_list)
715 struct emp_qelem *qp;
716 struct emp_qelem *next;
720 int with_eng = contains_engineer(land_list);
722 for (qp = land_list->q_back; qp != land_list; qp = next) {
724 llp = (struct llist *)qp;
725 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
726 if (sect.sct_oldown == llp->land.lnd_own)
728 if (sect.sct_type == SCT_BSPAN)
732 if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
733 lnd_hit_mine(&llp->land, llp->lcp);
736 putland(llp->land.lnd_uid, &llp->land);
737 if (!llp->land.lnd_own) {
748 lnd_list(struct emp_qelem *land_list)
750 struct emp_qelem *qp;
751 struct emp_qelem *next;
755 pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
757 for (qp = land_list->q_back; qp != land_list; qp = next) {
759 llp = (struct llist *)qp;
761 pr("%4d ", lnd->lnd_uid);
762 pr("%-16.16s ", llp->lcp->l_name);
763 prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
764 pr("%1.1s", &lnd->lnd_army);
765 pr("%4d%%", lnd->lnd_effic);
766 pr("%4d", lnd->lnd_item[I_SHELL]);
767 pr("%4d", lnd->lnd_item[I_GUN]);
768 count_land_planes(lnd);
769 pr("%3d", lnd->lnd_nxlight);
770 pr("%4d", lnd->lnd_mobil);
771 pr("%4d", lnd->lnd_tech);
772 pr("%4d%%", lnd->lnd_retreat);
773 pr("%5d\n", lnd->lnd_fuel);
778 lnd_mess(char *str, struct llist *llp)
780 mpr(llp->land.lnd_own, "%s %s & stays in %s\n",
782 str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
783 if (llp->mobil < -127)
785 llp->land.lnd_mobil = llp->mobil;
786 putland(llp->land.lnd_uid, &llp->land);
787 emp_remque((struct emp_qelem *)llp);
792 lnd_count(struct emp_qelem *list)
794 struct emp_qelem *qp;
795 struct emp_qelem *next;
799 for (qp = list->q_back; qp != list; qp = next) {
801 llp = (struct llist *)qp;
808 lnd_damage(struct emp_qelem *list, int totdam)
810 struct emp_qelem *qp;
811 struct emp_qelem *next;
816 if (!totdam || !(count = lnd_count(list)))
818 dam = ldround((double)totdam / count, 1);
819 for (qp = list->q_back; qp != list; qp = next) {
821 llp = (struct llist *)qp;
822 /* have to get it again because of collateral damage */
823 getland(llp->land.lnd_uid, &llp->land);
824 landdamage(&llp->land, dam);
825 putland(llp->land.lnd_uid, &llp->land);
826 if (!llp->land.lnd_own) {
835 lnd_easiest_target(struct emp_qelem *list)
837 struct emp_qelem *qp;
838 struct emp_qelem *next;
841 int easiest = 9876; /* things start great for victim */
844 for (qp = list->q_back; qp != list; qp = next) {
846 llp = (struct llist *)qp;
847 hard = lnd_hardtarget(&llp->land);
849 easiest = hard; /* things get worse for victim */
852 return easiest - count;
856 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
860 struct emp_qelem msl_list, *qp, *newqp;
862 msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
864 dam = msl_launch_mindam(&msl_list, newx, newy,
865 lnd_easiest_target(list), EF_LAND,
866 lnd_count(list) * 20, "troops", victim,
869 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
870 collateral_damage(newx, newy, dam, 0);
872 qp = msl_list.q_forw;
873 while (qp != msl_list.q_forw) {
883 /* Steve M. - commented out for now until abuse is decided upon */
884 /* risner: allow forts to interdict land units. */
886 lnd_fort_interdiction(struct emp_qelem *list,
887 coord newx, coord newy, natid victim)
898 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
899 while (nxtsct(&ns, &fsect)) {
900 if (fsect.sct_own == 0)
902 if (fsect.sct_own == victim)
904 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
906 gun = fsect.sct_item[I_GUN];
909 range = roundrange(fortrange(&fsect));
910 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
913 if (fsect.sct_item[I_MILIT] < 5)
915 shell = fsect.sct_item[I_SHELL];
917 shell += supply_commod(fsect.sct_own, fsect.sct_x, fsect.sct_y,
922 fsect.sct_item[I_SHELL] = shell;
926 guneff = landgun((int)fsect.sct_effic, gun);
929 mpr(victim, "Incoming fire does %d damage!\n", dam);
931 "%s fires at %s land units in %s for %d!\n",
932 xyas(fsect.sct_x, fsect.sct_y,
934 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
935 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
938 return lnd_damage(list, totdam);
944 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
949 if (!opt_NO_FORT_FIRE)
950 /* Steve M. - commented out for now until abuse is decided upon */
951 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
956 unit_interdict(newx, newy, victim, "land units",
957 lnd_easiest_target(list), MI_INTERDICT));
961 lnd_missile_interdiction(list, newx, newy, victim));
965 /* high value of hardtarget is harder to hit */
967 lnd_hardtarget(struct lndstr *lp)
971 getsect(lp->lnd_x, lp->lnd_y, §);
972 return (int)((lp->lnd_effic / 100.0) *
973 (10 + dchr[sect.sct_type].d_dstr * 2 + lp->lnd_spd / 2.0
978 lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
982 mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
983 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
985 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
988 if (lcp->l_flags & L_ENGINEER)
991 landdamage(lp, ldround(m, 1));
997 lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
1002 /* supply unit's speed depends on their eff, since
1003 that is their purpose */
1004 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
1005 mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd;
1007 mobcost = lp->lnd_spd;
1011 /* sector_mcost now takes 2 different arguments, a sector pointer, and
1012 whether or not to figure in the highway bonus, rail bonus or none.
1013 bridge heads, bridges and highways have built-in highways bonus
1014 because they are a 1, and this will discount that. */
1016 smobcost = sector_mcost(sp, mobtype);
1017 if (smobcost < 0.01)
1020 /* marching through 0 mobility conquered sectors takes lots of mobility,
1021 unless you are a train. Capturing railways is a good thing. */
1023 if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 &&
1024 smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL)
1025 smobcost = LND_MINMOBCOST;
1027 mobcost = smobcost * 5.0 * 480.0 /
1028 (mobcost + techfact(lp->lnd_tech, mobcost));
1034 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
1037 struct sctstr sect, osect;
1038 struct emp_qelem *qp;
1039 struct emp_qelem *qp2;
1040 struct emp_qelem *next;
1042 struct emp_qelem cur, done;
1054 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
1055 lnd_put(list, actor);
1058 dx = diroff[dir][0];
1059 dy = diroff[dir][1];
1060 for (qp = list->q_back; qp != list; qp = next) {
1062 llp = (struct llist *)qp;
1063 getsect(llp->land.lnd_x, llp->land.lnd_y, &osect);
1064 oldown = osect.sct_own;
1065 newx = xnorm(llp->land.lnd_x + dx);
1066 newy = ynorm(llp->land.lnd_y + dy);
1067 getsect(newx, newy, §);
1068 rel = getrel(getnatp(sect.sct_own), player->cnum);
1069 if ((sect.sct_own != actor && rel != ALLIED &&
1070 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
1071 sect.sct_own) || (sect.sct_type == SCT_WATER ||
1072 sect.sct_type == SCT_SANCT ||
1073 sect.sct_type == SCT_WASTE)) {
1075 pr("can't go to %s\n", xyas(newx, newy, actor));
1078 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
1083 if (sect.sct_rail == 0 &&
1084 lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1086 pr("no rail system in %s\n", xyas(newx, newy, actor));
1089 sprintf(dp, "has no rail system in %s",
1090 xyas(newx, newy, actor));
1095 /* Note we check would_abandon first because we don't want
1096 to always have to do these checks */
1097 if (would_abandon(&osect, I_CIVIL, 0, &llp->land)) {
1099 if (!want_to_abandon(&osect, I_CIVIL, 0, &llp->land)) {
1102 /* now check stuff */
1103 if (!check_sect_ok(§))
1105 if (!check_sect_ok(&osect))
1107 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
1108 if (!check_land_ok(&((struct llist *)qp2)->land))
1112 lnd_mess("stops", llp);
1116 if (llp->mobil <= 0.0) {
1117 lnd_mess("is out of mobility", llp);
1120 llp->land.lnd_x = newx;
1121 llp->land.lnd_y = newy;
1122 if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1123 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL);
1125 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_ROAD);
1127 llp->land.lnd_mobil = (int)llp->mobil;
1128 llp->land.lnd_harden = 0;
1129 putland(llp->land.lnd_uid, &llp->land);
1131 getsect(osect.sct_x, osect.sct_y, &osect);
1132 if (osect.sct_own != oldown && oldown == player->cnum) {
1133 /* It was your sector, now it's not. Simple :) */
1134 pr("You no longer own %s\n",
1135 xyas(osect.sct_x, osect.sct_y, player->cnum));
1137 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
1138 /* Always a 10% chance of getting caught. */
1139 if (chance(LND_SPY_DETECT_CHANCE(llp->land.lnd_effic))) {
1140 if (rel == NEUTRAL || rel == FRIENDLY) {
1142 "%s unit spotted in %s\n", cname(player->cnum),
1143 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1144 setrel(sect.sct_own, llp->land.lnd_own, HOSTILE);
1145 } else if (rel == HOSTILE || rel == AT_WAR ||
1146 rel == SITZKRIEG || rel == MOBILIZATION) {
1148 "%s spy shot in %s\n", cname(player->cnum),
1149 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1150 pr("%s was shot and killed.\n", prland(&llp->land));
1151 llp->land.lnd_effic = 0;
1152 putland(llp->land.lnd_uid, &llp->land);
1160 lnd_sweep(list, 0, 1, actor);
1161 stopping |= lnd_check_mines(list);
1165 /* interdict land units sector by sector */
1168 while (!QEMPTY(list)) {
1169 llp = (struct llist *)list->q_back;
1170 newx = llp->land.lnd_x;
1171 newy = llp->land.lnd_y;
1172 /* move units in NEWX,NEWY to cur */
1174 for (qp = list->q_back; qp != list; qp = next) {
1176 llp = (struct llist *)qp;
1177 if (llp->land.lnd_x == newx && llp->land.lnd_y == newy) {
1179 emp_insque(qp, &cur);
1180 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY))
1184 /* interdict them */
1186 stopping |= lnd_interdict(&cur, newx, newy, actor);
1187 /* move survivors to done */
1188 for (qp = cur.q_back; qp != &cur; qp = next) {
1190 llp = (struct llist *)qp;
1192 emp_insque(qp, &done);
1195 /* assign surviving land units back to list */
1196 emp_insque(list, &done);
1203 * find all artillery units belonging
1204 * to the attacker or defender that can fire.
1205 * Each arty unit adds +1%/damage point
1209 lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
1211 struct nstr_item ni;
1220 snxtitem_all(&ni, EF_LAND);
1221 while (nxtitem(&ni, &land)) {
1222 if (land.lnd_frg == 0)
1224 if ((land.lnd_x == x) && (land.lnd_y == y))
1226 if (land.lnd_ship >= 0)
1228 if (land.lnd_land >= 0)
1230 if (land.lnd_mission > 0)
1232 if (land.lnd_effic < LAND_MINFIREEFF)
1234 /* Do we have mil? */
1235 if (land.lnd_item[I_MILIT] <= 0)
1237 rel = getrel(getnatp(land.lnd_own), attacker);
1238 rel2 = getrel(getnatp(land.lnd_own), victim);
1239 if ((land.lnd_own != attacker) &&
1240 ((rel != ALLIED) || (rel2 != AT_WAR)))
1243 /* do we have supplies? */
1244 if (!has_supply(&land))
1247 /* are we in range? */
1248 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1250 range = roundrange(effrange(land.lnd_frg, land.lnd_tech));
1254 shell = land.lnd_item[I_SHELL];
1255 gun = land.lnd_item[I_GUN];
1257 if (shell == 0 || gun == 0)
1262 nreport(land.lnd_own, N_FIRE_BACK, victim, 1);
1264 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1265 if (roll(100) < land.lnd_acc) {
1266 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1267 land.lnd_ammo, shell) / 2;
1269 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1270 land.lnd_ammo, shell);
1272 if (land.lnd_own != attacker)
1274 "%s supported %s at %s\n",
1275 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1281 lnd_path(int together, struct lndstr *lp, char *buf)
1285 struct sctstr d_sect, sect;
1289 if (!sarg_xy(buf, &destx, &desty))
1292 pr("Cannot go to a destination sector if not all starting in the same sector\n");
1295 if (!getsect(destx, desty, &d_sect)) {
1296 pr("%d,%d is not a sector\n", destx, desty);
1299 getsect(lp->lnd_x, lp->lnd_y, §);
1300 if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
1301 cp = BestLandPath(buf, §, &d_sect, &dummy, MOB_RAIL);
1303 cp = BestLandPath(buf, §, &d_sect, &dummy, MOB_ROAD);
1305 pr("No owned path from %s to %s!\n",
1306 xyas(lp->lnd_x, lp->lnd_y, player->cnum),
1307 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1310 pr("Using path '%s'\n", cp);
1315 lnd_can_attack(struct lndstr *lp)
1317 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1319 if (lcp->l_flags & L_SUPPLY)
1326 * Increase fortification value of LP.
1327 * Fortification costs mobility. Use up to HARD_AMT mobility.
1328 * Return actual fortification increase.
1331 lnd_fortify (struct lndstr *lp, int hard_amt)
1336 if ((lp->lnd_ship >= 0) || lp->lnd_land >= 0)
1339 hard_amt = MIN(lp->lnd_mobil, hard_amt);
1341 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1342 hard_amt = land_mob_max - lp->lnd_harden;
1344 eng = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own);
1349 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1350 hard_amt = land_mob_max - lp->lnd_harden;
1352 /* Ok, set the mobility used */
1353 mob_used = hard_amt;
1355 /* Now, if an engineer helped, it's really only 2/3rds of
1360 /* If we increased it, but not much, we gotta take at least 1
1362 if (mob_used <= 0 && hard_amt > 0)
1365 lp->lnd_mobil -= mob_used;
1366 if (lp->lnd_mobil < 0)
1369 lp->lnd_harden += hard_amt;
1370 lp->lnd_harden = MIN(lp->lnd_harden, land_mob_max);
1376 * Set LP's tech to TLEV along with everything else that depends on it.
1379 lnd_set_tech(struct lndstr *lp, int tlev)
1381 struct lchrstr *lcp = lchr + lp->lnd_type;
1382 int tech_diff = tlev - lcp->l_tech;
1384 if (CANT_HAPPEN(tech_diff < 0)) {
1389 lp->lnd_tech = tlev;
1390 lp->lnd_att = (float)LND_ATTDEF(lcp->l_att, tech_diff);
1391 lp->lnd_def = (float)LND_ATTDEF(lcp->l_def, tech_diff);
1392 lp->lnd_vul = (int)LND_VUL(lcp->l_vul, tech_diff);
1393 lp->lnd_spd = (int)LND_SPD(lcp->l_spd, tech_diff);
1394 lp->lnd_vis = (int)LND_VIS(lcp->l_vis, tech_diff);
1395 lp->lnd_spy = (int)LND_SPY(lcp->l_spy, tech_diff);
1396 lp->lnd_rad = (int)LND_RAD(lcp->l_rad, tech_diff);
1397 lp->lnd_frg = (int)LND_FRG(lcp->l_frg, tech_diff);
1398 lp->lnd_acc = (int)LND_ACC(lcp->l_acc, tech_diff);
1399 lp->lnd_dam = (int)LND_DAM(lcp->l_dam, tech_diff);
1400 lp->lnd_ammo = (int)LND_AMM(lcp->l_ammo, lcp->l_dam, tech_diff);
1401 lp->lnd_aaf = (int)LND_AAF(lcp->l_aaf, tech_diff);
1402 lp->lnd_fuelc = (int)LND_FC(lcp->l_fuelc, tech_diff);
1403 lp->lnd_fuelu = (int)LND_FU(lcp->l_fuelu, tech_diff);
1404 lp->lnd_maxlight = (int)LND_XPL(lcp->l_nxlight, tech_diff);
1405 lp->lnd_maxland = (int)LND_MXL(lcp->l_nland, tech_diff);