Esempio n. 1
0
        private void RemoveThingFromList(IBuilding_WaterNet thing)
        {
            // 全リストから削除
            this.allThings.Remove(thing);

            // 水抜きリストから削除
            this.drainers.Remove(thing);

            // 入力辞書から削除
            foreach (var item in this.inputterTypeDic)
            {
                item.Value.Remove(thing);
            }

            // 出力リストから削除
            this.outputters.Remove(thing);

            // タンクリストから削除
            this.allTanks.Remove(thing);
            foreach (var item in this.tankTypeDic)
            {
                item.Value.Remove(thing);
            }

            // 平坦化リストを再作成
            this.RefreshFlatTankList();
        }
Esempio n. 2
0
 public static bool IsConnectedAnd(
     this IBuilding_WaterNet t1,
     IBuilding_WaterNet t2,
     bool ignoreActivate = false)
 {
     return(t1.IsOutputTo(t2, ignoreActivate) && t2.IsOutputTo(t1, ignoreActivate));
 }
Esempio n. 3
0
        public void AddThing(IBuilding_WaterNet thing)
        {
            thing.InputWaterNet  = this;
            thing.OutputWaterNet = this;

            this.AddThingToList(thing);
        }
Esempio n. 4
0
        public void RemoveThing(IBuilding_WaterNet thing)
        {
            // 対象の物を除去
            thing.InputWaterNet.RemoveThing(thing);
            thing.OutputWaterNet.RemoveThing(thing);

            this.UpdateWaterNets();
        }
        protected override void TakePrintFrom(Thing t)
        {
            IBuilding_WaterNet building = t as IBuilding_WaterNet;

            if (building != null)
            {
                building.PrintForGrid(this);
            }
        }
Esempio n. 6
0
        public static bool IsOutputTo(this IBuilding_WaterNet t1, IBuilding_WaterNet t2, bool ignoreActivate = false)
        {
            if (!ignoreActivate && !t1.HasOutputConnector)
            {
                return(false);
            }

            if (!ignoreActivate && !t2.HasInputConnector)
            {
                return(false);
            }

            var t1_out_t2_body = false;

            foreach (var vec1 in t1.OutputConnectors)
            {
                foreach (var vec2 in t2.OccupiedRect())
                {
                    if (vec1 != vec2)
                    {
                        continue;
                    }

                    t1_out_t2_body = true;
                    break;
                }

                if (t1_out_t2_body)
                {
                    break;
                }
            }

            var t1_body_t2_in = false;

            foreach (var vec1 in t1.OccupiedRect())
            {
                foreach (var vec2 in t2.InputConnectors)
                {
                    if (vec1 != vec2)
                    {
                        continue;
                    }

                    t1_body_t2_in = true;
                    break;
                }

                if (t1_body_t2_in)
                {
                    break;
                }
            }

            return(t1_out_t2_body && t1_body_t2_in);
        }
Esempio n. 7
0
        private void AddThingToList(IBuilding_WaterNet thing)
        {
            // 全ての物を追加
            allThings.Add(thing);

            // 水抜き機能を持つ設備を追加
            if (thing.HasDrainCapability)
            {
                this.drainers.Add(thing);
            }

            // 入力系を仕分けして追加
            if (thing.InputComp != null)
            {
                foreach (var inputType in thing.InputComp.InputTypes)
                {
                    if (inputType == CompProperties_WaterNetInput.InputType.WaterNet)
                    {
                        // 水道網入力タイプは、この水道網からの入力を受ける場合のみ追加
                        if (thing.InputWaterNet == this)
                        {
                            this.inputterTypeDic[inputType].Add(thing);
                        }
                    }
                    else
                    {
                        // 水道網入力タイプ以外は無条件で追加
                        this.inputterTypeDic[inputType].Add(thing);
                    }
                }
            }

            // 出力系を追加
            if (thing.OutputComp != null && thing.OutputWaterNet == this)
            {
                this.outputters.Add(thing);
            }

            // タンク系を追加
            if (thing.TankComp != null)
            {
                this.allTanks.Add(thing);
                foreach (var drawType in thing.TankComp.DrawTypes)
                {
                    this.tankTypeDic[drawType].Add(thing);
                }
            }

            // 平坦化リストを再作成
            this.RefreshFlatTankList();
        }
        public void RemoveThing(IBuilding_WaterNet thing)
        {
            // 対象の物を除去
            thing.InputWaterNet?.RemoveThing(thing);

            thing.OutputWaterNet?.RemoveThing(thing);

            if (UnNetThings.Contains(thing))
            {
                UnNetThings.Remove(thing);
            }

            UpdateWaterNets();
        }
        public void RemoveThing(IBuilding_WaterNet thing)
        {
            // 対象の物を除去
            if (thing.InputWaterNet != null)
            {
                thing.InputWaterNet.RemoveThing(thing);
            }
            if (thing.OutputWaterNet != null)
            {
                thing.OutputWaterNet.RemoveThing(thing);
            }
            if (this.unNetThings.Contains(thing))
            {
                this.unNetThings.Remove(thing);
            }

            this.UpdateWaterNets();
        }
        public override bool ShouldLinkWith(IntVec3 c, Thing parent)
        {
            bool isFound             = false;
            IBuilding_WaterNet thing = parent as IBuilding_WaterNet;

            if (thing == null)
            {
                return(false);
            }
            if (parent.OccupiedRect().Contains(c))
            {
                return(GenGrid.InBounds(c, parent.Map));
            }
            if (!thing.HasConnector)
            {
                return(false);
            }

            foreach (var net in thing.WaterNetManager.Nets)
            {
                foreach (var t in net.AllThings)
                {
                    if (t == thing)
                    {
                        continue;
                    }
                    if (!t.HasConnector)
                    {
                        continue;
                    }

                    if (t.IsConnectedOr(thing) && t.OccupiedRect().Contains(c))
                    {
                        isFound = true;
                    }
                }
                if (isFound)
                {
                    break;
                }
            }

            return(GenGrid.InBounds(c, parent.Map) && isFound);
        }
