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

Freeciv-3.1

Loading...
Searching...
No Matches
ailog.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2002 - The Freeciv Project
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#include <stdarg.h>
19
20/* common */
21#include "map.h"
22#include "player.h"
23#include "research.h"
24
25/* server */
26#include "notify.h"
27
28/* ai/default */
29#include "aidata.h"
30#include "aiplayer.h"
31#include "aiunit.h"
32#include "daicity.h"
33
34#include "ailog.h"
35
36
37/**********************************************************************/
40 void dai_city_log(struct ai_type *ait, char *buffer, int buflength,
41 const struct city *pcity)
42{
43 struct ai_city *city_data = def_ai_city_data(pcity, ait);
44
45 fc_snprintf(buffer, buflength, "d%d u%d g%d",
46 city_data->danger, city_data->urgency,
47 city_data->grave_danger);
48}
49
50/**********************************************************************/
53 void dai_unit_log(struct ai_type *ait, char *buffer, int buflength,
54 const struct unit *punit)
55{
56 struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
57
58 fc_snprintf(buffer, buflength, "%d %d",
59 unit_data->bodyguard, unit_data->ferryboat);
60}
61
62/**********************************************************************/
65 void real_tech_log(struct ai_type *ait, const char *file, const char *function,
66 int line, enum log_level level, bool send_notify,
67 const struct player *pplayer, struct advance *padvance,
68 const char *msg, ...)
69{
70 char buffer[500];
71 char buffer2[500];
72 va_list ap;
73 struct ai_plr *plr_data;
74
75 if (!valid_advance(padvance) || advance_by_number(A_NONE) == padvance) {
76 return;
77 }
78
79 plr_data = def_ai_player_data(pplayer, ait);
80 fc_snprintf(buffer, sizeof(buffer), "%s::%s (want " ADV_WANT_PRINTF ", dist %d) ",
81 player_name(pplayer),
82 advance_rule_name(padvance),
83 plr_data->tech_want[advance_index(padvance)],
84 research_goal_unknown_techs(research_get(pplayer),
85 advance_number(padvance)));
86
87 va_start(ap, msg);
88 fc_vsnprintf(buffer2, sizeof(buffer2), msg, ap);
89 va_end(ap);
90
91 cat_snprintf(buffer, sizeof(buffer), "%s", buffer2);
92 if (send_notify) {
93 notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer);
94 }
95 do_log(file, function, line, FALSE, level, "%s", buffer);
96}
97
98/**********************************************************************/
103 void real_diplo_log(struct ai_type *ait, const char *file,
104 const char *function, int line,
105 enum log_level level, bool send_notify,
106 const struct player *pplayer,
107 const struct player *aplayer, const char *msg, ...)
108{
109 char buffer[500];
110 char buffer2[500];
111 va_list ap;
112 const struct ai_dip_intel *adip;
113
114 /* Don't use ai_data_get since it can have side effects. */
115 adip = dai_diplomacy_get(ait, pplayer, aplayer);
116
117 fc_snprintf(buffer, sizeof(buffer), "%s->%s(l%d,c%d,d%d%s): ",
118 player_name(pplayer),
119 player_name(aplayer),
120 pplayer->ai_common.love[player_index(aplayer)],
121 adip->countdown,
122 adip->distance,
123 adip->is_allied_with_enemy ? "?" :
124 (adip->at_war_with_ally ? "!" : ""));
125
126 va_start(ap, msg);
127 fc_vsnprintf(buffer2, sizeof(buffer2), msg, ap);
128 va_end(ap);
129
130 cat_snprintf(buffer, sizeof(buffer), "%s", buffer2);
131 if (send_notify) {
132 notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer);
133 }
134 do_log(file, function, line, FALSE, level, "%s", buffer);
135}
136
137/**********************************************************************/
142 void real_bodyguard_log(struct ai_type *ait, const char *file,
143 const char *function, int line,
144 enum log_level level, bool send_notify,
145 const struct unit *punit, const char *msg, ...)
146{
147 char buffer[500];
148 char buffer2[500];
149 va_list ap;
150 const struct unit *pcharge;
151 const struct city *pcity;
152 int id = -1;
153 int charge_x = -1;
154 int charge_y = -1;
155 const char *type = "guard";
156 const char *s = "none";
157 struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
158
159 pcity = game_city_by_number(unit_data->charge);
160 pcharge = game_unit_by_number(unit_data->charge);
161 if (pcharge) {
162 index_to_map_pos(&charge_x, &charge_y, tile_index(unit_tile(pcharge)));
163 id = pcharge->id;
164 type = "bodyguard";
165 s = unit_rule_name(pcharge);
166 } else if (pcity) {
167 index_to_map_pos(&charge_x, &charge_y, tile_index(city_tile(pcity)));
168 id = pcity->id;
169 type = "cityguard";
170 s = city_name_get(pcity);
171 }
172 /* else perhaps the charge died */
173
174 fc_snprintf(buffer, sizeof(buffer),
175 "%s %s[%d] %s (%d,%d){%s:%d@%d,%d} ",
176 nation_rule_name(nation_of_unit(punit)),
177 unit_rule_name(punit),
178 punit->id,
179 type,
180 TILE_XY(unit_tile(punit)),
181 s, id, charge_x, charge_y);
182
183 va_start(ap, msg);
184 fc_vsnprintf(buffer2, sizeof(buffer2), msg, ap);
185 va_end(ap);
186
187 cat_snprintf(buffer, sizeof(buffer), "%s", buffer2);
188 if (send_notify) {
189 notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer);
190 }
191 do_log(file, function, line, FALSE, level, "%s", buffer);
192}
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
aidata.h
dai_unit_log
void dai_unit_log(struct ai_type *ait, char *buffer, int buflength, const struct unit *punit)
Definition ailog.c:53
real_tech_log
void real_tech_log(struct ai_type *ait, const char *file, const char *function, int line, enum log_level level, bool send_notify, const struct player *pplayer, struct advance *padvance, const char *msg,...)
Definition ailog.c:65
real_bodyguard_log
void real_bodyguard_log(struct ai_type *ait, const char *file, const char *function, int line, enum log_level level, bool send_notify, const struct unit *punit, const char *msg,...)
Definition ailog.c:142
real_diplo_log
void real_diplo_log(struct ai_type *ait, const char *file, const char *function, int line, enum log_level level, bool send_notify, const struct player *pplayer, const struct player *aplayer, const char *msg,...)
Definition ailog.c:103
dai_city_log
void dai_city_log(struct ai_type *ait, char *buffer, int buflength, const struct city *pcity)
Definition ailog.c:40
ailog.h
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
def_ai_city_data
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
Definition aiplayer.h:42
def_ai_unit_data
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
Definition aiplayer.h:48
aiunit.h
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1111
city_tile
#define city_tile(_pcity_)
Definition city.h:544
daicity.h
punit
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 * punit
Definition dialogs_g.h:73
ADV_WANT_PRINTF
#define ADV_WANT_PRINTF
Definition fc_types.h:1207
ftc_log
const struct ft_color ftc_log
Definition featured_text.c:76
game_unit_by_number
struct unit * game_unit_by_number(int id)
Definition game.c:111
game_city_by_number
struct city * game_city_by_number(int id)
Definition game.c:102
type
GType type
Definition repodlgs.c:1312
do_log
void do_log(const char *file, const char *function, int line, bool print_from_where, enum log_level level, const char *message,...)
Definition log.c:514
log_level
log_level
Definition log.h:28
map.h
index_to_map_pos
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:227
nation_rule_name
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:137
nation_of_unit
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:462
notify_conn
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:239
notify.h
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:886
player_index
int player_index(const struct player *pplayer)
Definition player.c:820
player.h
research_goal_unknown_techs
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Definition research.c:747
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:126
research.h
level
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:183
advance
Definition tech.h:124
ai_city
Definition daicity.h:34
ai_city::danger
unsigned int danger
Definition daicity.h:47
ai_city::urgency
unsigned int urgency
Definition daicity.h:49
ai_city::grave_danger
unsigned int grave_danger
Definition daicity.h:48
ai_dip_intel
Definition aidata.h:53
ai_dip_intel::at_war_with_ally
struct player * at_war_with_ally
Definition aidata.h:56
ai_dip_intel::distance
int distance
Definition aidata.h:60
ai_dip_intel::countdown
int countdown
Definition aidata.h:61
ai_dip_intel::is_allied_with_enemy
struct player * is_allied_with_enemy
Definition aidata.h:55
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
city
Definition city.h:309
city::id
int id
Definition city.h:315
player_ai::love
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:130
player
Definition player.h:249
player::ai_common
struct player_ai ai_common
Definition player.h:288
unit_ai
Definition aiunit.h:32
unit_ai::bodyguard
int bodyguard
Definition aiunit.h:36
unit_ai::ferryboat
int ferryboat
Definition aiunit.h:34
unit_ai::charge
int charge
Definition aiunit.h:37
unit
Definition unit.h:138
unit::id
int id
Definition unit.h:145
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
cat_snprintf
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:995
fc_vsnprintf
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition support.c:896
FALSE
#define FALSE
Definition support.h:47
advance_by_number
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
valid_advance
struct advance * valid_advance(struct advance *padvance)
Definition tech.c:152
advance_rule_name
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:299
advance_index
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
advance_number
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
A_NONE
#define A_NONE
Definition tech.h:43
tile_index
#define tile_index(_pt_)
Definition tile.h:87
TILE_XY
#define TILE_XY(ptile)
Definition tile.h:42
unit_tile
#define unit_tile(_pu)
Definition unit.h:388
unit_rule_name
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1639