Freeciv-3.1
Loading...
Searching...
No Matches
aitraits.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 "mem.h"
20#include "rand.h"
21
22/* common */
23#include "game.h"
24#include "player.h"
25#include "traits.h"
26
27#include "aitraits.h"
28
29/**********************************************************************/
32void ai_traits_init(struct player *pplayer)
33{
34 enum trait tr;
35
36 pplayer->ai_common.traits = fc_realloc(pplayer->ai_common.traits,
37 sizeof(struct ai_trait) * TRAIT_COUNT);
38
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;
42
43 switch (game.server.trait_dist) {
44 case TDM_FIXED:
45 pplayer->ai_common.traits[tr].val = pplayer->nation->server.traits[tr].fixed;
46 break;
47 case TDM_EVEN:
48 pplayer->ai_common.traits[tr].val = fc_rand(max + 1 - min) + min;
49 break;
50 }
51 pplayer->ai_common.traits[tr].mod = 0;
52 }
53}
54
55/**********************************************************************/
58void ai_traits_close(struct player *pplayer)
59{
60 FC_FREE(pplayer->ai_common.traits);
61
62 pplayer->ai_common.traits = NULL;
63}
64
65/**********************************************************************/
68int ai_trait_get_value(enum trait tr, struct player *pplayer)
69{
70 int val = pplayer->ai_common.traits[tr].val + pplayer->ai_common.traits[tr].mod;
71
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);
78
79 return val;
80}
void ai_traits_init(struct player *pplayer)
Definition aitraits.c:32
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Definition aitraits.c:68
void ai_traits_close(struct player *pplayer)
Definition aitraits.c:58
@ TDM_FIXED
Definition fc_types.h:898
@ TDM_EVEN
Definition fc_types.h:899
struct civ_game game
Definition game.c:57
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_realloc(ptr, sz)
Definition mem.h:36
#define fc_rand(_size)
Definition rand.h:34
#define CLIP(lower, current, upper)
Definition shared.h:57
int val
Definition traits.h:38
int mod
Definition traits.h:39
struct civ_game::@30::@34 server
enum trait_dist_mode trait_dist
Definition game.h:164
struct trait_limits * traits
Definition nation.h:144
struct nation_type::@50::@52 server
struct ai_trait * traits
Definition player.h:132
struct player_ai ai_common
Definition player.h:288
struct nation_type * nation
Definition player.h:260
int fixed
Definition traits.h:46
#define TRAIT_MAX_VALUE
Definition traits.h:33