private static bool MakeFilth(IntVec3 c, Map map, ThingDef filthDef, IEnumerable <string> sources, bool shouldPropagate)
        {
            Filth filth = (Filth)(from t in c.GetThingList(map)
                                  where t.def == filthDef
                                  select t).FirstOrDefault();

            if (c.Walkable(map) && (filth == null || filth.CanBeThickened))
            {
                if (filth != null)
                {
                    filth.ThickenFilth();
                    filth.AddSources(sources);
                }
                else
                {
                    Filth filth2 = (Filth)ThingMaker.MakeThing(filthDef, null);
                    filth2.AddSources(sources);
                    GenSpawn.Spawn(filth2, c, map);
                }
                return(true);
            }
            if (shouldPropagate)
            {
                List <IntVec3> list = GenAdj.AdjacentCells8WayRandomized();
                for (int i = 0; i < 8; i++)
                {
                    IntVec3 c2 = c + list[i];
                    if (c2.InBounds(map) && FilthMaker.MakeFilth(c2, map, filthDef, sources, false))
                    {
                        return(true);
                    }
                }
            }
            if (filth != null)
            {
                filth.AddSources(sources);
            }
            return(false);
        }
示例#2
0
        public void Hatch()
        {
            PawnGenerationRequest request = new PawnGenerationRequest(this.Props.hatcherPawn, this.hatcheeFaction, PawnGenerationContext.NonPlayer, -1, false, true, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null);

            for (int i = 0; i < this.parent.stackCount; i++)
            {
                Pawn pawn = PawnGenerator.GeneratePawn(request);
                if (PawnUtility.TrySpawnHatchedOrBornPawn(pawn, this.parent))
                {
                    if (pawn != null)
                    {
                        if (this.hatcheeParent != null)
                        {
                            if (pawn.playerSettings != null && this.hatcheeParent.playerSettings != null && this.hatcheeParent.Faction == this.hatcheeFaction)
                            {
                                pawn.playerSettings.AreaRestriction = this.hatcheeParent.playerSettings.AreaRestriction;
                            }
                            if (pawn.RaceProps.IsFlesh)
                            {
                                pawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, this.hatcheeParent);
                            }
                        }
                        if (this.otherParent != null && (this.hatcheeParent == null || this.hatcheeParent.gender != this.otherParent.gender) && pawn.RaceProps.IsFlesh)
                        {
                            pawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, this.otherParent);
                        }
                    }
                    if (this.parent.Spawned)
                    {
                        FilthMaker.MakeFilth(this.parent.Position, this.parent.Map, ThingDefOf.FilthAmnioticFluid, 1);
                    }
                }
                else
                {
                    Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                }
            }
            this.parent.Destroy(DestroyMode.Vanish);
        }
 public static void DropFilthDueToDamage(Thing t, float damageDealt)
 {
     if (t.def.useHitPoints && t.Spawned && t.def.filthLeaving != null)
     {
         CellRect cellRect = t.OccupiedRect().ExpandedBy(1);
         GenLeaving.tmpCellsCandidates.Clear();
         foreach (IntVec3 item in cellRect)
         {
             if (item.InBounds(t.Map) && item.Walkable(t.Map))
             {
                 GenLeaving.tmpCellsCandidates.Add(item);
             }
         }
         if (GenLeaving.tmpCellsCandidates.Any())
         {
             int num = GenMath.RoundRandom(damageDealt * Mathf.Min(0.0166666675f, (float)(1.0 / ((float)t.MaxHitPoints / 10.0))));
             for (int i = 0; i < num; i++)
             {
                 FilthMaker.MakeFilth(GenLeaving.tmpCellsCandidates.RandomElement(), t.Map, t.def.filthLeaving, 1);
             }
         }
     }
 }
