Freeciv-3.3
Loading...
Searching...
No Matches
advchoice.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__ADVCHOICE_H
14#define FC__ADVCHOICE_H
15
16/*
17 * Uncomment ADV_CHOICE_TRACK to have choice information tracking enabled.
18 *
19 * To get the tracking information logged from specific place,
20 * then add there one of
21 * - ADV_CHOICE_LOG()
22 * - adv_choice_log_info()
23 * - adv_choice_log_int()
24 * - adv_choice_get_use().
25 *
26 * To get logging when specific choice ends as the winning one,
27 * mark it with adv_choice_mark()
28 */
29
30/* #define ADV_CHOICE_TRACK */
31
32#ifdef ADV_CHOICE_TRACK
33#define ADV_CHOICE_LOG_LEVEL LOG_NORMAL
34#endif
35
44
45struct adv_choice {
47 universals_u value; /* What the advisor wants */
48 adv_want want; /* How much it wants it */
49 bool need_boat; /* Unit being built wants a boat */
50#ifdef ADV_CHOICE_TRACK
51 char *use;
52 bool log_if_chosen; /* If this choice ends as the winning one, log it */
53#endif /* ADV_CHOICE_TRACK */
54};
55
56void adv_init_choice(struct adv_choice *choice);
57void adv_deinit_choice(struct adv_choice *choice);
58
59struct adv_choice *adv_new_choice(void);
60void adv_free_choice(struct adv_choice *choice);
61
62struct adv_choice *adv_better_choice(struct adv_choice *first,
63 struct adv_choice *second);
64struct adv_choice *adv_better_choice_free(struct adv_choice *first,
65 struct adv_choice *second);
66
68
69const char *adv_choice_rule_name(const struct adv_choice *choice);
70
71#ifdef ADV_CHOICE_TRACK
72void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src);
73void adv_choice_set_use(struct adv_choice *choice, const char *use);
74#define adv_choice_mark(_choice) (_choice)->log_if_chosen = TRUE
75void adv_choice_log_info(struct adv_choice *choice, const char *loc1, const char *loc2);
76void adv_choice_log_int(struct adv_choice *choice, const char *loc1, int loc2);
77const char *adv_choice_get_use(const struct adv_choice *choice);
78#else /* ADV_CHOICE_TRACK */
79static inline void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src)
80{
81 if (dest != src) {
82 *dest = *src;
83 }
84}
85#define adv_choice_set_use(_choice, _use)
86#define adv_choice_mark(_choice)
87#define adv_choice_log_info(_choice, _loc1, _loc2)
88#define adv_choice_log_int(_choice, _loc1, _loc2)
89static inline const char *adv_choice_get_use(const struct adv_choice *choice)
90{
91 return "(unknown)";
92}
93#endif /* ADV_CHOICE_TRACK */
94
95#define ADV_CHOICE_LOG(_choice) adv_choice_log_int((_choice), __FILE__, __FC_LINE__)
96
97#ifdef FREECIV_NDEBUG
98#define ADV_CHOICE_ASSERT(c) /* Do nothing. */
99#else /* FREECIV_NDEBUG */
100#define ADV_CHOICE_ASSERT(c) \
101 do { \
102 if ((c).want > 0) { \
103 fc_assert((c).type > CT_NONE && (c).type < CT_LAST); \
104 if (!is_unit_choice_type((c).type)) { \
105 int _iindex = improvement_index((c).value.building); \
106 fc_assert(_iindex >= 0 && _iindex < improvement_count()); \
107 } else { \
108 int _uindex = utype_index((c).value.utype); \
109 fc_assert(_uindex >= 0 && _uindex < utype_count()); \
110 } \
111 } \
112 } while (FALSE);
113#endif /* FREECIV_NDEBUG */
114
115#endif /* FC__ADVCHOICE_H */
void adv_deinit_choice(struct adv_choice *choice)
Definition advchoice.c:46
#define adv_choice_set_use(_choice, _use)
Definition advchoice.h:85
#define adv_choice_log_int(_choice, _loc1, _loc2)
Definition advchoice.h:88
void adv_init_choice(struct adv_choice *choice)
Definition advchoice.c:31
struct adv_choice * adv_better_choice_free(struct adv_choice *first, struct adv_choice *second)
Definition advchoice.c:98
void adv_free_choice(struct adv_choice *choice)
Definition advchoice.c:71
static void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src)
Definition advchoice.h:79
choice_type
Definition advchoice.h:36
@ CT_CIVILIAN
Definition advchoice.h:39
@ CT_LAST
Definition advchoice.h:42
@ CT_DEFENDER
Definition advchoice.h:41
@ CT_ATTACKER
Definition advchoice.h:40
@ CT_NONE
Definition advchoice.h:37
@ CT_BUILDING
Definition advchoice.h:38
struct adv_choice * adv_better_choice(struct adv_choice *first, struct adv_choice *second)
Definition advchoice.c:85
static const char * adv_choice_get_use(const struct adv_choice *choice)
Definition advchoice.h:89
struct adv_choice * adv_new_choice(void)
Definition advchoice.c:59
bool is_unit_choice_type(enum choice_type type)
Definition advchoice.c:115
#define adv_choice_log_info(_choice, _loc1, _loc2)
Definition advchoice.h:87
const char * adv_choice_rule_name(const struct adv_choice *choice)
Definition advchoice.c:124
char * incite_cost
Definition comments.c:76
float adv_want
Definition fc_types.h:1063
GType type
Definition repodlgs.c:1313
enum choice_type type
Definition advchoice.h:46
adv_want want
Definition advchoice.h:48
universals_u value
Definition advchoice.h:47
bool need_boat
Definition advchoice.h:49