Author: sveinung
Date: Wed Apr  1 13:52:48 2015
New Revision: 28682

URL: http://svn.gna.org/viewcvs/freeciv?rev=28682&view=rev
Log:
Add the new requirement type Action.

It is intended to be used like OutputType. Currently it can be used making
Illegal_Action_Move_Cost action specific.

See patch #5969

Modified:
    trunk/ai/default/daieffects.c
    trunk/client/helpdata.c
    trunk/common/actions.c
    trunk/common/actions.h
    trunk/common/fc_types.h
    trunk/common/metaknowledge.c
    trunk/common/requirements.c
    trunk/doc/README.effects
    trunk/fc_version
    trunk/server/cityturn.c
    trunk/server/rssanity.c

Modified: trunk/ai/default/daieffects.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/daieffects.c?rev=28682&r1=28681&r2=28682&view=diff
==============================================================================
--- trunk/ai/default/daieffects.c       (original)
+++ trunk/ai/default/daieffects.c       Wed Apr  1 13:52:48 2015
@@ -717,6 +717,7 @@
   case VUT_MINMOVES:
   case VUT_MINVETERAN:
   case VUT_MINHP:
+  case VUT_ACTION:
   case VUT_COUNT:
     /* No sensible implementation possible with data available. */
     break;

Modified: trunk/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/helpdata.c?rev=28682&r1=28681&r2=28682&view=diff
==============================================================================
--- trunk/client/helpdata.c     (original)
+++ trunk/client/helpdata.c     Wed Apr  1 13:52:48 2015
@@ -600,6 +600,24 @@
     case REQ_RANGE_TRADEROUTE:
     case REQ_RANGE_CONTINENT:
     case REQ_RANGE_COUNT:
+      /* Not supported. */
+      break;
+    }
+    break;
+
+  case VUT_ACTION:
+    switch (preq->range) {
+    case REQ_RANGE_LOCAL:
+      if (preq->present) {
+        cat_snprintf(buf, bufsz, _("Applies to the \"%s\" action.\n"),
+                     action_name_translation(preq->source.value.action));
+      } else {
+        cat_snprintf(buf, bufsz, _("Doesn't apply to the \"%s\""
+                                   " action.\n"),
+                     action_name_translation(preq->source.value.action));
+      }
+      return TRUE;
+    default:
       /* Not supported. */
       break;
     }

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=28682&r1=28681&r2=28682&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Wed Apr  1 13:52:48 2015
@@ -165,6 +165,21 @@
 }
 
 /**************************************************************************
+  Return the action with the given name.
+**************************************************************************/
+struct action *action_by_rule_name(const char *name)
+{
+  /* Actions are still hard coded in the gen_action enum. */
+  int action_id = gen_action_by_name(name, fc_strcasecmp);
+
+  if (!gen_action_is_valid(action_id)) {
+    return NULL;
+  }
+
+  return action_by_number(action_id);
+}
+
+/**************************************************************************
   Get the actor kind of an action.
 **************************************************************************/
 enum action_actor_kind action_get_actor_kind(int action_id)
@@ -192,6 +207,33 @@
   fc_assert_msg(actions[action_id], "Action %d don't exist.", action_id);
 
   return actions[action_id]->hostile;
