Factor prod_resource_limit() out of produce() and prod()
This commit is contained in:
parent
ec60098c36
commit
ba2600e7db
3 changed files with 23 additions and 9 deletions
|
@ -717,6 +717,7 @@ extern int bank_income(struct sctstr *, int);
|
|||
extern int produce(struct natstr *, struct sctstr *, short *, int, int,
|
||||
int, int *, int *);
|
||||
extern int prod_materials_cost(struct pchrstr *, short[], int *);
|
||||
extern int prod_resource_limit(struct pchrstr *, unsigned char *);
|
||||
extern double prod_eff(int, float);
|
||||
/* removewants.c */
|
||||
extern int update_removewants(void);
|
||||
|
|
|
@ -82,6 +82,7 @@ prod(void)
|
|||
int there;
|
||||
int unit_work; /* sum of component amounts */
|
||||
int used; /* production w/infinite workforce */
|
||||
int res_limit;
|
||||
i_type it;
|
||||
i_type vtype;
|
||||
unsigned char *resource;
|
||||
|
@ -227,10 +228,9 @@ prod(void)
|
|||
* workforce?
|
||||
*/
|
||||
max = (int)(work * p_e / (double)unit_work + 0.5);
|
||||
if (resource && pp->p_nrdep != 0) {
|
||||
if (*resource * 100 < pp->p_nrdep * max)
|
||||
max = *resource * 100 / pp->p_nrdep;
|
||||
}
|
||||
res_limit = prod_resource_limit(pp, resource);
|
||||
if (max > res_limit)
|
||||
max = res_limit;
|
||||
act = MIN(used, max);
|
||||
|
||||
real = (double)act * prodeff;
|
||||
|
|
|
@ -57,7 +57,7 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
|
|||
int unit_work;
|
||||
i_type item;
|
||||
int worker_limit;
|
||||
int material_limit;
|
||||
int material_limit, res_limit;
|
||||
int material_consume;
|
||||
int val;
|
||||
|
||||
|
@ -93,10 +93,9 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
|
|||
worker_limit = roundavg(work * p_e / unit_work);
|
||||
if (material_consume > worker_limit)
|
||||
material_consume = worker_limit;
|
||||
if (resource && product->p_nrdep != 0) {
|
||||
if (*resource * 100 < product->p_nrdep * material_consume)
|
||||
material_consume = *resource * 100 / product->p_nrdep;
|
||||
}
|
||||
res_limit = prod_resource_limit(product, resource);
|
||||
if (material_consume > res_limit)
|
||||
material_consume = res_limit;
|
||||
if (material_consume == 0)
|
||||
return 0;
|
||||
prodeff = prod_eff(desig, np->nat_level[product->p_nlndx]);
|
||||
|
@ -217,6 +216,20 @@ materials_charge(struct pchrstr *pp, short *vec, int count)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return how much of product PP can be made from its resource.
|
||||
* If PP depletes a resource, RESOURCE must point to its value.
|
||||
*/
|
||||
int
|
||||
prod_resource_limit(struct pchrstr *pp, unsigned char *resource)
|
||||
{
|
||||
if (CANT_HAPPEN(pp->p_nrndx && !resource))
|
||||
return 0;
|
||||
if (resource && pp->p_nrdep != 0)
|
||||
return *resource * 100 / pp->p_nrdep;
|
||||
return ITEM_MAX;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return p.e. for sector type TYPE.
|
||||
* Zero means level is too low for production.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue