From e42f7e82109b6159c8efe21b5480472c66d4bd07 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 8 Apr 2004 19:14:09 +0000 Subject: [PATCH] (build_ship, orde, qorde, nav_loadship, load_it, unload_it): Store item types instead of mnemo characters in shpstr members shp_tstart[] and shp_tend[]. (com_num): No longer used, remove. (orde): Simplify swap code. (prhold): New, factored out of qorde(). --- include/prototypes.h | 1 - src/lib/commands/buil.c | 4 ++-- src/lib/commands/orde.c | 47 ++++++++++++++++++++------------------- src/lib/update/nav_ship.c | 8 ++----- src/lib/update/nav_util.c | 42 ++++++---------------------------- 5 files changed, 35 insertions(+), 67 deletions(-) diff --git a/include/prototypes.h b/include/prototypes.h index 7e2c2b0d..d35baf65 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -583,7 +583,6 @@ extern int nav_ship(register struct shpstr *); extern int check_nav(struct sctstr *); extern int load_it(register struct shpstr *, register struct sctstr *, int); -extern int com_num(s_char *); extern void unload_it(register struct shpstr *); extern void auto_fuel_ship(register struct shpstr *); /* nxtitemp.c */ diff --git a/src/lib/commands/buil.c b/src/lib/commands/buil.c index 538066c9..b6b05ba3 100644 --- a/src/lib/commands/buil.c +++ b/src/lib/commands/buil.c @@ -411,8 +411,8 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp, ship.shp_autonav = 0; /* new code for autonav, Chad Zabel 1-15-94 */ for (i = 0; i < TMAX; ++i) { - ship.shp_tstart[i] = ' '; - ship.shp_tend[i] = ' '; + ship.shp_tstart[i] = I_NONE; + ship.shp_tend[i] = I_NONE; ship.shp_lstart[i] = 0; ship.shp_lend[i] = 0; } diff --git a/src/lib/commands/orde.c b/src/lib/commands/orde.c index b28c3d6b..2f1fb10c 100644 --- a/src/lib/commands/orde.c +++ b/src/lib/commands/orde.c @@ -121,8 +121,8 @@ orde(void) ship.shp_mission = 0; ship.shp_autonav &= ~(AN_AUTONAV + AN_STANDBY + AN_LOADING); for (i = 0; i < TMAX; i++) { - ship.shp_tstart[i] = ' '; - ship.shp_tend[i] = ' '; + ship.shp_tstart[i] = I_NONE; + ship.shp_tend[i] = I_NONE; ship.shp_lstart[i] = 0; ship.shp_lend[i] = 0; } @@ -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_mnem; + ship.shp_tstart[sub] = (s_char)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_mnem; + ship.shp_tend[sub] = (s_char)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[TMAX]; + s_char tcomm; short lev[TMAX]; int i; @@ -306,9 +306,9 @@ orde(void) lev[i] = ship.shp_lstart[i]; ship.shp_lstart[i] = ship.shp_lend[i]; ship.shp_lend[i] = lev[i]; - tcomm[i] = ship.shp_tstart[i]; + tcomm = ship.shp_tstart[i]; ship.shp_tstart[i] = ship.shp_tend[i]; - ship.shp_tend[i] = tcomm[i]; + ship.shp_tend[i] = tcomm; } } /* @@ -353,6 +353,19 @@ eta_calc(struct shpstr *sp, s_char *path, int *len, int *nupdates) } } +static void +prhold(int hold, int itype, int amt) +{ + if (itype != I_NONE && amt != 0) { + if (CANT_HAPPEN((unsigned)itype > I_MAX)) + return; + pr("%d-", hold + 1); + pr("%c", ichr[itype].i_mnem); + pr(":"); + pr("%d ", amt); + } +} + int qorde(void) { @@ -388,23 +401,11 @@ qorde(void) if (ship.shp_autonav & AN_AUTONAV) { pr(" ["); - for (i = 0; i < TMAX; i++) { - if (ship.shp_tend[i] != ' ' && ship.shp_lend[i] != 0) { - pr("%d-", i + 1); - pr("%c", ship.shp_tend[i]); - pr(":"); - pr("%d ", ship.shp_lend[i]); - } - } + for (i = 0; i < TMAX; i++) + prhold(i, ship.shp_tend[i], ship.shp_lend[i]); pr("] , ("); - for (i = 0; i < TMAX; i++) { - if (ship.shp_tstart[i] != ' ' && ship.shp_lstart[i] != 0) { - pr("%d-", i + 1); - pr("%c", ship.shp_tstart[i]); - pr(":"); - pr("%d ", ship.shp_lstart[i]); - } - } + for (i = 0; i < TMAX; i++) + prhold(i, ship.shp_tstart[i], ship.shp_lstart[i]); pr(")"); if (ship.shp_autonav & AN_SCUTTLE) pr(" scuttling"); diff --git a/src/lib/update/nav_ship.c b/src/lib/update/nav_ship.c index 12e8477e..c12866f2 100644 --- a/src/lib/update/nav_ship.c +++ b/src/lib/update/nav_ship.c @@ -158,8 +158,7 @@ static int nav_loadship(register struct shpstr *sp, natid cnum) { struct sctstr *sectp; - s_char item; - int i, landown, shipown, level, didsomething[TMAX], rel; + int i, landown, shipown, didsomething[TMAX], rel; for (i = 0; i < TMAX; i++) didsomething[i] = 0; @@ -182,12 +181,9 @@ nav_loadship(register struct shpstr *sp, natid cnum) /* loop through each field for that ship */ for (i = 0; i < TMAX; ++i) { - item = sp->shp_tend[i]; /* commodity */ - level = sp->shp_lend[i]; /* amount */ - /* check and see if the data fields have been set. */ - if (item == ' ' || level == 0) { + if (sp->shp_tend[i] == I_NONE || sp->shp_lend[i] == 0) { /* nothing to do move on. */ didsomething[i] = 1; continue; diff --git a/src/lib/update/nav_util.c b/src/lib/update/nav_util.c index dfcbc730..0a1513b6 100644 --- a/src/lib/update/nav_util.c +++ b/src/lib/update/nav_util.c @@ -86,13 +86,13 @@ load_it(register struct shpstr *sp, register struct sctstr *psect, int i) { int comm, shipown, amount, ship_amt, sect_amt; int abs_max, max_amt, transfer; - s_char item; struct mchrstr *vship; amount = sp->shp_lend[i]; shipown = sp->shp_own; - item = sp->shp_tend[i]; /* commodity */ - comm = com_num(&item); + comm = sp->shp_tend[i]; + if (CANT_HAPPEN((unsigned)comm > I_MAX)) + return 0; ship_amt = sp->shp_item[comm]; sect_amt = psect->sct_item[comm]; @@ -161,7 +161,6 @@ void unload_it(register struct shpstr *sp) { struct sctstr *sectp; - s_char item; int i; int landowner; int shipown; @@ -169,8 +168,6 @@ unload_it(register struct shpstr *sp) int sect_amt; int ship_amt; int max_amt; - int level; - sectp = getsectp(sp->shp_x, sp->shp_y); @@ -178,17 +175,16 @@ unload_it(register struct shpstr *sp) shipown = sp->shp_own; for (i = 0; i < TMAX; ++i) { - item = sp->shp_tend[i]; - level = sp->shp_lend[i]; - - if (item == ' ' || level == 0) + if (sp->shp_tend[i] == I_NONE || sp->shp_lend[i] == 0) continue; if (landowner == 0) continue; if (sectp->sct_type != SCT_HARBR) continue; - comm = com_num(&item); + comm = sp->shp_tend[i]; + if (CANT_HAPPEN((unsigned)comm > I_MAX)) + continue; ship_amt = sp->shp_item[comm]; sect_amt = sectp->sct_item[comm]; @@ -217,30 +213,6 @@ unload_it(register struct shpstr *sp) } } -/* com_num - * This small but useful bit of code runs through the list - * of commodities and return the integer value of the - * commodity it finds if possible. - * Basicly its a hacked version of whatitem.c found in the - * /player directory. - * new autonav code. - * Chad Zabel 6/1/94 - */ - -int -com_num(s_char *ptr) -{ - struct ichrstr *ip; - - for (ip = &ichr[1]; ip->i_mnem != 0; ip++) { - if (*ptr == ip->i_mnem) - return ip->i_vtype; - } - return 0; /*NOTREACHED*/ -} - - - /* auto_fuel_ship * Assume a check for fuel=0 has already been made and passed. * Try to fill a ship using petro. and then oil.