]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/check.c
Update copyright notice
[empserver] / src / lib / subs / check.c
index 6e50ebce68aa1d4dc449a25941f5ef4733aa4678..00525518771e0656d2dcf2820ce4b2b3dace22ce 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-2021, 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/>.
  *
  *  ---
  *
  *
  *  Known contributors to this file:
  *     Steve McClure, 1998
+ *     Markus Armbruster, 2004-2014
  */
 
 #include <config.h>
 
+#include <ctype.h>
 #include "commodity.h"
-#include "file.h"
-#include "land.h"
-#include "loan.h"
-#include "misc.h"
-#include "nat.h"
-#include "nsc.h"
-#include "nuke.h"
-#include "plane.h"
+#include "empobj.h"
 #include "player.h"
 #include "prototypes.h"
-#include "sect.h"
-#include "ship.h"
-#include "trade.h"
 #include "xy.h"
 
-/* Note that timestamps make things tricky.  And, we don't
- * really care about the timestamp, we just care about the rest
- * of the structure.  So, we make a copy, and zero the timestamps
- * in both copies, and then compare. */
+static int
+obj_changed(struct empobj *obj)
+{
+    union empobj_storage old;
+
+    if (!get_empobj(obj->ef_type, obj->uid, &old))
+       return 0;
+    if (!ef_typedstr_eq((struct ef_typedstr *)&old,
+                       (struct ef_typedstr *)obj))
+       return 1;
+    ef_mark_fresh(obj->ef_type, obj);
+    return 0;
+}
 
 int
-check_sect_ok(struct sctstr *sectp)
+check_obj_ok(struct empobj *obj)
 {
-    struct sctstr chksect;
-    struct sctstr tsect;
-
-    getsect(sectp->sct_x, sectp->sct_y, &chksect);
-    memcpy(&tsect, sectp, sizeof(struct sctstr));
-    tsect.sct_timestamp = chksect.sct_timestamp = 0;
-    if (memcmp(&tsect, &chksect, sizeof(struct sctstr))) {
-       pr("Sector %s has changed!\n",
-          xyas(sectp->sct_x, sectp->sct_y, player->cnum));
+    char *s;
+
+    if (obj_changed(obj)) {
+       if (obj->ef_type == EF_SECTOR)
+           pr("Sector %s has changed!\n",
+              xyas(obj->x, obj->y, player->cnum));
+       else {
+           s = ef_nameof_pretty(obj->ef_type);
+           pr("%c%s %d has changed!\n", toupper(*s), s + 1, obj->uid);
+       }
        return 0;
     }
     return 1;
 }
 
 int
-check_ship_ok(struct shpstr *shipp)
+check_sect_ok(struct sctstr *sectp)
 {
-    struct shpstr chkship;
-    struct shpstr tship;
+    return check_obj_ok((struct empobj *)sectp);
+}
 
-    getship(shipp->shp_uid, &chkship);
-    memcpy(&tship, shipp, sizeof(struct shpstr));
-    tship.shp_timestamp = chkship.shp_timestamp = 0;
-    if (memcmp(&tship, &chkship, sizeof(struct shpstr))) {
-       pr("Ship #%d has changed!\n", shipp->shp_uid);
-       return 0;
-    }
-    return 1;
+int
+check_ship_ok(struct shpstr *shipp)
+{
+    return check_obj_ok((struct empobj *)shipp);
 }
 
 int
 check_plane_ok(struct plnstr *planep)
 {
-    struct plnstr chkplane;
-    struct plnstr tplane;
-
-    getplane(planep->pln_uid, &chkplane);
-    memcpy(&tplane, planep, sizeof(struct plnstr));
-    tplane.pln_timestamp = chkplane.pln_timestamp = 0;
-    if (memcmp(&tplane, &chkplane, sizeof(struct plnstr))) {
-       pr("Plane #%d has changed!\n", planep->pln_uid);
-       return 0;
-    }
-    return 1;
+    return check_obj_ok((struct empobj *)planep);
 }
 
 int
 check_land_ok(struct lndstr *landp)
 {
-    struct lndstr chkland;
-    struct lndstr tland;
-
-    getland(landp->lnd_uid, &chkland);
-    memcpy(&tland, landp, sizeof(struct lndstr));
-    tland.lnd_timestamp = chkland.lnd_timestamp = 0;
-    if (memcmp(&tland, &chkland, sizeof(struct lndstr))) {
-       pr("Land unit #%d has changed!\n", landp->lnd_uid);
-       return 0;
-    }
-    return 1;
+    return check_obj_ok((struct empobj *)landp);
 }
 
 int
 check_nuke_ok(struct nukstr *nukep)
 {
-    struct nukstr chknuke;
-    struct nukstr tnuke;
-
-    getnuke(nukep->nuk_uid, &chknuke);
-    memcpy(&tnuke, nukep, sizeof(struct nukstr));
-    tnuke.nuk_timestamp = chknuke.nuk_timestamp = 0;
-    if (memcmp(&tnuke, &chknuke, sizeof(struct nukstr))) {
-       pr("Nuke %d has changed!\n", nukep->nuk_uid);
-       return 0;
-    }
-    return 1;
+    return check_obj_ok((struct empobj *)nukep);
 }
 
 int
 check_loan_ok(struct lonstr *loanp)
 {
-    struct lonstr chkloan;
-
-    getloan(loanp->l_uid, &chkloan);
-    if (memcmp(loanp, &chkloan, sizeof(struct lonstr))) {
-       pr("Loan %d has changed!\n", loanp->l_uid);
-       return 0;
-    }
-    return 1;
+    return check_obj_ok((struct empobj *)loanp);
 }
 
 int
 check_comm_ok(struct comstr *commp)
 {
-    struct comstr chkcomm;
-
-    getcomm(commp->com_uid, &chkcomm);
-    if (memcmp(commp, &chkcomm, sizeof(struct comstr))) {
-       pr("Commodity %d has changed!\n", commp->com_uid);
-       return 0;
-    }
-    return 1;
+    return check_obj_ok((struct empobj *)commp);
 }
 
 int
 check_trade_ok(struct trdstr *tp)
 {
-    struct trdstr chktrade;
-
-    gettrade(tp->trd_uid, &chktrade);
-    if (memcmp(tp, &chktrade, sizeof(struct trdstr))) {
-       pr("Trade lot #%d has changed!\n", tp->trd_uid);
-       return 0;
-    }
-    return 1;
+    return check_obj_ok((struct empobj *)tp);
 }