1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2025-02-03 17:27:31 +01:00

Transfers, mainly.

This commit is contained in:
gyboth 2005-03-19 20:04:08 +00:00
parent a265c03a8c
commit 2f7c0bfe36
32 changed files with 595 additions and 152 deletions

View File

@ -985,35 +985,6 @@
</packing>
</child>
<child>
<widget class="GtkButton" id="button_fin_stad">
<property name="border_width">2</property>
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Finances and stadium (F)</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_button_fin_stad_clicked" last_modification_time="Tue, 03 Feb 2004 10:41:14 GMT"/>
<accelerator key="f" modifiers="0" signal="clicked"/>
<child>
<widget class="GtkImage" id="image33">
<property name="visible">True</property>
<property name="pixbuf">fin_stad.png</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button_preview">
<property name="border_width">2</property>
@ -1729,7 +1700,7 @@
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
<signal name="button_press_event" handler="on_player_list2_button_press_event" last_modification_time="Sun, 03 Oct 2004 09:18:03 GMT"/>
<signal name="button_press_event" handler="on_player_list1_button_press_event" last_modification_time="Sat, 19 Mar 2005 13:30:21 GMT"/>
</widget>
<packing>
<property name="tab_expand">False</property>

View File

@ -1369,7 +1369,7 @@
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="wrap">True</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>

View File

@ -1,4 +1,5 @@
#include "callback_func.h"
#include "callbacks.h"
#include "cup.h"
#include "finance.h"
#include "fixture.h"
@ -11,6 +12,7 @@
#include "start_end.h"
#include "support.h"
#include "team.h"
#include "transfer.h"
#include "treeview.h"
#include "user.h"
#include "variables.h"
@ -213,3 +215,32 @@ callback_pay_loan(void)
window_show_digits(buf, _("Payback"), max_payback, NULL, 0);
}
/** 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);
if(tr->pl->team == current_user.tm)
{
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."),
tr->pl->name->str);
stat1 = idx;
window_show_digits(buf, _("Fee"), tr->fee[current_user.scout % 10],
_("Wage"), tr->wage[current_user.scout % 10]);
}

View File

@ -24,4 +24,7 @@ callback_pay_loan(void);
void
callback_get_loan(void);
void
callback_transfer_list_clicked(gint idx);
#endif

View File

@ -4,6 +4,7 @@
#include "game_gui.h"
#include "main.h"
#include "team.h"
#include "transfer.h"
#include "treeview.h"
#include "variables.h"
#include "window.h"
@ -123,15 +124,9 @@ void
on_button_transfers_clicked (GtkButton *button,
gpointer user_data)
{
}
void
on_button_fin_stad_clicked (GtkButton *button,
gpointer user_data)
{
stat0 = STATUS_SHOW_TRANSFER_LIST;
game_gui_print_message(_("Left click to make an offer. Right click to remove offer."));
treeview_show_transfer_list(GTK_TREE_VIEW(lookup_widget(window.main, "treeview_right")));
}
@ -180,16 +175,6 @@ on_player_list1_button_press_event (GtkWidget *widget,
return FALSE;
}
gboolean
on_player_list2_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
return FALSE;
}
void
on_button_browse_forward_clicked (GtkButton *button,
gpointer user_data)
@ -500,6 +485,11 @@ on_treeview_right_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
gint idx;
treeview_select_row(GTK_TREE_VIEW(widget), event);
idx = treeview_get_index(GTK_TREE_VIEW(widget), 0);
switch(stat0)
{
case STATUS_SHOW_FINANCES:
@ -508,6 +498,17 @@ on_treeview_right_button_press_event (GtkWidget *widget,
else if(event->button == 3)
callback_pay_loan();
break;
case STATUS_SHOW_TRANSFER_LIST:
if(event->button == 1)
callback_transfer_list_clicked(idx - 1);
else if(event->button == 3)
{
if(transfer_remove_offer(idx - 1, current_user.tm))
game_gui_print_message(_("Your offer has been removed."));
else
game_gui_print_message(_("You haven't made an offer for the player."));
}
break;
}
return FALSE;
@ -576,10 +577,6 @@ on_menu_team_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
/*d*/
/* player_of(usr(0).tm, 10)->cskill = 0; */
/* player_of(usr(0).tm, 10)->health = 10; */
game_gui_read_radio_items(widget);
return FALSE;
@ -683,4 +680,3 @@ on_menu_show_stadium_activate (GtkMenuItem *menuitem,
{
window_show_stadium();
}

View File

@ -62,10 +62,6 @@ void
on_button_transfers_clicked (GtkButton *button,
gpointer user_data);
void
on_button_fin_stad_clicked (GtkButton *button,
gpointer user_data);
void
on_button_preview_clicked (GtkButton *button,
gpointer user_data);

View File

@ -56,12 +56,13 @@ enum Status0Value
STATUS_SHOW_FIXTURES,
STATUS_SHOW_TABLES,
STATUS_SHOW_FINANCES,
STATUS_SHOW_TRANSFER_LIST,
STATUS_GET_LOAN,
STATUS_PAY_LOAN,
STATUS_SHOW_EVENT,
STATUS_JOB_OFFER_SUCCESS,
STATUS_JOB_OFFER_FIRE_FINANCE,
STATUS_JOB_OFFER_FIRE_FAILURE,
STATUS_JOB_OFFER_FIRE_FAILURE,
STATUS_END
};

View File

