(get_materials): Redesign.
(shiprepair, planerepair, landrepair): Use it. Behavioral change: ship repairs outside harbors and plane repairs by a carrier can use fewer materials. Before, such repairs consumed each required commodity as far as available. Now, they consume the same fraction of the real cost of each commodity, i.e. commodity use is limited by the most scarce commodity. Neither old nor new behavior make much sense, but the new code is simpler.
This commit is contained in:
parent
63bdc89835
commit
ac9cdf5bb9
5 changed files with 51 additions and 127 deletions
|
@ -42,7 +42,7 @@
|
||||||
void fill_update_array(int *bp, struct sctstr *sp);
|
void fill_update_array(int *bp, struct sctstr *sp);
|
||||||
int gt_bg_nmbr(int *bp, struct sctstr *sp, i_type comm);
|
int gt_bg_nmbr(int *bp, struct sctstr *sp, i_type comm);
|
||||||
void pt_bg_nmbr(int *bp, struct sctstr *sp, i_type comm, int amount);
|
void pt_bg_nmbr(int *bp, struct sctstr *sp, i_type comm, int amount);
|
||||||
void get_materials(struct sctstr *sp, int *bp, int *mvec, int check);
|
int get_materials(struct sctstr *, int *, int *, int);
|
||||||
|
|
||||||
extern long money[MAXNOC];
|
extern long money[MAXNOC];
|
||||||
extern long pops[MAXNOC];
|
extern long pops[MAXNOC];
|
||||||
|
|
|
@ -213,16 +213,13 @@ upd_land(struct lndstr *lp, int etus,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*ARGSUSED*/
|
|
||||||
static void
|
static void
|
||||||
landrepair(struct lndstr *land, struct natstr *np, int *bp, int etus)
|
landrepair(struct lndstr *land, struct natstr *np, int *bp, int etus)
|
||||||
{
|
{
|
||||||
int delta;
|
int delta;
|
||||||
struct sctstr *sp;
|
struct sctstr *sp;
|
||||||
struct lchrstr *lp;
|
struct lchrstr *lp;
|
||||||
float leftp, buildp;
|
int build;
|
||||||
int left, build;
|
|
||||||
int mil_needed, lcm_needed, hcm_needed, gun_needed, shell_needed;
|
|
||||||
int avail;
|
int avail;
|
||||||
int w_p_eff;
|
int w_p_eff;
|
||||||
int mult;
|
int mult;
|
||||||
|
@ -255,53 +252,13 @@ landrepair(struct lndstr *land, struct natstr *np, int *bp, int etus)
|
||||||
return;
|
return;
|
||||||
if (delta > (int)((float)etus * land_grow_scale))
|
if (delta > (int)((float)etus * land_grow_scale))
|
||||||
delta = (int)((float)etus * land_grow_scale);
|
delta = (int)((float)etus * land_grow_scale);
|
||||||
|
if (delta > 100 - land->lnd_effic)
|
||||||
/* delta is the max amount we can grow */
|
delta = 100 - land->lnd_effic;
|
||||||
|
|
||||||
left = 100 - land->lnd_effic;
|
|
||||||
if (left > delta)
|
|
||||||
left = delta;
|
|
||||||
|
|
||||||
leftp = left / 100.0;
|
|
||||||
|
|
||||||
memset(mvec, 0, sizeof(mvec));
|
memset(mvec, 0, sizeof(mvec));
|
||||||
mvec[I_LCM] = lcm_needed = ldround(lp->l_lcm * leftp, 1);
|
mvec[I_LCM] = lp->l_lcm;
|
||||||
mvec[I_HCM] = hcm_needed = ldround(lp->l_hcm * leftp, 1);
|
mvec[I_HCM] = lp->l_hcm;
|
||||||
/*
|
build = get_materials(sp, bp, mvec, delta);
|
||||||
mvec[I_GUN] = gun_needed = ldround(lp->l_gun * leftp, 1);
|
|
||||||
mvec[I_MILIT] = mil_needed = ldround(lp->l_mil * leftp, 1);
|
|
||||||
mvec[I_SHELL] = shell_needed = ldround(lp->l_shell *leftp, 1);
|
|
||||||
*/
|
|
||||||
mvec[I_GUN] = gun_needed = 0;
|
|
||||||
mvec[I_MILIT] = mil_needed = 0;
|
|
||||||
mvec[I_SHELL] = shell_needed = 0;
|
|
||||||
get_materials(sp, bp, mvec, 0);
|
|
||||||
|
|
||||||
buildp = leftp;
|
|
||||||
if (mvec[I_MILIT] < mil_needed)
|
|
||||||
buildp = MIN(buildp, (float)mvec[I_MILIT] / (float)lp->l_mil);
|
|
||||||
if (mvec[I_LCM] < lcm_needed)
|
|
||||||
buildp = MIN(buildp, (float)mvec[I_LCM] / (float)lp->l_lcm);
|
|
||||||
if (mvec[I_HCM] < hcm_needed)
|
|
||||||
buildp = MIN(buildp, (float)mvec[I_HCM] / (float)lp->l_hcm);
|
|
||||||
if (mvec[I_GUN] < gun_needed)
|
|
||||||
buildp = MIN(buildp, (float)mvec[I_GUN] / (float)lp->l_gun);
|
|
||||||
if (mvec[I_SHELL] < shell_needed)
|
|
||||||
buildp = MIN(buildp, (float)mvec[I_SHELL] / (float)lp->l_shell);
|
|
||||||
|
|
||||||
build = ldround(buildp * 100.0, 1);
|
|
||||||
memset(mvec, 0, sizeof(mvec));
|
|
||||||
mvec[I_LCM] = roundavg(lp->l_lcm * buildp);
|
|
||||||
mvec[I_HCM] = roundavg(lp->l_hcm * buildp);
|
|
||||||
/*
|
|
||||||
mvec[I_GUN] = roundavg(lp->l_gun * buildp);
|
|
||||||
mvec[I_MILIT] = roundavg(lp->l_mil * buildp);
|
|
||||||
mvec[I_SHELL] = roundavg(lp->l_shell *buildp);
|
|
||||||
*/
|
|
||||||
mvec[I_GUN] = 0;
|
|
||||||
mvec[I_MILIT] = 0;
|
|
||||||
mvec[I_SHELL] = 0;
|
|
||||||
get_materials(sp, bp, mvec, 1);
|
|
||||||
|
|
||||||
if ((sp->sct_type != SCT_HEADQ) && (sp->sct_type != SCT_FORTR))
|
if ((sp->sct_type != SCT_HEADQ) && (sp->sct_type != SCT_FORTR))
|
||||||
build /= 3;
|
build /= 3;
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Ville Virrankoski, 1996
|
* Ville Virrankoski, 1996
|
||||||
|
* Markus Armbruster, 2007
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -37,30 +38,39 @@
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "update.h"
|
#include "update.h"
|
||||||
|
|
||||||
void
|
/*
|
||||||
get_materials(struct sctstr *sp, int *bp, int *mvec, int check)
|
* Get build materials from sector SP.
|
||||||
/* only check if found=0, remove them=1 */
|
* BP is the sector's build pointer.
|
||||||
|
* MVEC[] defines the materials needed to build 100%.
|
||||||
|
* PCT is the percentage to build.
|
||||||
|
* Adjust build percentage downwards so that available materials
|
||||||
|
* suffice. Remove the materials.
|
||||||
|
* Return adjusted build percentage.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
get_materials(struct sctstr *sp, int *bp, int *mvec, int pct)
|
||||||
{
|
{
|
||||||
i_type i;
|
int i, amt;
|
||||||
int still_left;
|
|
||||||
|
|
||||||
for (i = I_NONE + 1; i <= I_MAX; i++) {
|
for (i = I_NONE + 1; i <= I_MAX; i++) {
|
||||||
if (mvec[i] == 0)
|
if (mvec[i] == 0)
|
||||||
continue;
|
continue;
|
||||||
|
amt = gt_bg_nmbr(bp, sp, i);
|
||||||
if (check) {
|
if (amt * 100 < mvec[i] * pct)
|
||||||
still_left = gt_bg_nmbr(bp, sp, i);
|
pct = amt * 100 / mvec[i];
|
||||||
if ((still_left - mvec[i]) < 0)
|
|
||||||
still_left = 0;
|
|
||||||
else
|
|
||||||
still_left -= mvec[i];
|
|
||||||
pt_bg_nmbr(bp, sp, i, still_left);
|
|
||||||
if (!player->simulation)
|
|
||||||
sp->sct_item[i] = still_left;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
still_left = gt_bg_nmbr(bp, sp, i);
|
|
||||||
mvec[i] = MIN(mvec[i], still_left);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = I_NONE + 1; i <= I_MAX; i++) {
|
||||||
|
if (mvec[i] == 0)
|
||||||
|
continue;
|
||||||
|
amt = gt_bg_nmbr(bp, sp, i);
|
||||||
|
amt -= roundavg(mvec[i] * pct / 100.0);
|
||||||
|
if (CANT_HAPPEN(amt < 0))
|
||||||
|
amt = 0;
|
||||||
|
pt_bg_nmbr(bp, sp, i, amt);
|
||||||
|
if (!player->simulation)
|
||||||
|
sp->sct_item[i] = amt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pct;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,9 +127,7 @@ upd_plane(struct plnstr *pp, int etus,
|
||||||
static void
|
static void
|
||||||
planerepair(struct plnstr *pp, struct natstr *np, int *bp, int etus)
|
planerepair(struct plnstr *pp, struct natstr *np, int *bp, int etus)
|
||||||
{
|
{
|
||||||
float leftp, buildp;
|
int build;
|
||||||
int left, build;
|
|
||||||
int mil_needed, lcm_needed, hcm_needed;
|
|
||||||
int mvec[I_MAX + 1];
|
int mvec[I_MAX + 1];
|
||||||
struct shpstr *carrier;
|
struct shpstr *carrier;
|
||||||
struct plchrstr *pcp = &plchr[(int)pp->pln_type];
|
struct plchrstr *pcp = &plchr[(int)pp->pln_type];
|
||||||
|
@ -180,34 +178,14 @@ planerepair(struct plnstr *pp, struct natstr *np, int *bp, int etus)
|
||||||
return;
|
return;
|
||||||
if (delta > (int)((float)etus * plane_grow_scale))
|
if (delta > (int)((float)etus * plane_grow_scale))
|
||||||
delta = (int)((float)etus * plane_grow_scale);
|
delta = (int)((float)etus * plane_grow_scale);
|
||||||
|
if (delta > 100 - pp->pln_effic)
|
||||||
|
delta = 100 - pp->pln_effic;
|
||||||
|
|
||||||
/* delta is the max amount we can grow */
|
|
||||||
|
|
||||||
left = 100 - pp->pln_effic;
|
|
||||||
if (left > delta)
|
|
||||||
left = delta;
|
|
||||||
|
|
||||||
leftp = left / 100.0;
|
|
||||||
memset(mvec, 0, sizeof(mvec));
|
memset(mvec, 0, sizeof(mvec));
|
||||||
mvec[I_MILIT] = mil_needed = ldround(pcp->pl_crew * leftp, 1);
|
mvec[I_MILIT] = pcp->pl_crew;
|
||||||
mvec[I_LCM] = lcm_needed = ldround(pcp->pl_lcm * leftp, 1);
|
mvec[I_LCM] = pcp->pl_lcm;
|
||||||
mvec[I_HCM] = hcm_needed = ldround(pcp->pl_hcm * leftp, 1);
|
mvec[I_HCM] = pcp->pl_hcm;
|
||||||
get_materials(sp, bp, mvec, 0);
|
build = get_materials(sp, bp, mvec, delta);
|
||||||
|
|
||||||
buildp = leftp;
|
|
||||||
if (mvec[I_MILIT] < mil_needed)
|
|
||||||
buildp = MIN(buildp, (float)mvec[I_MILIT] / (float)pcp->pl_crew);
|
|
||||||
if (mvec[I_LCM] < lcm_needed)
|
|
||||||
buildp = MIN(buildp, (float)mvec[I_LCM] / (float)pcp->pl_lcm);
|
|
||||||
if (mvec[I_HCM] < hcm_needed)
|
|
||||||
buildp = MIN(buildp, (float)mvec[I_HCM] / (float)pcp->pl_hcm);
|
|
||||||
|
|
||||||
build = ldround(buildp * 100.0, 1);
|
|
||||||
memset(mvec, 0, sizeof(mvec));
|
|
||||||
mvec[I_MILIT] = roundavg(pcp->pl_crew * buildp);
|
|
||||||
mvec[I_LCM] = roundavg(pcp->pl_lcm * buildp);
|
|
||||||
mvec[I_HCM] = roundavg(pcp->pl_hcm * buildp);
|
|
||||||
get_materials(sp, bp, mvec, 1);
|
|
||||||
|
|
||||||
if (carrier)
|
if (carrier)
|
||||||
build = delta;
|
build = delta;
|
||||||
|
|
|
@ -271,9 +271,7 @@ shiprepair(struct shpstr *ship, struct natstr *np, int *bp, int etus)
|
||||||
int delta;
|
int delta;
|
||||||
struct sctstr *sp;
|
struct sctstr *sp;
|
||||||
struct mchrstr *mp;
|
struct mchrstr *mp;
|
||||||
float leftp, buildp;
|
int build;
|
||||||
int left, build;
|
|
||||||
int lcm_needed, hcm_needed;
|
|
||||||
int wf;
|
int wf;
|
||||||
int avail;
|
int avail;
|
||||||
int w_p_eff;
|
int w_p_eff;
|
||||||
|
@ -322,41 +320,22 @@ shiprepair(struct shpstr *ship, struct natstr *np, int *bp, int etus)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
left = 100 - ship->shp_effic;
|
|
||||||
delta = roundavg((double)avail / w_p_eff);
|
delta = roundavg((double)avail / w_p_eff);
|
||||||
if (delta <= 0)
|
if (delta <= 0)
|
||||||
return;
|
return;
|
||||||
if (delta > (int)((float)etus * ship_grow_scale))
|
if (delta > (int)((float)etus * ship_grow_scale))
|
||||||
delta = (int)((float)etus * ship_grow_scale);
|
delta = (int)((float)etus * ship_grow_scale);
|
||||||
if (delta > left)
|
if (delta > 100 - ship->shp_effic)
|
||||||
delta = left;
|
delta = 100 - ship->shp_effic;
|
||||||
|
|
||||||
/* delta is the max amount we can grow */
|
|
||||||
|
|
||||||
left = 100 - ship->shp_effic;
|
|
||||||
if (left > delta)
|
|
||||||
left = delta;
|
|
||||||
|
|
||||||
leftp = left / 100.0;
|
|
||||||
memset(mvec, 0, sizeof(mvec));
|
memset(mvec, 0, sizeof(mvec));
|
||||||
mvec[I_LCM] = lcm_needed = ldround(mp->m_lcm * leftp, 1);
|
mvec[I_LCM] = mp->m_lcm;
|
||||||
mvec[I_HCM] = hcm_needed = ldround(mp->m_hcm * leftp, 1);
|
mvec[I_HCM] = mp->m_hcm;
|
||||||
get_materials(sp, bp, mvec, 0);
|
build = get_materials(sp, bp, mvec, delta);
|
||||||
|
|
||||||
buildp = leftp;
|
|
||||||
if (mvec[I_LCM] < lcm_needed)
|
|
||||||
buildp = MIN(buildp, (float)mvec[I_LCM] / (float)mp->m_lcm);
|
|
||||||
if (mvec[I_HCM] < hcm_needed)
|
|
||||||
buildp = MIN(buildp, (float)mvec[I_HCM] / (float)mp->m_hcm);
|
|
||||||
|
|
||||||
build = ldround(buildp * 100.0, 1);
|
|
||||||
memset(mvec, 0, sizeof(mvec));
|
|
||||||
mvec[I_LCM] = roundavg(mp->m_lcm * buildp);
|
|
||||||
mvec[I_HCM] = roundavg(mp->m_hcm * buildp);
|
|
||||||
get_materials(sp, bp, mvec, 1);
|
|
||||||
|
|
||||||
if (sp->sct_type != SCT_HARBR)
|
if (sp->sct_type != SCT_HARBR)
|
||||||
build = delta;
|
build = delta;
|
||||||
|
|
||||||
wf -= build * w_p_eff;
|
wf -= build * w_p_eff;
|
||||||
if (wf < 0) {
|
if (wf < 0) {
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue