]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/load.c
Rearrange uses of getrel() slightly
[empserver] / src / lib / commands / load.c
index e6ff0b43891164969e2d254b9b9311a9346238f7..4e46212a98cca224b17edd63bc483b05a4f041be 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -31,7 +31,7 @@
  *     David Sharnoff, 1987
  *     Ken Stevens, 1995 (rewritten)
  *     Steve McClure, 1998-2000
- *     Markus Armbruster, 2004-2008
+ *     Markus Armbruster, 2004-2009
  */
 
 #include <config.h>
@@ -50,8 +50,8 @@
 /*
  * The values 1 and -1 are important below, don't change them.
  */
-#define        LOAD    1
-#define        UNLOAD  -1
+#define LOAD   1
+#define UNLOAD -1
 
 static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp,
                           int noisy, int load_unload, int *nshipsp);
@@ -83,9 +83,9 @@ load(void)
     char *p;
     char buf[1024];
 
-    if (!(p = getstarg(player->argp[1],
-                      "What commodity (or 'plane' or 'land')? ", buf))
-       || !*p)
+    p = getstarg(player->argp[1],
+                "What commodity (or 'plane' or 'land')? ", buf);
+    if (!p || !*p)
        return RET_SYN;
 
     if (!strncmp(p, "plane", 5))
@@ -99,7 +99,8 @@ load(void)
        return RET_SYN;
     }
 
-    if (!(p = getstarg(player->argp[2], "Ship(s): ", buf)) || !*p)
+    p = getstarg(player->argp[2], "Ship(s): ", buf);
+    if (!p || !*p)
        return RET_SYN;
 
     noisy = isdigit(*p);
@@ -142,7 +143,8 @@ load(void)
                   xyas(sect.sct_x, sect.sct_y, player->cnum));
            continue;
        }
-       if (!player->owner && load_unload == UNLOAD
+       if (load_unload == UNLOAD
+           && !player->owner
            && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
            if (noisy)
                pr("You can't unload into an unfriendly %s\n",
@@ -166,23 +168,21 @@ load(void)
 
        switch (type) {
        case EF_PLANE:
-           if (0 !=
-               (retval =
-                load_plane_ship(&sect, &ship, noisy, load_unload,
-                                &nships)))
+           retval = load_plane_ship(&sect, &ship, noisy, load_unload,
+                                    &nships);
+           if (retval != 0)
                return retval;
            break;
        case EF_LAND:
-           if (0 !=
-               (retval =
-                load_land_ship(&sect, &ship, noisy, load_unload,
-                               &nships)))
+           retval = load_land_ship(&sect, &ship, noisy, load_unload,
+                                   &nships);
+           if (retval != 0)
                return retval;
            break;
        case EF_SECTOR:
-           if (0 !=
-               (retval =
-                load_comm_ship(&sect, &ship, ich, load_unload, &nships)))
+           retval = load_comm_ship(&sect, &ship, ich, load_unload,
+                                   &nships);
+           if (retval != 0)
                return retval;
        }
        /* load/unload plague */
@@ -218,9 +218,9 @@ lload(void)
     char *p;
     char buf[1024];
 
-    if (!(p = getstarg(player->argp[1],
-                      "What commodity (or 'plane' or 'land')? ", buf))
-       || !*p)
+    p = getstarg(player->argp[1],
+                "What commodity (or 'plane' or 'land')? ", buf);
+    if (!p || !*p)
        return RET_SYN;
     if (!strncmp(p, "plane", 5))
        type = EF_PLANE;
@@ -233,7 +233,8 @@ lload(void)
        return RET_SYN;
     }
 
-    if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p)
+    p = getstarg(player->argp[2], "Unit(s): ", buf);
+    if (!p || !*p)
        return RET_SYN;
 
     noisy = isdigit(*p);
@@ -281,23 +282,21 @@ lload(void)
 
        switch (type) {
        case EF_LAND:
-           if (0 !=
-               (retval =
-                load_land_land(&sect, &land, noisy, load_unload,
-                               &nunits)))
+           retval = load_land_land(&sect, &land, noisy, load_unload,
+                                   &nunits);
+           if (retval != 0)
                return retval;
            break;
        case EF_PLANE:
-           if (0 !=
-               (retval =
-                load_plane_land(&sect, &land, noisy, load_unload,
-                                &nunits)))
+           retval = load_plane_land(&sect, &land, noisy, load_unload,
+                                    &nunits);
+           if (retval != 0)
                return retval;
            break;
        case EF_SECTOR:
-           if (0 !=
-               (retval =
-                load_comm_land(&sect, &land, ich, load_unload, &nunits)))
+           retval = load_comm_land(&sect, &land, ich, load_unload,
+                                   &nunits);
+           if (retval != 0)
                return retval;
        }
        /* load/unload plague */
@@ -321,7 +320,7 @@ lload(void)
 
 static int
 move_amount(int sect_amt, int unit_amt, int unit_max,
-           int load_unload, int amount)
+          int load_unload, int amount)
 {
     int move_amt;
 
@@ -458,27 +457,24 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
            continue;
        }
 
