Commit Graph

652 Commits

Author SHA1 Message Date
Tom Stellard 25d9880da4 Generate a 'pre-history' for cups
We know generate cup results for each cup before starting the game.
This allows cups to select last year's winner without having to
special case cup selection for the first season.
2021-07-27 14:41:40 -04:00
Tom Stellard 2d17321b94 Enusre that a teams aren't added to cups more than once. 2021-07-27 14:41:40 -04:00
Tom Stellard b2b3d55f58 Support the optional and alternative tags for user's league in cup defs 2021-07-27 14:41:40 -04:00
Tom Stellard e95c6aac96 Remove the team_names file from the Cup struct
This field was not being updated correctly in some case and we
can just you the teams field instead to get the names.
2021-07-27 14:41:40 -04:00
Tom Stellard f1c9f498fe Don't add the user's country to the country list
The user's country is already being stored in the country
global variable.
2021-07-27 14:41:40 -04:00
Tom Stellard f7713e8b96 Fix bug with choose_team alternatives
If the main team was in the user's country and the alternative was not,
the choose team would fail, because there are different paths for
the user's country and other countries.

This patch merges both paths into cup_load_choose_team() so that
function will work for any country.
2021-07-27 14:41:40 -04:00
Tom Stellard dd71c31eda Refactor cup_load_choose_team_generate()
Updates its signature to match cup_load_choose_team().
2021-07-27 14:41:40 -04:00
Tom Stellard a1119d0dd8 Randomize teams lists of non-user countries every season
This way the international cups will have new teams each year.
2021-07-27 14:41:40 -04:00
Tom Stellard 3e4ead3aae Reset all cups at the beginning of each season
This fixes a bug in league fixture scheduling where league matches would
be scheduled around cup matches from the previous season.  This caused
league matches to be scheduled in later week rounds which in some cases
caused these matches to not be played.
2021-07-27 14:41:40 -04:00
Tom Stellard ac4d0fc546 Use cup history for self-referential cups 2021-07-27 14:41:40 -04:00
Tom Stellard 30d96e9952 Save cup results at the end of each season 2021-07-27 14:41:40 -04:00
Tom Stellard fbfc2e22d8 Remove team_id from User object 2021-07-27 14:41:40 -04:00
Tom Stellard a23db0b434 Remove team_ids field from Fixture object
We can fetch the ids from the teams object instead.
2021-07-27 14:41:40 -04:00
Tom Stellard 47fa16ddcd fixture_write_round_robin: Use a NULL team to represent a bye
Also don't write byes to the fixture list.  Previously we were writing
byes and removing them later.
2021-07-27 14:41:40 -04:00
Tom Stellard 0f5213bc4e Don't refresh fixture team pointers at the start of season
This is no longer necessary now that team pointers are stable.
2021-07-27 14:41:40 -04:00
Tom Stellard 801cb99b74 Remove team_id member from TableElement
This is no longer needed now that Team pointers always point to the same
team.
2021-07-27 14:41:40 -04:00
Tom Stellard 47b6d5c80d Use a GPtrArray to store teams in leagues
This allows us to have stable Team pointers throughout the game,
so we don't need to recompute pointers from Team IDs every time
the league order changes.
2021-07-27 14:41:40 -04:00
Tom Stellard a004f939bb Refactor xml_league_read() 2021-07-27 14:41:40 -04:00
Tom Stellard 1fcec6e057 Refactor user_set_up_team_new_game() 2021-07-27 14:41:40 -04:00
Tom Stellard d4cf73b8d8 Refactor treeview_create_team_selection_list()
Add a Country parameter so that it does not rely on global variables and
simplify some of the code.
2021-07-27 14:41:40 -04:00
Tom Stellard 9a0388cafd Refactor stat_update_league_players() 2021-07-27 14:41:40 -04:00
Tom Stellard 7c1fe79763 Refactor start_new_season_league_changes() 2021-07-27 14:41:40 -04:00
Tom Stellard 19d361fb82 Refactor league_season_start() 2021-07-27 14:41:40 -04:00
Tom Stellard 9d144835ed Refactor team_get_average_talents() 2021-07-27 14:41:40 -04:00
Tom Stellard 5373da9c30 Refactor job_change_country() 2021-07-27 14:41:40 -04:00
Tom Stellard d84b8683ed Refactor fixture_remove_rrs() 2021-07-27 14:41:40 -04:00
Tom Stellard 05ac1ccb7c Refactor fixture_write_league_fixtures() 2021-07-27 14:41:40 -04:00
Tom Stellard 8ea51d65a1 Refactor cup_load_choose_team_from_cup() 2021-07-27 14:41:40 -04:00
Tom Stellard 273ca50688 json: Add command for getting the country's leagues 2021-07-27 14:41:40 -04:00
Tom Stellard 4d4d73caa0 Allow optional tag to be used when selecting teams from cups
This fixes a segfault caused by the uefa_el definitions when there
aren't enough teams in uefa_cl to fill all the spots in the choose_team
definition.
2021-07-27 14:41:40 -04:00
Tom Stellard b126786553 Add helper cup_choose_team_compute_{start,end}_idx helper functions 2021-07-27 14:41:40 -04:00
Tom Stellard 87b5a77ab2 Initialize current_interest after setting the random seed
The way when we run benchmark.sh --verify, the current_interest value
will always be the same.
2021-07-27 14:41:40 -04:00
Tom Stellard c62cbe01c6 Remove usage of g_ptr_array_foreach()
This function does not appear to provide any benefits compared to a
standard loop, and it may prevent some compiler optimizations, like
inlining.
2021-04-11 08:21:23 -07:00
Tom Stellard 5c3e3522c0 json: Fix bug serializing team pointers 2021-04-11 08:21:23 -07:00
Tom Stellard 34defb6642 Use teams from country_list for international jobs
This way we don't need to generate teams sepearately for jobs.
2021-04-03 15:43:39 -07:00
Tom Stellard 804185f354 Parse strategy conditions once when loading them from xml
This way strategy_live_game_check() only needs to evaluate the condition
and does not need to reparse it over and over again.

