Freeciv-3.2
Loading...
Searching...
No Matches
dailog.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 "nation.h"
23#include "player.h"
24#include "research.h"
25
26/* server */
27#include "notify.h"
28
29/* ai/default */
30#include "daicity.h"
31#include "daidata.h"
32#include "daiplayer.h"
33#include "daiunit.h"
34
35#include "dailog.h"
36
37
38/**********************************************************************/
41void dai_city_log(struct ai_type *ait, char *buffer, int buflength,
42 const struct city *pcity)
43{
44 struct ai_city *city_data = def_ai_city_data(pcity, ait);
45
46 fc_snprintf(buffer, buflength, "d%d u%d g%d",
47 city_data->danger, city_data->urgency,
48 city_data->grave_danger);
49}
50
51/**********************************************************************/
54void dai_unit_log(struct ai_type *ait, char *buffer, int buflength,
55 const struct unit *punit)
56{
58
59 fc_snprintf(buffer, buflength, "%d %d",
60 unit_data->bodyguard, unit_data->ferryboat);
61}
62
63/**********************************************************************/
66void real_tech_log(struct ai_type *ait, const char *file, const char *function,
67 int line, enum log_level level, bool send_notify,
68 const struct player *pplayer, struct advance *padvance,
69 const char *msg, ...)
70{
71 char buffer[500];
72 char buffer2[500];
73 va_list ap;
74 struct ai_plr *plr_data;
75
77 return;
78 }
79
80 plr_data = def_ai_player_data(pplayer, ait);
81 fc_snprintf(buffer, sizeof(buffer), "%s::%s (want " ADV_WANT_PRINTF ", dist %d) ",
82 player_name(pplayer),
84 plr_data->tech_want[advance_index(padvance)],
87
88 va_start(ap, msg);
89 fc_vsnprintf(buffer2, sizeof(buffer2), msg, ap);
90 va_end(ap);
91
92 cat_snprintf(buffer, sizeof(buffer), "%s", buffer2);
93 if (send_notify) {
94 notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer);
95 }
96 do_log(file, function, line, FALSE, level, "%s", buffer);
97}
98
99/**********************************************************************/
104void real_diplo_log(struct ai_type *ait, const char *file,
105 const char *function, int line,
106 enum log_level level, bool send_notify,
107 const struct player *pplayer,
108 const struct player *aplayer, const char *msg, ...)
109{
110 char buffer[500];
111 char buffer2[500];
112 va_list ap;
113 const struct ai_dip_intel *adip;
114
115 /* Don't use ai_data_get since it can have side effects. */
116 adip = dai_diplomacy_get(ait, pplayer, aplayer);
117
118 fc_snprintf(buffer, sizeof(buffer), "%s->%s(l%d,c%d,d%d%s): ",
119 player_name(pplayer),
122 adip->countdown,
123 adip->distance,
124 adip->is_allied_with_enemy ? "?" :
125 (adip->at_war_with_ally ? "!" : ""));
126
127 va_start(ap, msg);
128 fc_vsnprintf(buffer2, sizeof(buffer2), msg, ap);
129 va_end(ap);
130
131 cat_snprintf(buffer, sizeof(buffer), "%s", buffer2);
132 if (send_notify) {
133 notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer);
134 }
135 do_log(file, function, line, FALSE, level, "%s", buffer);
136}
137
138/**********************************************************************/
143void real_bodyguard_log(struct ai_type *ait, const char *file,
144 const char *function, int line,
145 enum log_level level, bool send_notify,
146 const struct unit *punit, const char *msg, ...)
147{
148 char buffer[500];
149 char buffer2[500];
150 va_list ap;
151 const struct unit *pcharge;
152 const struct city *pcity;
153 int id = -1;
154 int charge_x = -1;
155 int charge_y = -1;
156 const char *type = "guard";
157 const char *s = "none";
158 struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
159
160 pcity = game_city_by_number(unit_data->charge);
162 if (pcharge) {
164 id = pcharge->id;
165 type = "bodyguard";
167 } else if (pcity) {
169 id = pcity->id;
170 type = "cityguard";
171 s = city_name_get(pcity);
172 }
173 /* else perhaps the charge died */
174
175 fc_snprintf(buffer, sizeof(buffer),
176 "%s %s[%d] %s (%d,%d){%s:%d@%d,%d} ",
179 punit->id,
180 type,
182 s, id, charge_x, charge_y);
183
184 va_start(ap, msg);
185 fc_vsnprintf(buffer2, sizeof(buffer2), msg, ap);
186 va_end(ap);
187
188 cat_snprintf(buffer, sizeof(buffer), "%s", buffer2);
189 if (send_notify) {
190 notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer);
191 }
192 do_log(file, function, line, FALSE, level, "%s", buffer);
193}
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
#define city_tile(_pcity_)
Definition city.h:564
char * incite_cost
Definition comments.c:75
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_unit_log(struct ai_type *ait, char *buffer, int buflength, const struct unit *punit)
Definition dailog.c:54
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 dailog.c:66
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 dailog.c:143
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 dailog.c:104
void dai_city_log(struct ai_type *ait, char *buffer, int buflength, const struct city *pcity)
Definition dailog.c:41
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
Definition daiplayer.h:54
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
Definition daiplayer.h:42
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
Definition daiplayer.h:48
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:74
#define ADV_WANT_PRINTF
Definition fc_types.h:1355
const struct ft_color ftc_log
struct unit * game_unit_by_number(int id)
Definition game.c:116
struct city * game_city_by_number(int id)
Definition game.c:107
GType type
Definition repodlgs.c:1313
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:233
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:463
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:895
int player_index(const struct player *pplayer)
Definition player.c:829
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Definition research.c:750
struct research * research_get(const struct player *pplayer)
Definition research.c:128
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
Definition ai.h:50
Definition city.h:320
int id
Definition city.h:326
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:122
struct player_ai ai_common
Definition player.h:286
Definition unit.h:138
int id
Definition unit.h:145
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:1000
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition support.c:900
#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:88
#define TILE_XY(ptile)
Definition tile.h:43
#define unit_tile(_pu)
Definition unit.h:397
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1587