@ -56,12 +56,35 @@ finance_update_user_weekly(User *user)
for(i=0;i<MON_OUT_END;i++)
user->money += user->money_out[1][i];
if(user->money < -finance_team_drawing_credit_loan(user->tm, FALSE) &&
user->counters[COUNT_USER_POSITIVE] == -1)
{
user->counters[COUNT_USER_OVERDRAWN]++;
if(user->counters[COUNT_USER_OVERDRAWN] <=
const_int("int_finance_overdraw_limit"))
{
user_event_add(user, EVENT_TYPE_OVERDRAW,
user->counters[COUNT_USER_OVERDRAWN], -1, NULL, NULL);
user->counters[COUNT_USER_POSITIVE] =
const_int("int_finance_overdraw_positive");
}
}
else if(user->counters[COUNT_USER_POSITIVE] > -1)
user->counters[COUNT_USER_POSITIVE]--;
if(user->counters[COUNT_USER_LOAN] > -1)
user->counters[COUNT_USER_LOAN]--;
if(user->counters[COUNT_USER_LOAN] == 0)
user_event_add(user, EVENT_TYPE_PAYBACK, -1, -1, NULL,
user_event_add(user, EVENT_TYPE_WARNING, -1, -1, NULL,
_("You have to pay back your loan this week."));
else if(user->counters[COUNT_USER_LOAN] == -1 && user->debt != 0)
if(user->counters[COUNT_USER_POSITIVE] == 0)
user_event_add(user, EVENT_TYPE_WARNING, -1, -1, NULL,
_("Your bank account has to exceed your drawing credit limit next week."));
if((user->counters[COUNT_USER_LOAN] == -1 && user->debt != 0) ||
(user->counters[COUNT_USER_POSITIVE] == -1 &&
user->money < -finance_team_drawing_credit_loan(user->tm, FALSE)))
{
new_team = team_get_new(tm, TRUE);
user_event_add(user, EVENT_TYPE_FIRE_FINANCE, -1, -1, new_team, NULL);
@ -122,8 +145,6 @@ finance_get_loan(gint value)
current_user.counters[COUNT_USER_LOAN]);
game_gui_print_message(buf);
window_destroy(&window.digits, TRUE);
on_menu_show_finances_activate(NULL, NULL);
}
@ -155,8 +176,6 @@ finance_pay_loan(gint value)
}
game_gui_print_message(buf);
window_destroy(&window.digits, TRUE);
on_menu_show_finances_activate(NULL, NULL);
}

View File

