1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2024-12-16 10:21:15 +01:00

Variable interest rates.

This commit is contained in:
gyboth 2008-11-06 08:03:09 +00:00
parent 3f72a47a47
commit 43799da7be
13 changed files with 74 additions and 30 deletions

View File

@ -28,7 +28,7 @@ exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
datadir = @datadir@
libdir = @libdir@
localedir = $(libdir)/locale
localedir = $(datadir)/locale
gnulocaledir = $(datadir)/locale
gettextsrcdir = $(datadir)/glib-2.0/gettext/po
subdir = po

View File

@ -42,6 +42,8 @@ debug_action(const gchar *text)
gchar buf[SMALL];
gint value = -1;
printf("debact: %s\n", text);
sscanf(text, "%[^-0-9]%d", buf, &value);
if(g_str_has_prefix(text, "deb"))

View File

@ -121,7 +121,7 @@ finance_update_user_weekly(User *user)
user->money -= (gint)(finance_wage_unit(tm) * yc_factor[user->youth_academy.coach % 10]);
}
user->debt = (gint)rint((gfloat)user->debt * (1 + const_float("float_finance_interest")));
user->debt = (gint)rint((gfloat)user->debt * (1 + user->debt_interest));
if(user->money < -finance_team_drawing_credit_loan(user->tm, FALSE) &&
user->counters[COUNT_USER_POSITIVE] == -1 && debug < 50)
@ -200,12 +200,25 @@ finance_team_drawing_credit_loan(const Team *tm, gboolean loan)
void
finance_get_loan(gint value)
{
gfloat debt_old = current_user.debt;
gfloat debt_new = -value;
current_user.money += value;
current_user.debt -= value;
current_user.counters[COUNT_USER_LOAN] = (current_user.counters[COUNT_USER_LOAN] == -1) ?
const_int("int_finance_payback_weeks") :
current_user.counters[COUNT_USER_LOAN];
if(current_user.counters[COUNT_USER_LOAN] == -1)
{
current_user.counters[COUNT_USER_LOAN] = const_int("int_finance_payback_weeks");
current_user.debt_interest = current_interest;
}
else
{
/** Calculate new interest in a way that the user can't take unfair advantage of new market interest. */
current_user.debt_interest =
powf((debt_old * powf(1 + current_user.debt_interest, (gfloat)current_user.counters[COUNT_USER_LOAN]) +
debt_new * powf(1 + current_interest, (gfloat)current_user.counters[COUNT_USER_LOAN])) / (gfloat)current_user.debt,
1 / (gfloat)current_user.counters[COUNT_USER_LOAN]) - 1;
}
game_gui_print_message(_("You have %d weeks to pay back your loan."),
current_user.counters[COUNT_USER_LOAN]);
@ -356,3 +369,15 @@ finance_assign_game_money(const Fixture *fix)
}
}
}
/** Change the current interest on the market (random walk with three possibilities). */
void
finance_update_current_interest(void)
{
current_interest += math_rndi(-1, 1) * const_float("float_finance_interest_step");
if(current_interest < const_float("float_finance_interest_lower"))
current_interest = const_float("float_finance_interest_lower");
else if(current_interest > const_float("float_finance_interest_upper"))
current_interest = const_float("float_finance_interest_upper");
}

View File

@ -56,4 +56,7 @@ finance_get_stadium_improvement_duration(gfloat value, gboolean capacity);
void
finance_assign_game_money(const Fixture *fix);
void
finance_update_current_interest(void);
#endif

View File

@ -41,6 +41,7 @@
#include "live_game.h"
#include "load_save.h"
#include "main.h"
#include "maths.h"
#include "misc.h"
#include "misc_callbacks.h"
#include "name_struct.h"
@ -205,7 +206,6 @@ main_init_variables(void)
bets[1] = g_array_new(FALSE, FALSE, sizeof(BetMatch));
jobs = g_array_new(FALSE, FALSE, sizeof(Job));
job_teams = g_array_new(FALSE, FALSE, sizeof(Team));
save_file = NULL;
constants_app.list = settings.list =
@ -224,7 +224,11 @@ main_init_variables(void)
file_load_conf_files();
xml_strategy_load_strategies();
current_interest = rint(math_rnd(const_float("float_finance_interest_lower"),
const_float("float_finance_interest_upper")) /
const_float("float_finance_interest_step")) * const_float("float_finance_interest_step");
language_set(language_get_code_index(opt_str("string_opt_language_code")) + 1);
option_add(&options, "int_opt_calodds", 0, NULL);

