Freeciv21
Develop your civilization from humble roots to a global empire
advdata.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can redistribute it
4  and/or modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation, either version 3 of the
6  License, or (at your option) any later version. You should have received
7  a copy of the GNU General Public License along with Freeciv21. If not,
8  see https://www.gnu.org/licenses/.
9 **************************************************************************/
10 #pragma once
11 
12 // utility
13 #include "bitvector.h"
14 #include "support.h" // bool type
15 
16 // common
17 #include "fc_types.h"
18 #include "improvement.h"
19 
20 /* server/advisors */
21 #include "advtools.h"
22 
23 /*
24  * This file and advdata.c contains global data structures for the AI
25  * and some of the functions that fill them with useful values at the
26  * start of every turn.
27  */
28 
30  ADV_IMPR_CALCULATE, // Calculate exactly its effect
31  ADV_IMPR_CALCULATE_FULL, // Calculate including tile changes
32  ADV_IMPR_ESTIMATE, // Estimate its effect using wild guesses
34 };
35 
36 struct adv_dipl {
37  // Remember one example of each for text spam purposes.
39 };
40 
41 struct adv_data {
42  // Whether adv_data_phase_init() has been called or not.
44 
45  // The Wonder City
47 
48  // Precalculated info about city improvements
50  enum req_range impr_range[B_LAST];
51 
52  // Long-term threats, not to be confused with short-term danger
53  struct {
54  bool invasions; // check if we need to consider invasions
55  bool *continent; // non-allied cities on continent?
56  bool *ocean; // non-allied offensive ships in ocean?
57  bool suicide_attack; // check for non-allied missiles
58  int nuclear; // nuke check: 0=no, 1=capability, 2=built
59  bool igwall; // enemies have igwall units
61 
62  // Keeps track of which continents are fully explored already
63  struct {
64  bool *ocean; // are we done exploring this ocean?
65  bool *continent; // are we done exploring this continent?
66  bool land_done; // nothing more on land to explore anywhere
67  bool sea_done; // nothing more to explore at sea
69 
70  /* This struct is used for statistical unit building, eg to ensure
71  * that we don't build too few or too many units of a given type. */
72  struct {
73  // Counts of specific types of units.
74  struct {
75  // Unit-flag counts.
77 
78  // Unit can do action counts.
80 
82 
83  // Upgradeable units
85  } units;
86  int *cities; // Number of cities we have on continent
87  int *ocean_cities; // Number of cities we have on ocean
89  } stats;
90 
91  struct {
93 
94  struct player *spacerace_leader; // who is leading the space pack
96  } dipl;
97 
98  int num_continents; // last time we updated our continent data
99  int num_oceans; // last time we updated our continent data
100 
101  // Dynamic weights used in addition to Syela's hardcoded weights
112 
113  // Government data
114  std::vector<adv_want> government_want;
115  short govt_reeval;
116 
117  // Goals
118  struct {
119  struct {
120  struct government *gov; // The ideal government
121  adv_want val; // Its value (relative to the current gov)
122  int req; // The tech requirement for the ideal gov
123  } govt;
124  struct government *revolution; // The best gov of the now available
125  } goal;
126 
127  // Whether science would benefit player at all
129 
130  // If the AI celebrates.
131  bool celebrate;
132 
133  // AI doesn't like having more than this number of cities
135 };
136 
137 void adv_data_init(struct player *pplayer);
138 void adv_data_default(struct player *pplayer);
139 void adv_data_close(struct player *pplayer);
140 
141 bool adv_data_phase_init(struct player *pplayer, bool is_new_phase);
142 void adv_data_phase_done(struct player *pplayer);
143 
144 void adv_data_analyze_rulesets(struct player *pplayer);
145 
146 struct adv_data *adv_data_get(struct player *pplayer, bool *close);
147 
148 void adv_best_government(struct player *pplayer);
149 
150 bool adv_wants_science(struct player *pplayer);
151 
152 bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer);
void adv_data_analyze_rulesets(struct player *pplayer)
Analyze rulesets.
Definition: advdata.cpp:194
void adv_data_close(struct player *pplayer)
Free memory for advisor data.
Definition: advdata.cpp:739
void adv_data_init(struct player *pplayer)
Allocate memory for advisor data.
Definition: advdata.cpp:685
bool adv_wants_science(struct player *pplayer)
Return whether science would help us at all.
Definition: advdata.cpp:1051
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Make and cache lots of calculations needed for other functions.
Definition: advdata.cpp:250
void adv_data_phase_done(struct player *pplayer)
Clean up our mess.
Definition: advdata.cpp:556
bool adv_is_player_dangerous(struct player *pplayer, struct player *aplayer)
There are some signs that a player might be dangerous: We are at war with him, he has done lots of ig...
Definition: advdata.cpp:1062
struct adv_data * adv_data_get(struct player *pplayer, bool *close)
Return a pointer to our data.
Definition: advdata.cpp:591
void adv_best_government(struct player *pplayer)
Find best government to aim for.
Definition: advdata.cpp:816
void adv_data_default(struct player *pplayer)
Initialize with sane values.
Definition: advdata.cpp:720
adv_improvement_status
Definition: advdata.h:29
@ ADV_IMPR_CALCULATE_FULL
Definition: advdata.h:31
@ ADV_IMPR_LAST
Definition: advdata.h:33
@ ADV_IMPR_ESTIMATE
Definition: advdata.h:32
@ ADV_IMPR_CALCULATE
Definition: advdata.h:30
float adv_want
Definition: fc_types.h:1144
#define UCL_LAST
Definition: fc_types.h:332
#define B_LAST
Definition: improvement.h:33
bool wants_science
Definition: advdata.h:128
int req
Definition: advdata.h:122
short govt_reeval
Definition: advdata.h:115
adv_want val
Definition: advdata.h:121
int pollution_priority
Definition: advdata.h:110
int shield_priority
Definition: advdata.h:102
bool * ocean
Definition: advdata.h:56
int coast_strict
Definition: advdata.h:76
struct adv_data::@85 threats
int average_production
Definition: advdata.h:88
int * cities
Definition: advdata.h:86
int * ocean_cities
Definition: advdata.h:87
bool invasions
Definition: advdata.h:54
struct government * revolution
Definition: advdata.h:124
int infra_priority
Definition: advdata.h:111
struct adv_dipl ** adv_dipl_slots
Definition: advdata.h:92
bool igwall
Definition: advdata.h:59
struct adv_data::@87 stats
bool celebrate
Definition: advdata.h:131
int num_oceans
Definition: advdata.h:99
int unhappy_priority
Definition: advdata.h:108
int byclass[UCL_LAST]
Definition: advdata.h:81
int luxury_priority
Definition: advdata.h:104
int nuclear
Definition: advdata.h:58
int angry_priority
Definition: advdata.h:109
int upgradeable
Definition: advdata.h:84
int food_priority
Definition: advdata.h:103
int max_num_cities
Definition: advdata.h:134
int num_continents
Definition: advdata.h:98
bool suicide_attack
Definition: advdata.h:57
struct player * production_leader
Definition: advdata.h:95
struct adv_data::@89 goal
struct adv_data::@88 dipl
struct government * gov
Definition: advdata.h:120
struct adv_data::@89::@91 govt
int airliftable
Definition: advdata.h:79
int happy_priority
Definition: advdata.h:107
struct adv_data::@87::@90 units
bool * continent
Definition: advdata.h:55
bool sea_done
Definition: advdata.h:67
enum adv_improvement_status impr_calc[B_LAST]
Definition: advdata.h:49
int suicide_attackers
Definition: advdata.h:79
bool phase_is_initialized
Definition: advdata.h:43
int wonder_city
Definition: advdata.h:46
std::vector< adv_want > government_want
Definition: advdata.h:114
enum req_range impr_range[B_LAST]
Definition: advdata.h:50
int science_priority
Definition: advdata.h:106
int gold_priority
Definition: advdata.h:105
bool land_done
Definition: advdata.h:66
int paratroopers
Definition: advdata.h:79
struct adv_data::@86 explore
struct player * spacerace_leader
Definition: advdata.h:94
bool allied_with_enemy
Definition: advdata.h:38
Definition: player.h:231