@ -57,7 +57,7 @@ free_user(User *user)
void
free_event(Event *event)
{
free_g_string(&event->string_value);
free_g_string(&event->value_string);
}
/** Free an array of options.

View File

@ -304,7 +304,7 @@ game_assign_attendance(Fixture *fix)
const_float("float_game_stadium_attendance_percentage_upper")) *
powf(tm[0]->stadium.safety,
const_float("float_game_stadium_attendance_safety_exponent"));
gint max_att = MIN((gint)rint((gfloat)league_cup_average_capacity(fix->clid) *
gint max_att = MIN((gint)rint((gfloat)league_cup_average_capacity(tm[0]->clid) *
const_float("float_game_stadium_attendance_average_exceed_factor")),
tm[0]->stadium.capacity);
@ -1084,13 +1084,8 @@ game_stadium_event(Stadium *stadium, gint type)
reduce = math_rnd(reduce_factor[type - LIVE_GAME_EVENT_STADIUM_BREAKDOWN][0],
reduce_factor[type - LIVE_GAME_EVENT_STADIUM_BREAKDOWN][1]);
printf("event %d saf %.2f cap %d\n",
type - LIVE_GAME_EVENT_STADIUM_BREAKDOWN, stadium->safety, stadium->capacity);
stadium->safety *= (1 - reduce);
stadium->capacity = (gint)rint((gfloat)stadium->capacity *
(1 - reduce *
const_float("float_game_stadium_capacity_reduce_factor")));
printf("2 event %d saf %.2f cap %d\n",
type - LIVE_GAME_EVENT_STADIUM_BREAKDOWN, stadium->safety, stadium->capacity);
}

View File

@ -170,6 +170,7 @@ game_gui_get_radio_items(GtkWidget **style, GtkWidget **scout,
void
game_gui_set_main_window_header(void)
{
gchar buf[SMALL];
GtkLabel *label_user= GTK_LABEL(lookup_widget(window.main, "label_user"));
GtkLabel *label_season= GTK_LABEL(lookup_widget(window.main, "label_season"));
GtkLabel *label_week= GTK_LABEL(lookup_widget(window.main, "label_week"));
@ -184,7 +185,10 @@ game_gui_set_main_window_header(void)
gui_label_set_text_from_int(label_week, week, FALSE);
gui_label_set_text_from_int(label_round, week_round, FALSE);
gui_label_set_text_from_int(label_rank, week_round, FALSE);
gui_label_set_text_from_int(label_money, current_user.money, FALSE);
misc_print_grouped_int(current_user.money, buf, FALSE);
gtk_label_set_text(label_money, buf);
gui_label_set_text_from_int(label_rank,
team_rank(current_user.tm, current_user.tm->clid), FALSE);

View File

@ -137,8 +137,6 @@ create_main_window (void)
GtkWidget *image20;
GtkWidget *button_transfers;
GtkWidget *image32;
GtkWidget *button_fin_stad;
GtkWidget *image33;
GtkWidget *button_preview;
GtkWidget *image36;
GtkWidget *vseparator16;
@ -700,19 +698,6 @@ create_main_window (void)
gtk_widget_show (image32);
gtk_container_add (GTK_CONTAINER (button_transfers), image32);
button_fin_stad = gtk_button_new ();
gtk_widget_show (button_fin_stad);
gtk_box_pack_start (GTK_BOX (hbox1), button_fin_stad, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (button_fin_stad), 2);
gtk_tooltips_set_tip (tooltips, button_fin_stad, _("Finances and stadium (F)"), NULL);
gtk_widget_add_accelerator (button_fin_stad, "clicked", accel_group,
GDK_f, 0,
GTK_ACCEL_VISIBLE);
image33 = create_pixmap (main_window, "fin_stad.png");
gtk_widget_show (image33);
gtk_container_add (GTK_CONTAINER (button_fin_stad), image33);
button_preview = gtk_button_new ();
gtk_widget_show (button_preview);
gtk_box_pack_start (GTK_BOX (hbox1), button_preview, FALSE, FALSE, 0);
@ -1193,9 +1178,6 @@ create_main_window (void)
g_signal_connect ((gpointer) button_transfers, "clicked",
G_CALLBACK (on_button_transfers_clicked),
NULL);
g_signal_connect ((gpointer) button_fin_stad, "clicked",
G_CALLBACK (on_button_fin_stad_clicked),
NULL);
g_signal_connect ((gpointer) button_preview, "clicked",
G_CALLBACK (on_button_preview_clicked),
NULL);
@ -1215,7 +1197,7 @@ create_main_window (void)
G_CALLBACK (on_player_list1_button_press_event),
NULL);
g_signal_connect ((gpointer) player_list2, "button_press_event",
G_CALLBACK (on_player_list2_button_press_event),
G_CALLBACK (on_player_list1_button_press_event),
NULL);
g_signal_connect ((gpointer) button_cl_back, "clicked",
G_CALLBACK (on_button_cl_back_clicked),
@ -1337,8 +1319,6 @@ create_main_window (void)
GLADE_HOOKUP_OBJECT (main_window, image20, "image20");
GLADE_HOOKUP_OBJECT (main_window, button_transfers, "button_transfers");
GLADE_HOOKUP_OBJECT (main_window, image32, "image32");
GLADE_HOOKUP_OBJECT (main_window, button_fin_stad, "button_fin_stad");
GLADE_HOOKUP_OBJECT (main_window, image33, "image33");
GLADE_HOOKUP_OBJECT (main_window, button_preview, "button_preview");
GLADE_HOOKUP_OBJECT (main_window, image36, "image36");
GLADE_HOOKUP_OBJECT (main_window, vseparator16, "vseparator16");

View File

@ -3,6 +3,7 @@
#include "bygfoot.h"
#include "league_struct.h"
#include "fixture_struct.h"
League
league_new(void);

View File

@ -147,7 +147,7 @@ live_game_fill_new_unit(LiveGameUnit *new)
new->event.type = LIVE_GAME_EVENT_INJURY;
else if(rndom < foul_event_prob +
injury_event_prob +
stadium_event && !match->stadium_event)
stadium_event && match->stadium_event == -1)
new->event.type = LIVE_GAME_EVENT_STADIUM;
else if(rndom < foul_event_prob +
injury_event_prob +
@ -454,7 +454,7 @@ live_game_event_stadium(void)
if(team_is_user(tm0) != -1)
game_stadium_event(&tm0->stadium, last_unit.event.type);
match->stadium_event = TRUE;
match->stadium_event = last_unit.event.type;
live_game_event_general(TRUE);
}
@ -762,7 +762,7 @@ live_game_event_send_off(gint team, gint player, gboolean second_yellow)
player_of_id(tm[team], player)->cskill = 0;
if(second_yellow)
player_card_set(player_of_id(tm[team], player), match->fix->clid, PLAYER_VALUE_CARD_RED, 1, FALSE);
player_card_set(player_of_id(tm[team], player), match->fix->clid, PLAYER_VALUE_CARD_RED, 2, FALSE);
else
player_card_set(player_of_id(tm[team], player), match->fix->clid, PLAYER_VALUE_CARD_RED,
game_player_get_ban_duration(), FALSE);
@ -1174,7 +1174,7 @@ live_game_reset(Fixture *fix)
match->fix = fix;
match->subs_left[0] = match->subs_left[1] = 3;
match->stadium_event = FALSE;
match->stadium_event = -1;
if(fix->home_advantage)
match->home_advantage =

View File

@ -184,7 +184,7 @@ typedef struct
gint started_game;
/** We keep track of the stadium events because
there shouldn't be more than one of them in a game. */
gboolean stadium_event;
gint stadium_event;
/** Attacking, defending etc. values for both teams.
@see #GameTeamValue */
gfloat team_values[2][GAME_TEAM_VALUE_END];

View File

@ -5,11 +5,11 @@
#include <time.h>
/*d*/
#include "misc_callbacks.h"
#include "file.h"
#include "free.h"
#include "main.h"
#include "transfer_struct.h"
#include "variables.h"
#include "window.h"
@ -30,9 +30,9 @@ main_init_variables(void)
live_game_temp.units = NULL;
users = g_array_new(FALSE, FALSE, sizeof(User));
options = g_array_new(FALSE, FALSE, sizeof(Option));
constants = g_array_new(FALSE, FALSE, sizeof(Option));
transfer_list = g_array_new(FALSE, FALSE, sizeof(Transfer));
popups_active = 0;
selected_row[0] = selected_row[1] = -1;

View File

