README.graphics typofix "form" -> "from"
[freeciv.git] / ai / handicaps.c
blob0ecedfb13f3a6ada1ce6501a1f0ee950976279e6
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.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* utility */
19 #include "shared.h"
21 /* common */
22 #include "player.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) {
32 return;
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) {
45 return;
48 free(pplayer->ai_common.handicaps);
49 pplayer->ai_common.handicaps = NULL;
52 /**************************************************************************
53 Set player handicaps
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
64 handicaps.
65 **************************************************************************/
66 bool has_handicap(const struct player *pplayer, enum handicap_type htype)
68 if (!pplayer->ai_controlled) {
69 return TRUE;
71 return BV_ISSET(*((bv_handicap *)pplayer->ai_common.handicaps), htype);