This is the mail archive of the
xconq7@sources.redhat.com
mailing list for the Xconq project.
do_extract_action
- From: "Stanley Sutton" <sutton at t-surf dot com>
- To: <xconq7 at sources dot redhat dot com>
- Date: Mon, 5 Aug 2002 15:51:50 -0500
- Subject: do_extract_action
I think the do extract action needs more changed than just checking the
availble material is more than 0. I think this will extract all the
remaining material from the cell, then walk down the unit stack until it
finds all the material it requested, or extracts all the availble
material from the cell.
It doesn't extract from multiple cells, or over a range of cells, unlike
distribute material.
do_extract_action(Unit *actor, Unit *extractor, int x, int y, int m, int
amount)
{
int oldamt, amt, newamt,extamt, excess, t, newt;
Unit *stack_unit;
if (any_cell_materials_defined()
&& cell_material_defined(m)
&& material_at(x, y, m) > 0 ) {
oldamt = material_at(x, y, m);
extamt = min(amount, oldamt);
newamt = oldamt - amt;
set_material_at(x, y, m, newamt);
/* (should do with a common routine) */
t = terrain_at(x, y);
if (newamt == 0
&& probability(tm_change_on_exhaust(t, m))
&& tm_exhaust_type(t, m) != NONTTYPE) {
newt = tm_exhaust_type(t, m);
/* Change the terrain's type. */
change_terrain_type(x, y, newt);
}
}
/* if not all of request (or none of the request) for
* material was not met from the terrain, get from units in
* cell. */
if( extamt < amount ) {
for_all_stack(x, y, stack_unit) {
if (in_play(stack_unit)
&& indep(stack_unit)
&& stack_unit->supply[m] > 0 ) {
oldamt = stack_unit->supply[m];
amt = min(amount - extamt, oldamt);
newamt = oldamt - amt;
stack_unit->supply[m] = newamt;
extamt += amt;
if( extamt >= amount) {
break;
}
}
}
}
extractor->supply[m] += extamt;
/* Clip to storage space and pass around any extra. */
excess = extractor->supply[m] - um_storage_x(extractor->type, m);
if (excess > 0) {
extractor->supply[m] -= excess;
distribute_material(extractor, m, excess);
}
use_up_acp(actor, um_acp_to_extract(extractor->type, m));
return A_ANY_DONE;
}