@ -5,6 +5,7 @@
#include "misc2_callbacks.h"
#include "misc2_interface.h"
#include "support.h"
#include "transfer.h"
#include "user.h"
#include "variables.h"
#include "window.h"
@ -126,8 +127,16 @@ on_button_digits_ok_clicked (GtkButton *button,
case STATUS_PAY_LOAN:
finance_pay_loan(values[0]);
break;
case STATUS_SHOW_TRANSFER_LIST:
if(transfer_add_offer(stat1, current_user.tm, values[0], values[1]))
game_gui_print_message(_("Your offer has been updated."));
else
game_gui_print_message(_("Your offer will be considered next week."));
break;
}
window_destroy(&window.digits, TRUE);
game_gui_set_main_window_header();
}

View File

@ -707,6 +707,7 @@ create_window_digits (void)
label_main = gtk_label_new (_("label42"));
gtk_widget_show (label_main);
gtk_box_pack_start (GTK_BOX (vbox14), label_main, FALSE, FALSE, 0);
gtk_label_set_line_wrap (GTK_LABEL (label_main), TRUE);
hbox15 = gtk_hbox_new (FALSE, 0);
gtk_widget_show (hbox15);

View File

@ -148,7 +148,8 @@ player_estimate_talent(Player *pl)
for(i=0;i<QUALITY_END;i++)
{
scout_deviance[i] = (i + 1) * const_float("float_player_etal_scout_factor");
scout_deviance[i] = (i + 1) * const_float("float_player_max_skill") *
(const_float("float_player_etal_scout_factor") / 100);
/* adjust deviance_bounds with regard to the scout's
deviance */
for(j=0;j<2;j++)
@ -1003,9 +1004,11 @@ player_update_post_match(Player *pl, gint clid)
player_card_set(pl, clid, PLAYER_VALUE_CARD_RED, -1, TRUE);
}
/** Replace a player by a new one in a cpu team. */
/** Replace a player by a new one in a cpu team.
@param free_player Whether to free the memory occupied
by the player. */
void
player_replace_by_new(Player *pl)
player_replace_by_new(Player *pl, gboolean free_player)
{
Team *tm = pl->team;
gint idx = player_id_index(tm, pl->id);
@ -1015,7 +1018,10 @@ player_replace_by_new(Player *pl)
new.cpos = pl->cpos;
new.id = pl->id;
player_remove_from_team(tm, idx);
if(free_player)
player_remove_from_team(tm, idx);
else
g_array_remove_index(tm->players, idx);
g_array_insert_val(tm->players, idx, new);
}

View File

@ -122,7 +122,7 @@ void
player_update_post_match(Player *pl, gint clid);
void
player_replace_by_new(Player *pl);
player_replace_by_new(Player *pl, gboolean free_player);
void
player_remove_from_team(Team *tm, gint idx);

View File

@ -36,7 +36,7 @@ WeekFunc start_week_round_funcs[] =
is started. */
WeekFunc start_week_funcs[] =
{start_week_update_users, start_week_update_user_teams,
start_week_update_user_finances, NULL};
start_week_update_user_finances, transfer_update, NULL};
WeekFunc end_week_funcs[] = {NULL};
@ -77,7 +77,6 @@ start_write_variables(void)
season = week = week_round = 1;
cur_user = 0;
/* week=24; week_round = 2; */
transfer_list = g_array_new(FALSE, FALSE, sizeof(TransferPlayer));
for(i=0;i<users->len;i++)
file_load_user_conf_file(&usr(i));
@ -197,6 +196,7 @@ end_week_round_results(void)
buf,
g_array_index(cp(i).fixtures, Fixture, j).teams[1]->name->str);
gui_show_progress((gfloat)done / num_matches, buf2);
printf("%s\n", buf2);
}
}

View File

@ -797,7 +797,7 @@ team_update_cpu_new_players(Team *tm)
math_generate_permutation(player_numbers, 0, tm->players->len - 1);
for(i=0;i<number_of_new;i++)
player_replace_by_new(player_of(tm, player_numbers[i]));
player_replace_by_new(player_of(tm, player_numbers[i]), TRUE);
}
/** Heal players, re-set fitnesses, make some random subs
@ -865,7 +865,7 @@ team_compare_func(gconstpointer a, gconstpointer b, gpointer data)
*(const Team**)b : (const Team*)b;
gint return_value = 0;
if(type == TEAM_COMPARE_RANK)
if(type == TEAM_COMPARE_LEAGUE_RANK)
{
if(tm1->clid == tm2->clid)
return_value = misc_int_compare(team_rank(tm2, tm2->clid), team_rank(tm1, tm1->clid));
@ -874,22 +874,37 @@ team_compare_func(gconstpointer a, gconstpointer b, gpointer data)
league_cup_get_index_from_clid(tm2->clid),
league_cup_get_index_from_clid(tm1->clid));
}
else if(type == TEAM_COMPARE_UNSORTED)
return 0;
return return_value;
}
/** Return the teams from all leagues sorted by the
specified function.
@param type The integer to pass to the compare function. */
@param type The integer to pass to the compare function.
@param cup Whether we return the international cup teams or league teams. */
GPtrArray*
team_get_sorted(GCompareDataFunc compare_function, gint type)
team_get_sorted(GCompareDataFunc compare_function, gint type, gboolean cup)
{
gint i, j;
GPtrArray *teams = g_ptr_array_new();
for(i=0;i<ligs->len;i++)
for(j=0;j<lig(i).teams->len;j++)
g_ptr_array_add(teams, team_get_pointer_from_ids(lig(i).id, j));
if(!cup)
{
for(i=0;i<ligs->len;i++)
for(j=0;j<lig(i).teams->len;j++)
g_ptr_array_add(teams, team_get_pointer_from_ids(lig(i).id, j));
}
else
{
for(i=0;i<cps->len;i++)
{
if(cp(i).type == CUP_TYPE_INTERNATIONAL)
for(j=0;j<cp(i).teams->len;j++)
g_ptr_array_add(teams, team_get_pointer_from_ids(cp(i).id, j));
}
}
g_ptr_array_sort_with_data(teams, compare_function, GINT_TO_POINTER(type));
@ -908,7 +923,7 @@ team_get_new(const Team *tm, gboolean fire)
bound2 = (fire) ? const_int("int_team_new_bound_lower") :
const_int("int_team_new_bound_upper");
gint idx = -1;
GPtrArray *teams = team_get_sorted(team_compare_func, TEAM_COMPARE_RANK);
GPtrArray *teams = team_get_sorted(team_compare_func, TEAM_COMPARE_LEAGUE_RANK, FALSE);
Team *return_value;
for(i=0;i<teams->len;i++)
@ -933,5 +948,7 @@ team_get_new(const Team *tm, gboolean fire)
while(return_value == tm)
return_value = (Team*)g_ptr_array_index(teams, math_rndi(i - bound1, i + bound2));
g_ptr_array_free(teams, TRUE);
return return_value;
}

