]> git.pond.sub.org Git - empserver/commitdiff
build: Report missing stuff more nicely for ship, plane, land units
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 12 Jan 2014 17:33:13 +0000 (18:33 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 16 Feb 2014 10:48:34 +0000 (11:48 +0100)
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>
src/lib/commands/buil.c
tests/build/final.xdump
tests/build/journal.log

index 89a42f8e8a139f68cabe0b1fcc55ab164f289a2d..38e7637c0cdc476d7770602783e273130856378b 100644 (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
index 5fc6dc659cd67dc76ad57e38c48b842577a65e50..1202dc29ce9c3318303ab5758a406f14d4a4f7fa 100644 (file)
@@ -11,7 +11,7 @@ owner xloc yloc des effic mobil off loyal terr0 terr1 terr2 terr3 dterr xdist yd
 0 -4 0 0 0 0 0 0 0 0 0 0 0 -4 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0
 1 -2 0 5 100 127 0 0 0 0 0 0 0 -2 0 0 0 0 1 5 0 0 0 0 0 1 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0
 2 1 1 14 100 127 0 0 0 0 0 0 0 1 1 3 0 0 0 14 0 0 0 0 0 2 100 2 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0
-2 3 1 14 60 127 0 0 0 0 0 0 0 3 1 7 0 0 0 14 0 0 0 0 0 2 100 3 0 0 0 0 0 0 0 0 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0
+2 3 1 14 60 127 0 0 0 0 0 0 0 3 1 7 0 0 0 14 0 0 0 0 0 2 100 3 0 0 0 0 0 0 0 0 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0
 2 5 1 14 59 127 0 0 0 0 0 0 0 5 1 11 0 0 1 14 0 0 0 0 0 2 100 50 0 0 0 0 0 0 0 500 500 500 0 500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0
 0 7 1 0 0 0 0 0 0 0 0 0 0 7 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0
 0 9 1 0 0 0 0 0 0 0 0 0 0 9 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0
index 819a77eb646e09c071da3d1bac80f59ddca3bbba..ee168c8b4866e4431b34d12511c675a7470a14e1 100644 (file)
@@ -61,7 +61,8 @@
     Play#1 output Play#1 6 0 635
     Play#1 input build s 4:6,0 pt
     Play#1 command build
-    Play#1 output Play#1 1 Not enough materials in 4,0
+    Play#1 output Play#1 1 Not enough light products in 4,0 (need 4 more)
+    Play#1 output Play#1 1 Not enough heavy products in 4,0 (need 2 more)
     Play#1 output Play#1 1 Sector 6,0 is not 60% efficient.
     Play#1 output Play#1 6 0 634
     Play#1 input move l 0,0 4 jh
@@ -86,8 +87,8 @@
     Play#1 output Play#1 6 0 630
     Play#1 input build s 2:4,0 pt
     Play#1 command build
-    Play#1 output Play#1 1 Not enough materials in 2,0
-    Play#1 output Play#1 1 Not enough materials in 4,0
+    Play#1 output Play#1 1 Not enough heavy products in 2,0 (need 1 more)
+    Play#1 output Play#1 1 Not enough light products in 4,0 (need 1 more)
     Play#1 output Play#1 6 0 629
     Play#1 input move l 0,0 12 jh
     Play#1 command move
     Play#2 output Play#2 6 0 635
     Play#2 input build p 3:5,1 f2
     Play#2 command build
-    Play#2 output Play#2 1 Not enough materials in 3,1
+    Play#2 output Play#2 1 Not enough light products in 3,1 (need 1 more)
+    Play#2 output Play#2 1 Not enough heavy products in 3,1 (need 1 more)
     Play#2 output Play#2 1 Sector 5,1 is not 60% efficient.
     Play#2 output Play#2 6 0 634
     Play#2 input move m -1,1 1 jh
     Play#2 output Play#2 6 0 631
     Play#2 input build p 1:3,1 f2
     Play#2 command build
-    Play#2 output Play#2 1 Not enough materials in 1,1
+    Play#2 output Play#2 1 Not enough light products in 1,1 (need 1 more)
+    Play#2 output Play#2 1 Not enough heavy products in 1,1 (need 1 more)
     Play#2 output Play#2 1 Not enough military for crew in 3,1
     Play#2 output Play#2 6 0 630
     Play#2 input move m -1,1 3 jh
     Play#2 output Play#2 1 COMMODITIES deliver--  distribute
     Play#2 output Play#2 1   sect      sgpidbolhr sgpidbolhr  sh gun  pet iron dust bar  oil  lcm  hcm rad
     Play#2 output Play#2 1    1,1    * .......... ..........   0   0    0    0    0   0    0    2    2   0
-    Play#2 output Play#2 1    3,1    * .......... ..........   0   0    0    0    0   0    0    3    4   0
+    Play#2 output Play#2 1    3,1    * .......... ..........   0   0    0    0    0   0    0    3    3   0
     Play#2 output Play#2 1    5,1    * .......... ..........   0   0    0    0    0   0  500  500  500 500
     Play#2 output Play#2 1 3 sectors
     Play#2 output Play#2 6 0 621
     Play#3 output Play#3 6 0 635
     Play#3 input build l 4:6,2 linf
     Play#3 command build
-    Play#3 output Play#3 1 Not enough materials in 4,2
+    Play#3 output Play#3 1 Not enough light products in 4,2 (need 1 more)
+    Play#3 output Play#3 1 Not enough heavy products in 4,2 (need 1 more)
     Play#3 output Play#3 1 Sector 6,2 is not 60% efficient.
     Play#3 output Play#3 6 0 634
     Play#3 input move l 0,2 1 jjh
     Play#3 output Play#3 6 0 632
     Play#3 input build l 2:4,2 linf
     Play#3 command build
-    Play#3 output Play#3 1 Not enough materials in 2,2
-    Play#3 output Play#3 1 Not enough materials in 4,2
+    Play#3 output Play#3 1 Not enough light products in 2,2 (need 1 more)
+    Play#3 output Play#3 1 Not enough heavy products in 4,2 (need 1 more)
     Play#3 output Play#3 6 0 631
     Play#3 input move l 0,2 4 jh
     Play#3 command move