Author: sveinung
Date: Tue Dec 30 10:32:12 2014
New Revision: 27451

URL: http://svn.gna.org/viewcvs/freeciv?rev=27451&view=rev
Log:
Gtk clients: ability establish trade route names menu item.

A unit with the TradeRoute unit type flag may be unable to establish a trade
route. A unit without it may be able to to establish a trade route. Set menu
item name based on ability to do action, not flag.

See patch #5623

Modified:
    trunk/client/gui-gtk-2.0/menu.c
    trunk/client/gui-gtk-3.0/menu.c
    trunk/common/unitlist.c
    trunk/common/unitlist.h

Modified: trunk/client/gui-gtk-2.0/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/menu.c?rev=27451&r1=27450&r2=27451&view=diff
==============================================================================
--- trunk/client/gui-gtk-2.0/menu.c     (original)
+++ trunk/client/gui-gtk-2.0/menu.c     Tue Dec 30 10:32:12 2014
@@ -2294,7 +2294,7 @@
     }
   }
 
-  if (units_have_type_flag(punits, UTYF_TRADE_ROUTE, TRUE)) {
+  if (units_can_do_action(punits, ACTION_TRADE_ROUTE, TRUE)) {
     menus_rename(unit_group, "BUILD_ROAD", _("Establish Trade _Route"));
   } else if (units_have_type_flag(punits, UTYF_SETTLERS, TRUE)) {
     char road_item[500];

Modified: trunk/client/gui-gtk-3.0/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/menu.c?rev=27451&r1=27450&r2=27451&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.0/menu.c     (original)
+++ trunk/client/gui-gtk-3.0/menu.c     Tue Dec 30 10:32:12 2014
@@ -2295,7 +2295,7 @@
     }
   }
 
-  if (units_have_type_flag(punits, UTYF_TRADE_ROUTE, TRUE)) {
+  if (units_can_do_action(punits, ACTION_TRADE_ROUTE, TRUE)) {
     menus_rename(unit_group, "BUILD_ROAD", _("Establish Trade _Route"));
   } else if (units_have_type_flag(punits, UTYF_SETTLERS, TRUE)) {
     char road_item[500];

Modified: trunk/common/unitlist.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unitlist.c?rev=27451&r1=27450&r2=27451&view=diff
==============================================================================
--- trunk/common/unitlist.c     (original)
+++ trunk/common/unitlist.c     Tue Dec 30 10:32:12 2014
@@ -191,6 +191,25 @@
   return FALSE;
 }
 
+/**************************************************************************
+  If has_flag is true, returns true iff any of the units are able to do
+  the specified action.
+
+  If has_flag is false, returns true iff any of the units are unable do
+  the specified action.
+**************************************************************************/
+bool units_can_do_action(const struct unit_list *punits,
+                         int action_id, bool can_do)
+{
+  unit_list_iterate(punits, punit) {
+    if (EQ(can_do, unit_can_do_action(punit, action_id))) {
+      return TRUE;
+    }
+  } unit_list_iterate_end;
+
+  return FALSE;
+}
+
 /****************************************************************************
   Return TRUE iff any of the units is a transporter that is occupied.
 ****************************************************************************/

Modified: trunk/common/unitlist.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unitlist.h?rev=27451&r1=27450&r2=27451&view=diff
==============================================================================
--- trunk/common/unitlist.h     (original)
+++ trunk/common/unitlist.h     Tue Dec 30 10:32:12 2014
@@ -78,6 +78,8 @@
                            enum base_gui_type base_gui);
 bool units_have_type_flag(const struct unit_list *punits,
                           enum unit_type_flag_id flag, bool has_flag);
+bool units_can_do_action(const struct unit_list *punits,
+                         int action_id, bool can_do);
 bool units_are_occupied(const struct unit_list *punits);
 bool units_can_load(const struct unit_list *punits);
 bool units_can_unload(const struct unit_list *punits);


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

Reply via email to