]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/empobj.c
Update copyright notice
[empserver] / src / lib / common / empobj.c
index 35a18d07f5902c9e3202c88ee9a75713e88873f0..ce9cb1dd766e2693c6fd83b9ca195d529ac9a411 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-2013, 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/>.
  *
  *  ---
  *
  *
  *  empobj.c: Common functions on struct empobj and
  *            union empobj_storage
- * 
+ *
  *  Known contributors to this file:
  *     Ron Koenderink, 2006
- *     Markus Armbruster, 2006
+ *     Markus Armbruster, 2006-2008
  */
 
 #include <config.h>
 
 #include "empobj.h"
 #include "file.h"
+#include "news.h"
 #include "optlist.h"
-#include "prototypes.h"
-
-char *
-obj_nameof(struct empobj *gp)
-{
-    switch (gp->ef_type) {
-    case EF_SHIP:
-       return prship((struct shpstr *)gp);
-    case EF_PLANE:
-       return prplane((struct plnstr *)gp);
-    case EF_LAND:
-       return prland((struct lndstr *)gp);
-    case EF_NUKE:
-       return prnuke((struct nukstr *)gp);
-    }
-    CANT_REACH();
-    return "The Beast #666";
-}
-
-struct empobj *
-get_empobjp(int type, int id)
-{
-    if (CANT_HAPPEN(type == EF_SECTOR || type == EF_BAD))
-       return NULL;
-    return ef_ptr(type, id);
-}
-
-int
-put_empobj(struct empobj *gp)
-{
-    switch (gp->ef_type)
-    {
-    case EF_SECTOR:
-        return ef_write(gp->ef_type, sctoff(gp->x, gp->y), gp);
-    case EF_NATION:
-    case EF_BMAP:
-    case EF_MAP:
-       return ef_write(gp->ef_type, gp->own, gp);
-    default:
-       return ef_write(gp->ef_type, gp->uid, gp);
-    }
-}
-
-struct empobj_chr *
-get_empobj_chr(struct empobj *gp)
-{
-    switch (gp->ef_type) {
-    case EF_LAND:
-       return (struct empobj_chr *)&lchr[(int)gp->type];
-    case EF_SHIP:
-       return (struct empobj_chr *)&mchr[(int)gp->type];
-    case EF_PLANE:
-       return (struct empobj_chr *)&plchr[(int)gp->type];
-    case EF_NUKE:
-       return (struct empobj_chr *)&nchr[(int)gp->type];
-    case EF_SECTOR:
-       return (struct empobj_chr *)&dchr[(int)gp->type];
-    }
-    CANT_REACH();
-    return NULL;
-}
+#include "product.h"
 
 char *
-emp_obj_chr_name(struct empobj *gp)
+empobj_chr_name(struct empobj *gp)
 {
     switch (gp->ef_type) {
     case EF_LAND:
@@ -116,7 +56,7 @@ emp_obj_chr_name(struct empobj *gp)
        return dchr[(int)gp->type].d_name;
     }
     CANT_REACH();
-    return NULL;
+    return "The Beast";
 }
 
 int
@@ -135,3 +75,45 @@ get_empobj_mob_max(int type)
     CANT_REACH();
     return -1;
 }
+
+int
+empobj_in_use(int type, void *p)
+{
+    switch (type) {
+    case EF_SHIP:
+    case EF_PLANE:
+    case EF_LAND:
+    case EF_NUKE:
+    case EF_TRADE:
+    case EF_COMM:
+    case EF_LOST:
+       return ((struct empobj *)p)->own != 0;
+    case EF_NATION:
+    case EF_COUNTRY:
+       return ((struct natstr *)p)->nat_stat != STAT_UNUSED;
+    case EF_NEWS:
+       return ((struct nwsstr *)p)->nws_vrb != 0;
+    case EF_TREATY:
+       return ((struct trtstr *)p)->trt_status != TS_FREE;
+    case EF_LOAN:
+       return ((struct lonstr *)p)->l_status != LS_FREE;
+    case EF_REALM:
+       return empobj_in_use(EF_NATION,
+                            ef_ptr(EF_NATION,
+                                   ((struct realmstr *)p)->r_cnum));
+    case EF_PRODUCT:
+       return ((struct pchrstr *)p)->p_sname[0];
+    case EF_SHIP_CHR:
+       return ((struct mchrstr *)p)->m_name[0];
+    case EF_PLANE_CHR:
+       return ((struct plchrstr *)p)->pl_name[0];
+    case EF_LAND_CHR:
+       return ((struct lchrstr *)p)->l_name[0];
+    case EF_NUKE_CHR:
+       return ((struct nchrstr *)p)->n_name[0];
+    case EF_NEWS_CHR:
+       return ((struct rptstr *)p)->r_newspage != 0;
+    default:
+       return 1;
+    }
+}