]> git.pond.sub.org Git - empserver/commitdiff
fire: Fix damage and ammunition use of return fire
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 14 May 2016 17:53:02 +0000 (19:53 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 2 Jul 2017 15:45:44 +0000 (17:45 +0200)
quiet_bigdef() runs for each attacker.  It lets each eligible defender
fire at most once.  The first time a defender is eligible, it fires
and is saved in the list of defenders, along with its firing damage.
If it's eligible again for a later attacker, it's found in the list of
defenders, and the damage is reused.  The list of defenders searched
with search_flist().  Unfortunately, search_flist() compares only uid,
not type, and therefore can return a previously found defender of
another type.

If there are multiple attackers and multiple defenders with the same
uid, total damage can be off, damage can be spread to attackers out of
range, and defenders may not be charged shells.  Abuse is possible,
but complicated to set up, and probably not worth the trouble.

Broken in commit f89edc7, v4.3.12.  Fix by comparing the type as well.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/commands/mfir.c

index 1983010fda14b005428467de4531eac89941b611..29d27cbad52bbd2f04c329cb06bd0f06bd7a63cf 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Steve McClure, 2000
  *
  *  Known contributors to this file:
  *     Steve McClure, 2000
- *     Markus Armbruster, 2004-2015
+ *     Markus Armbruster, 2004-2016
  */
 
 #include <config.h>
  */
 
 #include <config.h>
@@ -660,13 +660,16 @@ free_flist(struct emp_qelem *list)
 }
 
 static int
 }
 
 static int
-uid_eq(struct emp_qelem *elem, void *key)
+flist_eq(struct emp_qelem *elem, void *key)
 {
 {
-    return ((struct flist *)elem)->uid == ((struct empobj *)key)->uid;
+    struct flist *e = (struct flist *)elem;
+    struct flist *k = key;
+
+    return e->type == k->type && e->uid == k->uid;
 }
 
 static struct flist *
 search_flist(struct emp_qelem *list, struct empobj *gp)
 {
 }
 
 static struct flist *
 search_flist(struct emp_qelem *list, struct empobj *gp)
 {
-    return (struct flist *)emp_searchque(list, gp, uid_eq);
+    return (struct flist *)emp_searchque(list, gp, flist_eq);
 }
 }