]> git.pond.sub.org Git - empserver/blobdiff - src/lib/global/nsc.c
Clean up initialization of nat_ca[]
[empserver] / src / lib / global / nsc.c
index e976bf73fe8c6c48a86e6bdf9c051f4e2849f7c3..a088976323d4d48761d67e75b85754725e20315f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, 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
@@ -28,7 +28,7 @@
  *  nsc.c: Empire selection global structures
  * 
  *  Known contributors to this file:
- *     Markus Armbruster, 2004-2006
+ *     Markus Armbruster, 2004-2007
  */
 
 /*
 #include <config.h>
 
 #include <stddef.h>
-#include "misc.h"
-#include "xy.h"
-#include "loan.h"
+#include "empobj.h"
+#include "file.h"
 #include "nsc.h"
-#include "news.h"
-#include "nuke.h"
-#include "plane.h"
-#include "ship.h"
-#include "land.h"
-#include "sect.h"
-#include "trade.h"
-#include "treaty.h"
-#include "genitem.h"
-#include "nat.h"
-#include "map.h"
-#include "commodity.h"
-#include "lost.h"
 #include "product.h"
-#include "file.h"
 
 #define fldoff(str, fld) offsetof(struct str, fld)
 
@@ -120,6 +105,7 @@ struct castr pchr_ca[] = {
 struct castr sect_ca[] = {
     /* uid is encoded in x, y */
     {NSC_NATID, 0, 0, fldoff(sctstr, sct_own), "owner", EF_NATION},
+    {NSC_SHORT, NSC_DEITY, 0, fldoff(sctstr, sct_elev), "elev", EF_BAD},
     {NSC_XCOORD, NSC_CONST, 0, fldoff(sctstr, sct_x), "xloc", EF_BAD},
     {NSC_YCOORD, NSC_CONST, 0, fldoff(sctstr, sct_y), "yloc", EF_BAD},
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_type), "des", EF_SECTOR_CHR},
@@ -157,7 +143,7 @@ struct castr sect_ca[] = {
     {NSC_NATID, NSC_DEITY, 0, fldoff(sctstr, sct_che_target), "che_target",
      EF_NATION},
     {NSC_USHORT, 0, 0, fldoff(sctstr, sct_fallout), "fallout", EF_BAD},
-    {NSC_TIME, 0, 0, fldoff(sctstr, sct_access), "access", EF_BAD},
+    {NSC_SHORT, 0, 0, fldoff(sctstr, sct_access), "access", EF_BAD},
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_road), "road", EF_BAD},
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_rail), "rail", EF_BAD},
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_defense), "dfense", EF_BAD},
@@ -191,20 +177,20 @@ struct castr dchr_ca[] = {
 };
 
 #define NSC_GENITEM(ef_type, ef_chr)                                   \
