Author: sveinung
Date: Fri Sep 18 14:39:59 2015
New Revision: 29916

URL: http://svn.gna.org/viewcvs/freeciv?rev=29916&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:
    trunk/common/unit.c

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=29916&r1=29915&r2=29916&view=diff
==============================================================================
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Fri Sep 18 14:39: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