]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/empobj.c
Update copyright notice
[empserver] / src / lib / common / empobj.c
index af371bbd1658a03a6013a2ea9d5fa41d34448cf9..ce9cb1dd766e2693c6fd83b9ca195d529ac9a411 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, 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"
+#include "product.h"
 
 char *
-obj_nameof(struct empobj *gp)
+empobj_chr_name(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_HAPPEN("unsupported TYPE");
-    return "";
-}
-
-
-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);
-    }
-}
-
-void *
-get_empobj_chr(struct empobj *gp)
-{
-    void *cp;
-
-    switch (gp->ef_type) {
-    case EF_LAND:
-       cp = &lchr[(int)gp->type];
-       break;
+       return lchr[(int)gp->type].l_name;
     case EF_SHIP:
-       cp = &mchr[(int)gp->type];
-       break;
+       return mchr[(int)gp->type].m_name;
     case EF_PLANE:
-       cp = &plchr[(int)gp->type];
-       break;
+       return plchr[(int)gp->type].pl_name;
     case EF_NUKE:
-       cp = &nchr[(int)gp->type];
-       break;
+       return nchr[(int)gp->type].n_name;
     case EF_SECTOR:
-       cp = &dchr[(int)gp->type];
-       break;
-    default:
-        CANT_HAPPEN("unsupported TYPE");
-        cp = NULL;
-       break;
+       return dchr[(int)gp->type].d_name;
     }
-    return cp;
+    CANT_REACH();
+    return "The Beast";
 }
 
 int
-get_empobj_mob_max(int ef_type)
+get_empobj_mob_max(int type)
 {
-    switch (ef_type) {
+    switch (type) {
     case EF_SHIP:
        return ship_mob_max;
     case EF_LAND:
@@ -115,8 +71,49 @@ get_empobj_mob_max(int ef_type)
        return plane_mob_max;
     case EF_SECTOR:
        return sect_mob_max;
+    }
+    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:
-       CANT_REACH();
-       return -1;
+       return 1;
     }
 }