(I_NONE, I_CIVIL, I_MILIT, I_SHELL, I_GUN, I_PETROL, I_IRON, I_DUST,

I_BAR, I_FOOD, I_OIL, I_LCM, I_HCM, I_UW, I_RAD, I_MAX): Turn macros
into enumeration constants.
(i_type): New.  Use where appropriate.  No functional changes, except
that I_NONE is now catched properly in a few places.
This commit is contained in:
Marc Olzheim 2004-09-16 21:18:01 +00:00
parent 308430e751
commit d30942632b
38 changed files with 143 additions and 134 deletions

View file

@ -65,7 +65,7 @@ static void plane_bomb(struct emp_qelem *list, struct sctstr *target);
static void land_bomb(struct emp_qelem *list, struct sctstr *target);
static void ship_bomb(struct emp_qelem *list, struct sctstr *target);
static int bombcomm[] = {
static i_type bombcomm[] = {
I_CIVIL,
I_MILIT,
I_SHELL,

View file

@ -237,7 +237,7 @@ check_market(void)
tleft = 0;
if (tleft > 0.0)
continue;
if (CANT_HAPPEN((unsigned)comm.com_type > I_MAX))
if (CANT_HAPPEN(comm.com_type <= I_NONE || comm.com_type > I_MAX))
continue;
sect = getsectp(comm.com_x, comm.com_y);
m = sect->sct_item[comm.com_type];

View file

@ -101,7 +101,7 @@ coll(void)
}
pay = dchr[sect.sct_type].d_value * ((float)sect.sct_effic + 100.0);
for (i = 0; ichr[i].i_name; i++) {
if (ichr[i].i_value == 0 || ichr[i].i_vtype == 0)
if (ichr[i].i_value == 0 || ichr[i].i_vtype == I_NONE)
continue;
val = sect.sct_item[ichr[i].i_vtype];
pay += val * ichr[i].i_value;

View file

@ -56,7 +56,7 @@ explore(void)
double weight;
int mcost, dam;
int infected;
int vtype;
i_type vtype;
int amt_src;
int amt_dst;
struct ichrstr *ip;

View file

@ -737,7 +737,7 @@ static int
load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
struct ichrstr *ich, int load_unload, int *nshipsp)
{
register int item = ich->i_vtype;
i_type item = ich->i_vtype;
struct mchrstr *mcp = &mchr[(int)sp->shp_type];
int ship_amt, ship_max, sect_amt, move_amt;
int amount;
@ -940,7 +940,7 @@ static int
load_comm_land(struct sctstr *sectp, struct lndstr *lp,
struct ichrstr *ich, int load_unload, int *nunitsp)
{
register int item = ich->i_vtype;
i_type item = ich->i_vtype;
struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
int land_amt, land_max, sect_amt, move_amt;
int amount;

View file

@ -92,14 +92,14 @@ pr_mark(struct comstr *comm)
}
int
display_mark(int only_itype, int only_cheapest)
display_mark(i_type only_itype, int only_cheapest)
{
struct comstr comm;
struct comstr comm2;
int sellers = 0;
int cnt = 0;
int cheapest_items[I_MAX + 1];
int i;
i_type i;
/* Execute trades so report lists only lots that are still available. */
check_market();
@ -111,12 +111,13 @@ display_mark(int only_itype, int only_cheapest)
pr(" --- ------------- -- --------- ----- ---- ------ ------\n");
if (only_cheapest) {
for (i = 0; i < I_MAX + 1; i++)
for (i = I_NONE + 1; i <= I_MAX; i++)
cheapest_items[i] = -1;
for (sellers = 0; getcomm(sellers, &comm); sellers++) {
if (comm.com_owner == 0)
continue;
if (CANT_HAPPEN((unsigned)comm.com_type > I_MAX))
if (CANT_HAPPEN(comm.com_type <= I_NONE
|| comm.com_type > I_MAX))
continue;
if (cheapest_items[comm.com_type] != -1) {
getcomm(cheapest_items[comm.com_type], &comm2);
@ -128,7 +129,7 @@ display_mark(int only_itype, int only_cheapest)
}
}
CANT_HAPPEN(only_itype != I_NONE); /* not implemented */
for (i = 0; i < I_MAX + 1; i++) {
for (i = I_NONE + 1; i <= I_MAX; i++) {
if (cheapest_items[i] == -1)
continue;
getcomm(cheapest_items[i], &comm);

View file

@ -61,7 +61,7 @@ move(void)
int left;
int mcost, dam;
int infected;
int vtype;
i_type vtype;
int amt_src;
int amt_dst;
struct ichrstr *ip;
@ -347,7 +347,7 @@ cmd_move_map(s_char *what, coord curx, coord cury, s_char *arg)
}
int
want_to_abandon(struct sctstr *sp, int vtype, int amnt, struct lndstr *lp)
want_to_abandon(struct sctstr *sp, i_type vtype, int amnt, struct lndstr *lp)
{
char prompt[80];
@ -368,7 +368,7 @@ want_to_abandon(struct sctstr *sp, int vtype, int amnt, struct lndstr *lp)
}
int
would_abandon(struct sctstr *sp, int vtype, int amnt, struct lndstr *lp)
would_abandon(struct sctstr *sp, i_type vtype, int amnt, struct lndstr *lp)
{
int mil, civs, loyalcivs;

View file

@ -238,7 +238,7 @@ orde(void)
level = 0; /* prevent negatives. */
pr("You must use positive number! Level set to 0.\n");
}
ship.shp_tstart[sub] = (s_char)i1->i_vtype;
ship.shp_tstart[sub] = i1->i_vtype;
ship.shp_lstart[sub] = level;
pr("Order Set \n");
break;
@ -258,7 +258,7 @@ orde(void)
level = 0;
pr("You must use positive number! Level set to 0.\n");
}
ship.shp_tend[sub] = (s_char)i1->i_vtype;
ship.shp_tend[sub] = i1->i_vtype;
ship.shp_lend[sub] = level;
pr("Order Set \n");
break;
@ -286,7 +286,7 @@ orde(void)
&& (ship.shp_lstart[1] != ' '))) {
coord tcord;
s_char tcomm;
i_type tcomm;
short lev[TMAX];
int i;
@ -354,10 +354,10 @@ eta_calc(struct shpstr *sp, s_char *path, int *len, int *nupdates)
}
static void
prhold(int hold, int itype, int amt)
prhold(int hold, i_type itype, int amt)
{
if (itype != I_NONE && amt != 0) {
if (CANT_HAPPEN((unsigned)itype > I_MAX))
if (CANT_HAPPEN(itype <= I_NONE || itype > I_MAX))
return;
pr("%d-", hold + 1);
pr("%c", ichr[itype].i_mnem);

View file

@ -86,8 +86,8 @@ prod(void)
int unit_work; /* sum of component amounts */
int used; /* production w/infinite workforce */
int wforce;
int it;
u_char vtype;
i_type it;
i_type vtype;
s_char *resource;
s_char maxc[MAXPRCON][10];
s_char use[MAXPRCON][10];
@ -249,7 +249,7 @@ prod(void)
real = dmin(999.0, (double)act * prodeff);
maxr = dmin(999.0, (double)max * prodeff);
if (vtype != 0) {
if (vtype != I_NONE) {
if (real < 0.0)
real = 0.0;
/* production backlog? */
@ -305,7 +305,7 @@ prod(void)
pr(" %3.0f%%", p_e * 100.0);
pr(" %4d", wforce);
if (vtype != 0) {
if (vtype != I_NONE) {
pr(" %4d", (int)(real + 0.5));
} else if (type != SCT_ENLIST) {
switch (pp->p_level) {
@ -369,7 +369,7 @@ prod(void)
max = 0;
maxr = 0;
}
if (vtype != 0 || pp->p_level == NAT_ELEV
if (vtype != I_NONE || pp->p_level == NAT_ELEV
|| pp->p_level == NAT_HLEV)
pr(" %4d\n", min(999, (int)(max * prodeff + 0.05)));
else

View file

@ -116,7 +116,7 @@ rese(void)
pr("The destination sector must be at least 60%% efficient.\n");
return RET_OK;
}
if (CANT_HAPPEN((unsigned)comm.com_type > I_MAX)) {
if (CANT_HAPPEN(comm.com_type <= I_NONE || comm.com_type > I_MAX)) {
pr("The goods have been eaten by a grue.");
return RET_OK;
}

View file

@ -58,7 +58,7 @@ rout(void)
int row;
int y;
int ry;
int i_del;
i_type i_del;
int dir;
s_char *p;
s_char what[64];

View file

@ -63,7 +63,7 @@ scra(void)
struct plchrstr *pp;
struct lchrstr *lp;
s_char *p;
int i;
i_type i;
struct nstr_item ni2;
struct plnstr plane;
struct lndstr land;
@ -187,7 +187,7 @@ scra(void)
}
pr("%s", prship(&item.ship));
/* FIXME obey ITEM_MAX */
for (i = 1; i <= I_MAX; i++) {
for (i = I_NONE + 1; i <= I_MAX; i++) {
sect.sct_item[i] += item.ship.shp_item[i];
}
sect.sct_item[I_LCM] += mp->m_lcm * 2 / 3 * eff;
@ -254,7 +254,7 @@ scra(void)
lp = &lchr[(int)item.land.lnd_type];
pr("%s", prland(&item.land));
/* FIXME obey ITEM_MAX */
for (i = 1; i <= I_MAX; i++) {
for (i = I_NONE + 1; i <= I_MAX; i++) {
sect.sct_item[i] += item.land.lnd_item[i];
}
sect.sct_item[I_LCM] += lp->l_lcm * 2 / 3 * eff;

View file

@ -54,7 +54,7 @@ shoo(void)
int nshot;
int mob_cost;
double m;
int item;
i_type item;
struct ichrstr *ip;
struct lndstr land;
int targets;

View file

@ -55,7 +55,7 @@ thre(void)
struct ichrstr *ip;
s_char *p;
int thresh;
int type;
i_type type;
s_char prompt[128];
s_char buf[128];

View file

@ -82,14 +82,6 @@
/* Selector descriptors for characteristics tables */
/* FIXME belongs into src/lib/global/ */
/* Return nsc_type for a signed integer with the same size as TYPE. */
#define NSC_SITYPE(type) \
(sizeof(type) == 1 ? NSC_CHAR \
: sizeof(type) == sizeof(short) ? NSC_SHORT \
: sizeof(type) == sizeof(int) ? NSC_INT \
: sizeof(type) == sizeof(long) ? NSC_LONG \
: 1/0)
static struct castr dchr_ca[] = {
{NSC_STRING, 0, 0, offsetof(struct dchrstr, d_name), "name"},
{NSC_INT, 0, 0, offsetof(struct dchrstr, d_mnem), "mnem"},
@ -110,7 +102,7 @@ static struct castr dchr_ca[] = {
static struct castr ichr_ca[] = {
{NSC_STRING, 0, 0, offsetof(struct ichrstr, i_name), "name"},
{NSC_INT, 0, 0, offsetof(struct ichrstr, i_mnem), "mnem"},
{NSC_INT, 0, 0, offsetof(struct ichrstr, i_vtype), "vtype"},
{NSC_SITYPE(i_type), 0, 0, offsetof(struct ichrstr, i_vtype), "vtype"},
{NSC_INT, 0, 0, offsetof(struct ichrstr, i_value), "value"},
{NSC_INT, 0, 0, offsetof(struct ichrstr, i_sell), "sell"},
{NSC_INT, 0, 0, offsetof(struct ichrstr, i_lbs), "lbs"},
@ -166,9 +158,9 @@ static struct castr mchr_ca[] = {
static struct castr pchr_ca[] = {
{NSC_STRING, 0, 0, offsetof(struct pchrstr, p_name), "name"},
{NSC_STRING, 0, 0, offsetof(struct pchrstr, p_sname), "sname"},
{NSC_UCHAR, 0, MAXPRCON, offsetof(struct pchrstr, p_ctype), "ctype"},
{NSC_SITYPE(i_type), 0, MAXPRCON, offsetof(struct pchrstr, p_ctype), "ctype"},
{NSC_USHORT, 0, MAXPRCON, offsetof(struct pchrstr, p_camt), "camt"},
{NSC_INT, 0, 0, offsetof(struct pchrstr, p_type), "type"},
{NSC_SITYPE(i_type), 0, 0, offsetof(struct pchrstr, p_type), "type"},
{NSC_INT, 0, 0, offsetof(struct pchrstr, p_level), "level"},
{NSC_INT, 0, 0, offsetof(struct pchrstr, p_cost), "cost"},
{NSC_INT, 0, 0, offsetof(struct pchrstr, p_nrndx), "nrndx"},