Esempio n. 11
0
        public override bool ShouldLinkWith(IntVec3 c, Thing parent)
        {
            IBuilding_WaterNet thing = parent as IBuilding_WaterNet;

            bool foundWaterNetBase = false;

            foreach (var net in thing.WaterNetManager.Nets)
            {
                foreach (var t in net.AllThings)
                {
                    if (thing.IsConnectedOr(t, true))
                    {
                        if (t.OccupiedRect().Contains(c))
                        {
                            foundWaterNetBase = true;
                            break;
                        }
                    }
                }
                if (foundWaterNetBase)
                {
                    break;
                }
            }

            if (!foundWaterNetBase)
            {
                foreach (var t in thing.WaterNetManager.UnNetThings)
                {
                    if (thing.IsConnectedOr(t, true))
                    {
                        if (t.OccupiedRect().Contains(c))
                        {
                            foundWaterNetBase = true;
                            break;
                        }
                    }
                }
            }

            return(GenGrid.InBounds(c, parent.Map) && foundWaterNetBase);
        }
Esempio n. 12
0
        public static int GetRoofNumNearby(this IBuilding_WaterNet t, int dist)
        {
            int roofNum = 0;

            foreach (var cell in t.OccupiedRect().ExpandedBy(dist))
            {
                if (!cell.InBounds(t.Map))
                {
                    continue;
                }

                // 自然の屋根でなければボーナス
                var roofDef = t.Map.roofGrid.RoofAt(cell);
                if (roofDef != null && roofDef.isNatural == false)
                {
                    roofNum++;
                }
            }

            return(roofNum);
        }
Esempio n. 13
0
        public static float GetUnroofedPercent(this IBuilding_WaterNet t)
        {
            int allCells      = 0;
            int unroofedCells = 0;

            foreach (var c in t.OccupiedRect())
            {
                allCells++;
                if (!c.Roofed(t.Map))
                {
                    unroofedCells++;
                }
            }

            if (allCells == 0)
            {
                return(0f);
            }

            return((float)unroofedCells / allCells);
        }
