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
56 static int build_nuke(register struct sctstr *sp,
57 register struct nchrstr *np, register int *vec);
58 static int build_ship(register struct sctstr *sp,
59 register struct mchrstr *mp, register int *vec,
61 static int build_land(register struct sctstr *sp,
62 register struct lchrstr *lp, register int *vec,
64 static int build_bridge(register struct sctstr *sp, register int *vec);
65 static int build_tower(register struct sctstr *sp, register int *vec);
66 static int build_plane(register struct sctstr *sp,
67 register struct plchrstr *pp, register int *vec,
70 static int cash; /* static ok */
75 extern int morale_base;
76 extern int sect_mob_neg_factor;
77 extern int etu_per_update;
80 * build <WHAT> <SECTS> <TYPE|DIR|MEG> [NUMBER]
85 extern double buil_bt;
86 extern double buil_tower_bt;
88 struct nstr_sect nstr;
104 int hold, found, number = 1, x;
105 extern float drnuke_const;
109 natp = getnatp(player->cnum);
111 getstarg(player->argp[1],
112 "Build (ship, nuke, bridge, plane, land unit, tower)? ",
117 for (x = 0; x < number; x++) {
118 if (!snxtsct(&nstr, player->argp[2])) {
119 pr("Bad sector specification.\n");
123 tlev = (int)natp->nat_level[NAT_TLEV];
124 rlev = (int)natp->nat_level[NAT_RLEV];
128 p = getstarg(player->argp[3], "Plane type? ", buf);
129 if (p == 0 || *p == 0)
132 while (n && iscntrl(p[n - 1]))
136 for (found = 0, type = 0, pp = plchr; type <= pln_maxno;
138 if (pp->pl_tech > tlev)
140 if (pp->pl_name && strncmp(p, pp->pl_name, n) == 0) {
147 pr("Illegal plane type: \"%s\"\n", p);
148 if (confirm("List plane types? "))
149 show_plane_build(tlev);
155 rqtech = pp->pl_tech;
158 p = getstarg(player->argp[3], "Ship type? ", buf);
159 if (p == 0 || *p == 0)
162 while (n && iscntrl(p[n - 1]))
166 for (found = 0, mp = mchr, type = 0; type <= shp_maxno;
168 if (mp->m_tech > tlev)
170 /* Can't build trade ships unless it's turned on */
171 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
173 if (mp->m_name && strncmp(p, mp->m_name, n) == 0) {
180 pr("Illegal ship type: \"%s\"\n", p);
181 if (confirm("List ship types? "))
182 show_ship_build(tlev);
191 p = getstarg(player->argp[3], "Land unit type? ", buf);
192 if (p == 0 || *p == 0)
195 while (n && iscntrl(p[n - 1]))
199 for (found = 0, lp = lchr, type = 0; type <= lnd_maxno;
201 if (lp->l_tech > tlev)
203 if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
205 if (lp->l_name && strncmp(p, lp->l_name, n) == 0) {
212 pr("Illegal land unit type: \"%s\"\n", p);
213 if (confirm("List unit types? "))
214 show_land_build(tlev);
223 if (natp->nat_level[NAT_TLEV] + 0.005 < buil_bt) {
224 pr("Building a span requires a tech of %.0f\n", buil_bt);
229 if (!opt_BRIDGETOWERS) {
230 pr("Bridge tower building is disabled.\n");
233 if (natp->nat_level[NAT_TLEV] + 0.005 < buil_tower_bt) {
234 pr("Building a tower requires a tech of %.0f\n",
241 pr("There are no nukes in this game.\n");
244 p = getstarg(player->argp[3], "Nuke type? ", buf);
245 if (p == 0 || *p == 0)
248 while (n && iscntrl(p[n - 1]))
252 for (found = 0, np = nchr, type = 0; type < nuk_maxno;
254 if ((np->n_tech > tlev)
256 && ((np->n_tech * drnuke_const) > rlev)))
258 if (opt_NEUTRON == 0 && (np->n_flags & N_NEUT))
261 if (np->n_name && strncmp(p, np->n_name, n) == 0) {
269 pr("Possible nuke types are:\n");
271 tt = (tlev < (rlev / drnuke_const) ? (int)tlev :
272 (int)(rlev / drnuke_const));
283 pr("You can't build that!\n");
286 if (what != 'b' && what != 't') {
287 if (player->argp[4]) {
288 if (atoi(player->argp[4]) > 20 && !asked) {
292 "Are you sure that you want to build %s of them? ",
294 p = getstarg(player->argp[6], bstr, buf);
295 if (p == 0 || *p != 'y')
298 number = atoi(player->argp[4]);
301 if (what != 'b' && what != 'n' && what != 't') {
302 if (player->argp[5]) {
303 tlev = atoi(player->argp[5]);
304 if (tlev > natp->nat_level[NAT_TLEV] && !player->god) {
305 pr("Your tech level is only %d.\n",
306 (int)natp->nat_level[NAT_TLEV]);
310 pr("Required tech is %d.\n", rqtech);
313 pr("building with tech level %d.\n", tlev);
315 tlev = (int)natp->nat_level[NAT_TLEV];
317 cash = natp->nat_money;
318 while (nxtsct(&nstr, §)) {
322 getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
325 built = build_land(§, lp, vec, tlev);
328 built = build_ship(§, mp, vec, tlev);
331 built = build_bridge(§, vec);
334 built = build_tower(§, vec);
337 built = build_nuke(§, np, vec);
340 built = build_plane(§, pp, vec, tlev);
343 pr("internal error in build (%d)\n", what);
347 putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
353 pr("Bad sector specification.\n");
359 build_ship(register struct sctstr *sp, register struct mchrstr *mp,
360 register int *vec, int tlev)
363 struct nstr_item nstr;
366 float eff = ((float)SHIP_MINEFF / 100.0);
367 int points, lcm, hcm;
371 hcm = roundavg(((double)mp->m_hcm * (double)eff));
372 lcm = roundavg(((double)mp->m_lcm * (double)eff));
374 if (sp->sct_type != SCT_HARBR) {
375 pr("Ships must be built in harbours.\n");
378 if (sp->sct_effic < 60 && !player->god) {
379 pr("Sector %s is not 60%% efficient.\n",
380 xyas(sp->sct_x, sp->sct_y, player->cnum));
383 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
384 pr("Not enough materials in %s\n",
385 xyas(sp->sct_x, sp->sct_y, player->cnum));
388 w_p_eff = (20 + mp->m_lcm + (mp->m_hcm * 2));
389 points = sp->sct_avail * 100 / w_p_eff;
390 if (points < SHIP_MINEFF) {
391 pr("Not enough available work in %s to build a %s\n",
392 xyas(sp->sct_x, sp->sct_y, player->cnum), mp->m_name);
393 pr(" (%d available work required)\n",
394 1 + (w_p_eff * SHIP_MINEFF) / 100);
397 cost = mp->m_cost * eff;
399 pr("Not enough money left to build a %s\n", mp->m_name);
402 if (!trechk(player->cnum, 0, NEWSHP))
404 if (!check_sect_ok(sp))
406 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * SHIP_MINEFF) / 100;
407 player->dolcost += cost;
409 snxtitem_all(&nstr, EF_SHIP);
410 while (nxtitem(&nstr, (s_char *)&ship)) {
411 if (ship.shp_own == 0) {
417 ef_extend(EF_SHIP, 50);
419 bzero(&ship, sizeof(struct shpstr));
420 ship.shp_x = sp->sct_x;
421 ship.shp_y = sp->sct_y;
422 ship.shp_destx[0] = sp->sct_x;
423 ship.shp_desty[0] = sp->sct_y;
424 ship.shp_destx[1] = sp->sct_x;
425 ship.shp_desty[1] = sp->sct_y;
426 ship.shp_autonav = 0;
427 /* new code for autonav, Chad Zabel 1-15-94 */
428 for (i = 0; i < TMAX; ++i) {
429 ship.shp_tstart[i] = ' ';
430 ship.shp_tend[i] = ' ';
431 ship.shp_lstart[i] = 0;
432 ship.shp_lend[i] = 0;
434 ship.shp_mission = 0;
435 ship.shp_own = player->cnum;
436 ship.shp_type = mp - mchr;
437 ship.shp_effic = SHIP_MINEFF;
438 if (opt_MOB_ACCESS) {
439 time(&ship.shp_access);
440 ship.shp_mobil = -(etu_per_update / sect_mob_neg_factor);
444 ship.shp_uid = nstr.cur;
447 ship.shp_nxlight = 0;
448 ship.shp_nchoppers = 0;
449 ship.shp_fleet = ' ';
452 ship.shp_tech = tlev;
454 techdiff = (int)(tlev - mp->m_tech);
455 ship.shp_armor = (short)SHP_DEF(mp->m_armor, techdiff);
456 ship.shp_speed = (short)SHP_SPD(mp->m_speed, techdiff);
457 ship.shp_visib = (short)SHP_VIS(mp->m_visib, techdiff);
458 ship.shp_frnge = (short)SHP_RNG(mp->m_frnge, techdiff);
459 ship.shp_glim = (short)SHP_FIR(mp->m_glim, techdiff);
461 ship.shp_mobquota = 0;
463 ship.shp_follow = nstr.cur;
464 ship.shp_name[0] = 0;
465 ship.shp_orig_own = player->cnum;
466 ship.shp_orig_x = sp->sct_x;
467 ship.shp_orig_y = sp->sct_y;
468 ship.shp_fuel = mchr[(int)ship.shp_type].m_fuelc;
470 for (x = 0; x < 10; x++)
471 ship.shp_rpath[x] = 0;
476 if (getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_INFECT)
477 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP);
478 makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x,
480 putship(ship.shp_uid, &ship);
481 pr("%s", prship(&ship));
482 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
487 build_land(register struct sctstr *sp, register struct lchrstr *lp,
488 register int *vec, int tlev)
491 struct nstr_item nstr;
496 float eff = ((float)LAND_MINEFF / 100.0);
497 double techfact(int, double);
498 int mil, lcm, hcm, gun, shell;
502 mil = roundavg(((double)lp->l_mil * (double)eff));
503 shell = roundavg(((double)lp->l_shell * (double)eff));
504 gun = roundavg(((double)lp->l_gun * (double)eff));
506 mil = shell = gun = 0;
507 hcm = roundavg(((double)lp->l_hcm * (double)eff));
508 lcm = roundavg(((double)lp->l_lcm * (double)eff));
510 natp = getnatp(player->cnum);
512 if (sp->sct_type != SCT_HEADQ) {
513 pr("Land Units must be built in headquarters.\n");
516 if (sp->sct_effic < 60 && !player->god) {
517 pr("Sector %s is not 60%% efficient.\n",
518 xyas(sp->sct_x, sp->sct_y, player->cnum));
521 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
522 pr("Not enough materials in %s\n",
523 xyas(sp->sct_x, sp->sct_y, player->cnum));
527 if (vec[I_GUN] < gun || vec[I_GUN] == 0) {
528 pr("Not enough guns in %s\n",
529 xyas(sp->sct_x, sp->sct_y, player->cnum));
532 if (vec[I_SHELL] < shell) {
533 pr("Not enough shells in %s\n",
534 xyas(sp->sct_x, sp->sct_y, player->cnum));
537 if (vec[I_MILIT] < mil) {
538 pr("Not enough military in %s\n",
539 xyas(sp->sct_x, sp->sct_y, player->cnum));
543 if (!trechk(player->cnum, 0, NEWLND))
545 if (!check_sect_ok(sp))
547 w_p_eff = (20 + lp->l_lcm + (lp->l_hcm * 2));
548 points = sp->sct_avail * 100 / w_p_eff;
549 if (points < LAND_MINEFF) {
550 pr("Not enough available work in %s to build a %s\n",
551 xyas(sp->sct_x, sp->sct_y, player->cnum), lp->l_name);
552 pr(" (%d available work required)\n",
553 1 + (w_p_eff * LAND_MINEFF) / 100);
556 cost = ((float)lp->l_cost * eff);
557 /* cost = (int)LND_COST(cost, tlev - lp->l_tech); */
559 pr("Not enough money left to build a %s\n", lp->l_name);
562 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * LAND_MINEFF) / 100;
563 player->dolcost += cost;
565 snxtitem_all(&nstr, EF_LAND);
566 while (nxtitem(&nstr, (s_char *)&land)) {
567 if (land.lnd_own == 0) {
573 ef_extend(EF_LAND, 50);
575 bzero(&land, sizeof(struct lndstr));
576 land.lnd_x = sp->sct_x;
577 land.lnd_y = sp->sct_y;
578 land.lnd_own = player->cnum;
579 land.lnd_mission = 0;
580 land.lnd_type = lp - lchr;
581 land.lnd_effic = LAND_MINEFF;
582 if (opt_MOB_ACCESS) {
583 time(&land.lnd_access);
584 land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
589 land.lnd_tech = tlev;
590 land.lnd_uid = nstr.cur;
597 land.lnd_retreat = morale_base;
598 land.lnd_fuel = lp->l_fuelc;
599 land.lnd_nxlight = 0;
601 bzero(land.lnd_rpath, 10);
602 land.lnd_rad_max = 0;
604 land.lnd_att = (float)LND_ATTDEF(lp->l_att, tlev - lp->l_tech);
605 land.lnd_def = (float)LND_ATTDEF(lp->l_def, tlev - lp->l_tech);
606 land.lnd_vul = (int)LND_VUL(lp->l_vul, tlev - lp->l_tech);
607 land.lnd_spd = (int)LND_SPD(lp->l_spd, tlev - lp->l_tech);
608 land.lnd_vis = (int)LND_VIS(lp->l_vis, tlev - lp->l_tech);
609 land.lnd_spy = (int)LND_SPY(lp->l_spy, tlev - lp->l_tech);
610 land.lnd_rad = (int)LND_RAD(lp->l_rad, tlev - lp->l_tech);
611 land.lnd_frg = (int)LND_FRG(lp->l_frg, tlev - lp->l_tech);
612 land.lnd_acc = (int)LND_ACC(lp->l_acc, tlev - lp->l_tech);
613 land.lnd_dam = (int)LND_DAM(lp->l_dam, tlev - lp->l_tech);
614 land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, tlev - lp->l_tech);
615 land.lnd_aaf = (int)LND_AAF(lp->l_aaf, tlev - lp->l_tech);
616 land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, tlev - lp->l_tech);
617 land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, tlev - lp->l_tech);
618 land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech);
619 land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech);
625 vec[I_SHELL] -= shell;
627 /* Disabled autoloading of food onto units
628 max_amt = vl_find(V_FOOD, lp->l_vtype, lp->l_vamt, (int) lp->l_nv);
629 food_needed = (etu_per_update * eatrate) *
630 (vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW])+1;
631 if ((vec[I_FOOD]-max_amt) < food_needed)
632 max_amt = (vec[I_FOOD]-food_needed);
637 vec[I_FOOD] -= max_amt;
639 bzero(lvec, sizeof(lvec));
640 getvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
641 lvec[I_FOOD] += max_amt;
642 putvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
645 if (getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_INFECT)
646 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND);
647 putland(nstr.cur, &land);
648 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
650 pr("%s", prland(&land));
651 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
657 build_bridge(register struct sctstr *sp, register int *vec)
660 extern double buil_bc;
666 int nx, ny, i, good = 0;
670 if (opt_EASY_BRIDGES == 0) { /* must have a bridge head or tower */
671 if (sp->sct_type != SCT_BTOWER) {
672 if (sp->sct_type != SCT_BHEAD)
674 if (sp->sct_newtype != SCT_BHEAD)
681 for (i = 1; i <= 6; i++) {
683 nx = sp->sct_x + diroff[i][0];
684 ny = sp->sct_y + diroff[i][1];
685 getsect(nx, ny, §);
686 for (j = 1; j <= 6; j++) {
687 nx2 = sect.sct_x + diroff[j][0];
688 ny2 = sect.sct_y + diroff[j][1];
689 getsect(nx2, ny2, &s2);
690 if ((s2.sct_type != SCT_WATER) &&
691 (s2.sct_type != SCT_BSPAN))
698 pr("Bridges must be built adjacent to land or bridge towers.\n");
699 pr("No eligible sectors adjacent to this sector.\n");
702 } /* end EASY_BRIDGES */
705 if (sp->sct_effic < 60 && !player->god) {
706 pr("Sector %s is not 60%% efficient.\n",
707 xyas(sp->sct_x, sp->sct_y, player->cnum));
712 if (vec[I_HCM] < buil_bh) {
713 pr("%s only has %d unit%s of hcm,\n",
714 xyas(sp->sct_x, sp->sct_y, player->cnum),
715 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
716 pr("(a bridge span requires %d)\n", buil_bh);
719 } else if (!opt_NO_LCMS) {
720 if (vec[I_LCM] < buil_bh) {
721 pr("%s only has %d unit%s of lcm,\n",
722 xyas(sp->sct_x, sp->sct_y, player->cnum),
723 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
724 pr("(a bridge span requires %d)\n", buil_bh);
728 if (cash < buil_bc) {
729 pr("A span costs $%.2f to build; ", buil_bc);
730 pr("you only have %d.\n", cash);
733 w_p_eff = buil_bh * 2;
734 points = sp->sct_avail * 100 / w_p_eff;
736 pr("Not enough available work in %s to build a bridge\n",
737 xyas(sp->sct_x, sp->sct_y, player->cnum));
738 pr(" (%d available work required)\n", 1 + (w_p_eff * 20) / 100);
741 if (!player->argp[3]) {
742 pr("Bridge head at %s\n",
743 xyas(sp->sct_x, sp->sct_y, player->cnum));
744 nav_map(sp->sct_x, sp->sct_y, 1);
748 getstarg(player->argp[3], "build span in what direction? ", buf))
752 /* Sanity check time */
753 if (!check_sect_ok(sp))
756 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
757 pr("'%c' is not a valid direction...\n", *p);
761 newx = sp->sct_x + diroff[val][0];
762 newy = sp->sct_y + diroff[val][1];
763 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
764 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
767 if (opt_EASY_BRIDGES) {
770 for (i = 1; i <= 6; i++) {
772 nx = sect.sct_x + diroff[i][0];
773 ny = sect.sct_y + diroff[i][1];
774 getsect(nx, ny, &s2);
775 if ((s2.sct_type != SCT_WATER) && (s2.sct_type != SCT_BSPAN))
779 pr("Bridges must be built adjacent to land or bridge towers.\n");
780 pr("That sector is not adjacent to land or a bridge tower.\n");
783 } /* end EASY_BRIDGES */
784 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100;
785 player->dolcost += buil_bc;
787 sect.sct_type = SCT_BSPAN;
788 sect.sct_newtype = SCT_BSPAN;
792 sect.sct_defense = 0;
793 if (!opt_DEFENSE_INFRA)
794 sect.sct_defense = sect.sct_effic;
795 if (opt_MOB_ACCESS) {
796 time(§.sct_access);
797 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
801 putvar(V_MINE, 0, (s_char *)§, EF_SECTOR);
803 pr("Bridge span built over %s\n",
804 xyas(sect.sct_x, sect.sct_y, player->cnum));
806 vec[I_HCM] -= buil_bh;
807 else if (!opt_NO_LCMS)
808 vec[I_LCM] -= buil_bh;
814 build_nuke(register struct sctstr *sp, register struct nchrstr *np,
820 if (sp->sct_type != SCT_NUKE && !player->god) {
821 pr("Nuclear weapons must be built in nuclear plants.\n");
824 if (sp->sct_effic < 60 && !player->god) {
825 pr("Sector %s is not 60%% efficient.\n",
826 xyas(sp->sct_x, sp->sct_y, player->cnum));
829 if (vec[I_HCM] < np->n_hcm || vec[I_LCM] < np->n_lcm ||
830 vec[I_OIL] < np->n_oil || vec[I_RAD] < np->n_rad) {
831 pr("Not enough materials for a %s bomb in %s\n",
832 np->n_name, xyas(sp->sct_x, sp->sct_y, player->cnum));
833 pr("(%d hcm, %d lcm, %d oil, & %d rads).\n",
834 np->n_hcm, np->n_lcm, np->n_oil, np->n_rad);
837 if (cash < np->n_cost) {
838 pr("You need $%d, you only have %d.\n", np->n_cost, cash);
841 w_p_eff = np->n_rad + np->n_oil + np->n_lcm + np->n_hcm * 2;
842 points = sp->sct_avail * 100 / w_p_eff;
844 * XXX when nukes turn into units (or whatever), then
845 * make them start at 20%. Since they don't have efficiency
846 * now, we choose 20% as a "big" number.
849 pr("Not enough available work in %s to build a %s;\n",
850 xyas(sp->sct_x, sp->sct_y, player->cnum), np->n_name);
851 pr(" (%d available work required)\n", 1 + w_p_eff * 20 / 100);
854 if (!trechk(player->cnum, 0, NEWNUK))
856 if (!check_sect_ok(sp))
858 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100;
859 player->dolcost += np->n_cost;
861 nuk_add(sp->sct_x, sp->sct_y, np - nchr, 1);
862 vec[I_HCM] -= np->n_hcm;
863 vec[I_LCM] -= np->n_lcm;
864 vec[I_OIL] -= np->n_oil;
865 vec[I_RAD] -= np->n_rad;
866 pr("%s warhead created in %s\n", np->n_name,
867 xyas(sp->sct_x, sp->sct_y, player->cnum));
873 build_plane(register struct sctstr *sp, register struct plchrstr *pp,
874 register int *vec, int tlev)
878 struct nstr_item nstr;
879 float eff = ((float)PLANE_MINEFF / 100.0);
885 mil = roundavg(((double)pp->pl_crew * (double)eff));
886 /* Always use at least 1 mil to build a plane */
887 if (mil == 0 && pp->pl_crew > 0)
889 hcm = roundavg(((double)pp->pl_hcm * (double)eff));
890 lcm = roundavg(((double)pp->pl_lcm * (double)eff));
891 if (sp->sct_type != SCT_AIRPT && !player->god) {
892 pr("Planes must be built in airports.\n");
895 if (sp->sct_effic < 60 && !player->god) {
896 pr("Sector %s is not 60%% efficient.\n",
897 xyas(sp->sct_x, sp->sct_y, player->cnum));
900 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
901 pr("Not enough materials in %s\n",
902 xyas(sp->sct_x, sp->sct_y, player->cnum));
905 w_p_eff = (20 + pp->pl_lcm + (pp->pl_hcm * 2));
906 points = sp->sct_avail * 100 / w_p_eff;
907 if (points < PLANE_MINEFF) {
908 pr("Not enough available work in %s to build a %s\n",
909 xyas(sp->sct_x, sp->sct_y, player->cnum), pp->pl_name);
910 pr(" (%d available work required)\n",
911 1 + PLANE_MINEFF * w_p_eff / 100);
914 cost = pp->pl_cost * eff;
916 pr("Not enough money left to build a %s\n", pp->pl_name);
919 if (vec[I_MILIT] < mil || (vec[I_MILIT] == 0 && pp->pl_crew > 0)) {
920 pr("Not enough military for crew in %s\n",
921 xyas(sp->sct_x, sp->sct_y, player->cnum));
924 if (!trechk(player->cnum, 0, NEWPLN))
926 if (!check_sect_ok(sp))
928 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * PLANE_MINEFF) / 100;
929 player->dolcost += cost;
931 snxtitem_all(&nstr, EF_PLANE);
933 while (nxtitem(&nstr, (s_char *)&plane)) {
934 if (plane.pln_own == 0) {
939 if (freeplane == 0) {
940 ef_extend(EF_PLANE, 50);
942 bzero(&plane, sizeof(struct plnstr));
943 plane.pln_x = sp->sct_x;
944 plane.pln_y = sp->sct_y;
945 plane.pln_own = sp->sct_own;
946 plane.pln_type = pp - plchr;
947 plane.pln_effic = PLANE_MINEFF;
948 if (opt_MOB_ACCESS) {
949 time(&plane.pln_access);
950 plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
954 plane.pln_mission = 0;
957 plane.pln_radius = 0;
959 /* Note that this next block of variables can be changed so that individual
960 * planes may have their own stats (like based on tech maybe? :) ) Thus,
961 * the code now checks the pln_acc, pln_load and pln_fuel instead of using
962 * the static definitions of them. */
964 n = (int) (pp->pl_range * (0.75 + techfact(tlev - pp->pl_tech, 2.0)));
968 plane.pln_range_max = n;
969 n = (int) (pp->pl_att * (0.75 + techfact(tlev - pp->pl_tech, 2.0)));
973 n = (int) (pp->pl_def * (0.75 + techfact(tlev - pp->pl_tech, 2.0)));
979 plane.pln_acc = pp->pl_acc;
980 plane.pln_load = pp->pl_load;
981 plane.pln_fuel = pp->pl_fuel;
983 plane.pln_att = PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech));
984 plane.pln_def = PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech));
985 plane.pln_acc = PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech));
986 plane.pln_range = PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech));
987 plane.pln_range_max = plane.pln_range;
988 plane.pln_load = PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech));
989 plane.pln_fuel = pp->pl_fuel;
991 plane.pln_wing = ' ';
992 plane.pln_tech = tlev;
995 plane.pln_uid = nstr.cur;
996 plane.pln_nuketype = -1;
997 plane.pln_harden = 0;
1000 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
1002 putplane(plane.pln_uid, &plane);
1003 pr("%s built in sector %s\n", prplane(&plane),
1004 xyas(sp->sct_x, sp->sct_y, player->cnum));
1007 vec[I_MILIT] -= mil;
1013 build_tower(register struct sctstr *sp, register int *vec)
1015 extern int buil_tower_bh;
1016 extern double buil_tower_bc;
1029 if (sp->sct_type != SCT_BSPAN) {
1030 pr("Bridge towers can only be built from bridge spans.\n");
1034 if (sp->sct_effic < 60 && !player->god) {
1035 pr("Sector %s is not 60%% efficient.\n",
1036 xyas(sp->sct_x, sp->sct_y, player->cnum));
1041 if (vec[I_HCM] < buil_tower_bh) {
1042 pr("%s only has %d unit%s of hcm,\n",
1043 xyas(sp->sct_x, sp->sct_y, player->cnum),
1044 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
1045 pr("(a bridge tower requires %d)\n", buil_tower_bh);
1048 } else if (!opt_NO_LCMS) {
1049 if (vec[I_LCM] < buil_tower_bh) {
1050 pr("%s only has %d unit%s of lcm,\n",
1051 xyas(sp->sct_x, sp->sct_y, player->cnum),
1052 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
1053 pr("(a bridge tower requires %d)\n", buil_tower_bh);
1057 if (cash < buil_tower_bc) {
1058 pr("A bridge tower costs $%.2f to build; ", buil_tower_bc);
1059 pr("you only have %d.\n", cash);
1062 w_p_eff = buil_tower_bh * 2;
1063 points = sp->sct_avail * 100 / w_p_eff;
1065 pr("Not enough available work in %s to build a bridge tower\n",
1066 xyas(sp->sct_x, sp->sct_y, player->cnum));
1067 pr(" (%d available work required)\n", 1 + (w_p_eff * 20) / 100);
1070 if (!player->argp[3]) {
1071 pr("Building from %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
1072 nav_map(sp->sct_x, sp->sct_y, 1);
1076 getstarg(player->argp[3], "build tower in what direction? ", buf))
1080 /* Sanity check time */
1081 if (!check_sect_ok(sp))
1084 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
1085 pr("'%c' is not a valid direction...\n", *p);
1089 newx = sp->sct_x + diroff[val][0];
1090 newy = sp->sct_y + diroff[val][1];
1091 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
1092 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
1096 /* Now, check. You aren't allowed to build bridge towers
1099 for (i = 1; i <= 6; i++) {
1101 nx = sect.sct_x + diroff[i][0];
1102 ny = sect.sct_y + diroff[i][1];
1103 getsect(nx, ny, &s2);
1104 if ((s2.sct_type != SCT_WATER) &&
1105 (s2.sct_type != SCT_BTOWER) && (s2.sct_type != SCT_BSPAN)) {
1111 pr("Bridge towers cannot be built adjacent to land.\n");
1112 pr("That sector is adjacent to land.\n");
1116 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100;
1117 player->dolcost += buil_tower_bc;
1118 cash -= buil_tower_bc;
1119 sect.sct_type = SCT_BTOWER;
1120 sect.sct_newtype = SCT_BTOWER;
1121 sect.sct_effic = 20;
1124 sect.sct_defense = 0;
1125 if (opt_MOB_ACCESS) {
1126 time(§.sct_access);
1127 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
1131 if (!opt_DEFENSE_INFRA)
1132 sect.sct_defense = sect.sct_effic;
1133 putvar(V_MINE, 0, (s_char *)§, EF_SECTOR);
1135 pr("Bridge tower built in %s\n",
1136 xyas(sect.sct_x, sect.sct_y, player->cnum));
1138 vec[I_HCM] -= buil_tower_bh;
1139 else if (!opt_NO_LCMS)
1140 vec[I_LCM] -= buil_tower_bh;