示例#4
0
 public void Notify_EnteredNewCell()
 {
     if (Rand.Value < 0.05f)
     {
         TryDropFilth();
     }
     if (Rand.Value < 0.1f)
     {
         TryPickupFilth();
     }
     if (!pawn.RaceProps.Humanlike)
     {
         if (Rand.Value < PawnUtility.AnimalFilthChancePerCell(pawn.def, pawn.BodySize) && pawn.Position.GetTerrain(pawn.Map).acceptTerrainSourceFilth)
         {
             FilthMaker.MakeFilth(pawn.Position, pawn.Map, ThingDefOf.Filth_AnimalFilth);
             FilthMonitor.Notify_FilthAnimalGenerated();
         }
     }
     else if (Rand.Value < PawnUtility.HumanFilthChancePerCell(pawn.def, pawn.BodySize) && pawn.Position.GetTerrain(pawn.Map).acceptTerrainSourceFilth)
     {
         FilthMaker.MakeFilth(filthDef: (lastTerrainFilthDef == null || !Rand.Chance(0.66f)) ? ThingDefOf.Filth_Trash : lastTerrainFilthDef, c: pawn.Position, map: pawn.Map);
         FilthMonitor.Notify_FilthHumanGenerated();
     }
 }
        public static void DoLeavingsFor(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect, Predicate <IntVec3> nearPlaceValidator = null)
        {
            if ((Current.ProgramState != ProgramState.Playing && mode != DestroyMode.Refund) || mode == DestroyMode.Vanish)
            {
                return;
            }
            if (mode == DestroyMode.KillFinalize && diedThing.def.filthLeaving != null)
            {
                for (int i = leavingsRect.minZ; i <= leavingsRect.maxZ; i++)
                {
                    for (int j = leavingsRect.minX; j <= leavingsRect.maxX; j++)
                    {
                        IntVec3 c = new IntVec3(j, 0, i);
                        FilthMaker.MakeFilth(c, map, diedThing.def.filthLeaving, Rand.RangeInclusive(1, 3));
                    }
                }
            }
            ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();

            if (mode == DestroyMode.KillFinalize && diedThing.def.killedLeavings != null)
            {
                for (int k = 0; k < diedThing.def.killedLeavings.Count; k++)
                {
                    Thing thing = ThingMaker.MakeThing(diedThing.def.killedLeavings[k].thingDef, null);
                    thing.stackCount = diedThing.def.killedLeavings[k].count;
                    thingOwner.TryAdd(thing, true);
                }
            }
            if (GenLeaving.CanBuildingLeaveResources(diedThing, mode))
            {
                Frame frame = diedThing as Frame;
                if (frame != null)
                {
                    for (int l = frame.resourceContainer.Count - 1; l >= 0; l--)
                    {
                        int num = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(frame.resourceContainer[l].stackCount);
                        if (num > 0)
                        {
                            frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[l], thingOwner, num, true);
                        }
                    }
                    frame.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish);
                }
                else
                {
                    List <ThingDefCountClass> list = diedThing.CostListAdjusted();
                    for (int m = 0; m < list.Count; m++)
                    {
                        ThingDefCountClass thingDefCountClass = list[m];
                        int num2 = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(thingDefCountClass.count);
                        if (num2 > 0 && mode == DestroyMode.KillFinalize && thingDefCountClass.thingDef.slagDef != null)
                        {
                            int count = thingDefCountClass.thingDef.slagDef.smeltProducts.First((ThingDefCountClass pro) => pro.thingDef == ThingDefOf.Steel).count;
                            int num3  = num2 / 2 / 8;
                            for (int n = 0; n < num3; n++)
                            {
                                thingOwner.TryAdd(ThingMaker.MakeThing(thingDefCountClass.thingDef.slagDef, null), true);
                            }
                            num2 -= num3 * count;
                        }
                        if (num2 > 0)
                        {
                            Thing thing2 = ThingMaker.MakeThing(thingDefCountClass.thingDef, null);
                            thing2.stackCount = num2;
                            thingOwner.TryAdd(thing2, true);
                        }
                    }
                }
            }
            List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder(null).ToList <IntVec3>();
            int            num4  = 0;

            while (thingOwner.Count > 0)
            {
                if (mode == DestroyMode.KillFinalize && !map.areaManager.Home[list2[num4]])
                {
                    thingOwner[0].SetForbidden(true, false);
                }
                ThingOwner <Thing> thingOwner2 = thingOwner;
                Thing          thing3          = thingOwner[0];
                IntVec3        dropLoc         = list2[num4];
                ThingPlaceMode mode2           = ThingPlaceMode.Near;
                Thing          thing4;
                ref Thing      lastResultingThing = ref thing4;
                if (!thingOwner2.TryDrop(thing3, dropLoc, map, mode2, out lastResultingThing, null, nearPlaceValidator))
                {
                    Log.Warning(string.Concat(new object[]
                    {
                        "Failed to place all leavings for destroyed thing ",
                        diedThing,
                        " at ",
                        leavingsRect.CenterCell
                    }), false);
                    return;
                }
                num4++;
                if (num4 >= list2.Count)
                {
                    num4 = 0;
                }
            }
示例#6
0
 public static void MakeFilth(IntVec3 c, Map map, ThingDef filthDef, IEnumerable <string> sources)
 {
     FilthMaker.MakeFilth(c, map, filthDef, sources, true);
 }
