]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/type.c
Update copyright notice
[empserver] / src / lib / common / type.c
index ffd990b0134da5a5c7a424eca83cc3c63cb5ecb6..00c5442471658ee3efd08d4d4650a8cec8a63a37 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
  *  Known contributors to this file:
  *     Dave Pare, 1989
  *     Steve McClure, 2000
+ *     Markus Armbruster, 2004-2006
  */
 
-#include <stddef.h>
-#include <string.h>
-#include "misc.h"
-#include "ship.h"
+#include <config.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.
@@ -60,39 +62,51 @@ 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.
  * 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_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;
 }