View File

@ -9,7 +9,8 @@
/** Possibilities for team comparison. */
enum TeamCompare
{
TEAM_COMPARE_RANK = 0,
TEAM_COMPARE_LEAGUE_RANK = 0,
TEAM_COMPARE_UNSORTED,
TEAM_COMPARE_END
};
@ -119,7 +120,7 @@ Team*
team_get_new(const Team *tm, gboolean fire);
GPtrArray*
team_get_sorted(GCompareDataFunc compare_function, gint type);
team_get_sorted(GCompareDataFunc compare_function, gint type, gboolean cup);
gint
team_compare_func(gconstpointer a, gconstpointer b, gpointer data);

View File

@ -1 +1,265 @@
#include "finance.h"
#include "free.h"
#include "league.h"
#include "maths.h"
#include "option.h"
#include "player.h"
#include "team.h"
#include "transfer.h"
#include "user.h"
/** Weekly update of the transfer list. */
void
transfer_update(void)
{
gint i;
if(week > transfer_get_deadline())
return;
if(week == transfer_get_deadline())
{
for(i=transfer_list->len - 1;i>=0;i--)
transfer_remove_player(i);
return;
}
transfer_evaluate_offers();
for(i=transfer_list->len - 1;i>=0;i--)
{
trans(i).time--;
if(trans(i).time == 0)
transfer_remove_player(i);
}
transfer_add_new_players();
transfer_add_offers();
}
/** Add offers for the users' players on the list. */
void
transfer_add_offers(void)
{
}
/** Compare function for transfer offers. */
gint
transfer_offer_compare_func(gconstpointer a, gconstpointer b)
{
const TransferOffer *tr1 = (const TransferOffer*)a,
*tr2 = (const TransferOffer*)b;
gint return_value;
if(tr1->fee > tr2->fee)
return_value = -1;
else if(tr2->fee > tr1->fee)
return_value = 1;
else if(tr1->wage > tr2->wage)
return_value = -1;
else if(tr2->wage > tr1->wage)
return_value = 1;
else
return_value = 0;
return return_value;
}
/** Move players to the users' teams if their offer
was accepted or remove the players from the list if not. */
void
transfer_evaluate_offers(void)
{
gint i, j;
gint idx = -1;
for(i=transfer_list->len - 1;i>=0;i--)
{
if(trans(i).offers->len > 1)
g_array_sort(trans(i).offers, transfer_offer_compare_func);
for(j=0;j<trans(i).offers->len;j++)
if(team_is_user(transoff(i, j).tm) != -1 &&
transoff(i, j).fee > BUDGET(user_get_index(user_from_team(transoff(i, j).tm))))
user_event_add(user_from_team(transoff(i, j).tm),
EVENT_TYPE_TRANSFER_OFFER_MONEY, -1, -1,
trans(i).pl->team, trans(i).pl->name->str);
else
{
idx = j;
break;
}
for(j=idx + 1;j<trans(i).offers->len;j++)
user_event_add(user_from_team(transoff(i, j).tm),
EVENT_TYPE_TRANSFER_OFFER_REJECTED, -1, -1,
trans(i).pl->team, trans(i).pl->name->str);
if(trans(i).offers->len != 0)
{
printf("%s val %d wa %d fee %d wag %d\n",
trans(i).pl->name->str, trans(i).pl->value,
trans(i).pl->wage, transoff(i, idx).fee,
transoff(i, idx).wage);
if(trans(i).pl->value > transoff(i, idx).fee ||
trans(i).pl->wage > transoff(i, idx).wage)
user_event_add(user_from_team(transoff(i, idx).tm),
EVENT_TYPE_TRANSFER_OFFER_REJECTED, -1, -1,
trans(i).pl->team, trans(i).pl->name->str);
else if(transoff(i, idx).fee > BUDGET(user_get_index(user_from_team(transoff(i, idx).tm))))
user_event_add(user_from_team(transoff(i, idx).tm),
EVENT_TYPE_TRANSFER_OFFER_MONEY, -1, -1,
trans(i).pl->team, trans(i).pl->name->str);
else if(transoff(i, idx).tm->players->len >= const_int("int_team_max_players"))
user_event_add(user_from_team(transoff(i, idx).tm),
EVENT_TYPE_TRANSFER_OFFER_ROSTER, -1, -1,
trans(i).pl->team, trans(i).pl->name->str);
else
{
user_event_add(user_from_team(transoff(i, idx).tm),
EVENT_TYPE_TRANSFER_OFFER_ACCEPTED, -1, -1,
trans(i).pl->team, trans(i).pl->name->str);
player_move(trans(i).pl->team, player_id_index(trans(i).pl->team, trans(i).pl->id),
transoff(i, idx).tm, transoff(i, idx).tm->players->len);
player_replace_by_new(trans(i).pl, FALSE);
transfer_remove_player(i);
}
}
}
}
/** Add new players to the transfer list. */
void
transfer_add_new_players(void)
{
gint i;
gint number_of_new = math_rndi(const_int("int_transfer_new_players_lower"),
const_int("int_transfer_new_players_upper"));
number_of_new = MIN(number_of_new,
const_int("int_transfer_max_players") - transfer_list->len);
for(i=0;i<number_of_new;i++)
transfer_add_player(transfer_player_get_new(
(math_rnd(0, 1) < const_float("float_transfer_cup_percentage"))),
math_rndi(const_int("int_transfer_time_lower"),
const_int("int_transfer_time_upper")));
}
/** Select a random player for the transfer list. */
Player*
transfer_player_get_new(gboolean cup)
{
GPtrArray *teams = team_get_sorted(team_compare_func, TEAM_COMPARE_UNSORTED, cup);
Player *pl = NULL;
Team *tm = NULL;
while(pl == NULL || team_is_user(pl->team) != -1 ||
query_player_is_on_transfer_list(pl))
{
tm = (Team*)g_ptr_array_index(teams, math_rndi(0, teams->len - 1));
pl = player_of(tm, math_rndi(0, tm->players->len - 1));
}
return pl;
}
/** Add the player to the transfer list.
@param time The number of weeks he'll be on the list. */
void
transfer_add_player(Player *pl, gint time)
{
gint i;
Transfer new;
gfloat deviance = 0;
new.pl = pl;
new.time = time;
new.offers = g_array_new(FALSE, FALSE, sizeof(TransferOffer));
for(i=0;i<4;i++)
{
deviance = math_rnd(-(i + 1) * const_float("float_transfer_scout_deviance"),
(i + 1) * const_float("float_transfer_scout_deviance"));
new.fee[i] = (gint)rint((gfloat)pl->value * (1 + deviance));
new.wage[i] = (gint)rint((gfloat)pl->wage * (1 + deviance));
}
g_array_append_val(transfer_list, new);
}
/** Return the transfer deadline. */
gint
transfer_get_deadline(void)
{
gint i;
gint length = 0;
for(i=0;i<ligs->len;i++)
length = MAX(length, (lig(i).teams->len - 1) * 2);
return (gint)rint((gfloat)length * const_float("float_transfer_deadline_percentage"));
}
/** Remove a player from the transfer list. */
void
transfer_remove_player(gint idx)
{
free_g_array(&trans(idx).offers);
g_array_remove_index(transfer_list, idx);
}
/** Find out whether a player is on the transfer list. */
gboolean
query_player_is_on_transfer_list(const Player *pl)
{
gint i;
for(i=0;i<transfer_list->len;i++)
if(trans(i).pl == pl)
return TRUE;
return FALSE;
}
/** Add an offer to the player with specified index on the transfer list.
@param return TRUE if the offer updated an earlier offer, FALSE, otherwise. */
gboolean
transfer_add_offer(gint idx, Team *tm, gint fee, gint wage)
{
gint i;
TransferOffer new;
new.tm = tm;
new.fee = fee;
new.wage = wage;
for(i=0;i<trans(idx).offers->len;i++)
if(transoff(idx, i).tm == tm)
{
transoff(idx, i).fee = fee;
transoff(idx, i).wage = wage;
return TRUE;
}
g_array_append_val(trans(idx).offers, new);
return FALSE;
}
/** Remove any offers from the team for the given transfer player. */
gboolean
transfer_remove_offer(gint idx, const Team *tm)
{
gint i;
for(i=0;i<trans(idx).offers->len;i++)
if(transoff(idx, i).tm == tm)
{
g_array_remove_index(trans(idx).offers, i);
return TRUE;
}
return FALSE;
}

