]> git.pond.sub.org Git - empserver/commitdiff
(alloc_bp, bp_alloc): Rename.
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 13 Jan 2007 17:11:17 +0000 (17:11 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 13 Jan 2007 17:11:17 +0000 (17:11 +0000)
(fill_update_array, bp_set_from_sect): Rename.
(gt_bg_nmbr, pt_bg_nmbr, bp_get_item, bp_get_avail, bp_put_item,
bp_put_avail): Separate accessor functions for item and avail.

include/budg.h
src/lib/commands/budg.c
src/lib/update/bp.c
src/lib/update/human.c
src/lib/update/land.c
src/lib/update/main.c
src/lib/update/material.c
src/lib/update/plane.c
src/lib/update/prepare.c
src/lib/update/sect.c
src/lib/update/ship.c

index f33c3167cf8ca042b3c89f9fed591ca4bc96ca77..8e8f8a2c179497851d01774d1e9bcbf9c4efb2a1 100644 (file)
 
 #define SCT_EFFIC (SCT_TYPE_MAX + 1)
 
-struct bp *alloc_bp(void);
-void fill_update_array(struct bp *, struct sctstr *);
-int gt_bg_nmbr(struct bp *, struct sctstr *, i_type);
-void pt_bg_nmbr(struct bp *, struct sctstr *, i_type, int);
+struct bp *bp_alloc(void);
+void bp_set_from_sect(struct bp *, struct sctstr *);
+int bp_get_item(struct bp *, struct sctstr *, i_type);
+void bp_put_item(struct bp *, struct sctstr *, i_type, int);
+int bp_get_avail(struct bp *, struct sctstr *);
+void bp_put_avail(struct bp *, struct sctstr *, int);
+
 int get_materials(struct sctstr *, struct bp *, int *, int);
 
 extern long money[MAXNOC];
index 6befd20529cee9611027afac35ccd642562d6917..c14ae53368ca941f29ecbc77f50d7f16e437c0b7 100644 (file)
@@ -197,9 +197,9 @@ calc_all(long p_sect[][2],
     *planes = *pbuild = *npbuild = *pmaint = 0;
     
     np = getnatp(player->cnum);
-    bp = alloc_bp();
+    bp = bp_alloc();
     for (n = 0; NULL != (sp = getsectid(n)); n++) {
-       fill_update_array(bp, sp);
+       bp_set_from_sect(bp, sp);
        if (sp->sct_own == player->cnum) {
            sp->sct_updated = 0;
            tax(sp, np, etu, &pop, &civ_tax, &uw_tax, &mil_pay);
index d6bd3f0b9cc0739ae8e7d0116c8b1d4b728afb59..e0702e623c8ec8ee9157fc1715a14c6166749236 100644 (file)
 #include "update.h"
 
 struct bp {
-    int val[7];
+    int val[6];
+    int avail;
 };
 
-static int bud_key[I_MAX + 2] =
-    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0, 7 };
+static int bud_key[I_MAX + 1] =
+    { 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0 };
 
 static struct bp *
 bp_ref(struct bp *bp, struct sctstr *sp)
@@ -51,7 +52,7 @@ bp_ref(struct bp *bp, struct sctstr *sp)
 }
 
 int
-gt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm)
+bp_get_item(struct bp *bp, struct sctstr *sp, i_type comm)
 {
     int cm;
 
@@ -61,7 +62,7 @@ gt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm)
 }
 
 void
-pt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm, int amount)
+bp_put_item(struct bp *bp, struct sctstr *sp, i_type comm, int amount)
 {
     int cm;
 
@@ -69,8 +70,20 @@ pt_bg_nmbr(struct bp *bp, struct sctstr *sp, i_type comm, int amount)
        bp_ref(bp, sp)->val[cm - 1] = amount;
 }
 
+int
+bp_get_avail(struct bp *bp, struct sctstr *sp)
+{
+    return bp_ref(bp, sp)->avail;
+}
+
+void
+bp_put_avail(struct bp *bp, struct sctstr *sp, int amount)
+{
+    bp_ref(bp, sp)->avail = amount;
+}
+
 void
-fill_update_array(struct bp *bp, struct sctstr *sp)
+bp_set_from_sect(struct bp *bp, struct sctstr *sp)
 {
     int k;
     struct bp *p = bp_ref(bp, sp);
@@ -80,11 +93,11 @@ fill_update_array(struct bp *bp, struct sctstr *sp)
        if ((k = bud_key[i]) != 0)
            p->val[k - 1] = sp->sct_item[i];
     }
