Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] (PR#9878) new function building_has_effect
Home

[Freeciv-Dev] (PR#9878) new function building_has_effect

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9878) new function building_has_effect
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 30 Aug 2004 17:29:56 -0700
Reply-to: rt@xxxxxxxxxxx

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

This patch adds a new function building_has_effect.  This function takes 
a building type and an effect type and returns a boolean indicating 
whether the building provides the effect.  Unlike other functions which 
return the value of the effect, this one just returns a boolean. 
Finding the value of the effect requires more work (in theory) and also 
means knowing the range.  This function therefore will probably only 
ever work for some effects.

Naturally this function is taken from the effects patch.

To begin with only EFT_PROD_TO_GOLD (provided by B_CAPITAL) is supported.

I had to move the improvement_type enumeration into fc_types.h to make 
this work.  Otherwise there is a circular dependency between 
improvement.h and effects.h.  Of course eventually this enum should turn 
into an int.  In the process of moving I removed the enum name (having 
it around might tempt people to _use_ it) and the unnecessary #define 
(unecessary IMO since when the time comes we can just change the code).

jason

? civworld
? map
? map.in
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.43
diff -u -r1.43 citydlg_common.c
--- client/citydlg_common.c     28 Aug 2004 19:15:39 -0000      1.43
+++ client/citydlg_common.c     31 Aug 2004 00:24:24 -0000
@@ -281,7 +281,7 @@
                                     int id, bool is_unit,
                                     struct city *pcity)
 {
-  if (!is_unit && id == B_CAPITAL) {
+  if (!is_unit && building_has_effect(id, EFT_PROD_TO_GOLD)) {
     my_snprintf(buffer, buffer_len, _("%s (XX) %d/turn"),
                get_impr_name_ex(pcity, id), MAX(0, pcity->shield_surplus));
   } else {
@@ -333,7 +333,7 @@
     my_snprintf(buf[2], column_size, "%d", unit_build_shield_cost(id));
   } else {
     /* Total & turns left meaningless on capitalization */
-    if (id == B_CAPITAL) {
+    if (building_has_effect(id, EFT_PROD_TO_GOLD)) {
       my_snprintf(buf[0], column_size, get_improvement_type(id)->name);
       buf[1][0] = '\0';
       my_snprintf(buf[2], column_size, "---");
@@ -365,7 +365,7 @@
 
   /* Add the turns-to-build entry in the 4th position */
   if (pcity) {
-    if (!is_unit && id == B_CAPITAL) {
+    if (!is_unit && building_has_effect(id, EFT_PROD_TO_GOLD)) {
       my_snprintf(buf[3], column_size, _("%d/turn"),
                  MAX(0, pcity->shield_surplus));
     } else {
Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.136
diff -u -r1.136 climisc.c
--- client/climisc.c    28 Aug 2004 19:15:39 -0000      1.136
+++ client/climisc.c    31 Aug 2004 00:24:24 -0000
@@ -559,7 +559,7 @@
  struct items and also sort it.
 
  section 0: normal buildings
- section 1: B_CAPITAL
+ section 1: Capitalization
  section 2: F_NONMIL units
  section 3: other units
  section 4: wonders
@@ -583,7 +583,7 @@
       pitem->section = unit_type_flag(id, F_NONMIL) ? 2 : 3;
     } else {
       name = get_impr_name_ex(pcity, id);
-      if (id == B_CAPITAL) {
+      if (building_has_effect(id, EFT_PROD_TO_GOLD)) {
        cost = -1;
        pitem->section = 1;
       } else {
Index: common/effects.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.c,v
retrieving revision 1.6
diff -u -r1.6 effects.c
--- common/effects.c    28 Aug 2004 19:15:39 -0000      1.6
+++ common/effects.c    31 Aug 2004 00:24:24 -0000
@@ -215,6 +215,28 @@
 }
 
 /**************************************************************************
+  Returns TRUE if the building has any effect bonuses of the given type.
+
+  Note that this function returns a boolean rather than an integer value
+  giving the exact bonus.  Finding the exact bonus requires knowing the
+  effect range and may take longer.  This function should only be used
+  in situations where the range doesn't matter.
+
+  TODO:
+    1.  This function does not access the effect data directly; instead
+        it just associates the effect with a building.
+    2.  Only a few effects are supported.
+**************************************************************************/
+bool building_has_effect(Impr_Type_id building, enum effect_type effect)
+{
+  if (effect == EFT_PROD_TO_GOLD) {
+    return building == B_CAPITAL;
+  }
+  assert(0);
+  return 0;
+}
+
+/**************************************************************************
   Returns the effect bonus the currently-in-construction-item will provide.
 
   Note this is not called get_current_production_bonus because that would
Index: common/effects.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.h,v
retrieving revision 1.4
diff -u -r1.4 effects.h
--- common/effects.h    28 Aug 2004 19:15:39 -0000      1.4
+++ common/effects.h    31 Aug 2004 00:24:24 -0000
@@ -132,6 +132,7 @@
 bool are_effects_equal(const struct impr_effect *const peff1,
                       const struct impr_effect *const peff2);
 
+bool building_has_effect(Impr_Type_id building, enum effect_type effect);
 int get_current_construction_bonus(const struct city *pcity,
                                   enum effect_type effect);
 
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.3
diff -u -r1.3 fc_types.h
--- common/fc_types.h   28 Aug 2004 19:15:39 -0000      1.3
+++ common/fc_types.h   31 Aug 2004 00:24:24 -0000
@@ -21,6 +21,25 @@
 typedef signed short Continent_id;
 typedef enum tile_terrain_type Terrain_type_id;
 
+/* TODO: Remove this enum and make this an integer when gen-eff is done. */
+typedef enum {
+  B_AIRPORT=0, B_AQUEDUCT, B_BANK, B_BARRACKS, B_BARRACKS2, B_BARRACKS3, 
+  B_CATHEDRAL, B_CITY, B_COASTAL, B_COLOSSEUM, B_COURTHOUSE,  B_FACTORY, 
+  B_GRANARY, B_HARBOUR, B_HYDRO, B_LIBRARY, B_MARKETPLACE, B_MASS, B_MFG, 
+  B_NUCLEAR, B_OFFSHORE, B_PALACE, B_POLICE, B_PORT, B_POWER,
+  B_RECYCLING, B_RESEARCH, B_SAM, B_SDI, B_SEWER, B_SOLAR, B_SCOMP, 
+  B_SMODULE, B_SSTRUCTURAL, B_STOCK, B_SUPERHIGHWAYS, B_SUPERMARKET, B_TEMPLE,
+  B_UNIVERSITY,  
+  
+  B_APOLLO, B_ASMITHS, B_COLLOSSUS, B_COPERNICUS, B_CURE, B_DARWIN, B_EIFFEL,
+  B_GREAT, B_WALL, B_HANGING, B_HOOVER, B_ISAAC, B_BACH, B_RICHARDS, 
+  B_LEONARDO, B_LIGHTHOUSE, B_MAGELLAN, B_MANHATTEN, B_MARCO, B_MICHELANGELO, 
+  B_ORACLE, B_PYRAMIDS, B_SETI, B_SHAKESPEARE, B_LIBERTY, B_SUNTZU, 
+  B_UNITED, B_WOMENS,
+  B_CAPITAL, B_LAST_ENUM
+} Impr_Type_id;
+
+
 struct city;
 
 #endif /* FC__FC_TYPES_H */
Index: common/improvement.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.c,v
retrieving revision 1.43
diff -u -r1.43 improvement.c
--- common/improvement.c        13 Aug 2004 15:59:12 -0000      1.43
+++ common/improvement.c        31 Aug 2004 00:24:25 -0000
@@ -177,7 +177,7 @@
   int cost = 0, missing =
       improvement_types[id].build_cost - shields_in_stock;
 
-  if (id == B_CAPITAL) {
+  if (building_has_effect(id, EFT_PROD_TO_GOLD)) {
     /* Can't buy capitalization. */
     return 0;
   }
Index: common/improvement.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.h,v
retrieving revision 1.29
diff -u -r1.29 improvement.h
--- common/improvement.h        25 Aug 2004 18:24:19 -0000      1.29
+++ common/improvement.h        31 Aug 2004 00:24:25 -0000
@@ -15,13 +15,13 @@
 
 /* City Improvements, including Wonders.  (Alternatively "Buildings".) */
 
-#include "fc_types.h"
-
 #include "shared.h"            /* MAX_LEN_NAME */
+
+#include "effects.h"
+#include "fc_types.h"
 #include "tech.h"              /* Tech_Type_id */
 #include "terrain.h"           /* Terrain_type_id etc */
 #include "unittype.h"          /* Unit_Class_id, Unit_Type_id */
-#include "effects.h"
 
 struct player;
 
@@ -35,32 +35,6 @@
 #define I_REDUNDANT  3   /* Built, but replaced by wonder/other building */
 
 
-/* FIXME: Remove this define when there is per-file need for this enum. */
-#define OLD_IMPR_TYPE_ENUM
-
-/* FIXME: Remove this enum and the ifdef/endif when gen-impr implemented. */
-#ifdef OLD_IMPR_TYPE_ENUM
-enum improvement_type_id {
-  B_AIRPORT=0, B_AQUEDUCT, B_BANK, B_BARRACKS, B_BARRACKS2, B_BARRACKS3, 
-  B_CATHEDRAL, B_CITY, B_COASTAL, B_COLOSSEUM, B_COURTHOUSE,  B_FACTORY, 
-  B_GRANARY, B_HARBOUR, B_HYDRO, B_LIBRARY, B_MARKETPLACE, B_MASS, B_MFG, 
-  B_NUCLEAR, B_OFFSHORE, B_PALACE, B_POLICE, B_PORT, B_POWER,
-  B_RECYCLING, B_RESEARCH, B_SAM, B_SDI, B_SEWER, B_SOLAR, B_SCOMP, 
-  B_SMODULE, B_SSTRUCTURAL, B_STOCK, B_SUPERHIGHWAYS, B_SUPERMARKET, B_TEMPLE,
-  B_UNIVERSITY,  
-  
-  B_APOLLO, B_ASMITHS, B_COLLOSSUS, B_COPERNICUS, B_CURE, B_DARWIN, B_EIFFEL,
-  B_GREAT, B_WALL, B_HANGING, B_HOOVER, B_ISAAC, B_BACH, B_RICHARDS, 
-  B_LEONARDO, B_LIGHTHOUSE, B_MAGELLAN, B_MANHATTEN, B_MARCO, B_MICHELANGELO, 
-  B_ORACLE, B_PYRAMIDS, B_SETI, B_SHAKESPEARE, B_LIBERTY, B_SUNTZU, 
-  B_UNITED, B_WOMENS,
-  B_CAPITAL, B_LAST_ENUM
-};
-typedef enum improvement_type_id Impr_Type_id;
-#else
-typedef int Impr_Type_id;
-#endif
-
 /* B_LAST is a value which is guaranteed to be larger than all
  * actual Impr_Type_id values.  It is used as a flag value;
  * it can also be used for fixed allocations to ensure ability
Index: server/diplomats.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplomats.c,v
retrieving revision 1.58
diff -u -r1.58 diplomats.c
--- server/diplomats.c  26 Jul 2004 19:52:02 -0000      1.58
+++ server/diplomats.c  31 Aug 2004 00:24:27 -0000
@@ -1031,7 +1031,7 @@
      * City Walls, then there is a 50% chance of getting caught.
      */
     vulnerability = get_improvement_type(improvement)->sabotage;
-    if (city_got_building(pcity, B_CAPITAL)) {
+    if (city_got_building(pcity, B_PALACE)) {
       vulnerability /= 2;
     }
     if (myrand(100) >= vulnerability) {

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9878) new function building_has_effect, Jason Short <=