From b0fc95a7ad6c879641d49122e0a19008ab71e7bd Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Wed, 17 Mar 2021 19:50:35 -0700 Subject: [PATCH] Use teams from country_list for international jobs This way we don't need to generate teams sepearately for jobs. --- src/free.c | 11 ---------- src/job.c | 47 +++++++++-------------------------------- src/json_serialize.c | 1 - src/main.c | 1 - src/variables.h | 5 ++--- src/xml_loadsave_jobs.c | 6 ------ 6 files changed, 12 insertions(+), 59 deletions(-) diff --git a/src/free.c b/src/free.c index 899043ab..c3138932 100644 --- a/src/free.c +++ b/src/free.c @@ -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;ilen;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)); } } diff --git a/src/job.c b/src/job.c index 17256452..9bbe86c1 100644 --- a/src/job.c +++ b/src/job.c @@ -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;ilen - 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;ilen;i++) - if(g_array_index(job_teams, Team, i).id == job->team_id) - return &g_array_index(job_teams, Team, i); } else { diff --git a/src/json_serialize.c b/src/json_serialize.c index 32940a83..a79bc452 100644 --- a/src/json_serialize.c +++ b/src/json_serialize.c @@ -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; diff --git a/src/main.c b/src/main.c index c6361f1f..da87d972 100644 --- a/src/main.c +++ b/src/main.c @@ -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 = diff --git a/src/variables.h b/src/variables.h index f2f5bf36..cd169790 100644 --- a/src/variables.h +++ b/src/variables.h @@ -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]; diff --git a/src/xml_loadsave_jobs.c b/src/xml_loadsave_jobs.c index 5a6fcb08..d8cf4167 100644 --- a/src/xml_loadsave_jobs.c +++ b/src/xml_loadsave_jobs.c @@ -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);