1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2024-12-12 08:27:28 +01:00

Use teams from country_list for international jobs

This way we don't need to generate teams sepearately for jobs.
This commit is contained in:
Tom Stellard 2021-03-17 19:50:35 -07:00
parent 804185f354
commit b0fc95a7ad
6 changed files with 12 additions and 59 deletions

View File

@ -1070,14 +1070,6 @@ free_job(Job *job, gboolean free_tm)
free_gchar_ptr(job->country_file);
free_gchar_ptr(job->country_name);
free_gchar_ptr(job->league_name);
for(i=0;i<job_teams->len;i++)
if(g_array_index(job_teams, Team, i).id == job->team_id)
{
if(free_tm)
free_team(&g_array_index(job_teams, Team, i));
g_array_remove_index(job_teams, i);
}
}
}
@ -1096,7 +1088,6 @@ free_jobs(gboolean reset)
if(reset)
{
jobs = g_array_new(FALSE, FALSE, sizeof(Job));
job_teams = g_array_new(FALSE, FALSE, sizeof(Team));
}
return;
@ -1106,11 +1097,9 @@ free_jobs(gboolean reset)
free_job(&g_array_index(jobs, Job, i), TRUE);
free_g_array(&jobs);
free_g_array(&job_teams);
if(reset)
{
jobs = g_array_new(FALSE, FALSE, sizeof(Job));
job_teams = g_array_new(FALSE, FALSE, sizeof(Team));
}
}

View File

@ -94,9 +94,7 @@ job_add_new_international(gint num_of_new)
printf("job_add_new_international\n");
#endif
gint i, k, rndom, idx;
GPtrArray *country_files = file_get_country_files();
Country countries[num_of_new];
gint i, k, rndom;
Team *tm = NULL;
League *league = NULL;
gint team_id = -1;
@ -105,37 +103,22 @@ job_add_new_international(gint num_of_new)
k = 0;
for(i=0;i<num_of_new;i++)
{
countries[k].leagues = countries[k].cups = NULL;
countries[k].allcups = NULL;
countries[k].name = countries[k].symbol =
countries[k].sid = NULL;
Country *job_country = NULL;
do
rndom = math_rndi(0, country_files->len - 1);
while(g_strrstr((gchar*)g_ptr_array_index(country_files, rndom),
rndom = math_rndi(0, country_list->len - 1);
while(g_strrstr(((Country*)g_ptr_array_index(country_list, rndom))->sid,
country.sid));
idx = job_country_is_in_list(
(gchar*)g_ptr_array_index(country_files, rndom),
countries, num_of_new);
job_country = g_ptr_array_index(country_list, rndom);
if(idx == -1)
{
idx = k;
xml_country_read((gchar*)g_ptr_array_index(country_files, rndom),
&countries[k]);
counters[COUNT_LEAGUE_ID] -= countries[k].leagues->len;
k++;
}
job_pick_team_from_country(&countries[idx], &tm, &league);
job_pick_team_from_country(job_country, &tm, &league);
new_job.country_file =
g_strdup_printf("country_%s.xml", countries[idx].sid);
g_strdup_printf("country_%s.xml", job_country->sid);
new_job.time = math_rndi(const_int("int_job_update_interval") - 1,
const_int("int_job_update_interval") + 1);
new_job.country_name = g_strdup(countries[idx].name);
new_job.country_rating = countries[idx].rating;
new_job.country_name = g_strdup(job_country->name);
new_job.country_rating = job_country->rating;
new_job.league_name = g_strdup(league->name);
new_job.league_layer = league->layer;
@ -143,9 +126,6 @@ job_add_new_international(gint num_of_new)
if(team_id == -1)
{
team_generate_players_stadium(tm, league->average_talent);
g_array_append_val(job_teams, *tm);
new_job.team_id = tm->id;
new_job.type = JOB_TYPE_INTERNATIONAL;
}
@ -161,8 +141,6 @@ job_add_new_international(gint num_of_new)
g_array_append_val(jobs, new_job);
}
free_gchar_array(&country_files);
}
/** Find out whether the country file is already loaded and part
@ -308,13 +286,8 @@ job_get_team(const Job *job)
gint i, j;
if(job->type == JOB_TYPE_NATIONAL)
if(job->type == JOB_TYPE_NATIONAL || job->type == JOB_TYPE_INTERNATIONAL) {
return team_of_id(job->team_id);
else if(job->type == JOB_TYPE_INTERNATIONAL)
{
for(i=0;i<job_teams->len;i++)
if(g_array_index(job_teams, Team, i).id == job->team_id)
return &g_array_index(job_teams, Team, i);
}
else
{

View File

@ -162,7 +162,6 @@ bygfoot_json_serialize_bygfoot(const Bygfoot *bygfoot)
SERIALIZE_BYGFOOT_FIELD(bets, bygfoot_json_serialize_bets);
SERIALIZE_BYGFOOT_FIELD(current_interest, json_object_new_double);
SERIALIZE_BYGFOOT_FIELD(jobs, bygfoot_json_serialize_jobs);
SERIALIZE_BYGFOOT_FIELD(job_teams, bygfoot_json_serialize_teams);
SERIALIZE_BYGFOOT_FIELD(cur_user, json_object_new_int64);
return bygfoot_obj;

View File

@ -319,7 +319,6 @@ main_init_variables(void)
bets[0] = g_array_new(FALSE, FALSE, sizeof(BetMatch));
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 =

View File

@ -88,9 +88,8 @@ 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;
/** Array of jobs in the job exchange. */
GArray *jobs;
/** Some counters we use. */
gint counters[COUNT_END];

View File

@ -174,9 +174,6 @@ xml_loadsave_jobs_read(const gchar *dirname, const gchar *basename)
free_jobs(TRUE);
sprintf(file, "%s%s%s___job_teams.xml", dirname, G_DIR_SEPARATOR_S, basename);
xml_loadsave_teams_read(file, job_teams);
sprintf(file, "%s%s%s___jobs.xml", dirname, G_DIR_SEPARATOR_S, basename);
context =
@ -212,9 +209,6 @@ xml_loadsave_jobs_write(const gchar *prefix)
gchar buf[SMALL];
FILE *fil = NULL;
sprintf(buf, "%s___job_teams.xml", prefix);
xml_loadsave_teams_write(buf, job_teams);
sprintf(buf, "%s___jobs.xml", prefix);
file_my_fopen(buf, "w", &fil, TRUE);