示例#7
0
 public override void Tick()
 {
     if (base.Spawned)
     {
         sustainer.Maintain();
         Vector3 vector = base.Position.ToVector3Shifted();
         if (Rand.MTBEventOccurs(FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(base.Position, base.Map, FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors), null, null, out IntVec3 result))
         {
             FilthMaker.MakeFilth(result, base.Map, filthTypes.RandomElement());
         }
         if (Rand.MTBEventOccurs(DustMoteSpawnMTB, 1f, 1.TicksToSeconds()))
         {
             Vector3 loc = new Vector3(vector.x, 0f, vector.z);
             loc.y = AltitudeLayer.MoteOverhead.AltitudeFor();
             MoteMaker.ThrowDustPuffThick(loc, base.Map, Rand.Range(1.5f, 3f), new Color(1f, 1f, 1f, 2.5f));
         }
         if (secondarySpawnTick <= Find.TickManager.TicksGame)
         {
             sustainer.End();
             Map     map      = base.Map;
             IntVec3 position = base.Position;
             Destroy();
             if (spawnHive)
             {
                 Hive hive = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive), position, map);
                 hive.SetFaction(Faction.OfInsects);
                 foreach (CompSpawner comp in hive.GetComps <CompSpawner>())
                 {
                     if (comp.PropsSpawner.thingToSpawn == ThingDefOf.InsectJelly)
                     {
                         comp.TryDoSpawn();
                         break;
                     }
                 }
             }
             if (insectsPoints > 0f)
             {
                 insectsPoints = Mathf.Max(insectsPoints, Hive.spawnablePawnKinds.Min((PawnKindDef x) => x.combatPower));
                 float       pointsLeft = insectsPoints;
                 List <Pawn> list       = new List <Pawn>();
                 int         num        = 0;
                 while (pointsLeft > 0f)
                 {
                     num++;
                     if (num > 1000)
                     {
                         Log.Error("Too many iterations.");
                         break;
                     }
                     IEnumerable <PawnKindDef> source = from x in Hive.spawnablePawnKinds
                                                        where x.combatPower <= pointsLeft
                                                        select x;
                     if (!source.TryRandomElement(out PawnKindDef result2))
                     {
                         break;
                     }
                     Pawn pawn = PawnGenerator.GeneratePawn(result2, Faction.OfInsects);
                     GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2), map);
                     pawn.mindState.spawnedByInfestationThingComp = spawnedByInfestationThingComp;
                     list.Add(pawn);
                     pointsLeft -= result2.combatPower;
                 }
                 if (list.Any())
                 {
                     LordMaker.MakeNewLord(Faction.OfInsects, new LordJob_AssaultColony(Faction.OfInsects, canKidnap: true, canTimeoutOrFlee: false), map, list);
                 }
             }
         }
     }
 }
        public static void DoLeavingsFor(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect, Predicate <IntVec3> nearPlaceValidator = null, List <Thing> listOfLeavingsOut = null)
        {
            if (Current.ProgramState != ProgramState.Playing && mode != DestroyMode.Refund)
            {
                return;
            }
            switch (mode)
            {
            case DestroyMode.Vanish:
            case DestroyMode.QuestLogic:
                return;

            case DestroyMode.KillFinalize:
            {
                if (diedThing.def.filthLeaving == null)
                {
                    break;
                }
                for (int i = leavingsRect.minZ; i <= leavingsRect.maxZ; i++)
                {
                    for (int j = leavingsRect.minX; j <= leavingsRect.maxX; j++)
                    {
                        FilthMaker.TryMakeFilth(new IntVec3(j, 0, i), map, diedThing.def.filthLeaving, Rand.RangeInclusive(1, 3));
                    }
                }
                break;
            }
            }
            ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();

            if (mode == DestroyMode.KillFinalize && diedThing.def.killedLeavings != null)
            {
                for (int k = 0; k < diedThing.def.killedLeavings.Count; k++)
                {
                    Thing thing = ThingMaker.MakeThing(diedThing.def.killedLeavings[k].thingDef);
                    thing.stackCount = diedThing.def.killedLeavings[k].count;
                    thingOwner.TryAdd(thing);
                }
            }
            if (CanBuildingLeaveResources(diedThing, mode))
            {
                Frame frame = diedThing as Frame;
                if (frame != null)
                {
                    for (int num = frame.resourceContainer.Count - 1; num >= 0; num--)
                    {
                        int num2 = GetBuildingResourcesLeaveCalculator(diedThing, mode)(frame.resourceContainer[num].stackCount);
                        if (num2 > 0)
                        {
                            frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[num], thingOwner, num2);
                        }
                    }
                    frame.resourceContainer.ClearAndDestroyContents();
                }
                else
                {
                    List <ThingDefCountClass> list = diedThing.CostListAdjusted();
                    for (int l = 0; l < list.Count; l++)
                    {
                        ThingDefCountClass thingDefCountClass = list[l];
                        int num3 = GetBuildingResourcesLeaveCalculator(diedThing, mode)(thingDefCountClass.count);
                        if (num3 > 0 && mode == DestroyMode.KillFinalize && thingDefCountClass.thingDef.slagDef != null)
                        {
                            int count = thingDefCountClass.thingDef.slagDef.smeltProducts.First((ThingDefCountClass pro) => pro.thingDef == ThingDefOf.Steel).count;
                            int a     = num3 / count;
                            a = Mathf.Min(a, diedThing.def.Size.Area / 2);
                            for (int m = 0; m < a; m++)
                            {
                                thingOwner.TryAdd(ThingMaker.MakeThing(thingDefCountClass.thingDef.slagDef));
                            }
                            num3 -= a * count;
                        }
                        if (num3 > 0)
                        {
                            Thing thing2 = ThingMaker.MakeThing(thingDefCountClass.thingDef);
                            thing2.stackCount = num3;
                            thingOwner.TryAdd(thing2);
                        }
                    }
                }
            }
            List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder().ToList();
            int            num4  = 0;

            while (thingOwner.Count > 0)
            {
                if (mode == DestroyMode.KillFinalize && !map.areaManager.Home[list2[num4]])
                {
                    thingOwner[0].SetForbidden(value: true, warnOnFail: false);
                }
                if (!thingOwner.TryDrop(thingOwner[0], list2[num4], map, ThingPlaceMode.Near, out var lastResultingThing, null, nearPlaceValidator))
                {
                    Log.Warning(string.Concat("Failed to place all leavings for destroyed thing ", diedThing, " at ", leavingsRect.CenterCell));
                    break;
                }
                listOfLeavingsOut?.Add(lastResultingThing);
                num4++;
                if (num4 >= list2.Count)
                {
                    num4 = 0;
                }
            }
        }
        public static void DoLeavingsFor(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect)
        {
            if (Current.ProgramState != ProgramState.Playing && mode != DestroyMode.Refund)
            {
                return;
            }
            switch (mode)
            {
            case DestroyMode.Vanish:
                return;

            case DestroyMode.KillFinalize:
                if (diedThing.def.filthLeaving != null)
                {
                    for (int i = leavingsRect.minZ; i <= leavingsRect.maxZ; i++)
                    {
                        for (int j = leavingsRect.minX; j <= leavingsRect.maxX; j++)
                        {
                            IntVec3 c = new IntVec3(j, 0, i);
                            FilthMaker.MakeFilth(c, map, diedThing.def.filthLeaving, Rand.RangeInclusive(1, 3));
                        }
                    }
                }
                break;
            }
            ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();

            if (mode == DestroyMode.KillFinalize && diedThing.def.killedLeavings != null)
            {
                for (int k = 0; k < diedThing.def.killedLeavings.Count; k++)
                {
                    Thing thing = ThingMaker.MakeThing(diedThing.def.killedLeavings[k].thingDef, null);
                    thing.stackCount = diedThing.def.killedLeavings[k].count;
                    thingOwner.TryAdd(thing, true);
                }
            }
            if (GenLeaving.CanBuildingLeaveResources(diedThing, mode))
            {
                Frame frame = diedThing as Frame;
                if (frame != null)
                {
                    for (int num = frame.resourceContainer.Count - 1; num >= 0; num--)
                    {
                        int num2 = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(frame.resourceContainer[num].stackCount);
                        if (num2 > 0)
                        {
                            frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[num], thingOwner, num2, true);
                        }
                    }
                    frame.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish);
                }
                else
                {
                    List <ThingCountClass> list = diedThing.CostListAdjusted();
                    for (int l = 0; l < list.Count; l++)
                    {
                        ThingCountClass thingCountClass = list[l];
                        int             num3            = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(thingCountClass.count);
                        if (num3 > 0 && mode == DestroyMode.KillFinalize && thingCountClass.thingDef.slagDef != null)
                        {
                            int count = thingCountClass.thingDef.slagDef.smeltProducts.First((ThingCountClass pro) => pro.thingDef == ThingDefOf.Steel).count;
                            int num4  = num3 / 2 / 8;
                            for (int m = 0; m < num4; m++)
                            {
                                thingOwner.TryAdd(ThingMaker.MakeThing(thingCountClass.thingDef.slagDef, null), true);
                            }
                            num3 -= num4 * count;
                        }
                        if (num3 > 0)
                        {
                            Thing thing2 = ThingMaker.MakeThing(thingCountClass.thingDef, null);
                            thing2.stackCount = num3;
                            thingOwner.TryAdd(thing2, true);
                        }
                    }
                }
            }
            List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder(null).ToList();
            int            num5  = 0;

            while (true)
            {
                if (thingOwner.Count > 0)
                {
                    if (mode == DestroyMode.KillFinalize && !((Area)map.areaManager.Home)[list2[num5]])
                    {
                        thingOwner[0].SetForbidden(true, false);
                    }
                    Thing thing3 = default(Thing);
                    if (thingOwner.TryDrop(thingOwner[0], list2[num5], map, ThingPlaceMode.Near, out thing3, (Action <Thing, int>)null))
                    {
                        num5++;
                        if (num5 >= list2.Count)
                        {
                            num5 = 0;
                        }
                        continue;
                    }
                    break;
                }
                return;
            }
            Log.Warning("Failed to place all leavings for destroyed thing " + diedThing + " at " + leavingsRect.CenterCell);
        }
        // Token: 0x060000D7 RID: 215 RVA: 0x000066F8 File Offset: 0x000048F8
        public void CompleteConstruction(Pawn worker)
        {
            Map  map  = base.Map;
            bool flag = this.GetStatValue(StatDefOf.WorkToBuild, true) > 150f && this.def.entityDefToBuild is ThingDef && ((ThingDef)this.def.entityDefToBuild).category == ThingCategory.Building;

            if (flag)
            {
                SoundDefOf.Building_Complete.PlayOneShot(new TargetInfo(base.Position, map, false));
            }
            ThingDef thingDef = this.def.entityDefToBuild as ThingDef;
            Thing    thing    = null;
            bool     flag2    = thingDef != null;

            if (flag2)
            {
                thing = ThingMaker.MakeThing(thingDef, base.Stuff);
                thing.SetFactionDirect(base.Faction);
                CompQuality compQuality = thing.TryGetComp <CompQuality>();
                bool        flag3       = compQuality != null;
                if (flag3)
                {
                    int relevantSkillLevel = 1;
                    compQuality.SetQuality(QualityUtility.GenerateQualityCreatedByPawn(relevantSkillLevel, false), ArtGenerationContext.Colony);
                }
                CompArt compArt = thing.TryGetComp <CompArt>();
                bool    flag4   = compArt != null;
                if (flag4)
                {
                    bool flag5 = compQuality == null;
                    if (flag5)
                    {
                        compArt.InitializeArt(ArtGenerationContext.Colony);
                    }
                    compArt.JustCreatedBy(worker);
                }
                thing.HitPoints = Mathf.CeilToInt((float)this.HitPoints / (float)base.MaxHitPoints * (float)thing.MaxHitPoints);
                GenSpawn.Spawn(thing, base.Position, map, base.Rotation, WipeMode.FullRefund, false);
            }
            else
            {
                map.terrainGrid.SetTerrain(base.Position, (TerrainDef)this.def.entityDefToBuild);
                FilthMaker.RemoveAllFilth(base.Position, map);
            }
            bool flag6 = thingDef != null && (thingDef.passability == Traversability.Impassable || thingDef.Fillage == FillCategory.Full) && (thing == null || !(thing is Building_Door));

            if (flag6)
            {
                foreach (IntVec3 c in GenAdj.CellsOccupiedBy(base.Position, base.Rotation, this.def.Size))
                {
                    foreach (Thing thing2 in map.thingGrid.ThingsAt(c).ToList <Thing>())
                    {
                        bool flag7 = thing2 is Plant;
                        if (flag7)
                        {
                            thing2.Destroy(DestroyMode.KillFinalize);
                        }
                        else
                        {
                            bool flag8 = thing2.def.category == ThingCategory.Item || thing2 is Pawn;
                            if (flag8)
                            {
                                GenPlace.TryPlaceThing(thing2, thing2.Position, thing2.Map, ThingPlaceMode.Near, null, null, default(Rot4));
                            }
                        }
                    }
                }
            }
            worker.records.Increment(RecordDefOf.ThingsConstructed);
        }
