]> git.pond.sub.org Git - empserver/commitdiff
transport: Don't hardcode material weights
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 28 May 2016 14:21:08 +0000 (16:21 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 17:59:56 +0000 (19:59 +0200)
tran_plane() computes a plane's weight from its materials.  It
hardcodes lcm weight 1, hcm weight 2, and military weight 0.  Use
ichr[].i_lbs instead, which is 1 in the stock game for all three
materials.

While there, support arbitrary materials, even though they aren't yet
possible, just to avoid unnecessary assumptions on possible build
materials.

Since the stock game's planes use fewer military than hcms, they
become up to 15% lighter, except for zep, which becomes 10% heavier.
Missiles use no military and become 20-33% lighter.

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

index 5a71023f5d6e46c6a23aaca14c93c099e06c2629..843f7e2da51a3aee82c3a7ff229adae345880212 100644 (file)
@@ -42,6 +42,7 @@ static int tran_pmap(coord, coord, char *, char *);
 static int tran_nmap(coord, coord, char *, char *);
 static int tran_nuke(void);
 static int tran_plane(void);
+static int pln_weight(struct plnstr *);
 
 int
 tran(void)
@@ -147,7 +148,7 @@ tran_plane(void)
     coord dstx, dsty;
     int mcost;
     int weight, count;
-    int type, dam;
+    int dam;
     struct nstr_item nstr;
     struct plnstr plane;
     struct sctstr sect;
@@ -166,7 +167,6 @@ tran_plane(void)
     while (nxtitem(&nstr, &plane)) {
        if (!player->owner)
            continue;
-       type = plane.pln_type;
        if (plane.pln_ship >= 0) {
            pr("%s is stowed on ship #%d, and can't be transported\n",
               prplane(&plane), plane.pln_ship);
@@ -193,7 +193,7 @@ tran_plane(void)
                return RET_FAIL;
            }
        }
-       weight += plchr[type].pl_mat[I_LCM] + (plchr[type].pl_mat[I_HCM] * 2);
+       weight += pln_weight(&plane);
        ++count;
     }
     if (count == 0) {
@@ -241,6 +241,17 @@ tran_plane(void)
     return RET_OK;
 }
 
+static int
+pln_weight(struct plnstr *pp)
+{
+    int w, i;
+
+    w = 0;
+    for (i = I_NONE + 1; i <= I_MAX; i++)
+       w += plchr[pp->pln_type].pl_mat[i] * ichr[i].i_lbs;
+    return w;
+}
+
 /*
  * Pretty tacky, but it works.
  * If more commands start doing this, then
index cb3d0c07f525409f7fc6e87b624dd4b663706845..1fa3330f11f8c6d7adf024c61e6ced56eafba130 100644 (file)
     Play#1 command transport
     Play#1 output Play#1 1 Looking for best path to 11,-1
     Play#1 output Play#1 1 Using best path 'uuujjjh', movement cost 0.802
-    Play#1 output Play#1 1 Total movement cost = 29
+    Play#1 output Play#1 1 Total movement cost = 26
     Play#1 output Play#1 6 0 625
     Play#1 input reco 0 . 11,-1 ujbgh
     Play#1 command recon
     Play#1 output Play#1 1    7,1    d  100%     127 .. ..     1000    0    0    0 100%  489        0   1
     Play#1 output Play#1 1   -2,2    i  100%     127 .. ..     1000    0    0    0 100%    2        0   1
     Play#1 output Play#1 1    0,2    m  100%     127 .. ..     1000    0    0    0 100%    0        0
-    Play#1 output Play#1 1    2,2    *  100%      98 .. ..     1000   30    0    0 100%  569        0   1
+    Play#1 output Play#1 1    2,2    *  100%     101 .. ..     1000   30    0    0 100%  569        0   1
     Play#1 output Play#1 1    4,2    r  100%     127 .. ..     1000    0    0    0 100%  489        0   1
     Play#1 output Play#1 1    6,2    w  100%     127 .. ..     1000   75    0    0 100%  660        0   1
     Play#1 output Play#1 1    8,2    e  100%     127 .. ..      966    1    0    0 100%  649        0   1
     Play#0 output Play#0 1  10  -11,-11  g  100%     127 .. ..     1000    0    0    0 100%  650    0   1
     Play#0 output Play#0 1   1    3,-11  i  100%     127 .. ..     1000    0    0    0 100%    2    0   1
     Play#0 output Play#0 1   1    5,-11  m  100%     127 .. ..     1000    0    0    0 100%    0    0
-    Play#0 output Play#0 1   1    7,-11  *  100%      98 .. ..     1000   30    0    0 100%  569    0   1
+    Play#0 output Play#0 1   1    7,-11  *  100%     101 .. ..     1000   30    0    0 100%  569    0   1
     Play#0 output Play#0 1   1    9,-11  r  100%     127 .. ..     1000    0    0    0 100%  489    0   1
     Play#0 output Play#0 1   1   11,-11  w  100%     127 .. ..     1000   75    0    0 100%  660    0   1
     Play#0 output Play#0 1   1   13,-11  e  100%     127 .. ..      966    1    0    0 100%  649    0   1