/// <summary> /// Determines if the specified ship is human /// </summary> /// <param name="ship">The ship to determine if it's human</param> /// <returns>True if human, false if not</returns> public bool IsHuman(IAGCShip ship) { bool Result = false; try { if (ship != null) { if (ship.HullType != null) { short Capabilities = ship.HullType.Capabilities; if ((Capabilities & 16384) != 16384 && (Capabilities & 32768) != 32768 && (Capabilities & 1024) != 1024) { Result = true; } } } } catch (Exception) { // Checking Capabilities sometimes throws an exception on drones } return(Result); }
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> /// 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); } } } }