/* 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);
struct nstr_item;
struct nstr_sect;
struct nukstr;
+struct pchrstr;
struct player;
struct plist;
struct plnstr;
* Known contributors to this file:
* David Muir Sharnoff, 1987
* Steve McClure, 1997-2000
- * Markus Armbruster, 2004-2010
+ * Markus Armbruster, 2004-2013
*/
#include <config.h>
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 *)§ + pp->p_nrndx;
else
resource = NULL;
+ used = prod_materials_cost(pp, sect.sct_item, &unit_work);
/*
* sect p_e (inc improvements)
*/
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?
* produce.c: Produce goodies
*
* Known contributors to this file:
- * Markus Armbruster, 2004-2010
+ * Markus Armbruster, 2004-2013
*/
#include <config.h>
#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"
*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.
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;