]> git.pond.sub.org Git - empserver/commitdiff
config: Slightly neater configuration table size macros
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 26 Dec 2020 05:30:24 +0000 (06:30 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 23 Jan 2021 06:07:58 +0000 (07:07 +0100)
Macro SHP_TYPE_MAX is the largest possible ship type number.  It is
only used to size mchr[], and we need + 2 there.  Replace by MCHR_SZ
for simplicity.

Same for LND_TYPE_MAX, PLN_TYPE_MAX, P_MAX, and SCT_TYPE_MAX: replace
by LCHR_SZ, PLCHR_SZ, PCHR_SZ, and DCHR_SZ.

Same for N_MAXNUKE, except that one is more than the largest type
number.  Replace by NCHR_SZ.

For consistency, define ICHR_SZ and INTRCHR_SZ for sizing ichr[] and
intrchr_sz[].

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
14 files changed:
include/item.h
include/land.h
include/nuke.h
include/plane.h
include/product.h
include/sect.h
include/ship.h
src/lib/global/item.c
src/lib/global/land.c
src/lib/global/nuke.c
src/lib/global/plane.c
src/lib/global/product.c
src/lib/global/sect.c
src/lib/global/ship.c

index cc1fe96c742a916f44cf70ee342eb9a6cd1cd9e3..4c5bfa345042983a8e972c9f6ff818037ccb0d3e 100644 (file)
@@ -27,7 +27,7 @@
  *  item.h: Definitions for item characteristics stuff
  *
  *  Known contributors to this file:
  *  item.h: Definitions for item characteristics stuff
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2004-2016
+ *     Markus Armbruster, 2004-2020
  */
 
 #ifndef ITEM_H
  */
 
 #ifndef ITEM_H
@@ -80,7 +80,8 @@ struct ichrstr {
 
 /* variables using this structure */
 
 
 /* variables using this structure */
 
-extern struct ichrstr ichr[I_MAX + 2];
+#define ICHR_SZ (I_MAX + 2)
+extern struct ichrstr ichr[ICHR_SZ];
 
 /* procedures using/returning this struct */
 
 
 /* procedures using/returning this struct */
 
index 04774240885d52aacc4e495a934f9c188f385c3d..cb1bc44a76340faed8d184e88b6de4ff42adb5da 100644 (file)
@@ -30,7 +30,7 @@
  *     Thomas Ruschak, 1992
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
  *     Thomas Ruschak, 1992
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
- *     Markus Armbruster, 2004-2016
+ *     Markus Armbruster, 2004-2020
  */
 
 #ifndef LAND_H
  */
 
 #ifndef LAND_H
@@ -41,7 +41,6 @@
 #include "retreat.h"
 #include "types.h"
 
 #include "retreat.h"
 #include "types.h"
 
-#define LND_TYPE_MAX   30
 #define LAND_MINEFF    10
 #define LAND_MINFIREEFF 40     /* arty must be this effic to fire */
 
 #define LAND_MINEFF    10
 #define LAND_MINFIREEFF 40     /* arty must be this effic to fire */
 
@@ -125,7 +124,8 @@ struct lchrstr {
 #define putland(n, p) ef_write(EF_LAND, (n), (p))
 #define getlandp(n) ((struct lndstr *)ef_ptr(EF_LAND, (n)))
 
 #define putland(n, p) ef_write(EF_LAND, (n), (p))
 #define getlandp(n) ((struct lndstr *)ef_ptr(EF_LAND, (n)))
 
-extern struct lchrstr lchr[LND_TYPE_MAX + 2];
+#define LCHR_SZ 32
+extern struct lchrstr lchr[LCHR_SZ];
 
 enum {
     LND_AIROPS_EFF = 50                /* min. efficiency for air ops */
 
 enum {
     LND_AIROPS_EFF = 50                /* min. efficiency for air ops */
index d338d385c8f209a7d1f98f69f30022a9b2a63292..87bf875a253981fa0f214797d7ae0d8fdf512210 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *
  *  Known contributors to this file:
  *     Dave Pare, 1986
- *     Markus Armbruster, 2004-2016
+ *     Markus Armbruster, 2004-2020
  */
 
 #ifndef NUKE_H
  */
 
 #ifndef NUKE_H
@@ -38,7 +38,6 @@
 #include "item.h"
 #include "types.h"
 
 #include "item.h"
 #include "types.h"
 
-#define N_MAXNUKE      20
 #define MIN_DRNUKE_CONST       0.001
 
 struct nukstr {
 #define MIN_DRNUKE_CONST       0.001
 
 struct nukstr {
@@ -83,7 +82,8 @@ struct nchrstr {
 #define putnuke(n, p) ef_write(EF_NUKE, (n), (p))
 #define getnukep(n) ((struct nukstr *)ef_ptr(EF_NUKE, (n)))
 
 #define putnuke(n, p) ef_write(EF_NUKE, (n), (p))
 #define getnukep(n) ((struct nukstr *)ef_ptr(EF_NUKE, (n)))
 
-extern struct nchrstr nchr[N_MAXNUKE + 1];
+#define NCHR_SZ 21
+extern struct nchrstr nchr[NCHR_SZ];
 
 /* src/lib/common/cargo.c */
 extern void nuk_carrier_change(struct nukstr *, int, int, int);
 
 /* src/lib/common/cargo.c */
 extern void nuk_carrier_change(struct nukstr *, int, int, int);
index bef45c2f510b524a550f6184f47cecff5878ca20..019fb95b3ebe145048c343bf913cb8c96932ce68 100644 (file)
@@ -30,7 +30,7 @@
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
- *     Markus Armbruster, 2004-2016
+ *     Markus Armbruster, 2004-2020
  */
 
 #ifndef PLANE_H
  */
 
 #ifndef PLANE_H
@@ -41,7 +41,6 @@
 #include "queue.h"
 #include "types.h"
 
 #include "queue.h"
 #include "types.h"
 
-#define PLN_TYPE_MAX   46
 #define PLANE_MINEFF   10
 
 struct plnstr {
 #define PLANE_MINEFF   10
 
 struct plnstr {
@@ -135,7 +134,8 @@ struct plist {
 #define putplane(n, p) ef_write(EF_PLANE, (n), (p))
 #define getplanep(n) ((struct plnstr *)ef_ptr(EF_PLANE, (n)))
 
 #define putplane(n, p) ef_write(EF_PLANE, (n), (p))
 #define getplanep(n) ((struct plnstr *)ef_ptr(EF_PLANE, (n)))
 
-extern struct plchrstr plchr[PLN_TYPE_MAX + 2];
+#define PLCHR_SZ 48
+extern struct plchrstr plchr[PLCHR_SZ];
 
 struct shiplist {
     int uid;
 
 struct shiplist {
     int uid;
index 77e6c13bb1c950af21ff767c01173c322df0a5f4..42dec68868e6b6cb007864a77c334cdf2393a086 100644 (file)
@@ -57,8 +57,7 @@ struct pchrstr {
     char *p_sname;             /* short (7 char or less) name of product */
 };
 
     char *p_sname;             /* short (7 char or less) name of product */
 };
 
-#define P_MAX 22
-
-extern struct pchrstr pchr[P_MAX + 2];
+#define PCHR_SZ 24
+extern struct pchrstr pchr[PCHR_SZ];
 
 #endif
 
 #endif
index aa60b58c037540984440ff9479bf60a719f4f6e7..f7549a4ec02b2885d322e04ce91fa3509b3797d6 100644 (file)
@@ -30,7 +30,7 @@
  *     Dave Pare
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
  *     Dave Pare
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
- *     Markus Armbruster, 2004-2016
+ *     Markus Armbruster, 2004-2020
  */
 
 
  */
 
 
@@ -160,14 +160,14 @@ struct dchrstr {
 #define SCT_PLAINS     32      /* plains sector */
 #define SCT_BTOWER     33      /* Bridge tower */
 
 #define SCT_PLAINS     32      /* plains sector */
 #define SCT_BTOWER     33      /* Bridge tower */
 
-#define SCT_TYPE_MAX   38
-
 #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)))
 
 #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)))
 
-extern struct dchrstr dchr[SCT_TYPE_MAX + 2];
+#define DCHR_SZ 40
+extern struct dchrstr dchr[DCHR_SZ];
+
 #define IS_BIG_CITY(type) (dchr[(type)].d_pkg == UPKG)
 
 /* Minimal efficiency of sectors that can be knocked down (bridges) */
 #define IS_BIG_CITY(type) (dchr[(type)].d_pkg == UPKG)
 
 /* Minimal efficiency of sectors that can be knocked down (bridges) */
@@ -223,7 +223,8 @@ struct sctintrins {
     unsigned char in_enable;   /* enabled iff non-zero */
 };
 
     unsigned char in_enable;   /* enabled iff non-zero */
 };
 
-extern struct sctintrins intrchr[INT_DEF + 2];
+#define INTRCHR_SZ INT_DEF + 2
+extern struct sctintrins intrchr[INTRCHR_SZ];
 
 extern int fort_fire(struct sctstr *);
 extern int sct_rail_track(struct sctstr *);
 
 extern int fort_fire(struct sctstr *);
 extern int sct_rail_track(struct sctstr *);
index bb0e67f9d6405bc36f23bd36340de5f28079b9f9..d7bbb26d497cadae29276bfe672557400d6ca381 100644 (file)
@@ -31,7 +31,7 @@
  *     Thomas Ruschak, 1992
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
  *     Thomas Ruschak, 1992
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
- *     Markus Armbruster, 2004-2016
+ *     Markus Armbruster, 2004-2020
  */
 
 #ifndef SHIP_H
  */
 
 #ifndef SHIP_H
@@ -42,7 +42,6 @@
 #include "retreat.h"
 #include "types.h"
 
 #include "retreat.h"
 #include "types.h"
 
-#define SHP_TYPE_MAX   46
 #define SHIP_MINEFF    20
 
 #define MAXSHPNAMLEN   24
 #define SHIP_MINEFF    20
 
 #define MAXSHPNAMLEN   24
@@ -127,7 +126,8 @@ struct mchrstr {
 #define putship(n, p) ef_write(EF_SHIP, (n), (p))
 #define getshipp(n) ((struct shpstr *)ef_ptr(EF_SHIP, (n)))
 
 #define putship(n, p) ef_write(EF_SHIP, (n), (p))
 #define getshipp(n) ((struct shpstr *)ef_ptr(EF_SHIP, (n)))
 
-extern struct mchrstr mchr[SHP_TYPE_MAX + 2];
+#define MCHR_SZ 48
+extern struct mchrstr mchr[MCHR_SZ];
 
 enum {
     SHP_AIROPS_EFF = 50,       /* min. efficiency for air ops */
 
 enum {
     SHP_AIROPS_EFF = 50,       /* min. efficiency for air ops */
index eb271e127e96700f13ecec20d7135374d089fa9d..aea663e3aa66239f9efb83653aafb694b54eeb77 100644 (file)
@@ -38,4 +38,4 @@
  * Table of item types
  * Initialized on startup from item.config and deity custom config (if any).
  */
  * Table of item types
  * Initialized on startup from item.config and deity custom config (if any).
  */
-struct ichrstr ichr[I_MAX + 2];
+struct ichrstr ichr[ICHR_SZ];
index dbefcf9c52bd81a3111134665035aead20ad6ce6..1845f573086c40f615ebaeb6857708802da5f273 100644 (file)
@@ -43,7 +43,7 @@
  * Initialized on startup from land.config and deity custom config (if any).
  * Terminated by a sentinel with null l_name.
  */
  * Initialized on startup from land.config and deity custom config (if any).
  * Terminated by a sentinel with null l_name.
  */
-struct lchrstr lchr[LND_TYPE_MAX + 2];
+struct lchrstr lchr[LCHR_SZ];
 
 #define logx(a, b) (log((a)) / log((b)))
 #define LND_ATTDEF(b, t) (((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0)))  \
 
 #define logx(a, b) (log((a)) / log((b)))
 #define LND_ATTDEF(b, t) (((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0)))  \
index 4365c5cbc91610b64411a10ad2ab18cb1e5a025c..921fdea18a843160d4c6175b7e4ff29dec21ca1b 100644 (file)
@@ -38,4 +38,4 @@
  * Table of nuke types
  * Initialized on startup from nuke.config and deity custom config (if any).
  */
  * Table of nuke types
  * Initialized on startup from nuke.config and deity custom config (if any).
  */
-struct nchrstr nchr[N_MAXNUKE + 1];
+struct nchrstr nchr[NCHR_SZ];
index 51575e2840409173bc9ae6fa6050029e349b7daf..9ad17e2ec10e36b44a40a8463bb3a8dcff83ab46 100644 (file)
@@ -45,7 +45,7 @@
  * Initialized on startup from plane.config and deity custom config (if any).
  * Terminated by a sentinel with null pl_name.
  */
  * Initialized on startup from plane.config and deity custom config (if any).
  * Terminated by a sentinel with null pl_name.
  */
-struct plchrstr plchr[PLN_TYPE_MAX + 2];
+struct plchrstr plchr[PLCHR_SZ];
 
 #define logx(a, b) (log((a)) / log((b)))
 #define PLN_ATTDEF(b, t) (b + ((b?1:0) * ((t/20)>10?10:(t/20))))
 
 #define logx(a, b) (log((a)) / log((b)))
 #define PLN_ATTDEF(b, t) (b + ((b?1:0) * ((t/20)>10?10:(t/20))))
index cd6d8b034c183efb04ccb213508019e4fe7165a8..213896554990f6263bcbb8a1703ec01303f66a09 100644 (file)
@@ -38,4 +38,4 @@
  * Table of product types
  * Initialized on startup from product.config and deity custom config (if any).
  */
  * Table of product types
  * Initialized on startup from product.config and deity custom config (if any).
  */
-struct pchrstr pchr[P_MAX + 2];
+struct pchrstr pchr[PCHR_SZ];
index e19598431ee8b31f496543c0e2d35e592bde3a1c..de316b4df0362521c6df309ce33e1ceffabf0bfc 100644 (file)
  * Initialized on startup from sect.config and deity custom config (if any).
  * Terminated by a sentinel with null d_name.
  */
  * Initialized on startup from sect.config and deity custom config (if any).
  * Terminated by a sentinel with null d_name.
  */
-struct dchrstr dchr[SCT_TYPE_MAX + 2];
+struct dchrstr dchr[DCHR_SZ];
 
 /*
  * Table of infrastructure types
  * Initialized on startup from infra.config and deity custom config (if any).
  */
 
 /*
  * Table of infrastructure types
  * Initialized on startup from infra.config and deity custom config (if any).
  */
-struct sctintrins intrchr[INT_DEF + 2];
+struct sctintrins intrchr[INTRCHR_SZ];
index 110ecdb62580755e794b839649febb398cafa8ab..f9adac2b888eb9f50fca59716d68ea6bb06b7a9b 100644 (file)
@@ -45,7 +45,7 @@
  * Initialized on startup from ship.config and deity custom config (if any).
  * Terminated by a sentinel with null m_name.
  */
  * Initialized on startup from ship.config and deity custom config (if any).
  * Terminated by a sentinel with null m_name.
  */
-struct mchrstr mchr[SHP_TYPE_MAX + 2];
+struct mchrstr mchr[MCHR_SZ];
 
 #define logx(a, b) (log((a)) / log((b)))
 #define SHP_DEF(b, t) (t ? (b * (logx(t, 40.0) < 1.0 ? 1.0 : \
 
 #define logx(a, b) (log((a)) / log((b)))
 #define SHP_DEF(b, t) (t ? (b * (logx(t, 40.0) < 1.0 ? 1.0 : \