Example #1
0
        private void BlockAdded(IMySlimBlock slimblock)
        {
            //Log.Trace(slimblock.ToString() + " added to InventoryManager for " + Grid.DisplayName, "blockAdded");

            if (slimblock == null)
            {
                Log.Error("Received null slimblock", "blockAdded");
                return;
            }

            MyEntity fatEntity = slimblock.FatBlock as MyEntity;

            if (fatEntity == null)
            {
                return;
            }

            MyInventoryBase inventory;

            if (!fatEntity.TryGetInventory(out inventory))
            {
                return;
            }

            Log.Trace("Adding inventory " + slimblock.ToString(), "blockAdded");
            InventoryTotals[inventory] = new ItemCountsAggregate();
            //InventoryAggregate.ChildList.AddComponent(inventory);
            OnContentsChanged(inventory);
            inventory.ContentsChanged += OnContentsChanged;
        }
Example #2
0
        private void BlockRemoved(IMySlimBlock slimblock)
        {
            //Log.Trace(slimblock.ToString() + " removed from InventoryManager for " + Grid.DisplayName, "blockRemoved");

            if (slimblock == null)
            {
                Log.Error("Received null slimblock", "blockRemoved");
                return;
            }

            MyEntity fatEntity = slimblock.FatBlock as MyEntity;

            if (fatEntity == null)
            {
                return;
            }

            MyInventoryBase inventory;

            if (!fatEntity.TryGetInventory(out inventory))
            {
                return;
            }

            Log.Trace("Removing inventory " + slimblock.ToString(), "blockRemoved");
            if (!InventoryTotals.Remove(inventory))
            {
                Log.Error("Received an removal for inventory we're not tracking.", "blockRemoved");
                return;
            }

            //InventoryAggregate.ChildList.RemoveComponent(inventory);
            inventory.ContentsChanged -= OnContentsChanged;
        }
Example #3
0
        public static string getBestName(this IMySlimBlock slimBlock)
        {
            IMyCubeBlock Fatblock = slimBlock.FatBlock;

            if (Fatblock != null)
            {
                return(Fatblock.getBestName());
            }
            return(slimBlock.ToString());
        }
Example #4
0
        public static string nameWithId(this IMySlimBlock slimBlock)
        {
            IMyCubeBlock Fatblock = slimBlock.FatBlock;

            if (Fatblock != null)
            {
                return(Fatblock.nameWithId());
            }
            return(slimBlock.ToString());
        }
Example #5
0
        /// <summary>
        /// Does the passed block belong to this group?
        /// </summary>
        public bool appliesToBlock(IMySlimBlock block)
        {
            // IMySlimBlock.ToString() does:
            // FatBlock != null ? FatBlock.ToString() : BlockDefinition.DisplayNameText.ToString();
            // which is nice since we're not allowed access to BlockDefinition of a SlimBlock
            String blockString = block.ToString().ToLower();

            log("Does " + blockString + " belong in group " + SubTypeStrings.ToString() + " ? ",
                "appliedToBlock", Logger.severity.TRACE);

            foreach (String subType in SubTypeStrings) {
                if (blockString.Contains(subType.ToLower())) {
                    log("It does!", "appliedToBlock", Logger.severity.TRACE);
                    return true;
                }
            }
            log("It doesn't", "appliedToBlock", Logger.severity.TRACE);
            return false;
        }
        /// <summary>
        /// Does the passed block belong to this group?
        /// </summary>
        public bool appliesToBlock(IMySlimBlock block)
        {
            // IMySlimBlock.ToString() does:
            // FatBlock != null ? FatBlock.ToString() : BlockDefinition.DisplayNameText.ToString();
            // which is nice since we're not allowed access to BlockDefinition of a SlimBlock
            String blockString = block.ToString().ToLower();

            log("Does " + blockString + " belong in group " + SubTypeStrings.ToString() + " ? ",
                "appliedToBlock", Logger.severity.TRACE);

            foreach (String subType in SubTypeStrings)
            {
                if (blockString.Contains(subType.ToLower()))
                {
                    log("It does!", "appliedToBlock", Logger.severity.TRACE);
                    return(true);
                }
            }
            log("It doesn't", "appliedToBlock", Logger.severity.TRACE);
            return(false);
        }
Example #7
0
        /// <summary>
        /// Called when a block is removed.  Decrements counts and checks for declassification.
        /// </summary>
        /// <param name="removed"></param>
        private void blockRemoved(IMySlimBlock removed)
        {
            try {
                updateClassificationWithout(removed);
                decrementBlockCount();
                updateBlockTypeCountsWithout(removed);
                updateProjectorsWithout(removed);

                log(removed.ToString() + " removed from grid '" + m_Grid.DisplayName +
                    "'. Total Count now: " + m_BlockCount, "blockRemoved");

                m_CheckCleanupNextUpdate = true;

            } catch (Exception e) {
                log("Error: " + e, "blockRemoved");
            }
        }
