Author: sveinung
Date: Fri Jun  5 15:52:10 2015
New Revision: 29157

URL: http://svn.gna.org/viewcvs/freeciv?rev=29157&view=rev
Log:
AI: Warn if being a target of a new action isn't handled.

The AI uses the function action_target_neg_util() to consider how bad it is
for one of its cities to be the victim of an action. It is easy to forget it
when adding a new action that targets a city.

Make the compiler warn if a new hard coded action is added without being
listed in action_target_neg_util()'s switch statement. Being reminded to
consider actions with a city target is worth having to list actions that
don't target cities.

See patch #6106

Modified:
    trunk/ai/default/aicity.c

Modified: trunk/ai/default/aicity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aicity.c?rev=29157&r1=29156&r2=29157&view=diff
==============================================================================
--- trunk/ai/default/aicity.c   (original)
+++ trunk/ai/default/aicity.c   Fri Jun  5 15:52:10 2015
@@ -1045,10 +1045,7 @@
 static int action_target_neg_util(int action_id,
                                   const struct city *pcity)
 {
-  fc_assert_ret_val_msg(action_get_target_kind(action_id) == ATK_CITY,
-                        0, "Action not aimed at cities");
-
-  switch (action_id) {
+  switch ((enum gen_action)action_id) {
   case ACTION_SPY_INCITE_CITY:
     /* Copied from the evaluation of the No_Incite effect */
     return MAX((game.server.diplchance * 2
@@ -1083,8 +1080,21 @@
   case ACTION_JOIN_CITY:
     /* TODO: Individual and well balanced values */
     return -1;
-  }
-
+
+  /* Shouldn't happen. */
+  case ACTION_SPY_BRIBE_UNIT:
+  case ACTION_SPY_SABOTAGE_UNIT:
+  case ACTION_CAPTURE_UNITS:
+  case ACTION_FOUND_CITY:
+  case ACTION_COUNT:
+    fc_assert_msg(action_get_target_kind(action_id) == ATK_CITY,
+                  "Action not aimed at cities");
+  }
+
+  fc_assert_msg(gen_action_is_valid(action_id),
+                "Action %d don't exist.", action_id);
+
+  /* Wrong action. Ignore it. */
   return 0;
 }
 


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

Reply via email to