Freeciv-3.2: /fast/freeciv/nightly/S3_2/ai/aitraits.c Source File

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/**********************************************************************/
33 void 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/**********************************************************************/
59 void ai_traits_close(struct player *pplayer)
60{
61 FC_FREE(pplayer->ai_common.traits);
62
63 pplayer->ai_common.traits = NULL;
64}
65
66/**********************************************************************/
69 int 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}
ai_traits_init
void ai_traits_init(struct player *pplayer)
Definition aitraits.c:33
ai_trait_get_value
int ai_trait_get_value(enum trait tr, struct player *pplayer)
Definition aitraits.c:69
ai_traits_close
void ai_traits_close(struct player *pplayer)
Definition aitraits.c:59
aitraits.h
TDM_FIXED
@ TDM_FIXED
Definition fc_types.h:1045
TDM_EVEN
@ TDM_EVEN
Definition fc_types.h:1046
game
struct civ_game game
Definition game.c:62
game.h
mem.h
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_realloc
#define fc_realloc(ptr, sz)
Definition mem.h:36
nation.h
player.h
rand.h
fc_rand
#define fc_rand(_size)
Definition rand.h:56
CLIP
#define CLIP(lower, current, upper)
Definition shared.h:57
ai_trait
Definition traits.h:37
ai_trait::val
int val
Definition traits.h:38
ai_trait::mod
int mod
Definition traits.h:39
civ_game::trait_dist
enum trait_dist_mode trait_dist
Definition game.h:165
civ_game::server
struct civ_game::@31::@35 server
nation_type::traits
struct trait_limits * traits
Definition nation.h:145
nation_type::server
struct nation_type::@51::@53 server
player_ai::traits
struct ai_trait * traits
Definition player.h:124
player
Definition player.h:247
player::ai_common
struct player_ai ai_common
Definition player.h:286
player::nation
struct nation_type * nation
Definition player.h:258
trait_limits::fixed
int fixed
Definition traits.h:46
trait_limits::min
int min
Definition traits.h:44
trait_limits::max
int max
Definition traits.h:45
traits.h
TRAIT_MAX_VALUE
#define TRAIT_MAX_VALUE
Definition traits.h:33