/// <summary> /// Fills the PlayerTable with players and their teams /// </summary> /// <param name="server">A reference to the Allsrv server</param> public void Initialize(IAdminServer server) { _players.Clear(); foreach (IAdminUser User in server.Users) { string Callsign = User.Name; IAGCGame TempGame = User.Ship.Game; int GameID = TempGame.GameID; // Find this player's team int TeamID = 0; for (int j = 0; j < TempGame.Teams.Count; j++) { object TeamIndex = j; IAGCTeam Team = TempGame.Teams.get_Item(ref TeamIndex); if (User.Ship.Team == Team) { break; } TeamID += 1; } _players.Rows.Add(new object[] { Callsign, GameID, TeamID }); } }
private void btRefreshPlayersList_Click(object sender, System.EventArgs e) { lvPlayers.Items.Clear(); if (igame == null) { return; } IAGCTeams iteams = igame.Teams; IEnumerator ienumteams = iteams.GetEnumerator(); int teamnum = 0; while (ienumteams.MoveNext()) { teamnum++; tbEvents.Text += "team " + teamnum + "\r\n"; IAGCTeam iteam = (IAGCTeam)ienumteams.Current; IAGCShips iships = iteam.Ships; IEnumerator ienumships = iships.GetEnumerator(); while (ienumships.MoveNext()) { IAGCShip iship = (IAGCShip)ienumships.Current; tbEvents.Text += " ship " + iship.Name + "\r\n"; ListViewItem item = new ListViewItem(iship.UniqueID.ToString()); item.SubItems.Add(iship.Name); item.SubItems.Add("Team " + teamnum.ToString() + "(" + iteam.Name + ")"); item.SubItems.Add(iship.WingID.ToString()); if (iship.BaseHullType != null) { item.SubItems.Add(iship.BaseHullType.Name); } if (iship.Sector != null) { item.SubItems.Add(iship.Sector.Name); } lvPlayers.Items.Add(item); } } // IAdminUsers iusers = igame.Users; // IEnumerator ienum = iusers.GetEnumerator(); // while (ienum.MoveNext()) // { // IAdminUser iuser = (IAdminUser) ienum.Current; // ListViewItem item = new ListViewItem(iuser.UniqueID.ToString()); // item.Tag = iuser; // IAdminShip iship = iuser.Ship; // IAGCTeam iteam = iship.Team; // item.SubItems.Add(iuser.Name); // item.SubItems.Add(iteam.UniqueID.ToString()); // item.SubItems.Add(iship.WingID.ToString()); // lvPlayers.Items.Add(item); // } }
/// <summary> /// Analyzes all players' donating status to determine which player has /// the most donatees. /// </summary> public string GetCommander(IAGCTeam team) { Hashtable Commanders = new Hashtable(team.Ships.Count); // Build a list of all players who have someone donating to them for (int j = 0; j < team.Ships.Count; j++) { object ShipIndex = j; IAGCShip Ship = team.Ships.get_Item(ref ShipIndex); // Ignore non-human ships if (!IsHuman(Ship)) { continue; } // Get the name of the player they're donating to, or themselves if not donating string DonateeName = (Ship.AutoDonate != null) ? Ship.AutoDonate.Name : Ship.Name; if (Commanders.ContainsKey(DonateeName)) { // If we've already got them, increment the # of players donating to them. int Count = (int)Commanders[DonateeName]; Commanders[DonateeName] = Count++; } else { // We don't have them, so add them with 1 player donating to them. Commanders.Add(DonateeName, 1); } } // Now we have a list of all players who have someone donating to them, and // the # of players that are donating to them. // The one with the highest # of players donating to them is the commander. string Commander = string.Empty; int NumDonaters = 0; foreach (string Donatee in Commanders.Keys) { int Donaters = (int)Commanders[Donatee]; if (Donaters > NumDonaters) { // This donatee has more donaters than the last guy... Commander = Donatee; NumDonaters = Donaters; } } return(Commander); }
/// <summary> /// Retrieves the index of the specified team /// </summary> /// <param name="teamID">The ID of the team</param> /// <returns>The index of the team with the specified ID</returns> public int GetTeamIndex(int teamID) { int Result = 0; for (int i = 0; i < _game.Teams.Count; i++) { object Index = (object)i; IAGCTeam Team = _game.Teams.get_Item(ref Index); if (Team.ObjectID == teamID) { break; } Result++; } return(Result); }
/// <summary> /// Copies all game/team parameters into this game's GameData object /// </summary> /// <param name="startTime">The time this game started</param> public void Start(DateTime startTime) { // Create _gameData.Initialize(_game.Name, _game.GameParameters.IGCStaticFile, GameSettingsHelper.GetMapName(_game), _game.GameParameters.IsSquadGame, _game.GameParameters.IsGoalConquest, _game.GameParameters.IsGoalTeamKills, _game.GameParameters.GoalTeamKills, _game.GameParameters.AllowFriendlyFire, _game.GameParameters.ShowMap, _game.GameParameters.AllowDevelopments, _game.GameParameters.AllowShipyardPath, _game.GameParameters.AllowDefections, _game.GameParameters.InvulnerableStations, _game.GameParameters.ScoresCount, _game.GameParameters.MaxImbalance, _game.GameParameters.StartingMoney, _game.GameParameters.He3Density, GameSettingsHelper.GetResources(_game), DateTime.FromOADate(_game.GameParameters.TimeStart), DateTime.FromOADate(_game.GameParameters.TimeStart)); _gameData.InitializeTeamCount(_game.Teams.Count); string CommanderName = string.Empty; for (int i = 0; i < _game.Teams.Count; i++) { object Index = i; IAGCTeam Team = _game.Teams.get_Item(ref Index); CommanderName = GetCommander(Team); _gameData.InitializeTeam(i, Team.Name, Team.Civ, CommanderName); // Add team members to data for (int j = 0; j < Team.Ships.Count; j++) { object ShipIndex = j; IAGCShip Ship = Team.Ships.get_Item(ref ShipIndex); if (IsHuman(Ship)) { _gameData.AddTeamMember(Ship.Name, i, startTime); } } } }