Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#11138) [PATCH] Great Library discoveries claim 'acquir
Home

[Freeciv-Dev] (PR#11138) [PATCH] Great Library discoveries claim 'acquir

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: craig@xxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#11138) [PATCH] Great Library discoveries claim 'acquired by a building'
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Tue, 23 Nov 2004 13:05:53 -0800
Reply-to: rt@xxxxxxxxxxx

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

> [vasc - Tue Nov 23 00:52:06 2004]:
> 
> On Mon, 22 Nov 2004, Jason Short wrote:
> 
> >
> > <URL: http://rt.freeciv.org/Ticket/Display.html?id=11138 >
> >
> > > [craig@xxxxxxxxxxxxxx - Sun Nov 21 23:53:42 2004]:
> > >
> > > Great Library discoveries claim 'acquired by a building'
> > >
> > > When a player creates the Great Library and it grants a
technology, it's
> > > reported as being "acquired by a building".
> >
> > Fixing this isn't particularly easy.  I think the right solution is to
> > have a get_player_bonus_sources() function.  Vasco, will you write one?

Here is the patch, but I will need someone to test it.

Index: client/text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.c,v
retrieving revision 1.15
diff -u -r1.15 text.c
--- client/text.c       14 Nov 2004 03:39:09 -0000      1.15
+++ client/text.c       23 Nov 2004 21:04:20 -0000
@@ -732,7 +732,7 @@
 
   add_line(_("Buildings: "));
 
-  sources = get_city_bonus_sources(pcity, EFT_MAKE_CONTENT);
+  get_city_bonus_sources(&sources, pcity, EFT_MAKE_CONTENT);
   effect_source_vector_iterate(&sources, src) {
     faces++;
     add(_("%s. "), get_improvement_name(src->building));
@@ -757,21 +757,21 @@
 
   add_line(_("Wonders: "));
 
-  sources = get_city_bonus_sources(pcity, EFT_MAKE_HAPPY);
+  get_city_bonus_sources(&sources, pcity, EFT_MAKE_HAPPY);
   effect_source_vector_iterate(&sources, src) {
     faces++;
     add(_("%s. "), get_improvement_name(src->building));
   } effect_source_vector_iterate_end;
   effect_source_vector_free(&sources);
 
-  sources = get_city_bonus_sources(pcity, EFT_FORCE_CONTENT);
+  get_city_bonus_sources(&sources, pcity, EFT_FORCE_CONTENT);
   effect_source_vector_iterate(&sources, src) {
     faces++;
     add(_("%s. "), get_improvement_name(src->building));
   } effect_source_vector_iterate_end;
   effect_source_vector_free(&sources);
 
-  sources = get_city_bonus_sources(pcity, EFT_NO_UNHAPPY);
+  get_city_bonus_sources(&sources, pcity, EFT_NO_UNHAPPY);
   effect_source_vector_iterate(&sources, src) {
     faces++;
     add(_("%s. "), get_improvement_name(src->building));
Index: common/effects.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.c,v
retrieving revision 1.16
diff -u -r1.16 effects.c
--- common/effects.c    23 Oct 2004 20:41:00 -0000      1.16
+++ common/effects.c    23 Nov 2004 21:04:20 -0000
@@ -1183,22 +1183,46 @@
   target gives the type of the target
   (player,city,building,tile) give the exact target
   effect_type gives the effect type to be considered
+
+  Returns the effect sources of this type _currently active_.
+
+  The returned vector must be freed (building_vector_free) when the caller
+  is done with it.
 **************************************************************************/
-static int get_target_bonus(enum target_type target,
-                           const struct player *target_player,
-                           const struct city *target_city,
-                           Impr_Type_id target_building,
-                           const struct tile *target_tile,
-                           enum effect_type effect_type)
+static int get_target_bonus_sources(struct effect_source_vector *sources,
+                                   enum target_type target,
+                                   const struct player *target_player,
+                                   const struct city *target_city,
+                                   Impr_Type_id target_building,
+                                   const struct tile *target_tile,
+                                   enum effect_type effect_type)
 {
   int bonus = 0;
 
+  if (sources) {
+    effect_source_vector_init(sources);
+  }
+
   /* Loop over all sources that may provide this effect. */
   building_vector_iterate(get_buildings_with_effect(effect_type), pbldg) {
+    int value;
+
     /* And for each source, add on the amount of effect provided by it. */
-    bonus += get_effect_value(target, target_player, target_city,
-                             target_building, target_tile,
-                             *pbldg, effect_type);
+    value = get_effect_value(target, target_player, target_city,
+                            target_building, target_tile,
+                            *pbldg, effect_type);
+    bonus += value;
+
+    if (sources) {
+      struct effect_source e;
+
+      e.building = *pbldg;
+      e.effect_value = value;
+
+      if (value != 0) {
+       effect_source_vector_append(sources, &e);
+      }
+    }
   } building_vector_iterate_end;
 
   return bonus;
@@ -1210,9 +1234,9 @@
 int get_player_bonus(const struct player *pplayer,
                     enum effect_type effect_type)
 {
-  return get_target_bonus(TARGET_PLAYER,
-                         pplayer, NULL, B_LAST, NULL,
-                         effect_type);
+  return get_target_bonus_sources(NULL, TARGET_PLAYER,
+                                 pplayer, NULL, B_LAST, NULL,
+                                 effect_type);
 }
 
 /**************************************************************************
@@ -1220,9 +1244,9 @@
 **************************************************************************/
 int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
 {
-  return get_target_bonus(TARGET_CITY,
-                         city_owner(pcity), pcity, B_LAST, NULL,
-                         effect_type);
+  return get_target_bonus_sources(NULL, TARGET_CITY,
+                                 city_owner(pcity), pcity, B_LAST, NULL,
+                                 effect_type);
 }
 
 /**************************************************************************
@@ -1231,9 +1255,9 @@
 int get_city_tile_bonus(const struct city *pcity, const struct tile *ptile,
                        enum effect_type effect_type)
 {
-  return get_target_bonus(TARGET_CITY,
-                         city_owner(pcity), pcity, B_LAST, ptile,
-                         effect_type);
+  return get_target_bonus_sources(NULL, TARGET_CITY,
+                                 city_owner(pcity), pcity, B_LAST, ptile,
+                                 effect_type);
 }
 
 /**************************************************************************
@@ -1242,37 +1266,37 @@
 int get_building_bonus(const struct city *pcity, Impr_Type_id id,
                       enum effect_type effect_type)
 {
-  return get_target_bonus(TARGET_BUILDING,
-                         city_owner(pcity), pcity, id, NULL,
-                         effect_type);
+  return get_target_bonus_sources(NULL, TARGET_BUILDING,
+                                 city_owner(pcity), pcity, id, NULL,
+                                 effect_type);
 }
 
 /**************************************************************************
-  Returns the effect sources of this type _currently active_ at the city.
+  Returns the effect sources of this type _currently active_ at the player.
 
   The returned vector must be freed (building_vector_free) when the caller
   is done with it.
 **************************************************************************/
-struct effect_source_vector get_city_bonus_sources(const struct city *pcity,
-                                                enum effect_type effect_type)
+int get_player_bonus_sources(struct effect_source_vector *sources,
+    const struct player *pplayer, enum effect_type effect_type)
 {
-  struct player *pplayer = city_owner(pcity);
-  struct effect_source_vector sources;
-
-  effect_source_vector_init(&sources);
-
-  building_vector_iterate(get_buildings_with_effect(effect_type), pbldg) {
-    struct effect_source e;
+  return get_target_bonus_sources(sources, TARGET_PLAYER,
+                                 pplayer, NULL, B_LAST, NULL,
+                                 effect_type);
+}
 
-    e.building = *pbldg;
-    e.effect_value = get_effect_value(TARGET_CITY, pplayer, pcity,
-                                     B_LAST, NULL, *pbldg, effect_type);
-    if (e.effect_value != 0) {
-      effect_source_vector_append(&sources, &e);
-    }
-  } effect_source_vector_iterate_end;
+/**************************************************************************
+  Returns the effect sources of this type _currently active_ at the city.
 
-  return sources;
+  The returned vector must be freed (building_vector_free) when the caller
+  is done with it.
+**************************************************************************/
+int get_city_bonus_sources(struct effect_source_vector *sources,
+    const struct city *pcity, enum effect_type effect_type)
+{
+  return get_target_bonus_sources(sources, TARGET_CITY,
+                                 city_owner(pcity), pcity, B_LAST, NULL,
+                                 effect_type);
 }
 
 /**************************************************************************
@@ -1300,3 +1324,4 @@
 
   return 0;
 }
+
Index: common/effects.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.h,v
retrieving revision 1.10
diff -u -r1.10 effects.h
--- common/effects.h    23 Oct 2004 20:41:00 -0000      1.10
+++ common/effects.h    23 Nov 2004 21:04:20 -0000
@@ -268,8 +268,10 @@
                                         enum effect_type effect_type);
 struct effect_type_vector *get_building_effect_types(Impr_Type_id building);
 
-struct effect_source_vector get_city_bonus_sources(const struct city *pcity,
-                                       enum effect_type effect_type);
+int get_player_bonus_sources(struct effect_source_vector *sources,
+    const struct player *pplayer, enum effect_type effect_type);
+int get_city_bonus_sources(struct effect_source_vector *sources,
+    const struct city *pcity, enum effect_type effect_type);
 
 bool building_has_effect(Impr_Type_id building,
                         enum effect_type effect_type);
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.339
diff -u -r1.339 plrhand.c
--- server/plrhand.c    20 Nov 2004 19:35:14 -0000      1.339
+++ server/plrhand.c    23 Nov 2004 21:04:24 -0000
@@ -130,24 +130,40 @@
 void do_tech_parasite_effect(struct player *pplayer)
 {
   int mod;
+  struct effect_source_vector sources;
 
   /* Note that two EFT_TECH_PARASITE effects will combine into a single,
    * much worse effect. */
-  if ((mod = get_player_bonus(pplayer, EFT_TECH_PARASITE)) > 0) {
+  if ((mod = get_player_bonus_sources(&sources, pplayer,
+                                     EFT_TECH_PARASITE)) > 0) {
+    char buf[512];
+
+    buf[0] = '\0';
+    effect_source_vector_iterate(&sources, src) {
+      if (buf[0] != '\0') {
+       sz_strlcat(buf, ", ");
+      }
+      sz_strlcat(buf, get_improvement_name(src->building));
+    } effect_source_vector_iterate_end;
+
     tech_type_iterate(i) {
       if (get_invention(pplayer, i) != TECH_KNOWN
          && tech_is_available(pplayer, i)
          && game.global_advances[i] >= mod) {
        notify_player_ex(pplayer, NULL, E_TECH_GAIN,
-           _("Game: %s acquired from a building!"),
-           advances[i].name);
-       gamelog(GAMELOG_TECH, _("%s discover %s (building)"),
-           get_nation_name_plural(pplayer->nation), advances[i].name);
+           _("Game: %s acquired from %s!"),
+           advances[i].name,
+           buf);
+       gamelog(GAMELOG_TECH, _("%s discover %s (%s)"),
+           get_nation_name_plural(pplayer->nation),
+           advances[i].name,
+           buf);
        notify_embassies(pplayer, NULL,
            _("Game: The %s have acquired %s"
-             " from a building."),
+             " from %s."),
            get_nation_name_plural(pplayer->nation),
-           advances[i].name);
+           advances[i].name,
+           buf);
 
        do_free_cost(pplayer);
        found_new_tech(pplayer, i, FALSE, TRUE, A_NONE);
@@ -155,6 +171,7 @@
       }
     } tech_type_iterate_end;
   }
+  effect_source_vector_free(&sources);
 }
 
 /****************************************************************************

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