]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/cargo.c
Update copyright notice
[empserver] / src / lib / common / cargo.c
index 0dc371278365835aa9aa50bc0392efab21b7fa38..59ccf84b02abbd1ab8e50664bd83cea9201fcf40 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
@@ -26,7 +26,7 @@
  *  ---
  *
  *  cargo.c: Cargo lists
- * 
+ *
  *  Known contributors to this file:
  *     Markus Armbruster, 2008
  */
@@ -35,6 +35,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 #include "file.h"
 #include "unit.h"
 
@@ -185,9 +186,9 @@ unit_carrier_change(struct empobj *cargo, int type, int old, int new)
 {
     if (CANT_HAPPEN(type < 0 || type > EF_NUKE))
        return;
-    if (old >= 0)
+    if (old >= 0 && !CANT_HAPPEN(old >= nclink[type]))
        clink_rem(&clink[type][old], cargo->ef_type, cargo->uid);
-    if (new >= 0)
+    if (new >= 0 && !CANT_HAPPEN(new >= nclink[type]))
        clink_add(&clink[type][new], cargo->ef_type, cargo->uid);
 }
 
@@ -235,10 +236,9 @@ unit_cargo_init(void)
     struct lndstr *lp;
     struct nukstr *np;
 
-    for (i = EF_SHIP; i <= EF_NUKE; i++) {
-       nclink[i] = 0;
+    memset(nclink, 0, sizeof(nclink));
+    for (i = EF_SHIP; i <= EF_NUKE; i++)
        unit_onresize(i);
-    }
 
     for (i = 0; (pp = getplanep(i)); i++) {
        if (!pp->pln_own)
@@ -285,7 +285,8 @@ unit_onresize(int type)
        clink_init(&cl[i]);
     clink[type] = cl;
     nclink[type] = n;
-    clink_check(type);
+    if (ef_flags(type) & EFF_MEM)
+       clink_check(type);
     return 0;
 }