]> git.pond.sub.org Git - empserver/commitdiff
(produce_sect): Unless player->simulation, work directly on item
authorMarkus Armbruster <armbru@pond.sub.org>
Thu, 11 Mar 2004 22:00:58 +0000 (22:00 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 11 Mar 2004 22:00:58 +0000 (22:00 +0000)
arrays instead of copies made by getvec().  This is safe, because the
old code made single copies and always flushed them back into the unit
structures.  Else make copies by hand, not with getvec.
(starv_sects): Replace getvec() by direct, read-only item access.
(upd_buildeff, enlist, materials_charge, materials_cost, produce,
grow_people, growfood, trunc_people, do_feed, feed_people): Change
argument type to match uncopied item arrays.
(growfood): Obey ITEM_MAX.

include/prototypes.h
src/lib/commands/strv.c
src/lib/update/human.c
src/lib/update/produce.c
src/lib/update/sect.c

index d23e755215e42629fa632f2010c92f187e1e4038..12ab01b6f4a8b616a955f2a80f8cd0a214368c4b 100644 (file)
@@ -551,8 +551,8 @@ extern int dodistribute(struct sctstr *, int, s_char *, double, double);
 extern void finish_sects(int);
 /* human.c */
 extern int do_feed(register struct sctstr *, register struct natstr *,
-                  int *, int *, int *, int);
-extern int feed_people(register int *, int, int *);
+                  short *, int *, int *, int);
+extern int feed_people(short *, int, int *);
 /* land.c */
 extern int prod_land(int, int, int *, int);
 extern int feed_land(struct lndstr *, int, int *, int);
@@ -605,7 +605,7 @@ extern int upd_slmilcosts(natid, int);
 extern void prepare_sects(int, int *);
 extern int bank_income(struct sctstr *, int);
 /* produce.c */
-extern int produce(struct natstr *, struct sctstr *, int *, int, int,
+extern int produce(struct natstr *, struct sctstr *, short *, int, int,
                   int, int *, int *);
 /* removewants.c */
 extern int update_removewants(void);
index 83ef0e9567b2a00b84f06ebc60cc68e32b3ee723..1a3fd4511220188d5fab1aa22e7abc255c1b6834 100644 (file)
@@ -103,7 +103,7 @@ starv_sects(s_char *range)
     struct nstr_sect nstr;
     struct sctstr sect;
     int nsect = 0;
-    int vec[I_MAX + 1], s, needed;
+    int s, needed;
 
     if (!snxtsct(&nstr, range))
        return;
@@ -113,11 +113,10 @@ starv_sects(s_char *range)
        if (sect.sct_type == SCT_SANCT)
            continue;
 
-       getvec(VT_ITEM, vec, (s_char *)&sect, EF_SECTOR);
 /* This next 2 lines were added to overcompensate for the needy */
-       if (vec[I_FOOD])
-           vec[I_FOOD]--;
-       s = feed_people(vec, etu_per_update, &needed);
+       if (sect.sct_item[I_FOOD])
+           sect.sct_item[I_FOOD]--;
+       s = feed_people(sect.sct_item, etu_per_update, &needed);
 
        if (s == 0)
            continue;
index d30aa3683fb9731c7b415a56fc847f0e242f920d..f366d514a36a34fcb1b6ce546b00191f44c3f59a 100644 (file)
 
 static int grow_people(struct sctstr *, register int,
                       register struct natstr *, int *, int,
-                      register int *);
-static int growfood(struct sctstr *, register int *, int, int);
+                      short *);
+static int growfood(struct sctstr *, short *, int, int);
 static void starvation(struct sctstr *);
 static void trunc_people(struct sctstr *, register struct natstr *,
-                        register int *);
+                        short *);
 
 /*
  * feed the individual sector
  *
  */
 int