Example #8
0
        /// <summary>
        /// Called when a block is added to the grid.
        /// Decides whether or not to allow the block to be placed.
        /// Increments counts, checks for classification, and sets
        /// a flag to refresh cleanup status
        /// </summary>
        /// <param name="added">block that was added to the grid</param>
        private void blockAdded(IMySlimBlock added)
        {
            //log(added.ToString() + " added to grid " + m_Grid.DisplayName, "blockAdded");

            try {
                // Counts and Caches must be updated whether we're removing the block or not,
                // because blockRemoved has no way of knowing if we touched counts for it
                log("Update block lists and counts", "blockAdded");
                VIOLATION_TYPE classifierViolation = updateClassifiersWith(added);
                VIOLATION_TYPE totalBlocksViolation = incrementBlockCount();
                List<BlockType> violatedTypes = updateBlockTypeCountsWith(added);
                updateProjectorsWith(added);

                // we skip violation checks:
                // for blocks that aren't actually placed by a user, i.e. during World Load or a Merge
                log("checking enforcement skip conditions", "blockAdded");

                if (m_Merging || !m_BeyondFirst100) {
                    log("Currently merging or initing, don't do placement enforcment",
                        "blockAdded");
                    goto Allowed;
                }
                // if we're projecting
                if (Projecting) {
                    log("We are projecting, don't do placement enforcment",
                        "blockAdded");
                    goto Allowed;
                }

                // If there are violations, disallow placement
                // Everything will eventually be cleaned up over time, but we do this
                // enforcment on placement to help keep people in line
                log("check placement violations", "blockAdded");

                // classifier violations come first
                if (classifierViolation != VIOLATION_TYPE.NONE) {

                    // people find it really annoying that they have to have an
                    // owned block before placing a classifier.
                    if (classifierViolation == VIOLATION_TYPE.TOO_MANY_OF_CLASS &&
                        isUnowned()) {
                        log("Too many of class but unowned, don't do placement enforcment",
                            "checkClassAllowed");
                        goto Allowed;
                    }

                    log("classifierViolation enforce", "blockAdded");
                    notifyPlacementViolation(classifierViolation);
                    goto Denied;
                }

                // then total blocks
                else if (totalBlocksViolation != VIOLATION_TYPE.NONE) {

                    // people also find it annoying to have to delete all the blocks
                    // on a ship that just became unclassified before they can build
                    // another classifier or reactor to bring it in line
                    if (helpsClassifyUnclassified(added)) {
                        log("provides needed classification, don't do placement enforcment",
                            "blockAdded");
                        goto Allowed;
                    }

                    log("totalBlocksViolation enforce", "blockAdded");
                    notifyPlacementViolation(totalBlocksViolation);
                    goto Denied;
                }
                else if (violatedTypes.Count > 0) {
                    notifyPlacementViolation(VIOLATION_TYPE.BLOCK_TYPE);
                    log("block type violation enforced", "blockAdded");
                    goto Denied;
                }
            }
            catch (Exception e) {
                log("Error: " + e, "blockAdded");
            }

            Allowed:
            log(added.ToString() + " added to grid '" + m_Grid.DisplayName +
                "'. Total Count now: " + m_BlockCount, "blockAdded");
            m_CheckOwnerNextUpdate = true;
            m_CheckCleanupNextUpdate = true;
            return;

            Denied:
            log(added.ToString() + " denied for grid '" + m_Grid.DisplayName +
                "'. Total Count now: " + m_BlockCount, "blockAdded");

            removeBlock(added);
        }
        private void BlockRemoved(IMySlimBlock slimblock)
        {
            //Log.Trace(slimblock.ToString() + " removed from InventoryManager for " + Grid.DisplayName, "blockRemoved");

            if (slimblock == null) {
                Log.Error("Received null slimblock", "blockRemoved");
                return;
            }

            MyEntity fatEntity = slimblock.FatBlock as MyEntity;
            if (fatEntity == null)
                return;

            MyInventoryBase inventory;
            if (!fatEntity.TryGetInventory(out inventory))
                return;

            Log.Trace("Removing inventory " + slimblock.ToString(), "blockRemoved");
            if (!InventoryTotals.Remove(inventory)) {
                Log.Error("Received an removal for inventory we're not tracking.", "blockRemoved");
                return;
            }

            //InventoryAggregate.ChildList.RemoveComponent(inventory);
            inventory.ContentsChanged -= OnContentsChanged;
        }
        private void BlockAdded(IMySlimBlock slimblock)
        {
            //Log.Trace(slimblock.ToString() + " added to InventoryManager for " + Grid.DisplayName, "blockAdded");

            if (slimblock == null) {
                Log.Error("Received null slimblock", "blockAdded");
                return;
            }

            MyEntity fatEntity = slimblock.FatBlock as MyEntity;
            if (fatEntity == null) return;

            MyInventoryBase inventory;
            if (!fatEntity.TryGetInventory(out inventory)) return;

            Log.Trace("Adding inventory " + slimblock.ToString(), "blockAdded");
            InventoryTotals[inventory] = new ItemCountsAggregate();
            //InventoryAggregate.ChildList.AddComponent(inventory);
            OnContentsChanged(inventory);
            inventory.ContentsChanged += OnContentsChanged;
        }
Example #11
0
 public static string GetBlockName(IMySlimBlock block)
 {
     return(block.FatBlock == null ? block.ToString() : block.FatBlock.DefinitionDisplayNameText);
 }