/************************************************************************** Log city messages, they will appear like this 2: Polish Romenna(5,35) [s1 d106 u11 g1] must have Archers ... **************************************************************************/ void real_city_log(const char *file, const char *function, int line, enum log_level level, bool notify, const struct city *pcity, const char *msg, ...) { char buffer[500]; char buffer2[500]; va_list ap; char aibuf[500] = "\0"; CALL_PLR_AI_FUNC(log_fragment_city, city_owner(pcity), aibuf, sizeof(aibuf), pcity); fc_snprintf(buffer, sizeof(buffer), "%s %s(%d,%d) [s%d] {%s} ", nation_rule_name(nation_of_city(pcity)), city_name(pcity), TILE_XY(pcity->tile), city_size_get(pcity), aibuf); va_start(ap, msg); fc_vsnprintf(buffer2, sizeof(buffer2), msg, ap); va_end(ap); cat_snprintf(buffer, sizeof(buffer), "%s", buffer2); if (notify) { notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer); } do_log(file, function, line, FALSE, level, "%s", buffer); }
/**************************************************************************** Lookup an RGB color definition (<colorpath>.red, <colorpath>.green and <colorpath>.blue). Returns TRUE on success and FALSE on error. ****************************************************************************/ bool rgbcolor_load(struct section_file *file, struct rgbcolor **prgbcolor, char *path, ...) { int r, g, b; char colorpath[256]; va_list args; fc_assert_ret_val(file != NULL, FALSE); fc_assert_ret_val(*prgbcolor == NULL, FALSE); va_start(args, path); fc_vsnprintf(colorpath, sizeof(colorpath), path, args); va_end(args); if (!secfile_lookup_int(file, &r, "%s.r", colorpath) || !secfile_lookup_int(file, &g, "%s.g", colorpath) || !secfile_lookup_int(file, &b, "%s.b", colorpath)) { /* One color value (red, green or blue) is missing. */ return FALSE; } rgbcolor_check(colorpath, r, g, b); *prgbcolor = rgbcolor_new(r, g, b); return TRUE; }
/************************************************************************** Log player tech messages. **************************************************************************/ void real_tech_log(const char *file, const char *function, int line, enum log_level level, bool notify, const struct player *pplayer, struct advance *padvance, const char *msg, ...) { char buffer[500]; char buffer2[500]; va_list ap; if (!valid_advance(padvance) || advance_by_number(A_NONE) == padvance) { return; } fc_snprintf(buffer, sizeof(buffer), "%s::%s (want %d, dist %d) ", player_name(pplayer), advance_name_by_player(pplayer, advance_number(padvance)), pplayer->ai_common.tech_want[advance_index(padvance)], num_unknown_techs_for_goal(pplayer, advance_number(padvance))); va_start(ap, msg); fc_vsnprintf(buffer2, sizeof(buffer2), msg, ap); va_end(ap); cat_snprintf(buffer, sizeof(buffer), "%s", buffer2); if (notify) { notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer); } do_log(file, function, line, FALSE, level, "%s", buffer); }
/*************************************************************************** Do a fprintf from the internal charset into the local charset. ***************************************************************************/ void fc_fprintf(FILE *stream, const char *format, ...) { va_list ap; char string[4096]; const char *output; static bool recursion = FALSE; /* The recursion variable is used to prevent a recursive loop. If * an iconv conversion fails, then log_* will be called and an * fc_fprintf will be done. But below we do another iconv conversion * on the error messages, which is of course likely to fail also. */ if (recursion) { return; } va_start(ap, format); fc_vsnprintf(string, sizeof(string), format, ap); va_end(ap); recursion = TRUE; if (is_init) { output = internal_to_local_string_static(string); } else { output = string; } recursion = FALSE; fputs(output, stream); fflush(stream); }
/***************************************************************************** Add a line of text to the output ("chatline") window. The text is constructed in printf style. *****************************************************************************/ void luaconsole_vprintf(const struct ft_color color, const char *format, va_list args) { char featured_text[MAX_LEN_MSG]; fc_vsnprintf(featured_text, sizeof(featured_text), format, args); luaconsole_append(color, featured_text); }
/************************************************************************** Add a line of text to the output ("chatline") window. The text is constructed in printf style. **************************************************************************/ void output_window_vprintf(const struct ft_color color, const char *format, va_list args) { char featured_text[MAX_LEN_MSG]; fc_vsnprintf(featured_text, sizeof(featured_text), format, args); output_window_append(color, featured_text); }
/***************************************************************************** Print a message to the selected output handle. *****************************************************************************/ void luascript_log_vargs(struct fc_lua *fcl, enum log_level level, const char *format, va_list args) { char buf[1024]; fc_assert_ret(fcl); fc_assert_ret(0 <= level && level <= LOG_DEBUG); fc_vsnprintf(buf, sizeof(buf), format, args); if (fcl->output_fct) { fcl->output_fct(fcl, level, "%s", buf); } else { log_base(level, "%s", buf); } }
/**************************************************************************** Save an RGB color definition (<colorpath>.red, <colorpath>.green and <colorpath>.blue). ****************************************************************************/ void rgbcolor_save(struct section_file *file, const struct rgbcolor *prgbcolor, char *path, ...) { char colorpath[256]; va_list args; fc_assert_ret(file != NULL); fc_assert_ret(prgbcolor != NULL); va_start(args, path); fc_vsnprintf(colorpath, sizeof(colorpath), path, args); va_end(args); secfile_insert_int(file, prgbcolor->r, "%s.r", colorpath); secfile_insert_int(file, prgbcolor->g, "%s.g", colorpath); secfile_insert_int(file, prgbcolor->b, "%s.b", colorpath); }
/************************************************************************** Log unit messages, they will appear like this 2: Polish Archers[139] (5,35)->(0,0){0,0} stays to defend city where [] is unit id, ()->() are coordinates present and goto, and {,} contains bodyguard and ferryboat ids. **************************************************************************/ void real_unit_log(const char *file, const char *function, int line, enum log_level level, bool notify, const struct unit *punit, const char *msg, ...) { char buffer[500]; char buffer2[500]; va_list ap; int gx, gy; char aibuf[500] = "\0"; CALL_PLR_AI_FUNC(log_fragment_unit, unit_owner(punit), aibuf, sizeof(aibuf), punit); if (punit->goto_tile) { index_to_map_pos(&gx, &gy, tile_index(punit->goto_tile)); } else { gx = gy = -1; } fc_snprintf(buffer, sizeof(buffer), "%s %s[%d] %s (%d,%d)->(%d,%d){%s} ", nation_rule_name(nation_of_unit(punit)), unit_rule_name(punit), punit->id, get_activity_text(punit->activity), TILE_XY(unit_tile(punit)), gx, gy, aibuf); va_start(ap, msg); fc_vsnprintf(buffer2, sizeof(buffer2), msg, ap); va_end(ap); cat_snprintf(buffer, sizeof(buffer), "%s", buffer2); if (notify) { notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer); } do_log(file, function, line, FALSE, level, "%s", buffer); }