コード例 #1
0
 private void QuantumStockpileTick(int tickAmount)
 {
     if ((Find.TickManager.TicksGame + tickStagger) % tickAmount == 0)
     {
         if ((compPowerTrader == null || compPowerTrader.PowerOn) &&
             parent.OccupiedRect().CenterCell.Priority(parent.Map) != StoragePriority.Unstored)
         {
             if (compWarehouse == null)
             {
                 compWarehouse = parent.FindWarehouse();
                 if (compWarehouse != null)
                 {
                     compWarehouse.RegisterStockpile(this);
                 }
             }
             else
             {
                 if (compWarehouse.parent == null || compWarehouse.parent.Destroyed || !compWarehouse.IsValid())
                 {
                     compWarehouse.DeRegisterStockpile(this);
                     compWarehouse = null;
                 }
             }
             if (cellIndex >= cells.Count)
             {
                 cellIndex = 0;
                 if (compWarehouse == null)
                 {
                     DefragStacks();
                 }
                 else
                 {
                     ProcessCell(cells[cellIndex]);
                     cellIndex++;
                 }
             }
             else
             {
                 ProcessCell(cells[cellIndex]);
                 cellIndex++;
             }
         }
         else
         {
             if (compWarehouse != null)
             {
                 compWarehouse.DeRegisterStockpile(this);
                 compWarehouse = null;
             }
         }
     }
 }
コード例 #2
0
 public static CompRTQuantumWarehouse FindWarehouse(this Zone_Stockpile zoneStockpile)
 {
     if (zoneStockpile != null)
     {
         CompRTQuantumWarehouse compWarehouse = null;
         foreach (Thing thingWithComps in zoneStockpile.AllContainedThings.ToList <Thing>())
         {
             compWarehouse = thingWithComps.TryGetComp <CompRTQuantumWarehouse>();
             if (compWarehouse != null)
             {
                 return(compWarehouse);
             }
         }
     }
     return(null);
 }
コード例 #3
0
        public override void PostSpawnSetup()
        {
            compPowerTrader = parent.TryGetComp <CompPowerTrader>();

            lastTickStagger++;
            tickStagger = lastTickStagger;

            cellIndex = tickStagger;
            cells     = GenAdj.CellsAdjacent8Way(parent).ToList();
            while (cellIndex > cells.Count)
            {
                cellIndex -= cells.Count;
            }

            if (quantumWarehouse != null)
            {
                compWarehouse = quantumWarehouse.TryGetComp <CompRTQuantumWarehouse>();
            }
        }
コード例 #4
0
 private void QuantumStockpileTick(int tickAmount)
 {
     if ((Find.TickManager.TicksGame + tickStagger) % tickAmount == 0)
     {
         if ((compPowerTrader == null || compPowerTrader.PowerOn)
             && parent.OccupiedRect().CenterCell.Priority(parent.Map) != StoragePriority.Unstored)
         {
             if (compWarehouse == null)
             {
                 compWarehouse = parent.FindWarehouse();
                 if (compWarehouse != null) compWarehouse.RegisterStockpile(this);
             }
             else
             {
                 if (compWarehouse.parent == null || compWarehouse.parent.Destroyed || !compWarehouse.IsValid())
                 {
                     compWarehouse.DeRegisterStockpile(this);
                     compWarehouse = null;
                 }
             }
             if (cellIndex >= cells.Count)
             {
                 cellIndex = 0;
                 if (compWarehouse == null)
                 {
                     DefragStacks();
                 }
                 else
                 {
                     ProcessCell(cells[cellIndex]);
                     cellIndex++;
                 }
             }
             else
             {
                 ProcessCell(cells[cellIndex]);
                 cellIndex++;
             }
         }
         else
         {
             if (compWarehouse != null)
             {
                 compWarehouse.DeRegisterStockpile(this);
                 compWarehouse = null;
             }
         }
     }
 }
コード例 #5
0
        public override IEnumerable<Gizmo> CompGetGizmosExtra()
        {
            Command_Toggle commandSparkles = new Command_Toggle();
            commandSparkles.isActive = () => sparklesEnabled;
            commandSparkles.toggleAction = () => sparklesEnabled = !sparklesEnabled;
            commandSparkles.groupKey = 95918723;
            commandSparkles.icon = Resources.sparklesButtonTexture;
            commandSparkles.defaultLabel = "CompRTQuantumRelay_SparklesToggle".Translate();
            if (sparklesEnabled)
            {
                commandSparkles.defaultDesc = "CompRTQuantumRelay_SparklesAreOn".Translate();
            }
            else
            {
                commandSparkles.defaultDesc = "CompRTQuantumRelay_SparklesAreOff".Translate();
            }
            yield return commandSparkles;

            Command_Action commandWarehousePrev = new Command_Action();
            commandWarehousePrev.icon = Resources.leftArrowTexture;
            commandWarehousePrev.groupKey = 56182375;
            commandWarehousePrev.defaultLabel = "CompRTQuantumRelay_WarehousePrevLabel".Translate();
            commandWarehousePrev.defaultDesc = "CompRTQuantumRelay_WarehousePrevDesc".Translate();
            commandWarehousePrev.action = delegate
            {
                registered = false;
                if (compWarehouse != null) compWarehouse.DeRegisterRelay(this);
                List<Zone> zones = parent.Map.zoneManager.AllZones;
                if (zones != null && zones.Count != 0)
                {
                    List<Zone_Stockpile> stockpileZones =
                        (from zone in zones
                         where zone.GetType() == typeof(Zone_Stockpile)
                         select zone as Zone_Stockpile).ToList();
                    if (stockpileZones != null && stockpileZones.Count != 0)
                    {
                        List<CompRTQuantumWarehouse> warehouses =
                            (from zone in stockpileZones
                             where zone.FindWarehouse() != null
                             select zone.FindWarehouse()).ToList();
                        if (warehouses != null && warehouses.Count != 0)
                        {
                            if (compWarehouse != null)
                            {
                                CompRTQuantumWarehouse warehouse = warehouses.Find((CompRTQuantumWarehouse t) => t == compWarehouse);
                                if (warehouse != null)
                                {
                                    int warehouseIndex = warehouses.FindIndex((CompRTQuantumWarehouse t) => t == compWarehouse);
                                    if (warehouseIndex == 0)
                                    {
                                        compWarehouse = warehouses[warehouses.Count - 1];
                                    }
                                    else
                                    {
                                        compWarehouse = warehouses[warehouseIndex - 1];
                                    }
                                }
                                else
                                {
                                    compWarehouse = warehouses.First();
                                }
                            }
                            else
                            {
                                compWarehouse = warehouses.First();
                            }
                        }
                    }
                }
            };
            yield return commandWarehousePrev;

            Command_Action commandWarehouseNext = new Command_Action();
            commandWarehouseNext.icon = Resources.rightArrowTexture;
            commandWarehouseNext.groupKey = 91915621;
            commandWarehouseNext.defaultLabel = "CompRTQuantumRelay_WarehouseNextLabel".Translate();
            commandWarehouseNext.defaultDesc = "CompRTQuantumRelay_WarehouseNextDesc".Translate();
            commandWarehouseNext.action = delegate
            {
                registered = false;
                if (compWarehouse != null) compWarehouse.DeRegisterRelay(this);
                List<Zone> zones = parent.Map.zoneManager.AllZones;
                if (zones != null && zones.Count != 0)
                {
                    List<Zone_Stockpile> stockpileZones =
                        (from zone in zones
                         where zone.GetType() == typeof(Zone_Stockpile)
                         select zone as Zone_Stockpile).ToList();
                    if (stockpileZones != null && stockpileZones.Count != 0)
                    {
                        List<CompRTQuantumWarehouse> warehouses =
                            (from zone in stockpileZones
                             where zone.FindWarehouse() != null
                             select zone.FindWarehouse()).ToList();
                        if (warehouses != null && warehouses.Count != 0)
                        {
                            if (compWarehouse != null)
                            {
                                CompRTQuantumWarehouse warehouse = warehouses.Find((CompRTQuantumWarehouse t) => t == compWarehouse);
                                if (warehouse != null)
                                {
                                    int warehouseIndex = warehouses.FindIndex((CompRTQuantumWarehouse t) => t == compWarehouse);
                                    if (warehouseIndex == warehouses.Count - 1)
                                    {
                                        compWarehouse = warehouses.First();
                                    }
                                    else
                                    {
                                        compWarehouse = warehouses[warehouseIndex + 1];
                                    }
                                }
                                else
                                {
                                    compWarehouse = warehouses.First();
                                }
                            }
                            else
                            {
                                compWarehouse = warehouses.First();
                            }
                        }
                    }
                }
            };
            yield return commandWarehouseNext;
        }
コード例 #6
0
        public override void PostSpawnSetup()
        {
            compPowerTrader = parent.TryGetComp<CompPowerTrader>();

            lastTickStagger++;
            tickStagger = lastTickStagger;

            cellIndex = tickStagger;
            cells = GenAdj.CellsAdjacent8Way(parent).ToList();
            while (cellIndex > cells.Count)
            {
                cellIndex -= cells.Count;
            }

            if (quantumWarehouse != null)
            {
                compWarehouse = quantumWarehouse.TryGetComp<CompRTQuantumWarehouse>();
            }
        }
コード例 #7
0
        private void QuantumWarehouseTick(int tickAmount)
        {
            if ((Find.TickManager.TicksGame + tickStagger) % tickAmount == 0)
            {
                if (compPowerTrader == null || compPowerTrader.PowerOn)
                {
                    if (parent.OccupiedRect().CenterCell.Priority() == StoragePriority.Unstored)
                    {
                        valid = false;
                    }
                    if (valid)
                    {
                        if (compStockpiles.Count > 1)
                        {
                            qsSourceIndex++;
                            if (qsSourceIndex >= compStockpiles.Count)
                            {
                                qsTargetIndex++;
                                qsSourceIndex = qsTargetIndex + 1;
                            }
                            if (qsTargetIndex >= compStockpiles.Count - 1)
                            {
                                compStockpiles.Shuffle();
                                qsTargetIndex = 0;
                                qsSourceIndex = 1;
                            }
                            DefragStockpileStacks();
                            DefragStockpileCells();
                        }
                        else if (compStockpiles.Count == 1)
                        {
                            CompRTQuantumStockpile compStockpile = compStockpiles.First();
                            if (sparklesEnabled)
                            {
                                foreach (IntVec3 stockpileCell in compStockpile.parent.OccupiedRect().Cells)
                                {
                                    stockpileCell.ThrowSparkle();
                                }
                            }
                            compStockpile.DefragStacks();
                        }

                        if (compChunkSilos.Count > 1)
                        {
                            qcsSourceIndex++;
                            if (qcsSourceIndex >= compChunkSilos.Count)
                            {
                                qcsTargetIndex++;
                                qcsSourceIndex = qcsTargetIndex + 1;
                            }
                            if (qcsTargetIndex >= compChunkSilos.Count - 1)
                            {
                                compChunkSilos.Shuffle();
                                qcsTargetIndex = 0;
                                qcsSourceIndex = 1;
                            }
                            DefragChunkSilos();
                        }
                        else if (compChunkSilos.Count == 1)
                        {
                            CompRTQuantumChunkSilo compChunkSilo = compChunkSilos.First();
                            foreach (IntVec3 chunkSiloCell in compChunkSilo.parent.OccupiedRect().Cells)
                            {
                                if (sparklesEnabled)
                                {
                                    chunkSiloCell.ThrowSparkle();
                                }
                                List <Thing> cellThings = chunkSiloCell.GetItemList();
                                if (cellThings.Count != 0)
                                {
                                    QueueThing(cellThings.RandomElement());
                                }
                            }
                        }

                        if (compRelays.Count != 0)
                        {
                            if (qrIndex >= compRelays.Count)
                            {
                                qrIndex = 0;
                            }
                            SendItemsToRelay();
                            qrIndex++;
                        }

                        if (buffer.Count != 0)
                        {
                            Thing thing = buffer.RandomElement();
                            ReceiveThing(thing);
                            buffer.Remove(thing);
                            if (buffer.Count != 0)
                            {
                                if (bufferTicker == bufferLifespan)
                                {
                                    bufferTicker = 0;
                                    buffer.Clear();
                                }
                                bufferTicker++;
                            }
                        }
                    }
                    else
                    {
                        CompRTQuantumWarehouse compWarehouse = parent.FindWarehouse();
                        valid = (compWarehouse != null && compWarehouse == this &&
                                 parent.OccupiedRect().CenterCell.Priority() != StoragePriority.Unstored);
                    }
                }
                else
                {
                    valid = false;
                }
            }
        }
コード例 #8
0
        public override IEnumerable <Gizmo> CompGetGizmosExtra()
        {
            Command_Toggle commandSparkles = new Command_Toggle();

            commandSparkles.isActive     = () => sparklesEnabled;
            commandSparkles.toggleAction = () => sparklesEnabled = !sparklesEnabled;
            commandSparkles.groupKey     = 95918723;
            commandSparkles.icon         = Resources.sparklesButtonTexture;
            commandSparkles.defaultLabel = "CompRTQuantumRelay_SparklesToggle".Translate();
            if (sparklesEnabled)
            {
                commandSparkles.defaultDesc = "CompRTQuantumRelay_SparklesAreOn".Translate();
            }
            else
            {
                commandSparkles.defaultDesc = "CompRTQuantumRelay_SparklesAreOff".Translate();
            }
            yield return(commandSparkles);

            Command_Action commandWarehousePrev = new Command_Action();

            commandWarehousePrev.icon         = Resources.leftArrowTexture;
            commandWarehousePrev.groupKey     = 56182375;
            commandWarehousePrev.defaultLabel = "CompRTQuantumRelay_WarehousePrevLabel".Translate();
            commandWarehousePrev.defaultDesc  = "CompRTQuantumRelay_WarehousePrevDesc".Translate();
            commandWarehousePrev.action       = delegate
            {
                registered = false;
                if (compWarehouse != null)
                {
                    compWarehouse.DeRegisterRelay(this);
                }
                List <Zone> zones = parent.Map.zoneManager.AllZones;
                if (zones != null && zones.Count != 0)
                {
                    List <Zone_Stockpile> stockpileZones =
                        (from zone in zones
                         where zone.GetType() == typeof(Zone_Stockpile)
                         select zone as Zone_Stockpile).ToList();
                    if (stockpileZones != null && stockpileZones.Count != 0)
                    {
                        List <CompRTQuantumWarehouse> warehouses =
                            (from zone in stockpileZones
                             where zone.FindWarehouse() != null
                             select zone.FindWarehouse()).ToList();
                        if (warehouses != null && warehouses.Count != 0)
                        {
                            if (compWarehouse != null)
                            {
                                CompRTQuantumWarehouse warehouse = warehouses.Find((CompRTQuantumWarehouse t) => t == compWarehouse);
                                if (warehouse != null)
                                {
                                    int warehouseIndex = warehouses.FindIndex((CompRTQuantumWarehouse t) => t == compWarehouse);
                                    if (warehouseIndex == 0)
                                    {
                                        compWarehouse = warehouses[warehouses.Count - 1];
                                    }
                                    else
                                    {
                                        compWarehouse = warehouses[warehouseIndex - 1];
                                    }
                                }
                                else
                                {
                                    compWarehouse = warehouses.First();
                                }
                            }
                            else
                            {
                                compWarehouse = warehouses.First();
                            }
                        }
                    }
                }
            };
            yield return(commandWarehousePrev);

            Command_Action commandWarehouseNext = new Command_Action();

            commandWarehouseNext.icon         = Resources.rightArrowTexture;
            commandWarehouseNext.groupKey     = 91915621;
            commandWarehouseNext.defaultLabel = "CompRTQuantumRelay_WarehouseNextLabel".Translate();
            commandWarehouseNext.defaultDesc  = "CompRTQuantumRelay_WarehouseNextDesc".Translate();
            commandWarehouseNext.action       = delegate
            {
                registered = false;
                if (compWarehouse != null)
                {
                    compWarehouse.DeRegisterRelay(this);
                }
                List <Zone> zones = parent.Map.zoneManager.AllZones;
                if (zones != null && zones.Count != 0)
                {
                    List <Zone_Stockpile> stockpileZones =
                        (from zone in zones
                         where zone.GetType() == typeof(Zone_Stockpile)
                         select zone as Zone_Stockpile).ToList();
                    if (stockpileZones != null && stockpileZones.Count != 0)
                    {
                        List <CompRTQuantumWarehouse> warehouses =
                            (from zone in stockpileZones
                             where zone.FindWarehouse() != null
                             select zone.FindWarehouse()).ToList();
                        if (warehouses != null && warehouses.Count != 0)
                        {
                            if (compWarehouse != null)
                            {
                                CompRTQuantumWarehouse warehouse = warehouses.Find((CompRTQuantumWarehouse t) => t == compWarehouse);
                                if (warehouse != null)
                                {
                                    int warehouseIndex = warehouses.FindIndex((CompRTQuantumWarehouse t) => t == compWarehouse);
                                    if (warehouseIndex == warehouses.Count - 1)
                                    {
                                        compWarehouse = warehouses.First();
                                    }
                                    else
                                    {
                                        compWarehouse = warehouses[warehouseIndex + 1];
                                    }
                                }
                                else
                                {
                                    compWarehouse = warehouses.First();
                                }
                            }
                            else
                            {
                                compWarehouse = warehouses.First();
                            }
                        }
                    }
                }
            };
            yield return(commandWarehouseNext);
        }