示例#11
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    to            = new Toil();
                    to.initAction = delegate()
                    {
                        this.ticksLeft = Rand.Range(300, 900);
                        int     num2 = 0;
                        IntVec3 c;
                        for (;;)
                        {
                            c = this.pawn.Position + GenAdj.AdjacentCellsAndInside[Rand.Range(0, 9)];
                            num2++;
                            if (num2 > 12)
                            {
                                break;
                            }
                            if (c.InBounds(this.pawn.Map) && c.Standable(this.pawn.Map))
                            {
                                goto IL_A5;
                            }
                        }
                        c = this.pawn.Position;
IL_A5:
                        this.job.targetA = c;
                        this.pawn.pather.StopDead();
                    };
                    to.tickAction = delegate()
                    {
                        if (this.ticksLeft % 150 == 149)
                        {
                            FilthMaker.MakeFilth(this.job.targetA.Cell, base.Map, ThingDefOf.Filth_Vomit, this.pawn.LabelIndefinite(), 1);
                            if (this.pawn.needs.food.CurLevelPercentage > 0.1f)
                            {
                                this.pawn.needs.food.CurLevel -= this.pawn.needs.food.MaxLevel * 0.04f;
                            }
                        }
                        this.ticksLeft--;
                        if (this.ticksLeft <= 0)
                        {
                            base.ReadyForNextToil();
                            TaleRecorder.RecordTale(TaleDefOf.Vomited, new object[]
                            {
                                this.pawn
                            });
                        }
                    };
                    to.defaultCompleteMode = ToilCompleteMode.Never;
                    to.WithEffect(EffecterDefOf.Vomit, TargetIndex.A);
                    to.PlaySustainerOrSound(() => SoundDefOf.Vomit);
                    this.$current = to;
                    if (!this.$disposing)
                    {
                        this.$PC = 1;
                    }
                    return(true);

                case 1u:
                    this.$PC = -1;
                    break;
                }
                return(false);
            }