View File

@ -2,17 +2,48 @@
#define TRANSFER_H
#include "bygfoot.h"
#include "team.h"
#include "player_struct.h"
#include "transfer_struct.h"
#include "variables.h"
/** Structure representing a player on the transfer list. */
typedef struct
{
/** Cup or league id, team id, player id.*/
gint clid, team_nid, id;
/** Estimated wage and value. */
gint ewage, evalue;
/** Time until player gets removed from the list. */
gint time;
} TransferPlayer;
/** Convenience abbrev. */
#define trans(i) g_array_index(transfer_list, Transfer, i)
#define transoff(i, j) g_array_index(g_array_index(transfer_list, Transfer, i).offers, TransferOffer, j)
void
transfer_update(void);
void
transfer_add_offers(void);
void
transfer_evaluate_offers(void);
void
transfer_add_new_players(void);
Player*
transfer_player_get_new(gboolean cup);
void
transfer_add_player(Player *pl, gint time);
gint
transfer_get_deadline(void);
void
transfer_remove_player(gint idx);
gboolean
query_player_is_on_transfer_list(const Player *pl);
gboolean
transfer_add_offer(gint idx, Team *tm, gint fee, gint wage);
gboolean
transfer_remove_offer(gint idx, const Team *tm);
gint
transfer_offer_compare_func(gconstpointer a, gconstpointer b);
#endif

