Freeciv-3.3: /fast/freeciv/nightly/main/common/actions.h Source File

Freeciv-3.3

Loading...
Searching...
No Matches
actions.h
Go to the documentation of this file.
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.
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
14#ifndef FC_ACTIONS_H
15#define FC_ACTIONS_H
16
17/* common */
18#include "actres.h"
19#include "fc_types.h"
20#include "map_types.h"
21#include "requirements.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif /* __cplusplus */
26
27/* If 'enum gen_action' has currently unused values that should
28 * not be used in 'switch - cases', put those cases here. E.g.:
29 *
30 *#define ASSERT_UNUSED_ACTION_CASES \
31 * case ACTION_UNUSED_1: \
32 * fc_assert_msg(FALSE, "ACTION_UNUSED_1"); \
33 * break; \
34 * case ACTION_UNUSED_2: \
35 * fc_assert_msg(FALSE, "ACTION_UNUSED_2"); \
36 * break;
37 */
38#define ASSERT_UNUSED_ACTION_CASES \
39
40
41#define SPECENUM_NAME action_actor_kind
42#define SPECENUM_VALUE0 AAK_UNIT
43#define SPECENUM_VALUE0NAME N_("a unit")
44#define SPECENUM_COUNT AAK_COUNT
45#include "specenum_gen.h"
46
47const char *gen_action_name_update_cb(const char *old_name);
48
49#include "actions_enums_gen.h"
50
51/* Fake action id used in searches to signal "any action at all". */
52#define ACTION_ANY ACTION_COUNT
53
54/* Fake action id used to signal the absence of any actions. */
55#define ACTION_NONE ACTION_COUNT
56
57/* Used in the network protocol. */
58#define MAX_NUM_ACTIONS ACTION_COUNT
59#define NUM_ACTIONS MAX_NUM_ACTIONS
60
61/* Describes how a unit successfully performing an action will move it. */
62#define SPECENUM_NAME moves_actor_kind
63#define SPECENUM_VALUE0 MAK_STAYS
64#define SPECENUM_VALUE0NAME N_("stays")
65#define SPECENUM_VALUE1 MAK_REGULAR
66#define SPECENUM_VALUE1NAME N_("regular")
67#define SPECENUM_VALUE2 MAK_TELEPORT
68#define SPECENUM_VALUE2NAME N_("teleport")
69#define SPECENUM_VALUE3 MAK_ESCAPE
70#define SPECENUM_VALUE3NAME N_("escape")
71#define SPECENUM_VALUE4 MAK_FORCED
72#define SPECENUM_VALUE4NAME N_("forced")
73#define SPECENUM_VALUE5 MAK_UNREPRESENTABLE
74#define SPECENUM_VALUE5NAME N_("unrepresentable")
75#include "specenum_gen.h"
76
77/* Who ordered the action to be performed? */
78#define SPECENUM_NAME action_requester
79/* The player ordered it directly. */
80#define SPECENUM_VALUE0 ACT_REQ_PLAYER
81#define SPECENUM_VALUE0NAME N_("the player")
82/* The game it self because the rules requires it. */
83#define SPECENUM_VALUE1 ACT_REQ_RULES
84#define SPECENUM_VALUE1NAME N_("the game rules")
85/* A server side autonomous agent working for the player. */
86#define SPECENUM_VALUE2 ACT_REQ_SS_AGENT
87#define SPECENUM_VALUE2NAME N_("a server agent")
88/* Number of action requesters. */
89#define SPECENUM_COUNT ACT_REQ_COUNT
90#include "specenum_gen.h"
91
92/* The last action distance value that is interpreted as an actual
93 * distance rather than as a signal value.
94 *
95 * It is specified literally rather than referring to MAP_DISTANCE_MAX
96 * because Freeciv-web's MAP_DISTANCE_MAX differs from the regular Freeciv
97 * server's MAP_DISTANCE_MAX. A static assertion in actions.c makes sure
98 * that it can cover the whole map. */
99#define ACTION_DISTANCE_LAST_NON_SIGNAL 128016
100/* No action max distance to target limit. */
101#define ACTION_DISTANCE_UNLIMITED (ACTION_DISTANCE_LAST_NON_SIGNAL + 1)
102/* No action max distance can be bigger than this. */
103#define ACTION_DISTANCE_MAX ACTION_DISTANCE_UNLIMITED
104
105 struct action
106{
107 action_id id;
108
109 enum action_result result;
110 bv_action_sub_results sub_results;
111
112 enum action_actor_kind actor_kind;
113 enum action_target_kind target_kind;
114 enum action_sub_target_kind sub_target_kind;
115
116 /* Sub target policy. */
117 enum act_tgt_compl target_complexity;
118
119 /* Limits on the distance on the map between the actor and the target.
120 * The action is legal iff the distance is min_distance, max_distance or
121 * a value in between. */
122 int min_distance, max_distance;
123
124 /* The name of the action shown in the UI */
125 char ui_name[MAX_LEN_NAME];
126
127 /* Suppress automatic help text generation about what enables and/or
128 * disables this action. */
129 bool quiet;
130
131 /* Actions that blocks this action. The action will be illegal if any
132 * bloking action is legal. */
133 bv_actions blocked_by;
134
135 /* Successfully performing this action will always consume the actor.
136 * Don't set this for actions that consumes the unit in some cases
137 * (depending on luck, the presence of a flag, etc) but not in other
138 * cases. */
139 bool actor_consuming_always;
140
141 union {
142 struct {
143 /* A unit's ability to perform this action will pop up the action
144 * selection dialog before the player asks for it only in exceptional
145 * cases.
146 *
147 * The motivation for setting rare_pop_up is to minimize player
148 * annoyance and mistakes. Getting a pop up every time a unit moves is
149 * annoying. An unexpected offer to do something that in many cases is
150 * destructive can lead the player's muscle memory to perform the
151 * wrong action. */
152 bool rare_pop_up;
153
154 /* The unitwaittime setting blocks this action when done too soon. */
155 bool unitwaittime_controlled;
156
157 /* How successfully performing the specified action always will move
158 * the actor unit of the specified type. */
159 enum moves_actor_kind moves_actor;
160 } is_unit;
161 } actor;
162};
163
164 struct action_enabler
165{
166 action_id action;
167 struct requirement_vector actor_reqs;
168 struct requirement_vector target_reqs;
169
170 /* Only relevant for ruledit and other rulesave users. Indicates that
171 * this action enabler is deleted and shouldn't be saved. */
172 bool ruledit_disabled;
173};
174
175#define action_has_result(_act_, _res_) ((_act_)->result == (_res_))
176
177#define enabler_get_action(_enabler_) action_by_number(_enabler_->action)
178#define enabler_get_action_id(_enabler_) (_enabler_->action)
179
180#define SPECLIST_TAG action_enabler
181#define SPECLIST_TYPE struct action_enabler
182#include "speclist.h"
183#define action_enabler_list_iterate(action_enabler_list, aenabler) \
184 TYPED_LIST_ITERATE(struct action_enabler, action_enabler_list, aenabler)
185#define action_enabler_list_iterate_end LIST_ITERATE_END
186
187#define action_enabler_list_re_iterate(action_enabler_list, aenabler) \
188 action_enabler_list_iterate(action_enabler_list, aenabler) { \
189 if (!aenabler->ruledit_disabled) {
190
191#define action_enabler_list_re_iterate_end \
192 } \
193 } action_enabler_list_iterate_end
194
195#define action_iterate_all(_act_) \
196{ \
197 action_id _act_; \
198 for (_act_ = 0; _act_ < NUM_ACTIONS; _act_++) {
199
200#define action_iterate_all_end \
201 } \
202}
203
204/* Filter out unused action slots, in versions where those exist */
205#define action_iterate(_act_) \
206{ \
207 action_iterate_all(_act_) {
208
209#define action_iterate_end \
210 } action_iterate_all_end; \
211}
212
213/* Get 'struct action_id_list' and related functions: */
214#define SPECLIST_TAG action
215#define SPECLIST_TYPE struct action
216#include "speclist.h"
217
218#define action_list_iterate(_list_, _act_) \
219 TYPED_LIST_ITERATE(struct action, _list_, _act_)
220#define action_list_iterate_end LIST_ITERATE_END
221
222struct action_list *action_list_by_result(enum action_result result);
223struct action_list *action_list_by_activity(enum unit_activity activity);
224
225/* TODO: Turn this to an iteration over precalculated list */
226#define action_noninternal_iterate(_act_) \
227{ \
228 action_iterate(_act_) { \
229 if (!action_id_is_internal(_act_)) {
230
231#define action_noninternal_iterate_end \
232 } \
233 } action_iterate_end; \
234}
235
236#define action_by_result_iterate(_paction_, _result_) \
237{ \
238 action_list_iterate(action_list_by_result(_result_), _paction_) { \
239
240#define action_by_result_iterate_end \
241 } action_list_iterate_end; \
242}
243
244#define action_by_activity_iterate(_paction_, _activity_) \
245{ \
246 action_list_iterate(action_list_by_activity(_activity_), _paction_) {
247
248#define action_by_activity_iterate_end \
249 } action_list_iterate_end; \
250}
251
252#define action_array_iterate(_act_array_, _act_id_) \
253{ \
254 int _pos_; \
255 \
256 for (_pos_ = 0; _pos_ < NUM_ACTIONS; _pos_++) { \
257 const action_id _act_id_ = _act_array_[_pos_]; \
258 \
259 if (_act_id_ == ACTION_NONE) { \
260 /* No more actions in this list. */ \
261 break; \
262 }
263
264#define action_array_iterate_end \
265 } \
266}
267
268#define action_enablers_iterate(_enabler_) \
269{ \
270 action_iterate(_act_) { \
271 action_enabler_list_iterate( \
272 action_enablers_for_action(_act_), _enabler_) {
273
274#define action_enablers_iterate_end \
275 } action_enabler_list_iterate_end; \
276 } action_iterate_end; \
277}
278
279/* The reason why an action should be auto performed. */
280#define SPECENUM_NAME action_auto_perf_cause
281/* Can't pay the unit's upkeep. */
282/* (Can be triggered by food, shield or gold upkeep) */
283#define SPECENUM_VALUE0 AAPC_UNIT_UPKEEP
284#define SPECENUM_VALUE0NAME "Unit Upkeep"
285/* A unit moved to an adjacent tile (auto attack). */
286#define SPECENUM_VALUE1 AAPC_UNIT_MOVED_ADJ
287#define SPECENUM_VALUE1NAME "Moved Adjacent"
288/* An action was successfully performed and the (action specific) conditions
289 * for forcing a post action move are fulfilled. */
290#define SPECENUM_VALUE2 AAPC_POST_ACTION
291#define SPECENUM_VALUE2NAME "After Successful Action"
292/* The city that made the unit's current tile native is gone. Evaluated
293 * against an adjacent tile. */
294#define SPECENUM_VALUE3 AAPC_CITY_GONE
295#define SPECENUM_VALUE3NAME "City Gone"
296/* The unit's stack has been defeated and is scheduled for execution but the
297 * unit has the CanEscape unit type flag.
298 * Evaluated against an adjacent tile. */
299#define SPECENUM_VALUE4 AAPC_UNIT_STACK_DEATH
300#define SPECENUM_VALUE4NAME "Unit Stack Dead"
301/* Number of forced action auto performer causes. */
302#define SPECENUM_COUNT AAPC_COUNT
303#include "specenum_gen.h"
304
305/* An Action Auto Performer rule makes an actor try to perform an action
306 * without being ordered to do so by the player controlling it.
307 * - the first auto performer that matches the cause and fulfills the reqs
308 * is selected.
309 * - the actions listed by the selected auto performer is tried in order
310 * until an action is successful, all actions have been tried or the
311 * actor disappears.
312 * - if no action inside the selected auto performer is legal no action is
313 * performed. The system won't try to select another auto performer.
314 */
315 struct action_auto_perf
316{
317 /* The reason for trying to auto perform an action. */
318 enum action_auto_perf_cause cause;
319
320 /* Must be fulfilled if the game should try to force an action from this
321 * action auto performer. */
322 struct requirement_vector reqs;
323
324 /* Auto perform the first legal action in this list.
325 * The list is terminated by ACTION_NONE. */
326 action_id alternatives[MAX_NUM_ACTIONS];
327};
328
329#define action_auto_perf_iterate(_act_perf_) \
330{ \
331 int _ap_num_; \
332 \
333 for (_ap_num_ = 0; \
334 _ap_num_ < MAX_NUM_ACTION_AUTO_PERFORMERS \
335 && (action_auto_perf_by_number(_ap_num_)->cause \
336 != AAPC_COUNT); \
337 _ap_num_++) { \
338 const struct action_auto_perf *_act_perf_ \
339 = action_auto_perf_by_number(_ap_num_);
340
341#define action_auto_perf_iterate_end \
342 } \
343}
344
345#define action_auto_perf_by_cause_iterate(_cause_, _act_perf_) \
346action_auto_perf_iterate(_act_perf_) { \
347 if (_act_perf_->cause != _cause_) { \
348 continue; \
349 }
350
351#define action_auto_perf_by_cause_iterate_end \
352} action_auto_perf_iterate_end
353
354#define action_auto_perf_actions_iterate(_autoperf_, _act_id_) \
355 action_array_iterate(_autoperf_->alternatives, _act_id_)
356
357#define action_auto_perf_actions_iterate_end \
358 action_array_iterate_end
359
360/* Hard coded location of action auto performers. Used for conversion while
361 * action auto performers aren't directly exposed to the ruleset.
362 * Remember to update also MAX_NUM_ACTION_AUTO_PERFORMERS when changing these. */
363#define ACTION_AUTO_UPKEEP_FOOD 0
364#define ACTION_AUTO_UPKEEP_GOLD 1
365#define ACTION_AUTO_UPKEEP_SHIELD 2
366#define ACTION_AUTO_MOVED_ADJ 3
367#define ACTION_AUTO_POST_BRIBE 4
368#define ACTION_AUTO_POST_ATTACK 5
369#define ACTION_AUTO_POST_ATTACK2 6
370#define ACTION_AUTO_POST_COLLECT_RANSOM 7
371#define ACTION_AUTO_ESCAPE_CITY 8
372#define ACTION_AUTO_ESCAPE_STACK 9
373#define ACTION_AUTO_POST_WIPE_UNITS 10
374
375/* Initialization */
376void actions_init(void);
377void actions_rs_pre_san_gen(void);
378void actions_free(void);
379
380bool actions_are_ready(void);
381
382bool action_id_exists(const action_id act_id);
383
384extern struct action **_actions;
385/**********************************************************************/
390 static inline struct action *action_by_number(action_id act_id)
391{
392 if (!gen_action_is_valid((enum gen_action)act_id)) {
393 return NULL;
394 }
395
396 /* We return NULL if there's NULL there, no need to special case it */
397 return _actions[act_id];
398}
399
400struct action *action_by_rule_name(const char *name);
401
402enum action_actor_kind action_get_actor_kind(const struct action *paction);
403#define action_id_get_actor_kind(act_id) \
404 action_get_actor_kind(action_by_number(act_id))
405enum action_target_kind action_get_target_kind(
406 const struct action *paction);
407#define action_id_get_target_kind(act_id) \
408 action_get_target_kind(action_by_number(act_id))
409enum action_sub_target_kind action_get_sub_target_kind(
410 const struct action *paction);
411#define action_id_get_sub_target_kind(act_id) \
412 action_get_sub_target_kind(action_by_number(act_id))
413
414int action_number(const struct action *action);
415
416#define action_id(_act_) (_act_->id)
417
418#define action_has_result_safe(paction, result) \
419 (paction && action_has_result(paction, result))
420#define action_id_has_result_safe(act_id, result) \
421 (action_by_number(act_id) \
422 && action_has_result(action_by_number(act_id), result))
423
424bool action_has_complex_target(const struct action *paction);
425#define action_id_has_complex_target(act_id) \
426 action_has_complex_target(action_by_number(act_id))
427bool action_requires_details(const struct action *paction);
428#define action_id_requires_details(act_id) \
429 action_requires_details(action_by_number(act_id))
430
431#define action_id_get_act_time(act_id, actor_unit, tgt_tile, tgt_extra) \
432 actres_get_act_time(action_by_number(act_id)->result, \
433 actor_unit, tgt_tile, tgt_extra)
434
435bool action_id_is_rare_pop_up(action_id act_id);
436
437bool action_distance_accepted(const struct action *action,
438 const int distance);
439#define action_id_distance_accepted(act_id, distance) \
440 action_distance_accepted(action_by_number(act_id), distance)
441
442bool action_distance_inside_max(const struct action *action,
443 const int distance);
444#define action_id_distance_inside_max(act_id, distance) \
445 action_distance_inside_max(action_by_number(act_id), distance)
446
447bool action_would_be_blocked_by(const struct action *blocked,
448 const struct action *blocker);
449
450int action_get_role(const struct action *paction);
451#define action_id_get_role(act_id) \
452 action_get_role(action_by_number(act_id))
453
454#define action_get_activity(_pact_) \
455 actres_activity_result(_pact_->result)
456#define action_id_get_activity(act_id) \
457 action_get_activity(action_by_number(act_id))
458
459const char *action_rule_name(const struct action *action);
460const char *action_id_rule_name(action_id act_id);
461
462const char *action_name_translation(const struct action *paction);
463const char *action_id_name_translation(action_id act_id);
464const char *action_get_ui_name_mnemonic(action_id act_id,
465 const char *mnemonic);
466const char *action_prepare_ui_name(action_id act_id, const char *mnemonic,
467 const struct act_prob prob,
468 const char *custom);
469
470const char *action_ui_name_ruleset_var_name(int act);
471const char *action_ui_name_default(int act);
472
473const char *action_min_range_ruleset_var_name(int act);
474const char *action_max_range_ruleset_var_name(int act);
475
476const char *action_target_kind_ruleset_var_name(int act);
477const char *action_target_kind_help(enum action_target_kind kind);
478
479const char *action_actor_consuming_always_ruleset_var_name(action_id act);
480
481const char *action_blocked_by_ruleset_var_name(const struct action *act);
482
483const char *
484 action_post_success_forced_ruleset_var_name(const struct action *act);
485
486bool action_ever_possible(action_id action);
487
488struct action_enabler_list *
489 action_enablers_for_action(action_id action);
490
491struct action_enabler *action_enabler_new(void);
492void action_enabler_free(struct action_enabler *enabler);
493struct action_enabler *
494 action_enabler_copy(const struct action_enabler *original);
495void action_enabler_add(struct action_enabler *enabler);
496bool action_enabler_remove(struct action_enabler *enabler);
497
498struct req_vec_problem *
499 action_enabler_suggest_repair_oblig(const struct action_enabler *enabler);
500struct req_vec_problem *
501 action_enabler_suggest_repair(const struct action_enabler *enabler);
502struct req_vec_problem *
503 action_enabler_suggest_improvement(const struct action_enabler *enabler);
504
505 req_vec_num_in_item
506 action_enabler_vector_number(const void *enabler,
507 const struct requirement_vector *vec);
508struct requirement_vector *
509 action_enabler_vector_by_number(const void *enabler,
510 req_vec_num_in_item vec);
511const char *action_enabler_vector_by_number_name(req_vec_num_in_item vec);
512
513bool action_enabler_utype_possible_actor(const struct action_enabler *ae,
514 const struct unit_type *act_utype);
515bool action_enabler_possible_actor(const struct action_enabler *ae);
516
517struct action *action_is_blocked_by(const struct action *act,
518 const struct unit *actor_unit,
519 const struct tile *target_tile,
520 const struct city *target_city,
521 const struct unit *target_unit);
522
523bool is_action_enabled_unit_on_city(const struct civ_map *nmap,
524 const action_id wanted_action,
525 const struct unit *actor_unit,
526 const struct city *target_city);
527
528bool is_action_enabled_unit_on_unit(const struct civ_map *nmap,
529 const action_id wanted_action,
530 const struct unit *actor_unit,
531 const struct unit *target_unit);
532
533bool is_action_enabled_unit_on_stack(const struct civ_map *nmap,
534 const action_id wanted_action,
535 const struct unit *actor_unit,
536 const struct tile *target_tile);
537
538bool is_action_enabled_unit_on_tile(const struct civ_map *nmap,
539 const action_id wanted_action,
540 const struct unit *actor_unit,
541 const struct tile *target_tile,
542 const struct extra_type *target_extra);
543
544bool is_action_enabled_unit_on_extras(const struct civ_map *nmap,
545 const action_id wanted_action,
546 const struct unit *actor_unit,
547 const struct tile *target,
548 const struct extra_type *tgt_extra);
549
550bool is_action_enabled_unit_on_self(const struct civ_map *nmap,
551 const action_id wanted_action,
552 const struct unit *actor_unit);
553
554struct act_prob action_prob_vs_city(const struct civ_map *nmap,
555 const struct unit *actor,
556 const action_id act_id,
557 const struct city *victim);
558
559struct act_prob action_prob_vs_unit(const struct civ_map *nmap,
560 const struct unit *actor,
561 const action_id act_id,
562 const struct unit *victim);
563
564struct act_prob action_prob_vs_stack(const struct unit* actor,
565 const action_id act_id,
566 const struct tile* victims);
567
568struct act_prob action_prob_vs_tile(const struct unit *actor,
569 const action_id act_id,
570 const struct tile *victims,
571 const struct extra_type *target_extra);
572
573struct act_prob action_prob_vs_extras(const struct unit *actor,
574 const action_id act_id,
575 const struct tile *target,
576 const struct extra_type *tgt_extra);
577
578struct act_prob action_prob_self(const struct unit *actor,
579 const action_id act_id);
580
581struct act_prob action_prob_unit_vs_tgt(const struct action *paction,
582 const struct unit *act_unit,
583 const struct city *tgt_city,
584 const struct unit *tgt_unit,
585 const struct tile *tgt_tile,
586 const struct extra_type *sub_tgt);
587
588struct act_prob
589 action_speculate_unit_on_city(action_id act_id,
590 const struct unit *actor,
591 const struct city *actor_home,
592 const struct tile *actor_tile,
593 bool omniscient_cheat,
594 const struct city* target);
595
596struct act_prob
597 action_speculate_unit_on_unit(action_id act_id,
598 const struct unit *actor,
599 const struct city *actor_home,
600 const struct tile *actor_tile,
601 bool omniscient_cheat,
602 const struct unit *target);
603
604struct act_prob
605 action_speculate_unit_on_stack(action_id act_id,
606 const struct unit *actor,
607 const struct city *actor_home,
608 const struct tile *actor_tile,
609 bool omniscient_cheat,
610 const struct tile *target);
611
612struct act_prob
613 action_speculate_unit_on_tile(action_id act_id,
614 const struct unit *actor,
615 const struct city *actor_home,
616 const struct tile *actor_tile,
617 bool omniscient_cheat,
618 const struct tile *target_tile,
619 const struct extra_type *target_extra);
620
621struct act_prob
622 action_speculate_unit_on_extras(action_id act_id,
623 const struct unit *actor,
624 const struct city *actor_home,
625 const struct tile *actor_tile,
626 bool omniscient_cheat,
627 const struct tile *target_tile,
628 const struct extra_type *target_extra);
629
630struct act_prob
631 action_speculate_unit_on_self(action_id act_id,
632 const struct unit *actor,
633 const struct city *actor_home,
634 const struct tile *actor_tile,
635 bool omniscient_cheat);
636
637bool action_prob_possible(const struct act_prob probability);
638
639bool action_prob_certain(const struct act_prob probability);
640
641bool are_action_probabilitys_equal(const struct act_prob *ap1,
642 const struct act_prob *ap2);
643
644int action_prob_cmp_pessimist(const struct act_prob ap1,
645 const struct act_prob ap2);
646
647double action_prob_to_0_to_1_pessimist(const struct act_prob ap);
648
649struct act_prob action_prob_and(const struct act_prob *ap1,
650 const struct act_prob *ap2);
651
652struct act_prob action_prob_fall_back(const struct act_prob *ap1,
653 const struct act_prob *ap2);
654
655const char *action_prob_explain(const struct act_prob prob);
656
657struct act_prob action_prob_new_impossible(void);
658struct act_prob action_prob_new_not_relevant(void);
659struct act_prob action_prob_new_not_impl(void);
660struct act_prob action_prob_new_unknown(void);
661struct act_prob action_prob_new_certain(void);
662
663/* Special action probability values. Documented in fc_types.h's
664 * definition of struct act_prob. */
665#define ACTPROB_IMPOSSIBLE action_prob_new_impossible()
666#define ACTPROB_CERTAIN action_prob_new_certain()
667#define ACTPROB_NA action_prob_new_not_relevant()
668#define ACTPROB_NOT_IMPLEMENTED action_prob_new_not_impl()
669#define ACTPROB_NOT_KNOWN action_prob_new_unknown()
670
671/* ACTION_ODDS_PCT_DICE_ROLL_NA must be above 100%. */
672#define ACTION_ODDS_PCT_DICE_ROLL_NA 110
673int action_dice_roll_initial_odds(const struct action *paction);
674int action_dice_roll_odds(const struct player *act_player,
675 const struct unit *act_unit,
676 const struct city *tgt_city,
677 const struct player *tgt_player,
678 const struct action *paction);
679
680bool
681 action_actor_utype_hard_reqs_ok(const struct action *result,
682 const struct unit_type *actor_unittype);
683
684/* Reasoning about actions */
685bool action_univs_not_blocking(const struct action *paction,
686 struct universal *actor_uni,
687 struct universal *target_uni);
688#define action_id_univs_not_blocking(act_id, act_uni, tgt_uni) \
689 action_univs_not_blocking(action_by_number(act_id), act_uni, tgt_uni)
690
691bool action_immune_government(struct government *gov, action_id act);
692
693bool is_action_possible_on_city(action_id act_id,
694 const struct player *actor_player,
695 const struct city *target_city);
696
697bool action_maybe_possible_actor_unit(const struct civ_map *nmap,
698 const action_id wanted_action,
699 const struct unit *actor_unit);
700
701bool action_mp_full_makes_legal(const struct unit *actor,
702 const action_id act_id);
703
704bool action_is_in_use(struct action *paction);
705
706bool action_is_internal(struct action *paction);
707bool action_id_is_internal(action_id act);
708
709/* Action lists */
710void action_array_end(action_id *act_array, int size);
711void action_array_add_all_by_result(action_id *act_array,
712 int *position,
713 enum action_result result);
714
715/* Action auto performers */
716const struct action_auto_perf *action_auto_perf_by_number(const int num);
717struct action_auto_perf *action_auto_perf_slot_number(const int num);
718
719#ifdef __cplusplus
720}
721#endif /* __cplusplus */
722
723#endif /* FC_ACTIONS_H */
is_action_possible_on_city
bool is_action_possible_on_city(action_id act_id, const struct player *actor_player, const struct city *target_city)
Definition actions.c:5444
action_prepare_ui_name
const char * action_prepare_ui_name(action_id act_id, const char *mnemonic, const struct act_prob prob, const char *custom)
Definition actions.c:1287
action_distance_inside_max
bool action_distance_inside_max(const struct action *action, const int distance)
Definition actions.c:1148
action_prob_explain
const char * action_prob_explain(const struct act_prob prob)
Definition actions.c:1398
action_mp_full_makes_legal
bool action_mp_full_makes_legal(const struct unit *actor, const action_id act_id)
Definition actions.c:5522
action_get_actor_kind
enum action_actor_kind action_get_actor_kind(const struct action *paction)
Definition actions.c:1073
action_prob_certain
bool action_prob_certain(const struct act_prob probability)
Definition actions.c:5054
action_id_name_translation
const char * action_id_name_translation(action_id act_id)
Definition actions.c:1225
action_auto_perf_slot_number
struct action_auto_perf * action_auto_perf_slot_number(const int num)
Definition actions.c:5675
action_enabler_vector_number
req_vec_num_in_item action_enabler_vector_number(const void *enabler, const struct requirement_vector *vec)
Definition actions.c:2022
action_has_complex_target
bool action_has_complex_target(const struct action *paction)
Definition actions.c:1107
action_prob_vs_extras
struct act_prob action_prob_vs_extras(const struct unit *actor, const action_id act_id, const struct tile *target, const struct extra_type *tgt_extra)
Definition actions.c:4646
action_enabler_suggest_repair
struct req_vec_problem * action_enabler_suggest_repair(const struct action_enabler *enabler)
Definition actions.c:1892
action_prob_possible
bool action_prob_possible(const struct act_prob probability)
Definition actions.c:5044
action_prob_new_not_impl
struct act_prob action_prob_new_not_impl(void)
Definition actions.c:5023
action_enabler_suggest_improvement
struct req_vec_problem * action_enabler_suggest_improvement(const struct action_enabler *enabler)
Definition actions.c:1958
actions_rs_pre_san_gen
void actions_rs_pre_san_gen(void)
Definition actions.c:879
action_min_range_ruleset_var_name
const char * action_min_range_ruleset_var_name(int act)
Definition actions.c:6414
action_blocked_by_ruleset_var_name
const char * action_blocked_by_ruleset_var_name(const struct action *act)
Definition actions.c:7116
action_enabler_suggest_repair_oblig
struct req_vec_problem * action_enabler_suggest_repair_oblig(const struct action_enabler *enabler)
Definition actions.c:1653
action_array_add_all_by_result
void action_array_add_all_by_result(action_id *act_array, int *position, enum action_result result)
Definition actions.c:5740
action_name_translation
const char * action_name_translation(const struct action *paction)
Definition actions.c:1205
action_dice_roll_odds
int action_dice_roll_odds(const struct player *act_player, const struct unit *act_unit, const struct city *tgt_city, const struct player *tgt_player, const struct action *paction)
Definition actions.c:5344
action_array_end
void action_array_end(action_id *act_array, int size)
Definition actions.c:5723
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:390
action_maybe_possible_actor_unit
bool action_maybe_possible_actor_unit(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit)
Definition actions.c:5467
action_is_in_use
bool action_is_in_use(struct action *paction)
Definition actions.c:5629
action_prob_unit_vs_tgt
struct act_prob action_prob_unit_vs_tgt(const struct action *paction, const struct unit *act_unit, const struct city *tgt_city, const struct unit *tgt_unit, const struct tile *tgt_tile, const struct extra_type *sub_tgt)
Definition actions.c:4739
action_ever_possible
bool action_ever_possible(action_id action)
Definition actions.c:7481
action_enabler_vector_by_number_name
const char * action_enabler_vector_by_number_name(req_vec_num_in_item vec)
Definition actions.c:2069
are_action_probabilitys_equal
bool are_action_probabilitys_equal(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5095
action_post_success_forced_ruleset_var_name
const char * action_post_success_forced_ruleset_var_name(const struct action *act)
Definition actions.c:7308
action_by_rule_name
struct action * action_by_rule_name(const char *name)
Definition actions.c:1054
action_rule_name
const char * action_rule_name(const struct action *action)
Definition actions.c:1191
action_id_rule_name
const char * action_id_rule_name(action_id act_id)
Definition actions.c:1214
action_get_sub_target_kind
enum action_sub_target_kind action_get_sub_target_kind(const struct action *paction)
Definition actions.c:1094
actions_free
void actions_free(void)
Definition actions.c:889
action_enabler_free
void action_enabler_free(struct action_enabler *enabler)
Definition actions.c:1469
is_action_enabled_unit_on_stack
bool is_action_enabled_unit_on_stack(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile)
Definition actions.c:3217
action_list_by_activity
struct action_list * action_list_by_activity(enum unit_activity activity)
Definition actions.c:7535
action_number
int action_number(const struct action *action)
Definition actions.c:1183
action_prob_new_unknown
struct act_prob action_prob_new_unknown(void)
Definition actions.c:5033
action_would_be_blocked_by
bool action_would_be_blocked_by(const struct action *blocked, const struct action *blocker)
Definition actions.c:1171
action_speculate_unit_on_self
struct act_prob action_speculate_unit_on_self(action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat)
Definition actions.c:4965
is_action_enabled_unit_on_tile
bool is_action_enabled_unit_on_tile(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:3293
action_prob_and
struct act_prob action_prob_and(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5182
action_actor_consuming_always_ruleset_var_name
const char * action_actor_consuming_always_ruleset_var_name(action_id act)
Definition actions.c:6945
action_immune_government
bool action_immune_government(struct government *gov, action_id act)
Definition actions.c:5400
action_prob_self
struct act_prob action_prob_self(const struct unit *actor, const action_id act_id)
Definition actions.c:4717
action_prob_new_certain
struct act_prob action_prob_new_certain(void)
Definition actions.c:5003
action_max_range_ruleset_var_name
const char * action_max_range_ruleset_var_name(int act)
Definition actions.c:6590
action_speculate_unit_on_stack
struct act_prob action_speculate_unit_on_stack(action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct tile *target)
Definition actions.c:4864
action_is_internal
bool action_is_internal(struct action *paction)
Definition actions.c:5655
action_speculate_unit_on_city
struct act_prob action_speculate_unit_on_city(action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct city *target)
Definition actions.c:4796
action_dice_roll_initial_odds
int action_dice_roll_initial_odds(const struct action *paction)
Definition actions.c:5320
action_prob_fall_back
struct act_prob action_prob_fall_back(const struct act_prob *ap1, const struct act_prob *ap2)
Definition actions.c:5252
action_is_blocked_by
struct action * action_is_blocked_by(const struct action *act, const struct unit *actor_unit, const struct tile *target_tile, const struct city *target_city, const struct unit *target_unit)
Definition actions.c:2249
action_speculate_unit_on_extras
struct act_prob action_speculate_unit_on_extras(action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:4931
is_action_enabled_unit_on_city
bool is_action_enabled_unit_on_city(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct city *target_city)
Definition actions.c:3052
action_prob_vs_stack
struct act_prob action_prob_vs_stack(const struct unit *actor, const action_id act_id, const struct tile *victims)
Definition actions.c:4478
action_list_by_result
struct action_list * action_list_by_result(enum action_result result)
Definition actions.c:7525
MAX_NUM_ACTIONS
#define MAX_NUM_ACTIONS
Definition actions.h:58
action_univs_not_blocking
bool action_univs_not_blocking(const struct action *paction, struct universal *actor_uni, struct universal *target_uni)
Definition actions.c:5699
actions_are_ready
bool actions_are_ready(void)
Definition actions.c:931
is_action_enabled_unit_on_unit
bool is_action_enabled_unit_on_unit(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct unit *target_unit)
Definition actions.c:3129
action_actor_utype_hard_reqs_ok
bool action_actor_utype_hard_reqs_ok(const struct action *result, const struct unit_type *actor_unittype)
Definition actions.c:2569
action_target_kind_ruleset_var_name
const char * action_target_kind_ruleset_var_name(int act)
Definition actions.c:6775
action_enabler_add
void action_enabler_add(struct action_enabler *enabler)
Definition actions.c:1496
action_prob_vs_unit
struct act_prob action_prob_vs_unit(const struct civ_map *nmap, const struct unit *actor, const action_id act_id, const struct unit *victim)
Definition actions.c:4286
action_ui_name_default
const char * action_ui_name_default(int act)
Definition actions.c:6055
action_enabler_utype_possible_actor
bool action_enabler_utype_possible_actor(const struct action_enabler *ae, const struct unit_type *act_utype)
Definition actions.c:5545
action_enabler_new
struct action_enabler * action_enabler_new(void)
Definition actions.c:1450
action_requires_details
bool action_requires_details(const struct action *paction)
Definition actions.c:1120
action_prob_new_not_relevant
struct act_prob action_prob_new_not_relevant(void)
Definition actions.c:5013
action_target_kind_help
const char * action_target_kind_help(enum action_target_kind kind)
Definition actions.c:7515
action_get_role
int action_get_role(const struct action *paction)
Definition actions.c:1438
action_prob_vs_city
struct act_prob action_prob_vs_city(const struct civ_map *nmap, const struct unit *actor, const action_id act_id, const struct city *victim)
Definition actions.c:4203
action_speculate_unit_on_unit
struct act_prob action_speculate_unit_on_unit(action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct unit *target)
Definition actions.c:4831
action_auto_perf_by_number
const struct action_auto_perf * action_auto_perf_by_number(const int num)
Definition actions.c:5691
action_prob_new_impossible
struct act_prob action_prob_new_impossible(void)
Definition actions.c:4993
action_enabler_possible_actor
bool action_enabler_possible_actor(const struct action_enabler *ae)
Definition actions.c:5572
_actions
struct action ** _actions
Definition actions.c:58
action_prob_vs_tile
struct act_prob action_prob_vs_tile(const struct unit *actor, const action_id act_id, const struct tile *victims, const struct extra_type *target_extra)
Definition actions.c:4562
action_id_exists
bool action_id_exists(const action_id act_id)
Definition actions.c:1043
action_enabler_remove
bool action_enabler_remove(struct action_enabler *enabler)
Definition actions.c:1513
action_get_target_kind
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1083
action_enabler_copy
struct action_enabler * action_enabler_copy(const struct action_enabler *original)
Definition actions.c:1481
action_prob_cmp_pessimist
int action_prob_cmp_pessimist(const struct act_prob ap1, const struct act_prob ap2)
Definition actions.c:5104
action_id_is_internal
bool action_id_is_internal(action_id act)
Definition actions.c:5667
is_action_enabled_unit_on_self
bool is_action_enabled_unit_on_self(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit)
Definition actions.c:3442
action_id_is_rare_pop_up
bool action_id_is_rare_pop_up(action_id act_id)
Definition actions.c:1135
actions_init
void actions_init(void)
Definition actions.c:830
action_speculate_unit_on_tile
struct act_prob action_speculate_unit_on_tile(action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct tile *target_tile, const struct extra_type *target_extra)
Definition actions.c:4897
action_enabler_vector_by_number
struct requirement_vector * action_enabler_vector_by_number(const void *enabler, req_vec_num_in_item vec)
Definition actions.c:2045
action_prob_to_0_to_1_pessimist
double action_prob_to_0_to_1_pessimist(const struct act_prob ap)
Definition actions.c:5155
gen_action_name_update_cb
const char * gen_action_name_update_cb(const char *old_name)
Definition actions.c:7489
action_enablers_for_action
struct action_enabler_list * action_enablers_for_action(action_id action)
Definition actions.c:1529
action_distance_accepted
bool action_distance_accepted(const struct action *action, const int distance)
Definition actions.c:1159
action_ui_name_ruleset_var_name
const char * action_ui_name_ruleset_var_name(int act)
Definition actions.c:5760
action_get_ui_name_mnemonic
const char * action_get_ui_name_mnemonic(action_id act_id, const char *mnemonic)
Definition actions.c:1233
is_action_enabled_unit_on_extras
bool is_action_enabled_unit_on_extras(const struct civ_map *nmap, const action_id wanted_action, const struct unit *actor_unit, const struct tile *target, const struct extra_type *tgt_extra)
Definition actions.c:3370
actres.h
incite_cost
char * incite_cost
Definition comments.c:74
target_unit
struct unit struct city struct unit * target_unit
Definition dialogs_g.h:56
actor_unit
struct unit * actor_unit
Definition dialogs_g.h:55
actor
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit * actor
Definition dialogs_g.h:73
target_tile
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
target_city
struct unit struct city * target_city
Definition dialogs_g.h:56
target_extra
struct unit struct city struct unit struct tile struct extra_type * target_extra
Definition dialogs_g.h:57
fc_types.h
action_id
int action_id
Definition fc_types.h:393
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
name
const char * name
Definition inputfile.c:127
map_types.h
requirements.h
req_vec_num_in_item
signed char req_vec_num_in_item
req_vec_num_in_item a requirement vectors number in an item.
Definition requirements.h:237
specenum_gen.h
speclist.h
size
size_t size
Definition specvec.h:72
act_prob
Definition fc_types.h:1220
action_auto_perf
Definition actions.h:316
action_auto_perf::reqs
struct requirement_vector reqs
Definition actions.h:322
action_auto_perf::cause
enum action_auto_perf_cause cause
Definition actions.h:318
action_auto_perf::alternatives
action_id alternatives[MAX_NUM_ACTIONS]
Definition actions.h:326
action_enabler
Definition actions.h:165
action_enabler::ruledit_disabled
bool ruledit_disabled
Definition actions.h:172
action_enabler::action
action_id action
Definition actions.h:166
action_enabler::actor_reqs
struct requirement_vector actor_reqs
Definition actions.h:167
action_enabler::target_reqs
struct requirement_vector target_reqs
Definition actions.h:168
action
Definition actions.h:106
action::unitwaittime_controlled
bool unitwaittime_controlled
Definition actions.h:155
action::id
action_id id
Definition actions.h:107
action::actor_consuming_always
bool actor_consuming_always
Definition actions.h:139
action::rare_pop_up
bool rare_pop_up
Definition actions.h:152
action::max_distance
int max_distance
Definition actions.h:122
action::quiet
bool quiet
Definition actions.h:129
action::sub_target_kind
enum action_sub_target_kind sub_target_kind
Definition actions.h:114
action::moves_actor
enum moves_actor_kind moves_actor
Definition actions.h:159
action::is_unit
struct action::@12::@13 is_unit
action::result
enum action_result result
Definition actions.h:109
action::ui_name
char ui_name[MAX_LEN_NAME]
Definition actions.h:125
action::sub_results
bv_action_sub_results sub_results
Definition actions.h:110
action::actor_kind
enum action_actor_kind actor_kind
Definition actions.h:112
action::target_complexity
enum act_tgt_compl target_complexity
Definition actions.h:117
action::blocked_by
bv_actions blocked_by
Definition actions.h:133
action::actor
union action::@12 actor
action::target_kind
enum action_target_kind target_kind
Definition actions.h:113
action::min_distance
int min_distance
Definition actions.h:122
city
Definition city.h:320
civ_map
Definition map_types.h:71
extra_type
Definition extras.h:88
government
Definition government.h:52
player
Definition player.h:249
req_vec_problem
Definition requirements.h:295
tile
Definition tile.h:50
unit_type
Definition unittype.h:507
unit
Definition unit.h:140
universal
Definition fc_types.h:878