Freeciv-3.2: /fast/freeciv/nightly/S3_2/server/advisors/advchoice.h Source File

Freeciv-3.2

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
36 enum choice_type {
37 CT_NONE = 0,
38 CT_BUILDING = 1,
39 CT_CIVILIAN,
40 CT_ATTACKER,
41 CT_DEFENDER,
42 CT_LAST
43};
44
45 struct adv_choice {
46 enum choice_type type;
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
67bool is_unit_choice_type(enum choice_type type);
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 */
79 static 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)
89 static 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 */
adv_deinit_choice
void adv_deinit_choice(struct adv_choice *choice)
Definition advchoice.c:46
adv_choice_set_use
#define adv_choice_set_use(_choice, _use)
Definition advchoice.h:85
adv_choice_log_int
#define adv_choice_log_int(_choice, _loc1, _loc2)
Definition advchoice.h:88
adv_init_choice
void adv_init_choice(struct adv_choice *choice)
Definition advchoice.c:31
adv_better_choice_free
struct adv_choice * adv_better_choice_free(struct adv_choice *first, struct adv_choice *second)
Definition advchoice.c:98
adv_free_choice
void adv_free_choice(struct adv_choice *choice)
Definition advchoice.c:71
adv_choice_copy
static void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src)
Definition advchoice.h:79
choice_type
choice_type
Definition advchoice.h:36
CT_CIVILIAN
@ CT_CIVILIAN
Definition advchoice.h:39
CT_LAST
@ CT_LAST
Definition advchoice.h:42
CT_DEFENDER
@ CT_DEFENDER
Definition advchoice.h:41
CT_ATTACKER
@ CT_ATTACKER
Definition advchoice.h:40
CT_NONE
@ CT_NONE
Definition advchoice.h:37
CT_BUILDING
@ CT_BUILDING
Definition advchoice.h:38
adv_better_choice
struct adv_choice * adv_better_choice(struct adv_choice *first, struct adv_choice *second)
Definition advchoice.c:85
adv_choice_get_use
static const char * adv_choice_get_use(const struct adv_choice *choice)
Definition advchoice.h:89
adv_new_choice
struct adv_choice * adv_new_choice(void)
Definition advchoice.c:59
is_unit_choice_type
bool is_unit_choice_type(enum choice_type type)
Definition advchoice.c:115
adv_choice_log_info
#define adv_choice_log_info(_choice, _loc1, _loc2)
Definition advchoice.h:87
adv_choice_rule_name
const char * adv_choice_rule_name(const struct adv_choice *choice)
Definition advchoice.c:124
incite_cost
char * incite_cost
Definition comments.c:74
adv_want
float adv_want
Definition fc_types.h:1355
type
GType type
Definition repodlgs.c:1313
adv_choice
Definition advchoice.h:45
adv_choice::type
enum choice_type type
Definition advchoice.h:46
adv_choice::want
adv_want want
Definition advchoice.h:48
adv_choice::value
universals_u value
Definition advchoice.h:47
adv_choice::need_boat
bool need_boat
Definition advchoice.h:49
universals_u
Definition fc_types.h:713