public HullClassifier(IMySlimBlock block)
 {
     SlimBlock     = block;
     FatBlock      = block.FatBlock;
     m_SubTypeName = FatBlock.BlockDefinition.SubtypeName;
     Class         = HullClassFromSubTypeString(m_SubTypeName);
 }
Exemplo n.º 2
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");
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Increments the class count for a given class
        /// </summary>
        /// <param name="c">Class to increment</param>
        public void add(HullClass.CLASS c, GridEnforcer ge)
        {
            log("adding class " + ge.Class, "add", Logger.severity.TRACE);

            int classID = (int)ge.Class;

            //log("m_Counts[classID] is " + m_Counts[classID], "add", Logger.severity.TRACE);

            updateSupportAdded(ge);
            m_Counts[classID] += 1;
            m_TotalCount++;
            //log("m_Counts[classID] is " + m_Counts[classID], "add", Logger.severity.TRACE);

            //debugPrint("add");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Determines whether this fleet is allowed to support this class
        /// Alerts the grid and updates tracking
        /// Returns true if it was supported
        /// </summary>
        private bool updateSupportAdded(GridEnforcer ge)
        {
            HullClass.CLASS hc  = ge.Class;
            uint            c   = (uint)hc;
            long            eID = ge.Container.Entity.EntityId;

            //log("adding " + eID + " as " + c, "updateSupportAdded");

            // if we have enough room, support it
            if (canSupportAnother(hc))
            {
                log("we have enough room, supporting", "updateSupportAdded");
                m_SupportedGrids[c][eID] = ge;
                ge.markSupported(m_FactionId);
                return(true);
            }

            // if we don't, see if it's bigger than one of the supported ones
            foreach (KeyValuePair <long, GridEnforcer> pair in m_SupportedGrids[c])
            {
                GridEnforcer supported = pair.Value;

                // it is!
                if (ge.BlockCount > supported.BlockCount)
                {
                    log("it's larger than one of our supported, supporting", "updateSupportAdded");

                    // remove support from the old supported one
                    log("removing support from " + pair.Key, "updateSupportAdded");
                    m_SupportedGrids[c].Remove(pair.Key);
                    m_UnsupportedGrids[c][pair.Key] = supported;
                    supported.markUnsupported(m_FactionId);

                    // add support to the new
                    log("supporting " + eID, "updateSupportAdded");
                    m_SupportedGrids[c][eID] = ge;
                    ge.markSupported(m_FactionId);

                    return(true);
                }
            }

            // if not, mark as unsupported
            log("can't support, marking grid as unsupported", "updateSupportAdded");
            m_UnsupportedGrids[c][eID] = ge;
            ge.markUnsupported(m_FactionId);
            return(false);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Decrements the class count for a given class
        /// </summary>
        /// <param name="c">Class to decrement</param>
        public void remove(HullClass.CLASS c, GridEnforcer ge)
        {
            int classID = (int)c;

            if (m_Counts[classID] > 0)
            {
                m_Counts[classID] -= 1;
                m_TotalCount--;
            }
            else
            {
                log("Error: Decrementing class " + classID + " count, but already 0",
                    "removeClass", Logger.severity.ERROR);
            }

            updateSupportRemoved(classID, ge);
            //debugPrint("remove");
        }
Exemplo n.º 8
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);
            m_Grid = Container.Entity as IMyCubeGrid;

            m_Logger = new Logger(m_Grid.EntityId.ToString(), "GridEnforcer");
            log("Loaded into new grid", "Init");

            // If this is not the server we don't need this class.
            // When we modify the grid on the server the changes should be
            // sent to all clients
            try {
                m_IsServer = Utility.isServer();
                log("Is server: " + m_IsServer, "Init");
                if (!m_IsServer) {
                    // No cleverness allowed :[
                    log("Disabled.  Not server.", "Init");
                    m_Logger = null;
                    m_Grid = null;
                    return;
                }
            } catch (NullReferenceException e) {
                log("Exception.  Multiplayer is not initialized.  Assuming server for time being: " + e,
                    "Init");
                // If we get an exception because Multiplayer was null (WHY KEEN???)
                // assume we are the server for a little while and check again later
                m_IsServer = true;
                m_CheckServerLater = true;
            }

            // We need to only turn on our rule checking after startup. Otherwise, if
            // a beacon is destroyed and then the server restarts, all but the first
            // 25 blocks will be deleted on startup.
            m_Grid.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            m_BlockCount = 0;
            m_BlockTypeCounts = new int[s_Settings.BlockTypes.Length];
            m_Owner = new GridOwner(this);
            m_Classifiers = new Dictionary<long, HullClassifier>();
            m_Projectors = new Dictionary<long, InGame.IMyProjector>();
            m_ReservedClass = DEFAULT_CLASS;
            m_ReservedRules = s_Settings.HullRules[(int)DEFAULT_CLASS];
            m_EffectiveClass = DEFAULT_CLASS;
            m_EffectiveRules = s_Settings.HullRules[(int)DEFAULT_CLASS];
            reserveEffectiveClassFromOwner();

            m_Grid.OnBlockAdded += blockAdded;
            m_Grid.OnBlockRemoved += blockRemoved;
            m_Grid.OnBlockOwnershipChanged += blockOwnerChanged;
            m_GridSubscribed = true;
        }
Exemplo n.º 9
0
 private void setReservedTo(HullClass.CLASS newClass)
 {
     if (m_ReservedClass == newClass) {
         log("No change, ReservedClass remains " + m_ReservedClass, "setReservedTo");
     }
     else {
         log("Changing ReservedClass from " + m_ReservedClass + " to " + newClass,
             "setReservedTo");
         m_ReservedClass = newClass;
         m_ReservedRules = s_Settings.HullRules[(int)newClass];
     }
 }
Exemplo n.º 10
0
 private void setEffectiveTo(HullClass.CLASS newClass)
 {
     if (m_EffectiveClass == newClass) {
         log("No changed, EffectiveClass remains " + m_EffectiveClass, "setEffectiveTo");
     }
     else {
         log("Changing EffectiveClass from " + m_EffectiveClass + " to " + newClass,
             "setEffectiveTo");
         m_EffectiveClass = newClass;
         m_EffectiveRules = s_Settings.HullRules[(int)newClass];
         reserveEffectiveClassFromOwner();
         m_CheckCleanupNextUpdate = true;
     }
 }
Exemplo n.º 11
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");
        }
Exemplo n.º 12
0
 public bool canSupportAnother(HullClass.CLASS c)
 {
     return((countClass(c) < maxClass(c)) || (maxClass(c) < 0));
 }
Exemplo n.º 13
0
 public uint maxClass(HullClass.CLASS c)
 {
     return(m_Maximums[(int)c]);
 }
Exemplo n.º 14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="c">Class to check</param>
 /// <returns>Count of c</returns>
 public uint countClass(HullClass.CLASS c)
 {
     return(m_Counts[(int)c]);
 }