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 * 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;
466 float eff = LAND_MINEFF / 100.0;
467 int mil, lcm, hcm, gun, shell;
471 mil = roundavg(((double)lp->l_mil * eff));
472 shell = roundavg(((double)lp->l_shell * eff));
473 gun = roundavg(((double)lp->l_gun * eff));
475 mil = shell = gun = 0;
477 hcm = roundavg(((double)lp->l_hcm * eff));
478 lcm = roundavg(((double)lp->l_lcm * eff));
480 natp = getnatp(player->cnum);
482 if (sp->sct_type != SCT_HEADQ) {
483 pr("Land Units must be built in headquarters.\n");
486 if (sp->sct_effic < 60 && !player->god) {
487 pr("Sector %s is not 60%% efficient.\n",
488 xyas(sp->sct_x, sp->sct_y, player->cnum));
491 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
492 pr("Not enough materials in %s\n",
493 xyas(sp->sct_x, sp->sct_y, player->cnum));
497 if (vec[I_GUN] < gun || vec[I_GUN] == 0) {
498 pr("Not enough guns in %s\n",
499 xyas(sp->sct_x, sp->sct_y, player->cnum));
502 if (vec[I_SHELL] < shell) {
503 pr("Not enough shells in %s\n",
504 xyas(sp->sct_x, sp->sct_y, player->cnum));
507 if (vec[I_MILIT] < mil) {
508 pr("Not enough military in %s\n",
509 xyas(sp->sct_x, sp->sct_y, player->cnum));
513 if (!trechk(player->cnum, 0, NEWLND))
515 if (!check_sect_ok(sp))
517 avail = (LND_BLD_WORK(lp->l_lcm, lp->l_hcm) * LAND_MINEFF + 99) / 100;
518 if (sp->sct_avail < avail) {
519 pr("Not enough available work in %s to build a %s\n",
520 xyas(sp->sct_x, sp->sct_y, player->cnum), lp->l_name);
521 pr(" (%d available work required)\n", avail);
524 cost = lp->l_cost * LAND_MINEFF / 100;
526 pr("Not enough money left to build a %s\n", lp->l_name);
529 sp->sct_avail -= avail;
530 player->dolcost += cost;
532 snxtitem_all(&nstr, EF_LAND);
533 while (nxtitem(&nstr, (s_char *)&land)) {
534 if (land.lnd_own == 0) {
540 ef_extend(EF_LAND, 50);
542 memset(&land, 0, sizeof(struct lndstr));
543 land.lnd_x = sp->sct_x;
544 land.lnd_y = sp->sct_y;
545 land.lnd_own = player->cnum;
546 land.lnd_mission = 0;
547 land.lnd_type = lp - lchr;
548 land.lnd_effic = LAND_MINEFF;
549 if (opt_MOB_ACCESS) {
550 time(&land.lnd_access);
551 land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
555 land.lnd_uid = nstr.cur;
562 land.lnd_retreat = morale_base;
563 land.lnd_fuel = lp->l_fuelc;
564 land.lnd_nxlight = 0;
566 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
567 land.lnd_rad_max = 0;
568 memset(land.lnd_item, 0, sizeof(land.lnd_item));
569 land.lnd_pstage = PLG_HEALTHY;
571 lnd_set_tech(&land, tlev);
577 vec[I_SHELL] -= shell;
579 if (sp->sct_pstage == PLG_INFECT)
580 land.lnd_pstage = PLG_EXPOSED;
581 putland(nstr.cur, &land);
582 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
584 pr("%s", prland(&land));
585 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
590 build_bridge(register struct sctstr *sp, short *vec)
596 int nx, ny, i, good = 0;
600 if (opt_EASY_BRIDGES == 0) { /* must have a bridge head or tower */
601 if (sp->sct_type != SCT_BTOWER) {
602 if (sp->sct_type != SCT_BHEAD)
604 if (sp->sct_newtype != SCT_BHEAD)
611 for (i = 1; i <= 6; i++) {
613 nx = sp->sct_x + diroff[i][0];
614 ny = sp->sct_y + diroff[i][1];
615 getsect(nx, ny, §);
616 for (j = 1; j <= 6; j++) {
617 nx2 = sect.sct_x + diroff[j][0];
618 ny2 = sect.sct_y + diroff[j][1];
619 getsect(nx2, ny2, &s2);
620 if ((s2.sct_type != SCT_WATER) &&
621 (s2.sct_type != SCT_BSPAN))
628 pr("Bridges must be built adjacent to land or bridge towers.\n");
629 pr("No eligible sectors adjacent to this sector.\n");
632 } /* end EASY_BRIDGES */
635 if (sp->sct_effic < 60 && !player->god) {
636 pr("Sector %s is not 60%% efficient.\n",
637 xyas(sp->sct_x, sp->sct_y, player->cnum));
642 if (vec[I_HCM] < buil_bh) {
643 pr("%s only has %d unit%s of hcm,\n",
644 xyas(sp->sct_x, sp->sct_y, player->cnum),
645 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
646 pr("(a bridge span requires %d)\n", buil_bh);
649 } else if (!opt_NO_LCMS) {
650 if (vec[I_LCM] < buil_bh) {
651 pr("%s only has %d unit%s of lcm,\n",
652 xyas(sp->sct_x, sp->sct_y, player->cnum),
653 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
654 pr("(a bridge span requires %d)\n", buil_bh);
658 if (cash < buil_bc) {
659 pr("A span costs $%.2f to build; ", buil_bc);
660 pr("you only have %d.\n", cash);
663 avail = (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100;
664 if (sp->sct_avail < avail) {
665 pr("Not enough available work in %s to build a bridge\n",
666 xyas(sp->sct_x, sp->sct_y, player->cnum));
667 pr(" (%d available work required)\n", avail);
670 if (!player->argp[3]) {
671 pr("Bridge head at %s\n",
672 xyas(sp->sct_x, sp->sct_y, player->cnum));
673 nav_map(sp->sct_x, sp->sct_y, 1);
675 if (!(p = getstarg(player->argp[3], "build span in what direction? ", buf))
679 /* Sanity check time */
680 if (!check_sect_ok(sp))
683 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
684 pr("'%c' is not a valid direction...\n", *p);
688 newx = sp->sct_x + diroff[val][0];
689 newy = sp->sct_y + diroff[val][1];
690 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
691 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
694 if (opt_EASY_BRIDGES) {
697 for (i = 1; i <= 6; i++) {
699 nx = sect.sct_x + diroff[i][0];
700 ny = sect.sct_y + diroff[i][1];
701 getsect(nx, ny, &s2);
702 if ((s2.sct_type != SCT_WATER) && (s2.sct_type != SCT_BSPAN))
706 pr("Bridges must be built adjacent to land or bridge towers.\n");
707 pr("That sector is not adjacent to land or a bridge tower.\n");
710 } /* end EASY_BRIDGES */
711 sp->sct_avail -= avail;
712 player->dolcost += buil_bc;
714 sect.sct_type = SCT_BSPAN;
715 sect.sct_newtype = SCT_BSPAN;
716 sect.sct_effic = SCT_MINEFF;
719 sect.sct_defense = 0;
720 if (!opt_DEFENSE_INFRA)
721 sect.sct_defense = sect.sct_effic;
722 if (opt_MOB_ACCESS) {
723 time(§.sct_access);
724 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
730 pr("Bridge span built over %s\n",
731 xyas(sect.sct_x, sect.sct_y, player->cnum));
733 vec[I_HCM] -= buil_bh;
734 else if (!opt_NO_LCMS)
735 vec[I_LCM] -= buil_bh;
740 build_nuke(register struct sctstr *sp, register struct nchrstr *np,
745 if (sp->sct_type != SCT_NUKE && !player->god) {
746 pr("Nuclear weapons must be built in nuclear plants.\n");
749 if (sp->sct_effic < 60 && !player->god) {
750 pr("Sector %s is not 60%% efficient.\n",
751 xyas(sp->sct_x, sp->sct_y, player->cnum));
754 if (vec[I_HCM] < np->n_hcm || vec[I_LCM] < np->n_lcm ||
755 vec[I_OIL] < np->n_oil || vec[I_RAD] < np->n_rad) {
756 pr("Not enough materials for a %s bomb in %s\n",
757 np->n_name, xyas(sp->sct_x, sp->sct_y, player->cnum));
758 pr("(%d hcm, %d lcm, %d oil, & %d rads).\n",
759 np->n_hcm, np->n_lcm, np->n_oil, np->n_rad);
762 if (cash < np->n_cost) {
763 pr("You need $%d, you only have %d.\n", np->n_cost, cash);
766 avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
768 * XXX when nukes turn into units (or whatever), then
769 * make them start at 20%. Since they don't have efficiency
770 * now, we charge all the work right away.
772 if (sp->sct_avail < avail) {
773 pr("Not enough available work in %s to build a %s;\n",
774 xyas(sp->sct_x, sp->sct_y, player->cnum), np->n_name);
775 pr(" (%d available work required)\n", avail);
778 if (!trechk(player->cnum, 0, NEWNUK))
780 if (!check_sect_ok(sp))
782 sp->sct_avail -= avail;
783 player->dolcost += np->n_cost;
785 nuk_add(sp->sct_x, sp->sct_y, np - nchr, 1);
786 vec[I_HCM] -= np->n_hcm;
787 vec[I_LCM] -= np->n_lcm;
788 vec[I_OIL] -= np->n_oil;
789 vec[I_RAD] -= np->n_rad;
790 pr("%s warhead created in %s\n", np->n_name,
791 xyas(sp->sct_x, sp->sct_y, player->cnum));
796 build_plane(register struct sctstr *sp, register struct plchrstr *pp,
797 short *vec, int tlev)
801 struct nstr_item nstr;
802 float eff = PLANE_MINEFF / 100.0;
806 mil = roundavg(((double)pp->pl_crew * eff));
807 /* Always use at least 1 mil to build a plane */
808 if (mil == 0 && pp->pl_crew > 0)
810 hcm = roundavg(((double)pp->pl_hcm * eff));
811 lcm = roundavg(((double)pp->pl_lcm * eff));
812 if (sp->sct_type != SCT_AIRPT && !player->god) {
813 pr("Planes must be built in airports.\n");
816 if (sp->sct_effic < 60 && !player->god) {
817 pr("Sector %s is not 60%% efficient.\n",
818 xyas(sp->sct_x, sp->sct_y, player->cnum));
821 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
822 pr("Not enough materials in %s\n",
823 xyas(sp->sct_x, sp->sct_y, player->cnum));
826 avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * PLANE_MINEFF + 99) / 100;
827 if (sp->sct_avail < avail) {
828 pr("Not enough available work in %s to build a %s\n",
829 xyas(sp->sct_x, sp->sct_y, player->cnum), pp->pl_name);
830 pr(" (%d available work required)\n", avail);
833 cost = pp->pl_cost * PLANE_MINEFF / 100;
835 pr("Not enough money left to build a %s\n", pp->pl_name);
838 if (vec[I_MILIT] < mil || (vec[I_MILIT] == 0 && pp->pl_crew > 0)) {
839 pr("Not enough military for crew in %s\n",
840 xyas(sp->sct_x, sp->sct_y, player->cnum));
843 if (!trechk(player->cnum, 0, NEWPLN))
845 if (!check_sect_ok(sp))
847 sp->sct_avail -= avail;
848 player->dolcost += cost;
850 snxtitem_all(&nstr, EF_PLANE);
852 while (nxtitem(&nstr, (s_char *)&plane)) {
853 if (plane.pln_own == 0) {
858 if (freeplane == 0) {
859 ef_extend(EF_PLANE, 50);
861 memset(&plane, 0, sizeof(struct plnstr));
862 plane.pln_x = sp->sct_x;
863 plane.pln_y = sp->sct_y;
864 plane.pln_own = sp->sct_own;
865 plane.pln_type = pp - plchr;
866 plane.pln_effic = PLANE_MINEFF;
867 if (opt_MOB_ACCESS) {
868 time(&plane.pln_access);
869 plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
873 plane.pln_mission = 0;
876 plane.pln_radius = 0;
877 plane.pln_range = UCHAR_MAX; /* will be adjusted by pln_set_tech() */
878 plane.pln_range_max = plane.pln_range;
879 plane.pln_fuel = pp->pl_fuel;
880 plane.pln_wing = ' ';
883 plane.pln_uid = nstr.cur;
884 plane.pln_nuketype = -1;
885 plane.pln_harden = 0;
887 pln_set_tech(&plane, tlev);
893 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
895 putplane(plane.pln_uid, &plane);
896 pr("%s built in sector %s\n", prplane(&plane),
897 xyas(sp->sct_x, sp->sct_y, player->cnum));
902 build_tower(register struct sctstr *sp, short *vec)
915 if (sp->sct_type != SCT_BSPAN) {
916 pr("Bridge towers can only be built from bridge spans.\n");
920 if (sp->sct_effic < 60 && !player->god) {
921 pr("Sector %s is not 60%% efficient.\n",
922 xyas(sp->sct_x, sp->sct_y, player->cnum));
927 if (vec[I_HCM] < buil_tower_bh) {
928 pr("%s only has %d unit%s of hcm,\n",
929 xyas(sp->sct_x, sp->sct_y, player->cnum),
930 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
931 pr("(a bridge tower requires %d)\n", buil_tower_bh);
934 } else if (!opt_NO_LCMS) {
935 if (vec[I_LCM] < buil_tower_bh) {
936 pr("%s only has %d unit%s of lcm,\n",
937 xyas(sp->sct_x, sp->sct_y, player->cnum),
938 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
939 pr("(a bridge tower requires %d)\n", buil_tower_bh);
943 if (cash < buil_tower_bc) {
944 pr("A bridge tower costs $%.2f to build; ", buil_tower_bc);
945 pr("you only have %d.\n", cash);
948 avail = (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100;
949 if (sp->sct_avail < avail) {
950 pr("Not enough available work in %s to build a bridge tower\n",
951 xyas(sp->sct_x, sp->sct_y, player->cnum));
952 pr(" (%d available work required)\n", avail);
955 if (!player->argp[3]) {
956 pr("Building from %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
957 nav_map(sp->sct_x, sp->sct_y, 1);
959 if (!(p = getstarg(player->argp[3], "build tower in what direction? ", buf))
963 /* Sanity check time */
964 if (!check_sect_ok(sp))
967 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
968 pr("'%c' is not a valid direction...\n", *p);
972 newx = sp->sct_x + diroff[val][0];
973 newy = sp->sct_y + diroff[val][1];
974 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
975 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
979 /* Now, check. You aren't allowed to build bridge towers
982 for (i = 1; i <= 6; i++) {
984 nx = sect.sct_x + diroff[i][0];
985 ny = sect.sct_y + diroff[i][1];
986 getsect(nx, ny, &s2);
987 if ((s2.sct_type != SCT_WATER) &&
988 (s2.sct_type != SCT_BTOWER) && (s2.sct_type != SCT_BSPAN)) {
994 pr("Bridge towers cannot be built adjacent to land.\n");
995 pr("That sector is adjacent to land.\n");
999 sp->sct_avail -= avail;
1000 player->dolcost += buil_tower_bc;
1001 cash -= buil_tower_bc;
1002 sect.sct_type = SCT_BTOWER;
1003 sect.sct_newtype = SCT_BTOWER;
1004 sect.sct_effic = SCT_MINEFF;
1007 sect.sct_defense = 0;
1008 if (opt_MOB_ACCESS) {
1009 time(§.sct_access);
1010 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
1014 if (!opt_DEFENSE_INFRA)
1015 sect.sct_defense = sect.sct_effic;
1018 pr("Bridge tower built in %s\n",
1019 xyas(sect.sct_x, sect.sct_y, player->cnum));
1021 vec[I_HCM] -= buil_tower_bh;
1022 else if (!opt_NO_LCMS)
1023 vec[I_LCM] -= buil_tower_bh;