public static ControlPoint deserialize(VRage.ByteStream stream)
        {
            ControlPoint result = new ControlPoint();

            long x, y, z;
            x = stream.getLong();
            y = stream.getLong();
            z = stream.getLong();
            result.Position = new VRageMath.Vector3D(x, y, z);

            result.Name = stream.getString();
            result.Radius = (int)stream.getLong();
            result.TokensPerPeriod = (int)stream.getLong();

            return result;
        }
Exemple #2
0
        /// <summary>
        /// Notify players within the CP whether they won, lost, or tied
        /// </summary>
        public void notifyPlayersOfCPResults(int rewardsDistributed,
			List<long> winningFleetIds, List<IMyPlayer> nearbyPlayers, ControlPoint cp)
        {
            bool tie = (winningFleetIds.Count > 1);
            long winningFleetId = 0;
            if (!tie) winningFleetId = winningFleetIds.First();

            var winningPlayers = new List<long>();
            var tiedPlayers = new List<long>();
            var losingPlayers = new List<long>();

            foreach (IMyPlayer player in nearbyPlayers) {
                long fleetID = player.FleetID();

                if (!tie && fleetID == winningFleetId) {
                    winningPlayers.Add(player.PlayerID);
                } else if (tie && winningFleetIds.Contains(fleetID)) {
                    tiedPlayers.Add(player.PlayerID);
                } else {
                    losingPlayers.Add(player.PlayerID);
                }
            }

            if (winningPlayers.Count > 0) {
                notifyPlayers(String.Format(
                    "You control {0} and received {1} licenses.",
                    cp.Name, rewardsDistributed),
                    winningPlayers, MyFontEnum.Green);
            }
            if (tiedPlayers.Count > 0) {
                notifyPlayers(String.Format(
                    "You tied for control of {0} and received no licenses.",
                    cp.Name), tiedPlayers, MyFontEnum.Red);
            }
            if (losingPlayers.Count > 0) {
                notifyPlayers("Someone else controls " + cp.Name,
                    losingPlayers, MyFontEnum.Red);
            }
        }
Exemple #3
0
        /// <summary>
        /// Returns a list of grids in the vicinity of the CP
        /// </summary>
        /// <param name="cp">Control point to check</param>
        /// <returns></returns>
        private List<IMyCubeGrid> getGridsInCPRadius(ControlPoint cp)
        {
            // Get all ents within the radius
            VRageMath.BoundingSphereD bounds =
                new VRageMath.BoundingSphereD(cp.Position, (double)cp.Radius);
            List<IMyEntity> ents =
                MyAPIGateway.Entities.GetEntitiesInSphere(ref bounds);

            // Get only the ships/stations
            List<IMyCubeGrid> grids = new List<IMyCubeGrid>();
            foreach (IMyEntity e in ents) {
                if (e is IMyCubeGrid)
                    grids.Add(e as IMyCubeGrid);
            }

            return grids;
        }
        private static void notifyRewardsDistributed(int distributed, List<long> winningFleets,
			List<IMyPlayer> nearbyPlayers, ControlPoint cp)
        {
            if (actionDistributeRewards != null)
                actionDistributeRewards(distributed, winningFleets, nearbyPlayers, cp);
        }