Exemple #1
0
        /// <summary>
        /// If the class has changed, update class the fleet stored it as
        /// </summary>
        /// <param name="c">New Hull Class</param>
        public void setClassification(HullClass.CLASS c)
        {
            if (m_Class == c)
            {
                return;
            }

            log("changing owner class to " + c, "setClassification");
            m_Fleet.remove(m_Class, m_Enforcer);
            m_Class = c;
            m_Fleet.add(m_Class, m_Enforcer);
            log("Owner class changed to " + m_Class, "setClassification");
        }
Exemple #2
0
        public GridOwner(GridEnforcer ge)
        {
            m_Enforcer = ge;
            m_Logger = new Logger(m_Enforcer.Grid.EntityId.ToString(), "GridOwner");
            log("Loaded into new grid", "ctr");

            // the grid will update ownership later b/c this is initialized with the grid,
            // and the grid doesn't have any blocks yet
            m_OwnerType = OWNER_TYPE.UNOWNED;
            m_FleetID = getFleetID();

            m_Class = ge.Class;
            m_Fleet = getFleet();
            m_Fleet.add(m_Class, ge);
        }
Exemple #3
0
        public GridOwner(GridEnforcer ge)
        {
            m_Enforcer = ge;
            m_Logger   = new Logger(m_Enforcer.Grid.EntityId.ToString(), "GridOwner");
            log("Loaded into new grid", "ctr");

            // the grid will update ownership later b/c this is initialized with the grid,
            // and the grid doesn't have any blocks yet
            m_OwnerType = OWNER_TYPE.UNOWNED;
            m_FleetID   = getFleetID();

            m_Class = ge.Class;
            m_Fleet = getFleet();
            m_Fleet.add(m_Class, ge);
        }
Exemple #4
0
        /// <summary>
        /// Figures out who owns the grid now
        /// </summary>
        /// <returns>Returns true if the owner has changed</returns>
        public bool reevaluateOwnership(List <long> bigOwners)
        {
            log("Reevaluating owner", "reevaluateOwnership");
            bool changed = false;

            // = Get new ownership details
            OWNER_TYPE newType      = OWNER_TYPE.UNOWNED;
            long       newPlayerID  = 0;
            long       newFactionID = 0;

            if (bigOwners.Count == 0)
            {
                newType = OWNER_TYPE.UNOWNED;
            }
            else
            {
                if (bigOwners.Count > 1)
                {
                    log("bigOwner tie! Using first owner.",
                        "reevaluateOwnership", Logger.severity.WARNING);
                }

                newPlayerID = bigOwners[0];
                IMyFaction fac = MyAPIGateway.Session.Factions.TryGetPlayerFaction(newPlayerID);

                // Is the player solo?
                if (fac == null)
                {
                    newType = OWNER_TYPE.PLAYER;
                }
                else
                {
                    newType      = OWNER_TYPE.FACTION;
                    newFactionID = fac.FactionId;
                }
            }

            long newFleetID = calcFleetID(newType, newPlayerID, newFactionID);

            // = Effect changes
            if (m_OwnerType != newType)
            {
                log(String.Format("type changed from {0} => {1}",
                                  m_OwnerType, newType), "reevaluateOwnership");
                m_OwnerType = newType;
                changed     = true;
            }

            if (m_PlayerID != newPlayerID)
            {
                log(String.Format("player changed from {0} => {1}",
                                  m_PlayerID, newPlayerID), "reevaluateOwnership");
                m_PlayerID = newPlayerID;
                changed    = true;
            }

            if (m_FactionID != newFactionID)
            {
                log(String.Format("faction changed from {0} => {1}",
                                  m_FactionID, newFactionID), "reevaluateOwnership");
                m_FactionID = newFactionID;
                changed     = true;
            }

            // If the fleet tracking ID has changed, or if we've got a temp fleet, update the fleet
            if ((m_FleetID != newFleetID) || (!m_StateLoaded && GridEnforcer.StateTracker != null))
            {
                log(String.Format("Doing fleet change {0} => {1}, was temp? {2}",
                                  m_FleetID, newFleetID, !m_StateLoaded), "reevaluateOwnership");

                // Remove the grid from the previous fleet
                if (m_Fleet == null)
                {
                    log("Fleet is null", "reevaluateOwnership", Logger.severity.ERROR);
                }
                else
                {
                    m_Fleet.remove(m_Class, m_Enforcer);
                }

                m_FleetID = newFleetID;
                m_Fleet   = getFleet();

                // Add the grid to the new fleet
                if (m_Fleet == null)
                {
                    log("Failed to get new fleet for " + m_FleetID,
                        "reevaluateOwnership", Logger.severity.ERROR);
                }
                else
                {
                    m_Fleet.add(m_Class, m_Enforcer);
                }

                changed = true;
            }

            if (changed)
            {
                return(true);
            }
            else
            {
                log(String.Format("no change, owner: {0} {1}", m_OwnerType, m_FleetID),
                    "reevaluateOwnership");
                return(false);
            }
        }
