(s_commod): Clarify and comment the trickery required to make the
recursion work. By the way, resuppling from supply units in unit id order is a greedy algorithm, which is quite inappropriate for the problem.
This commit is contained in:
parent
e6ffdb71ee
commit
d35085e5c4
1 changed files with 15 additions and 9 deletions
|
@ -390,22 +390,28 @@ s_commod(int own, int x, int y, int type, int total_wanted,
|
||||||
|
|
||||||
if ((vec[type] - wanted) < get_minimum(&land, type)) {
|
if ((vec[type] - wanted) < get_minimum(&land, type)) {
|
||||||
int hold;
|
int hold;
|
||||||
struct lndstr l2;
|
struct lndstr save;
|
||||||
|
|
||||||
l2 = land;
|
/*
|
||||||
|
* Temporarily zap this unit's store, so the recursion
|
||||||
|
* avoids it.
|
||||||
|
*/
|
||||||
|
save = land;
|
||||||
hold = vec[type];
|
hold = vec[type];
|
||||||
vec[type] = 0;
|
vec[type] = 0;
|
||||||
putvec(VT_ITEM, vec, (s_char *)&land, EF_LAND);
|
putvec(VT_ITEM, vec, (s_char *)&land, EF_LAND);
|
||||||
land.lnd_fuel = 0;
|
land.lnd_fuel = 0;
|
||||||
putland(land.lnd_uid, &land);
|
putland(land.lnd_uid, &land);
|
||||||
hold +=
|
|
||||||
s_commod(own, land.lnd_x, land.lnd_y, type, wanted,
|
hold += s_commod(own, land.lnd_x, land.lnd_y, type, wanted,
|
||||||
actually_doit);
|
actually_doit);
|
||||||
|
|
||||||
vec[type] = hold;
|
vec[type] = hold;
|
||||||
putvec(VT_ITEM, vec, (s_char *)&land, EF_LAND);
|
if (actually_doit) {
|
||||||
putland(land.lnd_uid, &land);
|
putvec(VT_ITEM, vec, (s_char *)&land, EF_LAND);
|
||||||
if (!actually_doit)
|
putland(land.lnd_uid, &land);
|
||||||
putland(l2.lnd_uid, &l2);
|
} else
|
||||||
|
putland(save.lnd_uid, &save);
|
||||||
}
|
}
|
||||||
|
|
||||||
getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND);
|
getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue