Avoid SCT_TYPE_MAX, use ARRAY_SIZE() instead

The next commit will get rid of SCT_TYPE_MAX.  Prepare.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2020-12-26 06:27:18 +01:00
parent d1b844c6eb
commit 6bad464348
3 changed files with 8 additions and 7 deletions

View file

@ -28,7 +28,7 @@
* *
* Known contributors to this file: * Known contributors to this file:
* Ville Virrankoski, 1995 * Ville Virrankoski, 1995
* Markus Armbruster, 2004-2016 * Markus Armbruster, 2004-2020
*/ */
#ifndef UPDATE_H #ifndef UPDATE_H
@ -59,7 +59,7 @@ struct budg_item {
/* A nation's budget for an update */ /* A nation's budget for an update */
struct budget { struct budget {
/* production by sector type */ /* production by sector type */
struct budg_item prod[SCT_TYPE_MAX + 1]; struct budg_item prod[ARRAY_SIZE(dchr) - 1];
/* level production output */ /* level production output */
float level[4]; float level[4];
/* building and maintenance */ /* building and maintenance */

View file

@ -30,7 +30,7 @@
* Thomas Ruschak, 1992 * Thomas Ruschak, 1992
* Ville Virrankoski, 1995 * Ville Virrankoski, 1995
* Steve McClure, 1997-2000 * Steve McClure, 1997-2000
* Markus Armbruster, 2004-2016 * Markus Armbruster, 2004-2020
*/ */
#include <config.h> #include <config.h>
@ -61,7 +61,7 @@ budg(void)
{ "Sector building", "sector" }, { "Sector building", "sector" },
{ "Sector maintenance", "sector" } { "Sector maintenance", "sector" }
}; };
int i; unsigned i;
struct budget *budget; struct budget *budget;
int income, expenses, taxes; int income, expenses, taxes;
struct natstr *np; struct natstr *np;
@ -76,7 +76,7 @@ budg(void)
income = expenses = 0; income = expenses = 0;
pr("Sector Type\t\t\tProduction\t\t\t Cost\n"); pr("Sector Type\t\t\tProduction\t\t\t Cost\n");
for (i = 0; i <= SCT_TYPE_MAX; i++) { for (i = 0; i < ARRAY_SIZE(budget->prod); i++) {
if (!budget->prod[i].money) if (!budget->prod[i].money)
continue; continue;
pr("%-17s\t\t", dchr[i].d_name); pr("%-17s\t\t", dchr[i].d_name);

View file

@ -29,7 +29,7 @@
* Known contributors to this file: * Known contributors to this file:
* Ken Stevens, 1995 * Ken Stevens, 1995
* Steve McClure, 1998 * Steve McClure, 1998
* Markus Armbruster, 2004-2011 * Markus Armbruster, 2004-2020
* Ron Koenderink, 2006 * Ron Koenderink, 2006
*/ */
@ -358,7 +358,8 @@ bmnxtsct(struct nstr_sect *np)
static char static char
map_char(int type, natid own, int owner_or_god) map_char(int type, natid own, int owner_or_god)
{ {
if (CANT_HAPPEN(type > SCT_TYPE_MAX || !dchr[type].d_mnem)) if (CANT_HAPPEN((unsigned)type >= ARRAY_SIZE(dchr) - 1
|| !dchr[type].d_mnem))
return '?'; return '?';
if (owner_or_god if (owner_or_god
|| type == SCT_WATER || type == SCT_MOUNT || type == SCT_WASTE || type == SCT_WATER || type == SCT_MOUNT || type == SCT_WASTE