update: Push budget update into produce(), enlist()
produce() and enlist store the cost through a parameter and return the amount. Their caller produce_sect() then updates nat_budget[] accordingly. Move the nat_budget[] update into the callees. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
a5314a59c4
commit
058268595f
3 changed files with 29 additions and 32 deletions
|
@ -130,7 +130,7 @@ extern void upd_slmilcosts(int, natid);
|
||||||
extern void bank_income(struct sctstr *, int);
|
extern void bank_income(struct sctstr *, int);
|
||||||
extern void pay_reserve(struct natstr *, int);
|
extern void pay_reserve(struct natstr *, int);
|
||||||
/* produce.c */
|
/* produce.c */
|
||||||
extern int produce(struct natstr *, struct sctstr *, int *);
|
extern void produce(struct natstr *, struct sctstr *);
|
||||||
extern int prod_materials_cost(struct pchrstr *, short[], int *);
|
extern int prod_materials_cost(struct pchrstr *, short[], int *);
|
||||||
extern int prod_resource_limit(struct pchrstr *, unsigned char *);
|
extern int prod_resource_limit(struct pchrstr *, unsigned char *);
|
||||||
extern double prod_eff(int, float);
|
extern double prod_eff(int, float);
|
||||||
|
|
|
@ -46,9 +46,10 @@ static char *levelnames[] = {
|
||||||
"Technology", "Research", "Education", "Happiness"
|
"Technology", "Research", "Education", "Happiness"
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
void
|
||||||
produce(struct natstr *np, struct sctstr *sp, int *cost)
|
produce(struct natstr *np, struct sctstr *sp)
|
||||||
{
|
{
|
||||||
|
struct budget *budget = &nat_budget[sp->sct_own];
|
||||||
struct pchrstr *product;
|
struct pchrstr *product;
|
||||||
double p_e;
|
double p_e;
|
||||||
double prodeff;
|
double prodeff;
|
||||||
|
@ -61,21 +62,21 @@ produce(struct natstr *np, struct sctstr *sp, int *cost)
|
||||||
int material_limit, res_limit;
|
int material_limit, res_limit;
|
||||||
int material_consume;
|
int material_consume;
|
||||||
int val;
|
int val;
|
||||||
|
int cost;
|
||||||
|
|
||||||
if (dchr[sp->sct_type].d_prd < 0)
|
if (dchr[sp->sct_type].d_prd < 0)
|
||||||
return 0;
|
return;
|
||||||
product = &pchr[dchr[sp->sct_type].d_prd];
|
product = &pchr[dchr[sp->sct_type].d_prd];
|
||||||
item = product->p_type;
|
item = product->p_type;
|
||||||
if (product->p_nrndx)
|
if (product->p_nrndx)
|
||||||
resource = (unsigned char *)sp + product->p_nrndx;
|
resource = (unsigned char *)sp + product->p_nrndx;
|
||||||
else
|
else
|
||||||
resource = NULL;
|
resource = NULL;
|
||||||
*cost = 0;
|
|
||||||
|
|
||||||
material_limit = prod_materials_cost(product, sp->sct_item,
|
material_limit = prod_materials_cost(product, sp->sct_item,
|
||||||
&unit_work);
|
&unit_work);
|
||||||
if (material_limit <= 0)
|
if (material_limit <= 0)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
/* sector p.e. */
|
/* sector p.e. */
|
||||||
p_e = sp->sct_effic / 100.0;
|
p_e = sp->sct_effic / 100.0;
|
||||||
|
@ -95,7 +96,7 @@ produce(struct natstr *np, struct sctstr *sp, int *cost)
|
||||||
if (material_consume > material_limit)
|
if (material_consume > material_limit)
|
||||||
material_consume = material_limit;
|
material_consume = material_limit;
|
||||||
if (material_consume == 0)
|
if (material_consume == 0)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
prodeff = prod_eff(sp->sct_type, np->nat_level[product->p_nlndx]);
|
prodeff = prod_eff(sp->sct_type, np->nat_level[product->p_nlndx]);
|
||||||
if (prodeff <= 0.0) {
|
if (prodeff <= 0.0) {
|
||||||
|
@ -103,7 +104,7 @@ produce(struct natstr *np, struct sctstr *sp, int *cost)
|
||||||
wu(0, sp->sct_own,
|
wu(0, sp->sct_own,
|
||||||
"%s level too low to produce in %s (need %d)\n",
|
"%s level too low to produce in %s (need %d)\n",
|
||||||
levelnames[product->p_nlndx], ownxy(sp), product->p_nlmin);
|
levelnames[product->p_nlndx], ownxy(sp), product->p_nlmin);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Adjust produced amount by commodity production ratio
|
* Adjust produced amount by commodity production ratio
|
||||||
|
@ -119,7 +120,7 @@ produce(struct natstr *np, struct sctstr *sp, int *cost)
|
||||||
} else {
|
} else {
|
||||||
actual = roundavg(output);
|
actual = roundavg(output);
|
||||||
if (actual <= 0)
|
if (actual <= 0)
|
||||||
return 0;
|
return;
|
||||||
if (actual > 999) {
|
if (actual > 999) {
|
||||||
actual = 999;
|
actual = 999;
|
||||||
material_consume = roundavg(actual / prodeff);
|
material_consume = roundavg(actual / prodeff);
|
||||||
|
@ -151,22 +152,26 @@ produce(struct natstr *np, struct sctstr *sp, int *cost)
|
||||||
val = 0;
|
val = 0;
|
||||||
*resource = val;
|
*resource = val;
|
||||||
}
|
}
|
||||||
*cost = product->p_cost * material_consume;
|
|
||||||
|
|
||||||
|
cost = product->p_cost * material_consume;
|
||||||
if (opt_TECH_POP) {
|
if (opt_TECH_POP) {
|
||||||
if (product->p_level == NAT_TLEV) {
|
if (product->p_level == NAT_TLEV) {
|
||||||
if (tpops[sp->sct_own] > 50000)
|
if (tpops[sp->sct_own] > 50000)
|
||||||
*cost *= tpops[sp->sct_own] / 50000.0;
|
cost *= tpops[sp->sct_own] / 50000.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
budget->prod[sp->sct_type].count += actual;
|
||||||
|
budget->prod[sp->sct_type].money -= cost;
|
||||||
|
if (!player->simulation)
|
||||||
|
np->nat_money -= cost;
|
||||||
|
|
||||||
if (CANT_HAPPEN(p_e <= 0.0))
|
if (CANT_HAPPEN(p_e <= 0.0))
|
||||||
return actual;
|
return;
|
||||||
work_used = roundavg(unit_work * material_consume / p_e);
|
work_used = roundavg(unit_work * material_consume / p_e);
|
||||||
if (CANT_HAPPEN(work_used > sp->sct_avail))
|
if (CANT_HAPPEN(work_used > sp->sct_avail))
|
||||||
work_used = sp->sct_avail;
|
work_used = sp->sct_avail;
|
||||||
sp->sct_avail -= work_used;
|
sp->sct_avail -= work_used;
|
||||||
return actual;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -96,8 +96,8 @@ buildeff(struct sctstr *sp)
|
||||||
* Conversion will happen much more slowly without
|
* Conversion will happen much more slowly without
|
||||||
* some mil initially.
|
* some mil initially.
|
||||||
*/
|
*/
|
||||||
static int
|
static void
|
||||||
enlist(short *vec, int etu, int *cost)
|
enlist(struct natstr *np, short *vec, int etu)
|
||||||
{
|
{
|
||||||
int maxmil;
|
int maxmil;
|
||||||
int enlisted;
|
int enlisted;
|
||||||
|
@ -111,8 +111,11 @@ enlist(short *vec, int etu, int *cost)
|
||||||
vec[I_CIVIL] -= enlisted;
|
vec[I_CIVIL] -= enlisted;
|
||||||
vec[I_MILIT] += enlisted;
|
vec[I_MILIT] += enlisted;
|
||||||
}
|
}
|
||||||
*cost = enlisted * 3;
|
|
||||||
return enlisted;
|
nat_budget[np->nat_cnum].prod[SCT_ENLIST].count += enlisted;
|
||||||
|
nat_budget[np->nat_cnum].prod[SCT_ENLIST].money -= enlisted * 3;
|
||||||
|
if (!player->simulation)
|
||||||
|
np->nat_money -= enlisted * 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fallout is calculated here. */
|
/* Fallout is calculated here. */
|
||||||
|
@ -227,8 +230,8 @@ produce_sect(struct natstr *np, int etu, struct bp *bp)
|
||||||
{
|
{
|
||||||
struct budget *budget = &nat_budget[np->nat_cnum];
|
struct budget *budget = &nat_budget[np->nat_cnum];
|
||||||
struct sctstr *sp, scratch_sect;
|
struct sctstr *sp, scratch_sect;
|
||||||
int cost, ecost, pcost;
|
int cost;
|
||||||
int n, amount;
|
int n;
|
||||||
|
|
||||||
for (n = 0; NULL != (sp = getsectid(n)); n++) {
|
for (n = 0; NULL != (sp = getsectid(n)); n++) {
|
||||||
if (sp->sct_type == SCT_WATER)
|
if (sp->sct_type == SCT_WATER)
|
||||||
|
@ -261,9 +264,6 @@ produce_sect(struct natstr *np, int etu, struct bp *bp)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
amount = 0;
|
|
||||||
pcost = cost = ecost = 0;
|
|
||||||
|
|
||||||
if (dchr[sp->sct_type].d_maint) {
|
if (dchr[sp->sct_type].d_maint) {
|
||||||
cost = etu * dchr[sp->sct_type].d_maint;
|
cost = etu * dchr[sp->sct_type].d_maint;
|
||||||
budget->bm[BUDG_SCT_MAINT].count++;
|
budget->bm[BUDG_SCT_MAINT].count++;
|
||||||
|
@ -283,11 +283,7 @@ produce_sect(struct natstr *np, int etu, struct bp *bp)
|
||||||
|
|
||||||
if (sp->sct_type == SCT_ENLIST && sp->sct_effic >= 60 &&
|
if (sp->sct_type == SCT_ENLIST && sp->sct_effic >= 60 &&
|
||||||
sp->sct_own == sp->sct_oldown) {
|
sp->sct_own == sp->sct_oldown) {
|
||||||
budget->prod[sp->sct_type].count
|
enlist(np, sp->sct_item, etu);
|
||||||
+= enlist(sp->sct_item, etu, &ecost);
|
|
||||||
budget->prod[sp->sct_type].money -= ecost;
|
|
||||||
if (!player->simulation)
|
|
||||||
np->nat_money -= ecost;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -296,13 +292,9 @@ produce_sect(struct natstr *np, int etu, struct bp *bp)
|
||||||
|
|
||||||
if (sp->sct_effic >= 60) {
|
if (sp->sct_effic >= 60) {
|
||||||
if (np->nat_money >= 0 && dchr[sp->sct_type].d_prd >= 0)
|
if (np->nat_money >= 0 && dchr[sp->sct_type].d_prd >= 0)
|
||||||
amount = produce(np, sp, &pcost);
|
produce(np, sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
bp_set_from_sect(bp, sp);
|
bp_set_from_sect(bp, sp);
|
||||||
budget->prod[sp->sct_type].count += amount;
|
|
||||||
budget->prod[sp->sct_type].money -= pcost;
|
|
||||||
if (!player->simulation)
|
|
||||||
np->nat_money -= pcost;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue