]> git.pond.sub.org Git - empserver/blobdiff - src/lib/global/nsc.c
Update copyright notice.
[empserver] / src / lib / global / nsc.c
index 9f71ea68c25f83c40c7f509a661993a1b7922cb8..86bbbc3704fbcbd5a54256070005266bb45c60c0 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-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -29,7 +29,6 @@
  * 
  *  Known contributors to this file:
  *     Markus Armbruster, 2004-2006
- *  
  */
 
 /*
 #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)
 
-#define NSC_IELT(name, pfx, sfx, base, itype)          \
-{NSC_SHORT, 0, 0, ((base) + (itype)*sizeof(u_short)),  \
+#define NSC_IELT(name, pfx, sfx, base, itype)                  \
+{NSC_SHORT, 0, 0, ((base) + (itype)*sizeof(unsigned short)),   \
 sizeof(sfx) == 1 ? name : pfx sfx, EF_BAD}
 
 #define NSC_IVEC(base, sfx)            \
@@ -115,7 +99,6 @@ struct castr pchr_ca[] = {
     {NSC_INT, 0, 0, offsetof(struct pchrstr, p_nlndx), "nlndx", EF_LEVEL},
     {NSC_INT, 0, 0, offsetof(struct pchrstr, p_nlmin), "nlmin", EF_BAD},
     {NSC_INT, 0, 0, offsetof(struct pchrstr, p_nllag), "nllag", EF_BAD},
-    {NSC_INT, 0, 0, offsetof(struct pchrstr, p_effic), "effic", EF_BAD},
     {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
 };
 
@@ -124,7 +107,7 @@ struct castr sect_ca[] = {
     {NSC_NATID, 0, 0, fldoff(sctstr, sct_own), "owner", EF_NATION},
     {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_TYPEID, 0, 0, fldoff(sctstr, sct_type), "des", EF_SECTOR_CHR},
+    {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_type), "des", EF_SECTOR_CHR},
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_effic), "effic", EF_BAD},
     {NSC_SHORT, 0, 0, fldoff(sctstr, sct_mobil), "mobil", EF_BAD},
     {NSC_UCHAR, NSC_DEITY, 0, fldoff(sctstr, sct_loyal), "loyal", EF_BAD},
@@ -133,12 +116,13 @@ struct castr sect_ca[] = {
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_terr1), "terr1", EF_BAD},
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_terr2), "terr2", EF_BAD},
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_terr3), "terr3", EF_BAD},
+    {NSC_UCHAR, NSC_DEITY, 0, fldoff(sctstr, sct_dterr), "dterr", EF_BAD},
     {NSC_XCOORD, 0, 0, fldoff(sctstr, sct_dist_x), "xdist", EF_BAD},
     {NSC_YCOORD, 0, 0, fldoff(sctstr, sct_dist_y), "ydist", EF_BAD},
     {NSC_SHORT, 0, 0, fldoff(sctstr, sct_avail), "avail", EF_BAD},
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_work), "work", EF_BAD},
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_coastal), "coastal", EF_BAD},
-    {NSC_TYPEID, 0, 0, fldoff(sctstr, sct_newtype), "newdes", EF_SECTOR_CHR},
+    {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_newtype), "newdes", EF_SECTOR_CHR},
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_min), "min", EF_BAD},
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_gmin), "gold", EF_BAD},
     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_fertil), "fert", EF_BAD},
@@ -149,6 +133,7 @@ struct castr sect_ca[] = {
     NSC_IVEC(fldoff(sctstr, sct_item), ""),
     NSC_IVEC(fldoff(sctstr, sct_dist), "_dist"),
     NSC_IVEC(fldoff(sctstr, sct_del), "_del"),
+    /* should let old owner access mines, but can't express that: */
     {NSC_SHORT, NSC_DEITY, 0, fldoff(sctstr, sct_mines), "mines", EF_BAD},
     {NSC_SHORT, NSC_DEITY, 0, fldoff(sctstr, sct_pstage), "pstage",
      EF_PLAGUE_STAGES},
