]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/type.c
License upgrade to GPL version 3 or later
[empserver] / src / lib / common / type.c
index 0a2e9e3e757c1454fca3fb87fbd15641256516e5..ab5ef5021b08314922673709b50fa1970997c292 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-2011, 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,
  *  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/>.
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  type.c: typename to array offset translation
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1989
  *     Steve McClure, 2000
+ *     Markus Armbruster, 2004-2006
  */
 
 #include <config.h>
 
-#include <stddef.h>
-#include <string.h>
-#include "misc.h"
-#include "ship.h"
+#include "file.h"
+#include "item.h"
 #include "land.h"
+#include "match.h"
+#include "nuke.h"
 #include "plane.h"
+#include "product.h"
+#include "prototypes.h"
 #include "sect.h"
-#include "nuke.h"
-#include "file.h"
-#include "common.h"
-#include "match.h"
+#include "ship.h"
 
 /*
  * Return index of sector called NAME in dchr[], or M_NOTFOUND.
@@ -62,39 +61,54 @@ sct_typematch(char *name)
 }
 
 /*
- * Search for NAME in the characteristics table for TYPE, return index.
+ * Search table TYPE for an element matching NAME, return its index.
+ * Accepts EF_BAD, but of course never finds anything then.
  * Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
  * several.
- * If TYPE is EF_SECTOR, search dchr[]
- * If TYPE is EF_SHIP, search mchr[].
- * If TYPE is EF_PLANE, search plchr[].
- * If TYPE is EF_LAND, search lchr[].
- * If TYPE is EF_NUKE, search nchr[].
  */
 int
-typematch(char *name, int type)
+ef_elt_byname(int type, char *name)
 {
     switch (type) {
-    case EF_SECTOR:
+    case EF_BAD:
+       return M_NOTFOUND;
+    case EF_NATION:
+       return cnumb(name);
+    case EF_SECTOR_CHR:
        return sct_typematch(name);
-    case EF_SHIP:
+    case EF_SHIP_CHR:
        return stmtch(name, mchr,
                      offsetof(struct mchrstr, m_name),
                      sizeof(mchr[0]));
-    case EF_LAND:
+    case EF_LAND_CHR:
        return stmtch(name, lchr,
                      offsetof(struct lchrstr, l_name),
                      sizeof(lchr[0]));
-    case EF_PLANE:
+    case EF_PLANE_CHR:
        return stmtch(name, plchr,
                      offsetof(struct plchrstr, pl_name),
                      sizeof(plchr[0]));
-    case EF_NUKE:
+    case EF_NUKE_CHR:
        return stmtch(name, nchr,
                      offsetof(struct nchrstr, n_name),
                      sizeof(nchr[0]));
+    case EF_ITEM:
+       return stmtch(name, ichr,
+                     offsetof(struct ichrstr, i_name),
+                     sizeof(ichr[0]));
+    case EF_PRODUCT:
+       return stmtch(name, pchr,
+                     offsetof(struct pchrstr, p_sname),
+                     sizeof(pchr[0]));
+    case EF_TABLE:
+       return stmtch(name, empfile,
+                     offsetof(struct empfile, name),
+                     sizeof(empfile[0]));
     default:
-       break;
+       if (ef_cadef(type) == symbol_ca)
+           return stmtch(name, ef_ptr(type, 0),
+                         offsetof(struct symbol, name),
+                         sizeof(struct symbol));
     }
     return M_NOTFOUND;
 }