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/**********************************************************************/
38void 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/**********************************************************************/
50void 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);
59 }
60}
61
62/**********************************************************************/
65void dai_player_save(struct ai_type *ait, const char *aitstr,
66 struct player *pplayer, struct section_file *file,
67 int plrno)
68{
70 dai_player_save_relations(ait, aitstr, pplayer, other, file, plrno);
72}
73
74/**********************************************************************/
77void 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,
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/**********************************************************************/
108void dai_player_load(struct ai_type *ait, const char *aitstr,
109 struct player *pplayer,
110 const struct section_file *file, int plrno)
111{
113 dai_player_load_relations(ait, aitstr, pplayer, other, file, plrno);
115}
116
117/**********************************************************************/
120void 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,
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/**********************************************************************/
151void 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);
158
160 created_data->tech_want[i] = orig_data->tech_want[i];
162
163 if (close_original) {
164 dai_data_phase_finished(ait, original);
165 }
166 if (close_created) {
168 }
169}
170
171/**********************************************************************/
174void 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;
180
181 /* Clear worker tasks, some AIs (e.g. classic) does not use those */
182 city_list_iterate(pplayer->cities, pcity) {
185 }
186
187 dai_assess_danger_player(ait, &(wld.map), pplayer);
188}
#define city_list_iterate(citylist, pcity)
Definition city.h:505
#define city_list_iterate_end
Definition city.h:507
void clear_worker_tasks(struct city *pcity)
Definition citytools.c:3614
char * incite_cost
Definition comments.c:76
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_player_alloc(struct ai_type *ait, struct player *pplayer)
Definition daiplayer.c:38
void dai_player_save(struct ai_type *ait, const char *aitstr, struct player *pplayer, struct section_file *file, int plrno)
Definition daiplayer.c:65
void dai_player_copy(struct ai_type *ait, struct player *original, struct player *created)
Definition daiplayer.c:151
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
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
void dai_player_free(struct ai_type *ait, struct player *pplayer)
Definition daiplayer.c:50
void dai_gained_control(struct ai_type *ait, struct player *pplayer)
Definition daiplayer.c:174
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
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition daiplayer.h:54
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:62
#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
void player_set_ai_data(struct player *pplayer, const struct ai_type *ai, void *data)
Definition player.c:1954
int player_index(const struct player *pplayer)
Definition player.c:829
#define players_iterate_end
Definition player.h:542
#define players_iterate(_pplayer)
Definition player.h:537
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
#define secfile_insert_int(secfile, value, path,...)
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:244
#define A_NONE
Definition tech.h:43
#define advance_index_iterate(_start, _index)
Definition tech.h:240