Freeciv21
Develop your civilization from humble roots to a global empire
governor.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
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 #include "attribute.h"
14 
15 #include <set>
16 
17 class governor {
18 public:
20  static governor *i();
21  static void drop();
22  bool hot() { return superhot > 0; };
23  void freeze() { --superhot; };
24  void unfreeze()
25  {
26  ++superhot;
27  run();
28  };
29  void add_city_changed(struct city *pcity);
30  void add_city_new(struct city *pcity);
31  void add_city_remove(struct city *pcity);
32 
33 private:
34  governor() { superhot = 1; };
35  void run();
37  std::set<int> scity_changed;
38  std::set<int> scity_remove;
39  int superhot;
40 };
41 
42 void cma_put_city_under_agent(struct city *pcity,
43  const struct cm_parameter *const parameter);
44 void cma_release_city(struct city *pcity);
45 bool cma_is_city_under_agent(const struct city *pcity,
46  struct cm_parameter *parameter);
47 
48 /***************** utility methods *************************************/
49 bool cma_get_parameter(enum attr_city attr, int city_id,
50  struct cm_parameter *parameter);
51 void cma_set_parameter(enum attr_city attr, int city_id,
52  const struct cm_parameter *parameter);
53 
55 void cma_got_result(int);
56 
57 void cmafec_set_fe_parameter(struct city *pcity,
58  const struct cm_parameter *const parameter);
59 void cmafec_get_fe_parameter(struct city *pcity, struct cm_parameter *dest);
60 
61 const char *
62 cmafec_get_short_descr(const struct cm_parameter *const parameter);
63 const char *cmafec_get_short_descr_of_city(const struct city *pcity);
64 
65 /*
66  * Preset handling
67  */
68 void cmafec_preset_add(const char *descr_name, const cm_parameter *pparam);
69 void cmafec_preset_remove(int idx);
71  const struct cm_parameter *const parameter);
72 char *cmafec_preset_get_descr(int idx);
73 const struct cm_parameter *cmafec_preset_get_parameter(int idx);
74 int cmafec_preset_num();
attr_city
Definition: attribute.h:21
static void drop()
Definition: governor.cpp:98
static governor * m_instance
Definition: governor.h:36
void add_city_remove(struct city *pcity)
Definition: governor.cpp:128
int superhot
Definition: governor.h:39
std::set< int > scity_remove
Definition: governor.h:38
void add_city_changed(struct city *pcity)
Definition: governor.cpp:116
std::set< int > scity_changed
Definition: governor.h:37
governor()
Definition: governor.h:34
static governor * i()
Definition: governor.cpp:107
void add_city_new(struct city *pcity)
Definition: governor.cpp:122
void run()
Definition: governor.cpp:135
void unfreeze()
Definition: governor.h:24
void freeze()
Definition: governor.h:23
bool hot()
Definition: governor.h:22
int cities_results_request()
Definition: governor.cpp:204
void cma_got_result(int)
Definition: governor.cpp:206
const char * cmafec_get_short_descr_of_city(const struct city *pcity)
Return short description of city governor preset.
Definition: governor.cpp:774
void cmafec_set_fe_parameter(struct city *pcity, const struct cm_parameter *const parameter)
Sets the front-end parameter.
Definition: governor.cpp:663
int cmafec_preset_num()
Returns the total number of presets.
Definition: governor.cpp:769
const struct cm_parameter * cmafec_preset_get_parameter(int idx)
Returns the indexed preset's parameter.
Definition: governor.cpp:738
bool cma_is_city_under_agent(const struct city *pcity, struct cm_parameter *parameter)
Check whether city is under governor control, and fill parameter if it is.
Definition: governor.cpp:632
void create_default_cma_presets()
Create default cma presets for a new user (or without configuration file)
Definition: governor.cpp:804
char * cmafec_preset_get_descr(int idx)
Returns the indexed preset's description.
Definition: governor.cpp:725
void cma_put_city_under_agent(struct city *pcity, const struct cm_parameter *const parameter)
Put city under governor control.
Definition: governor.cpp:618
int cmafec_preset_get_index_of_parameter(const struct cm_parameter *const parameter)
Returns the index of the preset which matches the given parameter.
Definition: governor.cpp:752
const char * cmafec_get_short_descr(const struct cm_parameter *const parameter)
Returns the description of the matching preset or "custom" if no preset could be found.
Definition: governor.cpp:790
void cmafec_preset_remove(int idx)
Removes a preset.
Definition: governor.cpp:709
bool cma_get_parameter(enum attr_city attr, int city_id, struct cm_parameter *parameter)
Get the parameter.
Definition: governor.cpp:645
void cma_release_city(struct city *pcity)
Release city from governor control.
Definition: governor.cpp:627
void cma_set_parameter(enum attr_city attr, int city_id, const struct cm_parameter *parameter)
Set attribute block for city from parameter.
Definition: governor.cpp:654
void cmafec_preset_add(const char *descr_name, const cm_parameter *pparam)
Adds a preset.
Definition: governor.cpp:692
void cmafec_get_fe_parameter(struct city *pcity, struct cm_parameter *dest)
Return the front-end parameter for the given city.
Definition: governor.cpp:673
Definition: city.h:291