From b1461faea57355f1fd45c66153e6d94d96fe9f8e Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 5 Mar 2004 10:38:58 +0000 Subject: [PATCH] Replace getvec() by direct, read-only item access in some cases where that's obviously correct. --- src/lib/commands/bomb.c | 8 ++---- src/lib/commands/budg.c | 8 +++--- src/lib/commands/carg.c | 44 ++++++++++++++----------------- src/lib/commands/cens.c | 10 +++---- src/lib/commands/comm.c | 22 +++++++--------- src/lib/commands/dump.c | 30 ++++++++++----------- src/lib/commands/edit.c | 56 +++++++++++++++++++--------------------- src/lib/commands/land.c | 4 +-- src/lib/commands/ldump.c | 24 ++++++++--------- src/lib/commands/nuke.c | 10 +++---- src/lib/commands/prod.c | 44 ++++++++++++++----------------- src/lib/commands/sabo.c | 12 ++++----- src/lib/commands/sdump.c | 30 ++++++++++----------- src/lib/commands/shi.c | 10 +++---- src/lib/subs/lndsub.c | 6 ++--- src/lib/subs/move.c | 13 +++++----- src/lib/subs/retreat.c | 4 +-- src/lib/subs/satmap.c | 15 ++++++----- src/lib/update/bp.c | 9 ++----- src/lib/update/plane.c | 6 +---- src/lib/update/prepare.c | 7 +---- src/lib/update/revolt.c | 10 +++---- src/lib/update/sail.c | 4 +-- 23 files changed, 164 insertions(+), 222 deletions(-) diff --git a/src/lib/commands/bomb.c b/src/lib/commands/bomb.c index f2fefd81..407b2f65 100644 --- a/src/lib/commands/bomb.c +++ b/src/lib/commands/bomb.c @@ -220,7 +220,6 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target) int type; int bad; s_char *p; - int vec[I_MAX + 1]; struct plist *plp; struct emp_qelem *qp; int bestacc; @@ -253,7 +252,6 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target) } nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list); nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0); - getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR); retry: p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ", buf); @@ -333,7 +331,7 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target) } for (i = 0; i < nbomb; i++) { - if (!vec[bombcomm[i]]) + if (!target->sct_item[bombcomm[i]]) continue; break; } @@ -425,15 +423,13 @@ comm_bomb(struct emp_qelem *list, struct sctstr *target) int i; int amt, before; struct ichrstr *ip; - int vec[I_MAX + 1]; struct emp_qelem *qp; struct sctstr sect; int dam = 0; int nukedam; - getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR); for (i = 0; i < nbomb; i++) { - if (vec[bombcomm[i]] == 0) + if (target->sct_item[bombcomm[i]] == 0) continue; if (opt_SUPER_BARS && bombcomm[i] == I_BAR) continue; diff --git a/src/lib/commands/budg.c b/src/lib/commands/budg.c index 58021320..2a5de743 100644 --- a/src/lib/commands/budg.c +++ b/src/lib/commands/budg.c @@ -326,7 +326,6 @@ calc_all(long int (*p_sect)[2], int *taxes, int *Ncivs, int *Nuws, int n, civ_tax, uw_tax, mil_pay; struct sctstr *sp; int etu = etu_per_update; - int vec[I_MAX + 1]; long tmp_money; lnd_money[player->cnum] = sea_money[player->cnum] = 0; @@ -341,14 +340,13 @@ calc_all(long int (*p_sect)[2], int *taxes, int *Ncivs, int *Nuws, if (sp->sct_own == player->cnum) { sp->sct_updated = 0; tax(sp, np, etu, &pop, &civ_tax, &uw_tax, &mil_pay); - getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); - *Ncivs += vec[I_CIVIL]; - *Nuws += vec[I_UW]; + *Ncivs += sp->sct_item[I_CIVIL]; + *Nuws += sp->sct_item[I_UW]; *taxes += civ_tax + uw_tax; *mil += mil_pay; if (sp->sct_type == SCT_BANK) { *bars += bank_income(sp, etu); - *Nbars += vec[I_BAR]; + *Nbars += sp->sct_item[I_BAR]; } } } diff --git a/src/lib/commands/carg.c b/src/lib/commands/carg.c index 0ff9d2f7..9df03043 100644 --- a/src/lib/commands/carg.c +++ b/src/lib/commands/carg.c @@ -50,7 +50,6 @@ carg(void) int nships; struct nstr_item ni; struct shpstr ship; - int vec[I_MAX + 1]; if (!snxtitem(&ni, EF_SHIP, player->argp[1])) return RET_SYN; @@ -71,17 +70,16 @@ carg(void) prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); pr(" %1c", ship.shp_fleet); pr("%4d%%", ship.shp_effic); - getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); - pr("%4d", vec[I_SHELL]); - pr("%4d", vec[I_GUN]); - pr("%4d", vec[I_PETROL]); - pr("%4d", vec[I_IRON]); - pr("%4d", vec[I_DUST]); - pr("%4d", vec[I_BAR]); - pr("%4d", vec[I_OIL]); - pr("%4d", vec[I_LCM]); - pr("%4d", vec[I_HCM]); - pr("%4d\n", vec[I_RAD]); + pr("%4d", ship.shp_item[I_SHELL]); + pr("%4d", ship.shp_item[I_GUN]); + pr("%4d", ship.shp_item[I_PETROL]); + pr("%4d", ship.shp_item[I_IRON]); + pr("%4d", ship.shp_item[I_DUST]); + pr("%4d", ship.shp_item[I_BAR]); + pr("%4d", ship.shp_item[I_OIL]); + pr("%4d", ship.shp_item[I_LCM]); + pr("%4d", ship.shp_item[I_HCM]); + pr("%4d\n", ship.shp_item[I_RAD]); if (opt_SHIPNAMES) { if (ship.shp_name[0] != 0) { pr(" %s\n", ship.shp_name); @@ -105,7 +103,6 @@ lcarg(void) int nunits; struct nstr_item ni; struct lndstr land; - int vec[I_MAX + 1]; if (!snxtitem(&ni, EF_LAND, player->argp[1])) return RET_SYN; @@ -126,17 +123,16 @@ lcarg(void) prxy("%4d,%-4d ", land.lnd_x, land.lnd_y, player->cnum); pr(" %1c", land.lnd_army); pr("%4d%%", land.lnd_effic); - getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); - pr("%4d", vec[I_SHELL]); - pr("%4d", vec[I_GUN]); - pr("%4d", vec[I_PETROL]); - pr("%4d", vec[I_IRON]); - pr("%4d", vec[I_DUST]); - pr("%4d", vec[I_BAR]); - pr("%4d", vec[I_OIL]); - pr("%4d", vec[I_LCM]); - pr("%4d", vec[I_HCM]); - pr("%4d\n", vec[I_RAD]); + pr("%4d", land.lnd_item[I_SHELL]); + pr("%4d", land.lnd_item[I_GUN]); + pr("%4d", land.lnd_item[I_PETROL]); + pr("%4d", land.lnd_item[I_IRON]); + pr("%4d", land.lnd_item[I_DUST]); + pr("%4d", land.lnd_item[I_BAR]); + pr("%4d", land.lnd_item[I_OIL]); + pr("%4d", land.lnd_item[I_LCM]); + pr("%4d", land.lnd_item[I_HCM]); + pr("%4d\n", land.lnd_item[I_RAD]); } if (nunits == 0) { if (player->argp[1]) diff --git a/src/lib/commands/cens.c b/src/lib/commands/cens.c index 83e7b307..a46e1bb8 100644 --- a/src/lib/commands/cens.c +++ b/src/lib/commands/cens.c @@ -54,7 +54,6 @@ cens(void) int n; struct nstr_sect nstr; s_char dirstr[20]; - int vec[I_MAX + 1]; if (!snxtsct(&nstr, player->argp[1])) return RET_SYN; @@ -94,11 +93,10 @@ cens(void) pr("%c ", n == 0 ? '.' : '0' + (n / 100)); pr("%c", sect.sct_own != sect.sct_oldown ? '*' : ' '); - getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); - pr("%5d", vec[I_CIVIL]); - pr("%5d", vec[I_MILIT]); - pr("%5d", vec[I_UW]); - pr("%5d", vec[I_FOOD]); + pr("%5d", sect.sct_item[I_CIVIL]); + pr("%5d", sect.sct_item[I_MILIT]); + pr("%5d", sect.sct_item[I_UW]); + pr("%5d", sect.sct_item[I_FOOD]); pr("%4d%%", sect.sct_work); pr("%5d", sect.sct_avail); if (!player->god) { diff --git a/src/lib/commands/comm.c b/src/lib/commands/comm.c index aabfd5c2..2a544521 100644 --- a/src/lib/commands/comm.c +++ b/src/lib/commands/comm.c @@ -52,7 +52,6 @@ comm(void) int nsect; int n; struct nstr_sect nstr; - int item[I_MAX + 1]; if (!snxtsct(&nstr, player->argp[1])) return RET_SYN; @@ -75,7 +74,6 @@ comm(void) } if (player->god) pr("%3d", sect.sct_own); - getvec(VT_ITEM, item, (s_char *)§, EF_SECTOR); prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); pr(" %c", dchr[sect.sct_type].d_mnem); pr(" %c", dirstr[sect.sct_del[I_SHELL] & 0x7]); @@ -98,16 +96,16 @@ comm(void) prthresh("%c", sect.sct_dist[I_LCM]); prthresh("%c", sect.sct_dist[I_HCM]); prthresh("%c", sect.sct_dist[I_RAD]); - pr("%4d", item[I_SHELL]); - pr("%4d", item[I_GUN]); - pr("%5d", item[I_PETROL]); - pr("%5d", item[I_IRON]); - pr("%5d", item[I_DUST]); - pr("%4d", item[I_BAR]); - pr("%5d", item[I_OIL]); - pr("%5d", item[I_LCM]); - pr("%5d", item[I_HCM]); - pr("%4d", item[I_RAD]); + pr("%4d", sect.sct_item[I_SHELL]); + pr("%4d", sect.sct_item[I_GUN]); + pr("%5d", sect.sct_item[I_PETROL]); + pr("%5d", sect.sct_item[I_IRON]); + pr("%5d", sect.sct_item[I_DUST]); + pr("%4d", sect.sct_item[I_BAR]); + pr("%5d", sect.sct_item[I_OIL]); + pr("%5d", sect.sct_item[I_LCM]); + pr("%5d", sect.sct_item[I_HCM]); + pr("%4d", sect.sct_item[I_RAD]); pr("\n"); } if (nsect == 0) { diff --git a/src/lib/commands/dump.c b/src/lib/commands/dump.c index d84f3fa2..3f981349 100644 --- a/src/lib/commands/dump.c +++ b/src/lib/commands/dump.c @@ -52,7 +52,6 @@ dump(void) int nsect; int n, i; struct nstr_sect nstr; - int item[I_MAX + 1]; int field[128]; struct natstr *np; time_t now; @@ -510,7 +509,6 @@ dump(void) /* census */ if (player->god) pr("%d ", sect.sct_own); - getvec(VT_ITEM, item, (s_char *)§, EF_SECTOR); pr("%d %d", xrel(np, nstr.x), yrel(np, nstr.y)); set_coastal(§); @@ -564,47 +562,47 @@ dump(void) pr("%d", sect.sct_terr); break; case 15: - pr("%d", item[I_CIVIL]); + pr("%d", sect.sct_item[I_CIVIL]); break; case 16: - pr("%d", item[I_MILIT]); + pr("%d", sect.sct_item[I_MILIT]); break; case 17: - pr("%d", item[I_UW]); + pr("%d", sect.sct_item[I_UW]); break; case 18: - pr("%d", item[I_FOOD]); + pr("%d", sect.sct_item[I_FOOD]); break; /* commodity */ case 19: - pr("%d", item[I_SHELL]); + pr("%d", sect.sct_item[I_SHELL]); break; case 20: - pr("%d", item[I_GUN]); + pr("%d", sect.sct_item[I_GUN]); break; case 21: - pr("%d", item[I_PETROL]); + pr("%d", sect.sct_item[I_PETROL]); break; case 22: - pr("%d", item[I_IRON]); + pr("%d", sect.sct_item[I_IRON]); break; case 23: - pr("%d", item[I_DUST]); + pr("%d", sect.sct_item[I_DUST]); break; case 24: - pr("%d", item[I_BAR]); + pr("%d", sect.sct_item[I_BAR]); break; case 25: - pr("%d", item[I_OIL]); + pr("%d", sect.sct_item[I_OIL]); break; case 26: - pr("%d", item[I_LCM]); + pr("%d", sect.sct_item[I_LCM]); break; case 27: - pr("%d", item[I_HCM]); + pr("%d", sect.sct_item[I_HCM]); break; case 28: - pr("%d", item[I_RAD]); + pr("%d", sect.sct_item[I_RAD]); break; /* cutoff */ case 29: diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index c5064ac8..80ac29f3 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -363,7 +363,6 @@ pr_plane(struct plnstr *plane) static void pr_land(struct lndstr *land) { - int vec[I_MAX + 1]; struct lchrstr *lcp; lcp = &lchr[(int)land->lnd_type]; @@ -386,29 +385,27 @@ pr_land(struct lndstr *land) pr("Retreat percentage : %d\n", (int)land->lnd_retreat); pr("Retreat path : '%s'\t\tRetreat Flags : %d\n", land->lnd_rpath, (int)land->lnd_rflags); - getvec(VT_ITEM, vec, (s_char *)land, EF_LAND); pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n"); pr(" c m u f s g p i d o l h r\n"); - pr("%3d", vec[I_CIVIL]); - pr("%4d", vec[I_MILIT]); - pr("%4d", vec[I_UW]); - pr("%5d", vec[I_FOOD]); - pr("%4d", vec[I_SHELL]); - pr("%4d", vec[I_GUN]); - pr("%5d", vec[I_PETROL]); - pr("%5d", vec[I_IRON]); - pr("%5d", vec[I_DUST]); - pr("%5d", vec[I_OIL]); - pr("%5d", vec[I_LCM]); - pr("%5d", vec[I_HCM]); - pr("%4d", vec[I_RAD]); + pr("%3d", land->lnd_item[I_CIVIL]); + pr("%4d", land->lnd_item[I_MILIT]); + pr("%4d", land->lnd_item[I_UW]); + pr("%5d", land->lnd_item[I_FOOD]); + pr("%4d", land->lnd_item[I_SHELL]); + pr("%4d", land->lnd_item[I_GUN]); + pr("%5d", land->lnd_item[I_PETROL]); + pr("%5d", land->lnd_item[I_IRON]); + pr("%5d", land->lnd_item[I_DUST]); + pr("%5d", land->lnd_item[I_OIL]); + pr("%5d", land->lnd_item[I_LCM]); + pr("%5d", land->lnd_item[I_HCM]); + pr("%4d", land->lnd_item[I_RAD]); pr("\n"); } static void pr_ship(struct shpstr *ship) { - int vec[I_MAX + 1]; struct natstr *natp; if ((natp = getnatp(ship->shp_own)) == 0) @@ -432,24 +429,23 @@ pr_ship(struct shpstr *ship) pr("Fuel : %d\n", (int)ship->shp_fuel); pr("Retreat path : '%s'\t\tRetreat Flags : %d\n", ship->shp_rpath, (int)ship->shp_rflags); - getvec(VT_ITEM, vec, (s_char *)ship, EF_SHIP); pr("Plague Stage : %d\n", ship->shp_pstage); pr("Plague Time : %d\n", ship->shp_ptime); pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n"); pr(" c m u f s g p i d o l h r\n"); - pr("%3d", vec[I_CIVIL]); - pr("%4d", vec[I_MILIT]); - pr("%4d", vec[I_UW]); - pr("%5d", vec[I_FOOD]); - pr("%4d", vec[I_SHELL]); - pr("%4d", vec[I_GUN]); - pr("%5d", vec[I_PETROL]); - pr("%5d", vec[I_IRON]); - pr("%5d", vec[I_DUST]); - pr("%5d", vec[I_OIL]); - pr("%5d", vec[I_LCM]); - pr("%5d", vec[I_HCM]); - pr("%4d", vec[I_RAD]); + pr("%3d", ship->shp_item[I_CIVIL]); + pr("%4d", ship->shp_item[I_MILIT]); + pr("%4d", ship->shp_item[I_UW]); + pr("%5d", ship->shp_item[I_FOOD]); + pr("%4d", ship->shp_item[I_SHELL]); + pr("%4d", ship->shp_item[I_GUN]); + pr("%5d", ship->shp_item[I_PETROL]); + pr("%5d", ship->shp_item[I_IRON]); + pr("%5d", ship->shp_item[I_DUST]); + pr("%5d", ship->shp_item[I_OIL]); + pr("%5d", ship->shp_item[I_LCM]); + pr("%5d", ship->shp_item[I_HCM]); + pr("%4d", ship->shp_item[I_RAD]); pr("\n"); } diff --git a/src/lib/commands/land.c b/src/lib/commands/land.c index c21279f7..db4309eb 100644 --- a/src/lib/commands/land.c +++ b/src/lib/commands/land.c @@ -49,7 +49,6 @@ land(void) int nunits; struct nstr_item ni; struct lndstr land; - int vec[I_MAX + 1]; if (!snxtitem(&ni, EF_LAND, player->argp[1])) return RET_SYN; @@ -88,8 +87,7 @@ land(void) pr("%4d", lnd_getmil(&land)); pr("%4d", land.lnd_harden); pr("%4d", land.lnd_mobil); - getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); - pr("%4d", vec[I_FOOD]); + pr("%4d", land.lnd_item[I_FOOD]); if (opt_FUEL) pr("%3d", land.lnd_fuel); pr("%4d ", land.lnd_tech); diff --git a/src/lib/commands/ldump.c b/src/lib/commands/ldump.c index 0a9b793f..fbd6cb32 100644 --- a/src/lib/commands/ldump.c +++ b/src/lib/commands/ldump.c @@ -51,7 +51,6 @@ ldump(void) int field[128]; struct nstr_item ni; struct lndstr land; - int vec[I_MAX + 1]; int n, i; struct natstr *np; time_t now; @@ -308,7 +307,6 @@ ldump(void) pr("%3d ", land.lnd_own); pr("%d", ni.cur); n = 0; - getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); while (field[n]) { switch (field[n++]) { case 1: @@ -339,7 +337,7 @@ ldump(void) pr(" %d", land.lnd_mobil); break; case 9: - pr(" %d", vec[I_FOOD]); + pr(" %d", land.lnd_item[I_FOOD]); break; case 10: if (opt_FUEL) @@ -369,34 +367,34 @@ ldump(void) pr(" %d", land.lnd_ship); break; case 18: - pr(" %d", vec[I_SHELL]); + pr(" %d", land.lnd_item[I_SHELL]); break; case 19: - pr(" %d", vec[I_GUN]); + pr(" %d", land.lnd_item[I_GUN]); break; case 20: - pr(" %d", vec[I_PETROL]); + pr(" %d", land.lnd_item[I_PETROL]); break; case 21: - pr(" %d", vec[I_IRON]); + pr(" %d", land.lnd_item[I_IRON]); break; case 22: - pr(" %d", vec[I_DUST]); + pr(" %d", land.lnd_item[I_DUST]); break; case 23: - pr(" %d", vec[I_BAR]); + pr(" %d", land.lnd_item[I_BAR]); break; case 24: - pr(" %d", vec[I_OIL]); + pr(" %d", land.lnd_item[I_OIL]); break; case 25: - pr(" %d", vec[I_LCM]); + pr(" %d", land.lnd_item[I_LCM]); break; case 26: - pr(" %d", vec[I_HCM]); + pr(" %d", land.lnd_item[I_HCM]); break; case 27: - pr(" %d", vec[I_RAD]); + pr(" %d", land.lnd_item[I_RAD]); break; case 28: pr(" %1.2f", (float)land.lnd_att); diff --git a/src/lib/commands/nuke.c b/src/lib/commands/nuke.c index bc619b97..5b5b0026 100644 --- a/src/lib/commands/nuke.c +++ b/src/lib/commands/nuke.c @@ -52,7 +52,6 @@ nuke(void) struct nstr_item nstr; struct nukstr nuk; struct sctstr sect; - int item[I_MAX + 1]; if (!snxtitem(&nstr, EF_NUKE, player->argp[1])) return RET_SYN; @@ -68,7 +67,6 @@ nuke(void) pr(" sect eff num nuke-type lcm hcm oil rad avail\n"); } getsect(nuk.nuk_x, nuk.nuk_y, §); - getvec(VT_ITEM, item, (s_char *)§, EF_SECTOR); first_nuke = 1; show_comm = 0; if (sect.sct_type == SCT_NUKE && sect.sct_effic >= 60) @@ -94,10 +92,10 @@ nuke(void) pr("%-16.16s ", nchr[i].n_name); if (show_comm) { - pr("%5d ", item[I_LCM]); - pr("%5d ", item[I_HCM]); - pr("%5d ", item[I_OIL]); - pr("%5d ", item[I_RAD]); + pr("%5d ", sect.sct_item[I_LCM]); + pr("%5d ", sect.sct_item[I_HCM]); + pr("%5d ", sect.sct_item[I_OIL]); + pr("%5d ", sect.sct_item[I_RAD]); pr("%5d", sect.sct_avail); show_comm = 0; } diff --git a/src/lib/commands/prod.c b/src/lib/commands/prod.c index 6b78a7d5..397a0f28 100644 --- a/src/lib/commands/prod.c +++ b/src/lib/commands/prod.c @@ -51,16 +51,13 @@ count_pop(register int n) register int i; register int pop = 0; struct sctstr *sp; - int vec[I_MAX + 1]; for (i = 0; NULL != (sp = getsectid(i)); i++) { if (sp->sct_own != n) continue; if (sp->sct_oldown != n) continue; - if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) - continue; - pop += vec[I_CIVIL]; + pop += sp->sct_item[I_CIVIL]; } return pop; } @@ -99,8 +96,7 @@ prod(void) int c; s_char maxc[3][10]; s_char use[3][10]; - int items[I_MAX + 1]; - int vec[I_MAX + 1], lcms, hcms; + int lcms, hcms; int civs = 0; int uws = 0; int bwork; @@ -118,12 +114,11 @@ prod(void) while (nxtsct(&nstr, §)) { if (!player->owner) continue; - getvec(VT_ITEM, items, (s_char *)§, EF_SECTOR); - civs = min(9999, (int)((obrate * (double)etu_per_update + 1.0) - * (double)items[I_CIVIL])); - uws = min(9999, (int)((uwbrate * (double)etu_per_update + 1.0) - * (double)items[I_UW])); + civs = min(9999, (int)((obrate * etu_per_update + 1.0) + * sect.sct_item[I_CIVIL])); + uws = min(9999, (int)((uwbrate * etu_per_update + 1.0) + * sect.sct_item[I_UW])); if (opt_RES_POP) { natp = getnatp(sect.sct_own); maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §); @@ -136,9 +131,9 @@ prod(void) /* This isn't quite right, since research might rise/fall */ /* during the update, but it's the best we can really do */ - wforce = (int)(((double)civs * (double)sect.sct_work) - / 100.0 + (double)uws + - (double)items[I_MILIT] * 2.0 / 5.0); + wforce = (int)(((double)civs * sect.sct_work) / 100.0 + + uws + + sect.sct_item[I_MILIT] * 2.0 / 5.0); work = (double)etu_per_update *(double)wforce / 100.0; if (opt_ROLLOVER_AVAIL) { if (sect.sct_type == sect.sct_newtype) { @@ -179,9 +174,9 @@ prod(void) civs = min(9999, civs); uws = min(9999, uws); } - wforce = - (int)((civs * sect.sct_work) / 100.0 + uws + - items[I_MILIT] * 2 / 5.0); + wforce = (int)(((double)civs * sect.sct_work) / 100.0 + + uws + + sect.sct_item[I_MILIT] * 2 / 5.0); work = etu_per_update * wforce / 100.0; bwork = min((int)(work / 2), bwork); } @@ -190,15 +185,14 @@ prod(void) if (twork > bwork) { twork = bwork; } - getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); if (dchr[type].d_lcms > 0) { - lcms = vec[I_LCM]; + lcms = sect.sct_item[I_LCM]; lcms /= dchr[type].d_lcms; if (twork > lcms) twork = lcms; } if (dchr[type].d_hcms > 0) { - hcms = vec[I_HCM]; + hcms = sect.sct_item[I_HCM]; hcms /= dchr[type].d_hcms; if (twork > hcms) twork = hcms; @@ -378,8 +372,8 @@ prod(void) int enlisted; int civs; - civs = min(999, (int)((obrate * (double)etu_per_update + 1.0) - * (double)items[I_CIVIL])); + civs = min(999, (int)((obrate * etu_per_update + 1.0) + * sect.sct_item[I_CIVIL])); natp = getnatp(sect.sct_own); maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §); civs = min(civs, maxpop); @@ -387,9 +381,11 @@ prod(void) rise/fall during the update, but it's the best we can really do */ enlisted = 0; - maxmil = (civs / 2) - items[I_MILIT]; + maxmil = (civs / 2) - sect.sct_item[I_MILIT]; if (maxmil > 0) { - enlisted = (etu_per_update * (10 + items[I_MILIT]) * 0.05); + enlisted = (etu_per_update + * (10 + sect.sct_item[I_MILIT]) + * 0.05); if (enlisted > maxmil) enlisted = maxmil; } diff --git a/src/lib/commands/sabo.c b/src/lib/commands/sabo.c index 1a9f1895..da11654f 100644 --- a/src/lib/commands/sabo.c +++ b/src/lib/commands/sabo.c @@ -44,7 +44,6 @@ sabo(void) struct lndstr land; struct sctstr sect; double odds; - int vec[I_MAX + 1]; int dam; if (!snxtitem(&ni, EF_LAND, player->argp[1])) @@ -85,12 +84,13 @@ sabo(void) continue; } - getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); dam = landgun(3 * land.lnd_effic, 7); - if (vec[I_SHELL] > 20) - dam += seagun(land.lnd_effic, random() % (vec[I_SHELL] / 10)); - if (vec[I_PETROL] > 100) - dam += seagun(land.lnd_effic, random() % (vec[I_PETROL] / 50)); + if (sect.sct_item[I_SHELL] > 20) + dam += seagun(land.lnd_effic, + random() % (sect.sct_item[I_SHELL] / 10)); + if (sect.sct_item[I_PETROL] > 100) + dam += seagun(land.lnd_effic, + random() % (sect.sct_item[I_PETROL] / 50)); pr("Explosion in %s causes %d damage.\n", xyas(land.lnd_x, land.lnd_y, land.lnd_own), dam); diff --git a/src/lib/commands/sdump.c b/src/lib/commands/sdump.c index 3de18b0f..ed17fa49 100644 --- a/src/lib/commands/sdump.c +++ b/src/lib/commands/sdump.c @@ -50,7 +50,6 @@ sdump(void) int nships; struct nstr_item ni; struct shpstr ship; - int vec[I_MAX + 1]; int field[128]; struct natstr *np; int n, i; @@ -280,7 +279,6 @@ sdump(void) pr("%3d ", ship.shp_own); pr("%d", ni.cur); n = 0; - getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); while (field[n]) { switch (field[n++]) { case 1: @@ -302,16 +300,16 @@ sdump(void) pr(" %d", ship.shp_effic); break; case 6: - pr(" %d", vec[I_CIVIL]); + pr(" %d", ship.shp_item[I_CIVIL]); break; case 7: - pr(" %d", vec[I_MILIT]); + pr(" %d", ship.shp_item[I_MILIT]); break; case 8: - pr(" %d", vec[I_UW]); + pr(" %d", ship.shp_item[I_UW]); break; case 9: - pr(" %d", vec[I_FOOD]); + pr(" %d", ship.shp_item[I_FOOD]); break; case 10: pr(" %d", ship.shp_nplane); @@ -338,34 +336,34 @@ sdump(void) pr(" %d", ship.shp_tech); break; case 17: - pr(" %d", vec[I_SHELL]); + pr(" %d", ship.shp_item[I_SHELL]); break; case 18: - pr(" %d", vec[I_GUN]); + pr(" %d", ship.shp_item[I_GUN]); break; case 19: - pr(" %d", vec[I_PETROL]); + pr(" %d", ship.shp_item[I_PETROL]); break; case 20: - pr(" %d", vec[I_IRON]); + pr(" %d", ship.shp_item[I_IRON]); break; case 21: - pr(" %d", vec[I_DUST]); + pr(" %d", ship.shp_item[I_DUST]); break; case 22: - pr(" %d", vec[I_BAR]); + pr(" %d", ship.shp_item[I_BAR]); break; case 23: - pr(" %d", vec[I_OIL]); + pr(" %d", ship.shp_item[I_OIL]); break; case 24: - pr(" %d", vec[I_LCM]); + pr(" %d", ship.shp_item[I_LCM]); break; case 25: - pr(" %d", vec[I_HCM]); + pr(" %d", ship.shp_item[I_HCM]); break; case 26: - pr(" %d", vec[I_RAD]); + pr(" %d", ship.shp_item[I_RAD]); break; case 27: pr(" %d", ship.shp_armor); diff --git a/src/lib/commands/shi.c b/src/lib/commands/shi.c index 6c8a6fef..f83f34f9 100644 --- a/src/lib/commands/shi.c +++ b/src/lib/commands/shi.c @@ -50,7 +50,6 @@ shi(void) int nships; struct nstr_item ni; struct shpstr ship; - int vec[I_MAX + 1]; if (!snxtitem(&ni, EF_SHIP, player->argp[1])) return RET_SYN; @@ -85,11 +84,10 @@ shi(void) pr("%1c", ship.shp_fleet); pr("%4d%%", ship.shp_effic); - getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); - pr("%4d", vec[I_CIVIL]); - pr("%4d", vec[I_MILIT]); - pr("%4d", vec[I_UW]); - pr("%4d", vec[I_FOOD]); + pr("%4d", ship.shp_item[I_CIVIL]); + pr("%4d", ship.shp_item[I_MILIT]); + pr("%4d", ship.shp_item[I_UW]); + pr("%4d", ship.shp_item[I_FOOD]); pr("%3d", ship.shp_nplane); pr("%3d", ship.shp_nchoppers); diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index 221286f2..7e551236 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -785,7 +785,6 @@ lnd_list(struct emp_qelem *land_list) struct emp_qelem *next; struct llist *llp; struct lndstr *lnd; - int vec[I_MAX + 1]; pr("lnd# land type x,y a eff sh gun xl mu tech retr fuel\n"); @@ -798,9 +797,8 @@ lnd_list(struct emp_qelem *land_list) prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own); pr("%1c", lnd->lnd_army); pr("%4d%%", lnd->lnd_effic); - getvec(VT_ITEM, vec, (s_char *)lnd, EF_LAND); - pr("%4d", vec[I_SHELL]); - pr("%4d", vec[I_GUN]); + pr("%4d", lnd->lnd_item[I_SHELL]); + pr("%4d", lnd->lnd_item[I_GUN]); count_land_planes(lnd); pr("%3d", lnd->lnd_nxlight); pr("%4d", lnd->lnd_mobil); diff --git a/src/lib/subs/move.c b/src/lib/subs/move.c index aebc72ef..7843710f 100644 --- a/src/lib/subs/move.c +++ b/src/lib/subs/move.c @@ -55,7 +55,6 @@ move_ground(s_char *what, struct sctstr *start, struct sctstr *end, { struct sctstr sect, ending_sect; struct sctstr next, dsect; - int vec[I_MAX + 1]; coord curx, cury, oldx, oldy; coord tmpx, tmpy; coord dx, dy; @@ -191,9 +190,10 @@ move_ground(s_char *what, struct sctstr *start, struct sctstr *end, *movstr = 0; continue; } - getvec(VT_ITEM, vec, (s_char *)&next, EF_SECTOR); sect_mcost = sector_mcost(&next, MOB_ROAD); - if ((!player->owner && (!exploring || vec[I_MILIT] || vec[I_CIVIL])) + if ((!player->owner && (!exploring + || next.sct_item[I_MILIT] + || next.sct_item[I_CIVIL])) || sect_mcost == -1.0) { /* already-owned, or prohibited terrain */ pr("You can't go there...\n"); @@ -258,7 +258,6 @@ move_map(s_char *what, coord curx, coord cury, s_char *arg) s_char range[128]; s_char view[7]; int i; - int vec[I_MAX + 1]; int changed = 0; np = getnatp(player->cnum); @@ -295,13 +294,13 @@ move_map(s_char *what, coord curx, coord cury, s_char *arg) writemap(player->cnum); if (!getsect(curx, cury, §)) return RET_FAIL; - getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); pr(" %c %c eff mob civ mil uw food work avail\n", view[0], view[1]); pr(" %c %c %c %3d %3d %4d %4d %4d %4d %3d %3d\n", view[2], view[3], view[4], - sect.sct_effic, sect.sct_mobil, vec[I_CIVIL], vec[I_MILIT], - vec[I_UW], vec[I_FOOD], sect.sct_work, sect.sct_avail); + sect.sct_effic, sect.sct_mobil, + sect.sct_item[I_CIVIL], sect.sct_item[I_MILIT], sect.sct_item[I_UW], + sect.sct_item[I_FOOD], sect.sct_work, sect.sct_avail); pr(" %c %c\n", view[5], view[6]); return RET_OK; } diff --git a/src/lib/subs/retreat.c b/src/lib/subs/retreat.c index 5ccf57d0..8818f484 100644 --- a/src/lib/subs/retreat.c +++ b/src/lib/subs/retreat.c @@ -146,7 +146,6 @@ retreat_ship1(struct shpstr *sp, s_char code, int orig) int shells; double mobcost; struct mchrstr *mcp; - int vec[I_MAX + 1]; int time_to_stop; sp->shp_mission = 0; @@ -178,8 +177,7 @@ retreat_ship1(struct shpstr *sp, s_char code, int orig) } } /* check crew - uws don't count */ - getvec(VT_ITEM, vec, (s_char *)sp, EF_SHIP); - if (vec[I_MILIT] == 0 && vec[I_CIVIL] == 0) { + if (sp->shp_item[I_MILIT] == 0 && sp->shp_item[I_CIVIL] == 0) { wu(0, sp->shp_own, "%s %s,\nbut had no crew, and couldn't retreat!\n", prship(sp), conditions[findcondition(code)].desc[orig]); diff --git a/src/lib/subs/satmap.c b/src/lib/subs/satmap.c index 2112b51f..107e97ee 100644 --- a/src/lib/subs/satmap.c +++ b/src/lib/subs/satmap.c @@ -283,13 +283,11 @@ sathead(void) void satdisp(struct sctstr *sp, int acc, int showstuff) { - int vec[I_MAX + 1], first; + int first; struct nstr_item ni; struct shpstr ship; struct lndstr land; - if (getvec(VT_ITEM, vec, (caddr_t)sp, EF_SECTOR) < 0) - return; prxy("%4d,%-4d ", sp->sct_x, sp->sct_y, player->cnum); pr("%c %3d %3d %3d %3d %3d %4d %4d %4d %4d %4d %4d %5d\n", dchr[sp->sct_type].d_mnem, @@ -297,10 +295,13 @@ satdisp(struct sctstr *sp, int acc, int showstuff) roundintby((int)sp->sct_road, acc / 2), roundintby((int)sp->sct_rail, acc / 2), roundintby((int)sp->sct_defense, acc / 2), - roundintby(vec[I_CIVIL], acc), roundintby(vec[I_MILIT], acc), - roundintby(vec[I_SHELL], acc), roundintby(vec[I_GUN], acc), - roundintby(vec[I_IRON], acc), roundintby(vec[I_PETROL], acc), - roundintby(vec[I_FOOD], acc)); + roundintby(sp->sct_item[I_CIVIL], acc), + roundintby(sp->sct_item[I_MILIT], acc), + roundintby(sp->sct_item[I_SHELL], acc), + roundintby(sp->sct_item[I_GUN], acc), + roundintby(sp->sct_item[I_IRON], acc), + roundintby(sp->sct_item[I_PETROL], acc), + roundintby(sp->sct_item[I_FOOD], acc)); map_set(player->cnum, sp->sct_x, sp->sct_y, dchr[sp->sct_type].d_mnem, 0); if (!showstuff) diff --git a/src/lib/update/bp.c b/src/lib/update/bp.c index 8c03bdc9..2b376a3c 100644 --- a/src/lib/update/bp.c +++ b/src/lib/update/bp.c @@ -56,11 +56,9 @@ gt_bg_nmbr(int *bp, struct sctstr *sp, int comm) { int *wp; int cm; - int svec[I_MAX + 1]; if ((cm = bud_key[comm]) == 0) { - getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); - return svec[comm]; + return sp->sct_item[comm]; } else { wp = get_wp(bp, sp, cm); return *wp; @@ -82,16 +80,13 @@ pt_bg_nmbr(int *bp, struct sctstr *sp, int comm, int amount) void fill_update_array(int *bp, struct sctstr *sp) { - int vec[I_MAX + 1]; int i, k; int *wp; - if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) - return; for (i = 1; i <= I_MAX; i++) if ((k = bud_key[i]) != 0) { wp = get_wp(bp, sp, k); - *wp = vec[i]; + *wp = sp->sct_item[i]; } wp = get_wp(bp, sp, bud_key[I_MAX + 1]); *wp = sp->sct_avail; diff --git a/src/lib/update/plane.c b/src/lib/update/plane.c index 4a547978..8fb773d3 100644 --- a/src/lib/update/plane.c +++ b/src/lib/update/plane.c @@ -66,7 +66,6 @@ prod_plane(int etus, int natnum, int *bp, int buildem) int left, build; int lcm_needed, hcm_needed; int mil_needed; - int svec[I_MAX + 1]; int mvec[I_MAX + 1]; int n, k = 0; struct shpstr *shp; @@ -126,7 +125,6 @@ prod_plane(int etus, int natnum, int *bp, int buildem) np = getnatp(pp->pln_own); desc = &plchr[(int)pp->pln_type]; sp = getsectp(pp->pln_x, pp->pln_y); - getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); mult = 1; if (np->nat_level[NAT_TLEV] < pp->pln_tech * 0.85) mult = 2; @@ -178,10 +176,8 @@ prod_plane(int etus, int natnum, int *bp, int buildem) avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100; if (pp->pln_ship >= 0) { - int vec[I_MAX + 1]; shp = getshipp(pp->pln_ship); - getvec(VT_ITEM, vec, (s_char *)shp, EF_SHIP); - avail += (etus * vec[I_MILIT] / 2); + avail += (etus * shp->shp_item[I_MILIT] / 2); } w_p_eff = 20 + (desc->pl_lcm + 2 * desc->pl_hcm); delta = roundavg((double)avail / w_p_eff); diff --git a/src/lib/update/prepare.c b/src/lib/update/prepare.c index c18621d6..07b08a75 100644 --- a/src/lib/update/prepare.c +++ b/src/lib/update/prepare.c @@ -170,10 +170,5 @@ upd_slmilcosts(natid n, int etu) int bank_income(struct sctstr *sp, int etu) { - int vec[I_MAX + 1]; - - if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) - return 0; - else - return (int)(vec[I_BAR] * etu * bankint * sp->sct_effic / 100); + return (int)(sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100); } diff --git a/src/lib/update/revolt.c b/src/lib/update/revolt.c index e6f27d82..13da78b9 100644 --- a/src/lib/update/revolt.c +++ b/src/lib/update/revolt.c @@ -148,7 +148,6 @@ guerrilla(struct sctstr *sp) int convert; natid actor; natid victim; - int vec[I_MAX + 1]; int tmp; int min_mil; int val; @@ -162,16 +161,13 @@ guerrilla(struct sctstr *sp) move = 0; if (!sp->sct_che) return; - if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) - return; - civ = vec[I_CIVIL]; - - uw = vec[I_UW]; + civ = sp->sct_item[I_CIVIL]; + uw = sp->sct_item[I_UW]; victim = sp->sct_own; actor = sp->sct_oldown; che = sp->sct_che; + mil = sp->sct_item[I_MILIT]; - mil = vec[I_MILIT]; snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) { diff --git a/src/lib/update/sail.c b/src/lib/update/sail.c index bd0613cc..46811081 100644 --- a/src/lib/update/sail.c +++ b/src/lib/update/sail.c @@ -211,7 +211,6 @@ sail_nav_fleet(struct fltheadstr *fltp) { struct fltelemstr *fe; struct shpstr *sp, ship; - int vec[I_MAX + 1]; struct sctstr *sectp; int error = 0; s_char *s, *p; @@ -253,8 +252,7 @@ sail_nav_fleet(struct fltheadstr *fltp) } for (fe = fltp->head; fe; fe = fe->next) { sp = getshipp(fe->num); - getvec(VT_ITEM, vec, (s_char *)sp, EF_SHIP); - if (vec[I_MILIT] == 0 && vec[I_CIVIL] == 0) { + if (sp->shp_item[I_MILIT] == 0 && sp->shp_item[I_CIVIL] == 0) { wu(0, fltp->own, " ship #%d (%s) is crewless and can't go on\n", fe->num, cname(fe->own));