]> git.pond.sub.org Git - empserver/commitdiff
prod() duplicates materials_cost(), clean up
authorMarkus Armbruster <armbru@pond.sub.org>
Fri, 3 May 2013 18:52:02 +0000 (20:52 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 8 May 2013 04:57:58 +0000 (06:57 +0200)
Rename materials_cost() to prod_materials_cost(), give external
linkage, use it in prod().

include/prototypes.h
include/types.h
src/lib/commands/prod.c
src/lib/update/produce.c

index 0291f5e0bc0004dfd9bd9c013cfcd2ab3c811943..63d0a8d93adb13a2576e98911c5862fe08f445ae 100644 (file)
@@ -716,6 +716,7 @@ extern int bank_income(struct sctstr *, int);
 /* produce.c */
 extern int produce(struct natstr *, struct sctstr *, short *, int, int,
                   int, int *, int *);
+extern int prod_materials_cost(struct pchrstr *, short[], int *);
 extern double prod_eff(int, float);
 /* removewants.c */
 extern int update_removewants(void);
index 542ff1d76d4e5b7189db4979bfb43e868de024c1..44f8753d5e1fc39262582d3ccb2b74caf37cf528 100644 (file)
@@ -48,6 +48,7 @@ struct nchrstr;
 struct nstr_item;
 struct nstr_sect;
 struct nukstr;
+struct pchrstr;
 struct player;
 struct plist;
 struct plnstr;
index 882ff28cb79c84b96b7afe78241dc61761e16462..504b7fe257eb1f17939abf6ca3773f1b9276ff22 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     David Muir Sharnoff, 1987
  *     Steve McClure, 1997-2000
- *     Markus Armbruster, 2004-2010
+ *     Markus Armbruster, 2004-2013
  */
 
 #include <config.h>
@@ -202,13 +202,13 @@ prod(void)
 
        if (dchr[type].d_prd < 0)
            continue;
-       unit_work = 0;
        pp = &pchr[dchr[type].d_prd];
        vtype = pp->p_type;
        if (pp->p_nrndx)
            resource = (unsigned char *)&sect + pp->p_nrndx;
        else
            resource = NULL;
+       used = prod_materials_cost(pp, sect.sct_item, &unit_work);
        /*
         * sect p_e  (inc improvements)
         */
@@ -216,25 +216,12 @@ prod(void)
            unit_work++;
            p_e *= *resource / 100.0;
        }
+       if (unit_work == 0)
+           unit_work = 1;
        /*
         * production effic.
         */
        prodeff = prod_eff(type, natp->nat_level[pp->p_nlndx]);
-       /*
-        * raw material limit
-        */
-       used = 9999;
-       for (i = 0; i < MAXPRCON; ++i) {
-           it = pp->p_ctype[i];
-           if (!pp->p_camt[i])
-               continue;
-           if (CANT_HAPPEN(it <= I_NONE || I_MAX < it))
-               continue;
-           used = MIN(used, sect.sct_item[it] / pp->p_camt[i]);
-           unit_work += pp->p_camt[i];
-       }
-       if (unit_work == 0)
-           unit_work = 1;
        /*
         * is production limited by resources or
         * workforce?
index f0dec1ed5579c5eb24d37d694790bf7b21a419d8..f72dd75c577aeb86f158237039c945b1660933e0 100644 (file)
@@ -27,7 +27,7 @@
  *  produce.c: Produce goodies
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2004-2010
+ *     Markus Armbruster, 2004-2013
  */
 
 #include <config.h>
@@ -39,7 +39,6 @@
 #include "update.h"
 
 static void materials_charge(struct pchrstr *, short *, int);
-static int materials_cost(struct pchrstr *, short *, int *);
 
 static char *levelnames[] = {
     "Technology", "Research", "Education", "Happiness"
@@ -73,7 +72,8 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
     *amount = 0;
     *cost = 0;
 
-    if ((material_limit = materials_cost(product, vec, &unit_work)) <= 0)
+    material_limit = prod_materials_cost(product, vec, &unit_work);
+    if (material_limit <= 0)
        return 0;
     /*
      * calculate production efficiency.
@@ -172,8 +172,12 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
     return 0;
 }
 
-static int
-materials_cost(struct pchrstr *pp, short *vec, int *costp)
+/*
+ * Return how much of product PP can be made from materials VEC[].
+ * Store amount of work per unit in *COSTP.
+ */
+int
+prod_materials_cost(struct pchrstr *pp, short vec[], int *costp)
 {
     int count;
     int cost;