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);
102 defense_val(struct lndstr *lp)
104 extern int land_mob_max;
109 if (((int)lp->lnd_effic) < LAND_MINEFF){
110 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
112 putland(lp->lnd_uid,lp);
116 lcp = &lchr[(int)lp->lnd_type];
122 if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) &&
123 !(lcp->l_flags & L_MARINE))
126 value = men * lp->lnd_def;
128 value *= ((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))
140 total_mil(struct lndstr *lp)
145 lcp = &lchr[(int)lp->lnd_type];
147 men = lnd_getmil(lp);
148 /* men *= ((double)lp->lnd_effic)/100.0;*/
150 return ldround(men,1);
154 lnd_print(struct llist *llp, s_char *s)
156 if (llp->land.lnd_own == player->cnum)
157 pr("%s %s\n",prland(&llp->land), s);
159 wu(0, llp->land.lnd_own,
160 "%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);
173 lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
174 /* 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;
203 eff_eq = ldround((((double)cas*100.0) / (double)llp->lcp->l_mil),1);
204 llp->land.lnd_effic -= eff_eq;
205 lnd_submil(&(llp->land), cas);
208 if (llp->land.lnd_effic < LAND_MINEFF) {
209 sprintf(buf, "dies %s %s!",
210 combat_mode?att_mode[combat_mode]:(s_char*) "defending",
211 xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
212 lnd_delete(llp, buf);
213 /* Since we killed the unit, we killed all the mil on it */
216 /* Ok, now, how many did we take off? (sould be the diff) */
217 taken = taken - lnd_getmil(&(llp->land));
220 if (llp->land.lnd_effic >= llp->land.lnd_retreat)
223 /* we're being boarded */
224 if (llp->land.lnd_ship >= 0 && combat_mode == A_DEFEND)
227 /* we're being boarded */
228 if (llp->land.lnd_land >= 0 && combat_mode == A_DEFEND)
231 /* Have to make a retreat check */
233 ret_chance = llp->land.lnd_retreat - llp->land.lnd_effic;
234 if (roll(100) < ret_chance) {
236 lnd_print(llp, "fails morale check!");
237 llp->land.lnd_mission = 0;
238 llp->land.lnd_harden = 0;
239 if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0)
241 else if (combat_mode == A_DEFEND) {
243 * defending unit.. find a place to send it
244 * strategy: look for the most-populated
245 * adjacent sector that is owned by the unit
246 * player->owner. Charge mob..
250 for(n = 1; n <= 6; ++n) {
251 ret_x = llp->land.lnd_x + diroff[n][0];
252 ret_y = llp->land.lnd_y + diroff[n][1];
253 getsect(ret_x, ret_y, §);
254 if (sect.sct_own != llp->land.lnd_own)
256 if (sect.sct_type == SCT_MOUNT)
259 civs = getvar(V_CIVIL, (s_char *)§, EF_SECTOR);
269 /* retreat to bx,by */
270 llp->land.lnd_x = bx;
271 llp->land.lnd_y = by;
272 getsect(bx,by,&rsect);
273 mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD);
274 mob = llp->land.lnd_mobil-(int)mobcost;
277 orig = llp->land.lnd_mobil;
278 llp->land.lnd_mobil = (s_char)mob;
279 if (llp->land.lnd_mobil > orig)
280 llp->land.lnd_mobil = (-127);
281 sprintf(buf, "retreats at %d%% efficiency to %s!",
283 xyas(bx,by,llp->land.lnd_own));
284 lnd_delete(llp, buf);
286 } else { /* attacking from a sector */
287 sprintf(buf, "leaves the battlefield at %d%% efficiency",
288 llp->land.lnd_effic);
289 if ((llp->land.lnd_mobil - (int)llp->mobil) < -127)
290 llp->land.lnd_mobil = -127;
292 llp->land.lnd_mobil -= (int)llp->mobil;
294 lnd_delete(llp, buf);
298 /* nowhere to go.. take more casualties */
299 llp->land.lnd_effic -= 10;
300 lnd_submil(&llp->land, llp->lcp->l_mil / 10);
301 if (llp->land.lnd_effic < LAND_MINEFF)
302 lnd_delete(llp, "has nowhere to retreat, and dies!");
304 lnd_print(llp, "has nowhere to retreat and takes extra losses!");
311 lnd_takemob(struct emp_qelem *list, double loss)
313 extern double combat_mob;
314 struct emp_qelem *qp, *next;
317 int mcost = ldround(combat_mob * loss, 1);
319 for (qp = list->q_forw; qp != list; qp = next) {
321 llp = (struct llist *)qp;
324 use_supply(&llp->land);
325 if (llp->land.lnd_mission == MI_RESERVE)
326 new = llp->land.lnd_mobil - mcost/2;
329 new = llp->land.lnd_mobil - mcost;
332 llp->land.lnd_mobil = (s_char)new;
336 lnd_getmil(struct lndstr *lp)
340 getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
345 lnd_submil(struct lndstr *lp, int num)
349 getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
351 if (vec[I_MILIT] < 0)
353 putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
356 lnd_spyval(struct lndstr *lp)
358 if (lchr[(int)lp->lnd_type].l_flags & L_RECON)
359 return (lp->lnd_spy * (lp->lnd_effic/100.0))+2;
361 return (lp->lnd_spy * (lp->lnd_effic/100.0));
365 intelligence_report(int destination, struct lndstr *lp, int spy, s_char *mess)
368 s_char buf1[80],buf2[80],buf3[80];
369 double estimate = 0.0; /* estimated defense value */
371 if (destination == 0)
374 if (lp->lnd_own == 0)
377 lcp = &lchr[(int)lp->lnd_type];
382 if (chance((double)(spy+lp->lnd_vis)/10.0)){
383 if (destination == player->cnum)
384 pr("%s %s", mess, prland(lp));
386 sprintf(buf1,"%s %s", mess, prland(lp));
388 estimate = lnd_getmil(lp);
390 if (chance((double)(spy+lp->lnd_vis)/20.0)){
392 if (destination == player->cnum)
393 pr(" (eff %d, mil %d", roundintby(lp->lnd_effic,5), roundintby(lnd_getmil(lp),10));
395 sprintf(buf2," (eff %d, mil %d", roundintby(lp->lnd_effic,5), roundintby(lnd_getmil(lp),10));
396 estimate = lnd_getmil(lp) * lp->lnd_effic / 100.0;
398 if (chance((double)(spy+lp->lnd_vis)/20.0)){
400 t = lp->lnd_tech - 20 + roll(40);
402 if (destination == player->cnum)
403 pr(", tech %d)\n",t);
405 sprintf(buf3,", tech %d)\n",t);
407 if (destination == player->cnum)
413 if (destination == player->cnum)
420 if (destination != player->cnum){
421 wu(0, destination, "%s%s%s",buf1,buf2,buf3);
424 if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
425 estimate *= lp->lnd_def;
427 return (int)estimate;
430 /* Used by the spy command to count land units in a sector. If used
431 for anything else, you may want to reconsider, because this doesn't
432 always count spies. :) */
434 count_sect_units(struct sctstr *sp)
441 snxtitem_all(&ni, EF_LAND);
442 while (nxtitem(&ni, (s_char *)&land)) {
445 if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y)
447 /* Don't always see spies */
448 if (lchr[(int)land.lnd_type].l_flags & L_SPY) {
449 odds = (double)(100 - land.lnd_effic) + 0.10;
453 /* Got here, report it */
461 count_units(struct shpstr *sp)
467 if (sp->shp_effic < SHIP_MINEFF)
470 snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y);
471 while (nxtitem(&ni, (s_char *)&land)){
472 if (land.lnd_own == 0)
474 if (land.lnd_ship == sp->shp_uid)
478 if (sp->shp_nland != nland) {
479 sp->shp_nland = nland;
480 putship(sp->shp_uid,sp);
485 lnd_count_units(struct lndstr *lp)
491 if (lp->lnd_effic < LAND_MINEFF)
494 snxtitem_xy(&ni, EF_LAND, lp->lnd_x, lp->lnd_y);
495 while (nxtitem(&ni, (s_char *)&land)){
496 if (land.lnd_own == 0)
498 if (land.lnd_land == lp->lnd_uid)
502 if (lp->lnd_nland != nland) {
503 lp->lnd_nland = nland;
504 putland(lp->lnd_uid,lp);
509 lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
521 while (nxtitem(ni, (s_char *)&land)) {
525 if (ontradingblock(EF_LAND, (int *)&land)) {
526 pr("unit #%d inelligible - it's for sale.\n", land.lnd_uid);
530 lcp = &lchr[(int)land.lnd_type];
531 /* if (wantflags && (lcp->m_flags & wantflags) != wantflags)
533 if (nowantflags && lcp->m_flags & nowantflags)
536 /* This abuse is better fixed by building a unit with the normal negative
537 mobility that everything else is built with */
538 /* Just so that the player can't build a bunch of land units, and them
539 march them a few minutes later... */
541 if (opt_MOB_ACCESS) {
542 if (land.lnd_effic < 11 &&
543 land.lnd_mobil < etu_per_update) {
544 pr("Land unit #%d needs at least %d mob to march.\n",
545 land.lnd_uid, etu_per_update);
550 land.lnd_mission = 0;
553 bzero(land.lnd_rpath,RET_LEN);
554 putland(land.lnd_uid, &land);
555 llp = (struct llist *) malloc(sizeof(struct llist));
557 bcopy((s_char *)&land, (s_char *)&llp->land,
558 sizeof(struct lndstr));
559 llp->mobil = (double)land.lnd_mobil;
560 emp_insque(&llp->queue, list);
564 /* This function assumes that the list was created by lnd_sel */
566 lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp, int *togetherp, natid actor)
568 struct emp_qelem *qp;
569 struct emp_qelem *next;
582 for (qp = list->q_back; qp != list; qp = next) {
584 llp = (struct llist *) qp;
585 getland(llp->land.lnd_uid, &land);
586 if (land.lnd_own != actor) {
587 mpr(actor, "%s was disbanded at %s\n",
589 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
590 emp_remque((struct emp_qelem *)llp);
594 if (land.lnd_ship >= 0) {
595 lnd_mess("is on a ship", llp);
598 if (land.lnd_land >= 0) {
599 lnd_mess("is on a unit", llp);
602 if (!getsect(land.lnd_x, land.lnd_y, §)) {
603 lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */
606 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
607 !(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) &&
608 lnd_getmil(&llp->land) == 0) {
609 lnd_mess("has no mil on it to guide it", llp);
612 rel = getrel(getnatp(sect.sct_own), player->cnum);
613 if (sect.sct_own != land.lnd_own && rel != ALLIED &&
614 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
616 sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own));
625 if (land.lnd_x != allx ||
628 if (land.lnd_mobil + 1 < (int)llp->mobil) {
629 llp->mobil = (double)land.lnd_mobil;
631 if (llp->mobil < *minmobp)
632 *minmobp = llp->mobil;
633 if (llp->mobil > *maxmobp)
634 *maxmobp = llp->mobil;
635 bcopy((s_char *)&land, (s_char *)&llp->land,
636 sizeof(struct lndstr));
641 lnd_put(struct emp_qelem *list, natid actor)
643 register struct emp_qelem *qp;
644 register struct emp_qelem *newqp;
649 llp = (struct llist *) qp;
651 mpr(actor, "%s stopped at %s\n", prland(&llp->land),
652 xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
653 if (llp->mobil < -127)
655 llp->land.lnd_mobil = llp->mobil;
657 putland(llp->land.lnd_uid, &llp->land);
666 lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob, natid actor)
668 struct emp_qelem *qp;
669 struct emp_qelem *next;
672 int mines, m, max, sshells, lshells;
675 for (qp=land_list->q_back;qp!=land_list;qp=next) {
677 llp = (struct llist *) qp;
678 if (!(llp->lcp->l_flags & L_ENGINEER)) {
680 mpr(actor, "%s is not an engineer!\n",
684 if (takemob && llp->mobil < 0.0) {
686 lnd_mess("is out of mobility", llp);
689 getsect(llp->land.lnd_x,llp->land.lnd_y,§);
690 if (sect.sct_oldown == llp->land.lnd_own) {
692 mpr(actor, "%s is in a sector completely owned by you. Don't bother digging up mines there!\n",
696 if (sect.sct_type == SCT_BSPAN) {
698 mpr(actor, "%s is on a bridge. No mines there!\n", prland(&llp->land));
702 /* mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/
703 mobcost = llp->land.lnd_spd;
704 mobcost = 480.0 / (mobcost +
705 techfact(llp->land.lnd_tech,mobcost));
706 llp->mobil -= mobcost;
707 llp->land.lnd_mobil = (int)llp->mobil;
709 putland(llp->land.lnd_uid, &llp->land);
710 if (!(mines=getvar(V_MINE,(s_char *)§,EF_SECTOR)))
712 max = vl_find(V_SHELL, llp->lcp->l_vtype,
713 llp->lcp->l_vamt, (int)llp->lcp->l_nv);
714 lshells = getvar(V_SHELL, (s_char *)&llp->land, EF_LAND);
715 sshells = getvar(V_SHELL, (s_char *)§, EF_SECTOR);
716 for (m=0; mines > 0 && m < max * 2; m++) {
717 if (chance(0.5 * llp->lcp->l_att)) {
718 mpr(actor, "Sweep...\n");
726 putvar(V_MINE, mines, (s_char *)§, EF_SECTOR);
727 putvar(V_SHELL, lshells, (s_char *)&llp->land, EF_LAND);
728 putvar(V_SHELL, sshells, (s_char *)§, EF_SECTOR);
729 putland(llp->land.lnd_uid, &llp->land);
735 contains_engineer(struct emp_qelem *list)
737 struct emp_qelem *qp;
738 struct emp_qelem *next;
741 for (qp=list->q_back;qp!=list;qp=next) {
743 llp = (struct llist *) qp;
744 if (llp->lcp->l_flags & L_ENGINEER)
751 lnd_check_mines(struct emp_qelem *land_list)
753 struct emp_qelem *qp;
754 struct emp_qelem *next;
759 int has_engineers = contains_engineer(land_list);
761 for (qp=land_list->q_back;qp!=land_list;qp=next) {
763 llp = (struct llist *) qp;
764 getsect(llp->land.lnd_x,llp->land.lnd_y,§);
765 if (sect.sct_oldown == llp->land.lnd_own)
767 if (sect.sct_type == SCT_BSPAN)
769 if (!(mines=getvar(V_MINE,(s_char *)§,EF_SECTOR)))
771 if (chance(DMINE_LHITCHANCE(mines)/(1 + 2*has_engineers))) {
772 lnd_hit_mine(&llp->land, llp->lcp);
774 putvar(V_MINE,mines,(s_char *)§,EF_SECTOR);
776 putland(llp->land.lnd_uid, (s_char *)&llp->land);
777 if (!llp->land.lnd_own) {
788 lnd_list(struct emp_qelem *land_list)
790 struct emp_qelem *qp;
791 struct emp_qelem *next;
796 pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n");
798 for (qp=land_list->q_back;qp!=land_list;qp=next) {
800 llp = (struct llist *) qp;
802 pr("%4d ", lnd->lnd_uid);
803 pr("%-16.16s ", llp->lcp->l_name);
804 prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
805 pr("%1c", lnd->lnd_army);
806 pr("%4d%%", lnd->lnd_effic);
807 getvec(VT_ITEM, vec, (s_char *)lnd, EF_LAND);
808 pr("%4d", vec[I_SHELL]);
809 pr("%4d", vec[I_GUN]);
810 count_land_planes(lnd);
811 pr("%3d",lnd->lnd_nxlight);
812 pr("%4d", lnd->lnd_mobil);
813 pr("%4d", lnd->lnd_tech);
814 pr("%4d%%", lnd->lnd_retreat);
815 pr("%5d\n", lnd->lnd_fuel);
820 lnd_mess(s_char *str, struct llist *llp)
822 mpr(llp->land.lnd_own, "%s %s & stays in %s\n",
824 str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own));
825 if (llp->mobil < -127)
827 llp->land.lnd_mobil = llp->mobil;
828 putland(llp->land.lnd_uid, &llp->land);
829 emp_remque((struct emp_qelem *)llp);
834 lnd_count(struct emp_qelem *list)
836 struct emp_qelem *qp;
837 struct emp_qelem *next;
841 for (qp = list->q_back; qp != list; qp = next) {
843 llp = (struct llist *) qp;
850 lnd_damage(struct emp_qelem *list, int totdam)
852 struct emp_qelem *qp;
853 struct emp_qelem *next;
858 if (!totdam || !(count = lnd_count(list)))
860 dam = ldround(((double)totdam/(double)count),1);
861 for (qp = list->q_back; qp != list; qp = next) {
863 llp = (struct llist *) qp;
864 /* have to get it again because of collateral damage */
865 getland(llp->land.lnd_uid, &llp->land);
866 landdamage(&llp->land, dam);
867 putland(llp->land.lnd_uid, &llp->land);
868 if (!llp->land.lnd_own) {
876 static int lnd_easiest_target(struct emp_qelem *list)
878 struct emp_qelem *qp;
879 struct emp_qelem *next;
882 int easiest = 9876; /* things start great for victim */
885 for (qp = list->q_back; qp != list; qp = next) {
887 llp = (struct llist *) qp;
888 hard = lnd_hardtarget(&llp->land);
890 easiest = hard; /* things get worse for victim */
893 return easiest - count;
897 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy, natid victim)
900 struct emp_qelem msl_list, *qp, *newqp;
902 msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
904 dam = msl_launch_mindam(&msl_list, newx, newy,
905 lnd_easiest_target(list), EF_LAND,
906 lnd_count(list) * 20, "troops", victim,
909 mpr(victim, "missile interdiction mission does %d damage!\n", dam);
910 collateral_damage(newx, newy, dam, 0);
912 qp = msl_list.q_forw;
913 while(qp != msl_list.q_forw) {
923 /* Steve M. - commented out for now until abuse is decided upon */
924 /* risner: allow forts to interdict land units. */
926 lnd_fort_interdiction(struct emp_qelem *list,
927 coord newx, coord newy, natid victim)
929 extern int fort_max_interdiction_range;
933 double range, range2, guneff;
939 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
940 while (nxtsct(&ns,&fsect)) {
941 if (fsect.sct_own == 0)
943 if (fsect.sct_own == victim)
945 if (fsect.sct_type != SCT_FORTR)
947 if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
949 gun = getvar(V_GUN,(s_char *)&fsect,EF_SECTOR);
952 range = tfactfire(fsect.sct_own,(double)min(gun,7));
953 if (fsect.sct_effic > 59)
955 range2 = roundrange(range);
956 trange = mapdist(newx, newy,
957 fsect.sct_x, fsect.sct_y);
960 if (getvar(V_MILIT,(s_char *)&fsect,EF_SECTOR)<5)
962 shell = getvar(V_SHELL,(s_char *)&fsect,EF_SECTOR);
964 shell += supply_commod(fsect.sct_own,
965 fsect.sct_x,fsect.sct_y,I_SHELL,
970 putvar(V_SHELL, shell, (s_char *)&fsect, EF_SECTOR);
974 guneff = landgun((int)fsect.sct_effic, gun);
977 mpr(victim, "Incoming fire does %d damage!\n", dam);
979 "%s fires at %s land units in %s for %d!\n",
980 xyas(fsect.sct_x,fsect.sct_y,
983 xyas(newx,newy,fsect.sct_own), dam);
984 nreport(fsect.sct_own, N_SCT_SHELL, victim, 1);
987 return lnd_damage(list, totdam);
993 lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
998 if (!opt_NO_FORT_FIRE)
999 /* Steve M. - commented out for now until abuse is decided upon */
1000 stopping |= lnd_fort_interdiction(list, newx, newy, victim);
1003 stopping |= lnd_damage(list, unit_interdict(newx,newy,victim,"land units", lnd_easiest_target(list), MI_INTERDICT));
1005 stopping |= lnd_damage(list, lnd_missile_interdiction(list,newx,newy,victim));
1009 /* high value of hardtarget is harder to hit */
1011 lnd_hardtarget(struct lndstr *lp)
1015 getsect(lp->lnd_x, lp->lnd_y, §);
1016 return (int)(((double)lp->lnd_effic/100.0) *
1017 (10 + dchr[sect.sct_type].d_dstr * 2 +
1018 (double)lp->lnd_spd/2.0 - lp->lnd_vis));
1022 lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
1026 mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ",
1027 xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1029 nreport(lp->lnd_own, N_LHIT_MINE, 0, 1);
1032 if (lcp->l_flags & L_ENGINEER)
1035 landdamage(lp, ldround(m,1));
1041 lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
1046 /* supply unit's speed depends on their eff, since
1047 that is their purpose */
1048 if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
1049 mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd;
1051 mobcost = lp->lnd_spd;
1055 /* sector_mcost now takes 2 different arguments, a sector pointer, and
1056 whether or not to figure in the highway bonus, rail bonus or none.
1057 bridge heads, bridges and highways have built-in highways bonus
1058 because they are a 1, and this will discount that. */
1060 smobcost = (double)sector_mcost(sp, mobtype);
1061 if (smobcost < 0.01)
1064 /* marching through 0 mobility conquered sectors takes lots of mobility,
1065 unless you are a train. Capturing railways is a good thing. */
1067 if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 &&
1068 smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL)
1069 smobcost = LND_MINMOBCOST;
1071 mobcost = smobcost * 5.0 * 480.0 /
1072 (mobcost + techfact(lp->lnd_tech, mobcost));
1078 lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor, int together)
1080 struct sctstr sect, osect;
1081 struct emp_qelem *qp;
1082 struct emp_qelem *qp2;
1083 struct emp_qelem *next;
1097 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
1098 lnd_put(list, actor);
1101 dx = diroff[dir][0];
1102 dy = diroff[dir][1];
1103 for (qp=list->q_back;qp!=list;qp=next) {
1105 llp = (struct llist *)qp;
1106 getsect(llp->land.lnd_x, llp->land.lnd_y, &osect);
1107 oldown = osect.sct_own;
1108 newx = xnorm(llp->land.lnd_x + dx);
1109 newy = ynorm(llp->land.lnd_y + dy);
1110 getsect(newx, newy, §);
1111 rel = getrel(getnatp(sect.sct_own), player->cnum);
1112 if ((sect.sct_own != actor && rel != ALLIED &&
1113 !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
1114 sect.sct_own) || (sect.sct_type == SCT_WATER ||
1115 sect.sct_type == SCT_SANCT ||
1116 sect.sct_type == SCT_WASTE)) {
1118 pr("can't go to %s\n",xyas(newx, newy, actor));
1121 sprintf(dp, "can't go to %s",
1122 xyas(newx, newy, actor));
1128 if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY)) visible = 1;
1129 if (sect.sct_rail == 0 &&
1130 lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1132 pr("no rail system in %s\n",xyas(newx, newy, actor));
1135 sprintf(dp, "has no rail system in %s",
1136 xyas(newx, newy, actor));
1141 /* Note we check would_abandon first because we don't want
1142 to always have to do these checks */
1143 if (would_abandon(&osect, V_CIVIL, 0, &(llp->land))) {
1145 if (!want_to_abandon(&osect, V_CIVIL, 0, &(llp->land))) {
1148 /* now check stuff */
1149 if (!check_sect_ok(§))
1151 if (!check_sect_ok(&osect))
1153 for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) {
1154 if (!check_land_ok(&(((struct llist *)qp2)->land)))
1158 lnd_mess("stops", llp);
1162 if (llp->mobil <= 0.0) {
1163 lnd_mess("is out of mobility", llp);
1166 llp->land.lnd_x = newx;
1167 llp->land.lnd_y = newy;
1168 if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
1169 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL);
1171 llp->mobil -= lnd_mobcost(&llp->land, §, MOB_ROAD);
1173 llp->land.lnd_mobil = (int)llp->mobil;
1174 putland(llp->land.lnd_uid, &llp->land);
1176 getsect(osect.sct_x, osect.sct_y, &osect);
1177 if (osect.sct_own != oldown && oldown == player->cnum) {
1178 /* It was your sector, now it's not. Simple :) */
1179 pr("You no longer own %s\n",
1180 xyas(osect.sct_x, osect.sct_y, player->cnum));
1182 if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */
1183 /* Always a 10% chance of getting caught. */
1184 odds = (100 - llp->land.lnd_effic) + .10;
1186 if (rel == NEUTRAL || rel == FRIENDLY) {
1188 "%s unit spotted in %s\n", cname(player->cnum),
1189 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1190 setrel(sect.sct_own, llp->land.lnd_own, HOSTILE);
1191 } else if (rel == HOSTILE || rel == AT_WAR ||
1192 rel == SITZKRIEG || rel == MOBILIZATION) {
1194 "%s spy shot in %s\n", cname(player->cnum),
1195 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
1196 pr("%s was shot and killed.\n", prland(&llp->land));
1197 llp->land.lnd_effic = 0;
1198 putland(llp->land.lnd_uid, &llp->land);
1206 lnd_sweep(list, 0, 1, actor);
1207 stopping |= lnd_check_mines(list);
1210 if (visible) stopping |= lnd_interdict(list, newx, newy, actor);
1215 * find all artillery units belonging
1216 * to the attacker or defender that can fire.
1217 * Each arty unit adds +1%/damage point
1221 lnd_support(natid victim, natid attacker, coord x, coord y)
1223 struct nstr_item ni;
1230 double range, range2;
1232 snxtitem_all(&ni,EF_LAND);
1233 while(nxtitem(&ni,(s_char *)&land)){
1234 if (land.lnd_frg == 0)
1236 if ((land.lnd_x == x) && (land.lnd_y == y))
1238 if (land.lnd_ship >= 0)
1240 if (land.lnd_land >= 0)
1242 if (land.lnd_mission > 0)
1244 if (land.lnd_effic < LAND_MINFIREEFF)
1246 /* Do we have mil? */
1247 if (getvar(V_MILIT, (s_char *)&land, EF_LAND) <= 0)
1249 rel = getrel(getnatp(land.lnd_own),attacker);
1250 rel2 = getrel(getnatp(land.lnd_own),victim);
1251 if ((land.lnd_own != attacker) &&
1252 ((rel != ALLIED) || (rel2 != AT_WAR)))
1255 /* do we have supplies? */
1256 if (!has_supply(&land))
1259 /* are we in range? */
1260 dist=mapdist(land.lnd_x,land.lnd_y,x,y);
1262 range=techfact((int)land.lnd_tech,
1263 (double)land.lnd_frg / 2.0);
1265 range2=roundrange(range);
1269 shell = getvar(V_SHELL, (s_char *)&land, EF_LAND);
1270 gun = getvar(V_GUN, (s_char *)&land, EF_LAND);
1272 if (shell == 0 || gun == 0)
1276 nreport(land.lnd_own,N_FIRE_L_ATTACK,victim,1);
1277 if (roll(100) < land.lnd_acc){
1278 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1279 land.lnd_ammo, shell) / 2;
1281 dam += landunitgun(land.lnd_effic, land.lnd_dam, gun,
1282 land.lnd_ammo, shell);
1284 if (land.lnd_own != attacker)
1286 "%s supported %s at %s\n",
1288 cname(attacker),xyas(x,y,land.lnd_own));
1294 lnd_path(int together, struct lndstr *lp, s_char *buf)
1298 struct sctstr d_sect, sect;
1302 if (!sarg_xy(buf, &destx, &desty))
1305 pr("Cannot go to a destination sector if not all starting in the same sector\n");
1308 if (!getsect(destx, desty, &d_sect)) {
1309 pr("%d,%d is not a sector\n", destx, desty);
1312 getsect(lp->lnd_x, lp->lnd_y, §);
1313 if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
1314 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_RAIL);
1316 cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_ROAD);
1318 pr("No owned path from %s to %s!\n",
1319 xyas(lp->lnd_x,lp->lnd_y,player->cnum),
1320 xyas(d_sect.sct_x,d_sect.sct_y,player->cnum));
1323 pr("Using path '%s'\n",cp);
1328 lnd_can_attack(struct lndstr *lp)
1330 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
1332 /* if (lcp->l_flags & L_SUPPLY ||
1333 lcp->l_flags & L_SECURITY ||
1334 lcp->l_flags & L_FLAK ||
1337 if (lcp->l_flags & L_SUPPLY)