This reduces the number of instructions reported by
./test/benchmark.sh --benchmark by ~35%.
2021-03-30 10:20:11 -04:00
Tom Stellard 72549415cc Refactor strategy_live_game_check() 2021-03-30 10:20:11 -04:00
Tom Stellard ff343e94d3 Try to avoid calling team_get_fixture() from player_is_banned()
team_get_fixture() is expensive and we can avoid this call in the
majority of cases.

This reduces the number of instructions reported by
./test/benchmark.sh --benchmark by ~40%.
2021-03-27 09:23:22 -04:00
Tom Stellard 879190e971 Fix item size for Player cards array 2021-03-27 09:23:22 -04:00
Tom Stellard 8a701be6a1 Complete json serialization support for all Bygfoot objects 2021-03-26 22:47:26 -04:00
Tom Stellard 0f25c31ee5 Fix bug in query_cup_begins()
The function incorrectly assumed that cups where all the scheduled games
had been played wre complete, and did not take into account the fact
that games for later rounds may not have been scheduled yet.
2021-03-05 23:38:28 -05:00
Tom Stellard 4ad92b9884 Avoid infinite loop in job_pick_team_from_country()
This function was looping forever if all the national teams were added
to the job list.
2021-03-05 23:38:28 -05:00
Tom Stellard fdc15fdf8a Add optional tag 2021-03-05 23:38:28 -05:00
Tom Stellard a3a9e1bacc Add cup sid to debug printfs 2021-03-05 23:38:28 -05:00
Tom Stellard 38aa82d99b Iterate over cup rounds in reverse order when selecting teams
Some cups allow teams to qualify in multiple ways and we want to
always select teams into the highest round possible.
2021-03-05 23:38:28 -05:00
Tom Stellard be9b591c0e Add alternatives tag to choose_team
This allows you to specify an alternative choose_team in the case the
first choose_team does not match any teams.  This can happen if a team
qualifies for another cup in the same cup group.  You may list an
unlimited number of alternatives with this new tag.  Here is an example of
how to use it:

<choose_team>
  <choose_team_sid>faroe_islands_cup</choose_team_sid>
  <number_of_teams>1</number_of_teams>
  <start_idx>1</start_idx>
  <end_idx>1</end_idx>
  <alternatives>
    <choose_team>
      <choose_team_sid>faroe_islands1</choose_team_sid>
      <number_of_teams>1</number_of_teams>
      <start_idx>1</start_idx>
      <end_idx>1</end_idx>
    </choose_team>
  </alternatives>
</choose_team>

This example chooses the winner of the faroe_islands_cup, but if that
team is not eligible for the cup, then it will choose the winner of the
faroe_islands1 league.
2021-03-05 23:38:28 -05:00
Tom Stellard 8a3100a28c Add support for specifying cups in choose_team_sid tag for generated teams
This makes it possible to include national cup winners in international
cups.
2021-03-05 23:38:28 -05:00
Tom Stellard 347d74a3c4 Load all league and team names at the beginning of the game
This way we don't have to reload the country xml definitions every time
we have to generate a new team.
2021-03-05 23:38:28 -05:00
Tom Stellard 37b9d8bf46 Refactor cup_reset() 2021-03-05 23:38:28 -05:00
Tom Stellard f56e1b64be Refactor cup_load_choose_team_generate() 2021-03-05 23:38:28 -05:00