View File

@ -13,6 +13,7 @@
#include "option.h"
#include "support.h"
#include "team.h"
#include "transfer.h"
#include "treeview.h"
#include "treeview_cell.h"
#include "user.h"
@ -470,7 +471,9 @@ treeview_set_up_player_list (GtkTreeView *treeview, gint *attributes, gint max)
GINT_TO_POINTER(attributes[i]),
NULL);
if(attributes[i] != PLAYER_LIST_ATTRIBUTE_NAME)
if(attributes[i] != PLAYER_LIST_ATTRIBUTE_NAME &&
attributes[i] != PLAYER_LIST_ATTRIBUTE_TEAM &&
attributes[i] != PLAYER_LIST_ATTRIBUTE_LEAGUE_CUP)
{
gtk_tree_view_column_set_alignment(col, 0.5);
g_object_set(renderer, "xalign", 0.5,
@ -919,6 +922,22 @@ treeview_create_game_stats(LiveGame *live_game)
gtk_list_store_append(liststore, &iter);
gtk_list_store_set(liststore, &iter, 0, buf[1], 1, "", 2, "", -1);
if(live_game->stadium_event != -1)
{
gtk_list_store_append(liststore, &iter);
if(live_game->stadium_event == LIVE_GAME_EVENT_STADIUM_BREAKDOWN)
sprintf(buf[0], _("<span background='%s'>There were technical problems\nin the stadium.</span>"),
const_str("string_treeview_stadium_event_bg"));
else if(live_game->stadium_event == LIVE_GAME_EVENT_STADIUM_RIOTS)
sprintf(buf[0], _("<span background='%s'>There were riots\nin the stadium.</span>"),
const_str("string_treeview_stadium_event_bg"));
else
sprintf(buf[0], _("<span background='%s'>There was a fire\nin the stadium.</span>"),
const_str("string_treeview_stadium_event_bg"));
gtk_list_store_set(liststore, &iter, 0, buf[0], 1, "", 2, "", -1);
}
gtk_list_store_append(liststore, &iter);
gtk_list_store_set(liststore, &iter, 0, "", 1, "", 2, "", -1);
@ -1573,3 +1592,17 @@ treeview_show_finances(GtkTreeView *treeview, const User* user)
gtk_tree_view_set_model(treeview, model);
g_object_unref(model);
}
/** Show the transfer list. */
void
treeview_show_transfer_list(GtkTreeView *treeview)
{
gint i;
GPtrArray *players = g_ptr_array_new();
for(i=0;i<transfer_list->len;i++)
g_ptr_array_add(players, trans(i).pl);
treeview_show_player_list(treeview, players,
treeview_get_attributes_from_scout(current_user.scout), FALSE);
}

View File

@ -143,4 +143,7 @@ treeview_show_player_list_team(GtkTreeView *treeview, const Team *tm, gint scout
PlayerListAttribute
treeview_get_attributes_from_scout(gint scout);
void
treeview_show_transfer_list(GtkTreeView *treeview);
#endif

View File

@ -98,7 +98,6 @@ user_set_up_counters(User *user)
user->counters[COUNT_USER_LOAN] =
user->counters[COUNT_USER_POSITIVE] = -1;
}
/** Set up the user's finances when he's got a new team.
@param user The user we set up the finances for. */
@ -238,8 +237,8 @@ user_event_new(void)
new.user = NULL;
new.type = -1;
new.value1 = new.value2 = -1;
new.pointer_value = NULL;
new.string_value = NULL;
new.value_pointer = NULL;
new.value_string = NULL;
return new;
}
@ -247,7 +246,7 @@ user_event_new(void)
/** Add an event with the specified values to the event array of the user. */
void
user_event_add(User *user, gint type, gint value1, gint value2,
gpointer pointer_value, gchar *string_value)
gpointer value_pointer, gchar *value_string)
{
Event new = user_event_new();
@ -255,10 +254,10 @@ user_event_add(User *user, gint type, gint value1, gint value2,
new.type = type;
new.value1 = value1;
new.value2 = value2;
new.pointer_value = pointer_value;
new.value_pointer = value_pointer;
if(string_value != NULL)
new.string_value = g_string_new(string_value);
if(value_string != NULL)
new.value_string = g_string_new(value_string);
g_array_append_val(user->events, new);
@ -298,17 +297,49 @@ user_event_show_next(void)
break;
case EVENT_TYPE_PLAYER_LEFT:
sprintf(buf, _("%s has left your team because his contract expired."),
event->string_value->str);
event->value_string->str);
game_gui_show_warning(buf);
user_event_remove(&current_user, 0);
break;
case EVENT_TYPE_PAYBACK:
game_gui_show_warning(event->string_value->str);
case EVENT_TYPE_WARNING:
game_gui_show_warning(event->value_string->str);
user_event_remove(&current_user, 0);
break;
case EVENT_TYPE_FIRE_FINANCE:
stat0 = STATUS_JOB_OFFER_FIRE_FINANCE;
statp = event->pointer_value;
game_gui_show_job_offer((Team*)event->pointer_value, STATUS_JOB_OFFER_FIRE_FINANCE);
statp = event->value_pointer;
game_gui_show_job_offer((Team*)event->value_pointer, STATUS_JOB_OFFER_FIRE_FINANCE);
user_event_remove(&current_user, 0);
break;
case EVENT_TYPE_OVERDRAW:
if(event->value1 == 1)
sprintf(buf, _("You have overdrawn your bank account. The team owners give you %d weeks to exceed your drawing credit limit again."), const_int("int_finance_overdraw_positive"));
else
sprintf(buf, _("You have overdrawn your bank account once again. Bear in mind that after the fourth time you get fired.\nThe team owners give you %d weeks to exceed your drawing credit limit again."), const_int("int_finance_overdraw_positive"));
game_gui_show_warning(buf);
user_event_remove(&current_user, 0);
break;
case EVENT_TYPE_TRANSFER_OFFER_REJECTED:
sprintf(buf, _("The owners of %s have rejected your offer for %s. Either the fee or the wage you suggested was too low, apparently."), ((Team*)event->value_pointer)->name->str, event->value_string->str);
game_gui_show_warning(buf);
user_event_remove(&current_user, 0);
break;
case EVENT_TYPE_TRANSFER_OFFER_MONEY:
sprintf(buf, _("You didn't have enough money to buy %s from %s."),
event->value_string->str, ((Team*)event->value_pointer)->name->str);
game_gui_show_warning(buf);
user_event_remove(&current_user, 0);
break;
case EVENT_TYPE_TRANSFER_OFFER_ROSTER:
sprintf(buf, _("Your roster is full. You couldn't buy %s from %s."),
event->value_string->str, ((Team*)event->value_pointer)->name->str);
game_gui_show_warning(buf);
user_event_remove(&current_user, 0);
break;
case EVENT_TYPE_TRANSFER_OFFER_ACCEPTED:
sprintf(buf, _("Congratulations! The owners of %s have accepted your offer for %s!"),
((Team*)event->value_pointer)->name->str, event->value_string->str);
game_gui_show_warning(buf);
user_event_remove(&current_user, 0);
break;
}
@ -325,3 +356,18 @@ user_change_team(User *user, Team *tm)
for(i=user->events->len - 1; i >= 0; i--)
user_event_remove(user, i);
}
/** Return the index of the user in the users array. */
gint
user_get_index(User *user)
{
gint i;
for(i=0;i<users->len;i++)
if(&usr(i) == user)
return i;
g_warning("user_get_index: user not found.\n");
return -1;
}

