Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12686) new effect slow_down_timeline
Home

[Freeciv-Dev] (PR#12686) new effect slow_down_timeline

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12686) new effect slow_down_timeline
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 28 Mar 2005 18:01:51 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12686 >

This patch implements a new effect EFT_SLOW_DOWN_TIMELINE.  This 
replaces the *crazy* check we have now that checks the tech requirements 
of building requirements of space-part effects.  The actual code for 
this (in game.c) becomes rather simple.

However I had to add support for world-range tech requirements.  This 
means a new target TARGET_WORLD (remember I plan to remove the 
target_type enum), a function get_world_effects(), and a helper function 
is_tech_in_range().

-jason

Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.206
diff -u -r1.206 aicity.c
--- ai/aicity.c 24 Mar 2005 16:41:40 -0000      1.206
+++ ai/aicity.c 29 Mar 2005 01:53:38 -0000
@@ -326,6 +326,10 @@
        case EFT_WASTE_PCT:
          break;
 
+      case EFT_SLOW_DOWN_TIMELINE:
+       /* AI doesn't care about these. */
+       break;
+
        /* WAG evaluated effects */
        case EFT_INCITE_DIST_PCT:
          if (palace) {
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.228
diff -u -r1.228 capstr.c
--- common/capstr.c     28 Mar 2005 17:14:57 -0000      1.228
+++ common/capstr.c     29 Mar 2005 01:53:38 -0000
@@ -82,7 +82,7 @@
  *     as long as possible.  We want to maintain network compatibility with
  *     the stable branch for as long as possible.
  */
-#define CAPABILITY "+Freeciv.Devel.2004.Mar.28"
+#define CAPABILITY "+Freeciv.Devel.2004.Mar.28b"
 
 void init_our_capability(void)
 {
Index: common/effects.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.c,v
retrieving revision 1.24
diff -u -r1.24 effects.c
--- common/effects.c    9 Mar 2005 18:37:52 -0000       1.24
+++ common/effects.c    29 Mar 2005 01:53:39 -0000
@@ -117,7 +117,8 @@
   "Missile_Defend",
   "No_Incite",
   "Regen_Reputation",
-  "Gain_AI_Love"
+  "Gain_AI_Love",
+  "Slow_Down_Timeline"
 };
 
 /**************************************************************************
@@ -715,6 +716,15 @@
 }
 
 /**************************************************************************
+  Returns the effect bonus for the whole world.
+**************************************************************************/
+int get_world_bonus(enum effect_type effect_type)
+{
+  return get_target_bonus_effects(NULL, TARGET_WORLD,
+                                 NULL, NULL, B_LAST, NULL, effect_type);
+}
+
+/**************************************************************************
   Returns the effect bonus for a player.
 **************************************************************************/
 int get_player_bonus(const struct player *pplayer,
Index: common/effects.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.h,v
retrieving revision 1.14
diff -u -r1.14 effects.h
--- common/effects.h    2 Feb 2005 02:44:31 -0000       1.14
+++ common/effects.h    29 Mar 2005 01:53:39 -0000
@@ -105,6 +105,7 @@
   EFT_NO_INCITE,
   EFT_REGEN_REPUTATION,
   EFT_GAIN_AI_LOVE,
+  EFT_SLOW_DOWN_TIMELINE,
   EFT_LAST     /* keep this last */
 };
 
@@ -166,6 +167,7 @@
 bool is_building_replaced(const struct city *pcity, Impr_Type_id building);
 
 /* functions to know the bonuses a certain effect is granting */
+int get_world_bonus(enum effect_type effect_type);
 int get_player_bonus(const struct player *plr, enum effect_type effect_type);
 int get_city_bonus(const struct city *pcity, enum effect_type effect_type);
 int get_city_tile_bonus(const struct city *pcity, const struct tile *ptile,
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.202
diff -u -r1.202 game.c
--- common/game.c       25 Mar 2005 13:08:29 -0000      1.202
+++ common/game.c       29 Mar 2005 01:53:39 -0000
@@ -374,7 +374,8 @@
 ***************************************************************/
 int game_next_year(int year)
 {
-  int spaceshipparts, space_parts[3] = {0, 0, 0};
+  const int slowdown = (game.spacerace
+                       ? get_world_bonus(EFT_SLOW_DOWN_TIMELINE) : 0);
 
   if (year == 1) /* hacked it to get rid of year 0 */
     year = 0;
@@ -392,38 +393,15 @@
    * about 1900 AD
    */
 
-  /* Count how many of the different spaceship parts we can build.  Note this
-   * operates even if Enable_Space is not active. */
-  if (game.spacerace) {
-    impr_type_iterate(impr) {
-      Tech_Type_id t = improvement_types[impr].tech_req;
-
-      if (!improvement_exists(impr)) {
-       continue;
-      }
-      if (building_has_effect(impr, EFT_SS_STRUCTURAL)
-         && tech_exists(t) && game.global_advances[t] != 0) {
-       space_parts[0] = 1;
-      }
-      if (building_has_effect(impr, EFT_SS_COMPONENT)
-         && tech_exists(t) && game.global_advances[t] != 0) {
-       space_parts[1] = 1;
-      }
-      if (building_has_effect(impr, EFT_SS_MODULE)
-         && tech_exists(t) && game.global_advances[t] != 0) {
-       space_parts[2] = 1;
-      }
-    } impr_type_iterate_end;
-  }
-  spaceshipparts = space_parts[0] + space_parts[1] + space_parts[2];
-
-  if( year >= 1900 || ( spaceshipparts>=3 && year>0 ) )
+  /* Note the slowdown operates even if Enable_Space is not active.  See
+   * README.effects for specifics. */
+  if (year >= 1900 || (slowdown >= 3 && year > 0)) {
     year += 1;
-  else if( year >= 1750 || spaceshipparts>=2 )
+  } else if (year >= 1750 || slowdown >= 2) {
     year += 2;
-  else if( year >= 1500 || spaceshipparts>=1 )
+  } else if (year >= 1500 || slowdown >= 1) {
     year += 5;
-  else if( year >= 1000 )
+  } else if( year >= 1000 )
     year += 10;
   else if( year >= 0 )
     year += 20;
Index: common/requirements.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.c,v
retrieving revision 1.7
diff -u -r1.7 requirements.c
--- common/requirements.c       26 Mar 2005 05:59:15 -0000      1.7
+++ common/requirements.c       29 Mar 2005 01:53:39 -0000
@@ -311,6 +311,8 @@
                               enum req_range range)
 {
   switch (target) {
+  case TARGET_WORLD:
+    return (range >= REQ_RANGE_WORLD);
   case TARGET_PLAYER:
     return (range >= REQ_RANGE_PLAYER);
   case TARGET_CITY:
@@ -448,10 +450,6 @@
                             enum req_range range, bool survives,
                             Impr_Type_id source)
 {
-  if (!is_target_possible(target, range)) {
-    return 0;
-  }
-
   if (improvement_obsolete(target_player, source)) {
     return 0;
   }
@@ -497,6 +495,32 @@
 }
 
 /****************************************************************************
+  Is there a source tech within range of the target?
+****************************************************************************/
+static bool is_tech_in_range(enum target_type target,
+                            const struct player *target_player,
+                            enum req_range range,
+                            Tech_Type_id tech)
+{
+  switch (range) {
+  case REQ_RANGE_PLAYER:
+    return (target_player
+           && get_invention(target_player, tech) == TECH_KNOWN);
+  case REQ_RANGE_WORLD:
+    return game.global_advances[tech] > 0;
+  case REQ_RANGE_LOCAL:
+  case REQ_RANGE_ADJACENT:
+  case REQ_RANGE_CITY:
+  case REQ_RANGE_CONTINENT:
+  case REQ_RANGE_LAST:
+    break;
+  }
+
+  assert(0);
+  return FALSE;
+}
+
+/****************************************************************************
   Is there a source special within range of the target?
 ****************************************************************************/
 static bool is_special_in_range(enum target_type target,
@@ -575,6 +599,10 @@
                   const struct tile *target_tile,
                   const struct requirement *req)
 {
+  if (!is_target_possible(target, req->range)) {
+    return FALSE;
+  }
+
   /* Note the target may actually not exist.  In particular, effects that
    * have a REQ_SPECIAL or REQ_TERRAIN may often be passed to this function
    * with a city as their target.  In this case the requirement is simply
@@ -584,9 +612,8 @@
     return TRUE;
   case REQ_TECH:
     /* The requirement is filled if the player owns the tech. */
-    return (target_player
-           && get_invention(target_player,
-                            req->source.value.tech) == TECH_KNOWN);
+    return is_tech_in_range(target, target_player, req->range,
+                           req->source.value.tech);
   case REQ_GOV:
     /* The requirement is filled if the player is using the government. */
     return (target_player
Index: common/requirements.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.h,v
retrieving revision 1.5
diff -u -r1.5 requirements.h
--- common/requirements.h       26 Mar 2005 05:59:15 -0000      1.5
+++ common/requirements.h       29 Mar 2005 01:53:39 -0000
@@ -45,6 +45,7 @@
  * unit reqs the target will be a city; for tech reqs it will be a player;
  * for effect reqs it may be anything. */
 enum target_type {
+  TARGET_WORLD,
   TARGET_PLAYER,
   TARGET_CITY,
   TARGET_BUILDING 
Index: data/default/effects.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/effects.ruleset,v
retrieving revision 1.4
diff -u -r1.4 effects.ruleset
--- data/default/effects.ruleset        24 Mar 2005 16:41:42 -0000      1.4
+++ data/default/effects.ruleset        29 Mar 2005 01:53:39 -0000
@@ -625,6 +625,30 @@
       "Building", "Space Structural", "City"
     }
 
+[effect_plastics_slowdown]
+name    = "Slow_Down_Timeline"
+value   = 1
+reqs    =
+    { "type", "name", "range"
+      "Tech", "Plastics", "World"
+    }
+
+[effect_superconductor_slowdown]
+name    = "Slow_Down_Timeline"
+value   = 1
+reqs    =
+    { "type", "name", "range"
+      "Tech", "Superconductors", "World"
+    }
+
+[effect_spaceflight_slowdown]
+name    = "Slow_Down_Timeline"
+value   = 1
+reqs    =
+    { "type", "name", "range"
+      "Tech", "Space Flight", "World"
+    }
+
 [effect_stock_exchange]
 name   = "Tax_Bonus"
 value  = 50
Index: doc/README.effects
===================================================================
RCS file: /home/freeciv/CVS/freeciv/doc/README.effects,v
retrieving revision 1.6
diff -u -r1.6 README.effects
--- doc/README.effects  23 Mar 2005 02:07:45 -0000      1.6
+++ doc/README.effects  29 Mar 2005 01:53:39 -0000
@@ -153,6 +153,14 @@
 "Regen_Reputation" - Increase your reputation by AMOUNT units (out of 1000)
                   per turn
 
+"Slow_Down_Timeline" - Slow down the timeline based on the AMOUNT.  If
+                       AMOUNT >= 3 the timeline will be 1 year/turn; with
+                       AMOUNT == 2 it is 2 years/turn; with
+                       AMOUNT == 1 it is 5 years/turn; with
+                       AMOUNT <= 0 the timeline is unaffected.
+                       The effect will be ignored if game.spacerace isn't
+                       set.
+
 
 .range may be one of: 
              "None", "Local", "Adjacent", "City", "Continent",

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12686) new effect slow_down_timeline, Jason Short <=