示例#12
0
 public override void Tick()
 {
     if (base.Spawned)
     {
         this.sustainer.Maintain();
         Vector3 vector = base.Position.ToVector3Shifted();
         IntVec3 c;
         if (Rand.MTBEventOccurs(TunnelHiveSpawner.FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(base.Position, base.Map, TunnelHiveSpawner.FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), null, null, out c, 999999))
         {
             FilthMaker.MakeFilth(c, base.Map, TunnelHiveSpawner.filthTypes.RandomElement <ThingDef>(), 1);
         }
         if (Rand.MTBEventOccurs(TunnelHiveSpawner.DustMoteSpawnMTB, 1f, 1.TicksToSeconds()))
         {
             MoteMaker.ThrowDustPuffThick(new Vector3(vector.x, 0f, vector.z)
             {
                 y = AltitudeLayer.MoteOverhead.AltitudeFor()
             }, base.Map, Rand.Range(1.5f, 3f), new Color(1f, 1f, 1f, 2.5f));
         }
         if (this.secondarySpawnTick <= Find.TickManager.TicksGame)
         {
             this.sustainer.End();
             Map     map      = base.Map;
             IntVec3 position = base.Position;
             this.Destroy(DestroyMode.Vanish);
             if (this.spawnHive)
             {
                 Hive hive = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive, null), position, map, WipeMode.Vanish);
                 hive.SetFaction(Faction.OfInsects, null);
                 foreach (CompSpawner compSpawner in hive.GetComps <CompSpawner>())
                 {
                     if (compSpawner.PropsSpawner.thingToSpawn == ThingDefOf.InsectJelly)
                     {
                         compSpawner.TryDoSpawn();
                         break;
                     }
                 }
             }
             if (this.insectsPoints > 0f)
             {
                 this.insectsPoints = Mathf.Max(this.insectsPoints, Hive.spawnablePawnKinds.Min((PawnKindDef x) => x.combatPower));
                 float       pointsLeft = this.insectsPoints;
                 List <Pawn> list       = new List <Pawn>();
                 int         num        = 0;
                 while (pointsLeft > 0f)
                 {
                     num++;
                     if (num > 1000)
                     {
                         Log.Error("Too many iterations.", false);
                         break;
                     }
                     IEnumerable <PawnKindDef> source = from x in Hive.spawnablePawnKinds
                                                        where x.combatPower <= pointsLeft
                                                        select x;
                     PawnKindDef pawnKindDef;
                     if (!source.TryRandomElement(out pawnKindDef))
                     {
                         break;
                     }
                     Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDef, Faction.OfInsects);
                     GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2, null), map, WipeMode.Vanish);
                     pawn.mindState.spawnedByInfestationThingComp = this.spawnedByInfestationThingComp;
                     list.Add(pawn);
                     pointsLeft -= pawnKindDef.combatPower;
                 }
                 if (list.Any <Pawn>())
                 {
                     LordMaker.MakeNewLord(Faction.OfInsects, new LordJob_AssaultColony(Faction.OfInsects, true, false, false, false, true), map, list);
                 }
             }
         }
     }
 }
