Freeciv-3.3
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 "nation.h"
25#include "player.h"
26#include "traits.h"
27
28#include "aitraits.h"
29
30/**********************************************************************/
33void ai_traits_init(struct player *pplayer)
34{
35 enum trait tr;
36
37 pplayer->ai_common.traits = fc_realloc(pplayer->ai_common.traits,
38 sizeof(struct ai_trait) * TRAIT_COUNT);
39
40 for (tr = trait_begin(); tr != trait_end(); tr = trait_next(tr)) {
41 int min = pplayer->nation->server.traits[tr].min;
42 int max = pplayer->nation->server.traits[tr].max;
43
44 switch (game.server.trait_dist) {
45 case TDM_FIXED:
46 pplayer->ai_common.traits[tr].val = pplayer->nation->server.traits[tr].fixed;
47 break;
48 case TDM_EVEN:
49 pplayer->ai_common.traits[tr].val = fc_rand(max + 1 - min) + min;
50 break;
51 }
52 pplayer->ai_common.traits[tr].mod = 0;
53 }
54}
55
56/**********************************************************************/
59void ai_traits_close(struct player *pplayer)
60{
61 free(pplayer->ai_common.traits);
62 pplayer->ai_common.traits = nullptr;
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:33
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:59
@ TDM_FIXED
Definition fc_types.h:752
@ TDM_EVEN
Definition fc_types.h:753
struct civ_game game
Definition game.c:61
#define fc_realloc(ptr, sz)
Definition mem.h:36
#define fc_rand(_size)
Definition rand.h:56
#define CLIP(lower, current, upper)
Definition shared.h:57
int val
Definition traits.h:38
int mod
Definition traits.h:39
enum trait_dist_mode trait_dist
Definition game.h:172
struct civ_game::@32::@36 server
struct trait_limits * traits
Definition nation.h:145
struct nation_type::@54::@56 server
struct ai_trait * traits
Definition player.h:126
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