Freeciv-3.3: /fast/freeciv/nightly/main/ai/default/daiplayer.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
daiplayer.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/* common */
19#include "ai.h"
20#include "city.h"
21#include "game.h"
22#include "unit.h"
23#include "world_object.h"
24
25/* server */
26#include "citytools.h"
27
28/* ai/default */
29#include "daidata.h"
30#include "daimilitary.h"
31
32#include "daiplayer.h"
33
34/**********************************************************************/
38 void dai_player_alloc(struct ai_type *ait, struct player *pplayer)
39{
40 struct ai_plr *player_data = fc_calloc(1, sizeof(struct ai_plr));
41
42 player_set_ai_data(pplayer, ait, player_data);
43
44 dai_data_init(ait, pplayer);
45}
46
47/**********************************************************************/
50 void dai_player_free(struct ai_type *ait, struct player *pplayer)
51{
52 struct ai_plr *player_data = def_ai_player_data(pplayer, ait);
53
54 dai_data_close(ait, pplayer);
55
56 if (player_data != NULL) {
57 player_set_ai_data(pplayer, ait, NULL);
58 FC_FREE(player_data);
59 }
60}
61
62/**********************************************************************/
65 void dai_player_save(struct ai_type *ait, const char *aitstr,
66 struct player *pplayer, struct section_file *file,
67 int plrno)
68{
69 players_iterate(other) {
70 dai_player_save_relations(ait, aitstr, pplayer, other, file, plrno);
71 } players_iterate_end;
72}
73
74/**********************************************************************/
77 void dai_player_save_relations(struct ai_type *ait, const char *aitstr,
78 struct player *pplayer, struct player *other,
79 struct section_file *file, int plrno)
80{
81 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, other);
82 char buf[32];
83
84 fc_snprintf(buf, sizeof(buf), "player%d.%s%d", plrno, aitstr,
85 player_index(other));
86
87 secfile_insert_int(file, adip->spam,
88 "%s.spam", buf);
89 secfile_insert_int(file, adip->countdown,
90 "%s.countdown", buf);
91 secfile_insert_int(file, adip->war_reason,
92 "%s.war_reason", buf);
93 secfile_insert_int(file, adip->ally_patience,
94 "%s.patience", buf);
95 secfile_insert_int(file, adip->warned_about_space,
96 "%s.warn_space", buf);
97 secfile_insert_int(file, adip->asked_about_peace,
98 "%s.ask_peace", buf);
99 secfile_insert_int(file, adip->asked_about_alliance,
100 "%s.ask_alliance", buf);
101 secfile_insert_int(file, adip->asked_about_ceasefire,
102 "%s.ask_ceasefire", buf);
103}
104
105/**********************************************************************/
108 void dai_player_load(struct ai_type *ait, const char *aitstr,
109 struct player *pplayer,
110 const struct section_file *file, int plrno)
111{
112 players_iterate(other) {
113 dai_player_load_relations(ait, aitstr, pplayer, other, file, plrno);
114 } players_iterate_end;
115}
116
117/**********************************************************************/
120 void dai_player_load_relations(struct ai_type *ait, const char *aitstr,
121 struct player *pplayer, struct player *other,
122 const struct section_file *file, int plrno)
123{
124 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, other);
125 char buf[32];
126
127 fc_snprintf(buf, sizeof(buf), "player%d.%s%d", plrno, aitstr,
128 player_index(other));
129
130 adip->spam
131 = secfile_lookup_int_default(file, 0, "%s.spam", buf);
132 adip->countdown
133 = secfile_lookup_int_default(file, -1, "%s.countdown", buf);
134 adip->war_reason
135 = secfile_lookup_int_default(file, 0, "%s.war_reason", buf);
136 adip->ally_patience
137 = secfile_lookup_int_default(file, 0, "%s.patience", buf);
138 adip->warned_about_space
139 = secfile_lookup_int_default(file, 0, "%s.warn_space", buf);
140 adip->asked_about_peace
141 = secfile_lookup_int_default(file, 0, "%s.ask_peace", buf);
142 adip->asked_about_alliance
143 = secfile_lookup_int_default(file, 0, "%s.ask_alliance", buf);
144 adip->asked_about_ceasefire
145 = secfile_lookup_int_default(file, 0, "%s.ask_ceasefire", buf);
146}
147
148/**********************************************************************/
151 void dai_player_copy(struct ai_type *ait,
152 struct player *original, struct player *created)
153{
154 bool close_original;
155 bool close_created;
156 struct ai_plr *orig_data = dai_plr_data_get(ait, original, &close_original);
157 struct ai_plr *created_data = dai_plr_data_get(ait, created, &close_created);
158
159 advance_index_iterate(A_NONE, i) {
160 created_data->tech_want[i] = orig_data->tech_want[i];
161 } advance_index_iterate_end;
162
163 if (close_original) {
164 dai_data_phase_finished(ait, original);
165 }
166 if (close_created) {
167 dai_data_phase_finished(ait, created);
168 }
169}
170
171/**********************************************************************/
174 void dai_gained_control(struct ai_type *ait, struct player *pplayer)
175{
176 if (pplayer->ai_common.skill_level != AI_LEVEL_AWAY) {
177 multipliers_iterate(pmul) {
178 pplayer->multipliers[multiplier_index(pmul)].target = pmul->def;
179 } multipliers_iterate_end;
180
181 /* Clear worker tasks, some AIs (e.g. classic) does not use those */
182 city_list_iterate(pplayer->cities, pcity) {
183 clear_worker_tasks(pcity);
184 } city_list_iterate_end;
185 }
186
187 dai_assess_danger_player(ait, pplayer, &(wld.map));
188}
ai.h
city.h
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:508
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:510
clear_worker_tasks
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3582
citytools.h
incite_cost
char * incite_cost
Definition comments.c:74
dai_plr_data_get
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Definition daidata.c:308
dai_diplomacy_get
struct ai_dip_intel * dai_diplomacy_get(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Definition daidata.c:402
dai_data_init
void dai_data_init(struct ai_type *ait, struct player *pplayer)
Definition daidata.c:59
dai_data_phase_finished
void dai_data_phase_finished(struct ai_type *ait, struct player *pplayer)
Definition daidata.c:285
dai_data_close
void dai_data_close(struct ai_type *ait, struct player *pplayer)
Definition daidata.c:104
daidata.h
dai_assess_danger_player
void dai_assess_danger_player(struct ai_type *ait, struct player *pplayer, const struct civ_map *dmap)
Definition daimilitary.c:630
daimilitary.h
dai_player_alloc
void dai_player_alloc(struct ai_type *ait, struct player *pplayer)
Definition daiplayer.c:38
dai_player_save
void dai_player_save(struct ai_type *ait, const char *aitstr, struct player *pplayer, struct section_file *file, int plrno)
Definition daiplayer.c:65
dai_player_copy
void dai_player_copy(struct ai_type *ait, struct player *original, struct player *created)
Definition daiplayer.c:151
dai_player_save_relations
void dai_player_save_relations(struct ai_type *ait, const char *aitstr, struct player *pplayer, struct player *other, struct section_file *file, int plrno)
Definition daiplayer.c:77
dai_player_load
void dai_player_load(struct ai_type *ait, const char *aitstr, struct player *pplayer, const struct section_file *file, int plrno)
Definition daiplayer.c:108
dai_player_free
void dai_player_free(struct ai_type *ait, struct player *pplayer)
Definition daiplayer.c:50
dai_gained_control
void dai_gained_control(struct ai_type *ait, struct player *pplayer)
Definition daiplayer.c:174
dai_player_load_relations
void dai_player_load_relations(struct ai_type *ait, const char *aitstr, struct player *pplayer, struct player *other, const struct section_file *file, int plrno)
Definition daiplayer.c:120
daiplayer.h
def_ai_player_data
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition daiplayer.h:54
wld
struct world wld
Definition game.c:63
game.h
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
multiplier_index
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
multipliers_iterate
#define multipliers_iterate(_mul_)
Definition multipliers.h:61
multipliers_iterate_end
#define multipliers_iterate_end
Definition multipliers.h:67
player_set_ai_data
void player_set_ai_data(struct player *pplayer, const struct ai_type *ai, void *data)
Definition player.c:1952
player_index
int player_index(const struct player *pplayer)
Definition player.c:829
players_iterate_end
#define players_iterate_end
Definition player.h:539
players_iterate
#define players_iterate(_pplayer)
Definition player.h:534
secfile_lookup_int_default
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
Definition registry_ini.c:2000
secfile_insert_int
#define secfile_insert_int(secfile, value, path,...)
Definition registry_ini.h:116
ai_dip_intel
Definition daidata.h:53
ai_plr
Definition daidata.h:71
ai_type
Definition ai.h:50
multiplier_value::target
int target
Definition player.h:243
player_ai::skill_level
enum ai_level skill_level
Definition player.h:116
player
Definition player.h:249
player::cities
struct city_list * cities
Definition player.h:281
player::ai_common
struct player_ai ai_common
Definition player.h:288
player::multipliers
struct multiplier_value multipliers[MAX_NUM_MULTIPLIERS]
Definition player.h:314
section_file
Definition section_file.h:36
world::map
struct civ_map map
Definition world_object.h:38
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
advance_index_iterate_end
#define advance_index_iterate_end
Definition tech.h:249
A_NONE
#define A_NONE
Definition tech.h:43
advance_index_iterate
#define advance_index_iterate(_start, _index)
Definition tech.h:245
unit.h
world_object.h