@@ -172,7 +157,9 @@ struct castr dchr_ca[] = {
     {NSC_STRINGY, NSC_CONST, 1, offsetof(struct dchrstr, d_mnem), "mnem",
      EF_BAD},
     {NSC_INT, 0, 0, offsetof(struct dchrstr, d_prd), "prd", EF_PRODUCT},
-    {NSC_INT, 0, 0, offsetof(struct dchrstr, d_mcst), "mcst", EF_BAD},
+    {NSC_INT, 0, 0, offsetof(struct dchrstr, d_peffic), "peffic", EF_BAD},
+    {NSC_FLOAT, 0, 0, offsetof(struct dchrstr, d_mob0), "mob0", EF_BAD},
+    {NSC_FLOAT, 0, 0, offsetof(struct dchrstr, d_mob1), "mob1", EF_BAD},
     {NSC_SITYPE(d_navigation), 0, 0, offsetof(struct dchrstr, d_nav), "nav",
      EF_SECTOR_NAVIGATION},
     {NSC_SITYPE(i_packing), 0, 0, offsetof(struct dchrstr, d_pkg), "pkg",
@@ -189,23 +176,24 @@ 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_TYPEID, 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_SHORT, 0, 0, fldoff(genitem, tech), "tech", EF_BAD},             \
-{ NSC_CHAR, NSC_EXTRA, 0, 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),
-    {NSC_CHAR, 0, 0, fldoff(shpstr, shp_fleet), "fleet", EF_BAD},
+    {NSC_STRINGY, 0, 1, fldoff(shpstr, shp_fleet), "fleet", EF_BAD},
     {NSC_UCHAR, NSC_EXTRA, 0, fldoff(shpstr, shp_nplane), "nplane", EF_BAD},
     {NSC_UCHAR, NSC_EXTRA, 0, fldoff(shpstr, shp_nland), "nland", EF_BAD},
     {NSC_XCOORD, 0, 0, fldoff(shpstr, shp_destx[0]), "xstart", EF_BAD},
@@ -234,7 +222,7 @@ struct castr ship_ca[] = {
     {NSC_UCHAR, NSC_EXTRA, 0, fldoff(shpstr, shp_nchoppers), "nchoppers",
      EF_BAD},
     {NSC_UCHAR, NSC_EXTRA, 0, fldoff(shpstr, shp_nxlight), "nxlight", EF_BAD},
-    /* could let builder access these, but we can't express that yet: */
+    /* should let builder access xbuilt, ybuilt, but can't express that: */
     {NSC_XCOORD, NSC_DEITY, 0, fldoff(shpstr, shp_orig_x), "xbuilt", EF_BAD},
     {NSC_YCOORD, NSC_DEITY, 0, fldoff(shpstr, shp_orig_y), "ybuilt", EF_BAD},
     {NSC_NATID, NSC_DEITY, 0, fldoff(shpstr, shp_orig_own), "builder",
@@ -273,7 +261,7 @@ struct castr mchr_ca[] = {
 
 struct castr plane_ca[] = {
     NSC_GENITEM(EF_PLANE, EF_PLANE_CHR),
-    {NSC_CHAR, 0, 0, fldoff(plnstr, pln_wing), "wing", EF_BAD},
+    {NSC_STRINGY, 0, 1, fldoff(plnstr, pln_wing), "wing", EF_BAD},
     {NSC_UCHAR, 0, 0, fldoff(plnstr, pln_range), "range", EF_BAD},
     {NSC_SHORT, 0, 0, fldoff(plnstr, pln_ship), "ship", EF_BAD},
     {NSC_SHORT, 0, 0, fldoff(plnstr, pln_land), "land", EF_BAD},
@@ -312,7 +300,7 @@ struct castr plchr_ca[] = {
 
 struct castr land_ca[] = {
     NSC_GENITEM(EF_LAND, EF_LAND_CHR),
-    {NSC_CHAR, 0, 0, fldoff(lndstr, lnd_army), "army", EF_BAD},
+    {NSC_STRINGY, 0, 1, fldoff(lndstr, lnd_army), "army", EF_BAD},
     {NSC_SHORT, 0, 0, fldoff(lndstr, lnd_ship), "ship", EF_BAD},
     {NSC_CHAR, 0, 0, fldoff(lndstr, lnd_harden), "harden", EF_BAD},
     {NSC_SHORT, 0, 0, fldoff(lndstr, lnd_retreat), "retreat", EF_BAD},
@@ -380,12 +368,8 @@ struct castr lchr_ca[] = {
 };
 
 struct castr nuke_ca[] = {
-    {NSC_SHORT, 0, 0, fldoff(nukstr, nuk_uid), "uid", EF_NUKE},
-    {NSC_NATID, 0, 0, fldoff(nukstr, nuk_own), "owner", EF_NATION},
-    {NSC_XCOORD, 0, 0, fldoff(nukstr, nuk_x), "xloc", EF_BAD},
-    {NSC_YCOORD, 0, 0, fldoff(nukstr, nuk_y), "yloc", EF_BAD},
-    {NSC_CHAR, 0, 0, fldoff(nukstr, nuk_n), "number", EF_BAD},
-    {NSC_SHORT, 0, N_MAXNUKE, fldoff(nukstr, nuk_types), "types", EF_BAD},
+    NSC_GENITEM(EF_NUKE, EF_NUKE_CHR),
+    {NSC_SHORT, 0, 0, fldoff(nukstr, nuk_plane), "plane", EF_BAD},
     {NSC_TIME, NSC_EXTRA, 0, fldoff(nukstr, nuk_timestamp), "timestamp",
      EF_BAD},
     {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
@@ -466,10 +450,10 @@ struct castr commodity_ca[] = {
     {NSC_FLOAT, 0, 0, fldoff(comstr, com_price), "price", EF_BAD},
     {NSC_INT, 0, 0, fldoff(comstr, com_maxbidder), "maxbidder", EF_NATION},
     {NSC_TIME, 0, 0, fldoff(comstr, com_markettime), "markettime", EF_BAD},
-    /* could let maxbidder access these, but we can't express that yet: */
+    /* should let maxbidder access xbuy, ybuy, but can't express that: */
     {NSC_XCOORD, NSC_DEITY, 0, fldoff(comstr, com_x), "xbuy", EF_BAD},
     {NSC_XCOORD, NSC_DEITY, 0, fldoff(comstr, com_y), "ybuy", EF_BAD},
-    /* could let the owner access these, but we can't express that yet: */
+    /* should let owner access xsell, ysell, but can't express that: */
     {NSC_XCOORD, NSC_DEITY, 0, fldoff(comstr, sell_x), "xsell", EF_BAD},
     {NSC_YCOORD, NSC_DEITY, 0, fldoff(comstr, sell_y), "ysell", EF_BAD},
     {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
@@ -483,30 +467,38 @@ struct castr trade_ca[] = {
     {NSC_LONG, 0, 0, fldoff(trdstr, trd_price), "price", EF_BAD},
     {NSC_INT, 0, 0, fldoff(trdstr, trd_maxbidder), "maxbidder", EF_NATION},
     {NSC_TIME, 0, 0, fldoff(trdstr, trd_markettime), "markettime", EF_BAD},
-    /* could let the maxbidder access these, but we can't express that yet: */
+    /* should let maxbidder access xloc, yloc, but can't express that: */
     {NSC_XCOORD, NSC_DEITY, 0, fldoff(trdstr, trd_x), "xloc", EF_BAD},
     {NSC_YCOORD, NSC_DEITY, 0, fldoff(trdstr, trd_y), "yloc", EF_BAD},
     {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
 };
 
-struct castr nat_ca[] = {
+struct castr cou_ca[] = {
     /*
-     * Keep selectors cnum, stat and cname at the beginning.
-     * ef_init_srv() makes their copies in cou_ca[] accessible for
-     * mortals.
+     * This is the owner's view, i.e. it applies only to the own
+     * nation.  The public view nat_ca[], which applies to all
+     * nations, has the same selectors with different flags: NSC_DEITY
+     * is set except for cnum (which must come first) and all
+     * NSC_EXTRA selectors, NSC_EXTRA is cleared.
+     * nat_ca[] should also make tech, research, education and
+     * happiness available, but we can't express the obfuscation
+     * necessary for foreign levels.
      */
     {NSC_NATID, 0, 0, fldoff(natstr, nat_cnum), "cnum", EF_NATION},
-    {NSC_SITYPE(nat_status), 0, 0, fldoff(natstr, nat_stat), "stat",
-     EF_NATION_STATUS},
-    {NSC_STRINGY, 0, 20, fldoff(natstr, nat_cnam), "cname", EF_BAD},
-    {NSC_STRINGY, NSC_DEITY, 20, fldoff(natstr, nat_pnam), "passwd", EF_BAD},
+    {NSC_SITYPE(nat_status), NSC_EXTRA, 0, fldoff(natstr, nat_stat),
+     "stat", EF_NATION_STATUS},
+    {NSC_STRINGY, NSC_EXTRA, 20, fldoff(natstr, nat_cnam), "cname", EF_BAD},
+    {NSC_STRINGY, NSC_DEITY | NSC_EXTRA, 20, fldoff(natstr, nat_pnam),
+     "passwd", EF_BAD},
     {NSC_STRINGY, 0, 32, fldoff(natstr, nat_hostaddr), "ip", EF_BAD},
     {NSC_STRINGY, 0, 512, fldoff(natstr, nat_hostname), "hostname", EF_BAD},
     {NSC_STRINGY, 0, 32, fldoff(natstr, nat_userid), "userid", EF_BAD},
     {NSC_XCOORD, 0, 0, fldoff(natstr, nat_xcap), "xcap", EF_BAD},
     {NSC_YCOORD, 0, 0, fldoff(natstr, nat_ycap), "ycap", EF_BAD},
-    {NSC_XCOORD, NSC_DEITY, 0, fldoff(natstr, nat_xorg), "xorg", EF_BAD},
-    {NSC_YCOORD, NSC_DEITY, 0, fldoff(natstr, nat_yorg), "yorg", EF_BAD},
+    {NSC_XCOORD, NSC_DEITY | NSC_EXTRA, 0, fldoff(natstr, nat_xorg),
+     "xorg", EF_BAD},
+    {NSC_YCOORD, NSC_DEITY | NSC_EXTRA, 0, fldoff(natstr, nat_yorg),
+     "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},
@@ -526,17 +518,20 @@ struct castr nat_ca[] = {
      EF_BAD},
     {NSC_FLOAT, 0, 0, fldoff(natstr, nat_level[NAT_HLEV]), "happiness",
      EF_BAD},
-    {NSC_SHORT, 0, MAXNOC, fldoff(natstr, nat_relate), "relations",
+    {NSC_HIDDEN, NSC_EXTRA, MAXNOC, fldoff(natstr, nat_relate), "relations",
      EF_NATION_RELATIONS},
-    {NSC_UCHAR, NSC_DEITY, MAXNOC, fldoff(natstr, nat_contact), "contacts",
-     EF_BAD},
-    /* FIXME nat_rejects[], nat_priorities[] */
+    /* mortals know there's contact (relations show), but not how strong */
+    {NSC_UCHAR, NSC_DEITY | NSC_EXTRA, MAXNOC, fldoff(natstr, nat_contact),
+     "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 cou_ca[sizeof(nat_ca) / sizeof(*nat_ca)];
+struct castr nat_ca[sizeof(cou_ca) / sizeof(*cou_ca)];
 /* initialized in ef_init_srv() */
 
 struct castr realm_ca[] = {
@@ -558,6 +553,8 @@ struct castr intrchr_ca[] = {
     {NSC_UCHAR, 0, 0, offsetof(struct sctintrins, in_hcms), "hcms", EF_BAD},
     {NSC_UCHAR, 0, 0, offsetof(struct sctintrins, in_dcost), "dcost", EF_BAD},
     {NSC_UCHAR, 0, 0, offsetof(struct sctintrins, in_mcost), "mcost", EF_BAD},
+    {NSC_UCHAR, 0, 0, offsetof(struct sctintrins, in_enable), "enable",
+     EF_BAD},
     {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
 };