View File

@ -71,7 +71,8 @@ WeekFunc start_week_round_funcs[] =
WeekFunc start_week_funcs[] =
{start_week_add_cups, start_week_update_users,
start_week_update_teams, start_week_update_user_finances,
youth_academy_update_weekly, transfer_update, job_update, NULL};
youth_academy_update_weekly, transfer_update, job_update,
finance_update_current_interest, NULL};
WeekFunc end_week_funcs[] = {stat_update_leagues, end_week_hide_cups, NULL};

View File

@ -1473,12 +1473,17 @@ treeview_create_finances(const User* user)
misc_print_grouped_int(finance_team_drawing_credit_loan(user->tm, FALSE), buf);
gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter, 0, _("Drawing credit"), 1, buf, 2, "", -1);
sprintf(buf, "%.2f%%", current_interest * 100);
gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter, 0, _("Current market interest"), 1, buf, 2, "", -1);
if(user->debt != 0)
{
misc_print_grouped_int(user->debt, buf);
sprintf(buf2, "<span foreground='%s'>%s</span>",
const_app("string_treeview_finances_expenses_fg"), buf);
sprintf(buf2, "<span foreground='%s'>%s (%.2f%% %s)</span>",
const_app("string_treeview_finances_expenses_fg"), buf,
user->debt_interest * 100, _("interest rate"));
sprintf(buf, _("Debt (repay in %d weeks)"), user->counters[COUNT_USER_LOAN]);
gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter, 0, buf, 1, "", 2, buf2, -1);

View File

@ -165,7 +165,9 @@ typedef struct
We have double arrays to store information about
the current and the past week. */
gint money, debt, money_in[2][MON_IN_END],
money_out[2][MON_OUT_END];
money_out[2][MON_OUT_END];
/** Interest the debt was taken at. */
gfloat debt_interest;
/** The user's scout and physio qualities.
@see #Quality */
gint scout, physio;

View File

@ -72,6 +72,9 @@ GArray *strategies;
/** Array of current and recent bets. */
GArray *bets[2];
/** Loan interest for the current week. */
gfloat current_interest;
/** Array of jobs in the job exchange and
teams going with the international jobs. */
GArray *jobs, *job_teams;

View File

