]> git.pond.sub.org Git - empserver/commitdiff
build: Report missing stuff more nicely for bridges
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 13 Jan 2014 08:23:26 +0000 (09:23 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 16 Feb 2014 10:51:50 +0000 (11:51 +0100)
By switching build_nuke() to sector_can_build(), build_charge().

Report missing available work, or else missing materials, or else
missing money, for consistency with the other things you can build.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/commands/buil.c
tests/build/journal.log

index 5821dd97e7c6fd7df90f8e88454fdb11930dc794..3fafc904293deac3e8439f82e812d6513de729d1 100644 (file)
@@ -472,11 +472,11 @@ build_bridge(char what)
 static int
 build_bspan(struct sctstr *sp)
 {
-    short *vec = sp->sct_item;
     struct sctstr sect;
+    short mat[I_MAX+1];
+    int work;
     int val;
     int newx, newy;
-    int avail;
     int nx, ny, i, good = 0;
     char *p;
     char buf[1024];
@@ -490,29 +490,14 @@ build_bspan(struct sctstr *sp)
        }
     }
 
-    if (sp->sct_effic < 60 && !player->god) {
-       pr("Sector %s is not 60%% efficient.\n",
-          xyas(sp->sct_x, sp->sct_y, player->cnum));
-       return 0;
-    }
+    memset(mat, 0, sizeof(mat));
+    mat[I_HCM] = buil_bh;
+    work = (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100;
 
-    if (vec[I_HCM] < buil_bh) {
-       pr("%s only has %d unit%s of hcm,\n",
-          xyas(sp->sct_x, sp->sct_y, player->cnum),
-          vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
-       pr("(a bridge span requires %d)\n", buil_bh);
+    if (!sector_can_build(sp, mat, work, 100, dchr[SCT_BSPAN].d_name))
        return 0;
-    }
-
     if (!build_can_afford(buil_bc, 100, dchr[SCT_BSPAN].d_name))
        return 0;
-    avail = (SCT_BLD_WORK(0, buil_bh) * SCT_MINEFF + 99) / 100;
-    if (sp->sct_avail < avail) {
-       pr("Not enough available work in %s to build a bridge\n",
-          xyas(sp->sct_x, sp->sct_y, player->cnum));
-       pr(" (%d available work required)\n", avail);
-       return 0;
-    }
     if (!player->argp[3]) {
        pr("Bridge head at %s\n",
           xyas(sp->sct_x, sp->sct_y, player->cnum));
@@ -522,7 +507,6 @@ build_bspan(struct sctstr *sp)
     if (!p || !*p) {
        return 0;
     }
-    /* Sanity check time */
     if (!check_sect_ok(sp))
        return 0;
 
@@ -554,8 +538,8 @@ build_bspan(struct sctstr *sp)
            return 0;
        }
     }                          /* end EASY_BRIDGES */
-    sp->sct_avail -= avail;
-    player->dolcost += buil_bc;
+    build_charge(sp, mat, work, buil_bc, 100);
+
     sect.sct_type = SCT_BSPAN;
     sect.sct_newtype = SCT_BSPAN;
     sect.sct_effic = SCT_MINEFF;
@@ -574,18 +558,17 @@ build_bspan(struct sctstr *sp)
     putsect(&sect);
     pr("Bridge span built over %s\n",
        xyas(sect.sct_x, sect.sct_y, player->cnum));
-    vec[I_HCM] -= buil_bh;
     return 1;
 }
 
 static int
 build_btower(struct sctstr *sp)
 {
-    short *vec = sp->sct_item;
     struct sctstr sect;
+    short mat[I_MAX+1];
+    int work;
     int val;
     int newx, newy;
-    int avail;
     char *p;
     char buf[1024];
     int i;
@@ -597,29 +580,14 @@ build_btower(struct sctstr *sp)
        return 0;
     }
 
-    if (sp->sct_effic < 60 && !player->god) {
-       pr("Sector %s is not 60%% efficient.\n",
-          xyas(sp->sct_x, sp->sct_y, player->cnum));
-       return 0;
-    }
+    memset(mat, 0, sizeof(mat));
+    mat[I_HCM] = buil_tower_bh;
+    work = (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100;
 
-    if (vec[I_HCM] < buil_tower_bh) {
-       pr("%s only has %d unit%s of hcm,\n",
-          xyas(sp->sct_x, sp->sct_y, player->cnum),
-          vec[I_HCM], vec[I_HCM] > 1 ? "s" : "");
-       pr("(a bridge tower requires %d)\n", buil_tower_bh);
+    if (!sector_can_build(sp, mat, work, 100, dchr[SCT_BTOWER].d_name))
        return 0;
-    }
-
     if (!build_can_afford(buil_tower_bc, 100, dchr[SCT_BTOWER].d_name))
        return 0;
-    avail = (SCT_BLD_WORK(0, buil_tower_bh) * SCT_MINEFF + 99) / 100;
-    if (sp->sct_avail < avail) {
-       pr("Not enough available work in %s to build a bridge tower\n",
-          xyas(sp->sct_x, sp->sct_y, player->cnum));
-       pr(" (%d available work required)\n", avail);
-       return 0;
-    }
     if (!player->argp[3]) {
        pr("Building from %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum));
        nav_map(sp->sct_x, sp->sct_y, 1);
@@ -628,7 +596,6 @@ build_btower(struct sctstr *sp)
     if (!p || !*p) {
        return 0;
     }
-    /* Sanity check time */
     if (!check_sect_ok(sp))
        return 0;
 
@@ -659,8 +626,8 @@ build_btower(struct sctstr *sp)
        }
     }
 
-    sp->sct_avail -= avail;
-    player->dolcost += buil_tower_bc;
+    build_charge(sp, mat, work, buil_tower_bc, 100);
+
     sect.sct_type = SCT_BTOWER;
     sect.sct_newtype = SCT_BTOWER;
     sect.sct_effic = SCT_MINEFF;
@@ -679,7 +646,6 @@ build_btower(struct sctstr *sp)
     putsect(&sect);
     pr("Bridge tower built in %s\n",
        xyas(sect.sct_x, sect.sct_y, player->cnum));
-    vec[I_HCM] -= buil_tower_bh;
     return 1;
 }
 