+}
+
+/**************************************************************************
+  Get the universal number of the action.
+**************************************************************************/
+int action_number(const struct action *action)
+{
+  return action->id;
+}
+
+/**************************************************************************
+  Get the rule name of the action.
+**************************************************************************/
+const char *action_rule_name(const struct action *action)
+{
+  /* Rule name is still hard coded. */
+  return action_get_rule_name(action->id);
+}
+
+/**************************************************************************
+  Get the action name used when displaying the action in the UI. Nothing
+  is added to the UI name.
+**************************************************************************/
+const char *action_name_translation(const struct action *action)
+{
+  /* Use action_get_ui_name() to format the UI name. */
+  return action_get_ui_name(action->id);
 }
 
 /**************************************************************************

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=28682&r1=28681&r2=28682&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Wed Apr  1 13:52:48 2015
@@ -178,9 +178,15 @@
 void actions_free(void);
 
 struct action *action_by_number(int action_id);
+struct action *action_by_rule_name(const char *name);
 
 enum action_actor_kind action_get_actor_kind(int action_id);
 enum action_target_kind action_get_target_kind(int action_id);
+
+int action_number(const struct action *action);
+const char *action_rule_name(const struct action *action);
+
+const char *action_name_translation(const struct action *action);
 
 bool action_is_hostile(int action_id);
 

Modified: trunk/common/fc_types.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/fc_types.h?rev=28682&r1=28681&r2=28682&view=diff
==============================================================================
--- trunk/common/fc_types.h     (original)
+++ trunk/common/fc_types.h     Wed Apr  1 13:52:48 2015
@@ -320,6 +320,7 @@
   struct achievement *achievement;
   struct nation_group *nationgroup;
   struct nation_style *style;
+  struct action *action;
 
   enum ai_level ai_level;
   enum citytile_type citytile;
@@ -425,6 +426,8 @@
 #define SPECENUM_VALUE34NAME "Age"
 #define SPECENUM_VALUE35 VUT_NATIONGROUP
 #define SPECENUM_VALUE35NAME "NationGroup"
+#define SPECENUM_VALUE36 VUT_ACTION
+#define SPECENUM_VALUE36NAME "Action"
 /* Keep this last. */
 #define SPECENUM_COUNT VUT_COUNT
 #include "specenum_gen.h"

Modified: trunk/common/metaknowledge.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/metaknowledge.c?rev=28682&r1=28681&r2=28682&view=diff
==============================================================================
--- trunk/common/metaknowledge.c        (original)
+++ trunk/common/metaknowledge.c        Wed Apr  1 13:52:48 2015
@@ -517,7 +517,8 @@
     }
   }
 
-  if (req->source.kind == VUT_OTYPE) {
+  if (req->source.kind == VUT_ACTION
+      || req->source.kind == VUT_OTYPE) {
     /* This requirement type is intended to specify the situation. */
     return TRUE;
   }

Modified: trunk/common/requirements.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/requirements.c?rev=28682&r1=28681&r2=28682&view=diff
==============================================================================
--- trunk/common/requirements.c (original)
+++ trunk/common/requirements.c Wed Apr  1 13:52:48 2015
@@ -207,6 +207,12 @@
   case VUT_AGE:
     source.value.age = atoi(value);
     if (source.value.age > 0) {
+      return source;
+    }
+    break;
+  case VUT_ACTION:
+    source.value.action = action_by_rule_name(value);
+    if (source.value.action != NULL) {
       return source;
     }
     break;
@@ -415,6 +421,12 @@
   case VUT_AGE:
     source.value.age = value;
     return source;
+  case VUT_ACTION:
+    source.value.action = action_by_number(value);
+    if (source.value.action != NULL) {
+      return source;
+    }
+    break;
   case VUT_OTYPE:
     source.value.outputtype = value;
     return source;
@@ -528,6 +540,8 @@
     return source->value.min_hit_points;
   case VUT_AGE:
     return source->value.age;
+  case VUT_ACTION:
+    return action_number(source->value.action);
   case VUT_OTYPE:
     return source->value.outputtype;
   case VUT_SPECIALIST:
@@ -619,6 +633,7 @@
     case VUT_MINMOVES:
     case VUT_MINHP:
     case VUT_AGE:
+    case VUT_ACTION:
     case VUT_OTYPE:
     case VUT_SPECIALIST:
     case VUT_TERRAINCLASS:
@@ -720,6 +735,7 @@
   case VUT_UNITSTATE:
   case VUT_MINMOVES:
   case VUT_MINHP:
+  case VUT_ACTION:
   case VUT_OTYPE:
   case VUT_SPECIALIST:
   case VUT_TERRAINALTER: /* XXX could in principle support C/ADJACENT */
@@ -776,6 +792,7 @@
     case VUT_MINMOVES:
     case VUT_MINHP:
     case VUT_AGE:
+    case VUT_ACTION:
     case VUT_OTYPE:
     case VUT_SPECIALIST:
     case VUT_MINSIZE:
@@ -2625,6 +2642,11 @@
       break;
     }
     break;
