]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/attsub.c
Fix automatic supply of defending and reacting units
[empserver] / src / lib / subs / attsub.c
index c55fc5009f4cf11d41740f1cb73b298aedaed63d..7f47f1323057d6073e0e1e00d7fc6b30027250fb 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -966,7 +966,8 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
 {
     struct nstr_item ni;
     struct lndstr land;
-    double mobcost;
+    double pathcost, mobcost;
+    int reqmob;
     struct ulist *llp;
     struct lchrstr *lcp;
     double att_val;
@@ -1040,17 +1041,18 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
             * of high-mobility sectors (mountains): for those we
             * still require attack mobility.
             */
-           mobcost = att_mobcost(off->own, def, lnd_mobtype(&land));
-           if (mobcost < 1.0) {
+           pathcost = att_mobcost(off->own, def, lnd_mobtype(&land));
+           mobcost = lnd_pathcost(&land, pathcost);
+           if (pathcost < 1.0) {
                if (land.lnd_mobil <= 0) {
                    pr("%s is out of mobility\n", prland(&land));
                    continue;
                }
            } else {
-               mobcost = lnd_pathcost(&land, mobcost);
-               if (land.lnd_mobil < mobcost) {
+               reqmob = MIN(land_mob_max, (int)ceil(mobcost));
+               if (land.lnd_mobil < reqmob) {
                    pr("%s does not have enough mobility (%d needed)\n",
-                      prland(&land), (int)ceil(mobcost));
+                      prland(&land), reqmob);
                    continue;
                }
            }
@@ -1072,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;
@@ -1233,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)
@@ -1481,7 +1485,7 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
     while (nxtitem(&ni, &land) && dtotal + new_land * eff < 1.2 * ototal) {
        if (!land.lnd_own)
            continue;
-       if (!land.lnd_rad_max)
+       if (land.lnd_mission != MI_RESERVE)
            continue;
        if ((land.lnd_x == def->x) && (land.lnd_y == def->y))
            continue;
@@ -1497,18 +1501,19 @@ 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 (land.lnd_mission == MI_RESERVE) {
-           if (!in_oparea((struct empobj *)&land, def->x, def->y))
+       if (list) {
+           resupply_all(&land);
+           putland(land.lnd_uid, &land);
+           if (!lnd_in_supply(&land))
                continue;
        } else {
-           if (mapdist(land.lnd_x, land.lnd_y, def->x, def->y)
-               > lnd_reaction_range(&land))
+           if (!lnd_could_be_supplied(&land))
                continue;
        }
 
+       if (!in_oparea((struct empobj *)&land, def->x, def->y))
+           continue;
+
        getsect(land.lnd_x, land.lnd_y, &sect);
        getsect(def->x, def->y, &dsect);
        if (!BestLandPath(buf, &sect, &dsect, &pathcost,