Author: jtn
Date: Tue Oct  4 11:06:35 2016
New Revision: 33984

URL: http://svn.gna.org/viewcvs/freeciv?rev=33984&view=rev
Log:
Add MinCalFrag requirement, matching on calendar fragments.

See patch #7751.

Modified:
    trunk/ai/default/daieffects.c
    trunk/common/calendar.c
    trunk/common/calendar.h
    trunk/common/fc_types.h
    trunk/common/reqtext.c
    trunk/common/requirements.c
    trunk/doc/README.effects
    trunk/server/cityturn.c
    trunk/server/rssanity.c
    trunk/tools/ruledit/univ_value.c

Modified: trunk/ai/default/daieffects.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/daieffects.c?rev=33984&r1=33983&r2=33984&view=diff
==============================================================================
--- trunk/ai/default/daieffects.c       (original)
+++ trunk/ai/default/daieffects.c       Tue Oct  4 11:06:35 2016
@@ -738,6 +738,7 @@
   case VUT_MINHP:
   case VUT_ACTION:
   case VUT_GOOD:
+  case VUT_MINCALFRAG:
   case VUT_COUNT:
     /* No sensible implementation possible with data available. */
     break;

Modified: trunk/common/calendar.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/calendar.c?rev=33984&r1=33983&r2=33984&view=diff
==============================================================================
--- trunk/common/calendar.c     (original)
+++ trunk/common/calendar.c     Tue Oct  4 11:06:35 2016
@@ -95,6 +95,25 @@
 
 /****************************************************************************
   Produce a statically allocated textual representation of the given
+  calendar fragment.
+****************************************************************************/
+const char *textcalfrag(int frag)
+{
+  static char buf[MAX_LEN_NAME];
+
+  fc_assert_ret_val(game.calendar.calendar_fragments > 0, "");
+  if (game.calendar.calendar_fragment_name[frag][0] != '\0') {
+    fc_snprintf(buf, sizeof(buf), "%s",
+                _(game.calendar.calendar_fragment_name[frag]));
+  } else {
+    /* Human readable fragment count starts from 1, not 0 */
+    fc_snprintf(buf, sizeof(buf), "%d", frag + 1);
+  }
+  return buf;
+}
+
+/****************************************************************************
+  Produce a statically allocated textual representation of the given
   year.
 ****************************************************************************/
 const char *textyear(int year)
@@ -123,15 +142,8 @@
   if (game.calendar.calendar_fragments) {
     static char buffer[128];
 
-    if (game.calendar.calendar_fragment_name[game.info.fragment_count][0] != 
'\0') {
-      fc_snprintf(buffer, sizeof(buffer), "%s/%s", textyear(game.info.year),
-                  
_(game.calendar.calendar_fragment_name[game.info.fragment_count]));
-    } else {
-      /* Human readable fragment count starts from 1, not 0 */
-      fc_snprintf(buffer, sizeof(buffer), "%s/%d", textyear(game.info.year),
-                  game.info.fragment_count + 1);
-    }
-
+    fc_snprintf(buffer, sizeof(buffer), "%s/%s", textyear(game.info.year),
+                textcalfrag(game.info.fragment_count));
     return buffer;
   } else {
     return textyear(game.info.year);

Modified: trunk/common/calendar.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/calendar.h?rev=33984&r1=33983&r2=33984&view=diff
==============================================================================
--- trunk/common/calendar.h     (original)
+++ trunk/common/calendar.h     Tue Oct  4 11:06:35 2016
@@ -20,6 +20,7 @@
 int game_next_year(int);
 void game_advance_year(void);
 
+const char *textcalfrag(int frag);
 const char *textyear(int year);
 const char *calendar_text(void);
 

Modified: trunk/common/fc_types.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/fc_types.h?rev=33984&r1=33983&r2=33984&view=diff
==============================================================================
--- trunk/common/fc_types.h     (original)
+++ trunk/common/fc_types.h     Tue Oct  4 11:06:35 2016
@@ -377,6 +377,7 @@
   int minsize;
   int minculture;
   int minyear;
+  int mincalfrag;
   Output_type_id outputtype;
   int terrainclass;                    /* enum terrain_class */
   int terrainalter;                     /* enum terrain_alteration */
@@ -491,6 +492,8 @@
 #define SPECENUM_VALUE39NAME "MinTechs"
 #define SPECENUM_VALUE40 VUT_EXTRAFLAG
 #define SPECENUM_VALUE40NAME "ExtraFlag"
+#define SPECENUM_VALUE41 VUT_MINCALFRAG
+#define SPECENUM_VALUE41NAME "MinCalFrag"
 /* Keep this last. */
 #define SPECENUM_COUNT VUT_COUNT
 #include "specenum_gen.h"

Modified: trunk/common/reqtext.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/reqtext.c?rev=33984&r1=33983&r2=33984&view=diff
==============================================================================
--- trunk/common/reqtext.c      (original)
+++ trunk/common/reqtext.c      Tue Oct  4 11:06:35 2016
@@ -2277,6 +2277,25 @@
     }
     return TRUE;
 