示例#13
0
        private void GrowLowRockFormationFrom(IntVec3 root, Map map)
        {
            ThingDef        filth_RubbleRock = ThingDefOf.Filth_RubbleRock;
            ThingDef        mineableThing    = Find.World.NaturalRockTypesIn(map.Tile).RandomElement <ThingDef>().building.mineableThing;
            Rot4            random           = Rot4.Random;
            MapGenFloatGrid elevation        = MapGenerator.Elevation;
            IntVec3         intVec           = root;

            for (;;)
            {
                Rot4 random2;
                do
                {
                    random2 = Rot4.Random;
                }while (random2 == random);
                intVec += random2.FacingCell;
                if (!intVec.InBounds(map) || intVec.GetEdifice(map) != null || intVec.GetFirstItem(map) != null)
                {
                    break;
                }
                if (elevation[intVec] > 0.55f)
                {
                    break;
                }
                if (!map.terrainGrid.TerrainAt(intVec).affordances.Contains(TerrainAffordanceDefOf.Heavy))
                {
                    break;
                }
                GenSpawn.Spawn(mineableThing, intVec, map, WipeMode.Vanish);
                IntVec3[] adjacentCellsAndInside = GenAdj.AdjacentCellsAndInside;
                int       i = 0;
                while (i < adjacentCellsAndInside.Length)
                {
                    IntVec3 b = adjacentCellsAndInside[i];
                    if (Rand.Value < 0.5f)
                    {
                        IntVec3 c = intVec + b;
                        if (c.InBounds(map))
                        {
                            bool         flag      = false;
                            List <Thing> thingList = c.GetThingList(map);
                            for (int j = 0; j < thingList.Count; j++)
                            {
                                Thing thing = thingList[j];
                                if (thing.def.category != ThingCategory.Plant && thing.def.category != ThingCategory.Item && thing.def.category != ThingCategory.Pawn)
                                {
                                    flag = true;
                                    break;
                                }
                            }
                            if (!flag)
                            {
                                FilthMaker.MakeFilth(c, map, filth_RubbleRock, 1);
                            }
                        }
                    }
IL_1AD:
                    i++;
                    continue;
                    goto IL_1AD;
                }
            }
        }
