Freeciv-3.4
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#include "sanitycheck.h"
28
29/* ai/default */
30#include "daidata.h"
31#include "daimilitary.h"
32
33#include "daiplayer.h"
34
35/**********************************************************************/
39void dai_player_alloc(struct ai_type *ait, struct player *pplayer)
40{
41 struct ai_plr *player_data = fc_calloc(1, sizeof(struct ai_plr));
42
43 player_set_ai_data(pplayer, ait, player_data);
44
45 dai_data_init(ait, pplayer);
46}
47
48/**********************************************************************/
51void dai_player_free(struct ai_type *ait, struct player *pplayer)
52{
53 struct ai_plr *player_data = def_ai_player_data(pplayer, ait);
54
55 dai_data_close(ait, pplayer);
56
57 if (player_data != NULL) {
58 player_set_ai_data(pplayer, ait, NULL);
60 }
61}
62
63/**********************************************************************/
66void dai_player_save(struct ai_type *ait, const char *aitstr,
67 struct player *pplayer, struct section_file *file,
68 int plrno)
69{
71 dai_player_save_relations(ait, aitstr, pplayer, other, file, plrno);
73}
74
75/**********************************************************************/
78void dai_player_save_relations(struct ai_type *ait, const char *aitstr,
79 struct player *pplayer, struct player *other,
80 struct section_file *file, int plrno)
81{
82 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, other);
83 char buf[32];
84
85 fc_snprintf(buf, sizeof(buf), "player%d.%s%d", plrno, aitstr,
87
88 secfile_insert_int(file, adip->spam,
89 "%s.spam", buf);
90 secfile_insert_int(file, adip->countdown,
91 "%s.countdown", buf);
92 secfile_insert_int(file, adip->war_reason,
93 "%s.war_reason", buf);
94 secfile_insert_int(file, adip->ally_patience,
95 "%s.patience", buf);
96 secfile_insert_int(file, adip->warned_about_space,
97 "%s.warn_space", buf);
98 secfile_insert_int(file, adip->asked_about_peace,
99 "%s.ask_peace", buf);
100 secfile_insert_int(file, adip->asked_about_alliance,
101 "%s.ask_alliance", buf);
102 secfile_insert_int(file, adip->asked_about_ceasefire,
103 "%s.ask_ceasefire", buf);
104}
105
106/**********************************************************************/
109void dai_player_load(struct ai_type *ait, const char *aitstr,
110 struct player *pplayer,
111 const struct section_file *file, int plrno)
112{
114 dai_player_load_relations(ait, aitstr, pplayer, other, file, plrno);
116}
117
118/**********************************************************************/
121void dai_player_load_relations(struct ai_type *ait, const char *aitstr,
122 struct player *pplayer, struct player *other,
123 const struct section_file *file, int plrno)
124{
125 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, other);
126 char buf[32];
127
128 fc_snprintf(buf, sizeof(buf), "player%d.%s%d", plrno, aitstr,
130
131 adip->spam
132 = secfile_lookup_int_default(file, 0, "%s.spam", buf);
133 adip->countdown
134 = secfile_lookup_int_default(file, -1, "%s.countdown", buf);
135 adip->war_reason
136 = secfile_lookup_int_default(file, 0, "%s.war_reason", buf);
137 adip->ally_patience
138 = secfile_lookup_int_default(file, 0, "%s.patience", buf);
139 adip->warned_about_space
140 = secfile_lookup_int_default(file, 0, "%s.warn_space", buf);
141 adip->asked_about_peace
142 = secfile_lookup_int_default(file, 0, "%s.ask_peace", buf);
143 adip->asked_about_alliance
144 = secfile_lookup_int_default(file, 0, "%s.ask_alliance", buf);
145 adip->asked_about_ceasefire
146 = secfile_lookup_int_default(file, 0, "%s.ask_ceasefire", buf);
147}
148
149/**********************************************************************/
152void dai_player_copy(struct ai_type *ait,
153 struct player *original, struct player *created)
154{
155 bool close_original;
156 bool close_created;
157 struct ai_plr *orig_data = dai_plr_data_get(ait, original, &close_original);
159
161 created_data->tech_want[i] = orig_data->tech_want[i];
163
164 if (close_original) {
165 dai_data_phase_finished(ait, original);
166 }
167 if (close_created) {
169 }
170}
171
172/**********************************************************************/
175void dai_gained_control(struct ai_type *ait, struct player *pplayer)
176{
177 if (pplayer->ai_common.skill_level != AI_LEVEL_AWAY) {
178 multipliers_iterate(pmul) {
179 pplayer->multipliers[multiplier_index(pmul)].target = pmul->def;
181
182 /* Clear worker tasks, some AIs (e.g. classic) does not use those */
183 city_list_iterate(pplayer->cities, pcity) {
186 }
187
188 dai_assess_danger_player(ait, &(wld.map), pplayer);
189}
190
191/**********************************************************************/
194void dai_sanity_check(struct ai_type *ait, struct player *pplayer)
195{
196#ifdef SANITY_CHECKING
197
198#define SANITY_CHECK(check) \
199 fc_assert_full(__FILE__, __FUNCTION__, __FC_LINE__, check, , NOLOGMSG, NOLOGMSG)
200
201 struct player *wt = def_ai_player_data(pplayer, ait)->diplomacy.war_target;
202
204 struct ai_dip_intel *adip = dai_diplomacy_get(ait, pplayer, opponent);
205 bool at_war = pplayers_at_war(pplayer, opponent);
206 bool war_target = (wt == opponent);
207
208 /* SANITY_CHECK(adip->countdown < 0 || !at_war); */
209 SANITY_CHECK(adip->countdown >= -1 || at_war || war_target);
211
212#endif /* SANITY_CHECKING */
213}
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define city_list_iterate_end
Definition city.h:510
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3617
char * incite_cost
Definition comments.c:77
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Definition daidata.c:308
struct ai_dip_intel * dai_diplomacy_get(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Definition daidata.c:402
void dai_data_init(struct ai_type *ait, struct player *pplayer)
Definition daidata.c:59
void dai_data_phase_finished(struct ai_type *ait, struct player *pplayer)
Definition daidata.c:285
void dai_data_close(struct ai_type *ait, struct player *pplayer)
Definition daidata.c:104
void dai_assess_danger_player(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer)
void dai_sanity_check(struct ai_type *ait, struct player *pplayer)
Definition daiplayer.c:194
void dai_player_alloc(struct ai_type *ait, struct player *pplayer)
Definition daiplayer.c:39
void dai_player_save(struct ai_type *ait, const char *aitstr, struct player *pplayer, struct section_file *file, int plrno)
Definition daiplayer.c:66
void dai_player_copy(struct ai_type *ait, struct player *original, struct player *created)
Definition daiplayer.c:152
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:78
void dai_player_load(struct ai_type *ait, const char *aitstr, struct player *pplayer, const struct section_file *file, int plrno)
Definition daiplayer.c:109
void dai_player_free(struct ai_type *ait, struct player *pplayer)
Definition daiplayer.c:51
void dai_gained_control(struct ai_type *ait, struct player *pplayer)
Definition daiplayer.c:175
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:121
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition daiplayer.h:56
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
struct world wld
Definition game.c:63
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
#define multipliers_iterate(_mul_)
Definition multipliers.h:61
#define multipliers_iterate_end
Definition multipliers.h:67
bool pplayers_at_war(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1376
void player_set_ai_data(struct player *pplayer, const struct ai_type *ai, void *data)
Definition player.c:1937
int player_index(const struct player *pplayer)
Definition player.c:818
#define players_iterate_end
Definition player.h:552
#define players_iterate(_pplayer)
Definition player.h:547
#define players_iterate_alive_end
Definition player.h:562
#define players_iterate_alive(_pplayer)
Definition player.h:557
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
#define secfile_insert_int(secfile, value, path,...)
struct ai_plr::@280 diplomacy
struct player * war_target
Definition daidata.h:97
Definition ai.h:50
enum ai_level skill_level
Definition player.h:116
struct city_list * cities
Definition player.h:281
struct player_ai ai_common
Definition player.h:288
struct multiplier_value multipliers[MAX_NUM_MULTIPLIERS]
Definition player.h:314
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define advance_index_iterate_end
Definition tech.h:246
#define A_NONE
Definition tech.h:43
#define advance_index_iterate(_start, _index)
Definition tech.h:242