예제 #1
0
파일: Fire.cs 프로젝트: potsh/RimWorld
        protected void TrySpread()
        {
            IntVec3 position = base.Position;
            bool    flag;

            if (Rand.Chance(0.8f))
            {
                position = base.Position + GenRadial.ManualRadialPattern[Rand.RangeInclusive(1, 8)];
                flag     = true;
            }
            else
            {
                position = base.Position + GenRadial.ManualRadialPattern[Rand.RangeInclusive(10, 20)];
                flag     = false;
            }
            if (position.InBounds(base.Map) && Rand.Chance(FireUtility.ChanceToStartFireIn(position, base.Map)))
            {
                if (!flag)
                {
                    CellRect startRect = CellRect.SingleCell(base.Position);
                    CellRect endRect   = CellRect.SingleCell(position);
                    if (GenSight.LineOfSight(base.Position, position, base.Map, startRect, endRect))
                    {
                        Spark spark = (Spark)GenSpawn.Spawn(ThingDefOf.Spark, base.Position, base.Map);
                        spark.Launch(this, position, position, ProjectileHitFlags.All);
                    }
                }
                else
                {
                    FireUtility.TryStartFireIn(position, base.Map, 0.1f);
                }
            }
        }
예제 #2
0
        public static bool TryStartFireIn(IntVec3 c, Map map, float fireSize)
        {
            float num = FireUtility.ChanceToStartFireIn(c, map);

            if (num <= 0.0)
            {
                return(false);
            }
            Fire fire = (Fire)ThingMaker.MakeThing(ThingDefOf.Fire, null);

            fire.fireSize = fireSize;
            GenSpawn.Spawn(fire, c, map, Rot4.North, false);
            return(true);
        }
예제 #3
0
        protected void TrySpread()
        {
            //This method is optimized as it is a performance bottleneck (as are the sparks it spawns)

            IntVec3 targLoc = Position;
            bool    adjacent;

            if (Rand.Chance(0.8f))
            {
                targLoc  = Position + GenRadial.ManualRadialPattern[Rand.RangeInclusive(1, 8)];         //Spark adjacent
                adjacent = true;
            }
            else
            {
                targLoc  = Position + GenRadial.ManualRadialPattern[Rand.RangeInclusive(10, 20)];               //Spark distant
                adjacent = false;
            }

            if (!targLoc.InBounds(Map))
            {
                return;
            }

            if (Rand.Chance(FireUtility.ChanceToStartFireIn(targLoc, Map)))
            {
                if (!adjacent)
                {
                    var startRect = CellRect.SingleCell(Position);
                    var endRect   = CellRect.SingleCell(targLoc);

                    // don't create a spark if we'll hit a wall in our way
                    if (!GenSight.LineOfSight(Position, targLoc, Map, startRect, endRect))
                    {
                        return;
                    }

                    var sp = (Spark)GenSpawn.Spawn(ThingDefOf.Spark, Position, Map);
                    sp.Launch(this, targLoc, targLoc, ProjectileHitFlags.All);
                }
                else
                {
                    //When adjacent, skip sparks and just magically spawn fires
                    FireUtility.TryStartFireIn(targLoc, Map, Fire.MinFireSize);
                }
            }
        }
예제 #4
0
        public static bool TryStartFireIn(IntVec3 c, Map map, float fireSize)
        {
            float num = FireUtility.ChanceToStartFireIn(c, map);
            bool  result;

            if (num <= 0f)
            {
                result = false;
            }
            else
            {
                Fire fire = (Fire)ThingMaker.MakeThing(ThingDefOf.Fire, null);
                fire.fireSize = fireSize;
                GenSpawn.Spawn(fire, c, map, Rot4.North, WipeMode.Vanish, false);
                result = true;
            }
            return(result);
        }
예제 #5
0
        protected void TrySpread()
        {
            IntVec3 intVec = base.Position;
            bool    flag;

            if (Rand.Chance(0.8f))
            {
                intVec = base.Position + GenRadial.ManualRadialPattern[Rand.RangeInclusive(1, 8)];
                flag   = true;
            }
            else
            {
                intVec = base.Position + GenRadial.ManualRadialPattern[Rand.RangeInclusive(10, 20)];
                flag   = false;
            }
            if (!intVec.InBounds(base.Map))
            {
                return;
            }
            if (Rand.Chance(FireUtility.ChanceToStartFireIn(intVec, base.Map)))
            {
                if (!flag)
                {
                    CellRect startRect = CellRect.SingleCell(base.Position);
                    CellRect endRect   = CellRect.SingleCell(intVec);
                    if (!GenSight.LineOfSight(base.Position, intVec, base.Map, startRect, endRect, null))
                    {
                        return;
                    }
                    Spark spark = (Spark)GenSpawn.Spawn(ThingDefOf.Spark, base.Position, base.Map);
                    spark.Launch(this, intVec, null);
                }
                else
                {
                    FireUtility.TryStartFireIn(intVec, base.Map, 0.1f);
                }
            }
        }