-       /* Plane sanity done */
-       /* Find the right ship */
        if (load_unload == UNLOAD) {
            if (pln.pln_ship != sp->shp_uid)
                continue;
        } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
            continue;
 
-       /* ship to (plane or missle) sanity */
        if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
-           if (plchr[(int)pln.pln_type].pl_flags & P_L) {
-               strcpy(buf, "planes");
-           } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
-               strcpy(buf, "choppers");
-           } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
-               strcpy(buf, "missiles");
-           } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
-               strcpy(buf, "extra light planes");
-           }                   /* else impossible */
-           if (noisy)
-               pr("%s cannot carry %s.\n", prship(sp), buf);
+           if (noisy) {
+               if (plchr[(int)pln.pln_type].pl_flags & P_K)
+                   p = "choppers";
+               else if (plchr[(int)pln.pln_type].pl_flags & P_E)
+                   p = "extra light planes";
+               else if (plchr[(int)pln.pln_type].pl_flags & P_M)
+                   p = "missiles";
+               else
+                   p = "planes";
+               pr("%s cannot carry %s.\n", prship(sp), p);
+           }
            continue;
        }
        /* Fit plane on ship */
@@ -644,17 +640,19 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
            gift(sp->shp_own, player->cnum, &land, buf);
            land.lnd_ship = sp->shp_uid;
            land.lnd_harden = 0;
-#if 0
-           /*
-            * FIXME if this supplies from the sector, the putsect in
-            * load() / lload() duplicates those supplies, causing a
-            * seqno mismatch
-            */
-           resupply_all(&land);
-#endif
            putland(land.lnd_uid, &land);
-           if (!has_supply(&land))
+#if 0
+          /*
+           * FIXME if this supplies from the sector, the putsect in
+           * load() / lload() duplicates those supplies, causing a
+           * seqno mismatch
+           */
+           if (!lnd_supply_all(&land))
                pr("WARNING: %s is out of supply!\n", prland(&land));
+#else
+           if (!lnd_in_supply(&land))
+               pr("WARNING: %s is out of supply!\n", prland(&land));
+#endif
        } else {
            sprintf(buf, "unloaded in your %s at %s",
                    dchr[sectp->sct_type].d_name,
@@ -693,7 +691,8 @@ load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
            (load_unload == UNLOAD) ?
            "unload from" : "load onto",
            prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
-    if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
+    p = getstarg(player->argp[3], prompt, buf);
+    if (!p || !*p)
        return RET_SYN;
 
     if (!still_ok_ship(sectp, sp))
@@ -705,7 +704,7 @@ load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
                           load_unload, atoi(p));
     if (!load_comm_ok(sectp, sp->shp_own, item, move_amt))
        return RET_OK;
-    if (!want_to_abandon(sectp, item, move_amt, 0))
+    if (!want_to_abandon(sectp, item, move_amt, NULL))
        return RET_FAIL;
     if (!still_ok_ship(sectp, sp))
        return RET_SYN;
@@ -854,7 +853,8 @@ load_comm_land(struct sctstr *sectp, struct lndstr *lp,
            (load_unload == UNLOAD) ?
            "unload from" : "load onto",
            prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
-    if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
+    p = getstarg(player->argp[3], prompt, buf);
+    if (!p || !*p)
        return RET_SYN;
 
     if (!still_ok_land(sectp, lp))
@@ -994,13 +994,15 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
            gift(lp->lnd_own, player->cnum, &land, buf);
            land.lnd_land = lp->lnd_uid;
            land.lnd_harden = 0;
-#if 0
-           /* FIXME same issue as in load_land_ship() */
-           resupply_all(&land);
-#endif
            putland(land.lnd_uid, &land);
-           if (!has_supply(&land))
+#if 0
+          /* FIXME same issue as in load_land_ship() */
+           if (!lnd_supply_all(&land))
                pr("WARNING: %s is out of supply!\n", prland(&land));
+#else
+           if (!lnd_in_supply(&land))
+               pr("WARNING: %s is out of supply!\n", prland(&land));
+#endif
        } else {
            sprintf(buf, "unloaded in your %s at %s",
                    dchr[sectp->sct_type].d_name,