From: Markus Armbruster Date: Sat, 26 Dec 2020 05:30:24 +0000 (+0100) Subject: config: Slightly neater configuration table size macros X-Git-Tag: v4.4.1~80 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=e7583a519e063bbf6b29343a173fd020b3ad6dca config: Slightly neater configuration table size macros 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 --- diff --git a/include/item.h b/include/item.h index cc1fe96c7..4c5bfa345 100644 --- a/include/item.h +++ b/include/item.h @@ -27,7 +27,7 @@ * item.h: Definitions for item characteristics stuff * * Known contributors to this file: - * Markus Armbruster, 2004-2016 + * Markus Armbruster, 2004-2020 */ #ifndef ITEM_H @@ -80,7 +80,8 @@ struct ichrstr { /* 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 */ diff --git a/include/land.h b/include/land.h index 047742408..cb1bc44a7 100644 --- a/include/land.h +++ b/include/land.h @@ -30,7 +30,7 @@ * Thomas Ruschak, 1992 * Ken Stevens, 1995 * Steve McClure, 1998 - * Markus Armbruster, 2004-2016 + * Markus Armbruster, 2004-2020 */ #ifndef LAND_H @@ -41,7 +41,6 @@ #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 */ @@ -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))) -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 */ diff --git a/include/nuke.h b/include/nuke.h index d338d385c..87bf875a2 100644 --- a/include/nuke.h +++ b/include/nuke.h @@ -28,7 +28,7 @@ * * Known contributors to this file: * Dave Pare, 1986 - * Markus Armbruster, 2004-2016 + * Markus Armbruster, 2004-2020 */ #ifndef NUKE_H @@ -38,7 +38,6 @@ #include "item.h" #include "types.h" -#define N_MAXNUKE 20 #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))) -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); diff --git a/include/plane.h b/include/plane.h index bef45c2f5..019fb95b3 100644 --- a/include/plane.h +++ b/include/plane.h @@ -30,7 +30,7 @@ * Dave Pare, 1986 * Ken Stevens, 1995 * Steve McClure, 1998 - * Markus Armbruster, 2004-2016 + * Markus Armbruster, 2004-2020 */ #ifndef PLANE_H @@ -41,7 +41,6 @@ #include "queue.h" #include "types.h" -#define PLN_TYPE_MAX 46 #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))) -extern struct plchrstr plchr[PLN_TYPE_MAX + 2]; +#define PLCHR_SZ 48 +extern struct plchrstr plchr[PLCHR_SZ]; struct shiplist { int uid; diff --git a/include/product.h b/include/product.h index 77e6c13bb..42dec6886 100644 --- a/include/product.h +++ b/include/product.h @@ -57,8 +57,7 @@ struct pchrstr { 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 diff --git a/include/sect.h b/include/sect.h index aa60b58c0..f7549a4ec 100644 --- a/include/sect.h +++ b/include/sect.h @@ -30,7 +30,7 @@ * 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_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))) -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) */ @@ -223,7 +223,8 @@ struct sctintrins { 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 *); diff --git a/include/ship.h b/include/ship.h index bb0e67f9d..d7bbb26d4 100644 --- a/include/ship.h +++ b/include/ship.h @@ -31,7 +31,7 @@ * Thomas Ruschak, 1992 * Ken Stevens, 1995 * Steve McClure, 1998 - * Markus Armbruster, 2004-2016 + * Markus Armbruster, 2004-2020 */ #ifndef SHIP_H @@ -42,7 +42,6 @@ #include "retreat.h" #include "types.h" -#define SHP_TYPE_MAX 46 #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))) -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 */ diff --git a/src/lib/global/item.c b/src/lib/global/item.c index eb271e127..aea663e3a 100644 --- a/src/lib/global/item.c +++ b/src/lib/global/item.c @@ -38,4 +38,4 @@ * 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]; diff --git a/src/lib/global/land.c b/src/lib/global/land.c index dbefcf9c5..1845f5730 100644 --- a/src/lib/global/land.c +++ b/src/lib/global/land.c @@ -43,7 +43,7 @@ * 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))) \ diff --git a/src/lib/global/nuke.c b/src/lib/global/nuke.c index 4365c5cbc..921fdea18 100644 --- a/src/lib/global/nuke.c +++ b/src/lib/global/nuke.c @@ -38,4 +38,4 @@ * 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]; diff --git a/src/lib/global/plane.c b/src/lib/global/plane.c index 51575e284..9ad17e2ec 100644 --- a/src/lib/global/plane.c +++ b/src/lib/global/plane.c @@ -45,7 +45,7 @@ * 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)))) diff --git a/src/lib/global/product.c b/src/lib/global/product.c index cd6d8b034..213896554 100644 --- a/src/lib/global/product.c +++ b/src/lib/global/product.c @@ -38,4 +38,4 @@ * 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]; diff --git a/src/lib/global/sect.c b/src/lib/global/sect.c index e19598431..de316b4df 100644 --- a/src/lib/global/sect.c +++ b/src/lib/global/sect.c @@ -43,10 +43,10 @@ * 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). */ -struct sctintrins intrchr[INT_DEF + 2]; +struct sctintrins intrchr[INTRCHR_SZ]; diff --git a/src/lib/global/ship.c b/src/lib/global/ship.c index 110ecdb62..f9adac2b8 100644 --- a/src/lib/global/ship.c +++ b/src/lib/global/ship.c @@ -45,7 +45,7 @@ * 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 : \