bygfoot/src/debug.c

310 lines
9.1 KiB
C
Raw Normal View History

2005-10-20 17:45:00 +02:00
/*
2009-04-29 19:18:54 +02:00
debug.c
2005-11-26 17:52:51 +01:00
2009-04-29 19:18:54 +02:00
Bygfoot Football Manager -- a small and simple GTK2-based
football management game.
2005-10-20 17:45:00 +02:00
2009-04-29 19:18:54 +02:00
http://bygfoot.sourceforge.net
2005-10-20 17:45:00 +02:00
2009-04-29 19:18:54 +02:00
Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com)
2005-10-20 17:45:00 +02:00
2009-04-29 19:18:54 +02:00
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
2005-10-20 17:45:00 +02:00
2009-04-29 19:18:54 +02:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2005-10-20 17:45:00 +02:00
2009-04-29 19:18:54 +02:00
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2005-10-20 17:45:00 +02:00
*/
2005-08-14 21:03:11 +02:00
#include "callbacks.h"
2005-05-13 20:20:47 +02:00
#include "debug.h"
#include "game_gui.h"
2005-10-27 23:10:15 +02:00
#include "league.h"
#include "live_game.h"
2005-05-13 20:20:47 +02:00
#include "option.h"
2005-10-27 23:10:15 +02:00
#include "strategy.h"
2005-06-20 16:24:54 +02:00
#include "support.h"
2005-10-27 23:10:15 +02:00
#include "team.h"
2005-05-13 20:20:47 +02:00
#include "user.h"
#include "variables.h"
2009-04-29 19:18:54 +02:00
void
debug_print_message(gchar *format, ...)
{
gchar text[SMALL];
va_list args;
gchar buf[SMALL];
const gchar *home;
FILE *fil = NULL;
GTimeVal logtime;
gchar *logtime_string;
if(format != NULL)
{
va_start (args, format);
g_vsprintf(buf, format, args);
va_end (args);
}
if(debug_output != DEBUG_OUT_LOGFILE)
g_warning("%s\n", buf);
if(debug_output != DEBUG_OUT_STDOUT)
{
g_get_current_time(&logtime);
logtime_string = g_time_val_to_iso8601(&logtime);
sprintf(text, "%s %s\n", logtime_string, buf);
g_free(logtime_string);
home = g_get_home_dir();
if(os_is_unix)
sprintf(buf, "%s%s%s%sbygfoot.log", home, G_DIR_SEPARATOR_S,
HOMEDIRNAME, G_DIR_SEPARATOR_S);
else
{
gchar *pwd = g_get_current_dir();
sprintf(buf, "%s%sbygfoot.log", pwd, G_DIR_SEPARATOR_S);
g_free(pwd);
}
fil = fopen(buf, "a");
if(fil == NULL)
{
g_warning("Couldn't open log file %s\n", buf);
return;
}
fprintf(fil, "%s\n", text);
fclose(fil);
}
}
2005-12-10 13:21:19 +01:00
/** Take some debug action depending on the text. Text is a prefix and a number. */
2005-05-13 20:20:47 +02:00
void
2005-12-10 13:21:19 +01:00
debug_action(const gchar *text)
2005-05-13 20:20:47 +02:00
{
#ifdef DEBUG
printf("debug_action\n");
#endif
2005-12-10 13:21:19 +01:00
gchar buf[SMALL];
gint value = -1;
2008-12-22 12:33:55 +01:00
gint i, j;
2005-12-10 13:21:19 +01:00
2008-11-06 09:03:09 +01:00
printf("debact: %s\n", text);
2005-12-10 13:21:19 +01:00
sscanf(text, "%[^-0-9]%d", buf, &value);
2005-05-13 20:20:47 +02:00
if(g_str_has_prefix(text, "deb"))
{
2009-04-29 19:18:54 +02:00
debug_level = value;
2005-07-08 11:26:00 +02:00
game_gui_print_message("Debug value set to %d.", value);
2005-05-13 20:20:47 +02:00
}
else if(g_str_has_prefix(text, "cap"))
{
current_user.tm->stadium.capacity += value;
2005-07-08 11:26:00 +02:00
game_gui_print_message("Stadium capacity changed by %d. New: %d.", value,
2009-04-29 19:18:54 +02:00
current_user.tm->stadium.capacity);
2005-05-13 20:20:47 +02:00
}
else if(g_str_has_prefix(text, "saf"))
{
current_user.tm->stadium.safety += ((gfloat)value / 100);
current_user.tm->stadium.safety =
CLAMP(current_user.tm->stadium.safety, 0, 1);
2005-07-08 11:26:00 +02:00
game_gui_print_message("Stadium safety changed by %d. New: %.2f", value,
2009-04-29 19:18:54 +02:00
current_user.tm->stadium.safety);
2005-05-13 20:20:47 +02:00
}
else if(g_str_has_prefix(text, "mon"))
{
current_user.money += value;
2005-07-08 11:26:00 +02:00
game_gui_print_message("Money changed by %d. New: %d.", value,
2009-04-29 19:18:54 +02:00
current_user.money);
2005-05-13 20:20:47 +02:00
}
2005-05-28 12:41:53 +02:00
else if(g_str_has_prefix(text, "suc"))
{
current_user.counters[COUNT_USER_SUCCESS] += value;
2005-07-08 11:26:00 +02:00
game_gui_print_message("Success counter changed by %d. New: %d.", value,
2009-04-29 19:18:54 +02:00
current_user.counters[COUNT_USER_SUCCESS]);
2005-05-28 12:41:53 +02:00
}
2005-07-15 14:42:57 +02:00
else if(g_str_has_prefix(text, "scout"))
{
current_user.scout = value;
game_gui_print_message("Scout changed to %d.", value);
}
else if(g_str_has_prefix(text, "phys"))
{
current_user.physio = value;
game_gui_print_message("Physio changed to %d.", value);
}
else if(g_str_has_prefix(text, "yc"))
{
current_user.youth_academy.coach = value;
game_gui_print_message("Youth coach changed to %d.", value);
}
else if(g_str_has_prefix(text, "pospref"))
{
current_user.youth_academy.pos_pref = value;
game_gui_print_message("Recruiting pref changed to %d.", value);
}
2005-08-14 21:03:11 +02:00
else if(g_str_has_prefix(text, "goto"))
{
2009-01-25 11:32:52 +01:00
if(debug < 50)
2009-04-29 19:18:54 +02:00
debug_level = 50;
2009-01-25 11:32:52 +01:00
if(option_int("int_opt_user_show_live_game", &current_user.options))
option_set_int("int_opt_user_show_live_game", &current_user.options, 0);
2009-01-09 15:32:34 +01:00
sett_set_int("int_opt_goto_mode", 1);
2009-01-10 11:41:27 +01:00
if(value < 100)
while(week < value)
2009-01-11 11:23:55 +01:00
{
2009-01-10 11:41:27 +01:00
on_button_new_week_clicked(NULL, NULL);
2009-01-11 11:23:55 +01:00
game_gui_set_main_window_header();
while (gtk_events_pending ())
gtk_main_iteration ();
}
2009-01-10 11:41:27 +01:00
else
while(season < value - 100)
2009-01-11 11:23:55 +01:00
{
2009-01-10 11:41:27 +01:00
on_button_new_week_clicked(NULL, NULL);
2009-01-11 11:23:55 +01:00
game_gui_set_main_window_header();
while (gtk_events_pending ())
gtk_main_iteration ();
}
2009-01-09 15:32:34 +01:00
sett_set_int("int_opt_goto_mode", 0);
2005-08-14 21:03:11 +02:00
}
2005-08-27 18:17:50 +02:00
else if(g_str_has_prefix(text, "testcom") ||
g_str_has_prefix(text, "tc"))
{
2005-08-28 13:35:21 +02:00
stat5 = -value - 1000;
2005-08-27 18:17:50 +02:00
game_gui_print_message("Commentary type displayed: %d.", value);
}
2008-12-22 12:33:55 +01:00
else if(g_str_has_prefix(text, "printweeks"))
{
for(i = 0; i < cps->len; i++)
{
if(cp(i).add_week != 1000)
{
g_print("Cup: %s\n", cp(i).name);
for(j = 0; j < cp(i).rounds->len; j++)
g_print(" Round %2d: Week %2d (w/o delay: %2d)\n",
j, cup_get_first_week_of_cup_round(&cp(i), j, TRUE),
cup_get_first_week_of_cup_round(&cp(i), j, FALSE));
}
}
}
2005-05-28 12:41:53 +02:00
else if(g_str_has_prefix(text, "help"))
{
2005-12-14 15:05:59 +01:00
g_print("Debug options:\n"
2009-04-29 19:18:54 +02:00
"deb \t set debug value\n"
"writer \t set debug-writer value\n"
"cap \t change stadium capacity\n"
"saf \t change stadium safety\n"
"mon \t change money\n"
"suc \t change success counter\n"
"scout \t change scout\n"
"physio \t change physio\n"
"printweeks \t print the starting weeks of all cup rounds\n"
"youth coach \t change youth coach\n"
"pospref \t change recruiting pref\n"
"goto \t Press 'new week' automatically until\n"
" \t the appropriate week is reached\n"
" \t Supply 100+X to go to season X (e.g. 102)\n"
"testcom|tc \t Test a specific live game commentary.\n"
" \t Find the numbers in live_game_struct.h (LiveGameEventType)\n"
" \t Use 'goto' afterwards.\n"
"help \t display this help\n");
2005-05-28 12:41:53 +02:00
}
2005-05-13 20:20:47 +02:00
2005-06-20 16:24:54 +02:00
setsav0;
2005-05-13 20:20:47 +02:00
}
gboolean
debug_reset_counter(gpointer data)
{
#ifdef DEBUG
printf("debug_reset_counter\n");
#endif
2005-05-13 20:20:47 +02:00
counters[COUNT_SHOW_DEBUG] = 0;
return FALSE;
}
2005-10-27 23:10:15 +02:00
void
debug_calibrate_betting_odds(gint skilldiffmax, gint matches_per_skilldiff)
{
#ifdef DEBUG
printf("debug_calibrate_betting_odds\n");
#endif
2005-10-27 23:10:15 +02:00
gint i, skilldiff, matches;
Fixture *fix = &g_array_index(lig(0).fixtures, Fixture, 0);
2008-12-01 21:39:16 +01:00
LiveGame live_game;
2005-10-27 23:10:15 +02:00
fix->home_advantage = FALSE;
for(skilldiff=0;skilldiff<=skilldiffmax;skilldiff++)
{
gint res[3] = {0, 0, 0};
for(matches=0;matches<matches_per_skilldiff;matches++)
{
fix->attendance = -1;
fix->result[0][0] = fix->result[1][0] = 0;
for(i=0;i<fix->teams[0]->players->len;i++)
{
strategy_repair_player(&g_array_index(fix->teams[0]->players, Player, i));
strategy_repair_player(&g_array_index(fix->teams[1]->players, Player, i));
g_array_index(fix->teams[0]->players, Player, i).skill = 90;
g_array_index(fix->teams[1]->players, Player, i).skill = 90 - skilldiff;
g_array_index(fix->teams[0]->players, Player, i).fitness = 0.9;
g_array_index(fix->teams[1]->players, Player, i).fitness = 0.9;
}
2008-12-01 21:39:16 +01:00
live_game_calculate_fixture(fix, &live_game);
2005-10-27 23:10:15 +02:00
if(fix->result[0][0] < fix->result[1][0])
res[2]++;
else
res[(fix->result[0][0] == fix->result[1][0])]++;
}
2005-12-14 15:05:59 +01:00
g_print("sd %3d res %3d %3d %3d prob %.2f %.2f %.2f\n", skilldiff,
res[0], res[1], res[2], (gfloat)res[0] / (gfloat)matches,
(gfloat)res[1] / (gfloat)matches, (gfloat)res[2] / (gfloat)matches);
2005-10-27 23:10:15 +02:00
}
}
2005-11-26 17:52:51 +01:00
/** Check whether the 4 forwards, boost on, style all-out-attack
easter egg should be activated. */
gboolean
debug_egg_forwards_boost_style(void)
{
#ifdef DEBUG
printf("debug_egg_forwards_boost_style\n");
#endif
2005-11-26 17:52:51 +01:00
gint i, fwds = 0;
if(current_user.tm->boost != 1 ||
current_user.tm->style != 2 ||
current_user.tm->players->len < 11)
return FALSE;
for(i=0;i<11;i++)
if(g_array_index(current_user.tm->players, Player, i).cpos == 3 &&
g_array_index(current_user.tm->players, Player, i).cskill > 0)
fwds++;
return (fwds > 3);
}