示例#14
0
        public void CompleteConstruction(Pawn worker)
        {
            this.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish);
            Map map = base.Map;

            this.Destroy(DestroyMode.Vanish);
            if (this.GetStatValue(StatDefOf.WorkToBuild, true) > 150.0 && base.def.entityDefToBuild is ThingDef && ((ThingDef)base.def.entityDefToBuild).category == ThingCategory.Building)
            {
                SoundDefOf.BuildingComplete.PlayOneShot(new TargetInfo(base.Position, map, false));
            }
            ThingDef thingDef = base.def.entityDefToBuild as ThingDef;
            Thing    thing    = null;

            if (thingDef != null)
            {
                thing = ThingMaker.MakeThing(thingDef, base.Stuff);
                thing.SetFactionDirect(base.Faction);
                CompQuality compQuality = thing.TryGetComp <CompQuality>();
                if (compQuality != null)
                {
                    int level = worker.skills.GetSkill(SkillDefOf.Construction).Level;
                    compQuality.SetQuality(QualityUtility.RandomCreationQuality(level), ArtGenerationContext.Colony);
                }
                CompArt compArt = thing.TryGetComp <CompArt>();
                if (compArt != null)
                {
                    if (compQuality == null)
                    {
                        compArt.InitializeArt(ArtGenerationContext.Colony);
                    }
                    compArt.JustCreatedBy(worker);
                }
                thing.HitPoints = Mathf.CeilToInt((float)this.HitPoints / (float)base.MaxHitPoints * (float)thing.MaxHitPoints);
                GenSpawn.Spawn(thing, base.Position, map, base.Rotation, false);
            }
            else
            {
                map.terrainGrid.SetTerrain(base.Position, (TerrainDef)base.def.entityDefToBuild);
                FilthMaker.RemoveAllFilth(base.Position, map);
            }
            if (thingDef != null && (thingDef.passability == Traversability.Impassable || thingDef.Fillage == FillCategory.Full) && (thing == null || !(thing is Building_Door)))
            {
                foreach (IntVec3 item in GenAdj.CellsOccupiedBy(base.Position, base.Rotation, base.def.Size))
                {
                    foreach (Thing item2 in map.thingGrid.ThingsAt(item).ToList())
                    {
                        if (item2 is Plant)
                        {
                            item2.Destroy(DestroyMode.KillFinalize);
                        }
                        else if (item2.def.category == ThingCategory.Item || item2 is Pawn)
                        {
                            GenPlace.TryMoveThing(item2, item2.Position, item2.Map);
                        }
                    }
                }
            }
            worker.records.Increment(RecordDefOf.ThingsConstructed);
            if (thing != null && thing.GetStatValue(StatDefOf.WorkToBuild, true) >= 10000.0)
            {
                TaleRecorder.RecordTale(TaleDefOf.CompletedLongConstructionProject, worker, thing.def);
            }
        }