-    p->val[bud_key[I_MAX + 1] - 1] = sp->sct_avail;
+    p->avail = sp->sct_avail;
 }
 
 struct bp *
-alloc_bp(void)
+bp_alloc(void)
 {
     return calloc(WORLD_X * WORLD_Y, sizeof(struct bp));
 }
index 43c0b1a3a85d62a8cb45ac993032d6bb63d70ede..cf5a788a74684a482de3bcc9ecdc4f0a44ec23c9 100644 (file)
@@ -78,7 +78,7 @@ do_feed(struct sctstr *sp, struct natstr *np, short *vec,
                /* need to grow "emergency rations" */
                work_avail -= 2 * growfood(sp, vec, work_avail / 2, etu);
                /* It's twice as hard to grow those than norm */
-               pt_bg_nmbr(bp, sp, I_MAX + 1, work_avail);
+               bp_put_avail(bp, sp, work_avail);
                if (!player->simulation)
                    sp->sct_avail = work_avail;
            }
@@ -118,9 +118,9 @@ do_feed(struct sctstr *sp, struct natstr *np, short *vec,
     /* Here is where we truncate extra people, always */
     trunc_people(sp, np, vec);
 
-    pt_bg_nmbr(bp, sp, I_CIVIL, vec[I_CIVIL]);
-    pt_bg_nmbr(bp, sp, I_UW, vec[I_UW]);
-    pt_bg_nmbr(bp, sp, I_MILIT, vec[I_MILIT]);
+    bp_put_item(bp, sp, I_CIVIL, vec[I_CIVIL]);
+    bp_put_item(bp, sp, I_UW, vec[I_UW]);
+    bp_put_item(bp, sp, I_MILIT, vec[I_MILIT]);
     *workp = work_avail;
     return sctwork;
 }
index a6d3566c899c6b6865f7baf6e48a0d09043be094..eb9fbc603fd372332700dbb1955e7ea5f8f0c679 100644 (file)
@@ -244,7 +244,7 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
     if (!player->simulation)
        avail = sp->sct_avail * 100;
     else
-       avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100;
+       avail = bp_get_avail(bp, sp) * 100;
 
     w_p_eff = LND_BLD_WORK(lp->l_lcm, lp->l_hcm);
     delta = roundavg((double)avail / w_p_eff);
@@ -269,7 +269,7 @@ landrepair(struct lndstr *land, struct natstr *np, struct bp *bp, int etus)
     if (!player->simulation)
        sp->sct_avail = avail / 100;
     else
-       pt_bg_nmbr(bp, sp, I_MAX + 1, avail / 100);
+       bp_put_avail(bp, sp, avail / 100);
 
     if (build < 0)
        logerror("land unit %d building %d ! \n", land->lnd_uid, build);
index 65ebb573617fa9f1d510bc6dd94a3387c4e60562..3564460e62114645cf987a044849b123279f2273 100644 (file)
@@ -92,7 +92,7 @@ update_main(void *unused)
     memset(air_money, 0, sizeof(air_money));
     memset(sea_money, 0, sizeof(sea_money));
     memset(lnd_money, 0, sizeof(lnd_money));
-    bp = alloc_bp();
+    bp = bp_alloc();
     for (n = 0; n < MAXNOC; n++) {
        money[n] = 0;
        if (!(np = getnatp(n)))
index 8ccd09b37d560cb17726ffdffbd5839a2d16382c..e5bb927c60a23fe2aa418681dd12e356165d8a6a 100644 (file)
@@ -55,7 +55,7 @@ get_materials(struct sctstr *sp, struct bp *bp, int *mvec, int pct)
     for (i = I_NONE + 1; i <= I_MAX; i++) {
        if (mvec[i] == 0)
            continue;
-       amt = gt_bg_nmbr(bp, sp, i);
+       amt = bp_get_item(bp, sp, i);
        if (amt * 100 < mvec[i] * pct)
            pct = amt * 100 / mvec[i];
     }
@@ -63,11 +63,11 @@ get_materials(struct sctstr *sp, struct bp *bp, int *mvec, int pct)
     for (i = I_NONE + 1; i <= I_MAX; i++) {
        if (mvec[i] == 0)
            continue;
-       amt = gt_bg_nmbr(bp, sp, i);
+       amt = bp_get_item(bp, sp, i);
        amt -= roundavg(mvec[i] * pct / 100.0);
        if (CANT_HAPPEN(amt < 0))
            amt = 0;
-       pt_bg_nmbr(bp, sp, i, amt);
+       bp_put_item(bp, sp, i, amt);
        if (!player->simulation)
            sp->sct_item[i] = amt;
     }
index 82e2d91b9edfa101efcd1146f0dbe565aecf0257..de7324c9ffefe017a55b22628dc7dd49fc0218a7 100644 (file)
@@ -168,7 +168,7 @@ planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus)
     if (!player->simulation)
        avail = sp->sct_avail * 100;
     else
