Freeciv21
Develop your civilization from humble roots to a global empire
handicaps.cpp
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 
14 #include <QBitArray>
15 // utility
16 #include "shared.h"
17 
18 // common
19 #include "player.h"
20 
21 #include "handicaps.h"
22 
26 void handicaps_init(struct player *pplayer)
27 {
28  if (pplayer->ai_common.handicaps != nullptr) {
29  return;
30  }
31  pplayer->ai_common.handicaps = new QBitArray(H_LAST);
32 }
33 
37 void handicaps_close(struct player *pplayer)
38 {
39  if (pplayer->ai_common.handicaps == nullptr) {
40  return;
41  }
42 
43  delete pplayer->ai_common.handicaps;
44  pplayer->ai_common.handicaps = nullptr;
45 }
46 
50 void handicaps_set(struct player *pplayer, QBitArray *handicaps)
51 {
52  *(pplayer->ai_common.handicaps) = *handicaps;
53  delete handicaps;
54 }
55 
62 bool has_handicap(const struct player *pplayer, enum handicap_type htype)
63 {
64  if (is_human(pplayer)) {
65  return true;
66  }
67 
68  return pplayer->ai_common.handicaps->at(htype);
69 }
70 
76 const char *handicap_desc(enum handicap_type htype, bool *inverted)
77 {
78  *inverted = false;
79  switch (htype) {
80  case H_DIPLOMAT:
81  return _("Doesn't build offensive diplomatic units.");
82  case H_AWAY:
83  return nullptr; // AI_LEVEL_AWAY has its own description
84  case H_LIMITEDHUTS:
85  return _("Gets reduced bonuses from huts.");
86  case H_DEFENSIVE:
87  return _("Prefers defensive buildings and avoids close diplomatic "
88  "relations.");
89  case H_EXPERIMENTAL:
90  return _("THIS IS ONLY FOR TESTING OF NEW AI FEATURES! For ordinary "
91  "servers, this level is no different to 'Hard'.");
92  case H_RATES:
93  *inverted = true;
94  return _("Has no restrictions on national budget.");
95  case H_TARGETS:
96  *inverted = true;
97  return _(
98  "Can target units and cities in unseen or unexplored territory.");
99  case H_HUTS:
100  *inverted = true;
101  return _("Knows the location of huts in unexplored territory.");
102  case H_FOG:
103  *inverted = true;
104  return _("Can see through fog of war.");
105  case H_NOPLANES:
106  return _("Doesn't build air units.");
107  case H_MAP:
108  *inverted = true;
109  return _("Has complete map knowledge, including unexplored territory.");
110  case H_DIPLOMACY:
111  return _("Naive at diplomacy.");
112  case H_REVOLUTION:
113  *inverted = true;
114  return _("Can skip anarchy during revolution.");
115  case H_EXPANSION:
116  return _("Limits growth to match human players.");
117  case H_DANGER:
118  return _("Believes its cities are always under threat.");
119  case H_CEASEFIRE:
120  return _("Always offers cease-fire on first contact.");
121  case H_NOBRIBE_WF:
122  return _("Doesn't bribe worker or city founder units.");
123  case H_PRODCHGPEN:
124  *inverted = true;
125  return _("Can change city production type without penalty.");
126 #ifdef FREECIV_WEB
127  case H_ASSESS_DANGER_LIMITED:
128  return _("Limits the distance to search for threatening enemy units.");
129 #endif
130  case H_LAST:
131  break; // fall through -- should never see this
132  }
133 
134  // Should never reach here
135  fc_assert(false);
136  return nullptr;
137 }
#define _(String)
Definition: fcintl.h:50
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
AI players may have handicaps - allowing them to cheat or preventing them from using certain algorith...
Definition: handicaps.cpp:62
void handicaps_set(struct player *pplayer, QBitArray *handicaps)
Set player handicaps.
Definition: handicaps.cpp:50
const char * handicap_desc(enum handicap_type htype, bool *inverted)
Return a short (translated) string describing the handicap, for help.
Definition: handicaps.cpp:76
void handicaps_init(struct player *pplayer)
Initialize handicaps for player.
Definition: handicaps.cpp:26
void handicaps_close(struct player *pplayer)
Free resources associated with player handicaps.
Definition: handicaps.cpp:37
handicap_type
Definition: handicaps.h:16
@ H_LAST
Definition: handicaps.h:35
@ H_MAP
Definition: handicaps.h:27
@ H_REVOLUTION
Definition: handicaps.h:29
@ H_DIPLOMACY
Definition: handicaps.h:28
@ H_DIPLOMAT
Definition: handicaps.h:17
@ H_TARGETS
Definition: handicaps.h:23
@ H_LIMITEDHUTS
Definition: handicaps.h:19
@ H_RATES
Definition: handicaps.h:22
@ H_AWAY
Definition: handicaps.h:18
@ H_HUTS
Definition: handicaps.h:24
@ H_EXPERIMENTAL
Definition: handicaps.h:21
@ H_DEFENSIVE
Definition: handicaps.h:20
@ H_DANGER
Definition: handicaps.h:31
@ H_NOBRIBE_WF
Definition: handicaps.h:33
@ H_NOPLANES
Definition: handicaps.h:26
@ H_FOG
Definition: handicaps.h:25
@ H_PRODCHGPEN
Definition: handicaps.h:34
@ H_EXPANSION
Definition: handicaps.h:30
@ H_CEASEFIRE
Definition: handicaps.h:32
#define fc_assert(condition)
Definition: log.h:89
#define is_human(plr)
Definition: player.h:226
QBitArray * handicaps
Definition: player.h:108
Definition: player.h:231
struct player_ai ai_common
Definition: player.h:270