]> git.pond.sub.org Git - empserver/blob - src/lib/commands/buil.c
config: Make work to build units independently configurable
[empserver] / src / lib / commands / buil.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 of the License, or
9  *  (at your option) any later version.
10  *
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.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  buil.c: Build ships, nukes, bridges, planes, land units, bridge towers
28  *
29  *  Known contributors to this file:
30  *     Steve McClure, 1998-2000
31  *     Markus Armbruster, 2004-2016
32  */
33
34 #include <config.h>
35
36 #include <limits.h>
37 #include <math.h>
38 #include "chance.h"
39 #include "commands.h"
40 #include "game.h"
41 #include "land.h"
42 #include "lost.h"
43 #include "map.h"
44 #include "nuke.h"
45 #include "optlist.h"
46 #include "path.h"
47 #include "plague.h"
48 #include "plane.h"
49 #include "ship.h"
50 #include "unit.h"
51
52 static int build_ship(struct sctstr *sp, int type, int tlev);
53 static int build_land(struct sctstr *sp, int type, int tlev);
54 static int build_nuke(struct sctstr *sp, int type, int tlev);
55 static int build_plane(struct sctstr *sp, int type, int tlev);
56 static int pick_unused_unit_uid(int);
57 static int build_bridge(char);
58 static int build_bspan(struct sctstr *sp);
59 static int build_btower(struct sctstr *sp);
60 static int sector_can_build(struct sctstr *, short[], int, int, char *);
61 static void build_charge(struct sctstr *, short[], int, double, int);
62 static int build_can_afford(double, int, char *);
63
64 /*
65  * build <WHAT> <SECTS> <TYPE|DIR|MEG> [NUMBER]
66  */
67 int
68 buil(void)
69 {
70     struct natstr *natp = getnatp(player->cnum);
71     int tlev = (int)natp->nat_level[NAT_TLEV];
72     struct sctstr sect;
73     struct nstr_sect nstr;
74     int rqtech, type, number, val, gotsect;
75     char *p, *what, *prompt;
76     int (*build_it)(struct sctstr *, int, int);
77     char buf[1024];
78
79     p = getstarg(player->argp[1],
80                  "Build (ship, nuke, bridge, plane, land unit, tower)? ",
81                  buf);
82     if (!p)
83         return RET_SYN;
84     switch (*p) {
85     case 'b':
86     case 't':
87         return build_bridge(*p);
88     case 's':
89         what = "ship";
90         prompt = "Ship type? ";
91         build_it = build_ship;
92         break;
93     case 'p':
94         what = "plane";
95         prompt = "Plane type? ";
96         build_it = build_plane;
97         break;
98     case 'l':
99         what = "land";
100         prompt = "Land unit type? ";
101         build_it = build_land;
102         break;
103     case 'n':
104         if (!ef_nelem(EF_NUKE_CHR)) {
105             pr("There are no nukes in this game.\n");
106             return RET_FAIL;
107         }
108         if (drnuke_const > MIN_DRNUKE_CONST)
109             tlev = MIN(tlev,
110                        (int)(natp->nat_level[NAT_RLEV] / drnuke_const));
111         what = "nuke";
112         prompt = "Nuke type? ";
113         build_it = build_nuke;
114         break;
115     default:
116         pr("You can't build that!\n");
117         return RET_SYN;
118     }
119
120     if (!snxtsct(&nstr, player->argp[2]))
121         return RET_SYN;
122
123     p = getstarg(player->argp[3], prompt, buf);
124     if (!p || !*p)
125         return RET_SYN;
126
127     rqtech = 0;
128     switch (*what) {
129     case 'p':
130         type = ef_elt_byname(EF_PLANE_CHR, p);
131         if (type >= 0)
132             rqtech = plchr[type].pl_tech;
133         break;
134     case 's':
135         type = ef_elt_byname(EF_SHIP_CHR, p);
136         if (type >= 0)
137             rqtech = mchr[type].m_tech;
138         break;
139     case 'l':
140         type = ef_elt_byname(EF_LAND_CHR, p);
141         if (type >= 0)
142             rqtech = lchr[type].l_tech;
143         break;
144     case 'n':
145         type = ef_elt_byname(EF_NUKE_CHR, p);
146         if (type >= 0)
147             rqtech = nchr[type].n_tech;
148         break;
149     default:
150         CANT_REACH();
151         return RET_FAIL;
152     }
153
154     if (tlev < rqtech && player->god)
155         tlev = rqtech;
156     if (type < 0 || tlev < rqtech) {
157         pr("You can't build that!\n");
158         pr("Use `show %s build %d' to show types you can build.\n",
159            what, tlev);
160         return RET_FAIL;
161     }
162
163     number = 1;
164     if (player->argp[4]) {
165         number = atoi(player->argp[4]);
166         if (number > 20) {
167             char bstr[80];
168             sprintf(bstr,
169                     "Are you sure that you want to build %d of them? ",
170                     number);
171             p = getstarg(player->argp[6], bstr, buf);
172             if (!p || *p != 'y')
173                 return RET_SYN;
174         }
175     }
176
177     if (player->argp[5]) {
178         val = atoi(player->argp[5]);
179         if (val > tlev && !player->god) {
180             pr("Your%s tech level is only %d.\n",
181                *what == 'n' && drnuke_const > MIN_DRNUKE_CONST
182                ? " effective" : "", tlev);
183             return RET_FAIL;
184         }
185         if (rqtech > val) {
186             pr("Required tech is %d.\n", rqtech);
187             return RET_FAIL;
188         }
189         tlev = val;
190         pr("Building with tech level %d.\n", tlev);
191     }
192
193     gotsect = 0;
194     while (number-- > 0) {
195         while (nxtsct(&nstr, &sect)) {
196             if (!player->owner)
197                 continue;
198             gotsect = 1;
199             if (build_it(&sect, type, tlev))
200                 putsect(&sect);
201         }
202         snxtsct_rewind(&nstr);
203     }
204     if (!gotsect)
205         pr("No sectors.\n");
206     return RET_OK;
207 }
208
209 static int
210 build_ship(struct sctstr *sp, int type, int tlev)
211 {
212     struct mchrstr *mp = &mchr[type];
213     short mat[I_MAX+1];
214     struct shpstr ship;
215
216     memset(mat, 0, sizeof(mat));
217     mat[I_LCM] = mp->m_lcm;
218     mat[I_HCM] = mp->m_hcm;
219
220     if (sp->sct_type != SCT_HARBR && !player->god) {
221         pr("Ships must be built in harbours.\n");
222         return 0;
223     }
224     if (!sector_can_build(sp, mat, mp->m_bwork, SHIP_MINEFF, mp->m_name))
225         return 0;
226     if (!build_can_afford(mp->m_cost, SHIP_MINEFF, mp->m_name))
227         return 0;
228     build_charge(sp, mat, mp->m_bwork, mp->m_cost, SHIP_MINEFF);
229
230     ef_blank(EF_SHIP, pick_unused_unit_uid(EF_SHIP), &ship);
231     ship.shp_x = sp->sct_x;
232     ship.shp_y = sp->sct_y;
233     ship.shp_own = sp->sct_own;
234     ship.shp_type = mp - mchr;
235     ship.shp_effic = SHIP_MINEFF;
236     if (opt_MOB_ACCESS) {
237         game_tick_to_now(&ship.shp_access);
238         ship.shp_mobil = -(etu_per_update / sect_mob_neg_factor);
239     } else {
240         ship.shp_mobil = 0;
241     }
242     memset(ship.shp_item, 0, sizeof(ship.shp_item));
243     ship.shp_pstage = PLG_HEALTHY;
244     ship.shp_ptime = 0;
245     ship.shp_name[0] = 0;
246     ship.shp_orig_own = sp->sct_own;
247     ship.shp_orig_x = sp->sct_x;
248     ship.shp_orig_y = sp->sct_y;
249     shp_set_tech(&ship, tlev);
250     unit_wipe_orders((struct empobj *)&ship);
251
252     if (sp->sct_pstage == PLG_INFECT)
253         ship.shp_pstage = PLG_EXPOSED;
254     putship(ship.shp_uid, &ship);
255     pr("%s", prship(&ship));
256     pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
257     return 1;
258 }
259
260 static int
261 build_land(struct sctstr *sp, int type, int tlev)
262 {
263     struct lchrstr *lp = &lchr[type];
264     short mat[I_MAX+1];
265     struct lndstr land;
266
267     memset(mat, 0, sizeof(mat));
268     mat[I_LCM] = lp->l_lcm;
269     mat[I_HCM] = lp->l_hcm;
270
271     if (sp->sct_type != SCT_HEADQ && !player->god) {
272         pr("Land units must be built in headquarters.\n");
273         return 0;
274     }
275     if (!sector_can_build(sp, mat, lp->l_bwork, LAND_MINEFF, lp->l_name))
276         return 0;
277     if (!build_can_afford(lp->l_cost, LAND_MINEFF, lp->l_name))
278         return 0;
279     build_charge(sp, mat, lp->l_bwork, lp->l_cost, LAND_MINEFF);
280
281     ef_blank(EF_LAND, pick_unused_unit_uid(EF_LAND), &land);
282     land.lnd_x = sp->sct_x;
283     land.lnd_y = sp->sct_y;
284     land.lnd_own = sp->sct_own;
285     land.lnd_type = lp - lchr;
286     land.lnd_effic = LAND_MINEFF;
287     if (opt_MOB_ACCESS) {
288         game_tick_to_now(&land.lnd_access);
289         land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
290     } else {
291         land.lnd_mobil = 0;
292     }
293     land.lnd_ship = -1;
294     land.lnd_land = -1;
295     land.lnd_harden = 0;
296     memset(land.lnd_item, 0, sizeof(land.lnd_item));
297     land.lnd_pstage = PLG_HEALTHY;
298     land.lnd_ptime = 0;
299     lnd_set_tech(&land, tlev);
300     unit_wipe_orders((struct empobj *)&land);
301
302     if (sp->sct_pstage == PLG_INFECT)
303         land.lnd_pstage = PLG_EXPOSED;
304     putland(land.lnd_uid, &land);
305     pr("%s", prland(&land));
306     pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
307     return 1;
308 }
309
310 static int
311 build_nuke(struct sctstr *sp, int type, int tlev)
312 {
313     struct nchrstr *np = &nchr[type];
314     short mat[I_MAX+1];
315     struct nukstr nuke;
316
317     if (sp->sct_type != SCT_NUKE && !player->god) {
318         pr("Nuclear weapons must be built in nuclear plants.\n");
319         return 0;
320     }
321     /*
322      * XXX when nukes turn into units (or whatever), then
323      * make them start at 20%.  Since they don't have efficiency
324      * now, we charge all the work right away.
325      */
326     memset(mat, 0, sizeof(mat));
327     mat[I_LCM] = np->n_lcm;
328     mat[I_HCM] = np->n_hcm;
329     mat[I_OIL] = np->n_oil;
330     mat[I_RAD] = np->n_rad;
331
332     if (!sector_can_build(sp, mat, np->n_bwork, 100, np->n_name))
333         return 0;
334     if (!build_can_afford(np->n_cost, 100, np->n_name))
335         return 0;
336     build_charge(sp, mat, np->n_bwork, np->n_cost, 100);
337
338     ef_blank(EF_NUKE, pick_unused_unit_uid(EF_NUKE), &nuke);
339     nuke.nuk_x = sp->sct_x;
340     nuke.nuk_y = sp->sct_y;
341     nuke.nuk_own = sp->sct_own;
342     nuke.nuk_type = np - nchr;
343     nuke.nuk_effic = 100;
344     nuke.nuk_plane = -1;
345     nuke.nuk_tech = tlev;
346     unit_wipe_orders((struct empobj *)&nuke);
347
348     putnuke(nuke.nuk_uid, &nuke);
349     pr("%s created in %s\n", prnuke(&nuke),
350        xyas(sp->sct_x, sp->sct_y, player->cnum));
351     return 1;
352 }
353
354 static int
355 build_plane(struct sctstr *sp, int type, int tlev)
356 {
357     struct plchrstr *pp = &plchr[type];
358     short mat[I_MAX+1];
359     struct plnstr plane;
360
361     memset(mat, 0, sizeof(mat));
362     mat[I_MILIT] = pp->pl_crew;
363     mat[I_LCM] = pp->pl_lcm;
364     mat[I_HCM] = pp->pl_hcm;
365
366     if (sp->sct_type != SCT_AIRPT && !player->god) {
367         pr("Planes must be built in airports.\n");
368         return 0;
369     }
370     if (!sector_can_build(sp, mat, pp->pl_bwork, PLANE_MINEFF, pp->pl_name))
371         return 0;
372     if (!build_can_afford(pp->pl_cost, PLANE_MINEFF, pp->pl_name))
373         return 0;
374     build_charge(sp, mat, pp->pl_bwork, pp->pl_cost, PLANE_MINEFF);
375
376     ef_blank(EF_PLANE, pick_unused_unit_uid(EF_PLANE), &plane);
377     plane.pln_x = sp->sct_x;
378     plane.pln_y = sp->sct_y;
379     plane.pln_own = sp->sct_own;
380     plane.pln_type = pp - plchr;
381     plane.pln_effic = PLANE_MINEFF;
382     if (opt_MOB_ACCESS) {
383         game_tick_to_now(&plane.pln_access);
384         plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
385     } else {
386         plane.pln_mobil = 0;
387     }
388     plane.pln_range = UCHAR_MAX; /* will be adjusted by pln_set_tech() */
389     plane.pln_ship = -1;
390     plane.pln_land = -1;
391     plane.pln_harden = 0;
392     plane.pln_flags = 0;
393     pln_set_tech(&plane, tlev);
394     unit_wipe_orders((struct empobj *)&plane);
395
396     putplane(plane.pln_uid, &plane);
397     pr("%s built in sector %s\n", prplane(&plane),
398        xyas(sp->sct_x, sp->sct_y, player->cnum));
399     return 1;
400 }
401
402 static int
403 pick_unused_unit_uid(int type)
404 {
405     struct nstr_item nstr;
406     union empobj_storage unit;
407
408     snxtitem_all(&nstr, type);
409     while (nxtitem(&nstr, &unit)) {
410         if (!unit.gen.own)
411             return nstr.cur;
412     }
413     ef_extend(type, 50);
414     return nstr.cur;
415 }
416
417 static int
418 build_bridge(char what)
419 {
420     struct natstr *natp = getnatp(player->cnum);
421     struct nstr_sect nstr;
422     int (*build_it)(struct sctstr *);
423     int gotsect;
424     struct sctstr sect;
425
426     switch (what) {
427     case 'b':
428         if (natp->nat_level[NAT_TLEV] < buil_bt && !player->god) {
429             pr("Building a span requires a tech of %.0f\n", buil_bt);
430             return RET_FAIL;
431         }
432         build_it = build_bspan;
433         break;
434     case 't':
435         if (!opt_BRIDGETOWERS) {
436             pr("Bridge tower building is disabled.\n");
437             return RET_FAIL;
438         }
439         if (natp->nat_level[NAT_TLEV] < buil_tower_bt && !player->god) {
440             pr("Building a tower requires a tech of %.0f\n",
441                buil_tower_bt);
442             return RET_FAIL;
443         }
444         build_it = build_btower;
445         break;
446     default:
447         CANT_REACH();
448         return RET_FAIL;
449     }
450
451     if (!snxtsct(&nstr, player->argp[2]))
452         return RET_SYN;
453     gotsect = 0;
454     while (nxtsct(&nstr, &sect)) {
455         if (!player->owner)
456             continue;
457         gotsect = 1;
458         if (build_it(&sect))
459             putsect(&sect);
460     }
461     if (!gotsect)
462         pr("No sectors.\n");
463     return RET_OK;
464 }
465
466 static int
467 build_bspan(struct sctstr *sp)
468 {
469     struct sctstr sect;
470     short mat[I_MAX+1];
471     int work;
472     int val;
473     int newx, newy;
474     char *p;
475     char buf[1024];
476
477     if (!opt_EASY_BRIDGES && !player->god) {
478         /* must have a bridge head or tower */
479         if (sp->sct_type != SCT_BTOWER) {
480             if (sp->sct_type != SCT_BHEAD)
481                 return 0;
482             if (sp->sct_newtype != SCT_BHEAD)
483                 return 0;
484         }
485     }
486
487     memset(mat, 0, sizeof(mat));
488     mat[I_HCM] = buil_bh;
489     work = (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100;
490
491     if (!sector_can_build(sp, mat, work, 100, dchr[SCT_BSPAN].d_name))
492         return 0;
493     if (!build_can_afford(buil_bc, 100, dchr[SCT_BSPAN].d_name))
494         return 0;
495     if (!player->argp[3]) {
496         pr("Bridge head at %s\n",
497            xyas(sp->sct_x, sp->sct_y, player->cnum));
498         nav_map(sp->sct_x, sp->sct_y, 1);
499     }
500     p = getstarg(player->argp[3], "build span in what direction? ", buf);
501     if (!p || !*p) {
502         return 0;
503     }
504     if (!check_sect_ok(sp))
505         return 0;
506
507     if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
508         pr("'%c' is not a valid direction...\n", *p);
509         direrr(NULL, NULL, NULL);
510         return 0;
511     }
512     newx = sp->sct_x + diroff[val][0];
513     newy = sp->sct_y + diroff[val][1];
514     if (getsect(newx, newy, &sect) == 0 || sect.sct_type != SCT_WATER) {
515         pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
516         return 0;
517     }
518     if (!bridge_support_at(&sect, DIR_STOP)) {
519         if (opt_EASY_BRIDGES) {
520             pr("%s is not next to land or a bridge tower",
521                xyas(newx, newy, player->cnum));
522         } else {
523             /*
524              * Note: because players need a 60% bridge head or tower,
525              * we can get here only for a deity.
526              */
527             pr("%s is not next to a supporting bridge head or tower\n",
528                xyas(newx, newy, player->cnum));
529         }
530         return 0;
531     }
532     build_charge(sp, mat, work, buil_bc, 100);
533
534     sect.sct_type = SCT_BSPAN;
535     sect.sct_newtype = SCT_BSPAN;
536     sect.sct_effic = SCT_MINEFF;
537     sect.sct_road = 0;
538     sect.sct_rail = 0;
539     sect.sct_defense = 0;
540     if (opt_MOB_ACCESS) {
541         game_tick_to_now(&sect.sct_access);
542         sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
543     } else {
544         sect.sct_mobil = 0;
545     }
546     sect.sct_mines = 0;
547     map_set(player->cnum, sect.sct_x, sect.sct_y, dchr[SCT_BSPAN].d_mnem, 2);
548     writemap(player->cnum);
549     putsect(&sect);
550     pr("Bridge span built over %s\n",
551        xyas(sect.sct_x, sect.sct_y, player->cnum));
552     return 1;
553 }
554
555 static int
556 build_btower(struct sctstr *sp)
557 {
558     struct sctstr sect;
559     short mat[I_MAX+1];
560     int work;
561     int val;
562     int newx, newy;
563     char *p;
564     char buf[1024];
565     int i;
566     int nx;
567     int ny;
568
569     if (sp->sct_type != SCT_BSPAN && !player->god) {
570         pr("Bridge towers can only be built from bridge spans.\n");
571         return 0;
572     }
573
574     memset(mat, 0, sizeof(mat));
575     mat[I_HCM] = buil_tower_bh;
576     work = (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100;
577
578     if (!sector_can_build(sp, mat, work, 100, dchr[SCT_BTOWER].d_name))
579         return 0;
580     if (!build_can_afford(buil_tower_bc, 100, dchr[SCT_BTOWER].d_name))
581         return 0;
582     if (!player->argp[3]) {
583         pr("Building from %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
584         nav_map(sp->sct_x, sp->sct_y, 1);
585     }
586     p = getstarg(player->argp[3], "build tower in what direction? ", buf);
587     if (!p || !*p) {
588         return 0;
589     }
590     if (!check_sect_ok(sp))
591         return 0;
592
593     if ((val = chkdir(*p, DIR_FIRST, DIR_LAST)) < 0) {
594         pr("'%c' is not a valid direction...\n", *p);
595         direrr(NULL, NULL, NULL);
596         return 0;
597     }
598     newx = sp->sct_x + diroff[val][0];
599     newy = sp->sct_y + diroff[val][1];
600     if (getsect(newx, newy, &sect) == 0 || sect.sct_type != SCT_WATER) {
601         pr("%s is not a water sector\n", xyas(newx, newy, player->cnum));
602         return 0;
603     }
604
605     /* Now, check.  You aren't allowed to build bridge towers
606        next to land. */
607     for (i = 1; i <= 6; i++) {
608         struct sctstr s2;
609         nx = sect.sct_x + diroff[i][0];
610         ny = sect.sct_y + diroff[i][1];
611         getsect(nx, ny, &s2);
612         if ((s2.sct_type != SCT_WATER) &&
613             (s2.sct_type != SCT_BTOWER) && (s2.sct_type != SCT_BSPAN)) {
614             pr("%s is next to land, can't build bridge tower there",
615                xyas(newx, newy, player->cnum));
616             return 0;
617         }
618     }
619
620     build_charge(sp, mat, work, buil_tower_bc, 100);
621
622     sect.sct_type = SCT_BTOWER;
623     sect.sct_newtype = SCT_BTOWER;
624     sect.sct_effic = SCT_MINEFF;
625     sect.sct_road = 0;
626     sect.sct_rail = 0;
627     sect.sct_defense = 0;
628     if (opt_MOB_ACCESS) {
629         game_tick_to_now(&sect.sct_access);
630         sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor);
631     } else {
632         sect.sct_mobil = 0;
633     }
634     sect.sct_mines = 0;
635     map_set(player->cnum, sect.sct_x, sect.sct_y, dchr[SCT_BTOWER].d_mnem, 2);
636     writemap(player->cnum);
637     putsect(&sect);
638     pr("Bridge tower built in %s\n",
639        xyas(sect.sct_x, sect.sct_y, player->cnum));
640     return 1;
641 }
642
643 static int
644 sector_can_build(struct sctstr *sp, short mat[], int work,
645                  int effic, char *what)
646 {
647     int i, avail, ret, req;
648     double used;
649
650     if (player->god)
651         return 1;               /* Deity builds ex nihilo */
652
653     if (sp->sct_effic < 60 && !player->god) {
654         pr("Sector %s is not 60%% efficient.\n",
655            xyas(sp->sct_x, sp->sct_y, player->cnum));
656         return 0;
657     }
658
659     avail = (work * effic + 99) / 100;
660     if (sp->sct_avail < avail) {
661         pr("Not enough available work in %s to build a %s\n",
662            xyas(sp->sct_x, sp->sct_y, player->cnum), what);
663         pr(" (%d available work required)\n", avail);
664         return 0;
665     }
666
667     ret = 1;
668     for (i = I_NONE + 1; i <= I_MAX; i++) {
669         used = mat[i] * effic;
670         req = (used + 99) / 100;
671         if (sp->sct_item[i] < req) {
672             pr("Not enough %s in %s (need %d more)\n",
673                ichr[i].i_name, xyas(sp->sct_x, sp->sct_y, player->cnum),
674                req - sp->sct_item[i]);
675             ret = 0;
676         }
677         mat[i] = roundavg(used / 100.0);
678     }
679
680     return ret;
681 }
682
683 static void
684 build_charge(struct sctstr *sp,
685              short mat[], int work, double cost, int effic)
686 {
687     int i;
688
689     if (player->god)
690         return;                 /* Deity builds ex nihilo */
691
692     for (i = I_NONE + 1; i <= I_MAX; i++)
693         sp->sct_item[i] -= mat[i];
694     sp->sct_avail -= (work * effic + 99) / 100;
695     player->dolcost += cost * effic / 100.0;
696 }
697
698 static int
699 build_can_afford(double cost, int effic, char *what)
700 {
701     struct natstr *natp = getnatp(player->cnum);
702
703     if (natp->nat_money < player->dolcost + cost * effic / 100.0) {
704         pr("Not enough money left to build a %s\n", what);
705         return 0;
706     }
707     return 1;
708 }