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
54 static int build_nuke(register struct sctstr *sp,
55 register struct nchrstr *np, short *vec);
56 static int build_ship(register struct sctstr *sp,
57 register struct mchrstr *mp, short *vec,
59 static int build_land(register struct sctstr *sp,
60 register struct lchrstr *lp, short *vec,
62 static int build_bridge(register struct sctstr *sp, short *vec);
63 static int build_tower(register struct sctstr *sp, short *vec);
64 static int build_plane(register struct sctstr *sp,
65 register struct plchrstr *pp, short *vec,
68 static int cash; /* static ok */
71 * build <WHAT> <SECTS> <TYPE|DIR|MEG> [NUMBER]
77 struct nstr_sect nstr;
92 int hold, found, number = 1, x;
96 natp = getnatp(player->cnum);
98 getstarg(player->argp[1],
99 "Build (ship, nuke, bridge, plane, land unit, tower)? ",
104 for (x = 0; x < number; x++) {
105 if (!snxtsct(&nstr, player->argp[2])) {
106 pr("Bad sector specification.\n");
110 tlev = (int)natp->nat_level[NAT_TLEV];
111 rlev = (int)natp->nat_level[NAT_RLEV];
115 p = getstarg(player->argp[3], "Plane type? ", buf);
116 if (p == 0 || *p == 0)
119 while (n && iscntrl(p[n - 1]))
123 for (found = 0, type = 0, pp = plchr; type <= pln_maxno;
125 if (pp->pl_tech > tlev)
127 if (pp->pl_name && strncmp(p, pp->pl_name, n) == 0) {
134 pr("Illegal plane type: \"%s\"\n", p);
135 if (confirm("List plane types? "))
136 show_plane_build(tlev);
142 rqtech = pp->pl_tech;
145 p = getstarg(player->argp[3], "Ship type? ", buf);
146 if (p == 0 || *p == 0)
149 while (n && iscntrl(p[n - 1]))
153 for (found = 0, mp = mchr, type = 0; type <= shp_maxno;
155 if (mp->m_tech > tlev)
157 /* Can't build trade ships unless it's turned on */
158 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
160 if (mp->m_name && strncmp(p, mp->m_name, n) == 0) {
167 pr("Illegal ship type: \"%s\"\n", p);
168 if (confirm("List ship types? "))
169 show_ship_build(tlev);
178 p = getstarg(player->argp[3], "Land unit type? ", buf);
179 if (p == 0 || *p == 0)
182 while (n && iscntrl(p[n - 1]))
186 for (found = 0, lp = lchr, type = 0; type <= lnd_maxno;
188 if (lp->l_tech > tlev)
190 if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
192 if (lp->l_name && strncmp(p, lp->l_name, n) == 0) {
199 pr("Illegal land unit type: \"%s\"\n", p);
200 if (confirm("List unit types? "))
201 show_land_build(tlev);
210 if (natp->nat_level[NAT_TLEV] + 0.005 < buil_bt) {
211 pr("Building a span requires a tech of %.0f\n", buil_bt);
216 if (!opt_BRIDGETOWERS) {
217 pr("Bridge tower building is disabled.\n");
220 if (natp->nat_level[NAT_TLEV] + 0.005 < buil_tower_bt) {
221 pr("Building a tower requires a tech of %.0f\n",
228 pr("There are no nukes in this game.\n");
231 p = getstarg(player->argp[3], "Nuke type? ", buf);
232 if (p == 0 || *p == 0)
235 while (n && iscntrl(p[n - 1]))
239 for (found = 0, np = nchr, type = 0; type < nuk_maxno;
241 if ((np->n_tech > tlev)
243 && ((np->n_tech * drnuke_const) > rlev)))
245 if (opt_NEUTRON == 0 && (np->n_flags & N_NEUT))
248 if (np->n_name && strncmp(p, np->n_name, n) == 0) {
256 pr("Possible nuke types are:\n");
258 tt = (tlev < (rlev / drnuke_const) ? (int)tlev :
259 (int)(rlev / drnuke_const));
270 pr("You can't build that!\n");
273 if (what != 'b' && what != 't') {
274 if (player->argp[4]) {
275 if (atoi(player->argp[4]) > 20 && !asked) {
279 "Are you sure that you want to build %s of them? ",
281 p = getstarg(player->argp[6], bstr, buf);
282 if (p == 0 || *p != 'y')
285 number = atoi(player->argp[4]);
288 if (what != 'b' && what != 'n' && what != 't') {
289 if (player->argp[5]) {
290 tlev = atoi(player->argp[5]);
291 if (tlev > natp->nat_level[NAT_TLEV] && !player->god) {
292 pr("Your tech level is only %d.\n",
293 (int)natp->nat_level[NAT_TLEV]);
297 pr("Required tech is %d.\n", rqtech);
300 pr("building with tech level %d.\n", tlev);
302 tlev = (int)natp->nat_level[NAT_TLEV];
304 cash = natp->nat_money;
305 while (nxtsct(&nstr, §)) {
311 built = build_land(§, lp, sect.sct_item, tlev);
314 built = build_ship(§, mp, sect.sct_item, tlev);
317 built = build_bridge(§, sect.sct_item);
320 built = build_tower(§, sect.sct_item);
323 built = build_nuke(§, np, sect.sct_item);
326 built = build_plane(§, pp, sect.sct_item, tlev);
329 CANT_HAPPEN("Bad WHAT");
338 pr("Bad sector specification.\n");
344 build_ship(register struct sctstr *sp, register struct mchrstr *mp,
345 short *vec, int tlev)
348 struct nstr_item nstr;
350 float eff = SHIP_MINEFF / 100.0;
354 hcm = roundavg((double)mp->m_hcm * eff);
355 lcm = roundavg((double)mp->m_lcm * eff);
357 if (sp->sct_type != SCT_HARBR) {
358 pr("Ships must be built in harbours.\n");
361 if (sp->sct_effic < 60 && !player->god) {
362 pr("Sector %s is not 60%% efficient.\n",
363 xyas(sp->sct_x, sp->sct_y, player->cnum));
366 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
367 pr("Not enough materials in %s\n",
368 xyas(sp->sct_x, sp->sct_y, player->cnum));
371 avail = (SHP_BLD_WORK(mp->m_lcm, mp->m_hcm) * SHIP_MINEFF + 99) / 100;
372 if (sp->sct_avail < avail) {
373 pr("Not enough available work in %s to build a %s\n",
374 xyas(sp->sct_x, sp->sct_y, player->cnum), mp->m_name);
375 pr(" (%d available work required)\n", avail);
378 cost = mp->m_cost * SHIP_MINEFF / 100;
380 pr("Not enough money left to build a %s\n", mp->m_name);
383 if (!trechk(player->cnum, 0, NEWSHP))
385 if (!check_sect_ok(sp))
387 sp->sct_avail -= avail;
388 player->dolcost += cost;
390 snxtitem_all(&nstr, EF_SHIP);
391 while (nxtitem(&nstr, (s_char *)&ship)) {
392 if (ship.shp_own == 0) {
398 ef_extend(EF_SHIP, 50);
400 memset(&ship, 0, sizeof(struct shpstr));
401 ship.shp_x = sp->sct_x;
402 ship.shp_y = sp->sct_y;
403 ship.shp_destx[0] = sp->sct_x;
404 ship.shp_desty[0] = sp->sct_y;
405 ship.shp_destx[1] = sp->sct_x;
406 ship.shp_desty[1] = sp->sct_y;
407 ship.shp_autonav = 0;
408 /* new code for autonav, Chad Zabel 1-15-94 */
409 for (i = 0; i < TMAX; ++i) {
410 ship.shp_tstart[i] = I_NONE;
411 ship.shp_tend[i] = I_NONE;
412 ship.shp_lstart[i] = 0;
413 ship.shp_lend[i] = 0;
415 ship.shp_mission = 0;
416 ship.shp_own = player->cnum;
417 ship.shp_type = mp - mchr;
418 ship.shp_effic = SHIP_MINEFF;
419 if (opt_MOB_ACCESS) {
420 time(&ship.shp_access);
421 ship.shp_mobil = -(etu_per_update / sect_mob_neg_factor);
425 ship.shp_uid = nstr.cur;
428 ship.shp_nxlight = 0;
429 ship.shp_nchoppers = 0;
430 ship.shp_fleet = ' ';
431 memset(ship.shp_item, 0, sizeof(ship.shp_item));
432 ship.shp_pstage = PLG_HEALTHY;
434 ship.shp_mobquota = 0;
436 ship.shp_follow = nstr.cur;
437 ship.shp_name[0] = 0;
438 ship.shp_orig_own = player->cnum;
439 ship.shp_orig_x = sp->sct_x;
440 ship.shp_orig_y = sp->sct_y;
441 ship.shp_fuel = mchr[(int)ship.shp_type].m_fuelc;
443 memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
444 shp_set_tech(&ship, tlev);
449 if (sp->sct_pstage == PLG_INFECT)
450 ship.shp_pstage = PLG_EXPOSED;
451 makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x,
453 putship(ship.shp_uid, &ship);
454 pr("%s", prship(&ship));
455 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
460 build_land(register struct sctstr *sp, register struct lchrstr *lp,
461 short *vec, int tlev)
464 struct nstr_item nstr;
467 float eff = LAND_MINEFF / 100.0;
468 int mil, lcm, hcm, gun, shell;
472 mil = roundavg(((double)lp->l_mil * eff));
473 shell = roundavg(((double)lp->l_shell * eff));
474 gun = roundavg(((double)lp->l_gun * eff));
476 mil = shell = gun = 0;
478 hcm = roundavg(((double)lp->l_hcm * eff));
479 lcm = roundavg(((double)lp->l_lcm * eff));
481 natp = getnatp(player->cnum);
483 if (sp->sct_type != SCT_HEADQ) {
484 pr("Land Units must be built in headquarters.\n");
487 if (sp->sct_effic < 60 && !player->god) {
488 pr("Sector %s is not 60%% efficient.\n",
489 xyas(sp->sct_x, sp->sct_y, player->cnum));
492 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
493 pr("Not enough materials in %s\n",
494 xyas(sp->sct_x, sp->sct_y, player->cnum));
498 if (vec[I_GUN] < gun || vec[I_GUN] == 0) {
499 pr("Not enough guns in %s\n",
500 xyas(sp->sct_x, sp->sct_y, player->cnum));
503 if (vec[I_SHELL] < shell) {
504 pr("Not enough shells in %s\n",
505 xyas(sp->sct_x, sp->sct_y, player->cnum));
508 if (vec[I_MILIT] < mil) {
509 pr("Not enough military in %s\n",
510 xyas(sp->sct_x, sp->sct_y, player->cnum));
514 if (!trechk(player->cnum, 0, NEWLND))
516 if (!check_sect_ok(sp))
518 avail = (LND_BLD_WORK(lp->l_lcm, lp->l_hcm) * LAND_MINEFF + 99) / 100;
519 if (sp->sct_avail < avail) {
520 pr("Not enough available work in %s to build a %s\n",
521 xyas(sp->sct_x, sp->sct_y, player->cnum), lp->l_name);
522 pr(" (%d available work required)\n", avail);
525 cost = lp->l_cost * LAND_MINEFF / 100;
527 pr("Not enough money left to build a %s\n", lp->l_name);
530 sp->sct_avail -= avail;
531 player->dolcost += cost;
533 snxtitem_all(&nstr, EF_LAND);
534 while (nxtitem(&nstr, (s_char *)&land)) {
535 if (land.lnd_own == 0) {
541 ef_extend(EF_LAND, 50);
543 memset(&land, 0, sizeof(struct lndstr));
544 land.lnd_x = sp->sct_x;
545 land.lnd_y = sp->sct_y;
546 land.lnd_own = player->cnum;
547 land.lnd_mission = 0;
548 land.lnd_type = lp - lchr;
549 land.lnd_effic = LAND_MINEFF;
550 if (opt_MOB_ACCESS) {
551 time(&land.lnd_access);
552 land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
556 land.lnd_uid = nstr.cur;
563 land.lnd_retreat = morale_base;
564 land.lnd_fuel = lp->l_fuelc;
565 land.lnd_nxlight = 0;
567 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
568 land.lnd_rad_max = 0;
569 memset(land.lnd_item, 0, sizeof(land.lnd_item));
570 land.lnd_pstage = PLG_HEALTHY;
572 lnd_set_tech(&land, tlev);
578 vec[I_SHELL] -= shell;
580 if (sp->sct_pstage == PLG_INFECT)
581 land.lnd_pstage = PLG_EXPOSED;
582 putland(nstr.cur, &land);
583 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
585 pr("%s", prland(&land));
586 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
591 build_bridge(register struct sctstr *sp, short *vec)
597 int nx, ny, i, good = 0;
601 if (opt_EASY_BRIDGES == 0) { /* must have a bridge head or tower */
602 if (sp->sct_type != SCT_BTOWER) {
603 if (sp->sct_type != SCT_BHEAD)
605 if (sp->sct_newtype != SCT_BHEAD)
612 for (i = 1; i <= 6; i++) {
614 nx = sp->sct_x + diroff[i][0];
615 ny = sp->sct_y + diroff[i][1];
616 getsect(nx, ny, §);
617 for (j = 1; j <= 6; j++) {
618 nx2 = sect.sct_x + diroff[j][0];
619 ny2 = sect.sct_y + diroff[j][1];
620 getsect(nx2, ny2, &s2);
621 if ((s2.sct_type != SCT_WATER) &&
622 (s2.sct_type != SCT_BSPAN))
629 pr("Bridges must be built adjacent to land or bridge towers.\n");
630 pr("No eligible sectors adjacent to this sector.\n");
633 } /* end EASY_BRIDGES */
636 if (sp->sct_effic < 60 && !player->god) {
637 pr("Sector %s is not 60%% efficient.\n",
638 xyas(sp->sct_x, sp->sct_y, player->cnum));
643 if (vec[I_HCM] < buil_bh) {
644 pr("%s only has %d unit%s of hcm,\n",
645 xyas(sp->sct_x, sp->sct_y, player->cnum),
646 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
647 pr("(a bridge span requires %d)\n", buil_bh);
650 } else if (!opt_NO_LCMS) {
651 if (vec[I_LCM] < buil_bh) {
652 pr("%s only has %d unit%s of lcm,\n",
653 xyas(sp->sct_x, sp->sct_y, player->cnum),
654 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
655 pr("(a bridge span requires %d)\n", buil_bh);
659 if (cash < buil_bc) {
660 pr("A span costs $%.2f to build; ", buil_bc);
661 pr("you only have %d.\n", cash);
664 avail = (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100;
665 if (sp->sct_avail < avail) {
666 pr("Not enough available work in %s to build a bridge\n",
667 xyas(sp->sct_x, sp->sct_y, player->cnum));
668 pr(" (%d available work required)\n", avail);
671 if (!player->argp[3]) {
672 pr("Bridge head at %s\n",
673 xyas(sp->sct_x, sp->sct_y, player->cnum));
674 nav_map(sp->sct_x, sp->sct_y, 1);
676 if (!(p = getstarg(player->argp[3], "build span in what direction? ", buf))
680 /* Sanity check time */
681 if (!check_sect_ok(sp))
684 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
685 pr("'%c' is not a valid direction...\n", *p);
689 newx = sp->sct_x + diroff[val][0];
690 newy = sp->sct_y + diroff[val][1];
691 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
692 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
695 if (opt_EASY_BRIDGES) {
698 for (i = 1; i <= 6; i++) {
700 nx = sect.sct_x + diroff[i][0];
701 ny = sect.sct_y + diroff[i][1];
702 getsect(nx, ny, &s2);
703 if ((s2.sct_type != SCT_WATER) && (s2.sct_type != SCT_BSPAN))
707 pr("Bridges must be built adjacent to land or bridge towers.\n");
708 pr("That sector is not adjacent to land or a bridge tower.\n");
711 } /* end EASY_BRIDGES */
712 sp->sct_avail -= avail;
713 player->dolcost += buil_bc;
715 sect.sct_type = SCT_BSPAN;
716 sect.sct_newtype = SCT_BSPAN;
717 sect.sct_effic = SCT_MINEFF;
720 sect.sct_defense = 0;
721 if (!opt_DEFENSE_INFRA)
722 sect.sct_defense = sect.sct_effic;
723 if (opt_MOB_ACCESS) {
724 time(§.sct_access);
725 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
731 pr("Bridge span built over %s\n",
732 xyas(sect.sct_x, sect.sct_y, player->cnum));
734 vec[I_HCM] -= buil_bh;
735 else if (!opt_NO_LCMS)
736 vec[I_LCM] -= buil_bh;
741 build_nuke(register struct sctstr *sp, register struct nchrstr *np,
746 if (sp->sct_type != SCT_NUKE && !player->god) {
747 pr("Nuclear weapons must be built in nuclear plants.\n");
750 if (sp->sct_effic < 60 && !player->god) {
751 pr("Sector %s is not 60%% efficient.\n",
752 xyas(sp->sct_x, sp->sct_y, player->cnum));
755 if (vec[I_HCM] < np->n_hcm || vec[I_LCM] < np->n_lcm ||
756 vec[I_OIL] < np->n_oil || vec[I_RAD] < np->n_rad) {
757 pr("Not enough materials for a %s bomb in %s\n",
758 np->n_name, xyas(sp->sct_x, sp->sct_y, player->cnum));
759 pr("(%d hcm, %d lcm, %d oil, & %d rads).\n",
760 np->n_hcm, np->n_lcm, np->n_oil, np->n_rad);
763 if (cash < np->n_cost) {
764 pr("You need $%d, you only have %d.\n", np->n_cost, cash);
767 avail = NUK_BLD_WORK(np->n_lcm, np->n_hcm, np->n_oil, np->n_rad);
769 * XXX when nukes turn into units (or whatever), then
770 * make them start at 20%. Since they don't have efficiency
771 * now, we charge all the work right away.
773 if (sp->sct_avail < avail) {
774 pr("Not enough available work in %s to build a %s;\n",
775 xyas(sp->sct_x, sp->sct_y, player->cnum), np->n_name);
776 pr(" (%d available work required)\n", avail);
779 if (!trechk(player->cnum, 0, NEWNUK))
781 if (!check_sect_ok(sp))
783 sp->sct_avail -= avail;
784 player->dolcost += np->n_cost;
786 nuk_add(sp->sct_x, sp->sct_y, np - nchr, 1);
787 vec[I_HCM] -= np->n_hcm;
788 vec[I_LCM] -= np->n_lcm;
789 vec[I_OIL] -= np->n_oil;
790 vec[I_RAD] -= np->n_rad;
791 pr("%s warhead created in %s\n", np->n_name,
792 xyas(sp->sct_x, sp->sct_y, player->cnum));
797 build_plane(register struct sctstr *sp, register struct plchrstr *pp,
798 short *vec, int tlev)
802 struct nstr_item nstr;
803 float eff = PLANE_MINEFF / 100.0;
807 mil = roundavg(((double)pp->pl_crew * eff));
808 /* Always use at least 1 mil to build a plane */
809 if (mil == 0 && pp->pl_crew > 0)
811 hcm = roundavg(((double)pp->pl_hcm * eff));
812 lcm = roundavg(((double)pp->pl_lcm * eff));
813 if (sp->sct_type != SCT_AIRPT && !player->god) {
814 pr("Planes must be built in airports.\n");
817 if (sp->sct_effic < 60 && !player->god) {
818 pr("Sector %s is not 60%% efficient.\n",
819 xyas(sp->sct_x, sp->sct_y, player->cnum));
822 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
823 pr("Not enough materials in %s\n",
824 xyas(sp->sct_x, sp->sct_y, player->cnum));
827 avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * PLANE_MINEFF + 99) / 100;
828 if (sp->sct_avail < avail) {
829 pr("Not enough available work in %s to build a %s\n",
830 xyas(sp->sct_x, sp->sct_y, player->cnum), pp->pl_name);
831 pr(" (%d available work required)\n", avail);
834 cost = pp->pl_cost * PLANE_MINEFF / 100;
836 pr("Not enough money left to build a %s\n", pp->pl_name);
839 if (vec[I_MILIT] < mil || (vec[I_MILIT] == 0 && pp->pl_crew > 0)) {
840 pr("Not enough military for crew in %s\n",
841 xyas(sp->sct_x, sp->sct_y, player->cnum));
844 if (!trechk(player->cnum, 0, NEWPLN))
846 if (!check_sect_ok(sp))
848 sp->sct_avail -= avail;
849 player->dolcost += cost;
851 snxtitem_all(&nstr, EF_PLANE);
853 while (nxtitem(&nstr, (s_char *)&plane)) {
854 if (plane.pln_own == 0) {
859 if (freeplane == 0) {
860 ef_extend(EF_PLANE, 50);
862 memset(&plane, 0, sizeof(struct plnstr));
863 plane.pln_x = sp->sct_x;
864 plane.pln_y = sp->sct_y;
865 plane.pln_own = sp->sct_own;
866 plane.pln_type = pp - plchr;
867 plane.pln_effic = PLANE_MINEFF;
868 if (opt_MOB_ACCESS) {
869 time(&plane.pln_access);
870 plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
874 plane.pln_mission = 0;
877 plane.pln_radius = 0;
878 plane.pln_range = UCHAR_MAX; /* will be adjusted by pln_set_tech() */
879 plane.pln_range_max = plane.pln_range;
880 plane.pln_fuel = pp->pl_fuel;
881 plane.pln_wing = ' ';
884 plane.pln_uid = nstr.cur;
885 plane.pln_nuketype = -1;
886 plane.pln_harden = 0;
888 pln_set_tech(&plane, tlev);
894 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
896 putplane(plane.pln_uid, &plane);
897 pr("%s built in sector %s\n", prplane(&plane),
898 xyas(sp->sct_x, sp->sct_y, player->cnum));
903 build_tower(register struct sctstr *sp, short *vec)
916 if (sp->sct_type != SCT_BSPAN) {
917 pr("Bridge towers can only be built from bridge spans.\n");
921 if (sp->sct_effic < 60 && !player->god) {
922 pr("Sector %s is not 60%% efficient.\n",
923 xyas(sp->sct_x, sp->sct_y, player->cnum));
928 if (vec[I_HCM] < buil_tower_bh) {
929 pr("%s only has %d unit%s of hcm,\n",
930 xyas(sp->sct_x, sp->sct_y, player->cnum),
931 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
932 pr("(a bridge tower requires %d)\n", buil_tower_bh);
935 } else if (!opt_NO_LCMS) {
936 if (vec[I_LCM] < buil_tower_bh) {
937 pr("%s only has %d unit%s of lcm,\n",
938 xyas(sp->sct_x, sp->sct_y, player->cnum),
939 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
940 pr("(a bridge tower requires %d)\n", buil_tower_bh);
944 if (cash < buil_tower_bc) {
945 pr("A bridge tower costs $%.2f to build; ", buil_tower_bc);
946 pr("you only have %d.\n", cash);
949 avail = (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100;
950 if (sp->sct_avail < avail) {
951 pr("Not enough available work in %s to build a bridge tower\n",
952 xyas(sp->sct_x, sp->sct_y, player->cnum));
953 pr(" (%d available work required)\n", avail);
956 if (!player->argp[3]) {
957 pr("Building from %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
958 nav_map(sp->sct_x, sp->sct_y, 1);
960 if (!(p = getstarg(player->argp[3], "build tower in what direction? ", buf))
964 /* Sanity check time */
965 if (!check_sect_ok(sp))
968 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
969 pr("'%c' is not a valid direction...\n", *p);
973 newx = sp->sct_x + diroff[val][0];
974 newy = sp->sct_y + diroff[val][1];
975 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
976 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
980 /* Now, check. You aren't allowed to build bridge towers
983 for (i = 1; i <= 6; i++) {
985 nx = sect.sct_x + diroff[i][0];
986 ny = sect.sct_y + diroff[i][1];
987 getsect(nx, ny, &s2);
988 if ((s2.sct_type != SCT_WATER) &&
989 (s2.sct_type != SCT_BTOWER) && (s2.sct_type != SCT_BSPAN)) {
995 pr("Bridge towers cannot be built adjacent to land.\n");
996 pr("That sector is adjacent to land.\n");
1000 sp->sct_avail -= avail;
1001 player->dolcost += buil_tower_bc;
1002 cash -= buil_tower_bc;
1003 sect.sct_type = SCT_BTOWER;
1004 sect.sct_newtype = SCT_BTOWER;
1005 sect.sct_effic = SCT_MINEFF;
1008 sect.sct_defense = 0;
1009 if (opt_MOB_ACCESS) {
1010 time(§.sct_access);
1011 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
1015 if (!opt_DEFENSE_INFRA)
1016 sect.sct_defense = sect.sct_effic;
1019 pr("Bridge tower built in %s\n",
1020 xyas(sect.sct_x, sect.sct_y, player->cnum));
1022 vec[I_HCM] -= buil_tower_bh;
1023 else if (!opt_NO_LCMS)
1024 vec[I_LCM] -= buil_tower_bh;