diff --git a/include/budg.h b/include/budg.h index d92f17b1..cf948c90 100644 --- a/include/budg.h +++ b/include/budg.h @@ -33,8 +33,8 @@ void fill_update_array(int *bp, struct sctstr *sp); int *get_wp(int *bp, struct sctstr *sp, int cm); -int gt_bg_nmbr(int *bp, struct sctstr *sp, int comm); -void pt_bg_nmbr(int *bp, struct sctstr *sp, int comm, int amount); +int gt_bg_nmbr(int *bp, struct sctstr *sp, i_type comm); +void pt_bg_nmbr(int *bp, struct sctstr *sp, i_type comm, int amount); void get_materials(struct sctstr *sp, int *bp, int *mvec, int check); extern long money[MAXNOC]; diff --git a/include/commodity.h b/include/commodity.h index a8741ba5..512f1d0f 100644 --- a/include/commodity.h +++ b/include/commodity.h @@ -40,7 +40,7 @@ struct comstr { short ef_type; natid com_owner; short com_uid; - int com_type; + i_type com_type; int com_amount; float com_price; int com_maxbidder; diff --git a/include/item.h b/include/item.h index 4b470516..c616d0b8 100644 --- a/include/item.h +++ b/include/item.h @@ -46,9 +46,28 @@ enum { NUMPKG = BPKG + 1 }; +typedef enum { + 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 = I_RAD +} ATTRIBUTE((packed)) i_type; + struct ichrstr { int i_mnem; /* usually the initial letter */ - int i_vtype; /* var type */ + i_type i_vtype; /* var type */ int i_value; /* mortgage value */ int i_sell; /* can this be sold? */ int i_lbs; /* how hard to move */ diff --git a/include/nsc.h b/include/nsc.h index 545f23d7..d0e0bba2 100644 --- a/include/nsc.h +++ b/include/nsc.h @@ -65,6 +65,14 @@ typedef enum { } nsc_type; typedef char packed_nsc_type; +/* 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) + /* Value category */ typedef enum { NSC_NOCAT, diff --git a/include/product.h b/include/product.h index 7934c7cf..381327e3 100644 --- a/include/product.h +++ b/include/product.h @@ -41,9 +41,9 @@ enum { MAXPRCON = 3 }; struct pchrstr { - u_char p_ctype[MAXPRCON]; /* constituent types */ + i_type p_ctype[MAXPRCON]; /* constituent types */ u_short p_camt[MAXPRCON]; /* constituent amounts */ - int p_type; /* product item type, or I_NONE if level */ + i_type p_type; /* product item type, or I_NONE if level */ int p_level; /* level index (NAT_?LEV), or -1 if item */ int p_cost; /* dollars / product unit */ int p_nrndx; /* index into sect of natural resource */ diff --git a/include/prototypes.h b/include/prototypes.h index a7ea72a1..7c4fffb4 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -65,9 +65,9 @@ extern int check_market(void); extern void set_coastal(struct sctstr *); extern int sendmessage(struct natstr *, struct natstr *, char *, int); extern void gift(int, int, s_char *, int, s_char *); -extern int display_mark(int, int); -extern int want_to_abandon(struct sctstr *, int, int, struct lndstr *); -extern int would_abandon(struct sctstr *, int, int, struct lndstr *); +extern int display_mark(i_type, int); +extern int want_to_abandon(struct sctstr *, i_type, int, struct lndstr *); +extern int would_abandon(struct sctstr *, i_type, int, struct lndstr *); extern int nav_map(int, int, int); extern int count_pop(register int); extern int scuttle_tradeship(struct shpstr *, int); @@ -102,7 +102,7 @@ extern void planedamage(struct plnstr *, int); extern int nukedamage(struct nchrstr *, int, int); extern int effdamage(register int, int); extern void item_damage(int, short *); -extern int commdamage(register int, int, int); +extern int commdamage(int, int, i_type); /* check.c */ extern int check_sect_ok(struct sctstr *); extern int check_ship_ok(struct shpstr *); @@ -511,9 +511,9 @@ extern int snxtitem(register struct nstr_item *, int, s_char *); extern int snxtsct(register struct nstr_sect *, s_char *); /* supply.c */ extern void resupply_all(struct lndstr *); -extern void resupply_commod(struct lndstr *, int); -extern int supply_commod(int, int, int, int, int); -extern int try_supply_commod(int, int, int, int, int); +extern void resupply_commod(struct lndstr *, i_type); +extern int supply_commod(int, int, int, i_type, int); +extern int try_supply_commod(int, int, int, i_type, int); extern int has_supply(struct lndstr *); extern int use_supply(struct lndstr *); /* takeover.c */ @@ -578,10 +578,10 @@ extern void prod_nat(int); extern int nav_ship(register struct shpstr *); /* nav_util.c */ extern int check_nav(struct sctstr *); -extern int load_it(register struct shpstr *, register struct sctstr *, +extern int load_it(struct shpstr *, struct sctstr *, int); -extern void unload_it(register struct shpstr *); -extern void auto_fuel_ship(register struct shpstr *); +extern void unload_it(struct shpstr *); +extern void auto_fuel_ship(struct shpstr *); /* nxtitemp.c */ extern s_char *nxtitemp(struct nstr_item *, int); /* nxtsctp.c */ diff --git a/include/ship.h b/include/ship.h index 227a0f84..9239b5c8 100644 --- a/include/ship.h +++ b/include/ship.h @@ -82,8 +82,8 @@ struct shpstr { short shp_glim; coord shp_destx[2]; /* location for ship destination */ coord shp_desty[2]; - s_char shp_tstart[TMAX]; /* what goods to pick up at start point */ - s_char shp_tend[TMAX]; /* what goods to pick up at end point */ + i_type shp_tstart[TMAX]; /* what goods to pick up at start point */ + i_type shp_tend[TMAX]; /* what goods to pick up at end point */ short shp_lstart[TMAX]; /* How much do we pick up at the start */ short shp_lend[TMAX]; /* How much do we pick up at the end */ u_char shp_autonav; /* autonavigation flags */ diff --git a/include/var.h b/include/var.h index e42fb531..28bfbffd 100644 --- a/include/var.h +++ b/include/var.h @@ -40,21 +40,4 @@ #define PLG_INCUBATE 3 #define PLG_EXPOSED 4 -#define I_NONE 0 -#define I_CIVIL 1 -#define I_MILIT 2 -#define I_SHELL 3 -#define I_GUN 4 -#define I_PETROL 5 -#define I_IRON 6 -#define I_DUST 7 -#define I_BAR 8 -#define I_FOOD 9 -#define I_OIL 10 -#define I_LCM 11 -#define I_HCM 12 -#define I_UW 13 -#define I_RAD 14 -#define I_MAX 14 - #endif /* _VAR_H_ */ diff --git a/src/lib/commands/bomb.c b/src/lib/commands/bomb.c index 9c3738f1..f8d44741 100644 --- a/src/lib/commands/bomb.c +++ b/src/lib/commands/bomb.c @@ -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, diff --git a/src/lib/commands/buy.c b/src/lib/commands/buy.c index bcaba85e..59972e5e 100644 --- a/src/lib/commands/buy.c +++ b/src/lib/commands/buy.c @@ -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]; diff --git a/src/lib/commands/coll.c b/src/lib/commands/coll.c index c704b638..9ad041d1 100644 --- a/src/lib/commands/coll.c +++ b/src/lib/commands/coll.c @@ -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; diff --git a/src/lib/commands/expl.c b/src/lib/commands/expl.c index af1ab6b7..38e7135d 100644 --- a/src/lib/commands/expl.c +++ b/src/lib/commands/expl.c @@ -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; diff --git a/src/lib/commands/load.c b/src/lib/commands/load.c index c28d8da7..6cc8ae63 100644 --- a/src/lib/commands/load.c +++ b/src/lib/commands/load.c @@ -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; diff --git a/src/lib/commands/mark.c b/src/lib/commands/mark.c index c723baa3..78ea9302 100644 --- a/src/lib/commands/mark.c +++ b/src/lib/commands/mark.c @@ -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); diff --git a/src/lib/commands/move.c b/src/lib/commands/move.c index 4fabbe9b..5a226841 100644 --- a/src/lib/commands/move.c +++ b/src/lib/commands/move.c @@ -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; diff --git a/src/lib/commands/orde.c b/src/lib/commands/orde.c index 100de2e4..0a1e94b6 100644 --- a/src/lib/commands/orde.c +++ b/src/lib/commands/orde.c @@ -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); diff --git a/src/lib/commands/prod.c b/src/lib/commands/prod.c index 22e0798a..d0641bf4 100644 --- a/src/lib/commands/prod.c +++ b/src/lib/commands/prod.c @@ -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 diff --git a/src/lib/commands/rese.c b/src/lib/commands/rese.c index abe96531..1eceec2a 100644 --- a/src/lib/commands/rese.c +++ b/src/lib/commands/rese.c @@ -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; } diff --git a/src/lib/commands/rout.c b/src/lib/commands/rout.c index 0c0d276f..755359f1 100644 --- a/src/lib/commands/rout.c +++ b/src/lib/commands/rout.c @@ -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]; diff --git a/src/lib/commands/scra.c b/src/lib/commands/scra.c index b1d700e9..28949986 100644 --- a/src/lib/commands/scra.c +++ b/src/lib/commands/scra.c @@ -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; diff --git a/src/lib/commands/shoo.c b/src/lib/commands/shoo.c index 0ee78620..780d35ca 100644 --- a/src/lib/commands/shoo.c +++ b/src/lib/commands/shoo.c @@ -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; diff --git a/src/lib/commands/thre.c b/src/lib/commands/thre.c index 38119389..a042d58e 100644 --- a/src/lib/commands/thre.c +++ b/src/lib/commands/thre.c @@ -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]; diff --git a/src/lib/commands/xdump.c b/src/lib/commands/xdump.c index a4b6308e..957de34a 100644 --- a/src/lib/commands/xdump.c +++ b/src/lib/commands/xdump.c @@ -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"}, diff --git a/src/lib/common/damage.c b/src/lib/common/damage.c index 0071cfab..ce876d79 100644 --- a/src/lib/common/damage.c +++ b/src/lib/common/damage.c @@ -52,9 +52,10 @@ void item_damage(int pct, short *item) { - int i, lose; + int lose; + i_type i; - for (i = 1; i <= I_MAX; ++i) { + for (i = I_NONE + 1; i <= I_MAX; ++i) { if (opt_SUPER_BARS && i == I_BAR) continue; lose = roundavg((double)item[i] * pct * 0.01); @@ -192,7 +193,7 @@ effdamage(register int amt, int dam) } int -commdamage(register int amt, int dam, int vtype) +commdamage(int amt, int dam, i_type vtype) { int lost; diff --git a/src/lib/global/nsc.c b/src/lib/global/nsc.c index e6e2bcb3..1a9ac5db 100644 --- a/src/lib/global/nsc.c +++ b/src/lib/global/nsc.c @@ -141,8 +141,8 @@ struct castr ship_ca[] = { {NSC_XCOORD, 0, 0, fldoff(shpstr, shp_destx[1]), "xend"}, {NSC_YCOORD, 0, 0, fldoff(shpstr, shp_desty[0]), "ystart"}, {NSC_YCOORD, 0, 0, fldoff(shpstr, shp_desty[1]), "yend"}, - {NSC_CHAR, 0, TMAX, fldoff(shpstr, shp_tstart), "cargostart"}, - {NSC_CHAR, 0, TMAX, fldoff(shpstr, shp_tend), "cargoend"}, + {NSC_SITYPE(i_type), 0, TMAX, fldoff(shpstr, shp_tstart), "cargostart"}, + {NSC_SITYPE(i_type), 0, TMAX, fldoff(shpstr, shp_tend), "cargoend"}, {NSC_SHORT, 0, TMAX, fldoff(shpstr, shp_lstart), "amtstart"}, {NSC_SHORT, 0, TMAX, fldoff(shpstr, shp_lend), "amtend"}, {NSC_UCHAR, 0, 0, fldoff(shpstr, shp_autonav), "autonav"}, @@ -279,7 +279,7 @@ struct castr lost_ca[] = { struct castr commodity_ca[] = { {NSC_NATID, 0, 0, fldoff(comstr, com_owner), "owner"}, {NSC_SHORT, 0, 0, fldoff(comstr, com_uid), "uid"}, - {NSC_INT, 0, 0, fldoff(comstr, com_type), "type"}, + {NSC_SITYPE(i_type), 0, 0, fldoff(comstr, com_type), "type"}, {NSC_INT, 0, 0, fldoff(comstr, com_amount), "amount"}, {NSC_INT, 0, 0, fldoff(comstr, com_maxbidder), "maxbidder"}, {NSC_TIME, 0, 0, fldoff(comstr, com_markettime), "markettime"}, diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index 69665d32..dd52c01e 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -1264,7 +1264,7 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags, struct lndstr land; struct shpstr ship; struct sctstr sect; - int itype; + i_type itype; int rval; short *item; diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index c02ebd6a..08e43430 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -567,7 +567,7 @@ pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission) struct lndstr land; struct shpstr ship; struct sctstr sect; - int itype; + i_type itype; int rval; short *item; int own; diff --git a/src/lib/subs/show.c b/src/lib/subs/show.c index df4142fb..6172a418 100644 --- a/src/lib/subs/show.c +++ b/src/lib/subs/show.c @@ -419,8 +419,9 @@ show_ship_stats(int tlev) void show_ship_capab(int tlev) { - register struct mchrstr *mp; - register int i; + struct mchrstr *mp; + i_type i; + int j; int scount; int n; s_char *p; @@ -436,14 +437,14 @@ show_ship_capab(int tlev) pr("%-25.25s ", mp->m_name); - for (i = 0; i <= I_MAX; ++i) + for (i = I_NONE + 1; i <= I_MAX; ++i) if (mp->m_item[i]) pr(" %d%c", mp->m_item[i], ichr[i].i_mnem); pr(" "); - for (i = n = 0; i < 32; i++) { - if (!(mp->m_flags & bit(i))) + for (j = n = 0; j < 32; j++) { + if (!(mp->m_flags & bit(j))) continue; - if (NULL != (p = lookup(bit(i), ship_flags))) { + if (NULL != (p = lookup(bit(j), ship_flags))) { if (n++ > 0) pr(" "); pr(p); @@ -546,8 +547,9 @@ show_land_capab(int tlev) { struct lchrstr *lcp; int lcount; - register int i, n; - register s_char *p; + i_type i; + int j, n; + s_char *p; pr("%25s capabilities\n", ""); @@ -559,14 +561,14 @@ show_land_capab(int tlev) pr("%-25s ", lcp->l_name); - for (i = 0; i <= I_MAX; ++i) + for (i = I_NONE + 1; i <= I_MAX; ++i) if (lcp->l_item[i]) pr(" %d%c", lcp->l_item[i], ichr[i].i_mnem); pr(" "); - for (i = n = 0; i < 32; i++) { - if (!(lcp->l_flags & bit(i))) + for (j = n = 0; j < 32; j++) { + if (!(lcp->l_flags & bit(j))) continue; - if (NULL != (p = lookup(bit(i), land_flags))) { + if (NULL != (p = lookup(bit(j), land_flags))) { if (n++ > 0) pr(" "); pr(p); diff --git a/src/lib/subs/supply.c b/src/lib/subs/supply.c index 3739dcf3..ec6b2077 100644 --- a/src/lib/subs/supply.c +++ b/src/lib/subs/supply.c @@ -49,8 +49,8 @@ #include "player.h" #include "prototypes.h" -static int get_minimum(struct lndstr *, int); -static int s_commod(int, int, int, int, int, int); +static int get_minimum(struct lndstr *, i_type); +static int s_commod(int, int, int, i_type, int, int); /* * We want to get enough guns to be maxed out, enough shells to @@ -84,7 +84,7 @@ resupply_all(struct lndstr *lp) */ void -resupply_commod(struct lndstr *lp, int type) +resupply_commod(struct lndstr *lp, i_type type) { int amt; struct lchrstr *lcp; @@ -131,7 +131,7 @@ resupply_commod(struct lndstr *lp, int type) * Actually get the commod */ int -supply_commod(int own, int x, int y, int type, int total_wanted) +supply_commod(int own, int x, int y, i_type type, int total_wanted) { if (total_wanted < 0) return 0; @@ -142,7 +142,7 @@ supply_commod(int own, int x, int y, int type, int total_wanted) * Just return the number you COULD get, without doing it */ int -try_supply_commod(int own, int x, int y, int type, int total_wanted) +try_supply_commod(int own, int x, int y, i_type type, int total_wanted) { if (total_wanted < 0) return 0; @@ -152,7 +152,7 @@ try_supply_commod(int own, int x, int y, int type, int total_wanted) /* Get supplies of a certain type */ static int -s_commod(int own, int x, int y, int type, int total_wanted, +s_commod(int own, int x, int y, i_type type, int total_wanted, int actually_doit) { int wanted = total_wanted; @@ -433,7 +433,7 @@ s_commod(int own, int x, int y, int type, int total_wanted, */ static int -get_minimum(struct lndstr *lp, int type) +get_minimum(struct lndstr *lp, i_type type) { struct lchrstr *lcp; int max, want = 0; diff --git a/src/lib/subs/trdsub.c b/src/lib/subs/trdsub.c index c860a2aa..0f27a73b 100644 --- a/src/lib/subs/trdsub.c +++ b/src/lib/subs/trdsub.c @@ -133,7 +133,7 @@ trade_desc(struct trdstr *tp, union trdgenstr *tgp) pr("(%3d) tech %d %d%% %s [", tp->trd_owner, sp->shp_tech, sp->shp_effic, prship(sp)); - for (i = 1; i <= I_MAX; ++i) { + for (i = I_NONE + 1; i <= I_MAX; ++i) { if (sp->shp_item[i]) pr("%c:%d ", ichr[i].i_mnem, sp->shp_item[i]); } @@ -191,7 +191,7 @@ trade_desc(struct trdstr *tp, union trdgenstr *tgp) pr("(%3d) tech %d %d%% %s [", tp->trd_owner, lp->lnd_tech, lp->lnd_effic, lchr[(int)lp->lnd_type].l_name); - for (i = 1; i <= I_MAX; ++i) { + for (i = I_NONE + 1; i <= I_MAX; ++i) { if (lp->lnd_item[i]) pr("%c:%d ", ichr[i].i_mnem, lp->lnd_item[i]); } @@ -252,7 +252,7 @@ get_couval(int cnum) secttot += (long)(dchr[sp->sct_type].d_value * ((float)sp->sct_effic + 100.0)); for (k = 0; ichr[k].i_name; k++) { - if (ichr[k].i_value == 0 || ichr[k].i_vtype == 0) + if (ichr[k].i_value == 0 || ichr[k].i_vtype == I_NONE) continue; val = sp->sct_item[ichr[k].i_vtype]; secttot += val * ichr[k].i_value; diff --git a/src/lib/update/bp.c b/src/lib/update/bp.c index 7dfa6485..8d32c32d 100644 --- a/src/lib/update/bp.c +++ b/src/lib/update/bp.c @@ -52,7 +52,7 @@ get_wp(int *bp, struct sctstr *sp, int cm) } int -gt_bg_nmbr(int *bp, struct sctstr *sp, int comm) +gt_bg_nmbr(int *bp, struct sctstr *sp, i_type comm) { int *wp; int cm; @@ -66,7 +66,7 @@ gt_bg_nmbr(int *bp, struct sctstr *sp, int comm) } void -pt_bg_nmbr(int *bp, struct sctstr *sp, int comm, int amount) +pt_bg_nmbr(int *bp, struct sctstr *sp, i_type comm, int amount) { int *wp; int cm; @@ -80,10 +80,11 @@ pt_bg_nmbr(int *bp, struct sctstr *sp, int comm, int amount) void fill_update_array(int *bp, struct sctstr *sp) { - int i, k; + int k; int *wp; + i_type i; - for (i = 1; i <= I_MAX; i++) + for (i = I_NONE + 1; i <= I_MAX; i++) if ((k = bud_key[i]) != 0) { wp = get_wp(bp, sp, k); *wp = sp->sct_item[i]; diff --git a/src/lib/update/deliver.c b/src/lib/update/deliver.c index 400bbf0d..5829e6e9 100644 --- a/src/lib/update/deliver.c +++ b/src/lib/update/deliver.c @@ -45,11 +45,11 @@ #define DELIVER_BONUS 4.0 static int -deliver(register struct sctstr *from, struct ichrstr *ip, int dir, +deliver(struct sctstr *from, struct ichrstr *ip, int dir, int thresh, int amt_src, int plague, i_packing packing) { - register struct sctstr *to; - int vtype; /* item vartype */ + struct sctstr *to; + i_type vtype; /* item vartype */ int amt_moved; int amt_dst; int mobility; @@ -119,7 +119,7 @@ deliver(register struct sctstr *from, struct ichrstr *ip, int dir, void dodeliver(struct sctstr *sp) { - register int i; + i_type i; int thresh; int dir; int plague; @@ -130,7 +130,7 @@ dodeliver(struct sctstr *sp) return; plague = sp->sct_pstage; packing = sp->sct_effic >= 60 ? dchr[sp->sct_type].d_pkg : IPKG; - for (i = 1; i <= I_MAX; i++) { + for (i = I_NONE + 1; i <= I_MAX; i++) { if (sp->sct_del[i] == 0) continue; thresh = sp->sct_del[i] & ~0x7; diff --git a/src/lib/update/distribute.c b/src/lib/update/distribute.c index fba6ec5e..1e60a57e 100644 --- a/src/lib/update/distribute.c +++ b/src/lib/update/distribute.c @@ -69,7 +69,7 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost, int pack; double mcost; int diff; - int item; + i_type item; int changed; int rplague; int lplague; @@ -91,7 +91,7 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost, sect_packing = sp->sct_effic >= 60 ? dchr[sp->sct_type].d_pkg : IPKG; lplague = rplague = changed = 0; - for (item = 1; item < I_MAX + 1; item++) { + for (item = I_NONE + 1; item <= I_MAX; item++) { if (sp->sct_dist[item] == 0) continue; ip = &ichr[item]; diff --git a/src/lib/update/material.c b/src/lib/update/material.c index b45c7b79..7b5f2dea 100644 --- a/src/lib/update/material.c +++ b/src/lib/update/material.c @@ -53,7 +53,7 @@ get_materials(struct sctstr *sp, int *bp, int *mvec, int check) int i; int still_left; - for (i = 1; i <= I_MAX; i++) { + for (i = I_NONE + 1; i <= I_MAX; i++) { if (mvec[i] == 0) continue; diff --git a/src/lib/update/nav_ship.c b/src/lib/update/nav_ship.c index 1473f4de..c786e798 100644 --- a/src/lib/update/nav_ship.c +++ b/src/lib/update/nav_ship.c @@ -52,7 +52,7 @@ #include "common.h" #include -static void swap(register struct shpstr *); +static void swap(struct shpstr *); static void scuttle_it(register struct shpstr *sp) @@ -116,10 +116,10 @@ nav_check_atdest(register struct shpstr *sp) /* CZ 6/1/94 */ static void -swap(register struct shpstr *sp) +swap(struct shpstr *sp) { coord tcord; - s_char tcomm[TMAX]; + i_type tcomm[TMAX]; short lev[TMAX]; int i; diff --git a/src/lib/update/nav_util.c b/src/lib/update/nav_util.c index 3e0ab507..4842468f 100644 --- a/src/lib/update/nav_util.c +++ b/src/lib/update/nav_util.c @@ -82,16 +82,17 @@ check_nav(struct sctstr *sect) * Chad Zabel 6/1/94 */ int -load_it(register struct shpstr *sp, register struct sctstr *psect, int i) +load_it(struct shpstr *sp, struct sctstr *psect, int i) { - int comm, shipown, amount, ship_amt, sect_amt; + int shipown, amount, ship_amt, sect_amt; int abs_max, max_amt, transfer; + i_type comm; struct mchrstr *vship; amount = sp->shp_lend[i]; shipown = sp->shp_own; comm = sp->shp_tend[i]; - if (CANT_HAPPEN((unsigned)comm > I_MAX)) + if (CANT_HAPPEN(comm <= I_NONE || comm > I_MAX)) return 0; ship_amt = sp->shp_item[comm]; @@ -157,13 +158,13 @@ load_it(register struct shpstr *sp, register struct sctstr *psect, int i) * Chad Zabel 6/1/94 */ void -unload_it(register struct shpstr *sp) +unload_it(struct shpstr *sp) { struct sctstr *sectp; int i; int landowner; int shipown; - int comm; + i_type comm; int sect_amt; int ship_amt; int max_amt; @@ -182,7 +183,7 @@ unload_it(register struct shpstr *sp) continue; comm = sp->shp_tend[i]; - if (CANT_HAPPEN((unsigned)comm > I_MAX)) + if (CANT_HAPPEN(comm <= I_NONE || comm > I_MAX)) continue; ship_amt = sp->shp_item[comm]; sect_amt = sectp->sct_item[comm]; @@ -221,7 +222,7 @@ unload_it(register struct shpstr *sp) */ void -auto_fuel_ship(register struct shpstr *sp) +auto_fuel_ship(struct shpstr *sp) { double d; int totalfuel = 0; diff --git a/src/lib/update/produce.c b/src/lib/update/produce.c index fe4b359c..dc36cf1c 100644 --- a/src/lib/update/produce.c +++ b/src/lib/update/produce.c @@ -63,7 +63,7 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work, double output; int actual; int unit_work; - int item; + i_type item; int worker_limit; int material_limit; int material_consume; @@ -199,7 +199,8 @@ materials_cost(struct pchrstr *pp, short *vec, int *costp) static void materials_charge(struct pchrstr *pp, short *vec, int count) { - int i, item, n; + int i, n; + i_type item; for (i = 0; i < MAXPRCON; ++i) { item = pp->p_ctype[i]; diff --git a/src/lib/update/sect.c b/src/lib/update/sect.c index 36e36284..af3f026d 100644 --- a/src/lib/update/sect.c +++ b/src/lib/update/sect.c @@ -167,13 +167,13 @@ enlist(short *vec, int etu, int *cost) /* Fallout is calculated here. */ static void -meltitems(int etus, int fallout, int own, short *vec, int type, int x, int y, +meltitems(int etus, int fallout, int own, short *vec, i_type type, int x, int y, int uid) { - int n; + i_type n; int melt; - for (n = 1; n <= I_MAX; n++) { + for (n = I_NONE + 1; n <= I_MAX; n++) { melt = roundavg(vec[n] * etus * (long)fallout / (1000.0 * melt_item_denom[n])); if (melt > vec[n])