Freeciv-3.1: /fast/freeciv/nightly/S3_1/ai/default/aiplayer.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
aiplayer.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
24/* server */
25#include "citytools.h"
26
27/* ai/default */
28#include "aidata.h"
29#include "daimilitary.h"
30
31#include "aiplayer.h"
32
33/**********************************************************************/
37 void dai_player_alloc(struct ai_type *ait, struct player *pplayer)
38{
39 struct ai_plr *player_data = fc_calloc(1, sizeof(struct ai_plr));
40
41 player_set_ai_data(pplayer, ait, player_data);
42
43 dai_data_init(ait, pplayer);
44}
45
46/**********************************************************************/
49 void dai_player_free(struct ai_type *ait, struct player *pplayer)
50{
51 struct ai_plr *player_data = def_ai_player_data(pplayer, ait);
52
53 dai_data_close(ait, pplayer);
54
55 if (player_data != NULL) {
56 player_set_ai_data(pplayer, ait, NULL);
57 FC_FREE(player_data);
58 }
59}
60
61/**********************************************************************/
64 void dai_player_save(struct ai_type *ait, const char *aitstr,
65 struct player *pplayer, struct section_file *file,
66 int plrno)
67{
68 players_iterate(other) {
69 dai_player_save_relations(ait, aitstr, pplayer, other, file, plrno);
70 } players_iterate_end;
71}
72
73/**********************************************************************/
76 void dai_player_save_relations(struct ai_type *ait, const char *aitstr,
77 struct player *pplayer, struct player *other,
78 struct section_file *file, int plrno)
79{
80 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, other);
81 char buf[32];
82
83 fc_snprintf(buf, sizeof(buf), "player%d.%s%d", plrno, aitstr,
84 player_index(other));
85
86 secfile_insert_int(file, adip->spam,
87 "%s.spam", buf);
88 secfile_insert_int(file, adip->countdown,
89 "%s.countdown", buf);
90 secfile_insert_int(file, adip->war_reason,
91 "%s.war_reason", buf);
92 secfile_insert_int(file, adip->ally_patience,
93 "%s.patience", buf);
94 secfile_insert_int(file, adip->warned_about_space,
95 "%s.warn_space", buf);
96 secfile_insert_int(file, adip->asked_about_peace,
97 "%s.ask_peace", buf);
98 secfile_insert_int(file, adip->asked_about_alliance,
99 "%s.ask_alliance", buf);
100 secfile_insert_int(file, adip->asked_about_ceasefire,
101 "%s.ask_ceasefire", buf);
102}
103
104/**********************************************************************/
107 void dai_player_load(struct ai_type *ait, const char *aitstr,
108 struct player *pplayer,
109 const struct section_file *file, int plrno)
110{
111 players_iterate(other) {
112 dai_player_load_relations(ait, aitstr, pplayer, other, file, plrno);
113 } players_iterate_end;
114}
115
116/**********************************************************************/
119 void dai_player_load_relations(struct ai_type *ait, const char *aitstr,
120 struct player *pplayer, struct player *other,
121 const struct section_file *file, int plrno)
122{
123 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, other);
124 char buf[32];
125
126 fc_snprintf(buf, sizeof(buf), "player%d.%s%d", plrno, aitstr,
127 player_index(other));
128
129 adip->spam
130 = secfile_lookup_int_default(file, 0, "%s.spam", buf);
131 adip->countdown
132 = secfile_lookup_int_default(file, -1, "%s.countdown", buf);
133 adip->war_reason
134 = secfile_lookup_int_default(file, 0, "%s.war_reason", buf);
135 adip->ally_patience
136 = secfile_lookup_int_default(file, 0, "%s.patience", buf);
137 adip->warned_about_space
138 = secfile_lookup_int_default(file, 0, "%s.warn_space", buf);
139 adip->asked_about_peace
140 = secfile_lookup_int_default(file, 0, "%s.ask_peace", buf);
141 adip->asked_about_alliance
142 = secfile_lookup_int_default(file, 0, "%s.ask_alliance", buf);
143 adip->asked_about_ceasefire
144 = secfile_lookup_int_default(file, 0, "%s.ask_ceasefire", buf);
145}
146
147/**********************************************************************/
150 void dai_player_copy(struct ai_type *ait,
151 struct player *original, struct player *created)
152{
153 bool close_original;
154 bool close_created;
155 struct ai_plr *orig_data = dai_plr_data_get(ait, original, &close_original);
156 struct ai_plr *created_data = dai_plr_data_get(ait, created, &close_created);
157
158 advance_index_iterate(A_NONE, i) {
159 created_data->tech_want[i] = orig_data->tech_want[i];
160 } advance_index_iterate_end;
161
162 if (close_original) {
163 dai_data_phase_finished(ait, original);
164 }
165 if (close_created) {
166 dai_data_phase_finished(ait, created);
167 }
168}
169
170/**********************************************************************/
173 void dai_gained_control(struct ai_type *ait, struct player *pplayer)
174{
175 if (pplayer->ai_common.skill_level != AI_LEVEL_AWAY) {
176 multipliers_iterate(pmul) {
177 pplayer->multipliers[multiplier_index(pmul)].target = pmul->def;
178 } multipliers_iterate_end;
179
180 /* Clear worker tasks, some AIs (e.g. classic) does not use those */
181 city_list_iterate(pplayer->cities, pcity) {
182 clear_worker_tasks(pcity);
183 } city_list_iterate_end;
184 }
185
186 dai_assess_danger_player(ait, pplayer, &(wld.map));
187}
ai.h
dai_plr_data_get
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Definition aidata.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 aidata.c:402
dai_data_init
void dai_data_init(struct ai_type *ait, struct player *pplayer)
Definition aidata.c:59
dai_data_phase_finished
void dai_data_phase_finished(struct ai_type *ait, struct player *pplayer)
Definition aidata.c:285
dai_data_close
void dai_data_close(struct ai_type *ait, struct player *pplayer)
Definition aidata.c:104
aidata.h
dai_player_alloc
void dai_player_alloc(struct ai_type *ait, struct player *pplayer)
Definition aiplayer.c:37
dai_player_save
void dai_player_save(struct ai_type *ait, const char *aitstr, struct player *pplayer, struct section_file *file, int plrno)
Definition aiplayer.c:64
dai_player_copy
void dai_player_copy(struct ai_type *ait, struct player *original, struct player *created)
Definition aiplayer.c:150
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 aiplayer.c:76
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 aiplayer.c:107
dai_player_free
void dai_player_free(struct ai_type *ait, struct player *pplayer)
Definition aiplayer.c:49
dai_gained_control
void dai_gained_control(struct ai_type *ait, struct player *pplayer)
Definition aiplayer.c:173
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 aiplayer.c:119
aiplayer.h
def_ai_player_data
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition aiplayer.h:54
city.h
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:488
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:490
clear_worker_tasks
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3495
citytools.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:613
daimilitary.h
wld
struct world wld
Definition game.c:58
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:1912
player_index
int player_index(const struct player *pplayer)
Definition player.c:820
players_iterate_end
#define players_iterate_end
Definition player.h:535
players_iterate
#define players_iterate(_pplayer)
Definition player.h:530
secfile_lookup_int_default
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
Definition registry_ini.c:1937
secfile_insert_int
#define secfile_insert_int(secfile, value, path,...)
Definition registry_ini.h:116
ai_dip_intel
Definition aidata.h:53
ai_dip_intel::asked_about_alliance
signed char asked_about_alliance
Definition aidata.h:65
ai_dip_intel::war_reason
enum war_reason war_reason
Definition aidata.h:62
ai_dip_intel::spam
signed char spam
Definition aidata.h:59
ai_dip_intel::asked_about_peace
signed char asked_about_peace
Definition aidata.h:64
ai_dip_intel::warned_about_space
signed char warned_about_space
Definition aidata.h:67
ai_dip_intel::countdown
int countdown
Definition aidata.h:61
ai_dip_intel::ally_patience
signed char ally_patience
Definition aidata.h:63
ai_dip_intel::asked_about_ceasefire
signed char asked_about_ceasefire
Definition aidata.h:66
ai_plr
Definition aidata.h:71
ai_plr::tech_want
adv_want tech_want[A_LAST+1]
Definition aidata.h:103
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:122
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:310
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:969
advance_index_iterate_end
#define advance_index_iterate_end
Definition tech.h:248
A_NONE
#define A_NONE
Definition tech.h:43
advance_index_iterate
#define advance_index_iterate(_start, _index)
Definition tech.h:244
unit.h