(feed_land): Simplify. Amount of food taken from ship could be off by
one due to rounding, fix. However, the fixed code is currently unreachable, as caller runs resupply_commod() before feed_land(). (feed_ship): Simplify. No functional changes.
This commit is contained in:
parent
0652930d67
commit
abaf9e06ec
2 changed files with 36 additions and 52 deletions
|
@ -364,29 +364,32 @@ feed_land(struct lndstr *lp, register int *vec, int etus, int *needed,
|
||||||
int doit)
|
int doit)
|
||||||
{
|
{
|
||||||
double food_eaten, ship_eaten;
|
double food_eaten, ship_eaten;
|
||||||
|
int ifood_eaten;
|
||||||
double people_left;
|
double people_left;
|
||||||
int can_eat, need;
|
int need;
|
||||||
int total_people;
|
int total_people;
|
||||||
int starved;
|
int starved;
|
||||||
struct lchrstr *lcp;
|
|
||||||
struct shpstr *sp;
|
struct shpstr *sp;
|
||||||
|
|
||||||
if (opt_NOFOOD)
|
if (opt_NOFOOD)
|
||||||
return 0; /* no food no work to be done */
|
return 0; /* no food no work to be done */
|
||||||
|
|
||||||
lcp = &lchr[(int)lp->lnd_type];
|
total_people = total_mil(lp);
|
||||||
|
food_eaten = etus * eatrate * total_people;
|
||||||
food_eaten = (etus * eatrate) * total_mil(lp);
|
ifood_eaten = (int)food_eaten;
|
||||||
|
if (food_eaten - ifood_eaten > 0)
|
||||||
|
ifood_eaten++;
|
||||||
starved = 0;
|
starved = 0;
|
||||||
*needed = 0;
|
*needed = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we're on a ship, and we don't have enough food,
|
* If we're on a ship, and we don't have enough food,
|
||||||
* get some food off the carrying ship. (Don't starve
|
* get some food off the carrying ship. (Don't starve
|
||||||
* the ship, tho...
|
* the ship, tho...
|
||||||
*/
|
*/
|
||||||
/* doit - Only try to take food off the ship during the update */
|
/* doit - Only try to take food off the ship during the update */
|
||||||
if ((food_eaten > vec[I_FOOD]) && (lp->lnd_ship >= 0) && doit) {
|
if (ifood_eaten > vec[I_FOOD] && lp->lnd_ship >= 0 && doit) {
|
||||||
need = (int)food_eaten - vec[I_FOOD];
|
need = ifood_eaten - vec[I_FOOD];
|
||||||
sp = getshipp(lp->lnd_ship);
|
sp = getshipp(lp->lnd_ship);
|
||||||
ship_eaten = etus * eatrate * (sp->shp_item[I_CIVIL]
|
ship_eaten = etus * eatrate * (sp->shp_item[I_CIVIL]
|
||||||
+ sp->shp_item[I_MILIT]
|
+ sp->shp_item[I_MILIT]
|
||||||
|
@ -400,26 +403,13 @@ feed_land(struct lndstr *lp, register int *vec, int etus, int *needed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (food_eaten > vec[I_FOOD]) {
|
if (ifood_eaten > vec[I_FOOD]) {
|
||||||
*needed = food_eaten - vec[I_FOOD];
|
*needed = ifood_eaten - vec[I_FOOD];
|
||||||
if (*needed < (food_eaten - vec[I_FOOD]))
|
|
||||||
(*needed)++;
|
|
||||||
can_eat = (vec[I_FOOD] / (etus * eatrate));
|
|
||||||
total_people = total_mil(lp);
|
|
||||||
/* only want to starve off at most 1/2 the populace. */
|
|
||||||
if (can_eat < (total_people / 2))
|
|
||||||
can_eat = total_people / 2;
|
|
||||||
|
|
||||||
people_left = (vec[I_FOOD] + 0.01) / (food_eaten + 0.01);
|
people_left = (vec[I_FOOD] + 0.01) / (food_eaten + 0.01);
|
||||||
/* only want to starve off at most 1/2 the populace. */
|
/* only want to starve off at most 1/2 the populace. */
|
||||||
if (people_left < 0.5)
|
if (people_left < 0.5)
|
||||||
people_left = 0.5;
|
people_left = 0.5;
|
||||||
/* lp->lnd_effic *= people_left;*/
|
starved = total_people * (1 - people_left);
|
||||||
starved = vec[I_MILIT] - (vec[I_MILIT] * people_left);
|
|
||||||
/* if (!player->simulation)
|
|
||||||
wu(0, lp->lnd_own, "%d mil starved on unit %s.\n",
|
|
||||||
starved,
|
|
||||||
prland(lp));*/
|
|
||||||
vec[I_MILIT] -= starved;
|
vec[I_MILIT] -= starved;
|
||||||
vec[I_FOOD] = 0;
|
vec[I_FOOD] = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -438,47 +438,41 @@ feed_ship(struct shpstr *sp, register int *vec, int etus, int *needed,
|
||||||
if (opt_NOFOOD)
|
if (opt_NOFOOD)
|
||||||
return 0; /* no food no work to do */
|
return 0; /* no food no work to do */
|
||||||
|
|
||||||
food_eaten =
|
total_people = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW];
|
||||||
(etus * eatrate) * (vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]);
|
food_eaten = etus * eatrate * total_people;
|
||||||
ifood_eaten = (int)food_eaten;
|
ifood_eaten = (int)food_eaten;
|
||||||
if ((food_eaten - ifood_eaten) > 0)
|
if (food_eaten - ifood_eaten > 0)
|
||||||
ifood_eaten++;
|
ifood_eaten++;
|
||||||
starved = 0;
|
starved = 0;
|
||||||
*needed = 0;
|
*needed = 0;
|
||||||
if (!player->simulation && food_eaten > vec[I_FOOD])
|
if (!player->simulation && ifood_eaten > vec[I_FOOD])
|
||||||
vec[I_FOOD] += supply_commod(sp->shp_own, sp->shp_x, sp->shp_y,
|
vec[I_FOOD] += supply_commod(sp->shp_own, sp->shp_x, sp->shp_y,
|
||||||
I_FOOD, (ifood_eaten - vec[I_FOOD]));
|
I_FOOD, ifood_eaten - vec[I_FOOD]);
|
||||||
|
|
||||||
if (food_eaten > vec[I_FOOD]) {
|
|
||||||
/* doit - only steal food from land units during the update */
|
/* doit - only steal food from land units during the update */
|
||||||
if (sp->shp_nland > 0 && doit) {
|
if (ifood_eaten > vec[I_FOOD] && sp->shp_nland > 0 && doit) {
|
||||||
snxtitem_all(&ni, EF_LAND);
|
snxtitem_all(&ni, EF_LAND);
|
||||||
while ((lp = (struct lndstr *)nxtitemp(&ni, 0)) &&
|
while ((lp = (struct lndstr *)nxtitemp(&ni, 0)) &&
|
||||||
(food_eaten > vec[I_FOOD])) {
|
ifood_eaten > vec[I_FOOD]) {
|
||||||
if (lp->lnd_ship != sp->shp_uid)
|
if (lp->lnd_ship != sp->shp_uid)
|
||||||
continue;
|
continue;
|
||||||
need = ifood_eaten - vec[I_FOOD];
|
need = ifood_eaten - vec[I_FOOD];
|
||||||
land_eaten = (etus * eatrate) * (double)lnd_getmil(lp);
|
land_eaten = etus * eatrate * lnd_getmil(lp);
|
||||||
if (lp->lnd_item[I_FOOD] - need > land_eaten) {
|
if (lp->lnd_item[I_FOOD] - need > land_eaten) {
|
||||||
vec[I_FOOD] += need;
|
vec[I_FOOD] += need;
|
||||||
lp->lnd_item[I_FOOD] -= need;
|
lp->lnd_item[I_FOOD] -= need;
|
||||||
} else if (lp->lnd_item[I_FOOD] - land_eaten > 0) {
|
} else if (lp->lnd_item[I_FOOD] - land_eaten > 0) {
|
||||||
vec[I_FOOD] += lp->lnd_item[I_FOOD] - land_eaten;
|
vec[I_FOOD] += lp->lnd_item[I_FOOD] - land_eaten;
|
||||||
lp->lnd_item[I_FOOD] -= lp->lnd_item[I_FOOD] - land_eaten;
|
lp->lnd_item[I_FOOD] -= lp->lnd_item[I_FOOD] - land_eaten;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (food_eaten > vec[I_FOOD]) {
|
if (ifood_eaten > vec[I_FOOD]) {
|
||||||
*needed = food_eaten - vec[I_FOOD];
|
*needed = ifood_eaten - vec[I_FOOD];
|
||||||
if (*needed < (food_eaten - vec[I_FOOD]))
|
can_eat = vec[I_FOOD] / (etus * eatrate);
|
||||||
(*needed)++;
|
|
||||||
can_eat = (vec[I_FOOD] / (etus * eatrate));
|
|
||||||
total_people = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW];
|
|
||||||
|
|
||||||
/* only want to starve off at most 1/2 the populace. */
|
/* only want to starve off at most 1/2 the populace. */
|
||||||
if (can_eat < (total_people / 2))
|
if (can_eat < total_people / 2)
|
||||||
can_eat = total_people / 2;
|
can_eat = total_people / 2;
|
||||||
|
|
||||||
to_starve = total_people - can_eat;
|
to_starve = total_people - can_eat;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue