示例#1
0
        protected virtual void LookForAttachedModules()
        {
            VicisMod.log(getPrefix(), "Looking neigbors");

            List <MassCrateModule> list = VicisMod.checkSurrounding <MassCrateModule>(this, out encounteredNullSegment);

            foreach (MassCrateModule m in list)
            {
                if (manager == null)
                {
                    m.manager.Add(this);
                }
                else if (manager != m.manager)
                {
                    manager.Merge(m.manager);
                }
                m.AddNeighbor(this);
                AddNeighbor(m);
            }

            VicisMod.log(getPrefix(), "I now have " + neighbors.Count + " neighbors");

            // FIRST!
            if (manager == null)
            {
                VicisMod.log(getPrefix(), "Creating a new manager for myself");
                MassCrateModuleManager newManager = new MassCrateModuleManager();
                newManager.Add(this);
            }
        }
示例#2
0
        public void Merge(MassCrateModuleManager mcmm)
        {
            // First, assign this MCMM as the manager for all modules controlled by the old manager
            foreach (MassCrateModule mcm in mcmm.modules)
            {
                Add(mcm);
            }

            mcmm.modules.Clear();
        }
示例#3
0
        public void Merge(MassCrateModuleManager mcmm)
        {
            // First, assign this MCMM as the manager for all modules controlled by the old manager
            for (int i = 0; i < mcmm.modules.Count; ++i)
            {
                Add(mcmm.modules[i]);
            }

            mcmm.modules.Clear();
        }
示例#4
0
        public void Remove(MassCrateModule mcm)
        {
            modules.Remove(mcm);

            if (modules.Count == 0)
            {
                VicisMod.log(LOGGER_PREFIX, "I'm All Alone. Goodbye.");
                return;
            }

            // Nothing elso to do
            if (mcm.neighbors.Count == 0)
            {
                return;
            }

            // Need to figure out if we need to split into two groups...
            VicisMod.log(LOGGER_PREFIX, "Getting ready for floodfill");
            List <List <MassCrateModule> > groups    = new List <List <MassCrateModule> >();
            List <MassCrateModule>         neighbors = mcm.neighbors;

            foreach (MassCrateModule neighbor in neighbors)
            {
                bool cont = false;
                foreach (List <MassCrateModule> group in groups)
                {
                    if (group.Contains(neighbor))
                    {
                        cont = true;
                        break;
                    }
                }
                if (cont)
                {
                    continue;
                }
                List <MassCrateModule> floodFillResults = floodFillFun(neighbor);
                groups.Add(floodFillResults);
            }

            // We found only one group, don't need to spin off any more managers!
            if (groups.Count == 1 && groups[0].Count == modules.Count)
            {
                return;
            }
            if (groups.Count == 1)
            {
                VicisMod.log(LOGGER_PREFIX, "Found one group, but it has " + groups[0].Count + " crates and I know of " + modules.Count + " crates. What?");
                return;
            }

            VicisMod.log(LOGGER_PREFIX, "I'm now the lord of " + groups[0].Count + " modules (hopefully after I create the other managers");

            // Ok, now we need to create new managers for the extra groups.
            // First, remove the results from current modules
            for (int i = 1; i < groups.Count; ++i)
            {
                VicisMod.log(LOGGER_PREFIX, "Removing " + groups[i].Count + " from old from modules");
                foreach (MassCrateModule m in groups[i])
                {
                    modules.Remove(m);
                }
                MassCrateModuleManager newManager = new MassCrateModuleManager();
                newManager.AddAll(groups[i]);
            }

            VicisMod.log(LOGGER_PREFIX, "I'm now the lord of " + modules.Count + " modules, really!");

            if (modules.Count == 0)
            {
                VicisMod.log(LOGGER_PREFIX, "Somehow, I have no more modules...");
            }
        }