From: Markus Armbruster Date: Fri, 5 Mar 2004 12:05:33 +0000 (+0000) Subject: Replace getvec() by direct, read-only item access in some cases where X-Git-Tag: v4.2.14~75 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=7d7945c3e9f0362343ca5a92c3e8f64bfb166001 Replace getvec() by direct, read-only item access in some cases where that's obviously correct. --- diff --git a/src/lib/commands/new.c b/src/lib/commands/new.c index 3db60ece6..6835ce488 100644 --- a/src/lib/commands/new.c +++ b/src/lib/commands/new.c @@ -306,7 +306,6 @@ deity_build_land(int type, coord x, coord y, natid own, int tlev) struct lchrstr *lp; struct nstr_item nstr; struct natstr *natp; - int lvec[I_MAX + 1]; int extend = 1; natp = getnatp(own); @@ -363,12 +362,7 @@ deity_build_land(int type, coord x, coord y, natid own, int tlev) land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, tlev - lp->l_tech); land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech); land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech); - - getvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND); - lvec[I_FOOD] += - vl_find(V_FOOD, lp->l_vtype, lp->l_vamt, (int)lp->l_nv); - lvec[I_MILIT] = lp->l_mil; - putvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND); + land.lnd_item[I_FOOD] = vl_find(V_FOOD, lp->l_vtype, lp->l_vamt, lp->l_nv); putland(land.lnd_uid, &land); makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, diff --git a/src/lib/commands/newe.c b/src/lib/commands/newe.c index f9e1c6634..a13735f71 100644 --- a/src/lib/commands/newe.c +++ b/src/lib/commands/newe.c @@ -51,7 +51,6 @@ newe(void) struct sctstr sect; struct nstr_sect nstr; double work, wforce, lcms, hcms; - int items[I_MAX + 1]; int nsect; int civs = 0; int uws = 0; @@ -70,12 +69,10 @@ newe(void) if (!player->owner) continue; if (!sect.sct_off) { - getvec(VT_ITEM, items, (s_char *)§, EF_SECTOR); - - civs = min(999, (int)((obrate * (double)etu_per_update + 1.0) - * (double)items[I_CIVIL])); - uws = min(999, (int)((uwbrate * (double)etu_per_update + 1.0) - * (double)items[I_UW])); + civs = min(999, (int)((obrate * etu_per_update + 1.0) + * sect.sct_item[I_CIVIL])); + uws = min(999, (int)((uwbrate * etu_per_update + 1.0) + * sect.sct_item[I_UW])); natp = getnatp(sect.sct_own); maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §); civs = min(civs, maxpop); @@ -83,7 +80,7 @@ newe(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)((civs * sect.sct_work) / 100.0 - + uws + items[I_MILIT] * 2 / 5.0); + + uws + sect.sct_item[I_MILIT] * 2 / 5.0); work = etu_per_update * wforce / 100.0; if (opt_ROLLOVER_AVAIL) { @@ -115,13 +112,13 @@ newe(void) twork = bwork; } if (dchr[type].d_lcms > 0) { - lcms = items[I_LCM]; + lcms = sect.sct_item[I_LCM]; lcms = (int)(lcms / dchr[type].d_lcms); if (twork > lcms) twork = lcms; } if (dchr[type].d_hcms > 0) { - hcms = items[I_HCM]; + hcms = sect.sct_item[I_HCM]; hcms = (int)(hcms / dchr[type].d_hcms); if (twork > hcms) twork = hcms; @@ -134,13 +131,13 @@ newe(void) twork = bwork; } if (dchr[type].d_lcms > 0) { - lcms = items[I_LCM]; + lcms = sect.sct_item[I_LCM]; lcms = (int)(lcms / dchr[type].d_lcms); if (twork > lcms) twork = lcms; } if (dchr[type].d_hcms > 0) { - hcms = items[I_HCM]; + hcms = sect.sct_item[I_HCM]; hcms = (int)(hcms / dchr[type].d_hcms); if (twork > hcms) twork = hcms; diff --git a/src/lib/commands/scra.c b/src/lib/commands/scra.c index ed21b4c6a..1adefc026 100644 --- a/src/lib/commands/scra.c +++ b/src/lib/commands/scra.c @@ -58,7 +58,6 @@ scra(void) struct nstr_item ni; union item_u item; int vec[I_MAX + 1]; - int itemvec[I_MAX + 1]; int type; struct sctstr sect; struct mchrstr *mp; @@ -189,9 +188,8 @@ scra(void) } } pr("%s", prship(&item.ship)); - getvec(VT_ITEM, itemvec, (s_char *)&item.ship, EF_SHIP); for (i = 1; i <= I_MAX; i++) { - vec[i] += itemvec[i]; + vec[i] += item.ship.shp_item[i]; } vec[I_LCM] += mp->m_lcm * 2 / 3 * eff; vec[I_HCM] += mp->m_hcm * 2 / 3 * eff; @@ -256,9 +254,8 @@ scra(void) eff = ((float)item.land.lnd_effic / 100.0); lp = &lchr[(int)item.land.lnd_type]; pr("%s", prland(&item.land)); - getvec(VT_ITEM, itemvec, (s_char *)&item.land, EF_LAND); for (i = 1; i <= I_MAX; i++) { - vec[i] += itemvec[i]; + vec[i] += item.land.lnd_item[i]; } /* Military, guns and shells are not required to build land units */ /* vec[I_MILIT] += total_mil(&item.land);*/ diff --git a/src/lib/commands/spy.c b/src/lib/commands/spy.c index 939035d72..55a62556f 100644 --- a/src/lib/commands/spy.c +++ b/src/lib/commands/spy.c @@ -75,7 +75,6 @@ spy(void) coord *table; /* sectors already seen */ int t_len = 0; int vec[I_MAX + 1]; - int dvec[I_MAX + 1]; int nrecon; int nunits; struct nstr_sect nstr; @@ -146,16 +145,16 @@ spy(void) continue; } getsect(nx, ny, &dsect); - getvec(VT_ITEM, dvec, (s_char *)&dsect, EF_SECTOR); - if (player->owner || (dsect.sct_type == SCT_WATER) || - (!dvec[I_MILIT] && !dvec[I_CIVIL] && - (num_units(nx, ny) == 0))) { + if (player->owner + || (dsect.sct_type == SCT_WATER) + || (!dsect.sct_item[I_MILIT] && !dsect.sct_item[I_CIVIL] + && num_units(nx, ny) == 0)) { /* mark sector as seen */ insert(table, &t_len, nx, ny); continue; } /* catch spy N/200 chance, N = # military */ - caught = chance((double)dvec[I_MILIT] / 200.0); + caught = chance((double)dsect.sct_item[I_MILIT] / 200.0); own = dsect.sct_own; /* determine spyee relations with spyer */ relat = getrel(getnatp(own), player->cnum); @@ -225,9 +224,6 @@ spy(void) static void spyline(struct sctstr *sp) { - int vec[I_MAX + 1]; - - getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); prxy("%4d,%-4d", sp->sct_x, sp->sct_y, player->cnum); pr(" %c%c %3d %3d %3d %3d %3d %3d %4d %4d %4d %3d %4d %4d %4d %3d %3d\n", dchr[sp->sct_type].d_mnem, @@ -238,13 +234,13 @@ spyline(struct sctstr *sp) roundintby((int)sp->sct_road, 10), roundintby((int)sp->sct_rail, 10), roundintby((int)sp->sct_defense, 10), - roundintby(vec[I_CIVIL], 10), - roundintby(vec[I_MILIT], 10), - roundintby(vec[I_SHELL], 10), - roundintby(vec[I_GUN], 10), - roundintby(vec[I_PETROL], 10), - roundintby(vec[I_FOOD], 10), - roundintby(vec[I_BAR], 10), + roundintby(sp->sct_item[I_CIVIL], 10), + roundintby(sp->sct_item[I_MILIT], 10), + roundintby(sp->sct_item[I_SHELL], 10), + roundintby(sp->sct_item[I_GUN], 10), + roundintby(sp->sct_item[I_PETROL], 10), + roundintby(sp->sct_item[I_FOOD], 10), + roundintby(sp->sct_item[I_BAR], 10), count_sect_units(sp), count_sect_planes(sp)); } diff --git a/src/lib/subs/shpsub.c b/src/lib/subs/shpsub.c index e63b022e7..b0b3b6814 100644 --- a/src/lib/subs/shpsub.c +++ b/src/lib/subs/shpsub.c @@ -121,7 +121,6 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp, struct mlist *mlp; struct sctstr sect; struct shpstr ship; - int vec[I_MAX + 1]; coord allx; coord ally; int first = 1; @@ -148,8 +147,7 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp, } } /* check crew - uws don't count */ - getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); - if (vec[I_MILIT] == 0 && vec[I_CIVIL] == 0) { + if (ship.shp_item[I_MILIT] == 0 && ship.shp_item[I_CIVIL] == 0) { shp_mess("is crewless", mlp); continue; } @@ -331,7 +329,6 @@ shp_list(struct emp_qelem *ship_list) struct emp_qelem *next; struct mlist *mlp; struct shpstr *shp; - int vec[I_MAX + 1]; pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n"); @@ -344,10 +341,9 @@ shp_list(struct emp_qelem *ship_list) prxy("%4d,%-4d ", shp->shp_x, shp->shp_y, mlp->ship.shp_own); pr("%1c", shp->shp_fleet); pr("%4d%%", shp->shp_effic); - getvec(VT_ITEM, vec, (s_char *)shp, EF_SHIP); - pr("%4d", vec[I_MILIT]); - pr("%4d", vec[I_SHELL]); - pr("%4d", vec[I_GUN]); + pr("%4d", shp->shp_item[I_MILIT]); + pr("%4d", shp->shp_item[I_SHELL]); + pr("%4d", shp->shp_item[I_GUN]); count_planes(shp); pr("%3d", shp->shp_nplane); pr("%3d", shp->shp_nchoppers); diff --git a/src/lib/update/ship.c b/src/lib/update/ship.c index ee991b290..d4c7628a1 100644 --- a/src/lib/update/ship.c +++ b/src/lib/update/ship.c @@ -277,7 +277,6 @@ shiprepair(register struct shpstr *ship, int *vec, struct natstr *np, int avail; int w_p_eff; int mult; - int svec[I_MAX + 1]; int mvec[I_MAX + 1]; int rel; @@ -348,8 +347,6 @@ shiprepair(register struct shpstr *ship, int *vec, struct natstr *np, if ((sp->sct_off) && (sp->sct_own == ship->shp_own)) return 1; - getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); - mult = 1; if (np->nat_level[NAT_TLEV] < ship->shp_tech * 0.85) mult = 2;