]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/check.c
Update copyright notice
[empserver] / src / lib / subs / check.c
index 4fe77d8b5d0ea503f6ab47ef778439b4b7c2c565..00525518771e0656d2dcf2820ce4b2b3dace22ce 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
  *
  *  Known contributors to this file:
  *     Steve McClure, 1998
- *     Markus Armbruster, 2004-2009
+ *     Markus Armbruster, 2004-2014
  */
 
 #include <config.h>
 
+#include <ctype.h>
 #include "commodity.h"
 #include "empobj.h"
-#include "file.h"
 #include "player.h"
 #include "prototypes.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, size_t sz)
+obj_changed(struct empobj *obj)
 {
-    union empobj_storage old, tobj;
+    union empobj_storage old;
 
-    get_empobj(obj->ef_type, obj->uid, &old);
-    memcpy(&tobj, obj, sz);
-    old.gen.timestamp = tobj.gen.timestamp = 0;
-    old.gen.generation = tobj.gen.generation = 0;
-    if (memcmp(&tobj, &old, sz))
+    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)
 {
-    if (obj_changed((struct empobj *)sectp, sizeof(*sectp))) {
-       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_sect_ok(struct sctstr *sectp)
+{
+    return check_obj_ok((struct empobj *)sectp);
+}
+
 int
 check_ship_ok(struct shpstr *shipp)
 {
-    if (obj_changed((struct empobj *)shipp, sizeof(*shipp))) {
-       pr("Ship #%d has changed!\n", shipp->shp_uid);
-       return 0;
-    }
-    return 1;
+    return check_obj_ok((struct empobj *)shipp);
 }
 
 int
 check_plane_ok(struct plnstr *planep)
 {
-    if (obj_changed((struct empobj *)planep, sizeof(*planep))) {
-       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)
 {
-    if (obj_changed((struct empobj *)landp, sizeof(*landp))) {
-       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)
 {
-    if (obj_changed((struct empobj *)nukep, sizeof(*nukep))) {
-       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)
 {
-    if (obj_changed((struct empobj *)loanp, sizeof(*loanp))) {
-       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)
 {
-    if (obj_changed((struct empobj *)commp, sizeof(*commp))) {
-       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)
 {
-    if (obj_changed((struct empobj *)tp, sizeof(*tp))) {
-       pr("Trade lot #%d has changed!\n", tp->trd_uid);
-       return 0;
-    }
-    return 1;
+    return check_obj_ok((struct empobj *)tp);
 }