]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/attsub.c
Narrow struct sctstr member sct_mobil to char
[empserver] / src / lib / subs / attsub.c
index bec3fd8ff28b0e2111653ed0aa61e46a19f92d34..3a8ada3f7bf5668567e3ff4fb8587217fd800ae2 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
@@ -30,7 +30,7 @@
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1996-2000
- *     Markus Armbruster, 2006-2008
+ *     Markus Armbruster, 2006-2009
  */
 
 #include <config.h>
@@ -353,12 +353,12 @@ put_combat(struct combat *com)
                if ((com->mob - com->mobcost) < -127)
                    sect.sct_mobil = -127;
                else
-                   sect.sct_mobil = (short)(com->mob - com->mobcost);
+                   sect.sct_mobil = com->mob - com->mobcost;
            } else {
                if ((com->mob - com->mobcost) < 0)
                    sect.sct_mobil = 0;
                else
-                   sect.sct_mobil = (short)(com->mob - com->mobcost);
+                   sect.sct_mobil = com->mob - com->mobcost;
            }
        }
        sect.sct_own = com->own;
@@ -709,29 +709,29 @@ att_ask_support(int offset, int *fortp, int *shipp, int *landp,
        *fortp = *shipp = 0;
        *landp = *planep = 0;
 
-       if (!(p = getstarg(player->argp[offset], "Use fort support? ",
-                          buf)))
+       p = getstarg(player->argp[offset], "Use fort support? ", buf);
+       if (!p)
            return RET_SYN;
 
        if ((*p == 'y') || (*p == 'Y'))
            *fortp = 1;
 
-       if (!(p = getstarg(player->argp[offset + 1], "Use ship support? ",
-                          buf)))
+       p = getstarg(player->argp[offset + 1], "Use ship support? ", buf);
+       if (!p)
            return RET_SYN;
 
        if ((*p == 'y') || (*p == 'Y'))
            *shipp = 1;
 
-       if (!(p = getstarg(player->argp[offset + 2], "Use land support? ",
-                          buf)))
+       p = getstarg(player->argp[offset + 2], "Use land support? ", buf);
+       if (!p)
            return RET_SYN;
 
        if ((*p == 'y') || (*p == 'Y'))
            *landp = 1;
 
-       if (!(p = getstarg(player->argp[offset + 3], "Use plane support? ",
-                          buf)))
+       p = getstarg(player->argp[offset + 3], "Use plane support? ", buf);
+       if (!p)
            return RET_SYN;
 
        if ((*p == 'y') || (*p == 'Y'))
@@ -912,7 +912,7 @@ ask_off(int combat_mode, struct combat *off, struct combat *def)
        sprintf(prompt, "Number of mil from %s (max %d) : ",
                prcom(0, off), mob_support);
     }
-    if ((attacking_mil = onearg(0, prompt)) < 0)
+    if ((attacking_mil = onearg(NULL, prompt)) < 0)
        abort_attack();
     if (att_abort(combat_mode, off, def))
        return 0;
@@ -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;
                }
            }
@@ -1070,9 +1072,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
            pr("%s has no offensive strength\n", prland(&land));
            continue;
        }
-       resupply_all(&land);
-       putland(land.lnd_uid, &land);
-       if (!has_supply(&land)) {
+       if (!lnd_supply_all(&land)) {
            pr("%s is out of supply, and cannot %s\n",
               prland(&land), att_mode[combat_mode]);
            continue;
@@ -1233,7 +1233,7 @@ 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);
+       llp->supplied = lnd_supply_all(&land);
        if (!get_land(A_DEFEND, def, land.lnd_uid, llp, 1))
            continue;
        if (lnd_spyval(&land) > *d_spyp)
@@ -1271,7 +1271,8 @@ get_ototal(int combat_mode, struct combat *off, struct emp_qelem *olist,
     for (qp = olist->q_forw; qp != olist; qp = next) {
        next = qp->q_forw;
        llp = (struct ulist *)qp;
-       if (check && !get_land(combat_mode, 0, llp->unit.land.lnd_uid, llp, 0))
+       if (check &&
+           !get_land(combat_mode, NULL, llp->unit.land.lnd_uid, llp, 0))
            continue;
        if (combat_mode == A_ATTACK) {
            w = -1;
@@ -1448,7 +1449,7 @@ put_land(struct emp_qelem *list)
            emp_remque((struct emp_qelem *)llp);
            free(llp);
        } else
-           get_land(A_ATTACK, 0, llp->unit.land.lnd_uid, llp, 0);
+           get_land(A_ATTACK, NULL, llp->unit.land.lnd_uid, llp, 0);
     }
 }
 
@@ -1497,7 +1498,7 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
            continue;
 
        /* Only supplied units can react */
-       if (!has_supply(&land))
+       if (list ? !lnd_supply_all(&land) : !lnd_could_be_supplied(&land))
            continue;
 
        if (!in_oparea((struct empobj *)&land, def->x, def->y))
@@ -1655,7 +1656,8 @@ get_mine_dsupport(struct combat *def, int a_engineer)
     getsect(def->x, def->y, &sect);
 
     if (sect.sct_oldown != player->cnum) {
-       mines = MIN(sect.sct_mines, 20);
+       mines = SCT_LANDMINES(&sect);
+       mines = MIN(mines, 20);
        if (a_engineer)
            mines = ldround(mines / 2.0, 1);
        if (mines > 0) {
@@ -2181,7 +2183,7 @@ take_def(int combat_mode, struct emp_qelem *list, struct combat *off,
 {
     int n;
     int occuppied = 0;
-    struct ulist *llp, *delete_me = 0;
+    struct ulist *llp, *delete_me = NULL;
     char buf[1024];
     struct sctstr sect;
     struct shpstr ship;
@@ -2288,9 +2290,9 @@ ask_move_in(struct combat *off, struct emp_qelem *olist,
            *answerp = 'N';
        if (*answerp == 'Y')
            continue;
+       if (!get_land(A_ATTACK, def, llp->unit.land.lnd_uid, llp, 0))
+           continue;
        if (*answerp != 'N') {
-           if (!get_land(A_ATTACK, def, llp->unit.land.lnd_uid, llp, 0))
-               continue;
            sprintf(prompt, "Move in with %s (%c %d%%) [ynYNq?] ",
                    prland(&llp->unit.land),
                    llp->unit.land.lnd_army ? llp->unit.land.lnd_army : '~',
@@ -2450,7 +2452,8 @@ ask_move_in_off(struct combat *off, struct combat *def)
        return;
     sprintf(prompt, "How many mil to move in from %s (%d max)? ",
            xyas(off->x, off->y, player->cnum), mob_support);
-    if (!(p = getstring(prompt, buf)) || !*p || (num_mil = atoi(p)) <= 0)
+    p = getstring(prompt, buf);
+    if (!p || !*p || (num_mil = atoi(p)) <= 0)
        return;
 /* Make sure we don't move in more than we can support mobility-wise */
     if (num_mil > mob_support)