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
55 static int build_nuke(register struct sctstr *sp,
56 register struct nchrstr *np, register int *vec);
57 static int build_ship(register struct sctstr *sp,
58 register struct mchrstr *mp, register int *vec,
60 static int build_land(register struct sctstr *sp,
61 register struct lchrstr *lp, register int *vec,
63 static int build_bridge(register struct sctstr *sp, register int *vec);
64 static int build_tower(register struct sctstr *sp, register int *vec);
65 static int build_plane(register struct sctstr *sp,
66 register struct plchrstr *pp, register int *vec,
69 static int cash; /* static ok */
72 * build <WHAT> <SECTS> <TYPE|DIR|MEG> [NUMBER]
78 struct nstr_sect nstr;
94 int hold, found, number = 1, x;
98 natp = getnatp(player->cnum);
100 getstarg(player->argp[1],
101 "Build (ship, nuke, bridge, plane, land unit, tower)? ",
106 for (x = 0; x < number; x++) {
107 if (!snxtsct(&nstr, player->argp[2])) {
108 pr("Bad sector specification.\n");
112 tlev = (int)natp->nat_level[NAT_TLEV];
113 rlev = (int)natp->nat_level[NAT_RLEV];
117 p = getstarg(player->argp[3], "Plane type? ", buf);
118 if (p == 0 || *p == 0)
121 while (n && iscntrl(p[n - 1]))
125 for (found = 0, type = 0, pp = plchr; type <= pln_maxno;
127 if (pp->pl_tech > tlev)
129 if (pp->pl_name && strncmp(p, pp->pl_name, n) == 0) {
136 pr("Illegal plane type: \"%s\"\n", p);
137 if (confirm("List plane types? "))
138 show_plane_build(tlev);
144 rqtech = pp->pl_tech;
147 p = getstarg(player->argp[3], "Ship type? ", buf);
148 if (p == 0 || *p == 0)
151 while (n && iscntrl(p[n - 1]))
155 for (found = 0, mp = mchr, type = 0; type <= shp_maxno;
157 if (mp->m_tech > tlev)
159 /* Can't build trade ships unless it's turned on */
160 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
162 if (mp->m_name && strncmp(p, mp->m_name, n) == 0) {
169 pr("Illegal ship type: \"%s\"\n", p);
170 if (confirm("List ship types? "))
171 show_ship_build(tlev);
180 p = getstarg(player->argp[3], "Land unit type? ", buf);
181 if (p == 0 || *p == 0)
184 while (n && iscntrl(p[n - 1]))
188 for (found = 0, lp = lchr, type = 0; type <= lnd_maxno;
190 if (lp->l_tech > tlev)
192 if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
194 if (lp->l_name && strncmp(p, lp->l_name, n) == 0) {
201 pr("Illegal land unit type: \"%s\"\n", p);
202 if (confirm("List unit types? "))
203 show_land_build(tlev);
212 if (natp->nat_level[NAT_TLEV] + 0.005 < buil_bt) {
213 pr("Building a span requires a tech of %.0f\n", buil_bt);
218 if (!opt_BRIDGETOWERS) {
219 pr("Bridge tower building is disabled.\n");
222 if (natp->nat_level[NAT_TLEV] + 0.005 < buil_tower_bt) {
223 pr("Building a tower requires a tech of %.0f\n",
230 pr("There are no nukes in this game.\n");
233 p = getstarg(player->argp[3], "Nuke type? ", buf);
234 if (p == 0 || *p == 0)
237 while (n && iscntrl(p[n - 1]))
241 for (found = 0, np = nchr, type = 0; type < nuk_maxno;
243 if ((np->n_tech > tlev)
245 && ((np->n_tech * drnuke_const) > rlev)))
247 if (opt_NEUTRON == 0 && (np->n_flags & N_NEUT))
250 if (np->n_name && strncmp(p, np->n_name, n) == 0) {
258 pr("Possible nuke types are:\n");
260 tt = (tlev < (rlev / drnuke_const) ? (int)tlev :
261 (int)(rlev / drnuke_const));
272 pr("You can't build that!\n");
275 if (what != 'b' && what != 't') {
276 if (player->argp[4]) {
277 if (atoi(player->argp[4]) > 20 && !asked) {
281 "Are you sure that you want to build %s of them? ",
283 p = getstarg(player->argp[6], bstr, buf);
284 if (p == 0 || *p != 'y')
287 number = atoi(player->argp[4]);
290 if (what != 'b' && what != 'n' && what != 't') {
291 if (player->argp[5]) {
292 tlev = atoi(player->argp[5]);
293 if (tlev > natp->nat_level[NAT_TLEV] && !player->god) {
294 pr("Your tech level is only %d.\n",
295 (int)natp->nat_level[NAT_TLEV]);
299 pr("Required tech is %d.\n", rqtech);
302 pr("building with tech level %d.\n", tlev);
304 tlev = (int)natp->nat_level[NAT_TLEV];
306 cash = natp->nat_money;
307 while (nxtsct(&nstr, §)) {
311 getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
314 built = build_land(§, lp, vec, tlev);
317 built = build_ship(§, mp, vec, tlev);
320 built = build_bridge(§, vec);
323 built = build_tower(§, vec);
326 built = build_nuke(§, np, vec);
329 built = build_plane(§, pp, vec, tlev);
332 pr("internal error in build (%d)\n", what);
336 putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
342 pr("Bad sector specification.\n");
348 build_ship(register struct sctstr *sp, register struct mchrstr *mp,
349 register int *vec, int tlev)
352 struct nstr_item nstr;
355 float eff = ((float)SHIP_MINEFF / 100.0);
356 int points, lcm, hcm;
360 hcm = roundavg(((double)mp->m_hcm * (double)eff));
361 lcm = roundavg(((double)mp->m_lcm * (double)eff));
363 if (sp->sct_type != SCT_HARBR) {
364 pr("Ships must be built in harbours.\n");
367 if (sp->sct_effic < 60 && !player->god) {
368 pr("Sector %s is not 60%% efficient.\n",
369 xyas(sp->sct_x, sp->sct_y, player->cnum));
372 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
373 pr("Not enough materials in %s\n",
374 xyas(sp->sct_x, sp->sct_y, player->cnum));
377 w_p_eff = (20 + mp->m_lcm + (mp->m_hcm * 2));
378 points = sp->sct_avail * 100 / w_p_eff;
379 if (points < SHIP_MINEFF) {
380 pr("Not enough available work in %s to build a %s\n",
381 xyas(sp->sct_x, sp->sct_y, player->cnum), mp->m_name);
382 pr(" (%d available work required)\n",
383 1 + (w_p_eff * SHIP_MINEFF) / 100);
386 cost = mp->m_cost * eff;
388 pr("Not enough money left to build a %s\n", mp->m_name);
391 if (!trechk(player->cnum, 0, NEWSHP))
393 if (!check_sect_ok(sp))
395 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * SHIP_MINEFF) / 100;
396 player->dolcost += cost;
398 snxtitem_all(&nstr, EF_SHIP);
399 while (nxtitem(&nstr, (s_char *)&ship)) {
400 if (ship.shp_own == 0) {
406 ef_extend(EF_SHIP, 50);
408 memset(&ship, 0, sizeof(struct shpstr));
409 ship.shp_x = sp->sct_x;
410 ship.shp_y = sp->sct_y;
411 ship.shp_destx[0] = sp->sct_x;
412 ship.shp_desty[0] = sp->sct_y;
413 ship.shp_destx[1] = sp->sct_x;
414 ship.shp_desty[1] = sp->sct_y;
415 ship.shp_autonav = 0;
416 /* new code for autonav, Chad Zabel 1-15-94 */
417 for (i = 0; i < TMAX; ++i) {
418 ship.shp_tstart[i] = ' ';
419 ship.shp_tend[i] = ' ';
420 ship.shp_lstart[i] = 0;
421 ship.shp_lend[i] = 0;
423 ship.shp_mission = 0;
424 ship.shp_own = player->cnum;
425 ship.shp_type = mp - mchr;
426 ship.shp_effic = SHIP_MINEFF;
427 if (opt_MOB_ACCESS) {
428 time(&ship.shp_access);
429 ship.shp_mobil = -(etu_per_update / sect_mob_neg_factor);
433 ship.shp_uid = nstr.cur;
436 ship.shp_nxlight = 0;
437 ship.shp_nchoppers = 0;
438 ship.shp_fleet = ' ';
441 ship.shp_tech = tlev;
443 techdiff = (int)(tlev - mp->m_tech);
444 ship.shp_armor = (short)SHP_DEF(mp->m_armor, techdiff);
445 ship.shp_speed = (short)SHP_SPD(mp->m_speed, techdiff);
446 ship.shp_visib = (short)SHP_VIS(mp->m_visib, techdiff);
447 ship.shp_frnge = (short)SHP_RNG(mp->m_frnge, techdiff);
448 ship.shp_glim = (short)SHP_FIR(mp->m_glim, techdiff);
450 ship.shp_mobquota = 0;
452 ship.shp_follow = nstr.cur;
453 ship.shp_name[0] = 0;
454 ship.shp_orig_own = player->cnum;
455 ship.shp_orig_x = sp->sct_x;
456 ship.shp_orig_y = sp->sct_y;
457 ship.shp_fuel = mchr[(int)ship.shp_type].m_fuelc;
459 for (x = 0; x < 10; x++)
460 ship.shp_rpath[x] = 0;
465 if (getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_INFECT)
466 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP);
467 makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x,
469 putship(ship.shp_uid, &ship);
470 pr("%s", prship(&ship));
471 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
476 build_land(register struct sctstr *sp, register struct lchrstr *lp,
477 register int *vec, int tlev)
480 struct nstr_item nstr;
485 float eff = ((float)LAND_MINEFF / 100.0);
486 int mil, lcm, hcm, gun, shell;
490 mil = roundavg(((double)lp->l_mil * (double)eff));
491 shell = roundavg(((double)lp->l_shell * (double)eff));
492 gun = roundavg(((double)lp->l_gun * (double)eff));
494 mil = shell = gun = 0;
495 hcm = roundavg(((double)lp->l_hcm * (double)eff));
496 lcm = roundavg(((double)lp->l_lcm * (double)eff));
498 natp = getnatp(player->cnum);
500 if (sp->sct_type != SCT_HEADQ) {
501 pr("Land Units must be built in headquarters.\n");
504 if (sp->sct_effic < 60 && !player->god) {
505 pr("Sector %s is not 60%% efficient.\n",
506 xyas(sp->sct_x, sp->sct_y, player->cnum));
509 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
510 pr("Not enough materials in %s\n",
511 xyas(sp->sct_x, sp->sct_y, player->cnum));
515 if (vec[I_GUN] < gun || vec[I_GUN] == 0) {
516 pr("Not enough guns in %s\n",
517 xyas(sp->sct_x, sp->sct_y, player->cnum));
520 if (vec[I_SHELL] < shell) {
521 pr("Not enough shells in %s\n",
522 xyas(sp->sct_x, sp->sct_y, player->cnum));
525 if (vec[I_MILIT] < mil) {
526 pr("Not enough military in %s\n",
527 xyas(sp->sct_x, sp->sct_y, player->cnum));
531 if (!trechk(player->cnum, 0, NEWLND))
533 if (!check_sect_ok(sp))
535 w_p_eff = (20 + lp->l_lcm + (lp->l_hcm * 2));
536 points = sp->sct_avail * 100 / w_p_eff;
537 if (points < LAND_MINEFF) {
538 pr("Not enough available work in %s to build a %s\n",
539 xyas(sp->sct_x, sp->sct_y, player->cnum), lp->l_name);
540 pr(" (%d available work required)\n",
541 1 + (w_p_eff * LAND_MINEFF) / 100);
544 cost = ((float)lp->l_cost * eff);
545 /* cost = (int)LND_COST(cost, tlev - lp->l_tech); */
547 pr("Not enough money left to build a %s\n", lp->l_name);
550 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * LAND_MINEFF) / 100;
551 player->dolcost += cost;
553 snxtitem_all(&nstr, EF_LAND);
554 while (nxtitem(&nstr, (s_char *)&land)) {
555 if (land.lnd_own == 0) {
561 ef_extend(EF_LAND, 50);
563 memset(&land, 0, sizeof(struct lndstr));
564 land.lnd_x = sp->sct_x;
565 land.lnd_y = sp->sct_y;
566 land.lnd_own = player->cnum;
567 land.lnd_mission = 0;
568 land.lnd_type = lp - lchr;
569 land.lnd_effic = LAND_MINEFF;
570 if (opt_MOB_ACCESS) {
571 time(&land.lnd_access);
572 land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
577 land.lnd_tech = tlev;
578 land.lnd_uid = nstr.cur;
585 land.lnd_retreat = morale_base;
586 land.lnd_fuel = lp->l_fuelc;
587 land.lnd_nxlight = 0;
589 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
590 land.lnd_rad_max = 0;
592 land.lnd_att = (float)LND_ATTDEF(lp->l_att, tlev - lp->l_tech);
593 land.lnd_def = (float)LND_ATTDEF(lp->l_def, tlev - lp->l_tech);
594 land.lnd_vul = (int)LND_VUL(lp->l_vul, tlev - lp->l_tech);
595 land.lnd_spd = (int)LND_SPD(lp->l_spd, tlev - lp->l_tech);
596 land.lnd_vis = (int)LND_VIS(lp->l_vis, tlev - lp->l_tech);
597 land.lnd_spy = (int)LND_SPY(lp->l_spy, tlev - lp->l_tech);
598 land.lnd_rad = (int)LND_RAD(lp->l_rad, tlev - lp->l_tech);
599 land.lnd_frg = (int)LND_FRG(lp->l_frg, tlev - lp->l_tech);
600 land.lnd_acc = (int)LND_ACC(lp->l_acc, tlev - lp->l_tech);
601 land.lnd_dam = (int)LND_DAM(lp->l_dam, tlev - lp->l_tech);
602 land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, tlev - lp->l_tech);
603 land.lnd_aaf = (int)LND_AAF(lp->l_aaf, tlev - lp->l_tech);
604 land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, tlev - lp->l_tech);
605 land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, tlev - lp->l_tech);
606 land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech);
607 land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech);
613 vec[I_SHELL] -= shell;
615 /* Disabled autoloading of food onto units
616 max_amt = vl_find(V_FOOD, lp->l_vtype, lp->l_vamt, (int) lp->l_nv);
617 food_needed = (etu_per_update * eatrate) *
618 (vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW])+1;
619 if ((vec[I_FOOD]-max_amt) < food_needed)
620 max_amt = (vec[I_FOOD]-food_needed);
625 vec[I_FOOD] -= max_amt;
627 memset(lvec, 0, sizeof(lvec));
628 getvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
629 lvec[I_FOOD] += max_amt;
630 putvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
633 if (getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_INFECT)
634 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND);
635 putland(nstr.cur, &land);
636 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
638 pr("%s", prland(&land));
639 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
644 build_bridge(register struct sctstr *sp, register int *vec)
651 int nx, ny, i, good = 0;
655 if (opt_EASY_BRIDGES == 0) { /* must have a bridge head or tower */
656 if (sp->sct_type != SCT_BTOWER) {
657 if (sp->sct_type != SCT_BHEAD)
659 if (sp->sct_newtype != SCT_BHEAD)
666 for (i = 1; i <= 6; i++) {
668 nx = sp->sct_x + diroff[i][0];
669 ny = sp->sct_y + diroff[i][1];
670 getsect(nx, ny, §);
671 for (j = 1; j <= 6; j++) {
672 nx2 = sect.sct_x + diroff[j][0];
673 ny2 = sect.sct_y + diroff[j][1];
674 getsect(nx2, ny2, &s2);
675 if ((s2.sct_type != SCT_WATER) &&
676 (s2.sct_type != SCT_BSPAN))
683 pr("Bridges must be built adjacent to land or bridge towers.\n");
684 pr("No eligible sectors adjacent to this sector.\n");
687 } /* end EASY_BRIDGES */
690 if (sp->sct_effic < 60 && !player->god) {
691 pr("Sector %s is not 60%% efficient.\n",
692 xyas(sp->sct_x, sp->sct_y, player->cnum));
697 if (vec[I_HCM] < buil_bh) {
698 pr("%s only has %d unit%s of hcm,\n",
699 xyas(sp->sct_x, sp->sct_y, player->cnum),
700 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
701 pr("(a bridge span requires %d)\n", buil_bh);
704 } else if (!opt_NO_LCMS) {
705 if (vec[I_LCM] < buil_bh) {
706 pr("%s only has %d unit%s of lcm,\n",
707 xyas(sp->sct_x, sp->sct_y, player->cnum),
708 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
709 pr("(a bridge span requires %d)\n", buil_bh);
713 if (cash < buil_bc) {
714 pr("A span costs $%.2f to build; ", buil_bc);
715 pr("you only have %d.\n", cash);
718 w_p_eff = buil_bh * 2;
719 points = sp->sct_avail * 100 / w_p_eff;
721 pr("Not enough available work in %s to build a bridge\n",
722 xyas(sp->sct_x, sp->sct_y, player->cnum));
723 pr(" (%d available work required)\n", 1 + (w_p_eff * 20) / 100);
726 if (!player->argp[3]) {
727 pr("Bridge head at %s\n",
728 xyas(sp->sct_x, sp->sct_y, player->cnum));
729 nav_map(sp->sct_x, sp->sct_y, 1);
731 if (!(p = getstarg(player->argp[3], "build span in what direction? ", buf))
735 /* Sanity check time */
736 if (!check_sect_ok(sp))
739 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
740 pr("'%c' is not a valid direction...\n", *p);
744 newx = sp->sct_x + diroff[val][0];
745 newy = sp->sct_y + diroff[val][1];
746 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
747 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
750 if (opt_EASY_BRIDGES) {
753 for (i = 1; i <= 6; i++) {
755 nx = sect.sct_x + diroff[i][0];
756 ny = sect.sct_y + diroff[i][1];
757 getsect(nx, ny, &s2);
758 if ((s2.sct_type != SCT_WATER) && (s2.sct_type != SCT_BSPAN))
762 pr("Bridges must be built adjacent to land or bridge towers.\n");
763 pr("That sector is not adjacent to land or a bridge tower.\n");
766 } /* end EASY_BRIDGES */
767 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100;
768 player->dolcost += buil_bc;
770 sect.sct_type = SCT_BSPAN;
771 sect.sct_newtype = SCT_BSPAN;
775 sect.sct_defense = 0;
776 if (!opt_DEFENSE_INFRA)
777 sect.sct_defense = sect.sct_effic;
778 if (opt_MOB_ACCESS) {
779 time(§.sct_access);
780 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
784 putvar(V_MINE, 0, (s_char *)§, EF_SECTOR);
786 pr("Bridge span built over %s\n",
787 xyas(sect.sct_x, sect.sct_y, player->cnum));
789 vec[I_HCM] -= buil_bh;
790 else if (!opt_NO_LCMS)
791 vec[I_LCM] -= buil_bh;
796 build_nuke(register struct sctstr *sp, register struct nchrstr *np,
802 if (sp->sct_type != SCT_NUKE && !player->god) {
803 pr("Nuclear weapons must be built in nuclear plants.\n");
806 if (sp->sct_effic < 60 && !player->god) {
807 pr("Sector %s is not 60%% efficient.\n",
808 xyas(sp->sct_x, sp->sct_y, player->cnum));
811 if (vec[I_HCM] < np->n_hcm || vec[I_LCM] < np->n_lcm ||
812 vec[I_OIL] < np->n_oil || vec[I_RAD] < np->n_rad) {
813 pr("Not enough materials for a %s bomb in %s\n",
814 np->n_name, xyas(sp->sct_x, sp->sct_y, player->cnum));
815 pr("(%d hcm, %d lcm, %d oil, & %d rads).\n",
816 np->n_hcm, np->n_lcm, np->n_oil, np->n_rad);
819 if (cash < np->n_cost) {
820 pr("You need $%d, you only have %d.\n", np->n_cost, cash);
823 w_p_eff = np->n_rad + np->n_oil + np->n_lcm + np->n_hcm * 2;
824 points = sp->sct_avail * 100 / w_p_eff;
826 * XXX when nukes turn into units (or whatever), then
827 * make them start at 20%. Since they don't have efficiency
828 * now, we choose 20% as a "big" number.
831 pr("Not enough available work in %s to build a %s;\n",
832 xyas(sp->sct_x, sp->sct_y, player->cnum), np->n_name);
833 pr(" (%d available work required)\n", 1 + w_p_eff * 20 / 100);
836 if (!trechk(player->cnum, 0, NEWNUK))
838 if (!check_sect_ok(sp))
840 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100;
841 player->dolcost += np->n_cost;
843 nuk_add(sp->sct_x, sp->sct_y, np - nchr, 1);
844 vec[I_HCM] -= np->n_hcm;
845 vec[I_LCM] -= np->n_lcm;
846 vec[I_OIL] -= np->n_oil;
847 vec[I_RAD] -= np->n_rad;
848 pr("%s warhead created in %s\n", np->n_name,
849 xyas(sp->sct_x, sp->sct_y, player->cnum));
854 build_plane(register struct sctstr *sp, register struct plchrstr *pp,
855 register int *vec, int tlev)
859 struct nstr_item nstr;
860 float eff = ((float)PLANE_MINEFF / 100.0);
866 mil = roundavg(((double)pp->pl_crew * (double)eff));
867 /* Always use at least 1 mil to build a plane */
868 if (mil == 0 && pp->pl_crew > 0)
870 hcm = roundavg(((double)pp->pl_hcm * (double)eff));
871 lcm = roundavg(((double)pp->pl_lcm * (double)eff));
872 if (sp->sct_type != SCT_AIRPT && !player->god) {
873 pr("Planes must be built in airports.\n");
876 if (sp->sct_effic < 60 && !player->god) {
877 pr("Sector %s is not 60%% efficient.\n",
878 xyas(sp->sct_x, sp->sct_y, player->cnum));
881 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
882 pr("Not enough materials in %s\n",
883 xyas(sp->sct_x, sp->sct_y, player->cnum));
886 w_p_eff = (20 + pp->pl_lcm + (pp->pl_hcm * 2));
887 points = sp->sct_avail * 100 / w_p_eff;
888 if (points < PLANE_MINEFF) {
889 pr("Not enough available work in %s to build a %s\n",
890 xyas(sp->sct_x, sp->sct_y, player->cnum), pp->pl_name);
891 pr(" (%d available work required)\n",
892 1 + PLANE_MINEFF * w_p_eff / 100);
895 cost = pp->pl_cost * eff;
897 pr("Not enough money left to build a %s\n", pp->pl_name);
900 if (vec[I_MILIT] < mil || (vec[I_MILIT] == 0 && pp->pl_crew > 0)) {
901 pr("Not enough military for crew in %s\n",
902 xyas(sp->sct_x, sp->sct_y, player->cnum));
905 if (!trechk(player->cnum, 0, NEWPLN))
907 if (!check_sect_ok(sp))
909 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * PLANE_MINEFF) / 100;
910 player->dolcost += cost;
912 snxtitem_all(&nstr, EF_PLANE);
914 while (nxtitem(&nstr, (s_char *)&plane)) {
915 if (plane.pln_own == 0) {
920 if (freeplane == 0) {
921 ef_extend(EF_PLANE, 50);
923 memset(&plane, 0, sizeof(struct plnstr));
924 plane.pln_x = sp->sct_x;
925 plane.pln_y = sp->sct_y;
926 plane.pln_own = sp->sct_own;
927 plane.pln_type = pp - plchr;
928 plane.pln_effic = PLANE_MINEFF;
929 if (opt_MOB_ACCESS) {
930 time(&plane.pln_access);
931 plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
935 plane.pln_mission = 0;
938 plane.pln_radius = 0;
940 /* Note that this next block of variables can be changed so that individual
941 * planes may have their own stats (like based on tech maybe? :) ) Thus,
942 * the code now checks the pln_acc, pln_load and pln_fuel instead of using
943 * the static definitions of them. */
945 n = (int) (pp->pl_range * (0.75 + techfact(tlev - pp->pl_tech, 2.0)));
949 plane.pln_range_max = n;
950 n = (int) (pp->pl_att * (0.75 + techfact(tlev - pp->pl_tech, 2.0)));
954 n = (int) (pp->pl_def * (0.75 + techfact(tlev - pp->pl_tech, 2.0)));
960 plane.pln_acc = pp->pl_acc;
961 plane.pln_load = pp->pl_load;
962 plane.pln_fuel = pp->pl_fuel;
964 plane.pln_att = PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech));
965 plane.pln_def = PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech));
966 plane.pln_acc = PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech));
967 plane.pln_range = PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech));
968 plane.pln_range_max = plane.pln_range;
969 plane.pln_load = PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech));
970 plane.pln_fuel = pp->pl_fuel;
972 plane.pln_wing = ' ';
973 plane.pln_tech = tlev;
976 plane.pln_uid = nstr.cur;
977 plane.pln_nuketype = -1;
978 plane.pln_harden = 0;
981 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
983 putplane(plane.pln_uid, &plane);
984 pr("%s built in sector %s\n", prplane(&plane),
985 xyas(sp->sct_x, sp->sct_y, player->cnum));
993 build_tower(register struct sctstr *sp, register int *vec)
1007 if (sp->sct_type != SCT_BSPAN) {
1008 pr("Bridge towers can only be built from bridge spans.\n");
1012 if (sp->sct_effic < 60 && !player->god) {
1013 pr("Sector %s is not 60%% efficient.\n",
1014 xyas(sp->sct_x, sp->sct_y, player->cnum));
1019 if (vec[I_HCM] < buil_tower_bh) {
1020 pr("%s only has %d unit%s of hcm,\n",
1021 xyas(sp->sct_x, sp->sct_y, player->cnum),
1022 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
1023 pr("(a bridge tower requires %d)\n", buil_tower_bh);
1026 } else if (!opt_NO_LCMS) {
1027 if (vec[I_LCM] < buil_tower_bh) {
1028 pr("%s only has %d unit%s of lcm,\n",
1029 xyas(sp->sct_x, sp->sct_y, player->cnum),
1030 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
1031 pr("(a bridge tower requires %d)\n", buil_tower_bh);
1035 if (cash < buil_tower_bc) {
1036 pr("A bridge tower costs $%.2f to build; ", buil_tower_bc);
1037 pr("you only have %d.\n", cash);
1040 w_p_eff = buil_tower_bh * 2;
1041 points = sp->sct_avail * 100 / w_p_eff;
1043 pr("Not enough available work in %s to build a bridge tower\n",
1044 xyas(sp->sct_x, sp->sct_y, player->cnum));
1045 pr(" (%d available work required)\n", 1 + (w_p_eff * 20) / 100);
1048 if (!player->argp[3]) {
1049 pr("Building from %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
1050 nav_map(sp->sct_x, sp->sct_y, 1);
1052 if (!(p = getstarg(player->argp[3], "build tower in what direction? ", buf))
1056 /* Sanity check time */
1057 if (!check_sect_ok(sp))
1060 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
1061 pr("'%c' is not a valid direction...\n", *p);
1065 newx = sp->sct_x + diroff[val][0];
1066 newy = sp->sct_y + diroff[val][1];
1067 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
1068 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
1072 /* Now, check. You aren't allowed to build bridge towers
1075 for (i = 1; i <= 6; i++) {
1077 nx = sect.sct_x + diroff[i][0];
1078 ny = sect.sct_y + diroff[i][1];
1079 getsect(nx, ny, &s2);
1080 if ((s2.sct_type != SCT_WATER) &&
1081 (s2.sct_type != SCT_BTOWER) && (s2.sct_type != SCT_BSPAN)) {
1087 pr("Bridge towers cannot be built adjacent to land.\n");
1088 pr("That sector is adjacent to land.\n");
1092 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100;
1093 player->dolcost += buil_tower_bc;
1094 cash -= buil_tower_bc;
1095 sect.sct_type = SCT_BTOWER;
1096 sect.sct_newtype = SCT_BTOWER;
1097 sect.sct_effic = 20;
1100 sect.sct_defense = 0;
1101 if (opt_MOB_ACCESS) {
1102 time(§.sct_access);
1103 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
1107 if (!opt_DEFENSE_INFRA)
1108 sect.sct_defense = sect.sct_effic;
1109 putvar(V_MINE, 0, (s_char *)§, EF_SECTOR);
1111 pr("Bridge tower built in %s\n",
1112 xyas(sect.sct_x, sect.sct_y, player->cnum));
1114 vec[I_HCM] -= buil_tower_bh;
1115 else if (!opt_NO_LCMS)
1116 vec[I_LCM] -= buil_tower_bh;