]> git.pond.sub.org Git - empserver/commitdiff
Fix automatic supply of defending and reacting units
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 14 Feb 2009 17:37:34 +0000 (18:37 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 17 Feb 2009 18:30:35 +0000 (19:30 +0100)
Being in supply is relevant for defending and reacting units.  The
code used has_supply() to check that.

Contrary to its name, has_supply() does not check whether the land
unit has enough supplies to be in supply, but whether it has or could
draw enough.  So, defending and reacting units did not actually draw
any missing supplies.

Fix that in get_dlist() and att_reacting_units() by calling
resupply_all(), then checking with new lnd_in_supply() instead of
has_supply().  The fix of att_reacting_units() is complicated by the
fact that it is also used in the strength command, and should keep not
drawing supplies there.

Rename has_supply() to lnd_could_be_supplied().  Replace its uses
immediately after resupply_all() by lnd_in_supply().

include/prototypes.h
src/lib/commands/load.c
src/lib/commands/stre.c
src/lib/commands/supp.c
src/lib/subs/attsub.c
src/lib/subs/supply.c

index 8a580c54fb39f7dbc041885f216c7f58d6dbee85..1d3ac26fc1a30e1e167a7754dd0bbe197164d0cc 100644 (file)
@@ -682,7 +682,8 @@ extern void snxtsct_dist(struct nstr_sect *, coord, coord, int);
 extern void resupply_all(struct lndstr *);
 extern void resupply_commod(struct lndstr *, i_type);
 extern int supply_commod(int, int, int, i_type, int);
-extern int has_supply(struct lndstr *);
+extern int lnd_in_supply(struct lndstr *);
+extern int lnd_could_be_supplied(struct lndstr *);
 /* takeover.c */
 extern void takeover_land(struct lndstr *, natid);
 extern void takeover(struct sctstr *, natid);
index e6ff0b43891164969e2d254b9b9311a9346238f7..b809a08b59f65baec1184798d6b9ccc882291267 100644 (file)
@@ -653,7 +653,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
            resupply_all(&land);
 #endif
            putland(land.lnd_uid, &land);
-           if (!has_supply(&land))
+           if (!lnd_in_supply(&land))
                pr("WARNING: %s is out of supply!\n", prland(&land));
        } else {
            sprintf(buf, "unloaded in your %s at %s",
@@ -999,7 +999,7 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
            resupply_all(&land);
 #endif
            putland(land.lnd_uid, &land);
-           if (!has_supply(&land))
+           if (!lnd_in_supply(&land))
                pr("WARNING: %s is out of supply!\n", prland(&land));
        } else {
            sprintf(buf, "unloaded in your %s at %s",
index ee3c94c4552db8f7e5e1de7d0798c1115ab43a83..20a96083f623c3197e535987dfa775945a49185f 100644 (file)
@@ -138,7 +138,7 @@ units_in_sector(struct combat *def)
        if (land.lnd_ship >= 0)
            continue;
        d_unit = defense_val(&land);
-       if (!has_supply(&land))
+       if (!lnd_could_be_supplied(&land))
            d_unit /= 2.0;
        dtotal += d_unit;
     }
index 90d31c0f55c8963d4c350d90dbc9b366b73cb052..61f64c041104039196ef3462556350561ca22849 100644 (file)
@@ -53,7 +53,7 @@ supp(void)
        nunits++;
        resupply_all(&land);
        putland(land.lnd_uid, &land);
-       if (has_supply(&land))
+       if (lnd_in_supply(&land))
            pr("%s has supplies\n", prland(&land));
        else
            pr("%s is out of supply\n", prland(&land));
index ba877e3e225e4395851fdafc846d3fd863115368..7f47f1323057d6073e0e1e00d7fc6b30027250fb 100644 (file)
@@ -1074,7 +1074,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
        }
        resupply_all(&land);
        putland(land.lnd_uid, &land);
-       if (!has_supply(&land)) {
+       if (!lnd_in_supply(&land)) {
            pr("%s is out of supply, and cannot %s\n",
               prland(&land), att_mode[combat_mode]);
            continue;
@@ -1235,7 +1235,9 @@ get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
        }
        memset(llp, 0, sizeof(struct ulist));
        emp_insque(&llp->queue, list);
-       llp->supplied = has_supply(&land);
+       resupply_all(&land);
+       putland(land.lnd_uid, &land);
+       llp->supplied = lnd_in_supply(&land);
        if (!get_land(A_DEFEND, def, land.lnd_uid, llp, 1))
            continue;
        if (lnd_spyval(&land) > *d_spyp)
@@ -1499,8 +1501,15 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
            continue;
 
        /* Only supplied units can react */
-       if (!has_supply(&land))
-           continue;
+       if (list) {
+           resupply_all(&land);
+           putland(land.lnd_uid, &land);
+           if (!lnd_in_supply(&land))
+               continue;
+       } else {
+           if (!lnd_could_be_supplied(&land))
+               continue;
+       }
 
        if (!in_oparea((struct empobj *)&land, def->x, def->y))
            continue;
index ce5bf89465757ea4ae5d4e8c4f2108ef9db4448c..d112cea8ca1c5ea4f065f60c0525b7d4eb6b7011 100644 (file)
@@ -86,6 +86,16 @@ resupply_commod(struct lndstr *lp, i_type type)
     }
 }
 
+int
+lnd_in_supply(struct lndstr *lp)
+{
+    if (!opt_NOFOOD) {
+       if (lp->lnd_item[I_FOOD] < get_minimum(lp, I_FOOD))
+           return 0;
+    }
+    return lp->lnd_item[I_SHELL] >= get_minimum(lp, I_SHELL);
+}
+
 /*
  * Actually get the commod
  */
@@ -410,7 +420,7 @@ get_minimum(struct lndstr *lp, i_type type)
 }
 
 int
-has_supply(struct lndstr *lp)
+lnd_could_be_supplied(struct lndstr *lp)
 {
     int shells_needed, shells, keepshells;
     int food, food_needed, keepfood;