예제 #6
0
        private static bool TryStartFireNear(Building b)
        {
            ShortCircuitUtility.tmpCells.Clear();
            int      num       = GenRadial.NumCellsInRadius(3f);
            CellRect startRect = b.OccupiedRect();

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec = b.Position + GenRadial.RadialPattern[i];
                if (GenSight.LineOfSight(b.Position, intVec, b.Map, startRect, CellRect.SingleCell(intVec), null) && FireUtility.ChanceToStartFireIn(intVec, b.Map) > 0f)
                {
                    ShortCircuitUtility.tmpCells.Add(intVec);
                }
            }
            return(ShortCircuitUtility.tmpCells.Any <IntVec3>() && FireUtility.TryStartFireIn(ShortCircuitUtility.tmpCells.RandomElement <IntVec3>(), b.Map, Rand.Range(0.1f, 1.75f)));
        }
예제 #7
0
        private void DoCellSteadyEffects(IntVec3 c)
        {
            Room room  = c.GetRoom(map, RegionType.Set_All);
            bool flag  = map.roofGrid.Roofed(c);
            bool flag2 = room?.UsesOutdoorTemperature ?? false;

            if ((room == null) | flag2)
            {
                if (outdoorMeltAmount > 0f)
                {
                    map.snowGrid.AddDepth(c, 0f - outdoorMeltAmount);
                }
                if (!flag && snowRate > 0.001f)
                {
                    AddFallenSnowAt(c, 0.046f * map.weatherManager.SnowRate);
                }
            }
            if (room != null)
            {
                bool         protectedByEdifice = ProtectedByEdifice(c, map);
                TerrainDef   terrain            = c.GetTerrain(map);
                List <Thing> thingList          = c.GetThingList(map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing = thingList[i];
                    Filth filth = thing as Filth;
                    if (filth != null)
                    {
                        if (!flag && thing.def.filth.rainWashes && Rand.Chance(rainRate))
                        {
                            filth.ThinFilth();
                        }
                        if (filth.DisappearAfterTicks != 0 && filth.TicksSinceThickened > filth.DisappearAfterTicks)
                        {
                            filth.Destroy();
                        }
                    }
                    else
                    {
                        TryDoDeteriorate(thing, flag, flag2, protectedByEdifice, terrain);
                    }
                }
                if (!flag2)
                {
                    float temperature = room.Temperature;
                    if (temperature > 0f)
                    {
                        float num = MeltAmountAt(temperature);
                        if (num > 0f)
                        {
                            map.snowGrid.AddDepth(c, 0f - num);
                        }
                        if (room.RegionType.Passable() && temperature > AutoIgnitionTemperatureRange.min)
                        {
                            float value = Rand.Value;
                            if (value < AutoIgnitionTemperatureRange.InverseLerpThroughRange(temperature) * 0.7f && Rand.Chance(FireUtility.ChanceToStartFireIn(c, map)))
                            {
                                FireUtility.TryStartFireIn(c, map, 0.1f);
                            }
                            if (value < 0.33f)
                            {
                                MoteMaker.ThrowHeatGlow(c, map, 2.3f);
                            }
                        }
                    }
                }
            }
            map.gameConditionManager.DoSteadyEffects(c, map);
        }
        private void DoCellSteadyEffects(IntVec3 c)
        {
            Room room  = c.GetRoom(this.map, RegionType.Set_All);
            bool flag  = this.map.roofGrid.Roofed(c);
            bool flag2 = room != null && room.UsesOutdoorTemperature;

            if (room == null || flag2)
            {
                if (this.outdoorMeltAmount > 0f)
                {
                    this.map.snowGrid.AddDepth(c, -this.outdoorMeltAmount);
                }
                if (!flag && this.snowRate > 0.001f)
                {
                    this.AddFallenSnowAt(c, 0.046f * this.map.weatherManager.SnowRate);
                }
            }
            if (room != null)
            {
                bool         protectedByEdifice = SteadyEnvironmentEffects.ProtectedByEdifice(c, this.map);
                TerrainDef   terrain            = c.GetTerrain(this.map);
                List <Thing> thingList          = c.GetThingList(this.map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing = thingList[i];
                    Filth filth = thing as Filth;
                    if (filth != null)
                    {
                        if (!flag && thing.def.filth.rainWashes && Rand.Chance(this.rainRate))
                        {
                            filth.ThinFilth();
                        }
                    }
                    else
                    {
                        this.TryDoDeteriorate(thing, flag, flag2, protectedByEdifice, terrain);
                    }
                }
                if (!flag2)
                {
                    float temperature = room.Temperature;
                    if (temperature > 0f)
                    {
                        float num = this.MeltAmountAt(temperature);
                        if (num > 0f)
                        {
                            this.map.snowGrid.AddDepth(c, -num);
                        }
                        if (room.RegionType.Passable() && temperature > SteadyEnvironmentEffects.AutoIgnitionTemperatureRange.min)
                        {
                            float value = Rand.Value;
                            if (value < SteadyEnvironmentEffects.AutoIgnitionTemperatureRange.InverseLerpThroughRange(temperature) * 0.7f && Rand.Chance(FireUtility.ChanceToStartFireIn(c, this.map)))
                            {
                                FireUtility.TryStartFireIn(c, this.map, 0.1f);
                            }
                            if (value < 0.33f)
                            {
                                MoteMaker.ThrowHeatGlow(c, this.map, 2.3f);
                            }
                        }
                    }
                }
            }
            this.map.gameConditionManager.DoSteadyEffects(c, this.map);
        }
        private void DoCellSteadyEffects(IntVec3 c)
        {
            Room room  = c.GetRoom(this.map, RegionType.Set_All);
            bool flag  = this.map.roofGrid.Roofed(c);
            bool flag2 = room != null && room.UsesOutdoorTemperature;

            if (room == null || flag2)
            {
                if (this.outdoorMeltAmount > 0.0)
                {
                    this.map.snowGrid.AddDepth(c, (float)(0.0 - this.outdoorMeltAmount));
                }
                if (!flag && this.snowRate > 0.0010000000474974513)
                {
                    this.AddFallenSnowAt(c, (float)(0.046000000089406967 * this.map.weatherManager.SnowRate));
                }
            }
            if (room != null)
            {
                if (flag2)
                {
                    if (!flag)
                    {
                        List <Thing> thingList = c.GetThingList(this.map);
                        for (int i = 0; i < thingList.Count; i++)
                        {
                            Thing thing = thingList[i];
                            Filth filth = thing as Filth;
                            if (filth != null)
                            {
                                if (thing.def.filth.rainWashes && Rand.Value < this.rainRate)
                                {
                                    ((Filth)thing).ThinFilth();
                                }
                            }
                            else
                            {
                                Corpse corpse = thing as Corpse;
                                if (corpse != null && corpse.InnerPawn.apparel != null)
                                {
                                    List <Apparel> wornApparel = corpse.InnerPawn.apparel.WornApparel;
                                    for (int j = 0; j < wornApparel.Count; j++)
                                    {
                                        this.TryDoDeteriorate(wornApparel[j], c, false);
                                    }
                                }
                                this.TryDoDeteriorate(thing, c, true);
                            }
                        }
                    }
                }
                else
                {
                    float temperature = room.Temperature;
                    if (temperature > 0.0)
                    {
                        float num = this.MeltAmountAt(temperature);
                        if (num > 0.0)
                        {
                            this.map.snowGrid.AddDepth(c, (float)(0.0 - num));
                        }
                        if (room.RegionType.Passable())
                        {
                            float      num2 = temperature;
                            FloatRange autoIgnitionTemperatureRange = SteadyAtmosphereEffects.AutoIgnitionTemperatureRange;
                            if (num2 > autoIgnitionTemperatureRange.min)
                            {
                                float value = Rand.Value;
                                if (value < SteadyAtmosphereEffects.AutoIgnitionTemperatureRange.InverseLerpThroughRange(temperature) * 0.699999988079071 && Rand.Chance(FireUtility.ChanceToStartFireIn(c, this.map)))
                                {
                                    FireUtility.TryStartFireIn(c, this.map, 0.1f);
                                }
                                if (value < 0.33000001311302185)
                                {
                                    MoteMaker.ThrowHeatGlow(c, this.map, 2.3f);
                                }
                            }
                        }
                    }
                }
            }
            List <GameCondition> activeConditions = this.map.gameConditionManager.ActiveConditions;

            for (int k = 0; k < activeConditions.Count; k++)
            {
                activeConditions[k].DoCellSteadyEffects(c);
            }
        }