public inbox for xconq7@sourceware.org
 help / color / mirror / Atom feed
From: Eric McDonald <mcdonald@phy.cmich.edu>
To: Hans Ronne <hronne@comhem.se>
Cc: xconq7@sources.redhat.com
Subject: Re: Major bug and what to do about it (long)
Date: Tue, 17 Aug 2004 01:13:00 -0000	[thread overview]
Message-ID: <4121565B.7070402@phy.cmich.edu> (raw)
In-Reply-To: <l03130301bd46e72c0141@[212.181.162.155]>

Hans Ronne wrote:

> To follow up, this problem already exists with the current code. If I
> switch off the AI and try to hit the same bogus unit view with a manual 'f'
> command I get the anser "No visible unit there" (and no acp is consumed).
> So probing the terrain for free is already possible, precisely because
> do_hit_unit_task tries to do a fire_at_action (or an attack_action) instead
> of a fire_into_action (or an overrun_action). Only the latter are really
> safe to use in a unit view context.

Unless this has been changed, the patch I made to the Tcl/Tk interface 
on 2003/12/29 addresses this. (This is what I was referring to earlier; 
I guess it was a comment in which I suggested the "attempted fire at" 
function, and not necessarily an email message.) If you look at the 
comments I put in the code, you can see that I was already thinking of 
ways to address the present problem back then.

2003-12-29  Eric McDonald

         Squash two firing bugs in Tcl/Tk interface with one fix.
         * tkcmd.c (common_fire_at): Get rid of call to unit_at, which
         would return the first unit, friend or foe. Instead iterate
         through view stack and pick out the first unit not on
         attacker's side, if there is any such unit. This accomplishes
         two things. First, this prevents a player from cheating by
         probing all cells in firing range, hoping to uncover an unseen
         enemy unit (the code would report "Nothing to fire at!" from
         unit_at()'s omniscient perspective rather than a non-see-all
         side's less knowledgable one). Second, this allows a player
         to fire into a cell which contains his or her own units. This
         is a mixed blessing, since friendly fire incidents can occur
         because of the way the firing code is currently set up.

RCS file: /cvs/xconq/xconq/tcltk/tkcmd.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- xconq/tcltk/tkcmd.c	2003/12/25 19:22:31	1.59
+++ xconq/tcltk/tkcmd.c	2003/12/29 23:57:36	1.60
@@ -624,16 +624,50 @@
  common_fire_at(Unit *unit, int x, int y)
  {
      int rslt;
-    Unit *other;
-
-    /* (should only be able to target unit if covered...) */
-    other = unit_at(x, y);
+    Unit *other = NULL;
+    UnitView *uview = NULL;
+    int methere = FALSE, minethere = FALSE;
+
+    /* Check only those units which we can see. */
+    for_all_view_stack(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;
+        }
+        /* If one of our units is in the cell, we make note of this, in
+           case there turns out to be no visible enemies there. */
+        else {
+            if (uview->unit == unit)
+              methere = TRUE;
+            else
+              minethere = TRUE;
+        }
+    }
+    /* Target may be a ghost (view of dead or moved unit), but the player
+       cannot know that, and hence we should proceed with a fire-into
+       action instead. */
+    /* (This code should not be in the interface. Instead the referee
+        code in the kernel should accept UnitView * instead of
+        Unit *, and perform these checks for us, and guide the
+        fire-into action to be safer in such cases. Or perhaps just run
+        an attempted_fire_at procedure, which would expend ammo, draw the
+        fire lines, and do not much else.) */
+    if (other && (!in_play(other) || (other->x != x) || (other->y != y))) {
+        common_fire_into(unit, x, y);
+        return;
+    }
      if (other == NULL) {
-	cmd_error(dside, "Nothing there to fire at!");
-    } else if (other == unit) {
-	cmd_error(dside, "You can't fire at yourself!");
-    } else if (other->side == unit->side) {
-	cmd_error(dside, "You can't fire at one of your own units!");
+        if (methere)
+          cmd_error(dside, "You can't fire at yourself!");
+        else if (minethere)
+          cmd_error(dside, "You can't fire at one of your own units!");
+        else
+	  cmd_error(dside, "Apparently nothing there to fire at!");
      } else {
  	rslt = check_fire_at_action(unit, unit, other, -1);
  	if (valid(rslt)) {


Eric

  reply	other threads:[~2004-08-17  0:50 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-16 21:53 Hans Ronne
2004-08-16 22:14 ` Eric McDonald
2004-08-16 22:43   ` Hans Ronne
2004-08-17  0:33     ` Hans Ronne
2004-08-17  1:13       ` Eric McDonald [this message]
2004-08-17  1:39         ` Hans Ronne
2004-08-17  2:21           ` Eric McDonald
2004-08-17  4:28           ` Jim Kingdon
2004-08-17  5:17             ` Hans Ronne
2004-08-17 18:00               ` Eric McDonald
2004-08-18  5:26               ` Jim Kingdon
2004-08-18 11:11                 ` Hans Ronne
2004-08-17 16:14             ` Eric McDonald
2004-08-17  0:35     ` Eric McDonald
2004-08-17  1:16       ` Hans Ronne
2004-08-17  1:46         ` Eric McDonald
2004-08-17  3:03           ` Hans Ronne
2004-08-17  3:56             ` Eric McDonald
2004-08-17  1:30 ` Eric McDonald
2004-08-17  2:52   ` Hans Ronne
2004-08-17  2:53     ` Eric McDonald
2004-08-17  4:42       ` Jim Kingdon
2004-08-17 16:37         ` Eric McDonald
2004-08-17  4:48       ` Hans Ronne
2004-08-17 16:42         ` Eric McDonald
2004-08-18 10:56         ` Jim Kingdon
2004-08-17 11:06 ` Stan Shebs
2004-08-17 15:29   ` Hans Ronne
2004-08-17 16:01     ` Hans Ronne
2004-08-17 18:57       ` Eric McDonald
2004-08-17 20:38         ` Hans Ronne
2004-08-17 21:55           ` Eric McDonald
2004-08-17 23:42             ` Hans Ronne
2004-08-18  0:49               ` Eric McDonald
2004-08-18  4:59                 ` Hans Ronne
2004-08-18 15:28                   ` Eric McDonald
2004-08-19  6:37                     ` Elijah Meeks
2004-08-19 12:46                       ` Hans Ronne
2004-08-19 16:46                       ` Eric McDonald
2004-08-19 13:09                     ` Hans Ronne
2004-08-19 16:05                       ` Eric McDonald
2004-08-19 20:09                         ` Hans Ronne
2004-08-19 23:37                           ` Eric McDonald
2004-08-20  1:42                             ` Hans Ronne
2004-08-20  3:29                               ` Clearing the Air (long) Eric McDonald
2004-08-20 15:26                                 ` Stan Shebs
2004-08-18  5:30         ` Major bug and what to do about it (long) Jim Kingdon
2004-08-18 12:52           ` Hans Ronne
2004-08-17 18:23     ` Eric McDonald
2004-08-17 18:47       ` Hans Ronne
2004-08-17 18:59         ` Eric McDonald
2004-08-17 19:39           ` Hans Ronne
2004-08-17 21:14             ` Eric McDonald

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4121565B.7070402@phy.cmich.edu \
    --to=mcdonald@phy.cmich.edu \
    --cc=hronne@comhem.se \
    --cc=xconq7@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).