]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/cargo.c
Update copyright notice
[empserver] / src / lib / common / cargo.c
index fbcd06205d823fc847621226eded1b60424025ab..5c36377d9ab223c32e7df9f040d5fec8effdd7d4 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
@@ -28,7 +27,7 @@
  *  cargo.c: Cargo lists
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2008
+ *     Markus Armbruster, 2009
  */
 
 #include <config.h>
@@ -40,8 +39,8 @@
 #include "unit.h"
 
 struct clink {
-    short next;
-    short head[EF_NUKE - EF_PLANE + 1];
+    int next;
+    int head[EF_NUKE - EF_PLANE + 1];
 };
 
 /*
@@ -70,15 +69,15 @@ struct clink {
  * cargo lists know nothing about that.
  */
 static struct clink *clink[EF_NUKE + 1];
-static short nclink[EF_NUKE + 1];
+static int nclink[EF_NUKE + 1];
 
 /*
  * Return pointer to CL's cargo list head for file type TYPE.
  */
-static short *
+static int *
 clink_headp(struct clink *cl, int type)
 {
-    static short dummy;
+    static int dummy;
 
     if (CANT_HAPPEN(type < EF_PLANE || type > EF_NUKE)) {
        dummy = -1;
@@ -104,7 +103,7 @@ clink_init(struct clink *cl)
  * Check whether *UIDP is a valid uid for file type TYPE.
  */
 static void
-clink_check1(short *uidp, int type)
+clink_check1(int *uidp, int type)
 {
     if (CANT_HAPPEN(*uidp >= nclink[type]))
        *uidp = -1;
@@ -138,7 +137,7 @@ clink_check(int type)
 static void
 clink_add(struct clink *cl, int type, int uid)
 {
-    short *head = clink_headp(cl, type);
+    int *head = clink_headp(cl, type);
 
     if (CANT_HAPPEN(type < 0 || type > EF_NUKE
                    || uid < 0 || uid >= nclink[type]))
@@ -157,10 +156,10 @@ clink_add(struct clink *cl, int type, int uid)
 static void
 clink_rem(struct clink *cl, int type, int uid)
 {
-    short *head = clink_headp(cl, type);
+    int *head = clink_headp(cl, type);
     struct clink *linkv;
     int n;
-    short *p;
+    int *p;
 
     if (CANT_HAPPEN(type < 0 || type > EF_NUKE))
        return;
@@ -241,24 +240,33 @@ unit_cargo_init(void)
        unit_onresize(i);
 
     for (i = 0; (pp = getplanep(i)); i++) {
-       if (!pp->pln_own)
+       if (!pp->pln_own) {
+           if (CANT_HAPPEN(pp->pln_ship >= 0 || pp->pln_land >= 0))
+               pp->pln_ship = pp->pln_land = -1;
            continue;
+       }
        if (CANT_HAPPEN(pp->pln_ship >= 0 && pp->pln_land >= 0))
            pp->pln_land = -1;
        pln_carrier_change(pp, EF_SHIP, -1, pp->pln_ship);
        pln_carrier_change(pp, EF_LAND, -1, pp->pln_land);
     }
     for (i = 0; (lp = getlandp(i)); i++) {
-       if (!lp->lnd_own)
+       if (!lp->lnd_own) {
+           if (CANT_HAPPEN(lp->lnd_ship >= 0 || lp->lnd_land >= 0))
+               lp->lnd_ship = lp->lnd_land = -1;
            continue;
+       }
        if (CANT_HAPPEN(lp->lnd_ship >= 0 && lp->lnd_land >= 0))
            lp->lnd_land = -1;
        lnd_carrier_change(lp, EF_SHIP, -1, lp->lnd_ship);
        lnd_carrier_change(lp, EF_LAND, -1, lp->lnd_land);
     }
     for (i = 0; (np = getnukep(i)); i++) {
-       if (!np->nuk_own)
+       if (!np->nuk_own) {
+           if (CANT_HAPPEN(np->nuk_plane >= 0))
+               np->nuk_plane = -1;
            continue;
+       }
        nuk_carrier_change(np, EF_PLANE, -1, np->nuk_plane);
     }
 }
@@ -268,14 +276,14 @@ unit_cargo_init(void)
  * Return 0 on success, -1 on error.
  * This is the struct empfile onresize callback for units.
  */
-int
+void
 unit_onresize(int type)
 {
     int n, i;
     struct clink *cl;
 
     if (CANT_HAPPEN(type < EF_SHIP || type > EF_NUKE))
-       return -1;
+       return;
 
     n = ef_nelem(type);
     cl = realloc(clink[type], n * sizeof(*clink[type]));
@@ -287,7 +295,6 @@ unit_onresize(int type)
     nclink[type] = n;
     if (ef_flags(type) & EFF_MEM)
        clink_check(type);
-    return 0;
 }
 
 /*
@@ -299,7 +306,7 @@ unit_onresize(int type)
 int
 unit_cargo_first(int type, int uid, int cargo_type)
 {
-    short *headp;
+    int *headp;
 
     if (CANT_HAPPEN(type < EF_SHIP || type > EF_NUKE))
        return -1;