Author: sveinung
Date: Fri Sep 23 11:06:18 2016
New Revision: 33865

URL: http://svn.gna.org/viewcvs/freeciv?rev=33865&view=rev
Log:
Introduce requirement_fulfilled_by_terrain().

Make universal_fulfills_requirement()'s terrain support easier to discover
by defining requirement_fulfilled_by_terrain(). Use it rather than using
universal_fulfills_requirement() directly. (Except in the Qt client. C++
doesn't like C99 designated initializers.)

Thanks to Marko Lindqvist <cazfi> for finding direct
universal_fulfills_requirement() calls missed in version 1 of this patch.

See patch #7717

Modified:
    branches/S2_6/client/gui-gtk-2.0/helpdlg.c
    branches/S2_6/client/gui-gtk-3.0/helpdlg.c
    branches/S2_6/common/requirements.h
    branches/S2_6/server/unithand.c

Modified: branches/S2_6/client/gui-gtk-2.0/helpdlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/helpdlg.c?rev=33865&r1=33864&r2=33865&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/helpdlg.c  (original)
+++ branches/S2_6/client/gui-gtk-2.0/helpdlg.c  Fri Sep 23 11:06:18 2016
@@ -1101,11 +1101,11 @@
                                            enum unit_activity act,
                                            char *label)
 {
-  struct universal for_terr = { .kind = VUT_TERRAIN, .value = { .terrain = 
pterr }};
   enum extra_cause cause = activity_to_extra_cause(act);
 
   extra_type_by_cause_iterate(cause, pextra) {
-    if (pextra->buildable && universal_fulfills_requirement(FALSE, 
&(pextra->reqs), &for_terr)) {
+    if (pextra->buildable
+        && requirement_fulfilled_by_terrain(pterr, &(pextra->reqs))) {
       GtkWidget *w;
       GtkWidget *hbox;
       char buffer[1024];

Modified: branches/S2_6/client/gui-gtk-3.0/helpdlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/helpdlg.c?rev=33865&r1=33864&r2=33865&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/helpdlg.c  (original)
+++ branches/S2_6/client/gui-gtk-3.0/helpdlg.c  Fri Sep 23 11:06:18 2016
@@ -1131,11 +1131,11 @@
                                            enum unit_activity act,
                                            char *label)
 {
-  struct universal for_terr = { .kind = VUT_TERRAIN, .value = { .terrain = 
pterr }};
   enum extra_cause cause = activity_to_extra_cause(act);
 
   extra_type_by_cause_iterate(cause, pextra) {
-    if (pextra->buildable && universal_fulfills_requirement(FALSE, 
&(pextra->reqs), &for_terr)) {
+    if (pextra->buildable
+        && requirement_fulfilled_by_terrain(pterr, &(pextra->reqs))) {
       GtkWidget *w;
       GtkWidget *hbox;
       char buffer[1024];

Modified: branches/S2_6/common/requirements.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/requirements.h?rev=33865&r1=33864&r2=33865&view=diff
==============================================================================
--- branches/S2_6/common/requirements.h (original)
+++ branches/S2_6/common/requirements.h Fri Sep 23 11:06:18 2016
@@ -164,6 +164,10 @@
   universal_fulfills_requirement(FALSE, (_rqs_),                           \
     &(struct universal){.kind = VUT_IMPROVEMENT,                           \
                         .value = {.building = (_imp_)}})
+#define requirement_fulfilled_by_terrain(_ter_, _rqs_)                 \
+  universal_fulfills_requirement(FALSE, (_rqs_),                       \
+    &(struct universal){.kind = VUT_TERRAIN,                           \
+                        .value = {.terrain = (_ter_)}})
 #define requirement_fulfilled_by_unit_class(_uc_, _rqs_)                   \
   universal_fulfills_requirement(FALSE, (_rqs_),                           \
       &(struct universal){.kind = VUT_UCLASS, .value = {.uclass = (_uc_)}})

Modified: branches/S2_6/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unithand.c?rev=33865&r1=33864&r2=33865&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c     (original)
+++ branches/S2_6/server/unithand.c     Fri Sep 23 11:06:18 2016
@@ -590,9 +590,6 @@
                                       bool is_target,
                                       struct terrain *pterrain)
 {
-  struct universal univ_terr
-      = {.kind = VUT_TERRAIN, .value = {.terrain = pterrain}};
-
   if (action_id == ACTION_ANY) {
     /* Any action is OK. */
     action_iterate(alt_act) {
@@ -611,10 +608,8 @@
 
   action_enabler_list_iterate(action_enablers_for_action(action_id),
                               enabler) {
-    if (universal_fulfills_requirement(FALSE,
-                                       (is_target ? &enabler->target_reqs
-                                                  : &enabler->actor_reqs),
-                                       &univ_terr)) {
+    if (requirement_fulfilled_by_terrain(pterrain,
+            (is_target ? &enabler->target_reqs : &enabler->actor_reqs))) {
       /* This terrain kind doesn't block this action enabler. */
       return FALSE;
     }


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

Reply via email to