+  case VUT_MINCALFRAG:
+    if (preq->range != REQ_RANGE_WORLD) {
+      break;
+    }
+    if (preq->present) {
+      cat_snprintf(buf, bufsz,
+                   /* TRANS: %s is a representation of a calendar fragment,
+                    * from the ruleset. May be a bare number. */
+                   _("Requires the game to have reached %s."),
+                   textcalfrag(preq->source.value.mincalfrag));
+    } else {
+      cat_snprintf(buf, bufsz,
+                   /* TRANS: %s is a representation of a calendar fragment,
+                    * from the ruleset. May be a bare number. */
+                   _("Requires that the game has not yet reached %s."),
+                   textcalfrag(preq->source.value.mincalfrag));
+    }
+    return TRUE;
+
   case VUT_TOPO:
     if (preq->range != REQ_RANGE_WORLD) {
       break;

Modified: trunk/common/requirements.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/requirements.c?rev=33984&r1=33983&r2=33984&view=diff
==============================================================================
--- trunk/common/requirements.c (original)
+++ trunk/common/requirements.c Tue Oct  4 11:06:35 2016
@@ -301,6 +301,13 @@
   case VUT_MINYEAR:
     source->value.minyear = atoi(value);
     return;
+  case VUT_MINCALFRAG:
+    /* Rule names are 0-based numbers, not pretty names from ruleset */
+    source->value.mincalfrag = atoi(value);
+    if (source->value.mincalfrag >= 0) {
+      /* More range checking done later, in sanity_check_req_individual() */
+      return;
+    }
   case VUT_TOPO:
     source->value.topo_property = topo_flag_by_name(value, fc_strcasecmp);
     if (topo_flag_is_valid(source->value.topo_property)) {
@@ -495,6 +502,9 @@
     return source;
   case VUT_MINYEAR:
     source.value.minyear = value;
+    return source;
+  case VUT_MINCALFRAG:
+    source.value.mincalfrag = value;
     return source;
   case VUT_TOPO:
     source.value.topo_property = value;
@@ -610,6 +620,8 @@
     return source->value.extraflag;
   case VUT_MINYEAR:
     return source->value.minyear;
+  case VUT_MINCALFRAG:
+    return source->value.mincalfrag;
   case VUT_TOPO:
     return source->value.topo_property;
   case VUT_TERRAINALTER:
@@ -718,6 +730,7 @@
         req.range = REQ_RANGE_PLAYER;
         break;
       case VUT_MINYEAR:
+      case VUT_MINCALFRAG:
       case VUT_TOPO:
       case VUT_MINTECHS:
         req.range = REQ_RANGE_WORLD;
@@ -810,6 +823,7 @@
                  && req.range != REQ_RANGE_ADJACENT);
       break;
     case VUT_MINYEAR:
+    case VUT_MINCALFRAG:
     case VUT_TOPO:
       invalid = (req.range != REQ_RANGE_WORLD);
       break;
@@ -870,6 +884,7 @@
     case VUT_AI_LEVEL:
     case VUT_TERRAINCLASS:
     case VUT_MINYEAR:
+    case VUT_MINCALFRAG:
     case VUT_TOPO:
     case VUT_TERRAINALTER:
     case VUT_CITYTILE:
@@ -2941,6 +2956,9 @@
     break;
   case VUT_MINYEAR:
     eval = BOOL_TO_TRISTATE(game.info.year >= req->source.value.minyear);
+    break;
+  case VUT_MINCALFRAG:
+    eval = BOOL_TO_TRISTATE(game.info.fragment_count >= 
req->source.value.mincalfrag);
     break;
   case VUT_TOPO:
     eval = 
BOOL_TO_TRISTATE(current_topo_has_flag(req->source.value.topo_property));
@@ -3068,6 +3086,7 @@
   case VUT_AGE:
   case VUT_ROADFLAG:
   case VUT_EXTRAFLAG:
+  case VUT_MINCALFRAG:  /* cyclically available */
     return FALSE;
   case VUT_TERRAIN:
   case VUT_EXTRA:
@@ -3195,6 +3214,8 @@
     return psource1->value.extraflag == psource2->value.extraflag;
   case VUT_MINYEAR:
     return psource1->value.minyear == psource2->value.minyear;
+  case VUT_MINCALFRAG:
+    return psource1->value.mincalfrag == psource2->value.mincalfrag;
   case VUT_TOPO:
     return psource1->value.topo_property == psource2->value.topo_property;
   case VUT_TERRAINALTER:
@@ -3224,6 +3245,11 @@
     return citytile_type_name(psource->value.citytile);
   case VUT_MINYEAR:
     fc_snprintf(buffer, sizeof(buffer), "%d", psource->value.minyear);
+
+    return buffer;
+  case VUT_MINCALFRAG:
+    /* Rule name is 0-based number, not pretty name from ruleset */
+    fc_snprintf(buffer, sizeof(buffer), "%d", psource->value.mincalfrag);
 
     return buffer;
   case VUT_TOPO:
@@ -3545,6 +3571,12 @@
     cat_snprintf(buf, bufsz, _("After %s"),
                  textyear(psource->value.minyear));
     return buf;
+  case VUT_MINCALFRAG:
+    /* TRANS: here >= means 'greater than or equal'.
+     * %s identifies a calendar fragment (may be bare number). */
+    cat_snprintf(buf, bufsz, _(">=%s"),
+                 textcalfrag(psource->value.mincalfrag));
+    return buf;
   case VUT_TOPO:
     cat_snprintf(buf, bufsz, _("%s map"),
                  _(topo_flag_name(psource->value.topo_property)));

Modified: trunk/doc/README.effects
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/doc/README.effects?rev=33984&r1=33983&r2=33984&view=diff
==============================================================================
--- trunk/doc/README.effects    (original)
+++ trunk/doc/README.effects    Tue Oct  4 11:06:35 2016
@@ -69,6 +69,7 @@
 OutputType:    Local
 Specialist:    Local
 MinYear:       World
+MinCalFrag:    World
 Topology:      World
 Age:           Local, City
 MinSize:       Traderoute, City
@@ -95,6 +96,8 @@
 UnitState is "Transported", "Transporting", "OnNativeTile", "OnLivableTile",
 "OnDomesticTile" or "HasHomeCity".
 MinMoveFargs is the minimum move fragments the unit must have left.
+MinCalFrag is the minimum sub-year division the calendar must have reached,
+if enabled (see [calendar].fragments in game.ruleset).
 
 Effect types
 ============

Modified: trunk/server/cityturn.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/cityturn.c?rev=33984&r1=33983&r2=33984&view=diff
==============================================================================
--- trunk/server/cityturn.c     (original)
+++ trunk/server/cityturn.c     Tue Oct  4 11:06:35 2016
@@ -1889,6 +1889,40 @@
                 success = FALSE;
               }
               break;