Esempio n. 14
0
        public void UpdateWaterNets()
        {
            Queue <IBuilding_WaterNet> unNetQueue     = this.ClearWaterNets();
            Queue <IBuilding_WaterNet> unNetDiffQueue = new Queue <IBuilding_WaterNet>();

            while (unNetQueue.Count > 0)
            {
                IBuilding_WaterNet thing      = unNetQueue.Dequeue();
                List <WaterNet>    inputNets  = new List <WaterNet>();
                List <WaterNet>    outputNets = new List <WaterNet>();

                if (!thing.IsSameConnector)
                {
                    unNetDiffQueue.Enqueue(thing);
                    continue;
                }

                if (!thing.HasConnector)
                {
                    this.unNetThings.Add(thing);
                    continue;
                }
                foreach (var net in nets)
                {
                    foreach (var t in net.AllThings)
                    {
                        if (thing.IsOutputTo(t) && !outputNets.Contains(net))
                        {
                            outputNets.Add(t.InputWaterNet);
                        }
                        if (t.IsOutputTo(thing) && !inputNets.Contains(net))
                        {
                            inputNets.Add(t.OutputWaterNet);
                        }
                    }
                }

                List <WaterNet> connectNets = new List <WaterNet>();
                connectNets.AddRange(inputNets);
                foreach (var net in outputNets)
                {
                    if (!connectNets.Contains(net))
                    {
                        connectNets.Add(net);
                    }
                }

                if (connectNets.Count == 0)
                {
                    // 0個=新しい水道網
                    WaterNet newNet = new WaterNet();
                    newNet.AddThing(thing);
                    this.AddNet(newNet);
                }
                else if (connectNets.Count == 1)
                {
                    // 1個=既存の水道網に加える
                    if (!connectNets[0].AllThings.Contains(thing))
                    {
                        connectNets[0].AddThing(thing);
                    }
                }
                else
                {
                    // 2個以上=新しい物と、既存の水道網を全て最初の水道網に結合する
                    if (!connectNets[0].AllThings.Contains(thing))
                    {
                        connectNets[0].AddThing(thing);
                    }
                    for (int i = 1; i < connectNets.Count; i++)
                    {
                        // 消滅する水道網に所属している物を全て移し替える
                        foreach (var t in connectNets[i].AllThings)
                        {
                            if (!connectNets[0].AllThings.Contains(t))
                            {
                                connectNets[0].AddThing(t);
                            }
                        }

                        // 接続水道網の終えたので水道網を削除
                        nets.Remove(connectNets[i]);
                    }
                }
            }

            while (unNetDiffQueue.Count > 0)
            {
                IBuilding_WaterNet thing      = unNetDiffQueue.Dequeue();
                List <WaterNet>    inputNets  = new List <WaterNet>();
                List <WaterNet>    outputNets = new List <WaterNet>();

                if (!thing.HasConnector)
                {
                    this.unNetThings.Add(thing);
                    continue;
                }
                foreach (var net in nets)
                {
                    foreach (var t in net.AllThings)
                    {
                        if (thing.IsOutputTo(t) && !outputNets.Contains(net))
                        {
                            outputNets.Add(t.InputWaterNet);
                        }
                        if (t.IsOutputTo(thing) && !inputNets.Contains(net))
                        {
                            inputNets.Add(t.OutputWaterNet);
                        }
                    }
                }

                if (inputNets.Count == 0)
                {
                    // 0個=新しい水道網
                    WaterNet newNet = new WaterNet();
                    newNet.AddInputThing(thing);
                    this.AddNet(newNet);
                }
                else if (inputNets.Count == 1)
                {
                    // 1個=既存の水道網に加える
                    if (!inputNets[0].AllThings.Contains(thing))
                    {
                        inputNets[0].AddInputThing(thing);
                    }
                }
                else
                {
                    // 2個以上=新しい物と、既存の水道網を全て最初の水道網に結合する
                    if (!inputNets[0].AllThings.Contains(thing))
                    {
                        inputNets[0].AddInputThing(thing);
                    }
                    for (int i = 1; i < inputNets.Count; i++)
                    {
                        // 消滅する水道網に所属している物を全て移し替える
                        foreach (var t in inputNets[i].AllThings)
                        {
                            if (!inputNets[0].AllThings.Contains(t))
                            {
                                inputNets[0].AddInputThing(t);
                            }
                        }

                        // 接続水道網の終えたので水道網を削除
                        nets.Remove(inputNets[i]);
                    }
                }

                if (outputNets.Count == 0)
                {
                    // 0個=新しい水道網
                    WaterNet newNet = new WaterNet();
                    newNet.AddOutputThing(thing);
                    this.AddNet(newNet);
                }
                else if (outputNets.Count == 1)
                {
                    // 1個=既存の水道網に加える
                    if (!outputNets[0].AllThings.Contains(thing))
                    {
                        outputNets[0].AddOutputThing(thing);
                    }
                }
                else
                {
                    // 2個以上=新しい物と、既存の水道網を全て最初の水道網に結合する
                    if (!outputNets[0].AllThings.Contains(thing))
                    {
                        outputNets[0].AddOutputThing(thing);
                    }
                    for (int i = 1; i < outputNets.Count; i++)
                    {
                        // 消滅する水道網に所属している物を全て移し替える
                        foreach (var t in outputNets[i].AllThings)
                        {
                            if (!outputNets[0].AllThings.Contains(t))
                            {
                                outputNets[0].AddOutputThing(t);
                            }
                        }

                        // 接続水道網の終えたので水道網を削除
                        nets.Remove(outputNets[i]);
                    }
                }
            }
        }
Esempio n. 15
0
 public void AddThing(IBuilding_WaterNet thing)
 {
     this.unNetThings.Add(thing);
     this.UpdateWaterNets();
 }
Esempio n. 16
0
 public virtual bool IsAdjacentToCardinalOrInside(IBuilding_WaterNet other)
 {
     return(GenAdj.IsAdjacentToCardinalOrInside(this.OccupiedRect(), other.OccupiedRect()));
 }
 public void AddThing(IBuilding_WaterNet thing)
 {
     UnNetThings.Add(thing);
     UpdateWaterNets();
 }
Esempio n. 18
0
 public void RemoveThing(IBuilding_WaterNet thing)
 {
     this.RemoveThingFromList(thing);
 }
Esempio n. 19
0
 public WaterNet(IBuilding_WaterNet thing) : this()
 {
     this.AddThing(thing);
 }