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

[Freeciv-Dev] (PR#9815) new function get_current_construction_bonus

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9815) new function get_current_construction_bonus
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 25 Aug 2004 20:08:59 -0700
Reply-to: rt@xxxxxxxxxxx

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

This patch adds a new function get_current_construction_bonus.

The function does the same thing it does in the effects patch: it takes 
a city and an effect, and returns the effect bonus (aka "power") 
provided by the current production.

It doesn't access the effect arrays (which are incomplete).  Instead 
it's just a wrapper for checking the improvement enum for the current 
production.  Also it's only used in a few simple places that previously 
checked B_CAPITAL - only EFT_PROD_TO_GOLD is supported.  There are more 
places it can be used but some of them are controversial.  If this goes 
in then I'll make a second patch for the remaining cases.

There are a few small improvements compared to the code in the effects 
patch.  Most notably there is no boolean/integer mixing.  But these 
differences are trivial.

In conclusion it's a small and simple step.

jason

? diff
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.42
diff -u -r1.42 citydlg_common.c
--- client/citydlg_common.c     17 Jul 2004 05:53:20 -0000      1.42
+++ client/citydlg_common.c     26 Aug 2004 03:02:23 -0000
@@ -240,7 +240,7 @@
     cost = impr_build_shield_cost(pcity->currently_building);
   }
 
