2005-03-03 13:46:48 +01:00
# include "callback_func.h"
2005-03-19 21:04:08 +01:00
# include "callbacks.h"
2005-03-03 13:46:48 +01:00
# include "cup.h"
2005-03-17 21:26:01 +01:00
# include "finance.h"
2005-03-03 13:46:48 +01:00
# include "fixture.h"
# include "game_gui.h"
# include "league.h"
# include "live_game.h"
2005-03-25 11:54:54 +01:00
# include "maths.h"
2005-03-17 21:26:01 +01:00
# include "misc.h"
2005-03-03 13:46:48 +01:00
# include "option.h"
# include "player.h"
# include "start_end.h"
# include "team.h"
2005-03-19 21:04:08 +01:00
# include "transfer.h"
2005-03-03 13:46:48 +01:00
# include "treeview.h"
# include "user.h"
# include "window.h"
/** Show the users' live games. */
void
callback_show_next_live_game ( void )
{
gint i , j ;
2005-03-08 09:25:46 +01:00
stat0 = STATUS_SHOW_LIVE_GAME ;
2005-03-03 13:46:48 +01:00
if ( week_round = = 1 )
{
for ( i = 0 ; i < ligs - > len ; i + + )
for ( j = 0 ; j < lig ( i ) . fixtures - > len ; j + + )
if ( g_array_index ( lig ( i ) . fixtures , Fixture , j ) . week_number = = week & &
g_array_index ( lig ( i ) . fixtures , Fixture , j ) . week_round_number = = week_round & &
fixture_user_team_involved ( & g_array_index ( lig ( i ) . fixtures , Fixture , j ) ) ! = - 1 & &
2005-03-13 16:46:15 +01:00
g_array_index ( lig ( i ) . fixtures , Fixture , j ) . attendance = = - 1 & &
option_int ( " int_opt_user_show_live_game " ,
2005-03-23 20:03:26 +01:00
& usr ( fixture_user_team_involved ( & g_array_index ( lig ( i ) . fixtures , Fixture , j ) ) ) .
2005-03-13 16:46:15 +01:00
options ) )
2005-03-03 13:46:48 +01:00
{
live_game_calculate_fixture ( & g_array_index ( lig ( i ) . fixtures , Fixture , j ) ) ;
return ;
}
}
else
{
for ( i = 0 ; i < cps - > len ; i + + )
for ( j = 0 ; j < cp ( i ) . fixtures - > len ; j + + )
if ( g_array_index ( cp ( i ) . fixtures , Fixture , j ) . week_number = = week & &
g_array_index ( cp ( i ) . fixtures , Fixture , j ) . week_round_number = = week_round & &
2005-03-08 09:25:46 +01:00
fixture_user_team_involved ( & g_array_index ( cp ( i ) . fixtures , Fixture , j ) ) ! = - 1 & &
2005-03-16 21:48:25 +01:00
g_array_index ( cp ( i ) . fixtures , Fixture , j ) . attendance = = - 1 & &
option_int ( " int_opt_user_show_live_game " ,
2005-03-23 20:03:26 +01:00
& usr ( fixture_user_team_involved ( & g_array_index ( cp ( i ) . fixtures , Fixture , j ) ) ) .
2005-03-16 21:48:25 +01:00
options ) )
2005-03-03 13:46:48 +01:00
{
live_game_calculate_fixture ( & g_array_index ( cp ( i ) . fixtures , Fixture , j ) ) ;
return ;
}
}
2005-03-08 09:25:46 +01:00
window_destroy ( & window . live , TRUE ) ;
2005-03-03 13:46:48 +01:00
/* no more user games to show: end round. */
end_week_round ( ) ;
}
/** Handle a click on the player list.
@ param idx The player number .
@ param event The type of button click . */
void
callback_player_clicked ( gint idx , GdkEventButton * event )
{
2005-03-20 21:49:55 +01:00
gchar buf [ SMALL ] ;
/* Only accept single-clicks right now. */
2005-03-03 13:46:48 +01:00
if ( event - > type ! = GDK_BUTTON_PRESS )
return ;
if ( event - > button = = 1 )
{
if ( selected_row [ 0 ] = = - 1 )
{
selected_row [ 0 ] = idx ;
return ;
}
2005-03-18 23:03:23 +01:00
player_swap ( current_user . tm , selected_row [ 0 ] ,
current_user . tm , idx ) ;
2005-03-13 16:46:15 +01:00
if ( opt_user_int ( " int_opt_user_swap_adapts " ) = = 1 & &
2005-03-18 23:03:23 +01:00
current_user . tm - > structure ! =
team_find_appropriate_structure ( current_user . tm ) )
2005-03-03 13:46:48 +01:00
{
2005-03-18 23:03:23 +01:00
team_change_structure ( current_user . tm ,
team_find_appropriate_structure ( current_user . tm ) ) ;
team_rearrange ( current_user . tm ) ;
2005-03-03 13:46:48 +01:00
}
2005-03-24 19:04:31 +01:00
2005-03-03 13:46:48 +01:00
game_gui_write_av_skills ( ) ;
selected_row [ 0 ] = - 1 ;
2005-03-24 21:22:44 +01:00
treeview_show_user_player_list ( ) ;
2005-03-25 21:18:35 +01:00
treeview_show_next_opponent ( ) ;
2005-03-03 13:46:48 +01:00
}
2005-03-20 21:49:55 +01:00
else if ( event - > button = = 3 )
{
if ( stat0 = = STATUS_SHOW_TRANSFER_LIST )
{
selected_row [ 0 ] = - 1 ;
if ( ! query_transfer_player_is_on_list ( player_of ( current_user . tm , idx ) ) )
{
transfer_add_player ( player_of ( current_user . tm , idx ) ,
( gint ) rint ( ( ( gfloat ) const_int ( " int_transfer_time_lower " ) +
( gfloat ) const_int ( " int_transfer_time_upper " ) ) / 2 ) ) ;
sprintf ( buf , _ ( " %s has been added to the transfer list for %d weeks. " ) ,
player_of ( current_user . tm , idx ) - > name - > str ,
( gint ) rint ( ( ( gfloat ) const_int ( " int_transfer_time_lower " ) +
( gfloat ) const_int ( " int_transfer_time_upper " ) ) / 2 ) ) ;
game_gui_print_message ( buf ) ;
}
else
transfer_remove_player_ptr ( player_of ( current_user . tm , idx ) ) ;
treeview_show_transfer_list ( GTK_TREE_VIEW ( lookup_widget ( window . main , " treeview_right " ) ) ) ;
}
}
2005-03-03 13:46:48 +01:00
}
2005-03-11 18:18:51 +01:00
/** Show the last match of the current user. */
void
callback_show_last_match ( void )
{
gint i ;
2005-03-18 23:03:23 +01:00
if ( current_user . live_game . units = = NULL )
2005-03-11 18:18:51 +01:00
{
game_gui_show_warning ( " No match to show. " ) ;
return ;
}
2005-03-18 23:03:23 +01:00
stat2 = cur_user ;
2005-03-11 18:18:51 +01:00
window_create ( WINDOW_LIVE ) ;
treeview_show_game_stats ( GTK_TREE_VIEW ( lookup_widget ( window . live , " treeview_stats " ) ) ,
2005-03-18 23:03:23 +01:00
& current_user . live_game ) ;
live_game_set_match ( & current_user . live_game ) ;
2005-03-11 18:18:51 +01:00
2005-03-18 23:03:23 +01:00
for ( i = 0 ; i < current_user . live_game . units - > len ; i + + )
game_gui_live_game_show_unit ( & g_array_index ( current_user . live_game . units , LiveGameUnit , i ) ) ;
2005-03-11 18:18:51 +01:00
}
2005-03-14 18:47:27 +01:00
/** Show some fixtures.
@ param type An integer telling us which league / cup and which
week and round to show . */
void
callback_show_fixtures ( gint type )
{
const Fixture * fix = fixture_get ( type , stat1 , stat2 , stat3 ,
2005-03-18 23:03:23 +01:00
current_user . tm ) ;
2005-03-14 18:47:27 +01:00
treeview_show_fixtures ( GTK_TREE_VIEW ( lookup_widget ( window . main , " treeview_right " ) ) ,
fix - > clid , fix - > week_number , fix - > week_round_number ) ;
stat1 = fix - > clid ;
stat2 = fix - > week_number ;
stat3 = fix - > week_round_number ;
}
2005-03-15 16:10:57 +01:00
/** Show tables.
@ type Integer telling us whether to show the current user ' s
tables or those of the previous / next league / cup . */
void
callback_show_tables ( gint type )
{
gint clid = - 1 ;
if ( type = = SHOW_CURRENT )
2005-03-18 23:03:23 +01:00
clid = current_user . tm - > clid ;
2005-03-15 16:10:57 +01:00
else if ( type = = SHOW_NEXT_LEAGUE )
{
clid = league_cup_get_next_clid ( stat1 ) ;
while ( clid > = ID_CUP_START & & cup_from_clid ( clid ) - > tables - > len = = 0 )
clid = league_cup_get_next_clid ( clid ) ;
}
else if ( type = = SHOW_PREVIOUS_LEAGUE )
{
clid = league_cup_get_previous_clid ( stat1 ) ;
while ( clid > = ID_CUP_START & & cup_from_clid ( clid ) - > tables - > len = = 0 )
clid = league_cup_get_previous_clid ( clid ) ;
}
stat1 = clid ;
treeview_show_table ( GTK_TREE_VIEW ( lookup_widget ( window . main , " treeview_right " ) ) , clid ) ;
}
2005-03-17 21:26:01 +01:00
/** Open the digits window to get a loan. */
void
callback_get_loan ( void )
{
gchar buf [ SMALL ] , buf2 [ SMALL ] ;
gint max_loan =
2005-03-18 23:03:23 +01:00
finance_team_drawing_credit_loan ( current_user . tm , TRUE ) + current_user . debt ;
2005-03-17 21:26:01 +01:00
if ( max_loan < = 0 )
{
game_gui_print_message ( _ ( " The bank doesn't grant you more money. " ) ) ;
return ;
}
stat0 = STATUS_GET_LOAN ;
misc_print_grouped_int ( max_loan , buf2 , FALSE ) ;
sprintf ( buf , _ ( " You can take out at most %s. " ) , buf2 ) ;
window_show_digits ( buf , _ ( " Loan " ) , max_loan , NULL , 0 ) ;
}
/** Open the digits window to pay back a loan. */
void
callback_pay_loan ( void )
{
gchar buf [ SMALL ] , buf2 [ SMALL ] ;
2005-03-18 23:03:23 +01:00
gint max_payback = MIN ( BUDGET ( cur_user ) , - current_user . debt ) ;
2005-03-17 21:26:01 +01:00
2005-03-18 23:03:23 +01:00
if ( current_user . debt = = 0 )
2005-03-17 21:26:01 +01:00
{
game_gui_print_message ( _ ( " You are not indebted. " ) ) ;
return ;
}
if ( max_payback < = 0 )
{
game_gui_print_message ( _ ( " You don't have enough money to pay back. " ) ) ;
return ;
}
stat0 = STATUS_PAY_LOAN ;
misc_print_grouped_int ( max_payback , buf2 , FALSE ) ;
sprintf ( buf , _ ( " You can pay back at most %s " ) , buf2 ) ;
window_show_digits ( buf , _ ( " Payback " ) , max_payback , NULL , 0 ) ;
}
2005-03-19 21:04:08 +01:00
/** Handle a click on the transfer list.
@ param idx The index of the selected player in the transfer list . */
void
callback_transfer_list_clicked ( gint idx )
{
gchar buf [ SMALL ] ;
Transfer * tr = & trans ( idx ) ;
2005-03-20 21:49:55 +01:00
if ( tr - > tm = = current_user . tm )
2005-03-19 21:04:08 +01:00
{
transfer_remove_player ( idx ) ;
on_button_transfers_clicked ( NULL , NULL ) ;
return ;
}
if ( current_user . tm - > players - > len = = const_int ( " int_team_max_players " ) )
{
game_gui_show_warning ( _ ( " Your roster is already full. You can't buy more players. " ) ) ;
return ;
}
sprintf ( buf , _ ( " You are making an offer for %s. Your scout's recommendations for value and wage are preset. " ) ,
2005-03-20 21:49:55 +01:00
player_of_id ( tr - > tm , tr - > id ) - > name - > str ) ;
2005-03-19 21:04:08 +01:00
stat1 = idx ;
window_show_digits ( buf , _ ( " Fee " ) , tr - > fee [ current_user . scout % 10 ] ,
_ ( " Wage " ) , tr - > wage [ current_user . scout % 10 ] ) ;
}
2005-03-25 11:54:54 +01:00
/** Show the contract window for the player with the specified index. */
void
callback_offer_new_contract ( gint idx )
{
gint i ;
gchar buf [ SMALL ] ;
Player * pl = player_of ( current_user . tm , idx ) ;
gfloat scout_dev = math_rnd ( - const_float ( " float_transfer_scout_deviance_wage " ) ,
const_float ( " float_transfer_scout_deviance_wage " ) ) *
( current_user . scout % 10 + 1 ) ;
GtkSpinButton * spinbuttons [ 4 ] ;
if ( pl - > contract > = 2 )
{
game_gui_print_message ( _ ( " You can't offer a new contract if the old one is still above 2 years. " ) ) ;
return ;
}
2005-03-25 12:44:49 +01:00
else if ( pl - > offers = = const_int ( " int_contract_max_offers " ) )
{
game_gui_print_message ( _ ( " The player won't negotiate with you anymore. " ) ) ;
return ;
}
2005-03-25 11:54:54 +01:00
stat1 = player_assign_wage ( pl ) ;
2005-03-25 12:44:49 +01:00
statp = ( gpointer ) pl ;
2005-03-25 11:54:54 +01:00
if ( pl - > age < pl - > peak_age )
stat1 = MAX ( stat1 , pl - > wage ) ;
else
stat1 = MIN ( stat1 , pl - > wage ) ;
window_create ( WINDOW_CONTRACT ) ;
2005-03-25 12:44:49 +01:00
sprintf ( buf , " You are negotiating with %s about a new contract. Pay attention to what you're doing; if you don't come to terms with him within %d offers, he's going to leave your team after his current contract expires (unless you sell him). \n Your scout's recommendations are preset: " , pl - > name - > str ,
const_int ( " int_contract_max_offers " ) ) ;
2005-03-25 11:54:54 +01:00
gtk_label_set_text ( GTK_LABEL ( lookup_widget ( window . contract , " label_contract " ) ) , buf ) ;
for ( i = 0 ; i < 4 ; i + + )
{
sprintf ( buf , " spinbutton_contract%d " , i + 1 ) ;
spinbuttons [ i ] = GTK_SPIN_BUTTON ( lookup_widget ( window . contract , buf ) ) ;
gtk_spin_button_set_value ( spinbuttons [ i ] ,
rint ( ( gfloat ) stat1 *
( 1 + ( i * const_float ( " float_contract_scale_factor " ) *
powf ( - 1 , ( pl - > age > pl - > peak_age ) ) ) ) *
( 1 + scout_dev ) ) ) ;
}
}
2005-03-25 21:18:35 +01:00
/** Show the player list of a team in the browse-teams mode. */
void
callback_show_team ( gint type )
{
GtkTreeView * treeview_right = GTK_TREE_VIEW ( lookup_widget ( window . main , " treeview_right " ) ) ;
const Team * tm ;
if ( type = = SHOW_CURRENT )
{
tm = ( const Team * ) treeview_get_pointer ( treeview_right , 2 ) ;
stat1 = team_get_index ( tm ) ;
}
else if ( type = = SHOW_NEXT )
{
stat1 = ( stat1 = = ( ( GArray * ) statp ) - > len - 1 ) ? 0 : stat1 + 1 ;
tm = & g_array_index ( ( GArray * ) statp , Team , stat1 ) ;
}
else if ( type = = SHOW_PREVIOUS )
{
stat1 = ( stat1 = = 0 ) ? ( ( GArray * ) statp ) - > len - 1 : stat1 - 1 ;
tm = & g_array_index ( ( GArray * ) statp , Team , stat1 ) ;
}
else
{
if ( type = = SHOW_NEXT_LEAGUE )
stat2 = league_cup_get_next_clid ( stat2 ) ;
else
stat2 = league_cup_get_previous_clid ( stat2 ) ;
statp = ( gpointer ) ( stat2 < ID_CUP_START ) ?
league_from_clid ( stat2 ) - > teams :
cup_from_clid ( stat2 ) - > teams ;
stat1 = 0 ;
tm = & g_array_index ( ( GArray * ) statp , Team , stat1 ) ;
}
stat0 = STATUS_BROWSE_TEAMS ;
stat2 = tm - > clid ;
statp = ( gpointer ) ( tm - > clid < ID_CUP_START ) ?
league_from_clid ( tm - > clid ) - > teams :
cup_from_clid ( tm - > clid ) - > teams ;
if ( tm ! = current_user . tm )
treeview_show_player_list_team ( treeview_right , tm , current_user . scout % 10 ) ;
else
callback_show_team ( ( type = = SHOW_PREVIOUS ) ? SHOW_PREVIOUS : SHOW_NEXT ) ;
}