/*
* 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,
* 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/>.
*
* ---
*
* cargo.c: Cargo lists
*
* Known contributors to this file:
- * Markus Armbruster, 2008
+ * Markus Armbruster, 2009
*/
#include <config.h>
#include "unit.h"
struct clink {
- short next;
- short head[EF_NUKE - EF_PLANE + 1];
+ int next;
+ int head[EF_NUKE - EF_PLANE + 1];
};
/*
* 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;
* 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;
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]))
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;
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);
}
}
* 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]));
nclink[type] = n;
if (ef_flags(type) & EFF_MEM)
clink_check(type);
- return 0;
}
/*
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;