Freeciv21
Develop your civilization from humble roots to a global empire
advchoice.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 // Uncomment to have choice information tracked
16 // #define ADV_CHOICE_TRACK
17 
18 #ifdef ADV_CHOICE_TRACK
19 #define ADV_CHOICE_QtMsgType LOG_NORMAL
20 #endif
21 
23  CT_NONE = 0,
28  CT_LAST
29 };
30 
31 struct adv_choice {
32  enum choice_type type;
33  universals_u value; // what the advisor wants
34  adv_want want; // how much it wants it
35  bool need_boat; // unit being built wants a boat
36 #ifdef ADV_CHOICE_TRACK
37  char *use;
38  bool log_if_chosen;
39 #endif // ADV_CHOICE_TRACK
40 };
41 
42 void adv_init_choice(struct adv_choice *choice);
43 void adv_deinit_choice(struct adv_choice *choice);
44 
45 struct adv_choice *adv_new_choice();
46 void adv_free_choice(struct adv_choice *choice);
47 
48 struct adv_choice *adv_better_choice(struct adv_choice *first,
49  struct adv_choice *second);
50 struct adv_choice *adv_better_choice_free(struct adv_choice *first,
51  struct adv_choice *second);
52 
54 
55 #ifdef ADV_CHOICE_TRACK
56 void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src);
57 void adv_choice_set_use(struct adv_choice *choice, const char *use);
58 void adv_choice_log_info(struct adv_choice *choice, const char *loc1,
59  const char *loc2);
60 const char *adv_choice_get_use(const struct adv_choice *choice);
61 #else // ADV_CHOICE_TRACK
62 static inline void adv_choice_copy(struct adv_choice *dest,
63  struct adv_choice *src)
64 {
65  if (dest != src) {
66  *dest = *src;
67  }
68 }
69 #define adv_choice_set_use(_choice, _use)
70 #define adv_choice_log_info(_choice, _loc1, _loc2)
71 static inline const char *adv_choice_get_use(const struct adv_choice *choice)
72 {
73  return "(unknown)";
74 }
75 #endif // ADV_CHOICE_TRACK
76 
77 #define ADV_CHOICE_ASSERT(c) \
78  do { \
79  if ((c).want > 0) { \
80  fc_assert((c).type > CT_NONE && (c).type < CT_LAST); \
81  if (!is_unit_choice_type((c).type)) { \
82  int _iindex = improvement_index((c).value.building); \
83  fc_assert(_iindex >= 0 && _iindex < improvement_count()); \
84  } else { \
85  int _uindex = utype_index((c).value.utype); \
86  fc_assert(_uindex >= 0 && _uindex < utype_count()); \
87  } \
88  } \
89  } while (false);
void adv_deinit_choice(struct adv_choice *choice)
Clear choice without freeing it itself.
Definition: advchoice.cpp:42
#define adv_choice_set_use(_choice, _use)
Definition: advchoice.h:69
void adv_init_choice(struct adv_choice *choice)
Sets the values of the choice to initial values.
Definition: advchoice.cpp:27
struct adv_choice * adv_new_choice()
Dynamically allocate a new choice.
Definition: advchoice.cpp:55
void adv_free_choice(struct adv_choice *choice)
Free dynamically allocated choice.
Definition: advchoice.cpp:67
static void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src)
Definition: advchoice.h:62
struct adv_choice * adv_better_choice(struct adv_choice *first, struct adv_choice *second)
Return better one of the choices given.
Definition: advchoice.cpp:81
static const char * adv_choice_get_use(const struct adv_choice *choice)
Definition: advchoice.h:71
choice_type
Definition: advchoice.h:22
@ CT_CIVILIAN
Definition: advchoice.h:25
@ CT_LAST
Definition: advchoice.h:28
@ CT_DEFENDER
Definition: advchoice.h:27
@ CT_ATTACKER
Definition: advchoice.h:26
@ CT_NONE
Definition: advchoice.h:23
@ CT_BUILDING
Definition: advchoice.h:24
struct adv_choice * adv_better_choice_free(struct adv_choice *first, struct adv_choice *second)
Return better one of the choices given, and free the other.
Definition: advchoice.cpp:94
bool is_unit_choice_type(enum choice_type type)
Does choice type refer to unit.
Definition: advchoice.cpp:111
#define adv_choice_log_info(_choice, _loc1, _loc2)
Definition: advchoice.h:70
float adv_want
Definition: fc_types.h:1144
enum choice_type type
Definition: advchoice.h:32
adv_want want
Definition: advchoice.h:34
universals_u value
Definition: advchoice.h:33
bool need_boat
Definition: advchoice.h:35