Freeciv-3.3
Loading...
Searching...
No Matches
effects.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13#ifndef FC__EFFECTS_H
14#define FC__EFFECTS_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* utility */
21#include "support.h" /* bool type */
22
23/* common */
24#include "fc_types.h"
25
26#include "requirements.h"
27
28struct conn_list;
29struct multiplier;
30
31#include "effects_enums_gen.h"
32
33#define EFT_USER_EFFECT_LAST EFT_USER_EFFECT_4
34
35#define USER_EFFECT_NUMBER(eff) (eff - EFT_USER_EFFECT_1)
36
37/* An effect is provided by a source. If the source is present, and the
38 * other conditions (described below) are met, the effect will be active.
39 * Note the difference between effect and effect_type. */
40struct effect {
41 enum effect_type type;
42
43 /* Pointer to multipliers (NULL means that this effect has no multiplier */
45
46 /* The "value" of the effect. The meaning of this varies between
47 * effects. When get_xxx_bonus() is called the value of all applicable
48 * effects will be summed up. */
49 int value;
50
51 /* An effect can have multiple requirements. The effect will only be
52 * active if all of these requirement are met. */
54
55 /* Only relevant for ruledit and other rulesave users. */
56 struct {
57 /* Indicates that this effect is deleted and shouldn't be saved. */
59
60 /* Comment field to save. While an entry in the ini-file, not
61 * used by freeciv. */
62 char *comment;
64};
65
66/* A callback type that takes an individual effect and a context for it
67 * and tells its weighted (by probability or something) value.
68 */
69typedef double
70 (*eft_value_filter_cb)(const struct effect *eft,
71 const struct req_context *context,
72 const struct player *other_player,
73 void *data, int n_data);
74
75/* An effect_list is a list of effects. */
76#define SPECLIST_TAG effect
77#define SPECLIST_TYPE struct effect
78#include "speclist.h"
79#define effect_list_iterate(effect_list, peffect) \
80 TYPED_LIST_ITERATE(struct effect, effect_list, peffect)
81#define effect_list_iterate_end LIST_ITERATE_END
82
83struct effect *effect_new(enum effect_type type, int value,
84 struct multiplier *pmul);
85struct effect *effect_copy(struct effect *old,
86 enum effect_type override_type);
87void effect_free(struct effect *peffect);
88void effect_remove(struct effect *peffect);
89void effect_req_append(struct effect *peffect, struct requirement req);
90
91struct astring;
92void get_effect_req_text(const struct effect *peffect,
93 char *buf, size_t buf_len);
95 struct astring *astr);
96
97/* ruleset cache creation and communication functions */
99
100void ruleset_cache_init(void);
101void ruleset_cache_free(void);
102void recv_ruleset_effect(const struct packet_ruleset_effect *packet);
103void send_ruleset_cache(struct conn_list *dest);
104
106 size_t n_unis);
108
110 struct universal *unis, size_t n_unis);
111
113 struct universal *unis,
114 size_t n_unis,
115 int min_value);
116
118
119bool is_building_replaced(const struct city *pcity,
120 const struct impr_type *pimprove,
121 const enum req_problem_type prob_type);
122
123/* Functions to know the bonuses a certain effect is granting */
125int get_player_bonus(const struct player *plr, enum effect_type effect_type);
126int get_city_bonus(const struct city *pcity, enum effect_type effect_type);
127int get_tile_bonus(const struct tile *ptile, enum effect_type effect_type);
129 const struct specialist *pspecialist,
130 const struct output_type *poutput,
132int get_city_tile_output_bonus(const struct city *pcity,
133 const struct tile *ptile,
134 const struct output_type *poutput,
136int get_tile_output_bonus(const struct city *pcity,
137 const struct tile *ptile,
138 const struct output_type *poutput,
140int get_player_output_bonus(const struct player *pplayer,
141 const struct output_type *poutput,
143int get_city_output_bonus(const struct city *pcity,
144 const struct output_type *poutput,
146int get_building_bonus(const struct city *pcity,
147 const struct impr_type *building,
149int get_unittype_bonus(const struct player *pplayer,
150 const struct tile *ptile, /* pcity is implied */
151 const struct unit_type *punittype,
152 const struct action *paction,
154int get_unit_bonus(const struct unit *punit, enum effect_type effect_type);
155int get_unit_vs_tile_bonus(const struct tile *ptile,
156 const struct unit *punit,
157 enum effect_type etype);
158
159/* Miscellaneous auxiliary effects functions */
161
163 const struct player *pplayer,
164 enum effect_type effect_type);
166 const struct city *pcity,
167 const struct output_type *poutput,
168 enum effect_type effect_type);
169
171 const struct req_context *context,
172 const struct req_context *other_context,
173 enum effect_type effect_type);
175 const struct player *other_player,
176 enum effect_type effect_type,
178 void *data, int n_data)
180
181bool building_has_effect(const struct impr_type *pimprove,
182 enum effect_type effect_type);
184 enum effect_type effect_type,
185 const enum req_problem_type prob_type);
186int get_potential_improvement_bonus(const struct impr_type *pimprove,
187 const struct city *pcity,
188 enum effect_type effect_type,
189 const enum req_problem_type prob_type,
191
192struct effect_list *get_effects(enum effect_type effect_type);
193
194typedef bool (*iec_cb)(struct effect*, void *data);
195bool iterate_effect_cache(iec_cb cb, void *data);
196
197bool is_user_effect(enum effect_type eff);
198enum effect_type user_effect_ai_valued_as(enum effect_type);
199void user_effect_ai_valued_set(enum effect_type tgt, enum effect_type valued_as);
200
201#ifdef __cplusplus
202}
203#endif /* __cplusplus */
204
205#endif /* FC__EFFECTS_H */
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
void effect_remove(struct effect *peffect)
Definition effects.c:230
void recv_ruleset_effect(const struct packet_ruleset_effect *packet)
Definition effects.c:591
bool effect_universals_value_never_below(enum effect_type type, struct universal *unis, size_t n_unis, int min_value)
Definition effects.c:545
int get_tile_output_bonus(const struct city *pcity, const struct tile *ptile, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:936
int get_player_output_bonus(const struct player *pplayer, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:957
int get_city_specialist_output_bonus(const struct city *pcity, const struct specialist *pspecialist, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:881
bool is_building_replaced(const struct city *pcity, const struct impr_type *pimprove, const enum req_problem_type prob_type)
Definition effects.c:693
int get_player_bonus_effects(struct effect_list *plist, const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:1128
bool iterate_effect_cache(iec_cb cb, void *data)
Definition effects.c:1321
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_current_construction_bonus(const struct city *pcity, enum effect_type effect_type, const enum req_problem_type prob_type)
Definition effects.c:1180
int get_city_bonus_effects(struct effect_list *plist, const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:1151
double(* eft_value_filter_cb)(const struct effect *eft, const struct req_context *context, const struct player *other_player, void *data, int n_data)
Definition effects.h:70
int get_unit_vs_tile_bonus(const struct tile *ptile, const struct unit *punit, enum effect_type etype)
Definition effects.c:1090
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:1066
double get_effect_expected_value(const struct req_context *context, const struct player *other_player, enum effect_type effect_type, eft_value_filter_cb weighter, void *data, int n_data) fc__attribute((nonnull(4)))
Definition effects.c:789
int get_city_output_bonus(const struct city *pcity, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:980
int get_potential_improvement_bonus(const struct impr_type *pimprove, const struct city *pcity, enum effect_type effect_type, const enum req_problem_type prob_type, bool consider_multipliers)
Definition effects.c:1202
void send_ruleset_cache(struct conn_list *dest)
Definition effects.c:609
void get_effect_req_text(const struct effect *peffect, char *buf, size_t buf_len)
Definition effects.c:1273
bool(* iec_cb)(struct effect *, void *data)
Definition effects.h:194
int get_player_bonus(const struct player *plr, enum effect_type effect_type)
Definition effects.c:824
void ruleset_cache_free(void)
Definition effects.c:329
struct effect * effect_new(enum effect_type type, int value, struct multiplier *pmul)
Definition effects.c:186
int get_building_bonus(const struct city *pcity, const struct impr_type *building, enum effect_type effect_type)
Definition effects.c:1004
int effect_value_from_universals(enum effect_type type, struct universal *unis, size_t n_unis)
Definition effects.c:459
int get_city_tile_output_bonus(const struct city *pcity, const struct tile *ptile, const struct output_type *poutput, enum effect_type effect_type)
Definition effects.c:912
void user_effect_ai_valued_set(enum effect_type tgt, enum effect_type valued_as)
Definition effects.c:1346
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
struct effect * effect_copy(struct effect *old, enum effect_type override_type)
Definition effects.c:246
int effect_cumulative_max(enum effect_type type, struct universal *unis, size_t n_unis)
Definition effects.c:388
void effect_free(struct effect *peffect)
Definition effects.c:216
void ruleset_cache_init(void)
Definition effects.c:297
enum effect_type user_effect_ai_valued_as(enum effect_type)
Definition effects.c:1357
int get_world_bonus(enum effect_type effect_type)
Definition effects.c:812
int effect_cumulative_min(enum effect_type type, struct universal *for_uni)
Definition effects.c:424
struct effect_list * get_effects(enum effect_type effect_type)
Definition effects.c:143
struct effect_list * get_req_source_effects(const struct universal *psource)
Definition effects.c:153
bool building_has_effect(const struct impr_type *pimprove, enum effect_type effect_type)
Definition effects.c:639
void effect_req_append(struct effect *peffect, struct requirement req)
Definition effects.c:266
int get_tile_bonus(const struct tile *ptile, enum effect_type effect_type)
Definition effects.c:862
int get_unittype_bonus(const struct player *pplayer, const struct tile *ptile, const struct unit_type *punittype, const struct action *paction, enum effect_type effect_type)
Definition effects.c:1031
void get_effect_list_req_text(const struct effect_list *plist, struct astring *astr)
Definition effects.c:1301
bool is_user_effect(enum effect_type eff)
Definition effects.c:1337
int effect_value_will_make_positive(enum effect_type type)
Definition effects.c:582
req_problem_type
Definition fc_types.h:531
GType type
Definition repodlgs.c:1313
Definition city.h:317
int value
Definition effects.h:49
char * comment
Definition effects.h:62
struct multiplier * multiplier
Definition effects.h:44
bool do_not_save
Definition effects.h:58
struct effect::@24 rulesave
struct requirement_vector reqs
Definition effects.h:53
enum effect_type type
Definition effects.h:41
enum effect_type effect_type
Definition tile.h:50
Definition unit.h:140
#define fc__attribute(x)
Definition support.h:99
#define bool
Definition support.h:71