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>
29 /**************************************************************************
30 Initialize ai traits for player
31 **************************************************************************/
32 void ai_traits_init(struct player
*pplayer
)
36 pplayer
->ai_common
.traits
= fc_realloc(pplayer
->ai_common
.traits
,
37 sizeof(struct ai_trait
) * TRAIT_COUNT
);
39 for (tr
= trait_begin(); tr
!= trait_end(); tr
= trait_next(tr
)) {
40 int min
= pplayer
->nation
->server
.traits
[tr
].min
;
41 int max
= pplayer
->nation
->server
.traits
[tr
].max
;
43 switch (game
.server
.trait_dist
) {
45 pplayer
->ai_common
.traits
[tr
].val
= pplayer
->nation
->server
.traits
[tr
].fixed
;
48 pplayer
->ai_common
.traits
[tr
].val
= fc_rand(max
+ 1 - min
) + min
;
51 pplayer
->ai_common
.traits
[tr
].mod
= 0;
55 /**************************************************************************
56 Free resources associated with player ai traits.
57 **************************************************************************/
58 void ai_traits_close(struct player
*pplayer
)
60 FC_FREE(pplayer
->ai_common
.traits
);
62 pplayer
->ai_common
.traits
= NULL
;
65 /**************************************************************************
66 Get current value of player trait
67 **************************************************************************/
68 int ai_trait_get_value(enum trait tr
, struct player
*pplayer
)
70 int val
= pplayer
->ai_common
.traits
[tr
].val
+ pplayer
->ai_common
.traits
[tr
].mod
;
72 /* Clip so that value is at least 1, and maximum is
73 * TRAIT_DEFAULT_VALUE as many times as TRAIT_DEFAULT value is
74 * minimum value of 1 ->
75 * minimum is default / TRAIT_DEFAULT_VALUE,
76 * maximum is default * TRAIT_DEFAULT_VALUE */
77 val
= CLIP(1, val
, TRAIT_MAX_VALUE
);