-  if (!pcity->is_building_unit && pcity->currently_building == B_CAPITAL) {
+  if (get_current_construction_bonus(pcity, EFT_PROD_TO_GOLD) > 0) {
     my_snprintf(buffer, buffer_len, _("%3d gold per turn"),
                MAX(0, pcity->shield_surplus));
   } else {
Index: client/cityrepdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.c,v
retrieving revision 1.33
diff -u -r1.33 cityrepdata.c
--- client/cityrepdata.c        27 May 2004 22:14:18 -0000      1.33
+++ client/cityrepdata.c        26 Aug 2004 03:02:23 -0000
@@ -355,7 +355,7 @@
     worklist_is_empty(&pcity->worklist) ? "" :
     concise_city_production ? "*" : _("(worklist)");
        
-  if (!pcity->is_building_unit && pcity->currently_building == B_CAPITAL) {
+  if (get_current_construction_bonus(pcity, EFT_PROD_TO_GOLD) > 0) {
     my_snprintf(buf, sizeof(buf), "%s (%d/X/X/X)%s",
                get_impr_name_ex(pcity, pcity->currently_building),
                MAX(0, pcity->shield_surplus), from_worklist);
Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.135
diff -u -r1.135 climisc.c
--- client/climisc.c    29 Jul 2004 00:09:26 -0000      1.135
+++ client/climisc.c    26 Aug 2004 03:02:23 -0000
@@ -983,12 +983,14 @@
 {
   int value = city_buy_cost(pcity);
 
-  if (!pcity->is_building_unit && pcity->currently_building == B_CAPITAL) {
+  if (get_current_construction_bonus(pcity, EFT_PROD_TO_GOLD) > 0) {
     char buf[512];
 
+    assert(!pcity->is_building_unit);
     my_snprintf(buf, sizeof(buf),
                _("Game: You don't buy %s in %s!"),
-               improvement_types[B_CAPITAL].name, pcity->name);
+               improvement_types[pcity->currently_building].name,
+               pcity->name);
     append_output_window(buf);
     return;
   }
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.141
diff -u -r1.141 mapview_common.c
--- client/mapview_common.c     25 Aug 2004 18:24:18 -0000      1.141
+++ client/mapview_common.c     26 Aug 2004 03:02:24 -0000
@@ -2075,7 +2075,7 @@
   } else {
     struct impr_type *pimprovement_type =
                get_improvement_type(pcity->currently_building);
-    if (pcity->currently_building == B_CAPITAL) {
+    if (get_current_construction_bonus(pcity, EFT_PROD_TO_GOLD) > 0) {
       my_snprintf(buffer, buffer_len, "%s", pimprovement_type->name);
     } else if (turns < 999) {
       my_snprintf(buffer, buffer_len, "%s %d",
Index: client/repodlgs_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/repodlgs_common.c,v
retrieving revision 1.11
diff -u -r1.11 repodlgs_common.c
--- client/repodlgs_common.c    19 Jul 2004 20:29:12 -0000      1.11
+++ client/repodlgs_common.c    26 Aug 2004 03:02:25 -0000
@@ -81,7 +81,7 @@
 
   city_list_iterate(game.player_ptr->cities, pcity) {
     *total_income += pcity->tax_total;
-    if (!pcity->is_building_unit && pcity->currently_building == B_CAPITAL) {
+    if (get_current_construction_bonus(pcity, EFT_PROD_TO_GOLD) > 0) {
       *total_income += MAX(0, pcity->shield_surplus);
     }
   } city_list_iterate_end;
Index: client/agents/cma_fec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_fec.c,v
retrieving revision 1.22
diff -u -r1.22 cma_fec.c
--- client/agents/cma_fec.c     20 Jul 2004 16:27:07 -0000      1.22
+++ client/agents/cma_fec.c     26 Aug 2004 03:02:25 -0000
@@ -290,7 +290,7 @@
   if (pcity->is_building_unit) {
     cost = unit_build_shield_cost(pcity->currently_building);
   } else {
-    if (pcity->currently_building == B_CAPITAL) {
+    if (get_current_construction_bonus(pcity, EFT_PROD_TO_GOLD) > 0) {
       my_snprintf(buffer, sizeof(buffer),
                  get_improvement_type(pcity->currently_building)->name);
       return buffer;
Index: common/effects.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.c,v
retrieving revision 1.5
diff -u -r1.5 effects.c
--- common/effects.c    25 Jun 2004 23:43:01 -0000      1.5
+++ common/effects.c    26 Aug 2004 03:02:25 -0000
@@ -213,3 +213,25 @@
   T(aff_spec);
   return TRUE;
 }
+
+/**************************************************************************
+  Returns the effect bonus the currently-in-construction-item will provide.
+
+  Note this is not called get_current_production_bonus because that would
+  be confused with EFT_PROD_BONUS.
+
+  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.
+**************************************************************************/
+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;
+  }
+  assert(0);
+  return 0;
+}
Index: common/effects.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.h,v
retrieving revision 1.3
diff -u -r1.3 effects.h
--- common/effects.h    28 Nov 2003 17:37:21 -0000      1.3
+++ common/effects.h    26 Aug 2004 03:02:25 -0000
@@ -16,6 +16,8 @@
 struct impr_effect;
 
 #include "shared.h"            /* bool */
+
+#include "fc_types.h"
 #include "terrain.h"
 
 /* Range of effects (used in equiv_range and effect.range fields)
@@ -130,4 +132,7 @@
 bool are_effects_equal(const struct impr_effect *const peff1,
                       const struct impr_effect *const peff2);
 
+int get_current_construction_bonus(const struct city *pcity,
+                                  enum effect_type effect);
+
 #endif  /* FC__EFFECTS_H */
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.2
diff -u -r1.2 fc_types.h
--- common/fc_types.h   25 Aug 2004 18:24:19 -0000      1.2
+++ common/fc_types.h   26 Aug 2004 03:02:25 -0000
@@ -21,4 +21,6 @@
 typedef signed short Continent_id;
 typedef enum tile_terrain_type Terrain_type_id;
 
+struct city;
+
 #endif /* FC__FC_TYPES_H */
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.145
diff -u -r1.145 player.c
--- common/player.c     23 Aug 2004 06:08:32 -0000      1.145
+++ common/player.c     26 Aug 2004 03:02:26 -0000
@@ -429,7 +429,7 @@
     } impr_type_iterate_end;
 
     /* Capitalization income. */
-    if (!pcity->is_building_unit && pcity->currently_building == B_CAPITAL) {
+    if (get_current_construction_bonus(pcity, EFT_PROD_TO_GOLD) > 0) {
       income += pcity->shield_stock + pcity->shield_surplus;
     }
   } city_list_iterate_end;
Index: server/cityhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityhand.c,v
retrieving revision 1.133
diff -u -r1.133 cityhand.c
--- server/cityhand.c   24 Aug 2004 06:33:31 -0000      1.133
+++ server/cityhand.c   26 Aug 2004 03:02:27 -0000
@@ -224,10 +224,11 @@
     return;
   }
 
-  if (!pcity->is_building_unit && pcity->currently_building==B_CAPITAL)  {
+  if (get_current_construction_bonus(pcity, EFT_PROD_TO_GOLD) > 0) {
+    assert(!pcity->is_building_unit);
     notify_player_ex(pplayer, pcity->x, pcity->y, E_NOEVENT,
                      _("Game: You don't buy %s!"),
-                    improvement_types[B_CAPITAL].name);
+                    improvement_types[pcity->currently_building].name);
     return;
   }
 
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.257
diff -u -r1.257 cityturn.c
--- server/cityturn.c   14 Aug 2004 19:41:23 -0000      1.257
+++ server/cityturn.c   26 Aug 2004 03:02:28 -0000
@@ -904,7 +904,7 @@
 {
   bool space_part;
 
-  if (pcity->currently_building == B_CAPITAL) {
+  if (get_current_construction_bonus(pcity, EFT_PROD_TO_GOLD) > 0) {
     assert(pcity->shield_surplus >= 0);
     /* pcity->before_change_shields already contains the surplus from
      * this turn. */

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