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/**********************************************************************/
40void 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/**********************************************************************/
53void 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/**********************************************************************/
65void 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)],
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/**********************************************************************/
103void 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/**********************************************************************/
142void 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} ",
178 punit->id,
179 type,
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}
struct ai_dip_intel * dai_diplomacy_get(struct ai_type *ait, const struct player *plr1, const struct player *plr2)
Definition aidata.c:402
void dai_unit_log(struct ai_type *ait, char *buffer, int buflength, const struct unit *punit)
Definition ailog.c:53
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
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
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
void dai_city_log(struct ai_type *ait, char *buffer, int buflength, const struct city *pcity)
Definition ailog.c:40
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition aiplayer.h:54
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
Definition aiplayer.h:42
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
Definition aiplayer.h:48
const char * city_name_get(const struct city *pcity)
Definition city.c:1115
#define city_tile(_pcity_)
Definition city.h:544
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
#define ADV_WANT_PRINTF
Definition fc_types.h:1207
const struct ft_color ftc_log
struct unit * game_unit_by_number(int id)
Definition game.c:111
struct city * game_city_by_number(int id)
Definition game.c:102
GType type
Definition repodlgs.c:1312
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
Definition log.h:28
#define index_to_map_pos(pmap_x, pmap_y, mindex)
Definition map.h:227
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:137
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:462
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:238
const char * player_name(const struct player *pplayer)
Definition player.c:886
int player_index(const struct player *pplayer)
Definition player.c:820
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Definition research.c:747
struct research * research_get(const struct player *pplayer)
Definition research.c:126
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:183
unsigned int danger
Definition daicity.h:47
unsigned int urgency
Definition daicity.h:49
unsigned int grave_danger
Definition daicity.h:48
struct player * at_war_with_ally
Definition aidata.h:56
int distance
Definition aidata.h:60
int countdown
Definition aidata.h:61
struct player * is_allied_with_enemy
Definition aidata.h:55
adv_want tech_want[A_LAST+1]
Definition aidata.h:103
Definition ai.h:50
Definition city.h:309
int id
Definition city.h:315
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:130
struct player_ai ai_common
Definition player.h:288
int bodyguard
Definition aiunit.h:36
int ferryboat
Definition aiunit.h:34
int charge
Definition aiunit.h:37
Definition unit.h:138
int id
Definition unit.h:145
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:995
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition support.c:896
#define FALSE
Definition support.h:47
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
struct advance * valid_advance(struct advance *padvance)
Definition tech.c:152
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:299
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:98
#define A_NONE
Definition tech.h:43
#define tile_index(_pt_)
Definition tile.h:87
#define TILE_XY(ptile)
Definition tile.h:42
#define unit_tile(_pu)
Definition unit.h:395
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1639