Author: sveinung
Date: Tue Nov 15 07:44:31 2016
New Revision: 34511

URL: http://svn.gna.org/viewcvs/freeciv?rev=34511&view=rev
Log:
Force all action target kinds to be handled.

Use a switch statement in handle_unit_get_actions() when getting the
probabilities of all actions. This forces all action target kinds to be
handled.

See patch #7976

Modified:
    trunk/server/unithand.c

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=34511&r1=34510&r2=34511&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Tue Nov 15 07:44:31 2016
@@ -1495,26 +1495,61 @@
       continue;
     }
 
-    if (target_city && action_id_get_target_kind(act) == ATK_CITY) {
-      probabilities[act] = action_prob_vs_city(actor_unit, act,
-                                               target_city);
-    } else if (target_unit && action_id_get_target_kind(act) == ATK_UNIT) {
-      probabilities[act] = action_prob_vs_unit(actor_unit, act,
-                                               target_unit);
-    } else if (target_tile
-               && action_id_get_target_kind(act) == ATK_UNITS) {
-      probabilities[act] = action_prob_vs_units(actor_unit, act,
-                                                target_tile);
-    } else if (target_tile && action_id_get_target_kind(act) == ATK_TILE) {
-      probabilities[act] = action_prob_vs_tile(actor_unit, act,
-                                               target_tile);
-    } else if (actor_target_distance == 0
-               && action_id_get_target_kind(act) == ATK_SELF) {
-      /* Don't bother with self targeted actions unless the actor is asking
-       * about what can be done to its own tile. */
-      probabilities[act] = action_prob_self(actor_unit, act);
-    } else {
-      probabilities[act] = ACTPROB_IMPOSSIBLE;
+    switch (action_id_get_target_kind(act)) {
+    case ATK_CITY:
+      if (target_city) {
+        /* Calculate the probabilities. */
+        probabilities[act] = action_prob_vs_city(actor_unit, act,
+                                                 target_city);
+      } else {
+        /* No target to act against. */
+        probabilities[act] = ACTPROB_IMPOSSIBLE;
+      }
+      break;
+    case ATK_UNIT:
+      if (target_unit) {
+        /* Calculate the probabilities. */
+        probabilities[act] = action_prob_vs_unit(actor_unit, act,
+                                                 target_unit);
+      } else {
+        /* No target to act against. */
+        probabilities[act] = ACTPROB_IMPOSSIBLE;
+      }
+      break;
+    case ATK_UNITS:
+      if (target_tile) {
+        /* Calculate the probabilities. */
+        probabilities[act] = action_prob_vs_units(actor_unit, act,
+                                                  target_tile);
+      } else {
+        /* No target to act against. */
+        probabilities[act] = ACTPROB_IMPOSSIBLE;
+      }
+      break;
+    case ATK_TILE:
+      if (target_tile) {
+        /* Calculate the probabilities. */
+        probabilities[act] = action_prob_vs_tile(actor_unit, act,
+                                                 target_tile);
+      } else {
+        /* No target to act against. */
+        probabilities[act] = ACTPROB_IMPOSSIBLE;
+      }
+      break;
+    case ATK_SELF:
+      if (actor_target_distance == 0) {
+        /* Calculate the probabilities. */
+        probabilities[act] = action_prob_self(actor_unit, act);
+      } else {
+        /* Don't bother with self targeted actions unless the actor is
+         * asking about what can be done to its own tile. */
+        probabilities[act] = ACTPROB_IMPOSSIBLE;
+      }
+      break;
+    case ATK_COUNT:
+      fc_assert_action(action_id_get_target_kind(act) != ATK_COUNT,
+                       probabilities[act] = ACTPROB_IMPOSSIBLE);
+      break;
     }
   } action_iterate_end;
 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to