+            case VUT_MINCALFRAG:
+              /* Unlike VUT_MINYEAR, a requirement in either direction is
+               * likely to be fulfilled sooner or later. */
+              if (preq->present) {
+                notify_player(pplayer, city_tile(pcity),
+                              E_CITY_CANTBUILD, ftc_server,
+                              /* TRANS: last %s is a calendar fragment from
+                               * the ruleset; may be a bare number */
+                              _("%s can't build %s from the worklist; "
+                                "only available from %s. Postponing..."),
+                              city_link(pcity),
+                              city_improvement_name_translation(pcity, 
ptarget),
+                              textcalfrag(preq->source.value.mincalfrag));
+                script_server_signal_emit("building_cant_be_built", 3,
+                                          API_TYPE_BUILDING_TYPE, ptarget,
+                                          API_TYPE_CITY, pcity,
+                                          API_TYPE_STRING, "need_mincalfrag");
+              } else {
+                fc_assert_action(preq->source.value.mincalfrag > 0, break);
+                notify_player(pplayer, city_tile(pcity),
+                              E_CITY_CANTBUILD, ftc_server,
+                              /* TRANS: last %s is a calendar fragment from
+                               * the ruleset; may be a bare number */
+                              _("%s can't build %s from the worklist; "
+                                "not available after %s. Postponing..."),
+                              city_link(pcity),
+                              city_improvement_name_translation(pcity, 
ptarget),
+                              textcalfrag(preq->source.value.mincalfrag-1));
+                script_server_signal_emit("building_cant_be_built", 3,
+                                          API_TYPE_BUILDING_TYPE, ptarget,
+                                          API_TYPE_CITY, pcity,
+                                          API_TYPE_STRING, "have_mincalfrag");
+              }
+              break;
             case VUT_TOPO:
               if (preq->present) {
                 notify_player(pplayer, city_tile(pcity),

Modified: trunk/server/rssanity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/rssanity.c?rev=33984&r1=33983&r2=33984&view=diff
==============================================================================
--- trunk/server/rssanity.c     (original)
+++ trunk/server/rssanity.c     Tue Oct  4 11:06:35 2016
@@ -108,6 +108,20 @@
       }
     }
     break;
