2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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
52 #include "prototypes.h"
55 attack_val(int combat_mode, struct lndstr *lp)
61 if (((int)lp->lnd_effic) < LAND_MINEFF) {
62 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
64 putland(lp->lnd_uid, lp);
68 lcp = &lchr[(int)lp->lnd_type];
70 /* Spies always count as 1 during assaults. If they are the only ones
71 in the assault, they get to sneak on anyway. */
73 if (lcp->l_flags & L_SPY && combat_mode == A_ASSAULT)
78 value = ldround(((double)men * (double)lp->lnd_att), 1);
80 value = (int)((double)value * ((double)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 (((int)lp->lnd_effic) < LAND_MINEFF) {
105 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
107 putland(lp->lnd_uid, lp);
111 lcp = &lchr[(int)lp->lnd_type];
117 if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) &&
118 !(lcp->l_flags & L_MARINE))
121 value = men * lp->lnd_def;
124 ((double)land_mob_max + lp->lnd_harden) / (double)land_mob_max;
125 value = (int)((double)value * ((double)lp->lnd_effic / 100.0));
126 value = (int)ldround(value, 1);
128 /* If there are military on the unit, you get at least a 1
129 man defensive unit, except for spies */
130 if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
137 total_mil(struct lndstr *lp)
142 lcp = &lchr[(int)lp->lnd_type];
144 men = lnd_getmil(lp);
145 /* men *= ((double)lp->lnd_effic)/100.0;*/
147 return ldround(men, 1);
151 lnd_print(struct llist *llp, s_char *s)
153 if (llp->land.lnd_own == player->cnum)
154 pr("%s %s\n", prland(&llp->land), s);
156 wu(0, llp->land.lnd_own, "%s %s\n", prland(&llp->land), s);
160 lnd_delete(struct llist *llp, s_char *s)
164 putland(llp->land.lnd_uid, &llp->land);
165 emp_remque((struct emp_qelem *)llp);
170 lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
171 /* attacking or assaulting or paratrooping? */
172 /* number of casualties to take */
185 int nowhere_to_go = 0;
191 taken = lnd_getmil(&llp->land);
192 /* Spies always die */
193 if (llp->lcp->l_flags & L_SPY) {
195 llp->land.lnd_effic = 0;
198 ldround((((double)cas * 100.0) / (double)llp->lcp->l_mil), 1);
199 llp->land.lnd_effic -= eff_eq;
200 lnd_submil(&llp->land, cas);
203 if (llp->land.lnd_effic < LAND_MINEFF) {
204 sprintf(buf, "dies %s %s!",
205 combat_mode ? att_mode[combat_mode] : "defending",
206 xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
207 lnd_delete(llp, buf);
208 /* Since we killed the unit, we killed all the mil on it */
211 /* Ok, now, how many did we take off? (sould be the diff) */
212 taken = taken - lnd_getmil(&llp->land);
215 if (llp->land.lnd_effic >= llp->land.lnd_retreat)
218 /* we're being boarded */
219 if (llp->land.lnd_ship >= 0 && combat_mode == A_DEFEND)
222 /* we're being boarded */
223 if (llp->land.lnd_land >= 0 && combat_mode == A_DEFEND)
226 /* Have to make a retreat check */
228 ret_chance = llp->land.lnd_retreat - llp->land.lnd_effic;
229 if (roll(100) < ret_chance) {
231 lnd_print(llp, "fails morale check!");
232 llp->land.lnd_mission = 0;
233 llp->land.lnd_harden = 0;
234 if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0)
236 else if (combat_mode == A_DEFEND) {
238 * defending unit.. find a place to send it
239 * strategy: look for the most-populated
240 * adjacent sector that is owned by the unit
241 * player->owner. Charge mob..
245 for (n = 1; n <= 6; ++n) {
246 ret_x = llp->land.lnd_x + diroff[n][0];
247 ret_y = llp->land.lnd_y + diroff[n][1];
248 getsect(ret_x, ret_y, §);
249 if (sect.sct_own != llp->land.lnd_own)
251 if (sect.sct_type == SCT_MOUNT)
254 civs = sect.sct_item[I_CIVIL];
255 if (civs > biggest) {
264 /* retreat to bx,by */
265 llp->land.lnd_x = bx;
266 llp->land.lnd_y = by;
267 getsect(bx, by, &rsect);
268 mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD);
269 mob = llp->land.lnd_mobil - (int)mobcost;
272 orig = llp->land.lnd_mobil;
273 llp->land.lnd_mobil = (s_char)mob;
274 if (llp->land.lnd_mobil > orig)
275 llp->land.lnd_mobil = -127;
276 sprintf(buf, "retreats at %d%% efficiency to %s!",
278 xyas(bx, by, llp->land.lnd_own));
279 lnd_delete(llp, buf);
281 } else { /* attacking from a sector */
282 sprintf(buf, "leaves the battlefield at %d%% efficiency",
283 llp->land.lnd_effic);
284 if ((llp->land.lnd_mobil - (int)llp->mobil) < -127)
285 llp->land.lnd_mobil = -127;
287 llp->land.lnd_mobil -= (int)llp->mobil;
289 lnd_delete(llp, buf);
293 /* nowhere to go.. take more casualties */
294 llp->land.lnd_effic -= 10;
295 lnd_submil(&llp->land, llp->lcp->l_mil / 10);
296 if (llp->land.lnd_effic < LAND_MINEFF)
297 lnd_delete(llp, "has nowhere to retreat, and dies!");
300 "has nowhere to retreat and takes extra losses!");
307 lnd_takemob(struct emp_qelem *list, double loss)
309 struct emp_qelem *qp, *next;
312 int mcost = ldround(combat_mob * loss, 1);
314 for (qp = list->q_forw; qp != list; qp = next) {
316 llp = (struct llist *)qp;
319 use_supply(&llp->land);
320 if (llp->land.lnd_mission == MI_RESERVE)
321 new = llp->land.lnd_mobil - mcost/2;
324 new = llp->land.lnd_mobil - mcost;
327 llp->land.lnd_mobil = (s_char)new;
331 lnd_getmil(struct lndstr *lp)
333 return lp->lnd_item[I_MILIT];
337 lnd_submil(struct lndstr *lp, int num)
339 int new = lp->lnd_item[I_MILIT] - num;
340 lp->lnd_item[I_MILIT] = new < 0 ? 0 : new;
344 lnd_spyval(struct lndstr *lp)
346 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
347 return lp->lnd_spy * (lp->lnd_effic / 100.0) + 2;
349 return lp->lnd_spy * (lp->lnd_effic / 100.0);
353 intelligence_report(int destination, struct lndstr *lp, int spy,
357 s_char buf1[80], buf2[80], buf3[80];
358 double estimate = 0.0; /* estimated defense value */
360 if (destination == 0)
363 if (lp->lnd_own == 0)
366 lcp = &lchr[(int)lp->lnd_type];
368 memset(buf1, 0, sizeof(buf1));
369 memset(buf2, 0, sizeof(buf2));
370 memset(buf3, 0, sizeof(buf3));
371 if (chance((double)(spy + lp->lnd_vis) / 10.0)) {
372 if (destination == player->cnum)
373 pr("%s %s", mess, prland(lp));
375 sprintf(buf1, "%s %s", mess, prland(lp));
377 estimate = lnd_getmil(lp);
379 if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
381 if (destination == player->cnum)
382 pr(" (eff %d, mil %d", roundintby(lp->lnd_effic, 5),
383 roundintby(lnd_getmil(lp), 10));
385 sprintf(buf2, " (eff %d, mil %d",
386 roundintby(lp->lnd_effic, 5),
387 roundintby(lnd_getmil(lp), 10));
388 estimate = lnd_getmil(lp) * lp->lnd_effic / 100.0;
390 if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
392 t = lp->lnd_tech - 20 + roll(40);
394 if (destination == player->cnum)
395 pr(", tech %d)\n", t);
397 sprintf(buf3, ", tech %d)\n", t);
399 if (destination == player->cnum)
402 sprintf(buf3, ")\n");
405 if (destination == player->cnum)
412 if (destination != player->cnum) {
413 wu(0, destination, "%s%s%s", buf1, buf2, buf3);
416 if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
417 estimate *= lp->lnd_def;
419 return (int)estimate;
422 /* Used by the spy command to count land units in a sector. If used
423 for anything else, you may want to reconsider, because this doesn't
424 always count spies. :) */
426 count_sect_units(struct sctstr *sp)
432 snxtitem_all(&ni, EF_LAND);
433 while (nxtitem(&ni, &land)) {
436 if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y)
438 /* Don't always see spies */
439 if (lchr[(int)land.lnd_type].l_flags & L_SPY) {
440 if (!(chance(LND_SPY_DETECT_CHANCE(land.lnd_effic))))
443 /* Got here, report it */
451 count_units(struct shpstr *sp)
457 if (sp->shp_effic < SHIP_MINEFF)
460 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
461 while (nxtitem(&ni, &land)) {
462 if (land.lnd_own == 0)
464 if (land.lnd_ship == sp->shp_uid)
468 if (sp->shp_nland != nland) {
469 sp->shp_nland = nland;
470 putship(sp->shp_uid, sp);
475 lnd_count_units(struct lndstr *lp)
481 if (lp->lnd_effic < LAND_MINEFF)
484 snxtitem_xy(&ni, EF_LAND, lp->lnd_x, lp->lnd_y);
485 while (nxtitem(&ni, &land)) {
486 if (land.lnd_own == 0)
488 if (land.lnd_land == lp->lnd_uid)
492 if (lp->lnd_nland != nland) {
493 lp->lnd_nland = nland;
494 putland(lp->lnd_uid, lp);
499 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
511 while (nxtitem(ni, &land)) {
515 if (ontradingblock(EF_LAND, (int *)&land)) {
516 pr("unit #%d inelligible - it's for sale.\n",
521 lcp = &lchr[(int)land.lnd_type];
522 /* if (wantflags && (lcp->m_flags & wantflags) != wantflags)
524 if (nowantflags && lcp->m_flags & nowantflags)
527 /* This abuse is better fixed by building a unit with the normal negative
528 mobility that everything else is built with */
529 /* Just so that the player can't build a bunch of land units, and them
530 march them a few minutes later... */
532 if (opt_MOB_ACCESS) {
533 if (land.lnd_effic < 11 &&
534 land.lnd_mobil < etu_per_update) {
535 pr("Land unit #%d needs at least %d mob to march.\n",
536 land.lnd_uid, etu_per_update);
541 land.lnd_mission = 0;
544 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
545 putland(land.lnd_uid, &land);
546 llp = malloc(sizeof(struct llist));
549 llp->mobil = (double)land.lnd_mobil;
550 emp_insque(&llp->queue, list);
554 /* This function assumes that the list was created by lnd_sel */
556 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
557 int *togetherp, natid actor)
559 struct emp_qelem *qp;
560 struct emp_qelem *next;
573 for (qp = list->q_back; qp != list; qp = next) {
575 llp = (struct llist *)qp;
576 getland(llp->land.lnd_uid, &land);
577 if (land.lnd_own != actor) {
578 mpr(actor, "%s was disbanded at %s\n",
579 prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own));
580 emp_remque((struct emp_qelem *)llp);
584 if (land.lnd_ship >= 0) {
585 lnd_mess("is on a ship", llp);
588 if (land.lnd_land >= 0) {
589 lnd_mess("is on a unit", llp);
592 if (!getsect(land.lnd_x, land.lnd_y, §)) {
593 lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
596 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
597 !(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) &&
598 lnd_getmil(&llp->land) == 0) {
599 lnd_mess("has no mil on it to guide it", llp);
602 rel = getrel(getnatp(sect.sct_own), player->cnum);
603 if (sect.sct_own != land.lnd_own && rel != ALLIED &&
604 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
606 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
615 if (land.lnd_x != allx || land.lnd_y != ally)
617 if (land.lnd_mobil + 1 < (int)llp->mobil) {
618 llp->mobil = (double)land.lnd_mobil;
620 if (llp->mobil < *minmobp)
621 *minmobp = llp->mobil;
622 if (llp->mobil > *maxmobp)
623 *maxmobp = llp->mobil;
629 lnd_put(struct emp_qelem *list, natid actor)
631 struct emp_qelem *qp;
632 struct emp_qelem *newqp;
637 llp = (struct llist *)qp;
639 mpr(actor, "%s stopped at %s\n", prland(&llp->land),
640 xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
641 if (llp->mobil < -127)
643 llp->land.lnd_mobil = llp->mobil;
645 putland(llp->land.lnd_uid, &llp->land);
654 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
657 struct emp_qelem *qp;
658 struct emp_qelem *next;
661 int mines, m, max, sshells, lshells;
664 for (qp = land_list->q_back; qp != land_list; qp = next) {
666 llp = (struct llist *)qp;
667 if (!(llp->lcp->l_flags & L_ENGINEER)) {
669 mpr(actor, "%s is not an engineer!\n", prland(&llp->land));
672 if (takemob && llp->mobil < 0.0) {
674 lnd_mess("is out of mobility", llp);
677 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
678 if (sect.sct_oldown == llp->land.lnd_own) {
681 "%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
685 if (sect.sct_type == SCT_BSPAN) {
687 mpr(actor, "%s is on a bridge. No mines there!\n",
692 /* mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/
693 mobcost = llp->land.lnd_spd;
694 mobcost = 480.0 / (mobcost +
695 techfact(llp->land.lnd_tech, mobcost));
696 llp->mobil -= mobcost;
697 llp->land.lnd_mobil = (int)llp->mobil;
698 llp->land.lnd_harden = 0;
700 putland(llp->land.lnd_uid, &llp->land);
701 if (!(mines = sect.sct_mines))
703 max = llp->lcp->l_item[I_SHELL];
704 lshells = llp->land.lnd_item[I_SHELL];
705 sshells = sect.sct_item[I_SHELL];
706 for (m = 0; mines > 0 && m < max * 2; m++) {
707 if (chance(0.5 * llp->lcp->l_att)) {
708 mpr(actor, "Sweep...\n");
712 else if (sshells < ITEM_MAX)
716 sect.sct_mines = mines;
717 llp->land.lnd_item[I_SHELL] = lshells;
718 sect.sct_item[I_SHELL] = sshells;
719 putland(llp->land.lnd_uid, &llp->land);
725 contains_engineer(struct emp_qelem *list)
727 struct emp_qelem *qp;
728 struct emp_qelem *next;
731 for (qp = list->q_back; qp != list; qp = next) {
733 llp = (struct llist *)qp;
734 if (llp->lcp->l_flags & L_ENGINEER)
741 lnd_check_mines(struct emp_qelem *land_list)
743 struct emp_qelem *qp;
744 struct emp_qelem *next;
748 int with_eng = contains_engineer(land_list);
750 for (qp = land_list->q_back; qp != land_list; qp = next) {
752 llp = (struct llist *)qp;
753 getsect(llp->land.lnd_x, llp->land.lnd_y, §);
754 if (sect.sct_oldown == llp->land.lnd_own)
756 if (sect.sct_type == SCT_BSPAN)
760 if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
761 lnd_hit_mine(&llp->land, llp->lcp);
764 putland(llp->land.lnd_uid, &llp->land);
765 if (!llp->land.lnd_own) {
776 lnd_list(struct emp_qelem *land_list)
778 struct emp_qelem *qp;
779 struct emp_qelem *next;
783 pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
785 for (qp = land_list->q_back; qp != land_list; qp = next) {
787 llp = (struct llist *)qp;
789 pr("%4d ", lnd->lnd_uid);
790 pr("%-16.16s ", llp->lcp->l_name);
791 prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
792 pr("%1c", lnd->lnd_army);
793 pr("%4d%%", lnd->lnd_effic);
794 pr("%4d", lnd->lnd_item[I_SHELL]);
795 pr("%4d", lnd->lnd_item[I_GUN]);
796 count_land_planes(lnd);
797 pr("%3d", lnd->lnd_nxlight);
798 pr("%4d", lnd->lnd_mobil);
799 pr("%4d", lnd->lnd_tech);
800 pr("%4d%%", lnd->lnd_retreat);
801 pr("%5d\n", lnd->lnd_fuel);
806 lnd_mess(s_char *str, struct llist *llp)
808 mpr(llp->land.lnd_own, "%s %s & stays in %s\n",
810 str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
811 if (llp->mobil < -127)
813 llp->land.lnd_mobil = llp->mobil;
814 putland(llp->land.lnd_uid, &llp->land);
815 emp_remque((struct emp_qelem *)llp);
820 lnd_count(struct emp_qelem *list)
822 struct emp_qelem *qp;
823 struct emp_qelem *next;
827 for (qp = list->q_back; qp != list; qp = next) {
829 llp = (struct llist *)qp;
836 lnd_damage(struct emp_qelem *list, int totdam)
838 struct emp_qelem *qp;
839 struct emp_qelem *next;
844 if (!totdam || !(count = lnd_count(list)))
846 dam = ldround(((double)totdam / (double)count), 1);
847 for (qp = list->q_back; qp != list; qp = next) {
849 llp = (struct llist *)qp;
850 /* have to get it again because of collateral damage */
851 getland(llp->land.lnd_uid, &llp->land);
852 landdamage(&llp->land, dam);
853 putland(llp->land.lnd_uid, &llp->land);
854 if (!llp->land.lnd_own) {
863 lnd_easiest_target(struct emp_qelem *list)
865 struct emp_qelem *qp;
866 struct emp_qelem *next;
869 int easiest = 9876; /* things start great for victim */
872 for (qp = list->q_back; qp != list; qp = next) {
874 llp = (struct llist *)qp;
875 hard = lnd_hardtarget(&llp->land);
877 easiest = hard; /* things get worse for victim */
880 return easiest - count;
884 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
888 struct emp_qelem msl_list, *qp, *newqp;
890 msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
892 dam = msl_launch_mindam(&msl_list, newx, newy,
893 lnd_easiest_target(list), EF_LAND,
894 lnd_count(list) * 20, "troops", victim,
897 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
898 collateral_damage(newx, newy, dam, 0);
900 qp = msl_list.q_forw;
901 while (qp != msl_list.q_forw) {
911 /* Steve M. - commented out for now until abuse is decided upon */
912 /* risner: allow forts to interdict land units. */
914 lnd_fort_interdiction(struct emp_qelem *list,
915 coord newx, coord newy, natid victim)
920 double range, range2, guneff;
926 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
927 while (nxtsct(&ns, &fsect)) {
928 if (fsect.sct_own == 0)
930 if (fsect.sct_own == victim)
932 if (fsect.sct_type != SCT_FORTR)
934 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
936 gun = fsect.sct_item[I_GUN];
939 range = tfactfire(fsect.sct_own, (double)min(gun, 7));
940 if (fsect.sct_effic > 59)
942 range2 = roundrange(range);
943 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
946 if (fsect.sct_item[I_MILIT] < 5)
948 shell = fsect.sct_item[I_SHELL];
950 shell += supply_commod(fsect.sct_own,
951 fsect.sct_x, fsect.sct_y, I_SHELL, 1);
955 fsect.sct_item[I_SHELL] = shell;
959 guneff = landgun((int)fsect.sct_effic, gun);
962 mpr(victim, "Incoming fire does %d damage!\n", dam);
964 "%s fires at %s land units in %s for %d!\n",
965 xyas(fsect.sct_x, fsect.sct_y,
967 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
968 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
971 return lnd_damage(list, totdam);
977 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
982 if (!opt_NO_FORT_FIRE)
983 /* Steve M. - commented out for now until abuse is decided upon */
984 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
989 unit_interdict(newx, newy, victim, "land units",
990 lnd_easiest_target(list), MI_INTERDICT));
994 lnd_missile_interdiction(list, newx, newy, victim));
998 /* high value of hardtarget is harder to hit */
1000 lnd_hardtarget(struct lndstr *lp)
1004 getsect(lp->lnd_x, lp->lnd_y, §);
1005 return (int)(((double)lp->lnd_effic / 100.0) *
1006 (10 + dchr[sect.sct_type].d_dstr * 2 +
1007 (double)lp->lnd_spd / 2.0 - lp->lnd_vis));
1011 lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
1015 mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
1016 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1018 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
1021 if (lcp->l_flags & L_ENGINEER)
1024 landdamage(lp, ldround(m, 1));
1030 lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
1035 /* supply unit's speed depends on their eff, since
1036 that is their purpose */
1037 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
1038 mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd;
1040 mobcost = lp->lnd_spd;
1044 /* sector_mcost now takes 2 different arguments, a sector pointer, and
1045 whether or not to figure in the highway bonus, rail bonus or none.
1046 bridge heads, bridges and highways have built-in highways bonus
1047 because they are a 1, and this will discount that. */
1049 smobcost = (double)sector_mcost(sp, mobtype);
1050 if (smobcost < 0.01)
1053 /* marching through 0 mobility conquered sectors takes lots of mobility,
1054 unless you are a train. Capturing railways is a good thing. */
1056 if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 &&
1057 smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL)
1058 smobcost = LND_MINMOBCOST;
1060 mobcost = smobcost * 5.0 * 480.0 /
1061 (mobcost + techfact(lp->lnd_tech, mobcost));
1067 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
1070 struct sctstr sect, osect;
1071 struct emp_qelem *qp;
1072 struct emp_qelem *qp2;
1073 struct emp_qelem *next;
1075 struct emp_qelem cur, done;
1087 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
1088 lnd_put(list, actor);
1091 dx = diroff[dir][0];
1092 dy = diroff[dir][1];
1093 for (qp = list->q_back; qp != list; qp = next) {
1095 llp = (struct llist *)qp;
1096 getsect(llp->land.lnd_x, llp->land.lnd_y, &osect);
1097 oldown = osect.sct_own;
1098 newx = xnorm(llp->land.lnd_x + dx);
1099 newy = ynorm(llp->land.lnd_y + dy);
1100 getsect(newx, newy, §);
1101 rel = getrel(getnatp(sect.sct_own), player->cnum);
1102 if ((sect.sct_own != actor && rel != ALLIED &&
1103 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
1104 sect.sct_own) || (sect.sct_type == SCT_WATER ||
1105 sect.sct_type == SCT_SANCT ||
1106 sect.sct_type == SCT_WASTE)) {
1108 pr("can't go to %s\n", xyas(newx, newy, actor));
1111 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
1116 if (sect.sct_rail == 0 &&
1117 lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1119 pr("no rail system in %s\n", xyas(newx, newy, actor));
1122 sprintf(dp, "has no rail system in %s",
1123 xyas(newx, newy, actor));
1128 /* Note we check would_abandon first because we don't want
1129 to always have to do these checks */
1130 if (would_abandon(&osect, I_CIVIL, 0, &llp->land)) {
1132 if (!want_to_abandon(&osect, I_CIVIL, 0, &llp->land)) {
1135 /* now check stuff */
1136 if (!check_sect_ok(§))
1138 if (!check_sect_ok(&osect))
1140 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
1141 if (!check_land_ok(&((struct llist *)qp2)->land))
1145 lnd_mess("stops", llp);
1149 if (llp->mobil <= 0.0) {
1150 lnd_mess("is out of mobility", llp);
1153 llp->land.lnd_x = newx;
1154 llp->land.lnd_y = newy;
1155 if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1156 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL);
1158 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_ROAD);
1160 llp->land.lnd_mobil = (int)llp->mobil;
1161 llp->land.lnd_harden = 0;
1162 putland(llp->land.lnd_uid, &llp->land);
1164 getsect(osect.sct_x, osect.sct_y, &osect);
1165 if (osect.sct_own != oldown && oldown == player->cnum) {
1166 /* It was your sector, now it's not. Simple :) */
1167 pr("You no longer own %s\n",
1168 xyas(osect.sct_x, osect.sct_y, player->cnum));
1170 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
1171 /* Always a 10% chance of getting caught. */
1172 if (chance(LND_SPY_DETECT_CHANCE(llp->land.lnd_effic))) {
1173 if (rel == NEUTRAL || rel == FRIENDLY) {
1175 "%s unit spotted in %s\n", cname(player->cnum),
1176 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1177 setrel(sect.sct_own, llp->land.lnd_own, HOSTILE);
1178 } else if (rel == HOSTILE || rel == AT_WAR ||
1179 rel == SITZKRIEG || rel == MOBILIZATION) {
1181 "%s spy shot in %s\n", cname(player->cnum),
1182 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1183 pr("%s was shot and killed.\n", prland(&llp->land));
1184 llp->land.lnd_effic = 0;
1185 putland(llp->land.lnd_uid, &llp->land);
1193 lnd_sweep(list, 0, 1, actor);
1194 stopping |= lnd_check_mines(list);
1198 /* interdict land units sector by sector */
1201 while (!QEMPTY(list)) {
1202 llp = (struct llist *)list->q_back;
1203 newx = llp->land.lnd_x;
1204 newy = llp->land.lnd_y;
1205 /* move units in NEWX,NEWY to cur */
1207 for (qp = list->q_back; qp != list; qp = next) {
1209 llp = (struct llist *)qp;
1210 if (llp->land.lnd_x == newx && llp->land.lnd_y == newy) {
1212 emp_insque(qp, &cur);
1213 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY))
1217 /* interdict them */
1219 stopping |= lnd_interdict(&cur, newx, newy, actor);
1220 /* move survivors to done */
1221 for (qp = cur.q_back; qp != &cur; qp = next) {
1223 llp = (struct llist *)qp;
1225 emp_insque(qp, &done);
1228 /* assign surviving land units back to list */
1229 emp_insque(list, &done);
1236 * find all artillery units belonging
1237 * to the attacker or defender that can fire.
1238 * Each arty unit adds +1%/damage point
1242 lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
1244 struct nstr_item ni;
1251 double range, range2;
1253 snxtitem_all(&ni, EF_LAND);
1254 while (nxtitem(&ni, &land)) {
1255 if (land.lnd_frg == 0)
1257 if ((land.lnd_x == x) && (land.lnd_y == y))
1259 if (land.lnd_ship >= 0)
1261 if (land.lnd_land >= 0)
1263 if (land.lnd_mission > 0)
1265 if (land.lnd_effic < LAND_MINFIREEFF)
1267 /* Do we have mil? */
1268 if (land.lnd_item[I_MILIT] <= 0)
1270 rel = getrel(getnatp(land.lnd_own), attacker);
1271 rel2 = getrel(getnatp(land.lnd_own), victim);
1272 if ((land.lnd_own != attacker) &&
1273 ((rel != ALLIED) || (rel2 != AT_WAR)))
1276 /* do we have supplies? */
1277 if (!has_supply(&land))
1280 /* are we in range? */
1281 dist = mapdist(land.lnd_x, land.lnd_y, x, y);
1283 range = techfact((int)land.lnd_tech, (double)land.lnd_frg / 2.0);
1285 range2 = roundrange(range);
1289 shell = land.lnd_item[I_SHELL];
1290 gun = land.lnd_item[I_GUN];
1292 if (shell == 0 || gun == 0)
1297 nreport(land.lnd_own, N_FIRE_BACK, victim, 1);
1299 nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
1300 if (roll(100) < land.lnd_acc) {
1301 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1302 land.lnd_ammo, shell) / 2;
1304 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1305 land.lnd_ammo, shell);
1307 if (land.lnd_own != attacker)
1309 "%s supported %s at %s\n",
1310 prland(&land), cname(attacker), xyas(x, y, land.lnd_own));
1316 lnd_path(int together, struct lndstr *lp, s_char *buf)
1320 struct sctstr d_sect, sect;
1324 if (!sarg_xy(buf, &destx, &desty))
1327 pr("Cannot go to a destination sector if not all starting in the same sector\n");
1330 if (!getsect(destx, desty, &d_sect)) {
1331 pr("%d,%d is not a sector\n", destx, desty);
1334 getsect(lp->lnd_x, lp->lnd_y, §);
1335 if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
1336 cp = BestLandPath(buf, §, &d_sect, &dummy, MOB_RAIL);
1338 cp = BestLandPath(buf, §, &d_sect, &dummy, MOB_ROAD);
1340 pr("No owned path from %s to %s!\n",
1341 xyas(lp->lnd_x, lp->lnd_y, player->cnum),
1342 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1345 pr("Using path '%s'\n", cp);
1350 lnd_can_attack(struct lndstr *lp)
1352 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1354 /* if (lcp->l_flags & L_SUPPLY ||
1355 lcp->l_flags & L_SECURITY ||
1356 lcp->l_flags & L_FLAK ||
1359 if (lcp->l_flags & L_SUPPLY)
1366 * Increase fortification value of LP.
1367 * Fortification costs mobility. Use up to HARD_AMT mobility.
1368 * Return actual fortification increase.
1371 lnd_fortify (struct lndstr *lp, int hard_amt)
1376 if ((lp->lnd_ship >= 0) || lp->lnd_land >= 0)
1379 hard_amt = min(lp->lnd_mobil, hard_amt);
1381 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1382 hard_amt = land_mob_max - lp->lnd_harden;
1384 eng = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own);
1387 hard_amt = ((float)hard_amt * 1.5);
1389 if ((lp->lnd_harden + hard_amt) > land_mob_max)
1390 hard_amt = land_mob_max - lp->lnd_harden;
1392 /* Ok, set the mobility used */
1393 mob_used = hard_amt;
1395 /* Now, if an engineer helped, it's really only 2/3rds of
1398 mob_used = (int)((float)mob_used / 1.5);
1400 /* If we increased it, but not much, we gotta take at least 1
1402 if (mob_used <= 0 && hard_amt > 0)
1405 lp->lnd_mobil -= mob_used;
1406 if (lp->lnd_mobil < 0)
1409 lp->lnd_harden += hard_amt;
1410 lp->lnd_harden = min(lp->lnd_harden, land_mob_max);
1416 * Set LP's tech to TLEV along with everything else that depends on it.
1419 lnd_set_tech(struct lndstr *lp, int tlev)
1421 struct lchrstr *lcp = lchr + lp->lnd_type;
1422 int tech_diff = tlev - lcp->l_tech;
1424 if (CANT_HAPPEN(tech_diff < 0)) {
1429 lp->lnd_tech = tlev;
1430 lp->lnd_att = (float)LND_ATTDEF(lcp->l_att, tech_diff);
1431 lp->lnd_def = (float)LND_ATTDEF(lcp->l_def, tech_diff);
1432 lp->lnd_vul = (int)LND_VUL(lcp->l_vul, tech_diff);
1433 lp->lnd_spd = (int)LND_SPD(lcp->l_spd, tech_diff);
1434 lp->lnd_vis = (int)LND_VIS(lcp->l_vis, tech_diff);
1435 lp->lnd_spy = (int)LND_SPY(lcp->l_spy, tech_diff);
1436 lp->lnd_rad = (int)LND_RAD(lcp->l_rad, tech_diff);
1437 lp->lnd_frg = (int)LND_FRG(lcp->l_frg, tech_diff);
1438 lp->lnd_acc = (int)LND_ACC(lcp->l_acc, tech_diff);
1439 lp->lnd_dam = (int)LND_DAM(lcp->l_dam, tech_diff);
1440 lp->lnd_ammo = (int)LND_AMM(lcp->l_ammo, lcp->l_dam, tech_diff);
1441 lp->lnd_aaf = (int)LND_AAF(lcp->l_aaf, tech_diff);
1442 lp->lnd_fuelc = (int)LND_FC(lcp->l_fuelc, tech_diff);
1443 lp->lnd_fuelu = (int)LND_FU(lcp->l_fuelu, tech_diff);
1444 lp->lnd_maxlight = (int)LND_XPL(lcp->l_nxlight, tech_diff);
1445 lp->lnd_maxland = (int)LND_MXL(lcp->l_mxland, tech_diff);