private IEnumerator DoIt(BS_MatchParams info, BS_MatchResult result) { string label = ""; foreach (var teamId in info.TeamIds) { BS_Team team = GM_Game.Finder.Get <BS_Team>(teamId); if (label.Length == 0) { label = "Team "; } else { label += " vs "; } label += team.DisplayName; } GM_Game.Popup.ShowPopup(label, "Simulating Match"); for (int i = 0; i < 5; i++) { yield return(null); } _isRunning = false; Dbg.Log("Match simulation finished"); GM_Game.Popup.ClearStatus(true); }
// --------------------------------------------------------------------------------------- /// <summary> /// Called when we're preparing to go into the match. I.e. still in League, about to go to Match. /// Creates list of MatchCombatant structures /// </summary> /// <param name="ndx"></param> /// <param name="team"></param> /// <param name="matchParams"></param> public void Initialize(int ndx, BS_Team team, BS_MatchParams matchParams) // --------------------------------------------------------------------------------------- { Combatants = new List <MT_Combatant>(); Score = 0; TeamNdx = ndx; Team = team; foreach (var v in team.GetCombatantsForMatch(matchParams)) { MT_Combatant cmbt = new MT_Combatant(); cmbt.Initialize(v, this); Combatants.Add(cmbt); } }
// ---------------------------------------------------------------------------------------------------- public IEnumerator InitializeAsNew(string name, int numTeams, int startBudget) // ---------------------------------------------------------------------------------------------------- { const string PopupHeaderText = "Creating League"; Dbg.Log("Creating new League " + name + " teams " + numTeams + " budget " + startBudget); GM_Game.Popup.ShowPopup("Initializing League " + name, PopupHeaderText); DisplayName = name; yield return(null); GM_Game.Popup.ShowPopup("Initializing arenas", PopupHeaderText); InitializeArenas(); yield return(null); Teams = new List <BS_Team>(); for (int i = 0; i < numTeams; i++) { BS_Team team = new BS_Team(); string teamName; // = "Team " + i; if (i == 0) { team.IsAI = false; teamName = "Your Team"; PT_Game.UIPlayer.Team = team; } else { team.IsAI = true; teamName = "Team " + i; } GM_Game.Popup.ShowPopup("Initializing team " + teamName, PopupHeaderText); team.Randomize(startBudget, teamName); Teams.Add(team); yield return(null); } Schedule = new LG_Schedule(); GM_Game.Popup.ShowPopup("Creating schedule", PopupHeaderText); Schedule.MakeRoundRobinSchedule(numTeams, PT_Game.Data.Consts.League_NumRRRounds); GM_Game.Popup.ClearStatus(true); Events.SendGlobal(new LG_NewLeagueInitializationFinishedEvent()); }
protected override void Start() { base.Start(); // if we're debugging arena, we might not have some things if (PT_Game.Match == null) { return; } _team = PT_Game.Match.GetTeam(_teamNdx); if (_team == null) { Dbg.LogWarning("Not team for this display"); UN.SetActive(this, false); return; } _backGround.color = _team.BaseColor; UN.SetText(_teamName, _team.DisplayName); UN.SetText(_scoreText, PT_Game.Match.GetTeamScore(_teamNdx).ToString()); List <MT_Combatant> cbts = PT_Game.Match.GetTeamCombatants(_teamNdx); int numPlayers = cbts.Count; UI_CombatantMiniDisplay thingToSet; for (int i = 0; i < numPlayers; i++) { if (i == 0) { thingToSet = _template; } else { object o = Instantiate(_template.gameObject, _playerListRoot.gameObject.transform); GameObject newThing = o as GameObject; thingToSet = newThing.GetComponent <UI_CombatantMiniDisplay>(); _combatants.Add(thingToSet); } UN.SetActive(thingToSet, true); thingToSet.SetCombatant(PT_Game.Match.GetTeamCombatants(_teamNdx)[i]); } }
// Use this for initialization protected override void OnEnable() { base.OnEnable(); if (PT_Game.Match.GetNumActiveTeams() == 0) // really only happens when debugging from match scene { return; } // ### TODO: implement 3+ teams BS_Team team = PT_Game.Match.GetTeam(0); UN.SetText(_teamL, team.DisplayName); //_teamL.color = team.BaseColor; //_scoreL.color = team.BaseColor; team = PT_Game.Match.GetTeam(1); UN.SetText(_teamR, team.DisplayName); //_teamR.color = team.BaseColor; //_scoreR.color = team.BaseColor; }
// TODO : this only supports 1v1 matches public void MakeRoundRobinSchedule(int numTeams, int numRounds) { Dbg.Log("Making round robin schedule"); // TODO fix this numteam limitation Dbg.Assert((numTeams % 2) == 0); for (int t1 = 0; t1 < numTeams; t1++) { for (int t2 = t1 + 1; t2 < numTeams; t2++) { BS_Team tm1 = PT_Game.League.Teams[t1]; BS_Team tm2 = PT_Game.League.Teams[t2]; GM_IDList idList = new GM_IDList(); idList.Add(tm1.Id); idList.Add(tm2.Id); BS_MatchParams match = new BS_MatchParams(); match.TeamIds = idList; match.Day = -1; bool found = false; for (int dayNdx = 0; dayNdx < numTeams; dayNdx++) { found = false; foreach (var m in Matches) { if (m.Day == dayNdx && (m.TeamIds.Contains(tm1.Id) || m.TeamIds.Contains(tm2.Id))) { found = true; break; } } if (found == false) { match.Day = dayNdx; break; } } Dbg.Assert(match.Day != -1); Matches.Add(match); Dbg.Log(t1 + " vs " + t2 + " day: " + match.Day); } } Matches.Sort((x, y) => { return((x.Day < y.Day) ? -1 : ((x.Day > y.Day) ? 1 : 0)); }); /* * * // this generates a full set of each team playing every other team once. * int[,] matchInfo = GenerateRoundRobin(numTeams); * NumDays = matchInfo.GetLength(1); * for (int teamIndex1 = 0; teamIndex1 < matchInfo.GetLength(0); teamIndex1++) * { * for (int round = 0; round < matchInfo.GetLength(1); round++) * { * BS_Team t1 = PT_Game.League.Teams[teamIndex1]; * BS_Team t2 = PT_Game.League.Teams[matchInfo[teamIndex1, round]]; * * //TODO add support for multiple teams * GM_IDList idList = new GM_IDList(); * idList.Add(t1.Id); * idList.Add(t2.Id); * * if (Matches.Find(FindMatch(idList, round)) == null) * { * BS_MatchParams match = new BS_MatchParams(); * match.Day = round; * match.TeamIds = idList; * * Matches.Add(match); * } * } * } * * Matches.Sort((x, y) => { return (x.Day < y.Day) ? -1 : ((x.Day > y.Day) ? 1 : 0); }); */ }