Пример #1
0
 public override void CompTick()
 {
     base.CompTick();
     // ReSharper disable once InvertIf I LIKE MY NESTED IFS!
     if (ShouldVentNow)
     {
         Notify_UsedThisTick();
         if (parent.IsHashIntervalTick(30))
         {
             GenGas.AddGas(ventPos, parent.Map, Props.ventingGas, Props.gasConsumptionWhenUsed);
         }
     }
 }
Пример #2
0
        public override void PostSpawnSetup(bool respawningAfterLoad)
        {
            base.PostSpawnSetup(respawningAfterLoad);

            flickable     = parent.GetComp <CompFlickable>();
            breakdownable = parent.GetComp <CompBreakdownable>();
            schedule      = parent.GetComp <CompSchedule>();

            // set flickable to false, to avoid immediately flooding the area with
            // deadly toxins.

            if (!respawningAfterLoad && flickable != null)
            {
                flickable.SwitchIsOn = false;
            }

            // get ventPos
            ventPos = GenGas.VentingPosition(parent);
        }
Пример #3
0
        public override void DrawGhost(ThingDef def, IntVec3 pos, Rot4 rot, Color ghostCol, Thing thing = null)
        {
            var ventingPos = GenGas.VentingPosition(pos, rot);

            // draw venting cell
            GenDraw.DrawFieldEdges(new List <IntVec3> {
                ventingPos
            }, Color.white);

            // draw venting area
            var map          = Find.CurrentMap;
            var affectedArea = GenGas.GetGasVentArea(ventingPos, map,
                                                     def.GetCompProperties <CompProperties_GasVent>()?.ventingRadius ?? 0);

            if (affectedArea.NullOrEmpty())
            {
                return;
            }

            GenDraw.DrawFieldEdges(affectedArea, Resources.GasGreen);
        }
Пример #4
0
        private void DissipateAndSpread()
        {
            var roofed = Position.Roofed(Map);

            // dissipate
            Density -= (float)GasProps.staticDissipation / GasProps.maxDensity;
            if (Density <= 0)
            {
                return;
            }

            // spread
            var room = Position.GetRoom(Map);

            if (roofed)
            {
                foreach (var neighbour in GenAdjFast.AdjacentCellsCardinal(Position))
                {
                    if (!neighbour.Impassable(Map) && neighbour.GetRoom(Map) == room)
                    {
                        var amountDissipated = GenGas.AddGas(neighbour, Map, def, GasProps.staticDissipation, false);
                        Density -= amountDissipated / GasProps.maxDensity;
                    }
                }
            }
            else
            {
                // not roofed, so lets assume wind influence.
                var wind = Map.windVector() * Density;

                // TODO: wind dissipation can probably use some balancing passes
                // have a look at fluid dynamics for a simplified but proper algorithm?
                var windNorth = Mathf.Clamp((Vector2.up * wind).y, .1f, float.MaxValue) * GasProps.windDissipation;
                var windEast  = Mathf.Clamp((Vector2.right * wind).x, .1f, float.MaxValue) * GasProps.windDissipation;
                var windSouth = Mathf.Clamp((Vector2.down * wind).y, .1f, float.MaxValue) * GasProps.windDissipation;
                var windWest  = Mathf.Clamp((Vector2.left * wind).x, .1f, float.MaxValue) * GasProps.windDissipation;

                // normalize dissipation so that no gas is created out of nothing
                var sum = windNorth + windEast + windSouth + windWest;
                if (sum > Density * GasProps.maxDensity)
                {
                    var factor = Density * GasProps.maxDensity / sum;
                    windNorth *= factor;
                    windEast  *= factor;
                    windSouth *= factor;
                    windWest  *= factor;
                }

                // north
                var neighbour = Position + IntVec3.North;
                if (!neighbour.Impassable(Map) && neighbour.GetRoom(Map) == room)
                {
                    var amountDissipated = GenGas.AddGas(
                        neighbour, Map, def, windNorth, false, true);
                    Density -= amountDissipated / GasProps.maxDensity;
                }

                // east
                neighbour = Position + IntVec3.East;
                if (!neighbour.Impassable(Map) && neighbour.GetRoom(Map) == room)
                {
                    var amountDissipated = GenGas.AddGas(
                        neighbour, Map, def, windEast, false, true);
                    Density -= amountDissipated / GasProps.maxDensity;
                }

                // south
                neighbour = Position + IntVec3.South;
                if (!neighbour.Impassable(Map) && neighbour.GetRoom(Map) == room)
                {
                    var amountDissipated = GenGas.AddGas(
                        neighbour, Map, def, windSouth, false, true);
                    Density -= amountDissipated / GasProps.maxDensity;
                }

                // west
                neighbour = Position + IntVec3.West;
                if (!neighbour.Impassable(Map) && neighbour.GetRoom(Map) == room)
                {
                    var amountDissipated = GenGas.AddGas(
                        neighbour, Map, def, windWest, false, true);
                    Density -= amountDissipated / GasProps.maxDensity;
                }
            }
        }