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)
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 ***********************************************************************/
15 #include <fc_config.h>
24 #include "handicaps.h"
26 /**************************************************************************
27 Initialize handicaps for player
28 **************************************************************************/
29 void handicaps_init(struct player
*pplayer
)
31 if (pplayer
->ai_common
.handicaps
!= NULL
) {
35 pplayer
->ai_common
.handicaps
= fc_malloc(sizeof(bv_handicap
));
36 BV_CLR_ALL(*((bv_handicap
*)pplayer
->ai_common
.handicaps
));
39 /**************************************************************************
40 Free resources associated with player handicaps.
41 **************************************************************************/
42 void handicaps_close(struct player
*pplayer
)
44 if (pplayer
->ai_common
.handicaps
== NULL
) {
48 free(pplayer
->ai_common
.handicaps
);
49 pplayer
->ai_common
.handicaps
= NULL
;
52 /**************************************************************************
54 **************************************************************************/
55 void handicaps_set(struct player
*pplayer
, bv_handicap handicaps
)
57 *((bv_handicap
*)pplayer
->ai_common
.handicaps
) = handicaps
;
60 /**************************************************************************
61 AI players may have handicaps - allowing them to cheat or preventing
62 them from using certain algorithms. This function returns whether the
63 player has the given handicap. Human players are assumed to have no
65 **************************************************************************/
66 bool has_handicap(const struct player
*pplayer
, enum handicap_type htype
)
68 if (!pplayer
->ai_controlled
) {
71 return BV_ISSET(*((bv_handicap
*)pplayer
->ai_common
.handicaps
), htype
);