]> git.pond.sub.org Git - empserver/blobdiff - include/sect.h
Update copyright notice
[empserver] / include / sect.h
index dd2224e0e14478ba9a623c110fa1fec1718a5c8f..336b71f11930e9521c275f06ebfb6ccc45455782 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-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
  *  sect.h: Definitions for things having to do with sectors.
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
+ *     Markus Armbruster, 2004-2008
  */
 
 
-#ifndef _SECT_H_
-#define _SECT_H_
-
-#include "var.h"
+#ifndef SECT_H
+#define SECT_H
 
-/* The order of the following elements is there to match up with genitem */
+#include <time.h>
+#include "item.h"
+#include "types.h"
 
 struct sctstr {
+    /* initial part must match struct empobj */
     short ef_type;
+    short sct_uid;             /* equals XYOFFSET(sct_x, sct_y) */
+    unsigned sct_seqno;
+    time_t sct_timestamp;      /* Last time this sector was written to */
     natid sct_own;             /* owner's country num */
-    short sct_elev;            /* elevation/depth */
     coord sct_x;               /* x coord of sector */
     coord sct_y;               /* y coord of sector */
-    u_char sct_type;           /* sector type */
-    u_char sct_effic;          /* 0% to 100% */
+    signed char sct_type;      /* sector type */
+    /* end of part matching struct empobj */
+    unsigned char sct_effic;   /* 0% to 100% */
     short sct_mobil;           /* mobility units */
-    u_char sct_loyal;          /* updates until civilans "converted" */
-    u_char sct_terr;           /* territory 0 id # of sector */
-    u_char sct_terr1;          /* territory 1 id # of sector */
-    u_char sct_terr2;          /* territory 2 id # of sector */
-    u_char sct_terr3;          /* territory 3 id # of sector */
+    unsigned char sct_loyal;   /* updates until civilans "converted" */
+    unsigned char sct_terr;    /* territory 0 id # of sector */
+    unsigned char sct_terr1;   /* territory 1 id # of sector */
+    unsigned char sct_terr2;   /* territory 2 id # of sector */
+    unsigned char sct_terr3;   /* territory 3 id # of sector */
+    unsigned char sct_dterr;   /* deity's territory # */
     coord sct_dist_x;          /* Dist sector */
     coord sct_dist_y;
     short sct_avail;           /* available workforce for "other things" */
     short sct_flags;           /* temporary flags */
-    short sct_fill;            /* gunk */
-    u_char sct_work;           /* pct of civ actually working */
-    u_char sct_coastal;                /* is this a coastal sector? */
-    u_char sct_newtype;                /* for changing designations */
-    u_char sct_min;            /* ease of mining ore */
-    u_char sct_gmin;           /* amount of gold ore */
-    u_char sct_fertil;         /* fertility of soil */
-    u_char sct_oil;            /* oil content */
-    u_char sct_uran;           /* uranium ore content */
+    short sct_elev;            /* elevation/depth */
+    unsigned char sct_work;    /* pct of civ actually working */
+    unsigned char sct_coastal; /* is this a coastal sector? */
+    signed char sct_newtype;   /* for changing designations */
+    unsigned char sct_min;     /* ease of mining ore */
+    unsigned char sct_gmin;    /* amount of gold ore */
+    unsigned char sct_fertil;  /* fertility of soil */
+    unsigned char sct_oil;     /* oil content */
+    unsigned char sct_uran;    /* uranium ore content */
     natid sct_oldown;          /* old owner of sector (for liberation) */
-    u_char sct_updated;                /* Has this sect been updated? */
-    u_char sct_off;            /* Should this sector produce? */
-    u_short sct_item[I_MAX+1]; /* amount of items stored here */
-    u_short sct_del[I_MAX+1];  /* delivieries */
-    u_short sct_dist[I_MAX+1]; /* distribution thresholds */
-    u_short sct_mines;         /* number of mines */
-    u_short sct_pstage;                /* plague stage */
-    u_short sct_ptime;         /* how many etus remain in this stage */
-    u_char sct_che;            /* number of guerrillas */
+    unsigned char sct_updated; /* Has this sect been updated? */
+    unsigned char sct_off;     /* Should this sector produce? */
+    short sct_item[I_MAX+1];   /* amount of items stored here */
+    short sct_del[I_MAX+1];    /* delivieries */
+    short sct_dist[I_MAX+1];   /* distribution thresholds */
+    short sct_mines;           /* number of mines */
+    short sct_pstage;          /* plague stage */
+    short sct_ptime;           /* how many etus remain in this stage */
+    unsigned char sct_che;     /* number of guerrillas */
     natid sct_che_target;      /* nation targeted by che */
-    u_short sct_fallout;
-    time_t sct_access;         /* Last time mob was updated (MOB_ACCESS) */
-    u_char sct_road;           /* Road value of a sector */
-    u_char sct_rail;           /* Rail value of a sector */
-    u_char sct_defense;                /* Defensive value of a sector */
-    time_t sct_timestamp;      /* Last time this sector was written to */
+    unsigned short sct_fallout;
+    short sct_access;          /* Last tick mob was updated (MOB_ACCESS) */
+    unsigned char sct_road;    /* Road value of a sector */
+    unsigned char sct_rail;    /* Rail value of a sector */
+    unsigned char sct_defense; /* Defensive value of a sector */
+};
+
+enum d_navigation {
+    NAV_NONE,  /* ships can't navigate */
+    NAVOK,     /* ships can always navigate */
+    NAV_02,    /* requires 2% effic to navigate */
+    NAV_CANAL, /* requires 2% effic to navigate and M_CANAL capability */
+    NAV_60     /* requires 60% effic to navigate */
 };
 
 struct dchrstr {
-    int d_mnem;                        /* map symbol */
-    int d_prd;                 /* product vtype */
-    int d_mcst;                        /* movement cost */
-    int d_flg;                 /* movement cost */
-    int d_pkg;                 /* type of packaging in these sects */
+    unsigned char d_uid;
+    char d_mnem;               /* map symbol */
+    unsigned char d_terrain;   /* terrain sector type */
+    int d_prd;                 /* product type */
+    int d_peffic;              /* process efficiency, in percent */
+    float d_mob0, d_mob1;      /* movement cost at 0 and 100% eff */
+    enum d_navigation d_nav;   /* navigation capability */
+    enum i_packing d_pkg;      /* type of packaging in these sects */
     float d_ostr;              /* offensive strength */
     float d_dstr;              /* defensive strength */
     int d_value;               /* resale ("collect") value */
@@ -100,19 +116,10 @@ struct dchrstr {
     int d_build;               /* cost multiplier for eff */
     int d_lcms;                        /* lcm's needed per point of eff */
     int d_hcms;                        /* hcm's needed per point of eff */
-    s_char *d_name;            /* full name of sector type */
+    int d_maxpop;              /* maximum population */
+    char *d_name;              /* full name of sector type */
 };
 
-#define        NPKG    0               /* no special packaging */
-#define        WPKG    1               /* "warehouse" packaging */
-#define        UPKG    2               /* "urban" packaging */
-#define        BPKG    3               /* "bank" packaging */
-
-/* for d_flg */
-#define        NAVOK   1               /* ships can always navigate */
-#define        NAV_02  2               /* requires 2% effic to navigate */
-#define        NAV_60  3               /* requires 60% effic to navigate */
-
        /* sector types (must agree with order in dchr, empglb.c) */
 
 #define        SCT_WATER       0       /* basics */
@@ -150,31 +157,39 @@ struct dchrstr {
 #define SCT_PLAINS      32     /* plains sector */
 #define SCT_BTOWER      33     /* Bridge tower */
 
-#define SCT_EFFIC       34     /* used in update & budget */
-#define        SCT_MAXDEF      34      /* highest sector type in header files */
+#define SCT_TYPE_MAX    38
 
-#define getsect(x, y, p) \
-       ef_read(EF_SECTOR, sctoff((int) x, (int) y), (caddr_t)p)
-#define putsect(p) \
-       ef_write(EF_SECTOR, sctoff((int) (p)->sct_x, \
-               (int) (p)->sct_y), (caddr_t)p)
-#define getsectp(x, y) \
-       (struct sctstr *) ef_ptr(EF_SECTOR, sctoff((int)x, (int)y))
-#define getsectid(id) \
-       (struct sctstr *) ef_ptr(EF_SECTOR, id)
+#define getsect(x, y, p) ef_read(EF_SECTOR, sctoff((x), (y)), (p))
+#define putsect(p) ef_write(EF_SECTOR, (p)->sct_uid, (p))
+#define getsectp(x, y) (struct sctstr *)ef_ptr(EF_SECTOR, sctoff((x), (y)))
+#define getsectid(id) (struct sctstr *)ef_ptr(EF_SECTOR, (id))
 
 /* things relating to sectors */
 extern int sctoff(coord x, coord y);
 
-extern int sct_maxno;
-extern struct dchrstr dchr[];
+extern struct dchrstr dchr[SCT_TYPE_MAX + 2];
 extern struct dchrstr bigcity_dchr;
+#define IS_BIG_CITY(type) (dchr[(type)].d_pkg == UPKG)
+
+/* Minimal efficiency of sectors that can be knocked down (bridges) */
+#define SCT_MINEFF 20
+
+/* Work required for building */
+#define SCT_BLD_WORK(lcm, hcm) ((lcm) + 2 * (hcm))
+
+/* Return SP's defense efficiency */
+#define SCT_DEFENSE(sp) \
+    (intrchr[INT_DEF].in_enable ? (sp)->sct_defense : (sp)->sct_effic)
 
-#define MIN_MOBCOST  0.001     /* lowest cost a sector can have to move into */
 #define FORTEFF 5              /* forts must be 5% efficient to fire. */
 
-#define MOB_NONE    0
-#define MOB_ROAD    1
+/* Can trains enter sector SP? */
+#define SCT_HAS_RAIL(sp)                                       \
+    (opt_RAILWAYS ? sct_rail_track((sp)) != 0                  \
+     : intrchr[INT_RAIL].in_enable && (sp)->sct_rail != 0)
+
+#define MOB_MOVE    0
+#define MOB_MARCH   1
 #define MOB_RAIL    2
 
 #define INT_ROAD    0
@@ -184,18 +199,30 @@ extern struct dchrstr bigcity_dchr;
 /* Sector flags */
 #define MOVE_IN_PROGRESS       bit(0)  /* move in progress */
 
-/* maximal number of che, must fit into struct sctstr member sct_che */
-#define CHE_MAX                 255
+/* maximum item amount, must fit into sct_item[], sct_del[], sct_dist[] */
+#define ITEM_MAX 9999
+/* maximum number of mines, must fit into struct sctstr member sct_mines */
+#define MINES_MAX 32767
+/* maximum number of che, must fit into struct sctstr member sct_che */
+#define CHE_MAX 255
+/* maximum fallout, must fit into struct sctstr member sct_fallout */
+#define FALLOUT_MAX 9999
+/* maximum territory, must fit into struct sctstr members sct_terr etc */
+#define TERR_MAX 99
 
 /* Each cost is per point of efficency */
 struct sctintrins {
     char *in_name;
-    u_char in_lcms;
-    u_char in_hcms;
-    u_char in_dcost;
-    u_char in_mcost;
+    unsigned char in_lcms;     /* construction materials */
+    unsigned char in_hcms;
+    unsigned char in_dcost;    /* dollars */
+    unsigned char in_mcost;    /* mobility */
+    unsigned char in_enable;   /* enabled iff non-zero */
 };
 
-extern struct sctintrins intrchr[];
+extern struct sctintrins intrchr[INT_DEF + 2];
+
+extern int fort_fire(struct sctstr *);
+extern int sct_rail_track(struct sctstr *);
 
-#endif /* _SECT_H_ */
+#endif