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 pr("internal error in build (%d)\n", 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;
351 float eff = ((float)SHIP_MINEFF / 100.0);
352 int points, lcm, hcm;
356 hcm = roundavg(((double)mp->m_hcm * (double)eff));
357 lcm = roundavg(((double)mp->m_lcm * (double)eff));
359 if (sp->sct_type != SCT_HARBR) {
360 pr("Ships must be built in harbours.\n");
363 if (sp->sct_effic < 60 && !player->god) {
364 pr("Sector %s is not 60%% efficient.\n",
365 xyas(sp->sct_x, sp->sct_y, player->cnum));
368 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
369 pr("Not enough materials in %s\n",
370 xyas(sp->sct_x, sp->sct_y, player->cnum));
373 w_p_eff = (20 + mp->m_lcm + (mp->m_hcm * 2));
374 points = sp->sct_avail * 100 / w_p_eff;
375 if (points < SHIP_MINEFF) {
376 pr("Not enough available work in %s to build a %s\n",
377 xyas(sp->sct_x, sp->sct_y, player->cnum), mp->m_name);
378 pr(" (%d available work required)\n",
379 1 + (w_p_eff * SHIP_MINEFF) / 100);
382 cost = mp->m_cost * eff;
384 pr("Not enough money left to build a %s\n", mp->m_name);
387 if (!trechk(player->cnum, 0, NEWSHP))
389 if (!check_sect_ok(sp))
391 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * SHIP_MINEFF) / 100;
392 player->dolcost += cost;
394 snxtitem_all(&nstr, EF_SHIP);
395 while (nxtitem(&nstr, (s_char *)&ship)) {
396 if (ship.shp_own == 0) {
402 ef_extend(EF_SHIP, 50);
404 memset(&ship, 0, sizeof(struct shpstr));
405 ship.shp_x = sp->sct_x;
406 ship.shp_y = sp->sct_y;
407 ship.shp_destx[0] = sp->sct_x;
408 ship.shp_desty[0] = sp->sct_y;
409 ship.shp_destx[1] = sp->sct_x;
410 ship.shp_desty[1] = sp->sct_y;
411 ship.shp_autonav = 0;
412 /* new code for autonav, Chad Zabel 1-15-94 */
413 for (i = 0; i < TMAX; ++i) {
414 ship.shp_tstart[i] = ' ';
415 ship.shp_tend[i] = ' ';
416 ship.shp_lstart[i] = 0;
417 ship.shp_lend[i] = 0;
419 ship.shp_mission = 0;
420 ship.shp_own = player->cnum;
421 ship.shp_type = mp - mchr;
422 ship.shp_effic = SHIP_MINEFF;
423 if (opt_MOB_ACCESS) {
424 time(&ship.shp_access);
425 ship.shp_mobil = -(etu_per_update / sect_mob_neg_factor);
429 ship.shp_uid = nstr.cur;
432 ship.shp_nxlight = 0;
433 ship.shp_nchoppers = 0;
434 ship.shp_fleet = ' ';
435 memset(ship.shp_item, 0, sizeof(ship.shp_item));
436 ship.shp_pstage = PLG_HEALTHY;
438 ship.shp_tech = tlev;
440 techdiff = (int)(tlev - mp->m_tech);
441 ship.shp_armor = (short)SHP_DEF(mp->m_armor, techdiff);
442 ship.shp_speed = (short)SHP_SPD(mp->m_speed, techdiff);
443 ship.shp_visib = (short)SHP_VIS(mp->m_visib, techdiff);
444 ship.shp_frnge = (short)SHP_RNG(mp->m_frnge, techdiff);
445 ship.shp_glim = (short)SHP_FIR(mp->m_glim, techdiff);
447 ship.shp_mobquota = 0;
449 ship.shp_follow = nstr.cur;
450 ship.shp_name[0] = 0;
451 ship.shp_orig_own = player->cnum;
452 ship.shp_orig_x = sp->sct_x;
453 ship.shp_orig_y = sp->sct_y;
454 ship.shp_fuel = mchr[(int)ship.shp_type].m_fuelc;
456 for (x = 0; x < 10; x++)
457 ship.shp_rpath[x] = 0;
462 if (sp->sct_pstage == PLG_INFECT)
463 ship.shp_pstage = PLG_EXPOSED;
464 makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x,
466 putship(ship.shp_uid, &ship);
467 pr("%s", prship(&ship));
468 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
473 build_land(register struct sctstr *sp, register struct lchrstr *lp,
474 short *vec, int tlev)
477 struct nstr_item nstr;
482 float eff = ((float)LAND_MINEFF / 100.0);
483 int mil, lcm, hcm, gun, shell;
487 mil = roundavg(((double)lp->l_mil * (double)eff));
488 shell = roundavg(((double)lp->l_shell * (double)eff));
489 gun = roundavg(((double)lp->l_gun * (double)eff));
491 mil = shell = gun = 0;
492 hcm = roundavg(((double)lp->l_hcm * (double)eff));
493 lcm = roundavg(((double)lp->l_lcm * (double)eff));
495 natp = getnatp(player->cnum);
497 if (sp->sct_type != SCT_HEADQ) {
498 pr("Land Units must be built in headquarters.\n");
501 if (sp->sct_effic < 60 && !player->god) {
502 pr("Sector %s is not 60%% efficient.\n",
503 xyas(sp->sct_x, sp->sct_y, player->cnum));
506 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
507 pr("Not enough materials in %s\n",
508 xyas(sp->sct_x, sp->sct_y, player->cnum));
512 if (vec[I_GUN] < gun || vec[I_GUN] == 0) {
513 pr("Not enough guns in %s\n",
514 xyas(sp->sct_x, sp->sct_y, player->cnum));
517 if (vec[I_SHELL] < shell) {
518 pr("Not enough shells in %s\n",
519 xyas(sp->sct_x, sp->sct_y, player->cnum));
522 if (vec[I_MILIT] < mil) {
523 pr("Not enough military in %s\n",
524 xyas(sp->sct_x, sp->sct_y, player->cnum));
528 if (!trechk(player->cnum, 0, NEWLND))
530 if (!check_sect_ok(sp))
532 w_p_eff = (20 + lp->l_lcm + (lp->l_hcm * 2));
533 points = sp->sct_avail * 100 / w_p_eff;
534 if (points < LAND_MINEFF) {
535 pr("Not enough available work in %s to build a %s\n",
536 xyas(sp->sct_x, sp->sct_y, player->cnum), lp->l_name);
537 pr(" (%d available work required)\n",
538 1 + (w_p_eff * LAND_MINEFF) / 100);
541 cost = ((float)lp->l_cost * eff);
542 /* cost = (int)LND_COST(cost, tlev - lp->l_tech); */
544 pr("Not enough money left to build a %s\n", lp->l_name);
547 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * LAND_MINEFF) / 100;
548 player->dolcost += cost;
550 snxtitem_all(&nstr, EF_LAND);
551 while (nxtitem(&nstr, (s_char *)&land)) {
552 if (land.lnd_own == 0) {
558 ef_extend(EF_LAND, 50);
560 memset(&land, 0, sizeof(struct lndstr));
561 land.lnd_x = sp->sct_x;
562 land.lnd_y = sp->sct_y;
563 land.lnd_own = player->cnum;
564 land.lnd_mission = 0;
565 land.lnd_type = lp - lchr;
566 land.lnd_effic = LAND_MINEFF;
567 if (opt_MOB_ACCESS) {
568 time(&land.lnd_access);
569 land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
573 land.lnd_tech = tlev;
574 land.lnd_uid = nstr.cur;
581 land.lnd_retreat = morale_base;
582 land.lnd_fuel = lp->l_fuelc;
583 land.lnd_nxlight = 0;
585 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
586 land.lnd_rad_max = 0;
587 memset(land.lnd_item, 0, sizeof(land.lnd_item));
588 land.lnd_pstage = PLG_HEALTHY;
590 land.lnd_att = (float)LND_ATTDEF(lp->l_att, tlev - lp->l_tech);
591 land.lnd_def = (float)LND_ATTDEF(lp->l_def, tlev - lp->l_tech);
592 land.lnd_vul = (int)LND_VUL(lp->l_vul, tlev - lp->l_tech);
593 land.lnd_spd = (int)LND_SPD(lp->l_spd, tlev - lp->l_tech);
594 land.lnd_vis = (int)LND_VIS(lp->l_vis, tlev - lp->l_tech);
595 land.lnd_spy = (int)LND_SPY(lp->l_spy, tlev - lp->l_tech);
596 land.lnd_rad = (int)LND_RAD(lp->l_rad, tlev - lp->l_tech);
597 land.lnd_frg = (int)LND_FRG(lp->l_frg, tlev - lp->l_tech);
598 land.lnd_acc = (int)LND_ACC(lp->l_acc, tlev - lp->l_tech);
599 land.lnd_dam = (int)LND_DAM(lp->l_dam, tlev - lp->l_tech);
600 land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, tlev - lp->l_tech);
601 land.lnd_aaf = (int)LND_AAF(lp->l_aaf, tlev - lp->l_tech);
602 land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, tlev - lp->l_tech);
603 land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, tlev - lp->l_tech);
604 land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech);
605 land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech);
611 vec[I_SHELL] -= shell;
613 if (sp->sct_pstage == PLG_INFECT)
614 land.lnd_pstage = PLG_EXPOSED;
615 putland(nstr.cur, &land);
616 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
618 pr("%s", prland(&land));
619 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
624 build_bridge(register struct sctstr *sp, short *vec)
631 int nx, ny, i, good = 0;
635 if (opt_EASY_BRIDGES == 0) { /* must have a bridge head or tower */
636 if (sp->sct_type != SCT_BTOWER) {
637 if (sp->sct_type != SCT_BHEAD)
639 if (sp->sct_newtype != SCT_BHEAD)
646 for (i = 1; i <= 6; i++) {
648 nx = sp->sct_x + diroff[i][0];
649 ny = sp->sct_y + diroff[i][1];
650 getsect(nx, ny, §);
651 for (j = 1; j <= 6; j++) {
652 nx2 = sect.sct_x + diroff[j][0];
653 ny2 = sect.sct_y + diroff[j][1];
654 getsect(nx2, ny2, &s2);
655 if ((s2.sct_type != SCT_WATER) &&
656 (s2.sct_type != SCT_BSPAN))
663 pr("Bridges must be built adjacent to land or bridge towers.\n");
664 pr("No eligible sectors adjacent to this sector.\n");
667 } /* end EASY_BRIDGES */
670 if (sp->sct_effic < 60 && !player->god) {
671 pr("Sector %s is not 60%% efficient.\n",
672 xyas(sp->sct_x, sp->sct_y, player->cnum));
677 if (vec[I_HCM] < buil_bh) {
678 pr("%s only has %d unit%s of hcm,\n",
679 xyas(sp->sct_x, sp->sct_y, player->cnum),
680 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
681 pr("(a bridge span requires %d)\n", buil_bh);
684 } else if (!opt_NO_LCMS) {
685 if (vec[I_LCM] < buil_bh) {
686 pr("%s only has %d unit%s of lcm,\n",
687 xyas(sp->sct_x, sp->sct_y, player->cnum),
688 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
689 pr("(a bridge span requires %d)\n", buil_bh);
693 if (cash < buil_bc) {
694 pr("A span costs $%.2f to build; ", buil_bc);
695 pr("you only have %d.\n", cash);
698 w_p_eff = buil_bh * 2;
699 points = sp->sct_avail * 100 / w_p_eff;
701 pr("Not enough available work in %s to build a bridge\n",
702 xyas(sp->sct_x, sp->sct_y, player->cnum));
703 pr(" (%d available work required)\n", 1 + (w_p_eff * 20) / 100);
706 if (!player->argp[3]) {
707 pr("Bridge head at %s\n",
708 xyas(sp->sct_x, sp->sct_y, player->cnum));
709 nav_map(sp->sct_x, sp->sct_y, 1);
711 if (!(p = getstarg(player->argp[3], "build span in what direction? ", buf))
715 /* Sanity check time */
716 if (!check_sect_ok(sp))
719 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
720 pr("'%c' is not a valid direction...\n", *p);
724 newx = sp->sct_x + diroff[val][0];
725 newy = sp->sct_y + diroff[val][1];
726 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
727 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
730 if (opt_EASY_BRIDGES) {
733 for (i = 1; i <= 6; i++) {
735 nx = sect.sct_x + diroff[i][0];
736 ny = sect.sct_y + diroff[i][1];
737 getsect(nx, ny, &s2);
738 if ((s2.sct_type != SCT_WATER) && (s2.sct_type != SCT_BSPAN))
742 pr("Bridges must be built adjacent to land or bridge towers.\n");
743 pr("That sector is not adjacent to land or a bridge tower.\n");
746 } /* end EASY_BRIDGES */
747 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100;
748 player->dolcost += buil_bc;
750 sect.sct_type = SCT_BSPAN;
751 sect.sct_newtype = SCT_BSPAN;
755 sect.sct_defense = 0;
756 if (!opt_DEFENSE_INFRA)
757 sect.sct_defense = sect.sct_effic;
758 if (opt_MOB_ACCESS) {
759 time(§.sct_access);
760 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
766 pr("Bridge span built over %s\n",
767 xyas(sect.sct_x, sect.sct_y, player->cnum));
769 vec[I_HCM] -= buil_bh;
770 else if (!opt_NO_LCMS)
771 vec[I_LCM] -= buil_bh;
776 build_nuke(register struct sctstr *sp, register struct nchrstr *np,
782 if (sp->sct_type != SCT_NUKE && !player->god) {
783 pr("Nuclear weapons must be built in nuclear plants.\n");
786 if (sp->sct_effic < 60 && !player->god) {
787 pr("Sector %s is not 60%% efficient.\n",
788 xyas(sp->sct_x, sp->sct_y, player->cnum));
791 if (vec[I_HCM] < np->n_hcm || vec[I_LCM] < np->n_lcm ||
792 vec[I_OIL] < np->n_oil || vec[I_RAD] < np->n_rad) {
793 pr("Not enough materials for a %s bomb in %s\n",
794 np->n_name, xyas(sp->sct_x, sp->sct_y, player->cnum));
795 pr("(%d hcm, %d lcm, %d oil, & %d rads).\n",
796 np->n_hcm, np->n_lcm, np->n_oil, np->n_rad);
799 if (cash < np->n_cost) {
800 pr("You need $%d, you only have %d.\n", np->n_cost, cash);
803 w_p_eff = np->n_rad + np->n_oil + np->n_lcm + np->n_hcm * 2;
804 points = sp->sct_avail * 100 / w_p_eff;
806 * XXX when nukes turn into units (or whatever), then
807 * make them start at 20%. Since they don't have efficiency
808 * now, we choose 20% as a "big" number.
811 pr("Not enough available work in %s to build a %s;\n",
812 xyas(sp->sct_x, sp->sct_y, player->cnum), np->n_name);
813 pr(" (%d available work required)\n", 1 + w_p_eff * 20 / 100);
816 if (!trechk(player->cnum, 0, NEWNUK))
818 if (!check_sect_ok(sp))
820 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100;
821 player->dolcost += np->n_cost;
823 nuk_add(sp->sct_x, sp->sct_y, np - nchr, 1);
824 vec[I_HCM] -= np->n_hcm;
825 vec[I_LCM] -= np->n_lcm;
826 vec[I_OIL] -= np->n_oil;
827 vec[I_RAD] -= np->n_rad;
828 pr("%s warhead created in %s\n", np->n_name,
829 xyas(sp->sct_x, sp->sct_y, player->cnum));
834 build_plane(register struct sctstr *sp, register struct plchrstr *pp,
835 short *vec, int tlev)
839 struct nstr_item nstr;
840 float eff = ((float)PLANE_MINEFF / 100.0);
846 mil = roundavg(((double)pp->pl_crew * (double)eff));
847 /* Always use at least 1 mil to build a plane */
848 if (mil == 0 && pp->pl_crew > 0)
850 hcm = roundavg(((double)pp->pl_hcm * (double)eff));
851 lcm = roundavg(((double)pp->pl_lcm * (double)eff));
852 if (sp->sct_type != SCT_AIRPT && !player->god) {
853 pr("Planes must be built in airports.\n");
856 if (sp->sct_effic < 60 && !player->god) {
857 pr("Sector %s is not 60%% efficient.\n",
858 xyas(sp->sct_x, sp->sct_y, player->cnum));
861 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
862 pr("Not enough materials in %s\n",
863 xyas(sp->sct_x, sp->sct_y, player->cnum));
866 w_p_eff = (20 + pp->pl_lcm + (pp->pl_hcm * 2));
867 points = sp->sct_avail * 100 / w_p_eff;
868 if (points < PLANE_MINEFF) {
869 pr("Not enough available work in %s to build a %s\n",
870 xyas(sp->sct_x, sp->sct_y, player->cnum), pp->pl_name);
871 pr(" (%d available work required)\n",
872 1 + PLANE_MINEFF * w_p_eff / 100);
875 cost = pp->pl_cost * eff;
877 pr("Not enough money left to build a %s\n", pp->pl_name);
880 if (vec[I_MILIT] < mil || (vec[I_MILIT] == 0 && pp->pl_crew > 0)) {
881 pr("Not enough military for crew in %s\n",
882 xyas(sp->sct_x, sp->sct_y, player->cnum));
885 if (!trechk(player->cnum, 0, NEWPLN))
887 if (!check_sect_ok(sp))
889 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * PLANE_MINEFF) / 100;
890 player->dolcost += cost;
892 snxtitem_all(&nstr, EF_PLANE);
894 while (nxtitem(&nstr, (s_char *)&plane)) {
895 if (plane.pln_own == 0) {
900 if (freeplane == 0) {
901 ef_extend(EF_PLANE, 50);
903 memset(&plane, 0, sizeof(struct plnstr));
904 plane.pln_x = sp->sct_x;
905 plane.pln_y = sp->sct_y;
906 plane.pln_own = sp->sct_own;
907 plane.pln_type = pp - plchr;
908 plane.pln_effic = PLANE_MINEFF;
909 if (opt_MOB_ACCESS) {
910 time(&plane.pln_access);
911 plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
915 plane.pln_mission = 0;
918 plane.pln_radius = 0;
920 /* Note that this next block of variables can be changed so that individual
921 * planes may have their own stats (like based on tech maybe? :) ) Thus,
922 * the code now checks the pln_acc, pln_load and pln_fuel instead of using
923 * the static definitions of them. */
925 n = (int) (pp->pl_range * (0.75 + techfact(tlev - pp->pl_tech, 2.0)));
929 plane.pln_range_max = n;
930 n = (int) (pp->pl_att * (0.75 + techfact(tlev - pp->pl_tech, 2.0)));
934 n = (int) (pp->pl_def * (0.75 + techfact(tlev - pp->pl_tech, 2.0)));
940 plane.pln_acc = pp->pl_acc;
941 plane.pln_load = pp->pl_load;
942 plane.pln_fuel = pp->pl_fuel;
944 plane.pln_att = PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech));
945 plane.pln_def = PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech));
946 plane.pln_acc = PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech));
947 plane.pln_range = PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech));
948 plane.pln_range_max = plane.pln_range;
949 plane.pln_load = PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech));
950 plane.pln_fuel = pp->pl_fuel;
952 plane.pln_wing = ' ';
953 plane.pln_tech = tlev;
956 plane.pln_uid = nstr.cur;
957 plane.pln_nuketype = -1;
958 plane.pln_harden = 0;
960 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
962 putplane(plane.pln_uid, &plane);
963 pr("%s built in sector %s\n", prplane(&plane),
964 xyas(sp->sct_x, sp->sct_y, player->cnum));
972 build_tower(register struct sctstr *sp, short *vec)
986 if (sp->sct_type != SCT_BSPAN) {
987 pr("Bridge towers can only be built from bridge spans.\n");
991 if (sp->sct_effic < 60 && !player->god) {
992 pr("Sector %s is not 60%% efficient.\n",
993 xyas(sp->sct_x, sp->sct_y, player->cnum));
998 if (vec[I_HCM] < buil_tower_bh) {
999 pr("%s only has %d unit%s of hcm,\n",
1000 xyas(sp->sct_x, sp->sct_y, player->cnum),
1001 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
1002 pr("(a bridge tower requires %d)\n", buil_tower_bh);
1005 } else if (!opt_NO_LCMS) {
1006 if (vec[I_LCM] < buil_tower_bh) {
1007 pr("%s only has %d unit%s of lcm,\n",
1008 xyas(sp->sct_x, sp->sct_y, player->cnum),
1009 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
1010 pr("(a bridge tower requires %d)\n", buil_tower_bh);
1014 if (cash < buil_tower_bc) {
1015 pr("A bridge tower costs $%.2f to build; ", buil_tower_bc);
1016 pr("you only have %d.\n", cash);
1019 w_p_eff = buil_tower_bh * 2;
1020 points = sp->sct_avail * 100 / w_p_eff;
1022 pr("Not enough available work in %s to build a bridge tower\n",
1023 xyas(sp->sct_x, sp->sct_y, player->cnum));
1024 pr(" (%d available work required)\n", 1 + (w_p_eff * 20) / 100);
1027 if (!player->argp[3]) {
1028 pr("Building from %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
1029 nav_map(sp->sct_x, sp->sct_y, 1);
1031 if (!(p = getstarg(player->argp[3], "build tower in what direction? ", buf))
1035 /* Sanity check time */
1036 if (!check_sect_ok(sp))
1039 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
1040 pr("'%c' is not a valid direction...\n", *p);
1044 newx = sp->sct_x + diroff[val][0];
1045 newy = sp->sct_y + diroff[val][1];
1046 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
1047 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
1051 /* Now, check. You aren't allowed to build bridge towers
1054 for (i = 1; i <= 6; i++) {
1056 nx = sect.sct_x + diroff[i][0];
1057 ny = sect.sct_y + diroff[i][1];
1058 getsect(nx, ny, &s2);
1059 if ((s2.sct_type != SCT_WATER) &&
1060 (s2.sct_type != SCT_BTOWER) && (s2.sct_type != SCT_BSPAN)) {
1066 pr("Bridge towers cannot be built adjacent to land.\n");
1067 pr("That sector is adjacent to land.\n");
1071 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100;
1072 player->dolcost += buil_tower_bc;
1073 cash -= buil_tower_bc;
1074 sect.sct_type = SCT_BTOWER;
1075 sect.sct_newtype = SCT_BTOWER;
1076 sect.sct_effic = 20;
1079 sect.sct_defense = 0;
1080 if (opt_MOB_ACCESS) {
1081 time(§.sct_access);
1082 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
1086 if (!opt_DEFENSE_INFRA)
1087 sect.sct_defense = sect.sct_effic;
1090 pr("Bridge tower built in %s\n",
1091 xyas(sect.sct_x, sect.sct_y, player->cnum));
1093 vec[I_HCM] -= buil_tower_bh;
1094 else if (!opt_NO_LCMS)
1095 vec[I_LCM] -= buil_tower_bh;