示例#15
0
 // Token: 0x06002627 RID: 9767 RVA: 0x00122210 File Offset: 0x00120610
 public override void Tick()
 {
     if (base.Spawned)
     {
         HiveLike hive = (HiveLike)ThingMaker.MakeThing(hiveDef, null);
         this.sustainer.Maintain();
         Vector3 vector = base.Position.ToVector3Shifted();
         ResetStaticData();
         if (Rand.MTBEventOccurs(FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(base.Position, base.Map, TunnelHiveLikeSpawner.FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), null, null, out IntVec3 c, 999999))
         {
             FilthMaker.TryMakeFilth(c, base.Map, filthTypes.RandomElement <ThingDef>(), 1);
         }
         if (Rand.MTBEventOccurs(DustMoteSpawnMTB, 1f, 1.TicksToSeconds()))
         {
             MoteMaker.ThrowDustPuffThick(new Vector3(vector.x, 0f, vector.z)
             {
                 y = AltitudeLayer.MoteOverhead.AltitudeFor()
             }, base.Map, Rand.Range(1.5f, 3f), new Color(1f, 1f, 1f, 2.5f));
         }
         if (this.secondarySpawnTick <= Find.TickManager.TicksGame)
         {
             this.sustainer.End();
             Map     map      = base.Map;
             IntVec3 position = base.Position;
             this.Destroy(DestroyMode.Vanish);
             if (this.spawnHive)
             {
                 if (Def.strikespreexplode)
                 {
                     FireEvent(map, position);
                     EventDraw(map, position);
                 }
                 if (Def.explodesprespawn)
                 {
                     GenExplosion.DoExplosion(position, map, Def.blastradius, Def.damageDef, null, -1, -1f, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false);
                 }
                 hive = (HiveLike)GenSpawn.Spawn(ThingMaker.MakeThing(hiveDef, null), position, map, WipeMode.Vanish);
                 hive.SetFaction(faction, null);
                 hive.InitialPawnsPoints    = hivePoints / 2;
                 hive.MaxSpawnedPawnsPoints = hivePoints;
                 if (parentHiveLike != null)
                 {
                     parentHiveLike.childHiveLikes.Add(hive);
                 }
                 foreach (CompXenomorph_SpawnerLike compSpawner in hive.GetComps <CompXenomorph_SpawnerLike>())
                 {
                     if (compSpawner.PropsSpawner.thingToSpawn == ThingDefOf.InsectJelly)
                     {
                         compSpawner.TryDoSpawn();
                         break;
                     }
                 }
             }
             if (this.hivePoints > 0f)
             {
                 this.hivePoints = Mathf.Max(this.hivePoints, pawnKinds.Min((PawnKindDef x) => x.combatPower));
                 float       pointsLeft = this.hivePoints;
                 List <Pawn> list       = new List <Pawn>();
                 int         num        = 0;
                 while (pointsLeft > 0f)
                 {
                     num++;
                     if (num > 1000)
                     {
                         //    Log.Error("Too many iterations.", false);
                         break;
                     }
                     IEnumerable <PawnKindDef> source = from x in pawnKinds
                                                        where x.combatPower <= pointsLeft
                                                        select x;
                     if (!source.TryRandomElement(out PawnKindDef pawnKindDef))
                     {
                         break;
                     }
                     Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDef, faction);
                     GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2, null), map, WipeMode.Vanish);
                     pawn.mindState.spawnedByInfestationThingComp = this.spawnedByInfestationThingComp;
                     list.Add(pawn);
                     pointsLeft -= pawnKindDef.combatPower;
                 }
                 if (list.Any <Pawn>())
                 {
                     LordMaker.MakeNewLord(faction, new LordJob_AssaultColony(faction, true, false, false, false, true), map, list);
                 }
             }
         }
     }
 }
 private void DropCarriedFilth(Filth f)
 {
     this.ThinCarriedFilth(f);
     FilthMaker.MakeFilth(this.pawn.Position, this.pawn.Map, f.def, f.sources);
 }
示例#17
0
 public bool CanDropAt(IntVec3 c, Map map, FilthSourceFlags additionalFlags = FilthSourceFlags.None)
 {
     return(FilthMaker.CanMakeFilth(c, map, def, additionalFlags));
 }