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 */
71 extern int morale_base;
72 extern int sect_mob_neg_factor;
73 extern int etu_per_update;
76 * build <WHAT> <SECTS> <TYPE|DIR|MEG> [NUMBER]
82 struct nstr_sect nstr;
98 int hold, found, number = 1, x;
102 natp = getnatp(player->cnum);
104 getstarg(player->argp[1],
105 "Build (ship, nuke, bridge, plane, land unit, tower)? ",
110 for (x = 0; x < number; x++) {
111 if (!snxtsct(&nstr, player->argp[2])) {
112 pr("Bad sector specification.\n");
116 tlev = (int)natp->nat_level[NAT_TLEV];
117 rlev = (int)natp->nat_level[NAT_RLEV];
121 p = getstarg(player->argp[3], "Plane type? ", buf);
122 if (p == 0 || *p == 0)
125 while (n && iscntrl(p[n - 1]))
129 for (found = 0, type = 0, pp = plchr; type <= pln_maxno;
131 if (pp->pl_tech > tlev)
133 if (pp->pl_name && strncmp(p, pp->pl_name, n) == 0) {
140 pr("Illegal plane type: \"%s\"\n", p);
141 if (confirm("List plane types? "))
142 show_plane_build(tlev);
148 rqtech = pp->pl_tech;
151 p = getstarg(player->argp[3], "Ship type? ", buf);
152 if (p == 0 || *p == 0)
155 while (n && iscntrl(p[n - 1]))
159 for (found = 0, mp = mchr, type = 0; type <= shp_maxno;
161 if (mp->m_tech > tlev)
163 /* Can't build trade ships unless it's turned on */
164 if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS)
166 if (mp->m_name && strncmp(p, mp->m_name, n) == 0) {
173 pr("Illegal ship type: \"%s\"\n", p);
174 if (confirm("List ship types? "))
175 show_ship_build(tlev);
184 p = getstarg(player->argp[3], "Land unit type? ", buf);
185 if (p == 0 || *p == 0)
188 while (n && iscntrl(p[n - 1]))
192 for (found = 0, lp = lchr, type = 0; type <= lnd_maxno;
194 if (lp->l_tech > tlev)
196 if ((lp->l_flags & L_SPY) && !opt_LANDSPIES)
198 if (lp->l_name && strncmp(p, lp->l_name, n) == 0) {
205 pr("Illegal land unit type: \"%s\"\n", p);
206 if (confirm("List unit types? "))
207 show_land_build(tlev);
216 if (natp->nat_level[NAT_TLEV] + 0.005 < buil_bt) {
217 pr("Building a span requires a tech of %.0f\n", buil_bt);
222 if (!opt_BRIDGETOWERS) {
223 pr("Bridge tower building is disabled.\n");
226 if (natp->nat_level[NAT_TLEV] + 0.005 < buil_tower_bt) {
227 pr("Building a tower requires a tech of %.0f\n",
234 pr("There are no nukes in this game.\n");
237 p = getstarg(player->argp[3], "Nuke type? ", buf);
238 if (p == 0 || *p == 0)
241 while (n && iscntrl(p[n - 1]))
245 for (found = 0, np = nchr, type = 0; type < nuk_maxno;
247 if ((np->n_tech > tlev)
249 && ((np->n_tech * drnuke_const) > rlev)))
251 if (opt_NEUTRON == 0 && (np->n_flags & N_NEUT))
254 if (np->n_name && strncmp(p, np->n_name, n) == 0) {
262 pr("Possible nuke types are:\n");
264 tt = (tlev < (rlev / drnuke_const) ? (int)tlev :
265 (int)(rlev / drnuke_const));
276 pr("You can't build that!\n");
279 if (what != 'b' && what != 't') {
280 if (player->argp[4]) {
281 if (atoi(player->argp[4]) > 20 && !asked) {
285 "Are you sure that you want to build %s of them? ",
287 p = getstarg(player->argp[6], bstr, buf);
288 if (p == 0 || *p != 'y')
291 number = atoi(player->argp[4]);
294 if (what != 'b' && what != 'n' && what != 't') {
295 if (player->argp[5]) {
296 tlev = atoi(player->argp[5]);
297 if (tlev > natp->nat_level[NAT_TLEV] && !player->god) {
298 pr("Your tech level is only %d.\n",
299 (int)natp->nat_level[NAT_TLEV]);
303 pr("Required tech is %d.\n", rqtech);
306 pr("building with tech level %d.\n", tlev);
308 tlev = (int)natp->nat_level[NAT_TLEV];
310 cash = natp->nat_money;
311 while (nxtsct(&nstr, §)) {
315 getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
318 built = build_land(§, lp, vec, tlev);
321 built = build_ship(§, mp, vec, tlev);
324 built = build_bridge(§, vec);
327 built = build_tower(§, vec);
330 built = build_nuke(§, np, vec);
333 built = build_plane(§, pp, vec, tlev);
336 pr("internal error in build (%d)\n", what);
340 putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
346 pr("Bad sector specification.\n");
352 build_ship(register struct sctstr *sp, register struct mchrstr *mp,
353 register int *vec, int tlev)
356 struct nstr_item nstr;
359 float eff = ((float)SHIP_MINEFF / 100.0);
360 int points, lcm, hcm;
364 hcm = roundavg(((double)mp->m_hcm * (double)eff));
365 lcm = roundavg(((double)mp->m_lcm * (double)eff));
367 if (sp->sct_type != SCT_HARBR) {
368 pr("Ships must be built in harbours.\n");
371 if (sp->sct_effic < 60 && !player->god) {
372 pr("Sector %s is not 60%% efficient.\n",
373 xyas(sp->sct_x, sp->sct_y, player->cnum));
376 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
377 pr("Not enough materials in %s\n",
378 xyas(sp->sct_x, sp->sct_y, player->cnum));
381 w_p_eff = (20 + mp->m_lcm + (mp->m_hcm * 2));
382 points = sp->sct_avail * 100 / w_p_eff;
383 if (points < SHIP_MINEFF) {
384 pr("Not enough available work in %s to build a %s\n",
385 xyas(sp->sct_x, sp->sct_y, player->cnum), mp->m_name);
386 pr(" (%d available work required)\n",
387 1 + (w_p_eff * SHIP_MINEFF) / 100);
390 cost = mp->m_cost * eff;
392 pr("Not enough money left to build a %s\n", mp->m_name);
395 if (!trechk(player->cnum, 0, NEWSHP))
397 if (!check_sect_ok(sp))
399 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * SHIP_MINEFF) / 100;
400 player->dolcost += cost;
402 snxtitem_all(&nstr, EF_SHIP);
403 while (nxtitem(&nstr, (s_char *)&ship)) {
404 if (ship.shp_own == 0) {
410 ef_extend(EF_SHIP, 50);
412 memset(&ship, 0, sizeof(struct shpstr));
413 ship.shp_x = sp->sct_x;
414 ship.shp_y = sp->sct_y;
415 ship.shp_destx[0] = sp->sct_x;
416 ship.shp_desty[0] = sp->sct_y;
417 ship.shp_destx[1] = sp->sct_x;
418 ship.shp_desty[1] = sp->sct_y;
419 ship.shp_autonav = 0;
420 /* new code for autonav, Chad Zabel 1-15-94 */
421 for (i = 0; i < TMAX; ++i) {
422 ship.shp_tstart[i] = ' ';
423 ship.shp_tend[i] = ' ';
424 ship.shp_lstart[i] = 0;
425 ship.shp_lend[i] = 0;
427 ship.shp_mission = 0;
428 ship.shp_own = player->cnum;
429 ship.shp_type = mp - mchr;
430 ship.shp_effic = SHIP_MINEFF;
431 if (opt_MOB_ACCESS) {
432 time(&ship.shp_access);
433 ship.shp_mobil = -(etu_per_update / sect_mob_neg_factor);
437 ship.shp_uid = nstr.cur;
440 ship.shp_nxlight = 0;
441 ship.shp_nchoppers = 0;
442 ship.shp_fleet = ' ';
445 ship.shp_tech = tlev;
447 techdiff = (int)(tlev - mp->m_tech);
448 ship.shp_armor = (short)SHP_DEF(mp->m_armor, techdiff);
449 ship.shp_speed = (short)SHP_SPD(mp->m_speed, techdiff);
450 ship.shp_visib = (short)SHP_VIS(mp->m_visib, techdiff);
451 ship.shp_frnge = (short)SHP_RNG(mp->m_frnge, techdiff);
452 ship.shp_glim = (short)SHP_FIR(mp->m_glim, techdiff);
454 ship.shp_mobquota = 0;
456 ship.shp_follow = nstr.cur;
457 ship.shp_name[0] = 0;
458 ship.shp_orig_own = player->cnum;
459 ship.shp_orig_x = sp->sct_x;
460 ship.shp_orig_y = sp->sct_y;
461 ship.shp_fuel = mchr[(int)ship.shp_type].m_fuelc;
463 for (x = 0; x < 10; x++)
464 ship.shp_rpath[x] = 0;
469 if (getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_INFECT)
470 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP);
471 makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x,
473 putship(ship.shp_uid, &ship);
474 pr("%s", prship(&ship));
475 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
480 build_land(register struct sctstr *sp, register struct lchrstr *lp,
481 register int *vec, int tlev)
484 struct nstr_item nstr;
489 float eff = ((float)LAND_MINEFF / 100.0);
490 int mil, lcm, hcm, gun, shell;
494 mil = roundavg(((double)lp->l_mil * (double)eff));
495 shell = roundavg(((double)lp->l_shell * (double)eff));
496 gun = roundavg(((double)lp->l_gun * (double)eff));
498 mil = shell = gun = 0;
499 hcm = roundavg(((double)lp->l_hcm * (double)eff));
500 lcm = roundavg(((double)lp->l_lcm * (double)eff));
502 natp = getnatp(player->cnum);
504 if (sp->sct_type != SCT_HEADQ) {
505 pr("Land Units must be built in headquarters.\n");
508 if (sp->sct_effic < 60 && !player->god) {
509 pr("Sector %s is not 60%% efficient.\n",
510 xyas(sp->sct_x, sp->sct_y, player->cnum));
513 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
514 pr("Not enough materials in %s\n",
515 xyas(sp->sct_x, sp->sct_y, player->cnum));
519 if (vec[I_GUN] < gun || vec[I_GUN] == 0) {
520 pr("Not enough guns in %s\n",
521 xyas(sp->sct_x, sp->sct_y, player->cnum));
524 if (vec[I_SHELL] < shell) {
525 pr("Not enough shells in %s\n",
526 xyas(sp->sct_x, sp->sct_y, player->cnum));
529 if (vec[I_MILIT] < mil) {
530 pr("Not enough military in %s\n",
531 xyas(sp->sct_x, sp->sct_y, player->cnum));
535 if (!trechk(player->cnum, 0, NEWLND))
537 if (!check_sect_ok(sp))
539 w_p_eff = (20 + lp->l_lcm + (lp->l_hcm * 2));
540 points = sp->sct_avail * 100 / w_p_eff;
541 if (points < LAND_MINEFF) {
542 pr("Not enough available work in %s to build a %s\n",
543 xyas(sp->sct_x, sp->sct_y, player->cnum), lp->l_name);
544 pr(" (%d available work required)\n",
545 1 + (w_p_eff * LAND_MINEFF) / 100);
548 cost = ((float)lp->l_cost * eff);
549 /* cost = (int)LND_COST(cost, tlev - lp->l_tech); */
551 pr("Not enough money left to build a %s\n", lp->l_name);
554 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * LAND_MINEFF) / 100;
555 player->dolcost += cost;
557 snxtitem_all(&nstr, EF_LAND);
558 while (nxtitem(&nstr, (s_char *)&land)) {
559 if (land.lnd_own == 0) {
565 ef_extend(EF_LAND, 50);
567 memset(&land, 0, sizeof(struct lndstr));
568 land.lnd_x = sp->sct_x;
569 land.lnd_y = sp->sct_y;
570 land.lnd_own = player->cnum;
571 land.lnd_mission = 0;
572 land.lnd_type = lp - lchr;
573 land.lnd_effic = LAND_MINEFF;
574 if (opt_MOB_ACCESS) {
575 time(&land.lnd_access);
576 land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
581 land.lnd_tech = tlev;
582 land.lnd_uid = nstr.cur;
589 land.lnd_retreat = morale_base;
590 land.lnd_fuel = lp->l_fuelc;
591 land.lnd_nxlight = 0;
593 memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
594 land.lnd_rad_max = 0;
596 land.lnd_att = (float)LND_ATTDEF(lp->l_att, tlev - lp->l_tech);
597 land.lnd_def = (float)LND_ATTDEF(lp->l_def, tlev - lp->l_tech);
598 land.lnd_vul = (int)LND_VUL(lp->l_vul, tlev - lp->l_tech);
599 land.lnd_spd = (int)LND_SPD(lp->l_spd, tlev - lp->l_tech);
600 land.lnd_vis = (int)LND_VIS(lp->l_vis, tlev - lp->l_tech);
601 land.lnd_spy = (int)LND_SPY(lp->l_spy, tlev - lp->l_tech);
602 land.lnd_rad = (int)LND_RAD(lp->l_rad, tlev - lp->l_tech);
603 land.lnd_frg = (int)LND_FRG(lp->l_frg, tlev - lp->l_tech);
604 land.lnd_acc = (int)LND_ACC(lp->l_acc, tlev - lp->l_tech);
605 land.lnd_dam = (int)LND_DAM(lp->l_dam, tlev - lp->l_tech);
606 land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, tlev - lp->l_tech);
607 land.lnd_aaf = (int)LND_AAF(lp->l_aaf, tlev - lp->l_tech);
608 land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, tlev - lp->l_tech);
609 land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, tlev - lp->l_tech);
610 land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech);
611 land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech);
617 vec[I_SHELL] -= shell;
619 /* Disabled autoloading of food onto units
620 max_amt = vl_find(V_FOOD, lp->l_vtype, lp->l_vamt, (int) lp->l_nv);
621 food_needed = (etu_per_update * eatrate) *
622 (vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW])+1;
623 if ((vec[I_FOOD]-max_amt) < food_needed)
624 max_amt = (vec[I_FOOD]-food_needed);
629 vec[I_FOOD] -= max_amt;
631 memset(lvec, 0, sizeof(lvec));
632 getvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
633 lvec[I_FOOD] += max_amt;
634 putvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND);
637 if (getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_INFECT)
638 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND);
639 putland(nstr.cur, &land);
640 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
642 pr("%s", prland(&land));
643 pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
648 build_bridge(register struct sctstr *sp, register int *vec)
655 int nx, ny, i, good = 0;
659 if (opt_EASY_BRIDGES == 0) { /* must have a bridge head or tower */
660 if (sp->sct_type != SCT_BTOWER) {
661 if (sp->sct_type != SCT_BHEAD)
663 if (sp->sct_newtype != SCT_BHEAD)
670 for (i = 1; i <= 6; i++) {
672 nx = sp->sct_x + diroff[i][0];
673 ny = sp->sct_y + diroff[i][1];
674 getsect(nx, ny, §);
675 for (j = 1; j <= 6; j++) {
676 nx2 = sect.sct_x + diroff[j][0];
677 ny2 = sect.sct_y + diroff[j][1];
678 getsect(nx2, ny2, &s2);
679 if ((s2.sct_type != SCT_WATER) &&
680 (s2.sct_type != SCT_BSPAN))
687 pr("Bridges must be built adjacent to land or bridge towers.\n");
688 pr("No eligible sectors adjacent to this sector.\n");
691 } /* end EASY_BRIDGES */
694 if (sp->sct_effic < 60 && !player->god) {
695 pr("Sector %s is not 60%% efficient.\n",
696 xyas(sp->sct_x, sp->sct_y, player->cnum));
701 if (vec[I_HCM] < buil_bh) {
702 pr("%s only has %d unit%s of hcm,\n",
703 xyas(sp->sct_x, sp->sct_y, player->cnum),
704 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
705 pr("(a bridge span requires %d)\n", buil_bh);
708 } else if (!opt_NO_LCMS) {
709 if (vec[I_LCM] < buil_bh) {
710 pr("%s only has %d unit%s of lcm,\n",
711 xyas(sp->sct_x, sp->sct_y, player->cnum),
712 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
713 pr("(a bridge span requires %d)\n", buil_bh);
717 if (cash < buil_bc) {
718 pr("A span costs $%.2f to build; ", buil_bc);
719 pr("you only have %d.\n", cash);
722 w_p_eff = buil_bh * 2;
723 points = sp->sct_avail * 100 / w_p_eff;
725 pr("Not enough available work in %s to build a bridge\n",
726 xyas(sp->sct_x, sp->sct_y, player->cnum));
727 pr(" (%d available work required)\n", 1 + (w_p_eff * 20) / 100);
730 if (!player->argp[3]) {
731 pr("Bridge head at %s\n",
732 xyas(sp->sct_x, sp->sct_y, player->cnum));
733 nav_map(sp->sct_x, sp->sct_y, 1);
735 if (!(p = getstarg(player->argp[3], "build span in what direction? ", buf))
739 /* Sanity check time */
740 if (!check_sect_ok(sp))
743 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
744 pr("'%c' is not a valid direction...\n", *p);
748 newx = sp->sct_x + diroff[val][0];
749 newy = sp->sct_y + diroff[val][1];
750 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
751 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
754 if (opt_EASY_BRIDGES) {
757 for (i = 1; i <= 6; i++) {
759 nx = sect.sct_x + diroff[i][0];
760 ny = sect.sct_y + diroff[i][1];
761 getsect(nx, ny, &s2);
762 if ((s2.sct_type != SCT_WATER) && (s2.sct_type != SCT_BSPAN))
766 pr("Bridges must be built adjacent to land or bridge towers.\n");
767 pr("That sector is not adjacent to land or a bridge tower.\n");
770 } /* end EASY_BRIDGES */
771 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100;
772 player->dolcost += buil_bc;
774 sect.sct_type = SCT_BSPAN;
775 sect.sct_newtype = SCT_BSPAN;
779 sect.sct_defense = 0;
780 if (!opt_DEFENSE_INFRA)
781 sect.sct_defense = sect.sct_effic;
782 if (opt_MOB_ACCESS) {
783 time(§.sct_access);
784 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
788 putvar(V_MINE, 0, (s_char *)§, EF_SECTOR);
790 pr("Bridge span built over %s\n",
791 xyas(sect.sct_x, sect.sct_y, player->cnum));
793 vec[I_HCM] -= buil_bh;
794 else if (!opt_NO_LCMS)
795 vec[I_LCM] -= buil_bh;
800 build_nuke(register struct sctstr *sp, register struct nchrstr *np,
806 if (sp->sct_type != SCT_NUKE && !player->god) {
807 pr("Nuclear weapons must be built in nuclear plants.\n");
810 if (sp->sct_effic < 60 && !player->god) {
811 pr("Sector %s is not 60%% efficient.\n",
812 xyas(sp->sct_x, sp->sct_y, player->cnum));
815 if (vec[I_HCM] < np->n_hcm || vec[I_LCM] < np->n_lcm ||
816 vec[I_OIL] < np->n_oil || vec[I_RAD] < np->n_rad) {
817 pr("Not enough materials for a %s bomb in %s\n",
818 np->n_name, xyas(sp->sct_x, sp->sct_y, player->cnum));
819 pr("(%d hcm, %d lcm, %d oil, & %d rads).\n",
820 np->n_hcm, np->n_lcm, np->n_oil, np->n_rad);
823 if (cash < np->n_cost) {
824 pr("You need $%d, you only have %d.\n", np->n_cost, cash);
827 w_p_eff = np->n_rad + np->n_oil + np->n_lcm + np->n_hcm * 2;
828 points = sp->sct_avail * 100 / w_p_eff;
830 * XXX when nukes turn into units (or whatever), then
831 * make them start at 20%. Since they don't have efficiency
832 * now, we choose 20% as a "big" number.
835 pr("Not enough available work in %s to build a %s;\n",
836 xyas(sp->sct_x, sp->sct_y, player->cnum), np->n_name);
837 pr(" (%d available work required)\n", 1 + w_p_eff * 20 / 100);
840 if (!trechk(player->cnum, 0, NEWNUK))
842 if (!check_sect_ok(sp))
844 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100;
845 player->dolcost += np->n_cost;
847 nuk_add(sp->sct_x, sp->sct_y, np - nchr, 1);
848 vec[I_HCM] -= np->n_hcm;
849 vec[I_LCM] -= np->n_lcm;
850 vec[I_OIL] -= np->n_oil;
851 vec[I_RAD] -= np->n_rad;
852 pr("%s warhead created in %s\n", np->n_name,
853 xyas(sp->sct_x, sp->sct_y, player->cnum));
858 build_plane(register struct sctstr *sp, register struct plchrstr *pp,
859 register int *vec, int tlev)
863 struct nstr_item nstr;
864 float eff = ((float)PLANE_MINEFF / 100.0);
870 mil = roundavg(((double)pp->pl_crew * (double)eff));
871 /* Always use at least 1 mil to build a plane */
872 if (mil == 0 && pp->pl_crew > 0)
874 hcm = roundavg(((double)pp->pl_hcm * (double)eff));
875 lcm = roundavg(((double)pp->pl_lcm * (double)eff));
876 if (sp->sct_type != SCT_AIRPT && !player->god) {
877 pr("Planes must be built in airports.\n");
880 if (sp->sct_effic < 60 && !player->god) {
881 pr("Sector %s is not 60%% efficient.\n",
882 xyas(sp->sct_x, sp->sct_y, player->cnum));
885 if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) {
886 pr("Not enough materials in %s\n",
887 xyas(sp->sct_x, sp->sct_y, player->cnum));
890 w_p_eff = (20 + pp->pl_lcm + (pp->pl_hcm * 2));
891 points = sp->sct_avail * 100 / w_p_eff;
892 if (points < PLANE_MINEFF) {
893 pr("Not enough available work in %s to build a %s\n",
894 xyas(sp->sct_x, sp->sct_y, player->cnum), pp->pl_name);
895 pr(" (%d available work required)\n",
896 1 + PLANE_MINEFF * w_p_eff / 100);
899 cost = pp->pl_cost * eff;
901 pr("Not enough money left to build a %s\n", pp->pl_name);
904 if (vec[I_MILIT] < mil || (vec[I_MILIT] == 0 && pp->pl_crew > 0)) {
905 pr("Not enough military for crew in %s\n",
906 xyas(sp->sct_x, sp->sct_y, player->cnum));
909 if (!trechk(player->cnum, 0, NEWPLN))
911 if (!check_sect_ok(sp))
913 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * PLANE_MINEFF) / 100;
914 player->dolcost += cost;
916 snxtitem_all(&nstr, EF_PLANE);
918 while (nxtitem(&nstr, (s_char *)&plane)) {
919 if (plane.pln_own == 0) {
924 if (freeplane == 0) {
925 ef_extend(EF_PLANE, 50);
927 memset(&plane, 0, sizeof(struct plnstr));
928 plane.pln_x = sp->sct_x;
929 plane.pln_y = sp->sct_y;
930 plane.pln_own = sp->sct_own;
931 plane.pln_type = pp - plchr;
932 plane.pln_effic = PLANE_MINEFF;
933 if (opt_MOB_ACCESS) {
934 time(&plane.pln_access);
935 plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
939 plane.pln_mission = 0;
942 plane.pln_radius = 0;
944 /* Note that this next block of variables can be changed so that individual
945 * planes may have their own stats (like based on tech maybe? :) ) Thus,
946 * the code now checks the pln_acc, pln_load and pln_fuel instead of using
947 * the static definitions of them. */
949 n = (int) (pp->pl_range * (0.75 + techfact(tlev - pp->pl_tech, 2.0)));
953 plane.pln_range_max = n;
954 n = (int) (pp->pl_att * (0.75 + techfact(tlev - pp->pl_tech, 2.0)));
958 n = (int) (pp->pl_def * (0.75 + techfact(tlev - pp->pl_tech, 2.0)));
964 plane.pln_acc = pp->pl_acc;
965 plane.pln_load = pp->pl_load;
966 plane.pln_fuel = pp->pl_fuel;
968 plane.pln_att = PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech));
969 plane.pln_def = PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech));
970 plane.pln_acc = PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech));
971 plane.pln_range = PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech));
972 plane.pln_range_max = plane.pln_range;
973 plane.pln_load = PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech));
974 plane.pln_fuel = pp->pl_fuel;
976 plane.pln_wing = ' ';
977 plane.pln_tech = tlev;
980 plane.pln_uid = nstr.cur;
981 plane.pln_nuketype = -1;
982 plane.pln_harden = 0;
985 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
987 putplane(plane.pln_uid, &plane);
988 pr("%s built in sector %s\n", prplane(&plane),
989 xyas(sp->sct_x, sp->sct_y, player->cnum));
997 build_tower(register struct sctstr *sp, register int *vec)
1011 if (sp->sct_type != SCT_BSPAN) {
1012 pr("Bridge towers can only be built from bridge spans.\n");
1016 if (sp->sct_effic < 60 && !player->god) {
1017 pr("Sector %s is not 60%% efficient.\n",
1018 xyas(sp->sct_x, sp->sct_y, player->cnum));
1023 if (vec[I_HCM] < buil_tower_bh) {
1024 pr("%s only has %d unit%s of hcm,\n",
1025 xyas(sp->sct_x, sp->sct_y, player->cnum),
1026 vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
1027 pr("(a bridge tower requires %d)\n", buil_tower_bh);
1030 } else if (!opt_NO_LCMS) {
1031 if (vec[I_LCM] < buil_tower_bh) {
1032 pr("%s only has %d unit%s of lcm,\n",
1033 xyas(sp->sct_x, sp->sct_y, player->cnum),
1034 vec[I_LCM], vec[I_LCM] > 1 ? "s" : "");
1035 pr("(a bridge tower requires %d)\n", buil_tower_bh);
1039 if (cash < buil_tower_bc) {
1040 pr("A bridge tower costs $%.2f to build; ", buil_tower_bc);
1041 pr("you only have %d.\n", cash);
1044 w_p_eff = buil_tower_bh * 2;
1045 points = sp->sct_avail * 100 / w_p_eff;
1047 pr("Not enough available work in %s to build a bridge tower\n",
1048 xyas(sp->sct_x, sp->sct_y, player->cnum));
1049 pr(" (%d available work required)\n", 1 + (w_p_eff * 20) / 100);
1052 if (!player->argp[3]) {
1053 pr("Building from %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
1054 nav_map(sp->sct_x, sp->sct_y, 1);
1056 if (!(p = getstarg(player->argp[3], "build tower in what direction? ", buf))
1060 /* Sanity check time */
1061 if (!check_sect_ok(sp))
1064 if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
1065 pr("'%c' is not a valid direction...\n", *p);
1069 newx = sp->sct_x + diroff[val][0];
1070 newy = sp->sct_y + diroff[val][1];
1071 if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) {
1072 pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
1076 /* Now, check. You aren't allowed to build bridge towers
1079 for (i = 1; i <= 6; i++) {
1081 nx = sect.sct_x + diroff[i][0];
1082 ny = sect.sct_y + diroff[i][1];
1083 getsect(nx, ny, &s2);
1084 if ((s2.sct_type != SCT_WATER) &&
1085 (s2.sct_type != SCT_BTOWER) && (s2.sct_type != SCT_BSPAN)) {
1091 pr("Bridge towers cannot be built adjacent to land.\n");
1092 pr("That sector is adjacent to land.\n");
1096 sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100;
1097 player->dolcost += buil_tower_bc;
1098 cash -= buil_tower_bc;
1099 sect.sct_type = SCT_BTOWER;
1100 sect.sct_newtype = SCT_BTOWER;
1101 sect.sct_effic = 20;
1104 sect.sct_defense = 0;
1105 if (opt_MOB_ACCESS) {
1106 time(§.sct_access);
1107 sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
1111 if (!opt_DEFENSE_INFRA)
1112 sect.sct_defense = sect.sct_effic;
1113 putvar(V_MINE, 0, (s_char *)§, EF_SECTOR);
1115 pr("Bridge tower built in %s\n",
1116 xyas(sect.sct_x, sect.sct_y, player->cnum));
1118 vec[I_HCM] -= buil_tower_bh;
1119 else if (!opt_NO_LCMS)
1120 vec[I_LCM] -= buil_tower_bh;