Exemple #5
0
        /// <summary>
        /// Figures out who owns the grid now
        /// </summary>
        /// <returns>Returns true if the owner has changed</returns>
        public bool reevaluateOwnership(List<long> bigOwners)
        {
            log("Reevaluating owner", "reevaluateOwnership");
            bool changed = false;

            // = Get new ownership details
            OWNER_TYPE newType = OWNER_TYPE.UNOWNED;
            long newPlayerID = 0;
            long newFactionID = 0;

            if (bigOwners.Count == 0) {
                newType = OWNER_TYPE.UNOWNED;

            } else {
                if (bigOwners.Count > 1) {
                    log("bigOwner tie! Using first owner.",
                        "reevaluateOwnership", Logger.severity.WARNING);
                }

                newPlayerID = bigOwners[0];
                IMyFaction fac = MyAPIGateway.Session.Factions.TryGetPlayerFaction(newPlayerID);

                // Is the player solo?
                if (fac == null) {
                    newType = OWNER_TYPE.PLAYER;
                } else {
                    newType = OWNER_TYPE.FACTION;
                    newFactionID = fac.FactionId;
                }
            }

            long newFleetID = calcFleetID(newType, newPlayerID, newFactionID);

            // = Effect changes
            if (m_OwnerType != newType) {
                log(String.Format("type changed from {0} => {1}",
                    m_OwnerType, newType), "reevaluateOwnership");
                m_OwnerType = newType;
                changed = true;
            }

            if (m_PlayerID != newPlayerID) {
                log(String.Format("player changed from {0} => {1}",
                    m_PlayerID, newPlayerID), "reevaluateOwnership");
                m_PlayerID = newPlayerID;
                changed = true;
            }

            if (m_FactionID != newFactionID) {
                log(String.Format("faction changed from {0} => {1}",
                    m_FactionID, newFactionID), "reevaluateOwnership");
                m_FactionID = newFactionID;
                changed = true;
            }

            // If the fleet tracking ID has changed, or if we've got a temp fleet, update the fleet
            if ((m_FleetID != newFleetID) || (!m_StateLoaded && GridEnforcer.StateTracker != null)) {
                log(String.Format("Doing fleet change {0} => {1}, was temp? {2}",
                    m_FleetID, newFleetID, !m_StateLoaded), "reevaluateOwnership");

                // Remove the grid from the previous fleet
                if (m_Fleet == null) {
                    log("Fleet is null", "reevaluateOwnership", Logger.severity.ERROR);
                } else {
                    m_Fleet.remove(m_Class, m_Enforcer);
                }

                m_FleetID = newFleetID;
                m_Fleet = getFleet();

                // Add the grid to the new fleet
                if (m_Fleet == null) {
                    log("Failed to get new fleet for " + m_FleetID,
                        "reevaluateOwnership", Logger.severity.ERROR);
                } else {
                    m_Fleet.add(m_Class, m_Enforcer);
                }

                changed = true;
            }

            if (changed) {
                return true;
            } else {
                log(String.Format("no change, owner: {0} {1}", m_OwnerType, m_FleetID),
                    "reevaluateOwnership");
                return false;
            }
        }