-{ NSC_SHORT, 0, 0, fldoff(genitem, uid), "uid", ef_type},              \
-{ NSC_NATID, 0, 0, fldoff(genitem, own), "owner", EF_NATION},          \
-{ NSC_XCOORD, 0, 0, fldoff(genitem, x), "xloc", EF_BAD},               \
-{ NSC_YCOORD, 0, 0, fldoff(genitem, y), "yloc", EF_BAD},               \
-{ NSC_CHAR, 0, 0, fldoff(genitem, type), "type", ef_chr},              \
-{ NSC_CHAR, 0, 0, fldoff(genitem, effic), "effic", EF_BAD},            \
-{ NSC_CHAR , 0, 0, fldoff(genitem, mobil), "mobil", EF_BAD},           \
-{ NSC_UCHAR , 0, 0, fldoff(genitem, off), "off", EF_BAD},              \
-{ NSC_SHORT, 0, 0, fldoff(genitem, tech), "tech", EF_BAD},             \
-{ NSC_STRINGY, NSC_EXTRA, 1, fldoff(genitem, group), "group", EF_BAD}, \
-{ NSC_XCOORD, 0, 0, fldoff(genitem, opx), "opx", EF_BAD},              \
-{ NSC_YCOORD, 0, 0, fldoff(genitem, opy), "opy", EF_BAD},              \
-{ NSC_SHORT, 0, 0, fldoff(genitem, mission), "mission", EF_MISSIONS},  \
-{ NSC_SHORT, 0, 0, fldoff(genitem, radius), "radius", EF_BAD}
+{ NSC_SHORT, 0, 0, fldoff(empobj, uid), "uid", ef_type},               \
+{ NSC_NATID, 0, 0, fldoff(empobj, own), "owner", EF_NATION},           \
+{ NSC_XCOORD, 0, 0, fldoff(empobj, x), "xloc", EF_BAD},                \
+{ NSC_YCOORD, 0, 0, fldoff(empobj, y), "yloc", EF_BAD},                \
+{ NSC_CHAR, 0, 0, fldoff(empobj, type), "type", ef_chr},               \
+{ NSC_CHAR, 0, 0, fldoff(empobj, effic), "effic", EF_BAD},             \
+{ NSC_CHAR , 0, 0, fldoff(empobj, mobil), "mobil", EF_BAD},            \
+{ NSC_UCHAR , 0, 0, fldoff(empobj, off), "off", EF_BAD},               \
+{ NSC_SHORT, 0, 0, fldoff(empobj, tech), "tech", EF_BAD},              \
+{ NSC_STRINGY, NSC_EXTRA, 1, fldoff(empobj, group), "group", EF_BAD},  \
+{ NSC_XCOORD, 0, 0, fldoff(empobj, opx), "opx", EF_BAD},               \
+{ NSC_YCOORD, 0, 0, fldoff(empobj, opy), "opy", EF_BAD},               \
+{ NSC_SHORT, 0, 0, fldoff(empobj, mission), "mission", EF_MISSIONS},   \
+{ NSC_SHORT, 0, 0, fldoff(empobj, radius), "radius", EF_BAD}
 
 struct castr ship_ca[] = {
     NSC_GENITEM(EF_SHIP, EF_SHIP_CHR),
@@ -226,7 +212,7 @@ struct castr ship_ca[] = {
     {NSC_SHORT, NSC_DEITY, 0, fldoff(shpstr, shp_pstage), "pstage",
      EF_PLAGUE_STAGES},
     {NSC_SHORT, NSC_DEITY, 0, fldoff(shpstr, shp_ptime), "ptime", EF_BAD},
-    {NSC_TIME, 0, 0, fldoff(shpstr, shp_access), "access", EF_BAD},
+    {NSC_SHORT, 0, 0, fldoff(shpstr, shp_access), "access", EF_BAD},
     {NSC_TIME, NSC_EXTRA, 0, fldoff(shpstr, shp_timestamp), "timestamp",
      EF_BAD},
     {NSC_UCHAR, 0, 0, fldoff(shpstr, shp_mobquota), "mquota", EF_BAD},
@@ -286,7 +272,7 @@ struct castr plane_ca[] = {
     {NSC_CHAR, 0, 0, fldoff(plnstr, pln_nuketype), "nuketype", EF_BAD},
     {NSC_CHAR, NSC_BITS, 0, fldoff(plnstr, pln_flags), "flags",
      EF_PLANE_FLAGS},
-    {NSC_TIME, 0, 0, fldoff(plnstr, pln_access), "access", EF_BAD},
+    {NSC_SHORT, 0, 0, fldoff(plnstr, pln_access), "access", EF_BAD},
     {NSC_TIME, NSC_EXTRA, 0, fldoff(plnstr, pln_timestamp), "timestamp",
      EF_BAD},
     {NSC_FLOAT, 0, 0, fldoff(plnstr, pln_theta), "theta", EF_BAD},
@@ -331,7 +317,7 @@ struct castr land_ca[] = {
     {NSC_SHORT, NSC_DEITY, 0, fldoff(lndstr, lnd_ptime), "ptime", EF_BAD},
     {NSC_SHORT, 0, 0, fldoff(lndstr, lnd_land), "land", EF_BAD},
     {NSC_UCHAR, NSC_EXTRA, 0, fldoff(lndstr, lnd_nland), "nland", EF_BAD},
-    {NSC_TIME, 0, 0, fldoff(lndstr, lnd_access), "access", EF_BAD},
+    {NSC_SHORT, 0, 0, fldoff(lndstr, lnd_access), "access", EF_BAD},
     {NSC_FLOAT, NSC_EXTRA, 0, fldoff(lndstr, lnd_att), "att", EF_BAD},
     {NSC_FLOAT, NSC_EXTRA, 0, fldoff(lndstr, lnd_def), "def", EF_BAD},
     {NSC_INT, NSC_EXTRA, 0, fldoff(lndstr, lnd_vul), "vul", EF_BAD},
@@ -516,11 +502,11 @@ struct castr cou_ca[] = {
      "yorg", EF_BAD},
     {NSC_CHAR, 0, 0, fldoff(natstr, nat_dayno), "dayno", EF_BAD},
     {NSC_CHAR, 0, 0, fldoff(natstr, nat_update), "update", EF_BAD},
-    {NSC_UCHAR, 0, 0, fldoff(natstr, nat_missed), "missed", EF_BAD},
     {NSC_USHORT, 0, 0, fldoff(natstr, nat_tgms), "tgms", EF_BAD},
     {NSC_USHORT, 0, 0, fldoff(natstr, nat_ann), "ann", EF_BAD},
     {NSC_USHORT, 0, 0, fldoff(natstr, nat_minused), "minused", EF_BAD},
     {NSC_SHORT, 0, 0, fldoff(natstr, nat_btu), "btu", EF_BAD},
+    {NSC_SHORT, 0, 0, fldoff(natstr, nat_access), "access", EF_BAD},
     {NSC_LONG, 0, 0, fldoff(natstr, nat_reserve), "milreserve", EF_BAD},
     {NSC_LONG, 0, 0, fldoff(natstr, nat_money), "money", EF_BAD},
     {NSC_TIME, 0, 0, fldoff(natstr, nat_last_login), "login", EF_BAD},
@@ -540,14 +526,13 @@ struct castr cou_ca[] = {
      "contacts", EF_BAD},
     {NSC_UCHAR, NSC_EXTRA | NSC_BITS, MAXNOC, fldoff(natstr, nat_rejects),
      "rejects", EF_NATION_REJECTS},
-    /* FIXME nat_priorities[] */
     {NSC_LONG, NSC_BITS, 0, fldoff(natstr, nat_flags), "flags",
      EF_NATION_FLAGS},
     {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
 };
 
 struct castr nat_ca[sizeof(cou_ca) / sizeof(*cou_ca)];
-/* initialized in ef_init_srv() */
+/* initialized by nsc_init() */
 
 struct castr realm_ca[] = {
     /* uid is encoded in cnum, realm */
@@ -560,6 +545,17 @@ struct castr realm_ca[] = {
     {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
 };
 
+struct castr game_ca[] = {
+    /* no need for uid */
+    {NSC_CHAR, 0, 0, offsetof(struct gamestr, game_upd_disable),
+     "upd_disable", EF_BAD},
+    {NSC_SHORT, 0, 0, offsetof(struct gamestr, game_turn), "turn", EF_BAD},
+    {NSC_SHORT, NSC_DEITY, 0, offsetof(struct gamestr, game_tick), "tick",
+     EF_BAD},
+    {NSC_TIME, NSC_DEITY, 0, offsetof(struct gamestr, game_rt), "rt", EF_BAD},
+    {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
+};
+
 struct castr intrchr_ca[] = {
     /* no need for uid as long as it's not referenced from other tables */
     {NSC_STRING, NSC_CONST, 0, offsetof(struct sctintrins, in_name), "name",
@@ -583,6 +579,11 @@ struct castr rpt_ca[] = {
     {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
 };
 
+struct castr update_ca[] = {
+    {NSC_TIME, 0, 0, 0, "time", EF_BAD},
+    {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
+};
+
 struct castr empfile_ca[] = {
     {NSC_INT, 0, 0, offsetof(struct empfile, uid), "uid", EF_TABLE},
     {NSC_STRING, NSC_CONST, 0, offsetof(struct empfile, name), "name", EF_BAD},
@@ -598,6 +599,7 @@ struct castr symbol_ca[] = {
     {NSC_STRING, NSC_CONST, 0, offsetof(struct symbol, name), "name", EF_BAD},
     {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
 };
+
 struct castr mdchr_ca[] = {
     /* no need for uid */
     /* name must come first, clients may rely on it */
@@ -613,3 +615,21 @@ struct castr mdchr_ca[] = {
      EF_BAD},
     {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
 };
+
+void
+nsc_init(void)
+{
+    int i;
+    unsigned flags;
+
+    for (i = 0; cou_ca[i].ca_name; i++) {
+       nat_ca[i] = cou_ca[i];
+       flags = nat_ca[i].ca_flags;
+       if (flags & NSC_EXTRA)
+           flags &= ~NSC_EXTRA;
+       else if (i != 0)
+           flags |= NSC_DEITY;
+       nat_ca[i].ca_flags = flags;
+    }
+    nat_ca[i] = cou_ca[i];
+}