Freeciv-3.2
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 FC_FREE(pplayer->ai_common.traits);
62
63 pplayer->ai_common.traits = NULL;
64}
65
66/**********************************************************************/
69int ai_trait_get_value(enum trait tr, struct player *pplayer)
70{
71 int val = pplayer->ai_common.traits[tr].val + pplayer->ai_common.traits[tr].mod;
72
73 /* Clip so that value is at least 1, and maximum is
74 * TRAIT_DEFAULT_VALUE as many times as TRAIT_DEFAULT value is
75 * minimum value of 1 ->
76 * minimum is default / TRAIT_DEFAULT_VALUE,
77 * maximum is default * TRAIT_DEFAULT_VALUE */
78 val = CLIP(1, val, TRAIT_MAX_VALUE);
79
80 return val;
81}
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:69
void ai_traits_close(struct player *pplayer)
Definition aitraits.c:59
@ TDM_FIXED
Definition fc_types.h:1044
@ TDM_EVEN
Definition fc_types.h:1045
struct civ_game game
Definition game.c:62
#define FC_FREE(ptr)
Definition mem.h:41
#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:169
struct civ_game::@31::@35 server
struct trait_limits * traits
Definition nation.h:145
struct nation_type::@51::@53 server
struct ai_trait * traits
Definition player.h:124
struct player_ai ai_common
Definition player.h:286
struct nation_type * nation
Definition player.h:258
int fixed
Definition traits.h:46
#define TRAIT_MAX_VALUE
Definition traits.h:33