2005-10-20 15:45:00 +00:00
/*
2005-11-26 16:52:51 +00:00
misc2_callback_func . c
2005-10-20 15:45:00 +00:00
Bygfoot Football Manager - - a small and simple GTK2 - based
football management game .
http : //bygfoot.sourceforge.net
Copyright ( C ) 2005 Gyözö Both ( gyboth @ bygfoot . com )
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 .
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 .
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-05-28 08:19:56 +00:00
# include "callbacks.h"
2005-08-22 13:37:02 +00:00
# include "callback_func.h"
2005-03-27 17:59:57 +00:00
# include "file.h"
2005-03-21 11:52:41 +00:00
# include "finance.h"
2005-08-22 13:37:02 +00:00
# include "free.h"
2005-03-21 11:52:41 +00:00
# include "game_gui.h"
2005-12-01 14:49:00 +00:00
# include "job.h"
2005-12-01 11:50:54 +00:00
# include "league.h"
2005-03-21 11:52:41 +00:00
# include "maths.h"
2005-10-09 09:35:44 +00:00
# include "misc.h"
2005-03-21 11:52:41 +00:00
# include "misc2_callback_func.h"
# include "option.h"
# include "player.h"
2005-03-25 20:18:35 +00:00
# include "support.h"
2005-03-21 11:52:41 +00:00
# include "team.h"
# include "treeview.h"
2005-08-22 13:37:02 +00:00
# include "treeview2.h"
2005-04-16 07:46:04 +00:00
# include "treeview_helper.h"
2005-03-21 11:52:41 +00:00
# include "transfer.h"
# include "user.h"
2005-03-25 20:18:35 +00:00
# include "window.h"
2005-03-21 11:52:41 +00:00
/** Transfer a user player. */
void
misc2_callback_transfer_user_player ( void )
{
2005-04-07 16:44:33 +00:00
Team * new_team = transoff ( stat2 , 0 ) . tm ;
2005-03-21 11:52:41 +00:00
2007-02-20 14:06:58 +00:00
if ( current_user . tm - > players - > len - 1 < const_int ( " int_team_min_players " ) )
2005-03-21 11:52:41 +00:00
{
2007-02-20 14:06:58 +00:00
game_gui_show_warning ( _ ( " Your team can't have less than 11 players. " ) ) ;
2005-03-21 11:52:41 +00:00
}
else
2007-02-20 14:06:58 +00:00
{
if ( team_is_user ( new_team ) ! = - 1 )
{
if ( ( new_team - > players - > len < const_int ( " int_team_max_players " ) ) & &
( BUDGET ( team_is_user ( new_team ) ) > = transoff ( stat2 , 0 ) . fee ) )
{
current_user . money + = transoff ( stat2 , 0 ) . fee ;
current_user . money_in [ 1 ] [ MON_IN_TRANSFERS ] + = transoff ( stat2 , 0 ) . fee ;
user_from_team ( new_team ) - > money - = transoff ( stat2 , 0 ) . fee ;
user_from_team ( new_team ) - > money_out [ 1 ] [ MON_OUT_TRANSFERS ] - =
transoff ( stat2 , 0 ) . fee ;
if ( player_of_id_team ( trans ( stat2 ) . tm , trans ( stat2 ) . id ) - > id = =
opt_user_int ( " int_opt_user_penalty_shooter " ) )
opt_user_set_int ( " int_opt_user_penalty_shooter " , - 1 ) ;
player_copy ( player_of_id_team ( trans ( stat2 ) . tm , trans ( stat2 ) . id ) ,
new_team , new_team - > players - > len ) ;
player_of_idx_team ( new_team , new_team - > players - > len - 1 ) - > contract =
( gfloat ) math_rndi ( const_int ( " int_transfer_contract_lower " ) ,
const_int ( " int_transfer_contract_upper " ) ) ;
player_of_idx_team ( new_team , new_team - > players - > len - 1 ) - > wage =
transoff ( stat2 , 0 ) . wage ;
g_array_remove_index ( current_user . tm - > players ,
player_id_index ( current_user . tm , trans ( stat2 ) . id ) ) ;
transfer_remove_player ( stat2 ) ;
}
else
{
game_gui_show_warning ( _ ( " %s couldn't afford to buy %s or his roster was full. " ) ,
user_from_team ( new_team ) - > name ,
player_of_id_team ( trans ( stat2 ) . tm , trans ( stat2 ) . id ) - > name ) ;
user_event_add ( user_from_team ( new_team ) , EVENT_TYPE_WARNING , - 1 , - 1 , NULL ,
_ ( " You didn't have enough money to buy %s or your roster was full. " ) ,
player_of_id_team ( trans ( stat2 ) . tm , trans ( stat2 ) . id ) - > name ) ;
g_array_remove_index ( trans ( stat2 ) . offers , 0 ) ;
if ( trans ( stat2 ) . offers - > len > 0 & & transoff ( stat2 , 0 ) . status = = TRANSFER_OFFER_NOT_CONSIDERED )
transoff ( stat2 , 0 ) . status = TRANSFER_OFFER_ACCEPTED ;
}
}
else
{
current_user . money + = transoff ( stat2 , 0 ) . fee ;
current_user . money_in [ 1 ] [ MON_IN_TRANSFERS ] + = transoff ( stat2 , 0 ) . fee ;
player_remove_from_team ( current_user . tm , player_id_index ( current_user . tm , trans ( stat2 ) . id ) ) ;
}
2005-03-21 11:52:41 +00:00
}
2005-03-24 20:22:44 +00:00
treeview_show_user_player_list ( ) ;
2005-03-21 11:52:41 +00:00
game_gui_set_main_window_header ( ) ;
2005-05-28 08:19:56 +00:00
on_button_transfers_clicked ( NULL , NULL ) ;
2005-03-21 11:52:41 +00:00
}
2005-03-24 18:04:31 +00:00
2005-05-27 18:48:36 +00:00
/** Transfer a cpu player to a user team. */
void
misc2_callback_transfer_cpu_player ( void )
{
2005-05-30 15:59:41 +00:00
if ( current_user . tm - > players - > len > const_int ( " int_team_max_players " ) | |
BUDGET ( cur_user ) < transoff ( stat2 , 0 ) . fee )
{
game_gui_show_warning ( _ ( " Your player roster is full or you don't enough money. " ) ) ;
return ;
}
2005-05-27 18:48:36 +00:00
player_copy ( player_of_id_team ( trans ( stat2 ) . tm , trans ( stat2 ) . id ) ,
current_user . tm , current_user . tm - > players - > len ) ;
player_of_idx_team ( current_user . tm , current_user . tm - > players - > len - 1 ) - > contract =
( gfloat ) math_rndi ( const_int ( " int_transfer_contract_lower " ) ,
const_int ( " int_transfer_contract_upper " ) ) ;
player_of_idx_team ( current_user . tm , current_user . tm - > players - > len - 1 ) - > wage =
transoff ( stat2 , 0 ) . wage ;
user_from_team ( current_user . tm ) - > money - = transoff ( stat2 , 0 ) . fee ;
user_from_team ( current_user . tm ) - > money_out [ 1 ] [ MON_OUT_TRANSFERS ] - =
transoff ( stat2 , 0 ) . fee ;
player_replace_by_new ( player_of_id_team ( trans ( stat2 ) . tm , trans ( stat2 ) . id ) , FALSE ) ;
transfer_remove_player ( stat2 ) ;
treeview_show_user_player_list ( ) ;
game_gui_set_main_window_header ( ) ;
2005-07-06 15:48:02 +00:00
if ( week < transfer_get_deadline ( ) | | transfer_list - > len > 0 )
on_button_transfers_clicked ( NULL , NULL ) ;
else
on_button_back_to_main_clicked ( NULL , NULL ) ;
2005-05-27 18:48:36 +00:00
}
2005-03-24 18:04:31 +00:00
/** Change the user team's structure to a value he's specified. */
2005-04-06 10:19:43 +00:00
gboolean
2005-03-24 18:04:31 +00:00
misc2_callback_change_structure ( gint structure )
{
2005-06-15 08:22:40 +00:00
gint poss_struct = team_find_appropriate_structure ( current_user . tm ) ;
2005-03-24 18:04:31 +00:00
if ( math_get_place ( structure , 1 ) + math_get_place ( structure , 2 ) +
2005-06-15 08:22:40 +00:00
math_get_place ( structure , 3 ) ! =
math_get_place ( poss_struct , 1 ) + math_get_place ( poss_struct , 2 ) +
math_get_place ( poss_struct , 3 ) )
2005-03-24 18:04:31 +00:00
{
2005-07-08 09:26:00 +00:00
game_gui_show_warning ( _ ( " The structure value %d is invalid. " ) , structure ) ;
2005-04-06 10:19:43 +00:00
return FALSE ;
2005-03-24 18:04:31 +00:00
}
team_change_structure ( current_user . tm , structure ) ;
2005-03-24 20:22:44 +00:00
treeview_show_user_player_list ( ) ;
2005-04-06 10:19:43 +00:00
2005-04-07 16:44:33 +00:00
setsav0 ;
2005-04-06 10:19:43 +00:00
return TRUE ;
2005-03-24 18:04:31 +00:00
}
2005-03-25 20:18:35 +00:00
/** Handle a click on the contract offer button. */
void
misc2_callback_contract_offer ( void )
{
gint i ;
gchar buf [ SMALL ] ;
GtkSpinButton * spinbutton ;
gint value = 0 ;
Player * pl = ( Player * ) statp ;
2005-07-05 18:37:26 +00:00
gtk_widget_set_sensitive ( lookup_widget ( window . contract , " button_contract_cancel " ) , FALSE ) ;
2005-03-25 20:18:35 +00:00
for ( i = 0 ; i < 4 ; i + + )
{
sprintf ( buf , " radiobutton_contract%d " , i + 1 ) ;
if ( gtk_toggle_button_get_active (
GTK_TOGGLE_BUTTON ( lookup_widget ( window . contract , buf ) ) ) )
{
sprintf ( buf , " spinbutton_contract%d " , i + 1 ) ;
spinbutton = GTK_SPIN_BUTTON ( lookup_widget ( window . contract , buf ) ) ;
value = gtk_spin_button_get_value_as_int ( spinbutton ) ;
if ( value > = ( gint ) rint ( ( gfloat ) stat1 *
( 1 + ( i * const_float ( " float_contract_scale_factor " ) *
powf ( - 1 , ( pl - > age > pl - > peak_age ) ) ) ) ) )
{
pl - > contract + = ( i + 1 ) ;
2005-08-04 12:37:50 +00:00
pl - > offers = 0 ;
2005-03-25 20:18:35 +00:00
pl - > wage = value ;
2005-10-09 09:35:44 +00:00
game_gui_show_warning ( _ ( " %s accepts your offer. " ) , pl - > name ) ;
2006-03-26 14:14:45 +00:00
window_destroy ( & window . contract ) ;
2005-03-25 20:18:35 +00:00
}
else
{
pl - > offers + + ;
if ( pl - > offers < const_int ( " int_contract_max_offers " ) )
2005-07-08 09:26:00 +00:00
game_gui_show_warning ( _ ( " %s rejects your offer. You may still make %d offers. " ) ,
2005-10-09 09:35:44 +00:00
pl - > name ,
2005-07-08 09:26:00 +00:00
const_int ( " int_contract_max_offers " ) - pl - > offers ) ;
2005-03-25 20:18:35 +00:00
else
{
2005-07-08 09:26:00 +00:00
game_gui_show_warning ( _ ( " %s rejects your offer and won't negotiate with you anymore. You should sell him before his contract expires (he'll simply leave your team otherwise). " ) ,
2005-10-09 09:35:44 +00:00
pl - > name ) ;
2006-03-26 14:14:45 +00:00
window_destroy ( & window . contract ) ;
2005-03-25 20:18:35 +00:00
}
}
break ;
}
}
}
2005-03-27 17:59:57 +00:00
/** Add a user to the users array. */
void
misc2_callback_add_user ( void )
{
GtkTreeView * treeview_user_management_teams =
2005-12-01 14:49:00 +00:00
GTK_TREE_VIEW ( lookup_widget ( window . user_management ,
" treeview_user_management_teams " ) ) ;
2005-03-27 17:59:57 +00:00
GtkEntry * entry_user_management =
GTK_ENTRY ( lookup_widget ( window . user_management , " entry_user_management " ) ) ;
const gchar * user_name = gtk_entry_get_text ( entry_user_management ) ;
User new_user = user_new ( ) ;
2005-04-16 07:46:04 +00:00
Team * tm = ( Team * ) treeview_helper_get_pointer ( treeview_user_management_teams , 2 ) ;
2005-03-27 17:59:57 +00:00
if ( strlen ( user_name ) > 0 )
2005-12-01 14:49:00 +00:00
{
misc_string_assign ( & new_user . name , user_name ) ;
gtk_entry_set_text ( entry_user_management , " " ) ;
}
2005-03-27 17:59:57 +00:00
2005-04-13 13:01:59 +00:00
new_user . tm = tm ;
new_user . team_id = tm - > id ;
2005-03-27 17:59:57 +00:00
2005-12-01 11:50:54 +00:00
user_history_add ( & new_user , USER_HISTORY_START_GAME ,
tm - > name , league_cup_get_name_string ( tm - > clid ) ,
NULL , NULL ) ;
2005-04-16 07:46:04 +00:00
2005-03-27 17:59:57 +00:00
g_array_append_val ( users , new_user ) ;
file_load_user_conf_file ( & usr ( users - > len - 1 ) ) ;
2007-09-01 11:28:09 +00:00
user_set_up_team ( & usr ( users - > len - 1 ) , TRUE ) ;
2005-12-01 14:49:00 +00:00
treeview_show_users (
GTK_TREE_VIEW ( lookup_widget ( window . user_management ,
" treeview_user_management_users " ) ) ) ;
2005-03-27 17:59:57 +00:00
treeview_show_team_list ( treeview_user_management_teams , FALSE , FALSE ) ;
2005-04-07 16:44:33 +00:00
setsav0 ;
2005-03-27 17:59:57 +00:00
}
2005-08-22 13:37:02 +00:00
/** Handle a click in the MM window treeview.
@ param widget The treeview widget .
@ param row_num The row that ' s been clicked on .
@ param col_num The column number . */
void
misc2_callback_mmatches_button_press ( GtkWidget * widget , gint row_num , gint col_num )
{
if ( row_num < current_user . mmatches - > len )
{
if ( col_num = = TREEVIEW_MMATCH_COL_REPLAY )
{
stat1 = STATUS_SHOW_LAST_MATCH ;
stat3 = 0 ;
2006-03-26 14:14:45 +00:00
callback_show_last_match (
TRUE ,
& g_array_index ( current_user . mmatches , MemMatch , row_num ) . lg ) ;
2005-08-22 13:37:02 +00:00
}
else if ( col_num = = TREEVIEW_MMATCH_COL_REMOVE )
{
gtk_widget_hide ( widget ) ;
2006-03-26 14:14:45 +00:00
free_g_string ( & g_array_index ( current_user . mmatches , MemMatch , row_num ) .
competition_name ) ;
free_gchar_ptr ( g_array_index ( current_user . mmatches , MemMatch , row_num ) .
country_name ) ;
2005-08-22 13:37:02 +00:00
free_live_game ( & g_array_index ( current_user . mmatches , MemMatch , row_num ) . lg ) ;
g_array_remove_index ( current_user . mmatches , row_num ) ;
treeview2_show_mmatches ( ) ;
gtk_widget_show ( widget ) ;
}
else if ( col_num = = TREEVIEW_MMATCH_COL_EXPORT )
{
stat5 = STATUS_SELECT_MM_FILE_EXPORT ;
stat4 = row_num ;
window_show_file_sel ( ) ;
}
}
else if ( row_num = = current_user . mmatches - > len & & col_num = = 1 )
{
if ( current_user . live_game . units - > len = = 0 )
{
game_gui_show_warning ( _ ( " No match stored. " ) ) ;
return ;
}
user_mm_add_last_match ( FALSE , FALSE ) ;
treeview2_show_mmatches ( ) ;
}
}
2005-12-01 14:49:00 +00:00
/** Find out whether the user's application for the job
is accepted and show the appropriate popups .
@ return TRUE if accepted , FALSE otherwise . */
gboolean
misc2_callback_evaluate_job_application ( Job * job , User * user )
{
if ( ! query_job_application_successful ( job , user ) )
{
game_gui_show_warning (
_ ( " The owners of %s politely reject your application. You're not successful enough in their eyes. " ) ,
job_get_team ( job ) - > name ) ;
return FALSE ;
}
if ( job - > type ! = JOB_TYPE_NATIONAL )
{
game_gui_show_warning (
2005-12-04 16:41:25 +00:00
/* A lame duck is someone who will quit his job soon and thus doesn't have
a lot of influence / impact anymore , e . g . an American president during
the last 2 years of his second presidency . */
2005-12-01 14:49:00 +00:00
_ ( " The owners of %s accept your application. Since %s don't want to get stuck with a lame duck, you get fired instantly and spend the rest of the current season tending your garden. " ) ,
job_get_team ( job ) - > name , user - > tm - > name ) ;
job_change_country ( job ) ;
}
else
game_gui_show_warning (
_ ( " The owners of %s accept your application. " ) ,
2005-12-10 16:18:43 +00:00
job_get_team ( job ) - > name ) ;
2005-12-01 14:49:00 +00:00
user_change_team ( user , team_of_id ( job - > team_id ) ) ;
if ( job - > type = = JOB_TYPE_NATIONAL )
job_remove ( job , TRUE ) ;
else
2005-12-10 12:21:19 +00:00
free_jobs ( TRUE ) ;
2005-12-01 14:49:00 +00:00
return TRUE ;
}