]> git.pond.sub.org Git - empserver/commitdiff
Replace getvec() by direct, read-only item access in some cases where
authorMarkus Armbruster <armbru@pond.sub.org>
Fri, 5 Mar 2004 12:05:33 +0000 (12:05 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 5 Mar 2004 12:05:33 +0000 (12:05 +0000)
that's obviously correct.

src/lib/commands/new.c
src/lib/commands/newe.c
src/lib/commands/scra.c
src/lib/commands/spy.c
src/lib/subs/shpsub.c
src/lib/update/ship.c

index 3db60ece6ff346c06ca96022f4dacc3b65be5a64..6835ce4885cb7b17bc329732f335db96a0563e80 100644 (file)
@@ -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,
index f9e1c66344148792e40c65f41d411c2ec7645684..a13735f71ca0b0f194598ba438292b3dc1bcbfb5 100644 (file)
@@ -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 *)&sect, 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], &sect);
            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;
index ed21b4c6aed46d62cd69654e7114c7c75dafc763..1adefc0268a00e910109b4d43379fbc279fb55a1 100644 (file)
@@ -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);*/
index 939035d72e665ea92a5d4d80b1a60d84265e6b70..55a62556fd2eb343b18e523053cb5887046564af 100644 (file)
@@ -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));
 }
index e63b022e72c36bc91f339e5262ea5b817853f0ea..b0b3b681430697bd490df5e521efdce9c77e1076 100644 (file)
@@ -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);
index ee991b2906682bc82bc9a3ad82bc64c03483d7f4..d4c7628a12961431044cf1c3db43e82d83909861 100644 (file)
@@ -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;