Freeciv-3.3
Loading...
Searching...
No Matches
handicaps.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "shared.h"
20
21/* common */
22#include "player.h"
23
24#include "handicaps.h"
25
26/**********************************************************************/
29void handicaps_init(struct player *pplayer)
30{
31 if (pplayer->ai_common.handicaps != NULL) {
32 return;
33 }
34
35 pplayer->ai_common.handicaps = fc_malloc(sizeof(bv_handicap));
37}
38
39/**********************************************************************/
42void handicaps_close(struct player *pplayer)
43{
44 if (pplayer->ai_common.handicaps == NULL) {
45 return;
46 }
47
48 free(pplayer->ai_common.handicaps);
49 pplayer->ai_common.handicaps = NULL;
50}
51
52/**********************************************************************/
55void handicaps_set(struct player *pplayer, bv_handicap handicaps)
56{
57 *((bv_handicap *)pplayer->ai_common.handicaps) = handicaps;
58}
59
60/**********************************************************************/
66bool has_handicap(const struct player *pplayer, enum handicap_type htype)
67{
68 if (is_human(pplayer)) {
69 return TRUE;
70 }
71
72 return BV_ISSET(*((bv_handicap *)pplayer->ai_common.handicaps), htype);
73}
74
75/**********************************************************************/
80const char *handicap_desc(enum handicap_type htype, bool *inverted)
81{
82 *inverted = FALSE;
83
84 switch (htype) {
85 case H_DIPLOMAT:
86 return _("Doesn't build offensive diplomatic units.");
87 case H_AWAY:
88 return NULL; /* AI_LEVEL_AWAY has its own description */
89 case H_LIMITEDHUTS:
90 return _("Gets reduced bonuses from huts.");
91 case H_DEFENSIVE:
92 return _("Prefers defensive buildings and avoids close diplomatic "
93 "relations.");
94 case H_EXPERIMENTAL:
95 return _("THIS IS ONLY FOR TESTING OF NEW AI FEATURES! For ordinary "
96 "servers, this level is no different to 'Hard'.");
97 case H_RATES:
98 *inverted = TRUE;
99 return _("Has no restrictions on tax rates.");
100 case H_TARGETS:
101 *inverted = TRUE;
102 return _("Can target units and cities in unseen or unexplored territory.");
103 case H_HUTS:
104 *inverted = TRUE;
105 return _("Knows the location of huts in unexplored territory.");
106 case H_FOG:
107 *inverted = TRUE;
108 return _("Can see through fog of war.");
109 case H_NOPLANES:
110 return _("Doesn't build air units.");
111 case H_MAP:
112 *inverted = TRUE;
113 return _("Has complete map knowledge, including unexplored territory.");
114 case H_DIPLOMACY:
115 return _("Naive at diplomacy.");
116 case H_REVOLUTION:
117 *inverted = TRUE;
118 return _("Can skip anarchy during revolution.");
119 case H_EXPANSION:
120 return _("Limits growth to match human players.");
121 case H_DANGER:
122 return _("Believes its cities are always under threat.");
123 case H_CEASEFIRE:
124 return _("Always offers cease-fire on first contact.");
125 case H_NOBRIBE_WF:
126 return _("Doesn't bribe worker or city founder units.");
127 case H_PRODCHGPEN:
128 *inverted = TRUE;
129 return _("Can change city production type without penalty.");
131 return _("Limits the distance to search for threatening enemy units.");
132 case H_LAST:
133 break; /* fall through -- should never see this */
134 }
135
136 /* Should never reach here */
138
139 return NULL;
140}
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
char * incite_cost
Definition comments.c:76
#define _(String)
Definition fcintl.h:67
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
void handicaps_init(struct player *pplayer)
Definition handicaps.c:29
void handicaps_close(struct player *pplayer)
Definition handicaps.c:42
const char * handicap_desc(enum handicap_type htype, bool *inverted)
Definition handicaps.c:80
void handicaps_set(struct player *pplayer, bv_handicap handicaps)
Definition handicaps.c:55
handicap_type
Definition handicaps.h:17
@ H_LAST
Definition handicaps.h:37
@ H_MAP
Definition handicaps.h:28
@ H_REVOLUTION
Definition handicaps.h:30
@ H_DIPLOMACY
Definition handicaps.h:29
@ H_DIPLOMAT
Definition handicaps.h:18
@ H_TARGETS
Definition handicaps.h:24
@ H_LIMITEDHUTS
Definition handicaps.h:20
@ H_RATES
Definition handicaps.h:23
@ H_AWAY
Definition handicaps.h:19
@ H_HUTS
Definition handicaps.h:25
@ H_EXPERIMENTAL
Definition handicaps.h:22
@ H_DEFENSIVE
Definition handicaps.h:21
@ H_DANGER
Definition handicaps.h:32
@ H_NOBRIBE_WF
Definition handicaps.h:34
@ H_NOPLANES
Definition handicaps.h:27
@ H_FOG
Definition handicaps.h:26
@ H_PRODCHGPEN
Definition handicaps.h:35
@ H_EXPANSION
Definition handicaps.h:31
@ H_CEASEFIRE
Definition handicaps.h:33
@ H_ASSESS_DANGER_LIMITED
Definition handicaps.h:36
#define fc_assert(condition)
Definition log.h:177
#define fc_malloc(sz)
Definition mem.h:34
#define is_human(plr)
Definition player.h:231
void * handicaps
Definition player.h:115
struct player_ai ai_common
Definition player.h:288
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47