Freeciv-3.2: /fast/freeciv/nightly/S3_2/ai/handicaps.c Source File

Freeciv-3.2

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/**********************************************************************/
29 void 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));
36 BV_CLR_ALL(*((bv_handicap *)pplayer->ai_common.handicaps));
37}
38
39/**********************************************************************/
42 void 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/**********************************************************************/
55 void handicaps_set(struct player *pplayer, bv_handicap handicaps)
56{
57 *((bv_handicap *)pplayer->ai_common.handicaps) = handicaps;
58}
59
60/**********************************************************************/
66 bool 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/**********************************************************************/
80 const 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.");
130 case H_ASSESS_DANGER_LIMITED:
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 */
137 fc_assert(FALSE);
138
139 return NULL;
140}
BV_CLR_ALL
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
incite_cost
char * incite_cost
Definition comments.c:74
_
#define _(String)
Definition fcintl.h:67
has_handicap
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
Definition handicaps.c:66
handicaps_init
void handicaps_init(struct player *pplayer)
Definition handicaps.c:29
handicaps_close
void handicaps_close(struct player *pplayer)
Definition handicaps.c:42
handicap_desc
const char * handicap_desc(enum handicap_type htype, bool *inverted)
Definition handicaps.c:80
handicaps_set
void handicaps_set(struct player *pplayer, bv_handicap handicaps)
Definition handicaps.c:55
handicaps.h
handicap_type
handicap_type
Definition handicaps.h:17
H_LAST
@ H_LAST
Definition handicaps.h:37
H_MAP
@ H_MAP
Definition handicaps.h:28
H_REVOLUTION
@ H_REVOLUTION
Definition handicaps.h:30
H_DIPLOMACY
@ H_DIPLOMACY
Definition handicaps.h:29
H_DIPLOMAT
@ H_DIPLOMAT
Definition handicaps.h:18
H_TARGETS
@ H_TARGETS
Definition handicaps.h:24
H_LIMITEDHUTS
@ H_LIMITEDHUTS
Definition handicaps.h:20
H_RATES
@ H_RATES
Definition handicaps.h:23
H_AWAY
@ H_AWAY
Definition handicaps.h:19
H_HUTS
@ H_HUTS
Definition handicaps.h:25
H_EXPERIMENTAL
@ H_EXPERIMENTAL
Definition handicaps.h:22
H_DEFENSIVE
@ H_DEFENSIVE
Definition handicaps.h:21
H_DANGER
@ H_DANGER
Definition handicaps.h:32
H_NOBRIBE_WF
@ H_NOBRIBE_WF
Definition handicaps.h:34
H_NOPLANES
@ H_NOPLANES
Definition handicaps.h:27
H_FOG
@ H_FOG
Definition handicaps.h:26
H_PRODCHGPEN
@ H_PRODCHGPEN
Definition handicaps.h:35
H_EXPANSION
@ H_EXPANSION
Definition handicaps.h:31
H_CEASEFIRE
@ H_CEASEFIRE
Definition handicaps.h:33
H_ASSESS_DANGER_LIMITED
@ H_ASSESS_DANGER_LIMITED
Definition handicaps.h:36
fc_assert
#define fc_assert(condition)
Definition log.h:176
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
player.h
is_human
#define is_human(plr)
Definition player.h:229
shared.h
player_ai::handicaps
void * handicaps
Definition player.h:113
player
Definition player.h:247
player::ai_common
struct player_ai ai_common
Definition player.h:286
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47