@ -49,6 +49,7 @@ enum XmlLoadSaveCountryTags
TAG_MISC_BET_FIX_ID,
TAG_MISC_BET_ODD,
TAG_MISC_VERSION,
TAG_MISC_CURRENT_INTEREST,
TAG_END
};
@ -108,6 +109,7 @@ xml_loadsave_misc_end_element (GMarkupParseContext *context,
tag == TAG_SYMBOL ||
tag == TAG_SID ||
tag == TAG_MISC_VERSION ||
tag == TAG_MISC_CURRENT_INTEREST ||
tag == TAG_MISC_RATING ||
tag == TAG_MISC_ALLCUP ||
tag == TAG_MISC_COUNTER ||
@ -175,6 +177,8 @@ xml_loadsave_misc_text (GMarkupParseContext *context,
new_bet.odds[oddidx] = float_value;
else if(state == TAG_MISC_BET_FIX_ID)
new_bet.fix_id = int_value;
else if(state == TAG_MISC_CURRENT_INTEREST)
current_interest = float_value;
}
@ -235,6 +239,7 @@ xml_loadsave_misc_write(const gchar *prefix)
fprintf(fil, "<_%d>\n", TAG_MISC);
xml_write_string(fil, VERS, TAG_MISC_VERSION, I0);
xml_write_float(fil, current_interest, TAG_MISC_CURRENT_INTEREST, I0);
xml_write_string(fil, country.name, TAG_NAME, I0);
xml_write_string(fil, country.symbol, TAG_SYMBOL, I0);
xml_write_string(fil, country.sid, TAG_SID, I0);

View File

@ -42,6 +42,7 @@ enum
TAG_USER_COUNTER,
TAG_USER_MONEY,
TAG_USER_DEBT,
TAG_USER_DEBT_INTEREST,
TAG_USER_MONEY_INS,
TAG_USER_MONEY_IN,
TAG_USER_MONEY_OUTS,
@ -163,6 +164,7 @@ xml_loadsave_users_end_element (GMarkupParseContext *context,
else if(tag == TAG_USER_COUNTER ||
tag == TAG_USER_MONEY ||
tag == TAG_USER_DEBT ||
tag == TAG_USER_DEBT_INTEREST ||
tag == TAG_USER_MONEY_INS ||
tag == TAG_USER_MONEY_OUTS ||
tag == TAG_USER_SCOUT ||
@ -268,6 +270,8 @@ xml_loadsave_users_text (GMarkupParseContext *context,
new_user.money = int_value;
else if(state == TAG_USER_DEBT)
new_user.debt = int_value;
else if(state == TAG_USER_DEBT_INTEREST)
new_user.debt_interest = float_value;
else if(state == TAG_USER_SCOUT)
new_user.scout = int_value;
else if(state == TAG_USER_PHYSIO)
@ -392,6 +396,7 @@ xml_loadsave_users_write(const gchar *prefix)
xml_write_int(fil, usr(i).team_id, TAG_TEAM_ID, I1);
xml_write_int(fil, usr(i).money, TAG_USER_MONEY, I1);
xml_write_int(fil, usr(i).debt, TAG_USER_DEBT, I1);
xml_write_float(fil, usr(i).debt_interest, TAG_USER_DEBT_INTEREST, I1);
xml_write_int(fil, usr(i).scout, TAG_USER_SCOUT, I1);
xml_write_int(fil, usr(i).physio, TAG_USER_PHYSIO, I1);

View File

@ -338,6 +338,12 @@ float_finance_credit_factor_loan 70000
# number of weeks to pay back a loan
int_finance_payback_weeks 15
# lower and upper limit for the current interest
# and the change step between weeks
float_finance_interest_lower 500
float_finance_interest_upper 6000
float_finance_interest_step 250
# live game scale configuration
float_game_gui_live_game_scale_attack 30000
float_game_gui_live_game_scale_chance 45000

View File

@ -1,13 +1,6 @@
# Bygfoot Football Manager
# Default user configuration file
# Most of these options are uncommented because their meaning
# is rather clear if you take a look at the options window in the game.
int_opt_user_confirm_youth 1
int_opt_user_show_live_game 1
int_opt_user_live_game_speed 20
int_opt_user_show_live_game 0
int_opt_user_live_game_speed 40
int_opt_user_live_game_verbosity 5
int_opt_user_show_tendency_bar 1
int_opt_user_pause_injury 1
@ -19,20 +12,13 @@ int_opt_user_swap_adapts 1
int_opt_user_show_overall 0
int_opt_user_show_all_leagues 0
int_opt_user_contract_limit 12
int_opt_user_penalty_shooter -1
int_opt_user_bet_show_all_leagues 0
int_opt_user_bet_show_cups 1
int_opt_user_bet_show_my_recent 1
int_opt_user_bet_default_wager 5000
# default training camp hotel
int_opt_user_training_camp_hotel 1
int_opt_user_training_camp_recreation 5
# the order of these attributes is important
# don't change it, only the values
int_opt_user_pl1_att_name 1
int_opt_user_pl1_att_cpos 1
int_opt_user_pl1_att_pos 1
@ -51,9 +37,6 @@ int_opt_user_pl1_att_wage 0
int_opt_user_pl1_att_contract 0
int_opt_user_pl1_att_team 0
int_opt_user_pl1_att_league_cup 0
# the order of these attributes is important
# don't change it, only the values
int_opt_user_pl2_att_name 1
int_opt_user_pl2_att_cpos 0
int_opt_user_pl2_att_pos 1