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 * 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(struct sctstr *sp,
54 struct nchrstr *np, short *vec);
55 static int build_ship(struct sctstr *sp,
56 struct mchrstr *mp, short *vec,
58 static int build_land(struct sctstr *sp,
59 struct lchrstr *lp, short *vec,
61 static int build_bridge(struct sctstr *sp, short *vec);
62 static int build_tower(struct sctstr *sp, short *vec);
63 static int build_plane(struct sctstr *sp,
64 struct plchrstr *pp, short *vec,
67 static int cash; /* static ok */
70 * build <WHAT> <SECTS> <TYPE|DIR|MEG> [NUMBER]
76 struct nstr_sect nstr;
94 natp = getnatp(player->cnum);
96 getstarg(player->argp[1],
97 "Build (ship, nuke, bridge, plane, land unit, tower)? ",
102 for (x = 0; x < number; x++) {
103 if (!snxtsct(&nstr, player->argp[2])) {
104 pr("Bad sector specification.\n");
108 tlev = (int)natp->nat_level[NAT_TLEV];
109 rlev = (int)natp->nat_level[NAT_RLEV];
113 p = getstarg(player->argp[3], "Plane type? ", buf);
114 if (p == 0 || *p == 0)
116 type = typematch(p, EF_PLANE);
119 rqtech = pp->pl_tech;
124 pr("Illegal plane type: \"%s\"\n", p);
125 if (confirm("List plane types? "))
126 show_plane_build(tlev);
132 p = getstarg(player->argp[3], "Ship type? ", buf);
133 if (p == 0 || *p == 0)
135 type = typematch(p, EF_SHIP);
141 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
145 pr("Illegal ship type: \"%s\"\n", p);
146 if (confirm("List ship types? "))
147 show_ship_build(tlev);
153 p = getstarg(player->argp[3], "Land unit type? ", buf);
154 if (p == 0 || *p == 0)
156 type = typematch(p, EF_LAND);
162 if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
166 pr("Illegal land unit type: \"%s\"\n", p);
167 if (confirm("List unit types? "))
168 show_land_build(tlev);
174 if (natp->nat_level[NAT_TLEV] + 0.005 < buil_bt) {
175 pr("Building a span requires a tech of %.0f\n", buil_bt);
180 if (!opt_BRIDGETOWERS) {
181 pr("Bridge tower building is disabled.\n");
184 if (natp->nat_level[NAT_TLEV] + 0.005 < buil_tower_bt) {
185 pr("Building a tower requires a tech of %.0f\n",
192 pr("There are no nukes in this game.\n");
195 p = getstarg(player->argp[3], "Nuke type? ", buf);
196 if (p == 0 || *p == 0)
198 type = typematch(p, EF_NUKE);
203 || (opt_DRNUKE && np->n_tech * drnuke_const > rlev))
205 if ((np->n_flags & N_NEUT) && !opt_NEUTRON)
210 pr("Possible nuke types are:\n");
212 tt = (tlev < (rlev / drnuke_const) ? (int)tlev :
213 (int)(rlev / drnuke_const));
221 pr("You can't build that!\n");
224 if (what != 'b' && what != 't') {
225 if (player->argp[4]) {
226 if (atoi(player->argp[4]) > 20 && !asked) {
230 "Are you sure that you want to build %s of them? ",
232 p = getstarg(player->argp[6], bstr, buf);
233 if (p == 0 || *p != 'y')
236 number = atoi(player->argp[4]);
239 if (what != 'b' && what != 'n' && what != 't') {
240 if (player->argp[5]) {
241 tlev = atoi(player->argp[5]);
242 if (tlev > natp->nat_level[NAT_TLEV] && !player->god) {
243 pr("Your tech level is only %d.\n",
244 (int)natp->nat_level[NAT_TLEV]);
248 pr("Required tech is %d.\n", rqtech);
251 pr("building with tech level %d.\n", tlev);
253 tlev = (int)natp->nat_level[NAT_TLEV];
255 cash = natp->nat_money;
256 while (nxtsct(&nstr, §)) {
262 built = build_land(§, lp, sect.sct_item, tlev);
265 built = build_ship(§, mp, sect.sct_item, tlev);
268 built = build_bridge(§, sect.sct_item);
271 built = build_tower(§, sect.sct_item);
274 built = build_nuke(§, np, sect.sct_item);
277 built = build_plane(§, pp, sect.sct_item, tlev);
280 CANT_HAPPEN("Bad WHAT");
289 pr("Bad sector specification.\n");
295 build_ship(struct sctstr *sp, struct mchrstr *mp,
296 short *vec, int tlev)
299 struct nstr_item nstr;
301 float eff = SHIP_MINEFF / 100.0;
305 hcm = roundavg((double)mp->m_hcm * eff);
306 lcm = roundavg((double)mp->m_lcm * eff);
308 if (sp->sct_type != SCT_HARBR) {
309 pr("Ships must be built in harbours.\n");
312 if (sp->sct_effic < 60 && !player->god) {
313 pr("Sector %s is not 60%% efficient.\n",
314 xyas(sp->sct_x, sp->sct_y, player->cnum));
317 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
318 pr("Not enough materials in %s\n",
319 xyas(sp->sct_x, sp->sct_y, player->cnum));
322 avail = (SHP_BLD_WORK(mp->m_lcm, mp->m_hcm) * SHIP_MINEFF + 99) / 100;
323 if (sp->sct_avail < avail) {
324 pr("Not enough available work in %s to build a %s\n",
325 xyas(sp->sct_x, sp->sct_y, player->cnum), mp->m_name);
326 pr(" (%d available work required)\n", avail);
329 cost = mp->m_cost * SHIP_MINEFF / 100;
331 pr("Not enough money left to build a %s\n", mp->m_name);
334 if (!trechk(player->cnum, 0, NEWSHP))
336 if (!check_sect_ok(sp))
338 sp->sct_avail -= avail;
339 player->dolcost += cost;
341 snxtitem_all(&nstr, EF_SHIP);
342 while (nxtitem(&nstr, &ship)) {
343 if (ship.shp_own == 0) {
349 ef_extend(EF_SHIP, 50);
351 memset(&ship, 0, sizeof(struct shpstr));
352 ship.shp_x = sp->sct_x;
353 ship.shp_y = sp->sct_y;
354 ship.shp_destx[0] = sp->sct_x;
355 ship.shp_desty[0] = sp->sct_y;
356 ship.shp_destx[1] = sp->sct_x;
357 ship.shp_desty[1] = sp->sct_y;
358 ship.shp_autonav = 0;
359 /* new code for autonav, Chad Zabel 1-15-94 */
360 for (i = 0; i < TMAX; ++i) {
361 ship.shp_tstart[i] = I_NONE;
362 ship.shp_tend[i] = I_NONE;
363 ship.shp_lstart[i] = 0;
364 ship.shp_lend[i] = 0;
366 ship.shp_mission = 0;
367 ship.shp_own = player->cnum;
368 ship.shp_type = mp - mchr;
369 ship.shp_effic = SHIP_MINEFF;
370 if (opt_MOB_ACCESS) {
371 time(&ship.shp_access);
372 ship.shp_mobil = -(etu_per_update / sect_mob_neg_factor);
376 ship.shp_uid = nstr.cur;
379 ship.shp_nxlight = 0;
380 ship.shp_nchoppers = 0;
381 ship.shp_fleet = ' ';
382 memset(ship.shp_item, 0, sizeof(ship.shp_item));
383 ship.shp_pstage = PLG_HEALTHY;
385 ship.shp_mobquota = 0;
387 ship.shp_follow = nstr.cur;
388 ship.shp_name[0] = 0;
389 ship.shp_orig_own = player->cnum;
390 ship.shp_orig_x = sp->sct_x;
391 ship.shp_orig_y = sp->sct_y;
392 ship.shp_fuel = mchr[(int)ship.shp_type].m_fuelc;
394 memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
395 shp_set_tech(&ship, tlev);
400 if (sp->sct_pstage == PLG_INFECT)
401 ship.shp_pstage = PLG_EXPOSED;
402 makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x,
404 putship(ship.shp_uid, &ship);
405 pr("%s", prship(&ship));
406 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
411 build_land(struct sctstr *sp, struct lchrstr *lp,
412 short *vec, int tlev)
415 struct nstr_item nstr;
417 float eff = LAND_MINEFF / 100.0;
418 int mil, lcm, hcm, gun, shell;
422 mil = roundavg(((double)lp->l_mil * eff));
423 shell = roundavg(((double)lp->l_shell * eff));
424 gun = roundavg(((double)lp->l_gun * eff));
426 mil = shell = gun = 0;
428 hcm = roundavg(((double)lp->l_hcm * eff));
429 lcm = roundavg(((double)lp->l_lcm * eff));
431 if (sp->sct_type != SCT_HEADQ) {
432 pr("Land Units must be built in headquarters.\n");
435 if (sp->sct_effic < 60 && !player->god) {
436 pr("Sector %s is not 60%% efficient.\n",
437 xyas(sp->sct_x, sp->sct_y, player->cnum));
440 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
441 pr("Not enough materials in %s\n",
442 xyas(sp->sct_x, sp->sct_y, player->cnum));
446 if (vec[I_GUN] < gun || vec[I_GUN] == 0) {
447 pr("Not enough guns in %s\n",
448 xyas(sp->sct_x, sp->sct_y, player->cnum));
451 if (vec[I_SHELL] < shell) {
452 pr("Not enough shells in %s\n",
453 xyas(sp->sct_x, sp->sct_y, player->cnum));
456 if (vec[I_MILIT] < mil) {
457 pr("Not enough military in %s\n",
458 xyas(sp->sct_x, sp->sct_y, player->cnum));
462 if (!trechk(player->cnum, 0, NEWLND))
464 if (!check_sect_ok(sp))
466 avail = (LND_BLD_WORK(lp->l_lcm, lp->l_hcm) * LAND_MINEFF + 99) / 100;
467 if (sp->sct_avail < avail) {
468 pr("Not enough available work in %s to build a %s\n",
469 xyas(sp->sct_x, sp->sct_y, player->cnum), lp->l_name);
470 pr(" (%d available work required)\n", avail);
473 cost = lp->l_cost * LAND_MINEFF / 100;
475 pr("Not enough money left to build a %s\n", lp->l_name);
478 sp->sct_avail -= avail;
479 player->dolcost += cost;
481 snxtitem_all(&nstr, EF_LAND);
482 while (nxtitem(&nstr, &land)) {
483 if (land.lnd_own == 0) {
489 ef_extend(EF_LAND, 50);
491 memset(&land, 0, sizeof(struct lndstr));
492 land.lnd_x = sp->sct_x;
493 land.lnd_y = sp->sct_y;
494 land.lnd_own = player->cnum;
495 land.lnd_mission = 0;
496 land.lnd_type = lp - lchr;
497 land.lnd_effic = LAND_MINEFF;
498 if (opt_MOB_ACCESS) {
499 time(&land.lnd_access);
500 land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
504 land.lnd_uid = nstr.cur;
511 land.lnd_retreat = morale_base;
512 land.lnd_fuel = lp->l_fuelc;
513 land.lnd_nxlight = 0;
515 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
516 land.lnd_rad_max = 0;
517 memset(land.lnd_item, 0, sizeof(land.lnd_item));
518 land.lnd_pstage = PLG_HEALTHY;
520 lnd_set_tech(&land, tlev);
526 vec[I_SHELL] -= shell;
528 if (sp->sct_pstage == PLG_INFECT)
529 land.lnd_pstage = PLG_EXPOSED;
530 putland(nstr.cur, &land);
531 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
533 pr("%s", prland(&land));
534 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
539 build_bridge(struct sctstr *sp, short *vec)
545 int nx, ny, i, good = 0;
549 if (opt_EASY_BRIDGES == 0) { /* must have a bridge head or tower */
550 if (sp->sct_type != SCT_BTOWER) {
551 if (sp->sct_type != SCT_BHEAD)
553 if (sp->sct_newtype != SCT_BHEAD)
558 if (sp->sct_effic < 60 && !player->god) {
559 pr("Sector %s is not 60%% efficient.\n",
560 xyas(sp->sct_x, sp->sct_y, player->cnum));
565 if (vec[I_HCM] < buil_bh) {
566 pr("%s only has %d unit%s of hcm,\n",
567 xyas(sp->sct_x, sp->sct_y, player->cnum),
568 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
569 pr("(a bridge span requires %d)\n", buil_bh);
572 } else if (!opt_NO_LCMS) {
573 if (vec[I_LCM] < buil_bh) {
574 pr("%s only has %d unit%s of lcm,\n",
575 xyas(sp->sct_x, sp->sct_y, player->cnum),
576 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
577 pr("(a bridge span requires %d)\n", buil_bh);
581 if (cash < buil_bc) {
582 pr("A span costs $%.2f to build; ", buil_bc);
583 pr("you only have %d.\n", cash);
586 avail = (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100;
587 if (sp->sct_avail < avail) {
588 pr("Not enough available work in %s to build a bridge\n",
589 xyas(sp->sct_x, sp->sct_y, player->cnum));
590 pr(" (%d available work required)\n", avail);
593 if (!player->argp[3]) {
594 pr("Bridge head at %s\n",
595 xyas(sp->sct_x, sp->sct_y, player->cnum));
596 nav_map(sp->sct_x, sp->sct_y, 1);
598 if (!(p = getstarg(player->argp[3], "build span in what direction? ", buf))
602 /* Sanity check time */
603 if (!check_sect_ok(sp))
606 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
607 pr("'%c' is not a valid direction...\n", *p);
611 newx = sp->sct_x + diroff[val][0];
612 newy = sp->sct_y + diroff[val][1];
613 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
614 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
617 if (opt_EASY_BRIDGES) {
620 for (i = 1; i <= 6; i++) {
622 nx = sect.sct_x + diroff[i][0];
623 ny = sect.sct_y + diroff[i][1];
624 getsect(nx, ny, &s2);
625 if ((s2.sct_type != SCT_WATER) && (s2.sct_type != SCT_BSPAN))
629 pr("Bridges must be built adjacent to land or bridge towers.\n");
630 pr("That sector is not adjacent to land or a bridge tower.\n");
633 } /* end EASY_BRIDGES */
634 sp->sct_avail -= avail;
635 player->dolcost += buil_bc;
637 sect.sct_type = SCT_BSPAN;
638 sect.sct_newtype = SCT_BSPAN;
639 sect.sct_effic = SCT_MINEFF;
642 sect.sct_defense = 0;
643 if (!opt_DEFENSE_INFRA)
644 sect.sct_defense = sect.sct_effic;
645 if (opt_MOB_ACCESS) {
646 time(§.sct_access);
647 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
652 map_set(player->cnum, sect.sct_x, sect.sct_y, dchr[SCT_BSPAN].d_mnem, 2);
653 writemap(player->cnum);
655 pr("Bridge span built over %s\n",
656 xyas(sect.sct_x, sect.sct_y, player->cnum));
658 vec[I_HCM] -= buil_bh;
659 else if (!opt_NO_LCMS)
660 vec[I_LCM] -= buil_bh;
665 build_nuke(struct sctstr *sp, struct nchrstr *np,
670 if (sp->sct_type != SCT_NUKE && !player->god) {
671 pr("Nuclear weapons must be built in nuclear plants.\n");
674 if (sp->sct_effic < 60 && !player->god) {
675 pr("Sector %s is not 60%% efficient.\n",
676 xyas(sp->sct_x, sp->sct_y, player->cnum));
679 if (vec[I_HCM] < np->n_hcm || vec[I_LCM] < np->n_lcm ||
680 vec[I_OIL] < np->n_oil || vec[I_RAD] < np->n_rad) {
681 pr("Not enough materials for a %s bomb in %s\n",
682 np->n_name, xyas(sp->sct_x, sp->sct_y, player->cnum));
683 pr("(%d hcm, %d lcm, %d oil, & %d rads).\n",
684 np->n_hcm, np->n_lcm, np->n_oil, np->n_rad);
687 if (cash < np->n_cost) {
688 pr("You need $%d, you only have %d.\n", np->n_cost, cash);
691 avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
693 * XXX when nukes turn into units (or whatever), then
694 * make them start at 20%. Since they don't have efficiency
695 * now, we charge all the work right away.
697 if (sp->sct_avail < avail) {
698 pr("Not enough available work in %s to build a %s;\n",
699 xyas(sp->sct_x, sp->sct_y, player->cnum), np->n_name);
700 pr(" (%d available work required)\n", avail);
703 if (!trechk(player->cnum, 0, NEWNUK))
705 if (!check_sect_ok(sp))
707 sp->sct_avail -= avail;
708 player->dolcost += np->n_cost;
710 nuk_add(sp->sct_x, sp->sct_y, np - nchr, 1);
711 vec[I_HCM] -= np->n_hcm;
712 vec[I_LCM] -= np->n_lcm;
713 vec[I_OIL] -= np->n_oil;
714 vec[I_RAD] -= np->n_rad;
715 pr("%s warhead created in %s\n", np->n_name,
716 xyas(sp->sct_x, sp->sct_y, player->cnum));
721 build_plane(struct sctstr *sp, struct plchrstr *pp,
722 short *vec, int tlev)
726 struct nstr_item nstr;
727 float eff = PLANE_MINEFF / 100.0;
731 mil = roundavg(((double)pp->pl_crew * eff));
732 /* Always use at least 1 mil to build a plane */
733 if (mil == 0 && pp->pl_crew > 0)
735 hcm = roundavg(((double)pp->pl_hcm * eff));
736 lcm = roundavg(((double)pp->pl_lcm * eff));
737 if (sp->sct_type != SCT_AIRPT && !player->god) {
738 pr("Planes must be built in airports.\n");
741 if (sp->sct_effic < 60 && !player->god) {
742 pr("Sector %s is not 60%% efficient.\n",
743 xyas(sp->sct_x, sp->sct_y, player->cnum));
746 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
747 pr("Not enough materials in %s\n",
748 xyas(sp->sct_x, sp->sct_y, player->cnum));
751 avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * PLANE_MINEFF + 99) / 100;
752 if (sp->sct_avail < avail) {
753 pr("Not enough available work in %s to build a %s\n",
754 xyas(sp->sct_x, sp->sct_y, player->cnum), pp->pl_name);
755 pr(" (%d available work required)\n", avail);
758 cost = pp->pl_cost * PLANE_MINEFF / 100;
760 pr("Not enough money left to build a %s\n", pp->pl_name);
763 if (vec[I_MILIT] < mil || (vec[I_MILIT] == 0 && pp->pl_crew > 0)) {
764 pr("Not enough military for crew in %s\n",
765 xyas(sp->sct_x, sp->sct_y, player->cnum));
768 if (!trechk(player->cnum, 0, NEWPLN))
770 if (!check_sect_ok(sp))
772 sp->sct_avail -= avail;
773 player->dolcost += cost;
775 snxtitem_all(&nstr, EF_PLANE);
777 while (nxtitem(&nstr, &plane)) {
778 if (plane.pln_own == 0) {
783 if (freeplane == 0) {
784 ef_extend(EF_PLANE, 50);
786 memset(&plane, 0, sizeof(struct plnstr));
787 plane.pln_x = sp->sct_x;
788 plane.pln_y = sp->sct_y;
789 plane.pln_own = sp->sct_own;
790 plane.pln_type = pp - plchr;
791 plane.pln_effic = PLANE_MINEFF;
792 if (opt_MOB_ACCESS) {
793 time(&plane.pln_access);
794 plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
798 plane.pln_mission = 0;
801 plane.pln_radius = 0;
802 plane.pln_range = UCHAR_MAX; /* will be adjusted by pln_set_tech() */
803 plane.pln_range_max = plane.pln_range;
804 plane.pln_wing = ' ';
807 plane.pln_uid = nstr.cur;
808 plane.pln_nuketype = -1;
809 plane.pln_harden = 0;
811 pln_set_tech(&plane, tlev);
817 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
819 putplane(plane.pln_uid, &plane);
820 pr("%s built in sector %s\n", prplane(&plane),
821 xyas(sp->sct_x, sp->sct_y, player->cnum));
826 build_tower(struct sctstr *sp, short *vec)
839 if (sp->sct_type != SCT_BSPAN) {
840 pr("Bridge towers can only be built from bridge spans.\n");
844 if (sp->sct_effic < 60 && !player->god) {
845 pr("Sector %s is not 60%% efficient.\n",
846 xyas(sp->sct_x, sp->sct_y, player->cnum));
851 if (vec[I_HCM] < buil_tower_bh) {
852 pr("%s only has %d unit%s of hcm,\n",
853 xyas(sp->sct_x, sp->sct_y, player->cnum),
854 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
855 pr("(a bridge tower requires %d)\n", buil_tower_bh);
858 } else if (!opt_NO_LCMS) {
859 if (vec[I_LCM] < buil_tower_bh) {
860 pr("%s only has %d unit%s of lcm,\n",
861 xyas(sp->sct_x, sp->sct_y, player->cnum),
862 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
863 pr("(a bridge tower requires %d)\n", buil_tower_bh);
867 if (cash < buil_tower_bc) {
868 pr("A bridge tower costs $%.2f to build; ", buil_tower_bc);
869 pr("you only have %d.\n", cash);
872 avail = (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100;
873 if (sp->sct_avail < avail) {
874 pr("Not enough available work in %s to build a bridge tower\n",
875 xyas(sp->sct_x, sp->sct_y, player->cnum));
876 pr(" (%d available work required)\n", avail);
879 if (!player->argp[3]) {
880 pr("Building from %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
881 nav_map(sp->sct_x, sp->sct_y, 1);
883 if (!(p = getstarg(player->argp[3], "build tower in what direction? ", buf))
887 /* Sanity check time */
888 if (!check_sect_ok(sp))
891 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
892 pr("'%c' is not a valid direction...\n", *p);
896 newx = sp->sct_x + diroff[val][0];
897 newy = sp->sct_y + diroff[val][1];
898 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
899 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
903 /* Now, check. You aren't allowed to build bridge towers
906 for (i = 1; i <= 6; i++) {
908 nx = sect.sct_x + diroff[i][0];
909 ny = sect.sct_y + diroff[i][1];
910 getsect(nx, ny, &s2);
911 if ((s2.sct_type != SCT_WATER) &&
912 (s2.sct_type != SCT_BTOWER) && (s2.sct_type != SCT_BSPAN)) {
918 pr("Bridge towers cannot be built adjacent to land.\n");
919 pr("That sector is adjacent to land.\n");
923 sp->sct_avail -= avail;
924 player->dolcost += buil_tower_bc;
925 cash -= buil_tower_bc;
926 sect.sct_type = SCT_BTOWER;
927 sect.sct_newtype = SCT_BTOWER;
928 sect.sct_effic = SCT_MINEFF;
931 sect.sct_defense = 0;
932 if (opt_MOB_ACCESS) {
933 time(§.sct_access);
934 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
938 if (!opt_DEFENSE_INFRA)
939 sect.sct_defense = sect.sct_effic;
941 map_set(player->cnum, sect.sct_x, sect.sct_y, dchr[SCT_BTOWER].d_mnem, 2);
942 writemap(player->cnum);
944 pr("Bridge tower built in %s\n",
945 xyas(sect.sct_x, sect.sct_y, player->cnum));
947 vec[I_HCM] -= buil_tower_bh;
948 else if (!opt_NO_LCMS)
949 vec[I_LCM] -= buil_tower_bh;