index 00e013c1e024d023a3a0da52ecffa5cca40bfb90..1650dfff6274877bd42bba201eb3f2a2d56cd04e 100644 (file)
     Play#5 output Play#5 6 0 639
     Play#5 input build b 4:6,4 n
     Play#5 command build
-    Play#5 output Play#5 1 4,4 only has 0 unit of hcm,
-    Play#5 output Play#5 1 (a bridge span requires 100)
+    Play#5 output Play#5 1 Not enough heavy products in 4,4 (need 100 more)
     Play#5 output Play#5 1 Sector 6,4 is not 60% efficient.
     Play#5 output Play#5 6 0 638
     Play#5 input move h 0,4 99 ggh
     Play#5 output Play#5 6 0 637
     Play#5 input build b -4,4 n
     Play#5 command build
-    Play#5 output Play#5 1 -4,4 only has 99 units of hcm,
-    Play#5 output Play#5 1 (a bridge span requires 100)
+    Play#5 output Play#5 1 Not enough heavy products in -4,4 (need 1 more)
     Play#5 output Play#5 6 0 636
     Play#5 input move h 0,4 201 ggh
     Play#5 command move
     Play#5 output Play#5 6 0 629
     Play#5 input build b -4:4,4 ?des#c&des#w b
     Play#5 command build
-    Play#5 output Play#5 1 Not enough available work in -4,4 to build a bridge
+    Play#5 output Play#5 1 Not enough available work in -4,4 to build a bridge span
     Play#5 output Play#5 1  (40 available work required)
-    Play#5 output Play#5 1 2,4 only has 0 unit of hcm,
-    Play#5 output Play#5 1 (a bridge span requires 100)
+    Play#5 output Play#5 1 Not enough heavy products in 2,4 (need 100 more)
     Play#5 output Play#5 1 Bridge span built over 3,5
     Play#5 output Play#5 1 That just cost you $1000.00
     Play#5 output Play#5 6 0 628
     Play#9 input build t -9:-8,-5:-4 b
     Play#9 command build
     Play#9 output Play#9 1 Sector -9,-5 is not 60% efficient.
-    Play#9 output Play#9 1 -8,-4 only has 0 unit of hcm,
-    Play#9 output Play#9 1 (a bridge tower requires 300)
+    Play#9 output Play#9 1 Not enough heavy products in -8,-4 (need 300 more)
     Play#9 output Play#9 6 0 638
     Play#9 input move h 0,-4 299 gyggbh
     Play#9 command move
     Play#9 output Play#9 6 0 637
     Play#9 input build t -8,-4 g
     Play#9 command build
-    Play#9 output Play#9 1 -8,-4 only has 299 units of hcm,
-    Play#9 output Play#9 1 (a bridge tower requires 300)
+    Play#9 output Play#9 1 Not enough heavy products in -8,-4 (need 1 more)
     Play#9 output Play#9 6 0 636
     Play#9 input move h 0,-4 601 gyggbh
     Play#9 command move
     Play#7 output Play#7 6 0 638
     Play#7 input build b 4:6,-2 u
     Play#7 command build
-    Play#7 output Play#7 1 4,-2 only has 0 unit of hcm,
-    Play#7 output Play#7 1 (a bridge span requires 100)
+    Play#7 output Play#7 1 Not enough heavy products in 4,-2 (need 100 more)
     Play#7 output Play#7 1 Sector 6,-2 is not 60% efficient.
     Play#7 output Play#7 6 0 637
     Play#7 input move h 0,-2 99 jh
     Play#7 output Play#7 6 0 636
     Play#7 input build b 2,-2 u
     Play#7 command build
-    Play#7 output Play#7 1 2,-2 only has 99 units of hcm,
-    Play#7 output Play#7 1 (a bridge span requires 100)
+    Play#7 output Play#7 1 Not enough heavy products in 2,-2 (need 1 more)
     Play#7 output Play#7 6 0 635
     Play#7 input move h 0,-2 201 jh
     Play#7 command move
     Play#7 output Play#7 6 0 628
     Play#7 input build b 2:4,-2
     Play#7 command build
-    Play#7 output Play#7 1 Not enough available work in 2,-2 to build a bridge
+    Play#7 output Play#7 1 Not enough available work in 2,-2 to build a bridge span
     Play#7 output Play#7 1  (40 available work required)
     Play#7 output Play#7 1 Bridge head at 4,-2
     Play#7 output Play#7 1  . .