2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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 * buil.c: Build ships, nukes, bridges, planes, land units, bridge towers
30 * Known contributors to this file:
31 * Steve McClure, 1998-2000
53 static int build_nuke(register struct sctstr *sp,
54 register struct nchrstr *np, short *vec);
55 static int build_ship(register struct sctstr *sp,
56 register struct mchrstr *mp, short *vec,
58 static int build_land(register struct sctstr *sp,
59 register struct lchrstr *lp, short *vec,
61 static int build_bridge(register struct sctstr *sp, short *vec);
62 static int build_tower(register struct sctstr *sp, short *vec);
63 static int build_plane(register struct sctstr *sp,
64 register struct plchrstr *pp, short *vec,
67 static int cash; /* static ok */
70 * build <WHAT> <SECTS> <TYPE|DIR|MEG> [NUMBER]
76 struct nstr_sect nstr;
91 int hold, found, number = 1, x;
95 natp = getnatp(player->cnum);
97 getstarg(player->argp[1],
98 "Build (ship, nuke, bridge, plane, land unit, tower)? ",
103 for (x = 0; x < number; x++) {
104 if (!snxtsct(&nstr, player->argp[2])) {
105 pr("Bad sector specification.\n");
109 tlev = (int)natp->nat_level[NAT_TLEV];
110 rlev = (int)natp->nat_level[NAT_RLEV];
114 p = getstarg(player->argp[3], "Plane type? ", buf);
115 if (p == 0 || *p == 0)
118 while (n && iscntrl(p[n - 1]))
122 for (found = 0, type = 0, pp = plchr; type <= pln_maxno;
124 if (pp->pl_tech > tlev)
126 if (pp->pl_name && strncmp(p, pp->pl_name, n) == 0) {
133 pr("Illegal plane type: \"%s\"\n", p);
134 if (confirm("List plane types? "))
135 show_plane_build(tlev);
141 rqtech = pp->pl_tech;
144 p = getstarg(player->argp[3], "Ship type? ", buf);
145 if (p == 0 || *p == 0)
148 while (n && iscntrl(p[n - 1]))
152 for (found = 0, mp = mchr, type = 0; type <= shp_maxno;
154 if (mp->m_tech > tlev)
156 /* Can't build trade ships unless it's turned on */
157 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
159 if (mp->m_name && strncmp(p, mp->m_name, n) == 0) {
166 pr("Illegal ship type: \"%s\"\n", p);
167 if (confirm("List ship types? "))
168 show_ship_build(tlev);
177 p = getstarg(player->argp[3], "Land unit type? ", buf);
178 if (p == 0 || *p == 0)
181 while (n && iscntrl(p[n - 1]))
185 for (found = 0, lp = lchr, type = 0; type <= lnd_maxno;
187 if (lp->l_tech > tlev)
189 if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
191 if (lp->l_name && strncmp(p, lp->l_name, n) == 0) {
198 pr("Illegal land unit type: \"%s\"\n", p);
199 if (confirm("List unit types? "))
200 show_land_build(tlev);
209 if (natp->nat_level[NAT_TLEV] + 0.005 < buil_bt) {
210 pr("Building a span requires a tech of %.0f\n", buil_bt);
215 if (!opt_BRIDGETOWERS) {
216 pr("Bridge tower building is disabled.\n");
219 if (natp->nat_level[NAT_TLEV] + 0.005 < buil_tower_bt) {
220 pr("Building a tower requires a tech of %.0f\n",
227 pr("There are no nukes in this game.\n");
230 p = getstarg(player->argp[3], "Nuke type? ", buf);
231 if (p == 0 || *p == 0)
234 while (n && iscntrl(p[n - 1]))
238 for (found = 0, np = nchr, type = 0; type < nuk_maxno;
240 if ((np->n_tech > tlev)
242 && ((np->n_tech * drnuke_const) > rlev)))
244 if (opt_NEUTRON == 0 && (np->n_flags & N_NEUT))
247 if (np->n_name && strncmp(p, np->n_name, n) == 0) {
255 pr("Possible nuke types are:\n");
257 tt = (tlev < (rlev / drnuke_const) ? (int)tlev :
258 (int)(rlev / drnuke_const));
269 pr("You can't build that!\n");
272 if (what != 'b' && what != 't') {
273 if (player->argp[4]) {
274 if (atoi(player->argp[4]) > 20 && !asked) {
278 "Are you sure that you want to build %s of them? ",
280 p = getstarg(player->argp[6], bstr, buf);
281 if (p == 0 || *p != 'y')
284 number = atoi(player->argp[4]);
287 if (what != 'b' && what != 'n' && what != 't') {
288 if (player->argp[5]) {
289 tlev = atoi(player->argp[5]);
290 if (tlev > natp->nat_level[NAT_TLEV] && !player->god) {
291 pr("Your tech level is only %d.\n",
292 (int)natp->nat_level[NAT_TLEV]);
296 pr("Required tech is %d.\n", rqtech);
299 pr("building with tech level %d.\n", tlev);
301 tlev = (int)natp->nat_level[NAT_TLEV];
303 cash = natp->nat_money;
304 while (nxtsct(&nstr, §)) {
310 built = build_land(§, lp, sect.sct_item, tlev);
313 built = build_ship(§, mp, sect.sct_item, tlev);
316 built = build_bridge(§, sect.sct_item);
319 built = build_tower(§, sect.sct_item);
322 built = build_nuke(§, np, sect.sct_item);
325 built = build_plane(§, pp, sect.sct_item, tlev);
328 CANT_HAPPEN("Bad WHAT");
337 pr("Bad sector specification.\n");
343 build_ship(register struct sctstr *sp, register struct mchrstr *mp,
344 short *vec, int tlev)
347 struct nstr_item nstr;
349 float eff = SHIP_MINEFF / 100.0;
353 hcm = roundavg((double)mp->m_hcm * eff);
354 lcm = roundavg((double)mp->m_lcm * eff);
356 if (sp->sct_type != SCT_HARBR) {
357 pr("Ships must be built in harbours.\n");
360 if (sp->sct_effic < 60 && !player->god) {
361 pr("Sector %s is not 60%% efficient.\n",
362 xyas(sp->sct_x, sp->sct_y, player->cnum));
365 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
366 pr("Not enough materials in %s\n",
367 xyas(sp->sct_x, sp->sct_y, player->cnum));
370 avail = (SHP_BLD_WORK(mp->m_lcm, mp->m_hcm) * SHIP_MINEFF + 99) / 100;
371 if (sp->sct_avail < avail) {
372 pr("Not enough available work in %s to build a %s\n",
373 xyas(sp->sct_x, sp->sct_y, player->cnum), mp->m_name);
374 pr(" (%d available work required)\n", avail);
377 cost = mp->m_cost * SHIP_MINEFF / 100;
379 pr("Not enough money left to build a %s\n", mp->m_name);
382 if (!trechk(player->cnum, 0, NEWSHP))
384 if (!check_sect_ok(sp))
386 sp->sct_avail -= avail;
387 player->dolcost += cost;
389 snxtitem_all(&nstr, EF_SHIP);
390 while (nxtitem(&nstr, (s_char *)&ship)) {
391 if (ship.shp_own == 0) {
397 ef_extend(EF_SHIP, 50);
399 memset(&ship, 0, sizeof(struct shpstr));
400 ship.shp_x = sp->sct_x;
401 ship.shp_y = sp->sct_y;
402 ship.shp_destx[0] = sp->sct_x;
403 ship.shp_desty[0] = sp->sct_y;
404 ship.shp_destx[1] = sp->sct_x;
405 ship.shp_desty[1] = sp->sct_y;
406 ship.shp_autonav = 0;
407 /* new code for autonav, Chad Zabel 1-15-94 */
408 for (i = 0; i < TMAX; ++i) {
409 ship.shp_tstart[i] = I_NONE;
410 ship.shp_tend[i] = I_NONE;
411 ship.shp_lstart[i] = 0;
412 ship.shp_lend[i] = 0;
414 ship.shp_mission = 0;
415 ship.shp_own = player->cnum;
416 ship.shp_type = mp - mchr;
417 ship.shp_effic = SHIP_MINEFF;
418 if (opt_MOB_ACCESS) {
419 time(&ship.shp_access);
420 ship.shp_mobil = -(etu_per_update / sect_mob_neg_factor);
424 ship.shp_uid = nstr.cur;
427 ship.shp_nxlight = 0;
428 ship.shp_nchoppers = 0;
429 ship.shp_fleet = ' ';
430 memset(ship.shp_item, 0, sizeof(ship.shp_item));
431 ship.shp_pstage = PLG_HEALTHY;
433 ship.shp_mobquota = 0;
435 ship.shp_follow = nstr.cur;
436 ship.shp_name[0] = 0;
437 ship.shp_orig_own = player->cnum;
438 ship.shp_orig_x = sp->sct_x;
439 ship.shp_orig_y = sp->sct_y;
440 ship.shp_fuel = mchr[(int)ship.shp_type].m_fuelc;
442 memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
443 shp_set_tech(&ship, tlev);
448 if (sp->sct_pstage == PLG_INFECT)
449 ship.shp_pstage = PLG_EXPOSED;
450 makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x,
452 putship(ship.shp_uid, &ship);
453 pr("%s", prship(&ship));
454 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
459 build_land(register struct sctstr *sp, register struct lchrstr *lp,
460 short *vec, int tlev)
463 struct nstr_item nstr;
465 float eff = LAND_MINEFF / 100.0;
466 int mil, lcm, hcm, gun, shell;
470 mil = roundavg(((double)lp->l_mil * eff));
471 shell = roundavg(((double)lp->l_shell * eff));
472 gun = roundavg(((double)lp->l_gun * eff));
474 mil = shell = gun = 0;
476 hcm = roundavg(((double)lp->l_hcm * eff));
477 lcm = roundavg(((double)lp->l_lcm * eff));
479 if (sp->sct_type != SCT_HEADQ) {
480 pr("Land Units must be built in headquarters.\n");
483 if (sp->sct_effic < 60 && !player->god) {
484 pr("Sector %s is not 60%% efficient.\n",
485 xyas(sp->sct_x, sp->sct_y, player->cnum));
488 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
489 pr("Not enough materials in %s\n",
490 xyas(sp->sct_x, sp->sct_y, player->cnum));
494 if (vec[I_GUN] < gun || vec[I_GUN] == 0) {
495 pr("Not enough guns in %s\n",
496 xyas(sp->sct_x, sp->sct_y, player->cnum));
499 if (vec[I_SHELL] < shell) {
500 pr("Not enough shells in %s\n",
501 xyas(sp->sct_x, sp->sct_y, player->cnum));
504 if (vec[I_MILIT] < mil) {
505 pr("Not enough military in %s\n",
506 xyas(sp->sct_x, sp->sct_y, player->cnum));
510 if (!trechk(player->cnum, 0, NEWLND))
512 if (!check_sect_ok(sp))
514 avail = (LND_BLD_WORK(lp->l_lcm, lp->l_hcm) * LAND_MINEFF + 99) / 100;
515 if (sp->sct_avail < avail) {
516 pr("Not enough available work in %s to build a %s\n",
517 xyas(sp->sct_x, sp->sct_y, player->cnum), lp->l_name);
518 pr(" (%d available work required)\n", avail);
521 cost = lp->l_cost * LAND_MINEFF / 100;
523 pr("Not enough money left to build a %s\n", lp->l_name);
526 sp->sct_avail -= avail;
527 player->dolcost += cost;
529 snxtitem_all(&nstr, EF_LAND);
530 while (nxtitem(&nstr, (s_char *)&land)) {
531 if (land.lnd_own == 0) {
537 ef_extend(EF_LAND, 50);
539 memset(&land, 0, sizeof(struct lndstr));
540 land.lnd_x = sp->sct_x;
541 land.lnd_y = sp->sct_y;
542 land.lnd_own = player->cnum;
543 land.lnd_mission = 0;
544 land.lnd_type = lp - lchr;
545 land.lnd_effic = LAND_MINEFF;
546 if (opt_MOB_ACCESS) {
547 time(&land.lnd_access);
548 land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
552 land.lnd_uid = nstr.cur;
559 land.lnd_retreat = morale_base;
560 land.lnd_fuel = lp->l_fuelc;
561 land.lnd_nxlight = 0;
563 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
564 land.lnd_rad_max = 0;
565 memset(land.lnd_item, 0, sizeof(land.lnd_item));
566 land.lnd_pstage = PLG_HEALTHY;
568 lnd_set_tech(&land, tlev);
574 vec[I_SHELL] -= shell;
576 if (sp->sct_pstage == PLG_INFECT)
577 land.lnd_pstage = PLG_EXPOSED;
578 putland(nstr.cur, &land);
579 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
581 pr("%s", prland(&land));
582 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
587 build_bridge(register struct sctstr *sp, short *vec)
593 int nx, ny, i, good = 0;
597 if (opt_EASY_BRIDGES == 0) { /* must have a bridge head or tower */
598 if (sp->sct_type != SCT_BTOWER) {
599 if (sp->sct_type != SCT_BHEAD)
601 if (sp->sct_newtype != SCT_BHEAD)
608 for (i = 1; i <= 6; i++) {
610 nx = sp->sct_x + diroff[i][0];
611 ny = sp->sct_y + diroff[i][1];
612 getsect(nx, ny, §);
613 for (j = 1; j <= 6; j++) {
614 nx2 = sect.sct_x + diroff[j][0];
615 ny2 = sect.sct_y + diroff[j][1];
616 getsect(nx2, ny2, &s2);
617 if ((s2.sct_type != SCT_WATER) &&
618 (s2.sct_type != SCT_BSPAN))
625 pr("Bridges must be built adjacent to land or bridge towers.\n");
626 pr("No eligible sectors adjacent to this sector.\n");
629 } /* end EASY_BRIDGES */
632 if (sp->sct_effic < 60 && !player->god) {
633 pr("Sector %s is not 60%% efficient.\n",
634 xyas(sp->sct_x, sp->sct_y, player->cnum));
639 if (vec[I_HCM] < buil_bh) {
640 pr("%s only has %d unit%s of hcm,\n",
641 xyas(sp->sct_x, sp->sct_y, player->cnum),
642 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
643 pr("(a bridge span requires %d)\n", buil_bh);
646 } else if (!opt_NO_LCMS) {
647 if (vec[I_LCM] < buil_bh) {
648 pr("%s only has %d unit%s of lcm,\n",
649 xyas(sp->sct_x, sp->sct_y, player->cnum),
650 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
651 pr("(a bridge span requires %d)\n", buil_bh);
655 if (cash < buil_bc) {
656 pr("A span costs $%.2f to build; ", buil_bc);
657 pr("you only have %d.\n", cash);
660 avail = (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100;
661 if (sp->sct_avail < avail) {
662 pr("Not enough available work in %s to build a bridge\n",
663 xyas(sp->sct_x, sp->sct_y, player->cnum));
664 pr(" (%d available work required)\n", avail);
667 if (!player->argp[3]) {
668 pr("Bridge head at %s\n",
669 xyas(sp->sct_x, sp->sct_y, player->cnum));
670 nav_map(sp->sct_x, sp->sct_y, 1);
672 if (!(p = getstarg(player->argp[3], "build span in what direction? ", buf))
676 /* Sanity check time */
677 if (!check_sect_ok(sp))
680 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
681 pr("'%c' is not a valid direction...\n", *p);
685 newx = sp->sct_x + diroff[val][0];
686 newy = sp->sct_y + diroff[val][1];
687 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
688 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
691 if (opt_EASY_BRIDGES) {
694 for (i = 1; i <= 6; i++) {
696 nx = sect.sct_x + diroff[i][0];
697 ny = sect.sct_y + diroff[i][1];
698 getsect(nx, ny, &s2);
699 if ((s2.sct_type != SCT_WATER) && (s2.sct_type != SCT_BSPAN))
703 pr("Bridges must be built adjacent to land or bridge towers.\n");
704 pr("That sector is not adjacent to land or a bridge tower.\n");
707 } /* end EASY_BRIDGES */
708 sp->sct_avail -= avail;
709 player->dolcost += buil_bc;
711 sect.sct_type = SCT_BSPAN;
712 sect.sct_newtype = SCT_BSPAN;
713 sect.sct_effic = SCT_MINEFF;
716 sect.sct_defense = 0;
717 if (!opt_DEFENSE_INFRA)
718 sect.sct_defense = sect.sct_effic;
719 if (opt_MOB_ACCESS) {
720 time(§.sct_access);
721 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
727 pr("Bridge span built over %s\n",
728 xyas(sect.sct_x, sect.sct_y, player->cnum));
730 vec[I_HCM] -= buil_bh;
731 else if (!opt_NO_LCMS)
732 vec[I_LCM] -= buil_bh;
737 build_nuke(register struct sctstr *sp, register struct nchrstr *np,
742 if (sp->sct_type != SCT_NUKE && !player->god) {
743 pr("Nuclear weapons must be built in nuclear plants.\n");
746 if (sp->sct_effic < 60 && !player->god) {
747 pr("Sector %s is not 60%% efficient.\n",
748 xyas(sp->sct_x, sp->sct_y, player->cnum));
751 if (vec[I_HCM] < np->n_hcm || vec[I_LCM] < np->n_lcm ||
752 vec[I_OIL] < np->n_oil || vec[I_RAD] < np->n_rad) {
753 pr("Not enough materials for a %s bomb in %s\n",
754 np->n_name, xyas(sp->sct_x, sp->sct_y, player->cnum));
755 pr("(%d hcm, %d lcm, %d oil, & %d rads).\n",
756 np->n_hcm, np->n_lcm, np->n_oil, np->n_rad);
759 if (cash < np->n_cost) {
760 pr("You need $%d, you only have %d.\n", np->n_cost, cash);
763 avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
765 * XXX when nukes turn into units (or whatever), then
766 * make them start at 20%. Since they don't have efficiency
767 * now, we charge all the work right away.
769 if (sp->sct_avail < avail) {
770 pr("Not enough available work in %s to build a %s;\n",
771 xyas(sp->sct_x, sp->sct_y, player->cnum), np->n_name);
772 pr(" (%d available work required)\n", avail);
775 if (!trechk(player->cnum, 0, NEWNUK))
777 if (!check_sect_ok(sp))
779 sp->sct_avail -= avail;
780 player->dolcost += np->n_cost;
782 nuk_add(sp->sct_x, sp->sct_y, np - nchr, 1);
783 vec[I_HCM] -= np->n_hcm;
784 vec[I_LCM] -= np->n_lcm;
785 vec[I_OIL] -= np->n_oil;
786 vec[I_RAD] -= np->n_rad;
787 pr("%s warhead created in %s\n", np->n_name,
788 xyas(sp->sct_x, sp->sct_y, player->cnum));
793 build_plane(register struct sctstr *sp, register struct plchrstr *pp,
794 short *vec, int tlev)
798 struct nstr_item nstr;
799 float eff = PLANE_MINEFF / 100.0;
803 mil = roundavg(((double)pp->pl_crew * eff));
804 /* Always use at least 1 mil to build a plane */
805 if (mil == 0 && pp->pl_crew > 0)
807 hcm = roundavg(((double)pp->pl_hcm * eff));
808 lcm = roundavg(((double)pp->pl_lcm * eff));
809 if (sp->sct_type != SCT_AIRPT && !player->god) {
810 pr("Planes must be built in airports.\n");
813 if (sp->sct_effic < 60 && !player->god) {
814 pr("Sector %s is not 60%% efficient.\n",
815 xyas(sp->sct_x, sp->sct_y, player->cnum));
818 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
819 pr("Not enough materials in %s\n",
820 xyas(sp->sct_x, sp->sct_y, player->cnum));
823 avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * PLANE_MINEFF + 99) / 100;
824 if (sp->sct_avail < avail) {
825 pr("Not enough available work in %s to build a %s\n",
826 xyas(sp->sct_x, sp->sct_y, player->cnum), pp->pl_name);
827 pr(" (%d available work required)\n", avail);
830 cost = pp->pl_cost * PLANE_MINEFF / 100;
832 pr("Not enough money left to build a %s\n", pp->pl_name);
835 if (vec[I_MILIT] < mil || (vec[I_MILIT] == 0 && pp->pl_crew > 0)) {
836 pr("Not enough military for crew in %s\n",
837 xyas(sp->sct_x, sp->sct_y, player->cnum));
840 if (!trechk(player->cnum, 0, NEWPLN))
842 if (!check_sect_ok(sp))
844 sp->sct_avail -= avail;
845 player->dolcost += cost;
847 snxtitem_all(&nstr, EF_PLANE);
849 while (nxtitem(&nstr, (s_char *)&plane)) {
850 if (plane.pln_own == 0) {
855 if (freeplane == 0) {
856 ef_extend(EF_PLANE, 50);
858 memset(&plane, 0, sizeof(struct plnstr));
859 plane.pln_x = sp->sct_x;
860 plane.pln_y = sp->sct_y;
861 plane.pln_own = sp->sct_own;
862 plane.pln_type = pp - plchr;
863 plane.pln_effic = PLANE_MINEFF;
864 if (opt_MOB_ACCESS) {
865 time(&plane.pln_access);
866 plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
870 plane.pln_mission = 0;
873 plane.pln_radius = 0;
874 plane.pln_range = UCHAR_MAX; /* will be adjusted by pln_set_tech() */
875 plane.pln_range_max = plane.pln_range;
876 plane.pln_fuel = pp->pl_fuel;
877 plane.pln_wing = ' ';
880 plane.pln_uid = nstr.cur;
881 plane.pln_nuketype = -1;
882 plane.pln_harden = 0;
884 pln_set_tech(&plane, tlev);
890 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
892 putplane(plane.pln_uid, &plane);
893 pr("%s built in sector %s\n", prplane(&plane),
894 xyas(sp->sct_x, sp->sct_y, player->cnum));
899 build_tower(register struct sctstr *sp, short *vec)
912 if (sp->sct_type != SCT_BSPAN) {
913 pr("Bridge towers can only be built from bridge spans.\n");
917 if (sp->sct_effic < 60 && !player->god) {
918 pr("Sector %s is not 60%% efficient.\n",
919 xyas(sp->sct_x, sp->sct_y, player->cnum));
924 if (vec[I_HCM] < buil_tower_bh) {
925 pr("%s only has %d unit%s of hcm,\n",
926 xyas(sp->sct_x, sp->sct_y, player->cnum),
927 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
928 pr("(a bridge tower requires %d)\n", buil_tower_bh);
931 } else if (!opt_NO_LCMS) {
932 if (vec[I_LCM] < buil_tower_bh) {
933 pr("%s only has %d unit%s of lcm,\n",
934 xyas(sp->sct_x, sp->sct_y, player->cnum),
935 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
936 pr("(a bridge tower requires %d)\n", buil_tower_bh);
940 if (cash < buil_tower_bc) {
941 pr("A bridge tower costs $%.2f to build; ", buil_tower_bc);
942 pr("you only have %d.\n", cash);
945 avail = (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100;
946 if (sp->sct_avail < avail) {
947 pr("Not enough available work in %s to build a bridge tower\n",
948 xyas(sp->sct_x, sp->sct_y, player->cnum));
949 pr(" (%d available work required)\n", avail);
952 if (!player->argp[3]) {
953 pr("Building from %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
954 nav_map(sp->sct_x, sp->sct_y, 1);
956 if (!(p = getstarg(player->argp[3], "build tower in what direction? ", buf))
960 /* Sanity check time */
961 if (!check_sect_ok(sp))
964 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
965 pr("'%c' is not a valid direction...\n", *p);
969 newx = sp->sct_x + diroff[val][0];
970 newy = sp->sct_y + diroff[val][1];
971 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
972 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
976 /* Now, check. You aren't allowed to build bridge towers
979 for (i = 1; i <= 6; i++) {
981 nx = sect.sct_x + diroff[i][0];
982 ny = sect.sct_y + diroff[i][1];
983 getsect(nx, ny, &s2);
984 if ((s2.sct_type != SCT_WATER) &&
985 (s2.sct_type != SCT_BTOWER) && (s2.sct_type != SCT_BSPAN)) {
991 pr("Bridge towers cannot be built adjacent to land.\n");
992 pr("That sector is adjacent to land.\n");
996 sp->sct_avail -= avail;
997 player->dolcost += buil_tower_bc;
998 cash -= buil_tower_bc;
999 sect.sct_type = SCT_BTOWER;
1000 sect.sct_newtype = SCT_BTOWER;
1001 sect.sct_effic = SCT_MINEFF;
1004 sect.sct_defense = 0;
1005 if (opt_MOB_ACCESS) {
1006 time(§.sct_access);
1007 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
1011 if (!opt_DEFENSE_INFRA)
1012 sect.sct_defense = sect.sct_effic;
1015 pr("Bridge tower built in %s\n",
1016 xyas(sect.sct_x, sect.sct_y, player->cnum));
1018 vec[I_HCM] -= buil_tower_bh;
1019 else if (!opt_NO_LCMS)
1020 vec[I_LCM] -= buil_tower_bh;