Author: sveinung
Date: Fri Sep 18 14:48:59 2015
New Revision: 29919

URL: http://svn.gna.org/viewcvs/freeciv?rev=29919&view=rev
Log:
Optimize unit_can_help_build_wonder_here()

Don't evaluate all "Help Wonder" action enablers when the unit in question
never can do the "Help Wonder" action. This saves some cycles without giving
up accuracy. (utype_can_do_action() is cached)

See patch #6359

Modified:
    branches/S2_6/common/unit.c

Modified: branches/S2_6/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unit.c?rev=29919&r1=29918&r2=29919&view=diff
==============================================================================
--- branches/S2_6/common/unit.c (original)
+++ branches/S2_6/common/unit.c Fri Sep 18 14:48:59 2015
@@ -198,10 +198,21 @@
 {
   struct city *pcity = tile_city(unit_tile(punit));
 
-  return (pcity
-          && action_prob_possible(action_prob_vs_city(punit,
-                                                      ACTION_HELP_WONDER,
-                                                      pcity)));
+  if (!pcity) {
+    /* No city to help at this tile. */
+    return FALSE;
+  }
+
+  if (!utype_can_do_action(unit_type(punit), ACTION_HELP_WONDER)) {
+    /* This unit can never do help wonder. */
+    return FALSE;
+  }
+
+  /* Evaluate all action enablers for extra accuracy. */
+  /* TODO: Is it worth it? */
+  return action_prob_possible(action_prob_vs_city(punit,
+                                                  ACTION_HELP_WONDER,
+                                                  pcity));
 }
 
 /**************************************************************************


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

Reply via email to