-do_feed(register struct sctstr *sp, register struct natstr *np, int *vec,
+do_feed(struct sctstr *sp, struct natstr *np, short *vec,
        int *workp, int *bp, int etu)
 {
     int people;
@@ -150,7 +150,7 @@ do_feed(register struct sctstr *sp, register struct natstr *np, int *vec,
 }
 
 static int
-growfood(struct sctstr *sp, register int *vec, int work, int etu)
+growfood(struct sctstr *sp, short *vec, int work, int etu)
 {
     double food_fertil;
     double food_workers;
@@ -174,8 +174,8 @@ growfood(struct sctstr *sp, register int *vec, int work, int etu)
     vec[I_FOOD] += (int)food;
     if (vec[I_FOOD] == 0)
        vec[I_FOOD] = 1;
-    if (vec[I_FOOD] > 9999)
-       vec[I_FOOD] = 9999;
+    if (vec[I_FOOD] > ITEM_MAX)
+       vec[I_FOOD] = ITEM_MAX;
     work_used = (int)food / fcrate;
     return work_used;
 }
@@ -184,7 +184,7 @@ growfood(struct sctstr *sp, register int *vec, int work, int etu)
  * returns the number who starved, if any.
  */
 int
-feed_people(register int *vec, int etu, int *needed)
+feed_people(short *vec, int etu, int *needed)
 {
     double food_eaten;
     int ifood_eaten;
@@ -241,7 +241,7 @@ feed_people(register int *vec, int etu, int *needed)
  */
 static void
 trunc_people(struct sctstr *sp, register struct natstr *np,
-            register int *vec)
+            short *vec)
 {
     int maxpop = max_pop(np->nat_level[NAT_RLEV], sp);
 
@@ -260,7 +260,7 @@ trunc_people(struct sctstr *sp, register struct natstr *np,
 static int
 grow_people(struct sctstr *sp, register int etu,
            register struct natstr *np, int *workp, int sctwork,
-           register int *vec)
+           short *vec)
 {
     int newciv;
     int newuw;
index 2b36f852299c016c2c4f7325c567d3448358b302..0a9d2ecb22eb9a80f4e635d9aea40afe83c6ebb3 100644 (file)
 #include "optlist.h"
 #include "budg.h"
 
-static void materials_charge(struct pchrstr *, register int *,
-                            register int);
-static int materials_cost(struct pchrstr *, register int *, int *);
+static void materials_charge(struct pchrstr *, short *, int);
+static int materials_cost(struct pchrstr *, short *, int *);
 
 s_char *levelnames[] =
     { "Technology", "Research", "Education", "Happiness" };
 
 int
-produce(struct natstr *np, struct sctstr *sp, int *vec, int work,
+produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
        int desig, int neweff, int *cost, int *amount)
 {
     register struct pchrstr *product;
@@ -190,7 +189,7 @@ produce(struct natstr *np, struct sctstr *sp, int *vec, int work,
 }
 
 static int
-materials_cost(struct pchrstr *product, register int *vec, int *costp)
+materials_cost(struct pchrstr *product, short *vec, int *costp)
 {
     register u_char *vp;
     register u_short *ap;
@@ -216,8 +215,7 @@ materials_cost(struct pchrstr *product, register int *vec, int *costp)
 }
 
 static void
-materials_charge(struct pchrstr *product, register int *vec,
-                register int count)
+materials_charge(struct pchrstr *product, short *vec, int count)
 {
     register u_char *vp;
     register u_short *ap;
index 87bb4d15f26a69603629fdcd987cb17ceb6e3667..4ddd27b62b676d5b6765d5cbf283b30bd07e8ba3 100644 (file)
@@ -88,7 +88,7 @@ dodeliver(struct sctstr *sp)
  */
 static int
 upd_buildeff(struct natstr *np, register struct sctstr *sp, int *workp,
-            int *vec, int etu, int *desig, int sctwork, int *cost)
+            short *vec, int etu, int *desig, int sctwork, int *cost)
 {
     register int work_cost = 0;
     int buildeff_work = (int)(*workp / 2);
@@ -171,7 +171,7 @@ upd_buildeff(struct natstr *np, register struct sctstr *sp, int *workp,
  * some mil initially.
  */
 static int
-enlist(register int *vec, int etu, int *cost)
+enlist(short *vec, int etu, int *cost)
 {
     int maxmil;
     int enlisted;
@@ -327,7 +327,8 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
 {
     register struct sctstr *sp;
     register struct natstr *np;
-    int vec[I_MAX + 1];
+    short buf[I_MAX + 1];
+    short *vec;
     int work, cost, ecost, pcost, sctwork;
     int n, desig, maxpop, neweff, amount;
 
@@ -346,8 +347,13 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
            p_sect[SCT_CAPIT][1] += etu;
        }
 
-       if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0)
-           continue;
+       if (player->simulation) {
+           /* work on a copy, which will be discarded */
+           memcpy(buf, sp->sct_item, sizeof(buf));
+           vec = buf;
+       } else
+           vec = sp->sct_item;
+
        /* If everybody is dead, the sector reverts to unowned. 
           * This is also checked at the end of the production in
           * they all starved or were plagued off.
@@ -375,10 +381,8 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
        bp_clear_cachepath();
 
        if (sp->sct_off || np->nat_money < 0) {
-           if (!player->simulation) {
-               putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
+           if (!player->simulation)
                sp->sct_off = 0;
-           }
            continue;
        }
        if ((np->nat_priorities[sp->sct_type] == 0) &&
@@ -386,7 +390,6 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
            ((pchr[dchr[sp->sct_type].d_prd].p_cost != 0) ||
             (sp->sct_type == SCT_ENLIST))) {
            if (!player->simulation) {
-               putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
                logerror("Skipping %s production for country %s\n",
                         dchr[sp->sct_type].d_name, np->nat_cnam);
            }
@@ -401,28 +404,14 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
 
        if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) &&
            np->nat_money > 0) {
-           neweff =
-               upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork,
-                            &cost);
+           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]);
            p_sect[SCT_EFFIC][0]++;
            p_sect[SCT_EFFIC][1] += cost;
            if (!player->simulation) {
                np->nat_money -= cost;
-               /* No longer tear down infrastructure
-                  if (sp->sct_type != desig) {
-                  sp->sct_road = 0;
-                  sp->sct_defense = 0;
-                  } else if (neweff < sp->sct_effic) {
-                  sp->sct_road -= (sp->sct_road * (sp->sct_effic - neweff) / 100.0);
-                  sp->sct_defense -= (sp->sct_defense * (sp->sct_effic - neweff) / 100.0);
-                  if (sp->sct_road < 0)
-                  sp->sct_road = 0;
-                  if (sp->sct_defense < 0)
-                  sp->sct_defense = 0;
-                  }
-                */
                sp->sct_type = desig;
                sp->sct_effic = neweff;
                if (!opt_DEFENSE_INFRA)
@@ -434,7 +423,6 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
            ((pchr[dchr[desig].d_prd].p_cost != 0) ||
             (desig == SCT_ENLIST))) {
            if (!player->simulation) {
-               putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
                logerror("Skipping %s production for country %s\n",
                         dchr[sp->sct_type].d_name, np->nat_cnam);
            }
@@ -468,7 +456,6 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
                vec[I_CIVIL] = maxpop;
            if (vec[I_UW] > maxpop)
                vec[I_UW] = maxpop;
-           putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
            sp->sct_avail = work;
            np->nat_money -= pcost;
        }