-       avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100;
+       avail = bp_get_avail(bp, sp) * 100;
     if (carrier)
        avail += etus * carrier->shp_item[I_MILIT] / 2;
 
@@ -198,14 +198,14 @@ planerepair(struct plnstr *pp, struct natstr *np, struct bp *bp, int etus)
     if (!player->simulation)
        avail = (sp->sct_avail * 100 - used) / 100;
     else
-       avail = (gt_bg_nmbr(bp, sp, I_MAX + 1) * 100 - used) / 100;
+       avail = (bp_get_avail(bp, sp) * 100 - used) / 100;
 
     if (avail < 0)
        avail = 0;
     if (!player->simulation)
        sp->sct_avail = avail;
     else
-       pt_bg_nmbr(bp, sp, I_MAX + 1, avail);
+       bp_put_avail(bp, sp, avail);
 
     if (sp->sct_type != SCT_AIRPT)
        build /= 3;
index cd0afb11e9fcda05646ea2226610b60130aaa6cb..6ae06959ae101a5a0325bf907e24a053df67eeb6 100644 (file)
@@ -77,7 +77,7 @@ prepare_sects(int etu, struct bp *bp)
 
        if (sp->sct_type == SCT_WATER)
            continue;
-       fill_update_array(bp, sp);
+       bp_set_from_sect(bp, sp);
        np = getnatp(sp->sct_own);
 
 #ifdef DEBUG
index ccc3637197b67471865ed509c52af7a28a853501..91996a8013924dfa9dae864e6fab6a82aeffeabf 100644 (file)
@@ -329,8 +329,8 @@ produce_sect(int natnum, int etu, struct bp *bp, long p_sect[][2])
            np->nat_money > 0) {
            neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork,
                                  &cost);
-           pt_bg_nmbr(bp, sp, I_LCM, vec[I_LCM]);
-           pt_bg_nmbr(bp, sp, I_HCM, vec[I_HCM]);
+           bp_put_item(bp, sp, I_LCM, vec[I_LCM]);
+           bp_put_item(bp, sp, I_HCM, vec[I_HCM]);
            p_sect[SCT_EFFIC][0]++;
            p_sect[SCT_EFFIC][1] += cost;
            if (!player->simulation) {
@@ -358,7 +358,7 @@ produce_sect(int natnum, int etu, struct bp *bp, long p_sect[][2])
                                &pcost, &amount);
        }
 
-       pt_bg_nmbr(bp, sp, I_MAX + 1, work);
+       bp_put_avail(bp, sp, work);
        p_sect[desig][0] += amount;
        p_sect[desig][1] += pcost;
        if (!player->simulation) {
index 54c18ec3388dbef81c60f0e50c407c2fd6765112..92a938f908347eee9f3545fbaf547a73d4724e1d 100644 (file)
@@ -303,7 +303,7 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
        if (!player->simulation)
            avail = wf + sp->sct_avail * 100;
        else
-           avail = wf + gt_bg_nmbr(bp, sp, I_MAX + 1) * 100;
+           avail = wf + bp_get_avail(bp, sp) * 100;
     }
 
     w_p_eff = SHP_BLD_WORK(mp->m_lcm, mp->m_hcm);
@@ -345,13 +345,13 @@ shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
        if (!player->simulation)
            avail = (sp->sct_avail * 100 + wf) / 100;
        else
-           avail = (gt_bg_nmbr(bp, sp, I_MAX + 1) * 100 + wf) / 100;
+           avail = (bp_get_avail(bp, sp) * 100 + wf) / 100;
        if (avail < 0)
            avail = 0;
        if (!player->simulation)
            sp->sct_avail = avail;
        else
-           pt_bg_nmbr(bp, sp, I_MAX + 1, avail);
+           bp_put_avail(bp, sp, avail);
     }
     if (sp->sct_type != SCT_HARBR)
        if ((build + ship->shp_effic) > 80) {