+  case VUT_ACTION:
+    eval = BOOL_TO_TRISTATE(target_action
+                            && action_number(target_action)
+                               == action_number(req->source.value.action));
+    break;
   case VUT_OTYPE:
     eval = BOOL_TO_TRISTATE(target_output
                             && target_output->index == 
req->source.value.outputtype);
@@ -2779,6 +2801,7 @@
 {
   switch (req->source.kind) {
   case VUT_NONE:
+  case VUT_ACTION:
   case VUT_OTYPE:
   case VUT_SPECIALIST: /* Only so long as it's at local range only */
   case VUT_AI_LEVEL:
@@ -2906,6 +2929,9 @@
     return psource1->value.min_hit_points == psource2->value.min_hit_points;
   case VUT_AGE:
     return psource1->value.age == psource2->value.age;
+  case VUT_ACTION:
+    return (action_number(psource1->value.action)
+            == action_number(psource2->value.action));
   case VUT_OTYPE:
     return psource1->value.outputtype == psource2->value.outputtype;
   case VUT_SPECIALIST:
@@ -3009,6 +3035,8 @@
     fc_snprintf(buffer, sizeof(buffer), "%d", psource->value.age);
 
     return buffer;
+  case VUT_ACTION:
+    return action_rule_name(psource->value.action);
   case VUT_OTYPE:
     return get_output_name(psource->value.outputtype);
   case VUT_SPECIALIST:
@@ -3169,6 +3197,10 @@
     cat_snprintf(buf, bufsz, _("Age %d"),
                  psource->value.age);
     return buf;
+  case VUT_ACTION:
+    fc_strlcat(buf, action_name_translation(psource->value.action),
+               bufsz);
+    return buf;
   case VUT_OTYPE:
     /* FIXME */
     fc_strlcat(buf, get_output_name(psource->value.outputtype), bufsz);

Modified: trunk/doc/README.effects
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/doc/README.effects?rev=28682&r1=28681&r2=28682&view=diff
==============================================================================
--- trunk/doc/README.effects    (original)
+++ trunk/doc/README.effects    Wed Apr  1 13:52:48 2015
@@ -62,6 +62,7 @@
 NationGroup:   World, Alliance, Team, Player
 Nationality:   Traderoute, City
 DiplRel:       World, Alliance, Team, Player, Local
+Action:        Local
 OutputType:    Local
 Specialist:    Local
 MinYear:       World

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=28682&r1=28681&r2=28682&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Wed Apr  1 13:52:48 2015
@@ -54,7 +54,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Mar.25"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Apr.01"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/cityturn.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/cityturn.c?rev=28682&r1=28681&r2=28682&view=diff
==============================================================================
--- trunk/server/cityturn.c     (original)
+++ trunk/server/cityturn.c     Wed Apr  1 13:52:48 2015
@@ -1697,6 +1697,7 @@
             case VUT_UNITSTATE:
             case VUT_MINMOVES:
             case VUT_MINHP:
+            case VUT_ACTION:
            case VUT_OTYPE:
            case VUT_SPECIALIST:
            case VUT_TERRAINALTER: /* XXX could do this in principle */

Modified: trunk/server/rssanity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/rssanity.c?rev=28682&r1=28681&r2=28682&view=diff
==============================================================================
--- trunk/server/rssanity.c     (original)
+++ trunk/server/rssanity.c     Wed Apr  1 13:52:48 2015
@@ -153,6 +153,7 @@
      case VUT_GOVERNMENT:
      case VUT_UTYPE:
      case VUT_UCLASS:
+     case VUT_ACTION:
      case VUT_OTYPE:
      case VUT_SPECIALIST:
      case VUT_MINSIZE: /* Breaks nothing, but has no sense either */


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

Reply via email to