build: Report missing stuff more nicely for ship, plane, land units

If both materials and avail are missing, report missing avail instead
of materials, to avoid tempting the player to move in materials only
to discover avail is lacking, too.

Report what materials are missing instead of just "Not enough
materials".  Does not yet include military for planes, but that's
next.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2014-01-12 18:33:13 +01:00
parent 1227d2c931
commit e2d176fd8a
3 changed files with 29 additions and 22 deletions

View file

@ -34,6 +34,7 @@
#include <config.h>
#include <limits.h>
#include <math.h>
#include "chance.h"
#include "commands.h"
#include "game.h"
@ -714,7 +715,7 @@ static int
sector_can_build(struct sctstr *sp, short mat[], int work,
int effic, char *what)
{
int i, avail;
int i, avail, ret;
double needed;
if (sp->sct_effic < 60 && !player->god) {
@ -723,16 +724,6 @@ sector_can_build(struct sctstr *sp, short mat[], int work,
return 0;
}
for (i = I_NONE + 1; i <= I_MAX; i++) {
needed = mat[i] * (effic / 100.0);
if (sp->sct_item[i] < needed) {
pr("Not enough materials in %s\n",
xyas(sp->sct_x, sp->sct_y, player->cnum));
return 0;
}
mat[i] = roundavg(needed);
}
avail = (work * effic + 99) / 100;
if (sp->sct_avail < avail) {
pr("Not enough available work in %s to build a %s\n",
@ -741,7 +732,19 @@ sector_can_build(struct sctstr *sp, short mat[], int work,
return 0;
}
return 1;
ret = 1;
for (i = I_NONE + 1; i <= I_MAX; i++) {
needed = mat[i] * (effic / 100.0);
if (sp->sct_item[i] < needed) {
pr("Not enough %s in %s (need %g more)\n",
ichr[i].i_name, xyas(sp->sct_x, sp->sct_y, player->cnum),
ceil(needed - sp->sct_item[i]));
ret = 0;
}
mat[i] = roundavg(needed);
}
return ret;
}
static void