[Freeciv-Dev] (PR#10675) get_city_bonus_sources should return the effect
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] (PR#10675) get_city_bonus_sources should return the effect value |
From: |
"Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx> |
Date: |
Thu, 21 Oct 2004 23:08:47 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=10675 >
Future users of get_city_bonus_sources will likely want to know the
value of the effect provided by the source. See PR#10575.
This patch adds a new type, "struct effect_source". This struct
contains a source (currently only a building) and an effect value. The
name could be improved. get_city_bonus_sources returns a *vector* of
these structs. (Returning a vector is easier than returning a list
because only one value needs to be allocated and freed.)
The existing callers (of which there are few) are changed.
jason
Index: client/text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.c,v
retrieving revision 1.13
diff -u -r1.13 text.c
--- client/text.c 18 Oct 2004 22:40:02 -0000 1.13
+++ client/text.c 22 Oct 2004 06:04:16 -0000
@@ -703,17 +703,17 @@
const char *get_happiness_buildings(const struct city *pcity)
{
int faces = 0;
- struct building_vector sources;
+ struct effect_source_vector sources;
INIT;
add_line(_("Buildings: "));
sources = get_city_bonus_sources(pcity, EFT_MAKE_CONTENT);
- building_vector_iterate(&sources, pbldg) {
+ effect_source_vector_iterate(&sources, src) {
faces++;
- add(_("%s. "), get_improvement_name(*pbldg));
- } building_vector_iterate_end;
- building_vector_free(&sources);
+ add(_("%s. "), get_improvement_name(src->building));
+ } effect_source_vector_iterate_end;
+ effect_source_vector_free(&sources);
if (faces == 0) {
add(_("None. "));
@@ -728,31 +728,31 @@
const char *get_happiness_wonders(const struct city *pcity)
{
int faces = 0;
- struct building_vector sources;
+ struct effect_source_vector sources;
INIT;
add_line(_("Wonders: "));
sources = get_city_bonus_sources(pcity, EFT_MAKE_HAPPY);
- building_vector_iterate(&sources, pbldg) {
+ effect_source_vector_iterate(&sources, src) {
faces++;
- add(_("%s. "), get_improvement_name(*pbldg));
- } building_vector_iterate_end;
- building_vector_free(&sources);
+ 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);
- building_vector_iterate(&sources, pbldg) {
+ effect_source_vector_iterate(&sources, src) {
faces++;
- add(_("%s. "), get_improvement_name(*pbldg));
- } building_vector_iterate_end;
- building_vector_free(&sources);
+ 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);
- building_vector_iterate(&sources, pbldg) {
+ effect_source_vector_iterate(&sources, src) {
faces++;
- add(_("%s. "), get_improvement_name(*pbldg));
- } building_vector_iterate_end;
- building_vector_free(&sources);
+ add(_("%s. "), get_improvement_name(src->building));
+ } effect_source_vector_iterate_end;
+ effect_source_vector_free(&sources);
if (faces == 0) {
add(_("None. "));
Index: common/effects.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.c,v
retrieving revision 1.14
diff -u -r1.14 effects.c
--- common/effects.c 10 Oct 2004 21:14:11 -0000 1.14
+++ common/effects.c 22 Oct 2004 06:04:16 -0000
@@ -1249,20 +1249,24 @@
The returned vector must be freed (building_vector_free) when the caller
is done with it.
**************************************************************************/
-struct building_vector get_city_bonus_sources(const struct city *pcity,
- enum effect_type effect_type)
+struct effect_source_vector get_city_bonus_sources(const struct city *pcity,
+ enum effect_type effect_type)
{
struct player *pplayer = city_owner(pcity);
- struct building_vector sources;
+ struct effect_source_vector sources;
- building_vector_init(&sources);
+ effect_source_vector_init(&sources);
building_vector_iterate(get_buildings_with_effect(effect_type), pbldg) {
- if (get_effect_value(TARGET_CITY, pplayer, pcity,
- B_LAST, NULL, *pbldg, effect_type) > 0) {
- building_vector_append(&sources, pbldg);
+ struct effect_source e;
+
+ 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);
}
- } building_vector_iterate_end;
+ } effect_source_vector_iterate_end;
return sources;
}
Index: common/effects.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.h,v
retrieving revision 1.9
diff -u -r1.9 effects.h
--- common/effects.h 22 Sep 2004 15:42:28 -0000 1.9
+++ common/effects.h 22 Oct 2004 06:04:16 -0000
@@ -199,6 +199,19 @@
TYPED_LIST_ITERATE(struct effect, effect_list, peffect)
#define effect_list_iterate_end LIST_ITERATE_END
+/* This struct contains a source building along with the effect value. It is
+ * primarily useful for get_city_bonus_sources(). */
+struct effect_source {
+ Impr_Type_id building;
+ int effect_value;
+};
+#define SPECVEC_TAG effect_source
+#define SPECVEC_TYPE struct effect_source
+#include "specvec.h"
+#define effect_source_vector_iterate(vector, psource) \
+ TYPED_VECTOR_ITERATE(struct effect_source, vector, psource)
+#define effect_source_vector_iterate_end VECTOR_ITERATE_END
+
/* ruleset cache creation and communication functions */
void ruleset_cache_init(void);
void ruleset_cache_free(void);
@@ -255,8 +268,8 @@
enum effect_type effect_type);
struct effect_type_vector *get_building_effect_types(Impr_Type_id building);
-struct building_vector get_city_bonus_sources(const struct city *pcity,
- enum effect_type effect_type);
+struct effect_source_vector get_city_bonus_sources(const struct city *pcity,
+ enum effect_type effect_type);
bool building_has_effect(Impr_Type_id building,
enum effect_type effect_type);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#10675) get_city_bonus_sources should return the effect value,
Jason Short <=
|
|