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]

The selective fire-at command


We have been arguing the merits of the selective fire-at command for the
last two days. Well, I've got news that will surprise some of you. The
selective fire-at command doesn't work in the tcltk interface. An as far as
I can tell from the CVS sources, it never worked.

First let me explain what I mean by a selective fire-at command, and until
now assumed that everybody else who was talking about it also meant. We
have two enemy units in the same cell, A and B. If I do a fire-into action,
one, both or neither unit will be hit, depending on the outcome. In
contrast, if I do a fire-at command ('f') with the cursor on top of A, I
will always hit A, never B. If I do the same thing with the cursor on top
of B, I will always hit B, never A. This is the whole point of the
selective command. You get to pick what unit to hit.

This is also how things work in the Mac interface. However, it is not how
the tcltk interface works. In the tcltk interface, I will always hit the
same unit (A) even if I target B. In fact, the unit that is hit (A) is
always the first unit in the stack. So the tcltk interface doesn't care one
iota about what unit I am trying to hit.

This is perhaps hard to believe, given the discussion we just had, but
there is a simple test that any of you can do to convince yourself that
what I am saying is true:

1. Launch the Magnuszew game.
2. Switch on see-all and sequential play.
3. Switch off both AIs and switch player to the German side.
4. Switch to survey mode and select one of the German mortars.

We are now ready for action. At the front of the Russian column, there are
two tanks, 1st SU85 and 2nd SU85. The 1st SU85 carries the 9th infantry
platoon inside.

5. Put the cursor on top of 1st SU85 and press 'f'. You will then hit 1st
SU85 and perhaps also the platoon inside. So far so good.

6. Now pick another mortar and target 2nd SU85. Amazingly, you will hit 1st
SU85 instead! In fact, no matter what other unit in the cell you try to
target, you will always hit 1st SU85 (since it is the first unit in the
stack).

Looking at the code, we can immediately understand why this is so (in fact
it was because I couldn't make sense of the code that I discovered the
whole thing). Here are the relevant lines from do_fire in tkcmd.c:

	sx = map->inpsx;  sy = map->inpsy;

	if (nearest_cell(widget_vp(map), sx, sy, &x, &y, NULL, NULL)) {
	    common_fire_at(unit, x, y);
	} else {
	    cmd_error(dside, "Cannot fire outside the world!");
	}

You will notice that the pixel coordinates are converted to (x, y) by
nearest_cell, and these cell coordinates are then passed on to
common_fire_at. What this means is that all information about what unit
within the cell you were trying to target is lost.

Looking further at common_fire_at we find:

    for_all_view_stack_with_occs(unit->side, x, y, uview) {
        /* And which are not on our side. Note that we are allowed to
           hit other trusted sides, though doing so may make them not
           trusted for long. :-) */
        if (unit->side != side_n(uview->siden)) {
            other = uview->unit;
            /* Assume we have the right target. (Bad assumption,
               but what else can one do with the info presently available?) */
            break;
        }

The code iterates through the stack and always selects the first enemy unit
it finds as "other". Which is then passed on to the kernel. QED.

Now, two comments. First, the fire-at command does work in the Mac
interface since the pixel coordinates are passed on and the unit under the
cursor is identified. Second, the tcltk (and Mac) attack commands also work
as expected. I won't give you the deatils, but you can check out the
sources and try for yourself.

I will try to fix the fire-at command since I am hacking the tcltk sources
anyway. It should not be too difficult given the fact that we have a
working command in the Mac interface.

Hans



















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