Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] Re: (PR#9892) space part effects
Home

[Freeciv-Dev] Re: (PR#9892) space part effects

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#9892) space part effects
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 1 Sep 2004 07:29:00 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9892 >

Gregory Berkolaiko wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=9892 >
> 
> On Tue, 31 Aug 2004, Jason Short wrote:
> 
> 
>><URL: http://rt.freeciv.org/Ticket/Display.html?id=9892 >
>>
>>In Vasco's effects patch the Space_Part effect is replaced with
>>SS_Component, SS_Structural, and SS_Module effects.  The only real
>>advantage of this is that building_has_effect can be used directly
>>(since that function returns a boolean rather than an integer).
> 
> 
> Against what is this patch?  CVS?  Because you seem to forgot to update
> building_has_effect so the first time it gets called you get an assert

Indeed, that part didn't get updated correctly.  This patch fixes that.

It also changes game_next_year to use this data.  In Vasco's patch he 
adds a tech flag TF_SPACE_PART_INC.  If spacerace is enabled and techs 
with this flag are known then years go by slower (this is the only 
effect).  This isn't documented very well, and if the number of techs 
with the flag isn't exactly 3 then it won't work very well.  This patch 
just goes straight to the source and finds out how many of the three 
spaceship parts have known tech_reqs.  Note that it's possible for one 
tech to provide more than one part, or for one part to be provided by 
more than one building.

jason

Index: common/effects.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.c,v
retrieving revision 1.7
diff -u -r1.7 effects.c
--- common/effects.c    1 Sep 2004 03:16:47 -0000       1.7
+++ common/effects.c    1 Sep 2004 14:23:30 -0000
@@ -98,7 +98,9 @@
   "Size_Unlimit",
   "Slow_Nuke_Winter",
   "Slow_Global_Warm",
-  "Space_Part",
+  "SS_Structural",
+  "SS_Component",
+  "SS_Module",
   "Spy_Resistant",
   "Tax_Bonus",
   "Tax_Pct",
@@ -232,6 +234,12 @@
   switch (effect) {
   case EFT_PROD_TO_GOLD:
     return building == B_CAPITAL;
+  case EFT_SS_STRUCTURAL:
+    return building == B_SSTRUCTURAL;
+  case EFT_SS_COMPONENT:
+    return building == B_SCOMP;
+  case EFT_SS_MODULE:
+    return building == B_SMODULE;
   default:
     break;
   }
@@ -253,10 +261,24 @@
 int get_current_construction_bonus(const struct city *pcity,
                                   enum effect_type effect)
 {
-  if (effect == EFT_PROD_TO_GOLD) {
-    return (!pcity->is_building_unit 
-           && pcity->currently_building == B_CAPITAL) ? 1 : 0;
+  if (pcity->is_building_unit) {
+    return 0; /* No effects for units. */
   }
+
+  switch (effect) {
+  case EFT_PROD_TO_GOLD:
+    return (pcity->currently_building == B_CAPITAL) ? 1 : 0;
+  case EFT_SS_STRUCTURAL:
+    return (pcity->currently_building == B_SSTRUCTURAL) ? 1 : 0;
+  case EFT_SS_COMPONENT:
+    return (pcity->currently_building == B_SCOMP) ? 1 : 0;
+  case EFT_SS_MODULE:
+    return (pcity->currently_building == B_SMODULE) ? 1 : 0;
+  default:
+    /* All others unsupported. */
+    break;
+  }
+
   assert(0);
   return 0;
 }
Index: common/effects.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.h,v
retrieving revision 1.5
diff -u -r1.5 effects.h
--- common/effects.h    1 Sep 2004 03:16:47 -0000       1.5
+++ common/effects.h    1 Sep 2004 14:23:30 -0000
@@ -91,7 +91,9 @@
   EFT_SIZE_UNLIMIT,
   EFT_SLOW_NUKE_WINTER,
   EFT_SLOW_GLOBAL_WARM,
-  EFT_SPACE_PART,
+  EFT_SS_STRUCTURAL,
+  EFT_SS_COMPONENT,
+  EFT_SS_MODULE,
   EFT_SPY_RESISTANT,
   EFT_TAX_BONUS,
   EFT_TAX_PCT,
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.183
diff -u -r1.183 game.c
--- common/game.c       21 Jul 2004 16:34:33 -0000      1.183
+++ common/game.c       1 Sep 2004 14:23:30 -0000
@@ -365,8 +365,7 @@
 ***************************************************************/
 int game_next_year(int year)
 {
-  int spaceshipparts, i;
-  Impr_Type_id parts[] = { B_SCOMP, B_SMODULE, B_SSTRUCTURAL, B_LAST };
+  int spaceshipparts, space_parts[3] = {0, 0, 0};
 
   if (year == 1) /* hacked it to get rid of year 0 */
     year = 0;
@@ -384,14 +383,30 @@
    * about 1900 AD
    */
 
-  spaceshipparts= 0;
+  /* Count how many of the different spaceship parts we can build.  Note this
+   * operates even if Enable_Space is not active. */
   if (game.spacerace) {
-    for(i=0; parts[i] < B_LAST; i++) {
-      int t = improvement_types[parts[i]].tech_req;
-      if (tech_exists(t) && game.global_advances[t] != 0)
-       spaceshipparts++;
-    }
+    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 ) )
     year += 1;
Index: common/improvement.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.c,v
retrieving revision 1.44
diff -u -r1.44 improvement.c
--- common/improvement.c        1 Sep 2004 03:16:47 -0000       1.44
+++ common/improvement.c        1 Sep 2004 14:23:30 -0000
@@ -130,9 +130,13 @@
   if (id<0 || id>=B_LAST || id>=game.num_impr_types)
     return FALSE;
 
-  if ((id==B_SCOMP || id==B_SMODULE || id==B_SSTRUCTURAL)
-      && !game.spacerace)
+  if (!game.spacerace
+      && (building_has_effect(id, EFT_SS_STRUCTURAL)
+         || building_has_effect(id, EFT_SS_COMPONENT)
+         || building_has_effect(id, EFT_SS_MODULE))) {
+    /* This assumes that space parts don't have any other effects. */
     return FALSE;
+  }
 
   return (improvement_types[id].tech_req!=A_LAST);
 }
@@ -383,6 +387,7 @@
                                              Impr_Type_id id)
 {
   struct impr_type *impr;
+  bool space_part = FALSE;
 
   /* This also checks if tech req is Never */
   if (!improvement_exists(id))
@@ -390,28 +395,31 @@
 
   impr = get_improvement_type(id);
 
-  if (impr->effect) {
-    struct impr_effect *peffect = impr->effect;
-    enum effect_type type;
-
-    /* This if for a spaceship component is asked */
-    while ((type = peffect->type) != EFT_LAST) {
-      if (type == EFT_SPACE_PART) {
-       /* TODO: remove this */
-       if (game.global_wonders[B_APOLLO] == 0)
-         return FALSE;
-        if (p->spaceship.state >= SSHIP_LAUNCHED)
-         return FALSE;
-       if (peffect->amount == 1 && p->spaceship.structurals >= 
NUM_SS_STRUCTURALS)
-         return FALSE;
-       if (peffect->amount == 2 && p->spaceship.components >= 
NUM_SS_COMPONENTS)
-         return FALSE;
-       if (peffect->amount == 3 && p->spaceship.modules >= NUM_SS_MODULES)
-         return FALSE;
-      }
-      peffect++;
+  /* Check for space part construction.  This assumes that space parts have
+   * no other effects. */
+  if (building_has_effect(id, EFT_SS_STRUCTURAL)) {
+    space_part = TRUE;
+    if (p->spaceship.structurals >= NUM_SS_STRUCTURALS) {
+      return FALSE;
     }
   }
+  if (building_has_effect(id, EFT_SS_COMPONENT)) {
+    space_part = TRUE;
+    if (p->spaceship.components >= NUM_SS_COMPONENTS) {
+      return FALSE;
+    }
+  }
+  if (building_has_effect(id, EFT_SS_MODULE)) {
+    space_part = TRUE;
+    if (p->spaceship.modules >= NUM_SS_MODULES) {
+      return FALSE;
+    }
+  }
+  if (space_part && (game.global_wonders[B_APOLLO] == 0
+                    || p->spaceship.state >= SSHIP_LAUNCHED)) {
+    return FALSE;
+  }
+
   if (is_wonder(id)) {
     /* Can't build wonder if already built */
     if (game.global_wonders[id] != 0) return FALSE;
Index: data/civ1/buildings.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ1/buildings.ruleset,v
retrieving revision 1.35
diff -u -r1.35 buildings.ruleset
--- data/civ1/buildings.ruleset 27 Aug 2004 17:14:42 -0000      1.35
+++ data/civ1/buildings.ruleset 1 Sep 2004 14:23:31 -0000
@@ -1000,8 +1000,8 @@
 upkeep         = 0
 sabotage       = 100
 effect         =
-    { "type", "range", "amount"
-       "Space_Part", "Local", 2
+    { "type", "range"
+       "SS_Component", "Local"
     }
 sound          = "b_space_component"
 sound_alt      = "b_generic"
@@ -1031,8 +1031,8 @@
 upkeep         = 0
 sabotage       = 100
 effect         =
-    { "type", "range", "amount"
-       "Space_Part", "Local", 3
+    { "type", "range"
+       "SS_Module", "Local"
     }
 sound          = "b_space_module"
 sound_alt      = "b_generic"
@@ -1071,8 +1071,8 @@
 upkeep         = 0
 sabotage       = 100
 effect         =
-    { "type", "range", "amount"
-       "Space_Part", "Local", 1
+    { "type", "range"
+       "SS_Structural", "Local"
     }
 sound          = "b_space_structural"
 sound_alt      = "b_generic"
Index: data/civ2/buildings.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ2/buildings.ruleset,v
retrieving revision 1.38
diff -u -r1.38 buildings.ruleset
--- data/civ2/buildings.ruleset 27 Aug 2004 17:14:42 -0000      1.38
+++ data/civ2/buildings.ruleset 1 Sep 2004 14:23:31 -0000
@@ -991,8 +991,8 @@
 upkeep         = 0
 sabotage       = 100
 effect         =
-    { "type", "range", "amount"
-       "Space_Part", "Local", 2
+    { "type", "range"
+       "SS_Component", "Local"
     }
 sound          = "b_space_component"
 sound_alt      = "b_generic"
@@ -1022,8 +1022,8 @@
 upkeep         = 0
 sabotage       = 100
 effect         =
-    { "type", "range", "amount"
-       "Space_Part", "Local", 3
+    { "type", "range"
+       "SS_Module", "Local"
     }
 sound          = "b_space_module"
 sound_alt      = "b_generic"
@@ -1062,8 +1062,8 @@
 upkeep         = 0
 sabotage       = 100
 effect         =
-    { "type", "range", "amount"
-       "Space_Part", "Local", 1
+    { "type", "range"
+       "SS_Structural", "Local"
     }
 sound          = "b_space_structural"
 sound_alt      = "b_generic"
Index: data/default/buildings.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/buildings.ruleset,v
retrieving revision 1.50
diff -u -r1.50 buildings.ruleset
--- data/default/buildings.ruleset      27 Aug 2004 17:14:42 -0000      1.50
+++ data/default/buildings.ruleset      1 Sep 2004 14:23:32 -0000
@@ -1058,8 +1058,8 @@
 upkeep         = 0
 sabotage       = 100
 effect         =
-    { "type", "range", "amount"
-       "Space_Part", "Local", 2
+    { "type", "range"
+       "SS_Component", "Local"
     }
 sound          = "b_space_component"
 sound_alt      = "b_generic"
@@ -1089,8 +1089,8 @@
 upkeep         = 0
 sabotage       = 100
 effect         =
-    { "type", "range", "amount"
-       "Space_Part", "Local", 3
+    { "type", "range"
+       "SS_Module", "Local"
     }
 sound          = "b_space_module"
 sound_alt      = "b_generic"
@@ -1129,8 +1129,8 @@
 upkeep         = 0
 sabotage       = 100
 effect         =
-    { "type", "range", "amount"
-       "Space_Part", "Local", 1
+    { "type", "range"
+       "SS_Structural", "Local"
     }
 sound          = "b_space_structural"
 sound_alt      = "b_generic"
Index: data/history/buildings.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/history/buildings.ruleset,v
retrieving revision 1.10
diff -u -r1.10 buildings.ruleset
--- data/history/buildings.ruleset      27 Aug 2004 17:14:42 -0000      1.10
+++ data/history/buildings.ruleset      1 Sep 2004 14:23:32 -0000
@@ -1011,8 +1011,8 @@
 upkeep         = 0
 sabotage       = 100
 effect         =
-    { "type", "range", "amount"
-       "Space_Part", "Local", 2
+    { "type", "range"
+       "SS_Component", "Local"
     }
 sound          = "b_space_component"
 sound_alt      = "b_generic"
@@ -1042,8 +1042,8 @@
 upkeep         = 0
 sabotage       = 100
 effect         =
-    { "type", "range", "amount"
-       "Space_Part", "Local", 3
+    { "type", "range"
+       "SS_Module", "Local"
     }
 sound          = "b_space_module"
 sound_alt      = "b_generic"
@@ -1082,8 +1082,8 @@
 upkeep         = 0
 sabotage       = 100
 effect         =
-    { "type", "range", "amount"
-       "Space_Part", "Local", 1
+    { "type", "range"
+       "SS_Structural", "Local"
     }
 sound          = "b_space_structural"
 sound_alt      = "b_generic"
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.258
diff -u -r1.258 cityturn.c
--- server/cityturn.c   28 Aug 2004 19:15:39 -0000      1.258
+++ server/cityturn.c   1 Sep 2004 14:23:33 -0000
@@ -934,11 +934,11 @@
     }
 
     space_part = TRUE;
-    if (pcity->currently_building == B_SSTRUCTURAL) {
+    if (get_current_construction_bonus(pcity, EFT_SS_STRUCTURAL) > 0) {
       pplayer->spaceship.structurals++;
-    } else if (pcity->currently_building == B_SCOMP) {
+    } else if (get_current_construction_bonus(pcity, EFT_SS_COMPONENT) > 0) {
       pplayer->spaceship.components++;
-    } else if (pcity->currently_building == B_SMODULE) {
+    } else if (get_current_construction_bonus(pcity, EFT_SS_MODULE) > 0) {
       pplayer->spaceship.modules++;
     } else {
       space_part = FALSE;

[Prev in Thread] Current Thread [Next in Thread]