Present treaty cancellation button in sdl-clients when it should.
[freeciv.git] / common / actions.h
blob900b5a2b3134bafc8a216dc66b3e15bda51ff821
1 /***********************************************************************
2 Freeciv - Copyright (C) 1996-2013 - Freeciv Development Team
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.
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 ***********************************************************************/
14 #ifndef FC_ACTIONS_H
15 #define FC_ACTIONS_H
17 /* common */
18 #include "fc_types.h"
19 #include "metaknowledge.h"
20 #include "requirements.h"
22 #ifdef __cplusplus
23 extern "C" {
24 #endif /* __cplusplus */
26 #define SPECENUM_NAME action_actor_kind
27 #define SPECENUM_VALUE0 AAK_UNIT
28 #define SPECENUM_VALUE0NAME N_("a unit")
29 #define SPECENUM_COUNT AAK_COUNT
30 #include "specenum_gen.h"
32 #define SPECENUM_NAME action_target_kind
33 #define SPECENUM_VALUE0 ATK_CITY
34 #define SPECENUM_VALUE0NAME N_("individual cities")
35 #define SPECENUM_VALUE1 ATK_UNIT
36 #define SPECENUM_VALUE1NAME N_("individual units")
37 #define SPECENUM_COUNT ATK_COUNT
38 #include "specenum_gen.h"
40 /* Values used in the network protocol. */
41 /* Names used in file formats but not normally shown to users. */
42 #define SPECENUM_NAME gen_action
43 #define SPECENUM_VALUE0 ACTION_ESTABLISH_EMBASSY
44 #define SPECENUM_VALUE0NAME "Establish Embassy"
45 #define SPECENUM_VALUE1 ACTION_SPY_INVESTIGATE_CITY
46 #define SPECENUM_VALUE1NAME "Investigate City"
47 #define SPECENUM_VALUE2 ACTION_SPY_POISON
48 #define SPECENUM_VALUE2NAME "Poison City"
49 #define SPECENUM_VALUE3 ACTION_SPY_STEAL_GOLD
50 #define SPECENUM_VALUE3NAME "Steal Gold"
51 #define SPECENUM_VALUE4 ACTION_SPY_SABOTAGE_CITY
52 #define SPECENUM_VALUE4NAME "Sabotage City"
53 #define SPECENUM_VALUE5 ACTION_SPY_TARGETED_SABOTAGE_CITY
54 #define SPECENUM_VALUE5NAME "Targeted Sabotage City"
55 #define SPECENUM_VALUE6 ACTION_SPY_STEAL_TECH
56 #define SPECENUM_VALUE6NAME "Steal Tech"
57 #define SPECENUM_VALUE7 ACTION_SPY_TARGETED_STEAL_TECH
58 #define SPECENUM_VALUE7NAME "Targeted Steal Tech"
59 #define SPECENUM_VALUE8 ACTION_SPY_INCITE_CITY
60 #define SPECENUM_VALUE8NAME "Incite City"
61 #define SPECENUM_VALUE9 ACTION_TRADE_ROUTE
62 #define SPECENUM_VALUE9NAME "Establish Trade Route"
63 #define SPECENUM_VALUE10 ACTION_MARKETPLACE
64 #define SPECENUM_VALUE10NAME "Enter Marketplace"
65 #define SPECENUM_VALUE11 ACTION_HELP_WONDER
66 #define SPECENUM_VALUE11NAME "Help Wonder"
67 #define SPECENUM_VALUE12 ACTION_SPY_BRIBE_UNIT
68 #define SPECENUM_VALUE12NAME "Bribe Unit"
69 #define SPECENUM_VALUE13 ACTION_SPY_SABOTAGE_UNIT
70 #define SPECENUM_VALUE13NAME "Sabotage Unit"
71 #define SPECENUM_COUNT ACTION_COUNT
72 #include "specenum_gen.h"
74 /* Used in searches to signal that any action at all is OK. */
75 #define ACTION_ANY ACTION_COUNT
77 /* Used to signal the absence of any actions. */
78 #define ACTION_NONE ACTION_COUNT
80 /* Used in the network protocol */
81 #define SPECENUM_NAME action_proto_signal
82 /* The player wants to be reminded to ask what actions the unit can perform
83 * to a certain target tile. */
84 #define SPECENUM_VALUE0 ACTSIG_QUEUE
85 /* The player no longer wants the reminder to ask what actions the unit can
86 * perform to a certain target tile. */
87 #define SPECENUM_VALUE1 ACTSIG_UNQUEUE
88 #include "specenum_gen.h"
90 struct action
92 enum gen_action id;
93 enum action_actor_kind actor_kind;
94 enum action_target_kind target_kind;
95 bool hostile; /* TODO: Should this be a scale in stead? */
97 /* The name of the action shown in the UI */
98 char ui_name[MAX_LEN_NAME];
100 /* Suppress automatic help text generation about what enables and/or
101 * disables this action. */
102 bool quiet;
105 struct action_enabler
107 enum gen_action action;
108 struct requirement_vector actor_reqs;
109 struct requirement_vector target_reqs;
112 #define SPECLIST_TAG action_enabler
113 #define SPECLIST_TYPE struct action_enabler
114 #include "speclist.h"
115 #define action_enabler_list_iterate(action_enabler_list, aenabler) \
116 TYPED_LIST_ITERATE(struct action_enabler, action_enabler_list, aenabler)
117 #define action_enabler_list_iterate_end LIST_ITERATE_END
119 #define action_iterate(_act_) \
121 int _act_; \
122 for (_act_ = 0; _act_ < ACTION_COUNT; _act_++) {
124 #define action_iterate_end \
128 #define action_enablers_iterate(_enabler_) \
130 action_iterate(_act_) { \
131 action_enabler_list_iterate( \
132 action_enablers_for_action(_act_), _enabler_) {
134 #define action_enablers_iterate_end \
135 } action_enabler_list_iterate_end; \
136 } action_iterate_end; \
139 /* Initialization */
140 void actions_init(void);
141 void actions_free(void);
143 bool actions_are_ready(void);
145 bool action_id_is_valid(const int action_id);
147 struct action *action_by_number(int action_id);
149 enum action_actor_kind action_get_actor_kind(const struct action *paction);
150 #define action_id_get_actor_kind(action_id) \
151 action_get_actor_kind(action_by_number(action_id))
152 enum action_target_kind action_get_target_kind(
153 const struct action *paction);
154 #define action_id_get_target_kind(action_id) \
155 action_get_target_kind(action_by_number(action_id))
157 bool action_is_hostile(int action_id);
159 int action_get_role(int action_id);
161 const char *action_id_rule_name(int action_id);
162 const char *action_id_name_translation(int action_id);
163 const char *action_get_ui_name_mnemonic(int action_id,
164 const char* mnemonic);
165 const char *action_prepare_ui_name(int action_id, const char* mnemonic,
166 const struct act_prob prob,
167 const char *custom);
168 const char *action_get_tool_tip(const int action_id,
169 const struct act_prob prob);
171 struct action_enabler_list *
172 action_enablers_for_action(enum gen_action action);
174 struct action_enabler *action_enabler_new(void);
175 void action_enabler_add(struct action_enabler *enabler);
176 bool action_enabler_remove(struct action_enabler *enabler);
178 bool is_action_enabled_unit_on_city(const enum gen_action wanted_action,
179 const struct unit *actor_unit,
180 const struct city *target_city);
182 bool is_action_enabled_unit_on_city_full(const enum gen_action wanted_action,
183 const struct unit *actor_unit,
184 const struct city *target_city,
185 const struct city *homecity,
186 bool ignore_dist);
188 bool is_action_enabled_unit_on_unit(const enum gen_action wanted_action,
189 const struct unit *actor_unit,
190 const struct unit *target_unit);
192 struct act_prob action_prob_vs_city(const struct unit* actor,
193 const int action_id,
194 const struct city* victim);
196 struct act_prob action_prob_vs_unit(const struct unit* actor,
197 const int action_id,
198 const struct unit* victim);
200 bool action_prob_possible(const struct act_prob probability);
202 bool are_action_probabilitys_equal(const struct act_prob *ap1,
203 const struct act_prob *ap2);
205 struct act_prob action_prob_new_impossible(void);
206 struct act_prob action_prob_new_not_relevant(void);
207 struct act_prob action_prob_new_not_impl(void);
208 struct act_prob action_prob_new_unknown(void);
209 struct act_prob action_prob_new_certain(void);
211 /* Special action probability values. Documented in fc_types.h's
212 * definition of struct act_prob. */
213 #define ACTPROB_IMPOSSIBLE action_prob_new_impossible()
214 #define ACTPROB_CERTAIN action_prob_new_certain()
215 #define ACTPROB_NA action_prob_new_not_relevant()
216 #define ACTPROB_NOT_IMPLEMENTED action_prob_new_not_impl()
217 #define ACTPROB_NOT_KNOWN action_prob_new_unknown()
219 /* Reasoning about actions */
220 bool action_immune_government(struct government *gov, int act);
222 bool is_action_possible_on_city(const enum gen_action action_id,
223 const struct player *actor_player,
224 const struct city* target_city);
226 bool action_mp_full_makes_legal(const struct unit *actor,
227 const int action_id);
229 #ifdef __cplusplus
231 #endif /* __cplusplus */
233 #endif /* FC_ACTIONS_H */