This is the mail archive of the xconq7@sources.redhat.com mailing list for the Xconq project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bug in the attack/fire code?


>I have noticed that if firing is dependent on having a material (e.g.
>torpedoes), and a unit can fight using regular attack as well as firing,
>if it runs out of the material that it uses to fire, and the player
>clicks on an enemy to attack, it fires, reducing its supply to -1, at
>which point it can't do anything.  Shouldn't it attack normally instead,
>or at least refuse to fire before it drops below zero storage?

Yes. There are two strange things here. First, the unit should not be able
to fire at all if it does not have enough torpedoes. So it should never
reach a supply of -1. From a quick look at the code, I think I have
identified the bug. check_fire_at_action calls enough_ammo, which checks if:

unit->supply[m] < um_consumption_per_attack(unit->type, m))

However, this is the material used for direct attack (in your case
"antimatter"), Clearly check_fire_at_action needs to check
um_consumption_per_fire (torpedoes) instead. The fire code will use
um_consumption_per_attack, but only as a fallback if
um_consumption_per_fire is not defined (similar to its using the hit-chance
table as a fallback if fire-hit-chance is not defined). So in this case the
code should check um_consumption_per_fire first and then
um_consumption_per_attack. Which it blatantly fails to do.

The other strange thing is that a direct attack should still work if the
unit runs out of torpedoes. The relevant piece of code (from
advance_into_cell) looks loke this:

/* Somebody else's unit, try to victimize it in
   various ways, trying coexistence only as a last
   resort. */
rslt = check_capture_action(unit, unit, other);
if (valid(rslt)) {
    net_prep_capture_action(unit, unit, other);
    return TRUE;
}
rslt = check_overrun_action(unit, unit, x, y, z, 100);
if (valid(rslt)) {
    net_prep_overrun_action(unit, unit, x, y, z, 100);
    return TRUE;
}
if (reason && rslt == A_ANY_NO_AMMO)
  *reason = (HistEventType)rslt;
rslt = check_attack_action(unit, unit, other, 100);
if (valid(rslt)) {
    net_prep_attack_action(unit, unit, other, 100);
    return TRUE;
}
if (reason && rslt == A_ANY_NO_AMMO)
  *reason = (HistEventType)rslt;
rslt = check_fire_at_action(unit, unit, other, -1);
if (valid(rslt)) {
    net_prep_fire_at_action(unit, unit, other, -1);
    return TRUE;
}

So if you click on an enemy unit, the computer first tries a capture, if
that is not possible an overrun action, if that is not possible a direct
attack, and as a final resort a fire attack. This means that a direct
attack will always be used by default, even if you have *not* run out of
torpedoes. So if the unit fails to execute a direct attack, it means that
such an attack is not possible. I can think of several reasons. Perhaps the
enemy unit is not within the range for a direct attack (adjacent or same
cell). Perhaps it ran out of the antimatter that it needs for a direct
attack. Or perhaps direct attacks are not possible for this unit type. It
is not uncommon to set acp-to-attack to zero for firing unit types in order
to avoid the compulsory direct attack described above. I have done that in
several of my games.

Hans













Hans Ronne

hronne@pp.sbbs.se



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]