(build_ship, build_land, build_plane): Compute cost in floating-point.

It's better to round just once, when subtracting player->dolcost from
nat_money.
This commit is contained in:
Markus Armbruster 2006-03-25 16:36:45 +00:00
parent 2625dc4b8f
commit 2a3da4916e

View file

@ -288,7 +288,8 @@ build_ship(struct sctstr *sp, struct mchrstr *mp,
{ {
struct shpstr ship; struct shpstr ship;
struct nstr_item nstr; struct nstr_item nstr;
int avail, cost, i; int avail, i;
double cost;
float eff = SHIP_MINEFF / 100.0; float eff = SHIP_MINEFF / 100.0;
int lcm, hcm; int lcm, hcm;
int freeship = 0; int freeship = 0;
@ -317,7 +318,7 @@ build_ship(struct sctstr *sp, struct mchrstr *mp,
pr(" (%d available work required)\n", avail); pr(" (%d available work required)\n", avail);
return 0; return 0;
} }
cost = mp->m_cost * SHIP_MINEFF / 100; cost = mp->m_cost * SHIP_MINEFF / 100.0;
if (!build_can_afford(cost, mp->m_name)) if (!build_can_afford(cost, mp->m_name))
return 0; return 0;
if (!trechk(player->cnum, 0, NEWSHP)) if (!trechk(player->cnum, 0, NEWSHP))
@ -401,7 +402,8 @@ build_land(struct sctstr *sp, struct lchrstr *lp,
{ {
struct lndstr land; struct lndstr land;
struct nstr_item nstr; struct nstr_item nstr;
int avail, cost; int avail;
double cost;
float eff = LAND_MINEFF / 100.0; float eff = LAND_MINEFF / 100.0;
int mil, lcm, hcm, gun, shell; int mil, lcm, hcm, gun, shell;
int freeland = 0; int freeland = 0;
@ -458,7 +460,7 @@ build_land(struct sctstr *sp, struct lchrstr *lp,
pr(" (%d available work required)\n", avail); pr(" (%d available work required)\n", avail);
return 0; return 0;
} }
cost = lp->l_cost * LAND_MINEFF / 100; cost = lp->l_cost * LAND_MINEFF / 100.0;
if (!build_can_afford(cost, lp->l_name)) if (!build_can_afford(cost, lp->l_name))
return 0; return 0;
sp->sct_avail -= avail; sp->sct_avail -= avail;
@ -688,8 +690,9 @@ build_plane(struct sctstr *sp, struct plchrstr *pp,
short *vec, int tlev) short *vec, int tlev)
{ {
struct plnstr plane; struct plnstr plane;
int avail, cost;
struct nstr_item nstr; struct nstr_item nstr;
int avail;
double cost;
float eff = PLANE_MINEFF / 100.0; float eff = PLANE_MINEFF / 100.0;
int hcm, lcm, mil; int hcm, lcm, mil;
int freeplane = 0; int freeplane = 0;
@ -721,7 +724,7 @@ build_plane(struct sctstr *sp, struct plchrstr *pp,
pr(" (%d available work required)\n", avail); pr(" (%d available work required)\n", avail);
return 0; return 0;
} }
cost = pp->pl_cost * PLANE_MINEFF / 100; cost = pp->pl_cost * PLANE_MINEFF / 100.0;
if (!build_can_afford(cost, pp->pl_name)) if (!build_can_afford(cost, pp->pl_name))
return 0; return 0;
if (vec[I_MILIT] < mil || (vec[I_MILIT] == 0 && pp->pl_crew > 0)) { if (vec[I_MILIT] < mil || (vec[I_MILIT] == 0 && pp->pl_crew > 0)) {