View File

@ -56,4 +56,7 @@ user_change_team(User *user, Team *tm);
void
user_set_up_counters(User *user);
gint
user_get_index(User *user);
#endif

View File

@ -84,11 +84,18 @@ typedef struct
enum EventType
{
EVENT_TYPE_PLAYER_LEFT = 0,
EVENT_TYPE_WARNING = 0,
EVENT_TYPE_PLAYER_LEFT,
EVENT_TYPE_PAYBACK,
EVENT_TYPE_OVERDRAW,
EVENT_TYPE_JOB_OFFER,
EVENT_TYPE_FIRE_FINANCE,
EVENT_TYPE_FIRE_UNSUCCESSFUL
EVENT_TYPE_FIRE_UNSUCCESSFUL,
EVENT_TYPE_TRANSFER_OFFER_REJECTED,
EVENT_TYPE_TRANSFER_OFFER_MONEY,
EVENT_TYPE_TRANSFER_OFFER_ROSTER,
EVENT_TYPE_TRANSFER_OFFER_ACCEPTED,
EVENT_TYPE_END
};
/** A structure representing an event for a user. This is used
@ -102,9 +109,9 @@ typedef struct
/** Some values that are used for different purposes. */
gint value1, value2;
/** A pointer for different purposes. */
gpointer pointer_value;
gpointer value_pointer;
/** A string for different purposes. */
GString *string_value;
GString *value_string;
} Event;

View File

@ -162,10 +162,6 @@ float_treeview_cell_limit_player_contract_below3 4000
# the integer that the cell data functions will interpret as an empty string.
int_treeview_cell_int_empty -5
# transfer list configuration
int_transfer_max_players 20
int_transfer_deadline 35
# maximum number of players in a team.
int_team_max_players 20
@ -176,6 +172,11 @@ float_player_max_skill 990000
int_initial_money_lower 80
int_initial_money_upper 110
# how often a user may overdraw his bank account
int_finance_overdraw_limit 3
# how many weeks until he's got to be positive
int_finance_overdraw_positive 6
# wage factors for scout and physio
# four apiece because of the different qualities
float_finance_scout_factor1 20000
@ -562,6 +563,27 @@ float_player_team_weight_forward_defense 2000
float_player_team_weight_forward_midfield 6000
float_player_team_weight_forward_attack 13000
# transfer list configuration
# maximal number of players on the list
int_transfer_max_players 20
# deadline in perc. of the longest league
# e.g if a league has 100 matchdays deadline would be after
# week 70
float_transfer_deadline_percentage 7500
# number of new players on the list each week
int_transfer_new_players_lower 0
int_transfer_new_players_upper 4
# how long they stay on the list
int_transfer_time_lower 3
int_transfer_time_upper 5
# percentage of players from international cup teams
float_transfer_cup_percentage 2500
# scout deviance in percent of the players' values and wages
# this value is the deviance for the best scout; the others
# are obtained by multiplying it
float_transfer_scout_deviance 400
#### colours and icons
@ -669,3 +691,6 @@ string_treeview_table_best_advance khaki
# colour for expenses in the finances
string_treeview_finances_expenses_fg red
# background colour of a stadium event in the stats
string_treeview_stadium_event_bg orange

View File

@ -5,7 +5,7 @@
<symbol>flag_en.png</symbol>
<sid>england_fa</sid>
<last_week>47</last_week>
<week_gap>4</week_gap>
<week_gap>4</week_gap>
<cup_rounds>
<cup_round>