+  case VUT_MINCALFRAG:
+    /* Currently [calendar] is loaded after some requirements are
+     * parsed, so we can't do this in universal_value_from_str(). */
+    if (game.calendar.calendar_fragments < 1) {
+      log_error("%s: MinCalFrag requirement used in ruleset without "
+                "calendar fragments", list_for);
+      return FALSE;
+    } else if (preq->source.value.mincalfrag >= 
game.calendar.calendar_fragments) {
+      log_error("%s: MinCalFrag requirement %d out of range (max %d in "
+                "this ruleset)", list_for, preq->source.value.mincalfrag,
+                game.calendar.calendar_fragments-1);
+      return FALSE;
+    }
+    break;
   default:
     /* No other universals have checks that can't be done at ruleset
      * load time. See req_from_str(). */
@@ -180,6 +194,7 @@
      case VUT_MINVETERAN: /* Breaks nothing, but has no sense either */
      case VUT_MINHP: /* Breaks nothing, but has no sense either */
      case VUT_MINYEAR:
+     case VUT_MINCALFRAG:
      case VUT_AI_LEVEL:
      case VUT_TERRAINALTER: /* Local range only */
      case VUT_CITYTILE:

Modified: trunk/tools/ruledit/univ_value.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/univ_value.c?rev=33984&r1=33983&r2=33984&view=diff
==============================================================================
--- trunk/tools/ruledit/univ_value.c    (original)
+++ trunk/tools/ruledit/univ_value.c    Tue Oct  4 11:06:35 2016
@@ -101,6 +101,9 @@
   case VUT_MINYEAR:
     src->value.minyear = 0;
     return TRUE;
+  case VUT_MINCALFRAG:
+    src->value.mincalfrag = 0;
+    return TRUE;
   case VUT_TERRAINALTER:
     src->value.terrainalter = TA_CAN_IRRIGATE;
     return TRUE;
@@ -375,6 +378,7 @@
     break;
   case VUT_MINSIZE:
   case VUT_MINYEAR:
+  case VUT_MINCALFRAG:
   case VUT_MAXTILEUNITS:
   case VUT_MINCULTURE:
   case VUT_MINMOVES:


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

Reply via email to