Freeciv21
Develop your civilization from humble roots to a global empire
cm.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 // common
13 #include "city.h" // CITY_MAP_MAX_SIZE
14 
15 // A description of the goal.
16 struct cm_parameter {
18  bool max_growth;
22 
23  int factor[O_LAST];
25 
31  cm_parameter &operator=(const cm_parameter &other) = default;
32 };
33 
34 // A result which can examined.
35 struct cm_result {
36  bool aborted;
38 
40 
42  std::vector<bool> worker_positions;
44 
45  ~cm_result() = default;
46 };
47 
48 void cm_init();
49 void cm_init_citymap();
50 void cm_free();
51 
52 std::unique_ptr<cm_result> cm_result_new(struct city *pcity);
53 
54 /*
55  * Will try to meet the requirements and fill out the result. Caller
56  * should test result->found_a_valid. cm_query_result() will not change
57  * the actual city setting.
58  */
59 void cm_query_result(struct city *pcity,
60  const struct cm_parameter *const parameter,
61  std::unique_ptr<cm_result> &result, bool negative_ok);
62 
63 /***************** utility methods *************************************/
64 bool operator==(const struct cm_parameter &p1,
65  const struct cm_parameter &p2);
66 void cm_copy_parameter(struct cm_parameter *dest,
67  const struct cm_parameter *const src);
68 void cm_init_parameter(struct cm_parameter *dest);
69 void cm_init_emergency_parameter(struct cm_parameter *dest);
70 
71 void cm_print_city(const struct city *pcity);
72 void cm_print_result(const std::unique_ptr<cm_result> &result);
73 
74 int cm_result_citizens(const std::unique_ptr<cm_result> &result);
75 int cm_result_specialists(const std::unique_ptr<cm_result> &result);
76 int cm_result_workers(const std::unique_ptr<cm_result> &result);
77 
78 void cm_result_from_main_map(std::unique_ptr<cm_result> &result,
79  const struct city *pcity);
void cm_init()
Initialize the CM data at the start of each game.
Definition: cm.cpp:288
void cm_query_result(struct city *pcity, const struct cm_parameter *const parameter, std::unique_ptr< cm_result > &result, bool negative_ok)
Wrapper that actually runs the branch & bound, and returns the best solution.
Definition: cm.cpp:2115
void cm_copy_parameter(struct cm_parameter *dest, const struct cm_parameter *const src)
Copy the parameter from the source to the destination field.
Definition: cm.cpp:2163
void cm_free()
Called at the end of a game to free any CM data.
Definition: cm.cpp:315
void cm_init_parameter(struct cm_parameter *dest)
Initialize the parameter to sane default values.
Definition: cm.cpp:2172
int cm_result_citizens(const std::unique_ptr< cm_result > &result)
Count the total number of citizens in the result.
Definition: cm.cpp:2246
bool operator==(const struct cm_parameter &p1, const struct cm_parameter &p2)
Definition: cm.cpp:2129
void cm_result_from_main_map(std::unique_ptr< cm_result > &result, const struct city *pcity)
Copy the city's current setup into the cm result structure.
Definition: cm.cpp:2255
void cm_init_citymap()
Initialize the CM citymap data.
Definition: cm.cpp:307
int cm_result_workers(const std::unique_ptr< cm_result > &result)
Count the total number of workers in the result.
Definition: cm.cpp:2211
std::unique_ptr< cm_result > cm_result_new(struct city *pcity)
Create a new cm_result.
Definition: cm.cpp:330
void cm_init_emergency_parameter(struct cm_parameter *dest)
Initialize the parameter to sane default values that will always produce a result.
Definition: cm.cpp:2192
void cm_print_result(const std::unique_ptr< cm_result > &result)
Print debugging information about a full CM result.
Definition: cm.cpp:2472
void cm_print_city(const struct city *pcity)
Debugging routines.
Definition: cm.cpp:2432
int cm_result_specialists(const std::unique_ptr< cm_result > &result)
Count the total number of specialists in the result.
Definition: cm.cpp:2233
unsigned char citizens
Definition: fc_types.h:305
#define SP_MAX
Definition: fc_types.h:324
@ O_LAST
Definition: fc_types.h:91
Definition: city.h:291
bool allow_disorder
Definition: cm.h:20
cm_parameter & operator=(const cm_parameter &other)=default
Copy assignment operator.
int factor[O_LAST]
Definition: cm.h:23
bool max_growth
Definition: cm.h:18
bool allow_specialists
Definition: cm.h:21
bool require_happy
Definition: cm.h:19
int minimal_surplus[O_LAST]
Definition: cm.h:17
int happy_factor
Definition: cm.h:24
Definition: cm.h:35
bool found_a_valid
Definition: cm.h:37
bool disorder
Definition: cm.h:37
bool aborted
Definition: cm.h:36
~cm_result()=default
int surplus[O_LAST]
Definition: cm.h:39
bool happy
Definition: cm.h:37
std::vector< bool > worker_positions
Definition: cm.h:42
int city_radius_sq
Definition: cm.h:41
citizens specialists[SP_MAX]
Definition: cm.h:43