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 <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2020-12-26 06:30:24 +01:00
parent 6bad464348
commit e7583a519e
14 changed files with 31 additions and 30 deletions

View file

@ -27,7 +27,7 @@
* item.h: Definitions for item characteristics stuff * item.h: Definitions for item characteristics stuff
* *
* Known contributors to this file: * 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 */

View file

@ -30,7 +30,7 @@
* Thomas Ruschak, 1992 * Thomas Ruschak, 1992
* Ken Stevens, 1995 * Ken Stevens, 1995
* Steve McClure, 1998 * 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 "retreat.h"
#include "types.h" #include "types.h"
#define LND_TYPE_MAX 30
#define LAND_MINEFF 10 #define LAND_MINEFF 10
#define LAND_MINFIREEFF 40 /* arty must be this effic to fire */ #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 putland(n, p) ef_write(EF_LAND, (n), (p))
#define getlandp(n) ((struct lndstr *)ef_ptr(EF_LAND, (n))) #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 { enum {
LND_AIROPS_EFF = 50 /* min. efficiency for air ops */ LND_AIROPS_EFF = 50 /* min. efficiency for air ops */

View file

@ -28,7 +28,7 @@
* *
* Known contributors to this file: * Known contributors to this file:
* Dave Pare, 1986 * 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 "item.h"
#include "types.h" #include "types.h"
#define N_MAXNUKE 20
#define MIN_DRNUKE_CONST 0.001 #define MIN_DRNUKE_CONST 0.001
struct nukstr { struct nukstr {
@ -83,7 +82,8 @@ struct nchrstr {
#define putnuke(n, p) ef_write(EF_NUKE, (n), (p)) #define putnuke(n, p) ef_write(EF_NUKE, (n), (p))
#define getnukep(n) ((struct nukstr *)ef_ptr(EF_NUKE, (n))) #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 */ /* src/lib/common/cargo.c */
extern void nuk_carrier_change(struct nukstr *, int, int, int); extern void nuk_carrier_change(struct nukstr *, int, int, int);

View file

@ -30,7 +30,7 @@
* Dave Pare, 1986 * Dave Pare, 1986
* Ken Stevens, 1995 * Ken Stevens, 1995
* Steve McClure, 1998 * 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 "queue.h"
#include "types.h" #include "types.h"
#define PLN_TYPE_MAX 46
#define PLANE_MINEFF 10 #define PLANE_MINEFF 10
struct plnstr { struct plnstr {
@ -135,7 +134,8 @@ struct plist {
#define putplane(n, p) ef_write(EF_PLANE, (n), (p)) #define putplane(n, p) ef_write(EF_PLANE, (n), (p))
#define getplanep(n) ((struct plnstr *)ef_ptr(EF_PLANE, (n))) #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 { struct shiplist {
int uid; int uid;

View 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 #define PCHR_SZ 24
extern struct pchrstr pchr[PCHR_SZ];
extern struct pchrstr pchr[P_MAX + 2];
#endif #endif

View file

@ -30,7 +30,7 @@
* Dave Pare * Dave Pare
* Ken Stevens, 1995 * Ken Stevens, 1995
* Steve McClure, 1998 * 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_PLAINS 32 /* plains sector */
#define SCT_BTOWER 33 /* Bridge tower */ #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 getsect(x, y, p) ef_read(EF_SECTOR, sctoff((x), (y)), (p))
#define putsect(p) ef_write(EF_SECTOR, (p)->sct_uid, (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 getsectp(x, y) ((struct sctstr *)ef_ptr(EF_SECTOR, sctoff((x), (y))))
#define getsectid(id) ((struct sctstr *)ef_ptr(EF_SECTOR, (id))) #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) #define IS_BIG_CITY(type) (dchr[(type)].d_pkg == UPKG)
/* Minimal efficiency of sectors that can be knocked down (bridges) */ /* 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 fort_fire(struct sctstr *);
extern int sct_rail_track(struct sctstr *); extern int sct_rail_track(struct sctstr *);

View file

@ -31,7 +31,7 @@
* Thomas Ruschak, 1992 * Thomas Ruschak, 1992
* Ken Stevens, 1995 * Ken Stevens, 1995
* Steve McClure, 1998 * 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 "retreat.h"
#include "types.h" #include "types.h"
#define SHP_TYPE_MAX 46
#define SHIP_MINEFF 20 #define SHIP_MINEFF 20
#define MAXSHPNAMLEN 24 #define MAXSHPNAMLEN 24
@ -127,7 +126,8 @@ struct mchrstr {
#define putship(n, p) ef_write(EF_SHIP, (n), (p)) #define putship(n, p) ef_write(EF_SHIP, (n), (p))
#define getshipp(n) ((struct shpstr *)ef_ptr(EF_SHIP, (n))) #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 { enum {
SHP_AIROPS_EFF = 50, /* min. efficiency for air ops */ SHP_AIROPS_EFF = 50, /* min. efficiency for air ops */

View file

@ -38,4 +38,4 @@
* Table of item types * Table of item types
* Initialized on startup from item.config and deity custom config (if any). * Initialized on startup from item.config and deity custom config (if any).
*/ */
struct ichrstr ichr[I_MAX + 2]; struct ichrstr ichr[ICHR_SZ];

View file

@ -43,7 +43,7 @@
* Initialized on startup from land.config and deity custom config (if any). * Initialized on startup from land.config and deity custom config (if any).
* Terminated by a sentinel with null l_name. * 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 logx(a, b) (log((a)) / log((b)))
#define LND_ATTDEF(b, t) (((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0))) \ #define LND_ATTDEF(b, t) (((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0))) \

View file

@ -38,4 +38,4 @@
* Table of nuke types * Table of nuke types
* Initialized on startup from nuke.config and deity custom config (if any). * Initialized on startup from nuke.config and deity custom config (if any).
*/ */
struct nchrstr nchr[N_MAXNUKE + 1]; struct nchrstr nchr[NCHR_SZ];

View file

@ -45,7 +45,7 @@
* Initialized on startup from plane.config and deity custom config (if any). * Initialized on startup from plane.config and deity custom config (if any).
* Terminated by a sentinel with null pl_name. * 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 logx(a, b) (log((a)) / log((b)))
#define PLN_ATTDEF(b, t) (b + ((b?1:0) * ((t/20)>10?10:(t/20)))) #define PLN_ATTDEF(b, t) (b + ((b?1:0) * ((t/20)>10?10:(t/20))))

View file

@ -38,4 +38,4 @@
* Table of product types * Table of product types
* Initialized on startup from product.config and deity custom config (if any). * Initialized on startup from product.config and deity custom config (if any).
*/ */
struct pchrstr pchr[P_MAX + 2]; struct pchrstr pchr[PCHR_SZ];

View file

@ -43,10 +43,10 @@
* Initialized on startup from sect.config and deity custom config (if any). * Initialized on startup from sect.config and deity custom config (if any).
* Terminated by a sentinel with null d_name. * Terminated by a sentinel with null d_name.
*/ */
struct dchrstr dchr[SCT_TYPE_MAX + 2]; struct dchrstr dchr[DCHR_SZ];
/* /*
* Table of infrastructure types * Table of infrastructure types
* Initialized on startup from infra.config and deity custom config (if any). * Initialized on startup from infra.config and deity custom config (if any).
*/ */
struct sctintrins intrchr[INT_DEF + 2]; struct sctintrins intrchr[INTRCHR_SZ];

View file

@ -45,7 +45,7 @@
* Initialized on startup from ship.config and deity custom config (if any). * Initialized on startup from ship.config and deity custom config (if any).
* Terminated by a sentinel with null m_name. * 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 logx(a, b) (log((a)) / log((b)))
#define SHP_DEF(b, t) (t ? (b * (logx(t, 40.0) < 1.0 ? 1.0 : \ #define SHP_DEF(b, t) (t ? (b * (logx(t, 40.0) < 1.0 ? 1.0 : \