Ejemplo n.º 1
0
        private bool CanSpawnAt(IntVec3 c, Map map)
        {
            bool result;

            if (!c.Standable(map) || c.Fogged(map) || map.fertilityGrid.FertilityAt(c) < ThingDefOf.Plant_Ambrosia.plant.fertilityMin || !c.GetRoom(map, RegionType.Set_Passable).PsychologicallyOutdoors || c.GetEdifice(map) != null || !GenPlant.GrowthSeasonNow(c, map, false))
            {
                result = false;
            }
            else
            {
                Plant plant = c.GetPlant(map);
                if (plant != null && plant.def.plant.growDays > 10f)
                {
                    result = false;
                }
                else
                {
                    List <Thing> thingList = c.GetThingList(map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        if (thingList[i].def == ThingDefOf.Plant_Ambrosia)
                        {
                            return(false);
                        }
                    }
                    result = true;
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static void MakeColony(params ColonyMakerFlag[] flags)
        {
            bool godMode = DebugSettings.godMode;

            DebugSettings.godMode            = true;
            Thing.allowDestroyNonDestroyable = true;
            if (Autotests_ColonyMaker.usedCells == null)
            {
                Autotests_ColonyMaker.usedCells = new BoolGrid(Autotests_ColonyMaker.Map);
            }
            else
            {
                Autotests_ColonyMaker.usedCells.ClearAndResizeTo(Autotests_ColonyMaker.Map);
            }
            IntVec3 center  = Autotests_ColonyMaker.Map.Center;
            int     minX    = center.x - 50;
            IntVec3 center2 = Autotests_ColonyMaker.Map.Center;

            Autotests_ColonyMaker.overRect = new CellRect(minX, center2.z - 50, 100, 100);
            Autotests_ColonyMaker.DeleteAllSpawnedPawns();
            GenDebug.ClearArea(Autotests_ColonyMaker.overRect, Find.VisibleMap);
            if (flags.Contains(ColonyMakerFlag.Animals))
            {
                foreach (PawnKindDef item in from k in DefDatabase <PawnKindDef> .AllDefs
                         where k.RaceProps.Animal
                         select k)
                {
                    CellRect cellRect = default(CellRect);
                    if (Autotests_ColonyMaker.TryGetFreeRect(6, 3, out cellRect))
                    {
                        cellRect = cellRect.ContractedBy(1);
                        foreach (IntVec3 item2 in cellRect)
                        {
                            Autotests_ColonyMaker.Map.terrainGrid.SetTerrain(item2, TerrainDefOf.Concrete);
                        }
                        GenSpawn.Spawn(PawnGenerator.GeneratePawn(item, null), cellRect.Cells.ElementAt(0), Autotests_ColonyMaker.Map);
                        IntVec3 intVec = cellRect.Cells.ElementAt(1);
                        Pawn    p      = (Pawn)GenSpawn.Spawn(PawnGenerator.GeneratePawn(item, null), intVec, Autotests_ColonyMaker.Map);
                        HealthUtility.DamageUntilDead(p);
                        Corpse       thing        = (Corpse)intVec.GetThingList(Find.VisibleMap).First((Thing t) => t is Corpse);
                        CompRottable compRottable = thing.TryGetComp <CompRottable>();
                        if (compRottable != null)
                        {
                            compRottable.RotProgress += 1200000f;
                        }
                        if (item.RaceProps.leatherDef != null)
                        {
                            GenSpawn.Spawn(item.RaceProps.leatherDef, cellRect.Cells.ElementAt(2), Autotests_ColonyMaker.Map);
                        }
                        if (item.RaceProps.meatDef != null)
                        {
                            GenSpawn.Spawn(item.RaceProps.meatDef, cellRect.Cells.ElementAt(3), Autotests_ColonyMaker.Map);
                        }
                        continue;
                    }
                    return;
                }
            }
            if (flags.Contains(ColonyMakerFlag.ConduitGrid))
            {
                Designator_Build designator_Build = new Designator_Build(ThingDefOf.PowerConduit);
                for (int i = Autotests_ColonyMaker.overRect.minX; i < Autotests_ColonyMaker.overRect.maxX; i++)
                {
                    for (int j = Autotests_ColonyMaker.overRect.minZ; j < Autotests_ColonyMaker.overRect.maxZ; j += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(i, 0, j));
                    }
                }
                for (int l = Autotests_ColonyMaker.overRect.minZ; l < Autotests_ColonyMaker.overRect.maxZ; l++)
                {
                    for (int m = Autotests_ColonyMaker.overRect.minX; m < Autotests_ColonyMaker.overRect.maxX; m += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(m, 0, l));
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.PowerPlants))
            {
                List <ThingDef> list = new List <ThingDef>();
                list.Add(ThingDefOf.SolarGenerator);
                list.Add(ThingDefOf.WindTurbine);
                List <ThingDef> list2 = list;
                int             num   = 0;
                while (num < 8)
                {
                    if (Autotests_ColonyMaker.TryMakeBuilding(list2[num % list2.Count]) != null)
                    {
                        num++;
                        continue;
                    }
                    Log.Message("Could not make solar generator.");
                    break;
                }
            }
            if (flags.Contains(ColonyMakerFlag.Batteries))
            {
                for (int n = 0; n < 6; n++)
                {
                    Thing thing2 = Autotests_ColonyMaker.TryMakeBuilding(ThingDefOf.Battery);
                    if (thing2 == null)
                    {
                        Log.Message("Could not make battery.");
                        break;
                    }
                    ((Building_Battery)thing2).GetComp <CompPowerBattery>().AddEnergy(999999f);
                }
            }
            if (flags.Contains(ColonyMakerFlag.WorkTables))
            {
                IEnumerable <ThingDef> enumerable = from def in DefDatabase <ThingDef> .AllDefs
                                                    where typeof(Building_WorkTable).IsAssignableFrom(def.thingClass)
                                                    select def;
                foreach (ThingDef item3 in enumerable)
                {
                    Thing thing3 = Autotests_ColonyMaker.TryMakeBuilding(item3);
                    if (thing3 == null)
                    {
                        Log.Message("Could not make worktable: " + item3.defName);
                        break;
                    }
                    Building_WorkTable building_WorkTable = thing3 as Building_WorkTable;
                    if (building_WorkTable != null)
                    {
                        foreach (RecipeDef allRecipe in building_WorkTable.def.AllRecipes)
                        {
                            building_WorkTable.billStack.AddBill(allRecipe.MakeNewBill());
                        }
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.AllBuildings))
            {
                IEnumerable <ThingDef> enumerable2 = from def in DefDatabase <ThingDef> .AllDefs
                                                     where def.category == ThingCategory.Building && def.designationCategory != null
                                                     select def;
                foreach (ThingDef item4 in enumerable2)
                {
                    if (item4 != ThingDefOf.PowerConduit)
                    {
                        Thing thing4 = Autotests_ColonyMaker.TryMakeBuilding(item4);
                        if (thing4 == null)
                        {
                            Log.Message("Could not make building: " + item4.defName);
                            break;
                        }
                    }
                }
            }
            CellRect rect = default(CellRect);

            if (!Autotests_ColonyMaker.TryGetFreeRect(33, 33, out rect))
            {
                Log.Error("Could not get wallable rect");
            }
            rect = rect.ContractedBy(1);
            if (flags.Contains(ColonyMakerFlag.AllItems))
            {
                List <ThingDef> itemDefs = (from def in DefDatabase <ThingDef> .AllDefs
                                            where DebugThingPlaceHelper.IsDebugSpawnable(def) && def.category == ThingCategory.Item
                                            select def).ToList();
                Autotests_ColonyMaker.FillWithItems(rect, itemDefs);
            }
            else if (flags.Contains(ColonyMakerFlag.ItemsRawFood))
            {
                List <ThingDef> list3 = new List <ThingDef>();
                list3.Add(ThingDefOf.RawPotatoes);
                Autotests_ColonyMaker.FillWithItems(rect, list3);
            }
            if (flags.Contains(ColonyMakerFlag.Filth))
            {
                foreach (IntVec3 item5 in rect)
                {
                    GenSpawn.Spawn(ThingDefOf.FilthDirt, item5, Autotests_ColonyMaker.Map);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ItemsWall))
            {
                CellRect         cellRect2         = rect.ExpandedBy(1);
                Designator_Build designator_Build2 = new Designator_Build(ThingDefOf.Wall);
                designator_Build2.SetStuffDef(ThingDefOf.WoodLog);
                foreach (IntVec3 edgeCell in cellRect2.EdgeCells)
                {
                    designator_Build2.DesignateSingleCell(edgeCell);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsMany))
            {
                Autotests_ColonyMaker.MakeColonists(15, Autotests_ColonyMaker.overRect.CenterCell);
            }
            else if (flags.Contains(ColonyMakerFlag.ColonistOne))
            {
                Autotests_ColonyMaker.MakeColonists(1, Autotests_ColonyMaker.overRect.CenterCell);
            }
            if (flags.Contains(ColonyMakerFlag.Fire))
            {
                CellRect cellRect3 = default(CellRect);
                if (!Autotests_ColonyMaker.TryGetFreeRect(30, 30, out cellRect3))
                {
                    Log.Error("Could not get free rect for fire.");
                }
                ThingDef plantTreeOak = ThingDefOf.PlantTreeOak;
                foreach (IntVec3 item6 in cellRect3)
                {
                    GenSpawn.Spawn(plantTreeOak, item6, Autotests_ColonyMaker.Map);
                }
                foreach (IntVec3 item7 in cellRect3)
                {
                    IntVec3 current9 = item7;
                    if (current9.x % 7 == 0 && current9.z % 7 == 0)
                    {
                        GenExplosion.DoExplosion(current9, Find.VisibleMap, 3.9f, DamageDefOf.Flame, null, -1, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsHungry))
            {
                Autotests_ColonyMaker.DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.food.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsTired))
            {
                Autotests_ColonyMaker.DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.rest.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsInjured))
            {
                Autotests_ColonyMaker.DoToColonists(0.4f, delegate(Pawn col)
                {
                    DamageDef def2 = (from d in DefDatabase <DamageDef> .AllDefs
                                      where d.externalViolence
                                      select d).RandomElement();
                    col.TakeDamage(new DamageInfo(def2, 10, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsDiseased))
            {
                foreach (HediffDef item8 in from d in DefDatabase <HediffDef> .AllDefs
                         where d.hediffClass != typeof(Hediff_AddedPart) && (d.HasComp(typeof(HediffComp_Immunizable)) || d.HasComp(typeof(HediffComp_GrowthMode)))
                         select d)
                {
                    Pawn     pawn      = PawnGenerator.GeneratePawn(Faction.OfPlayer.def.basicMemberKind, Faction.OfPlayer);
                    CellRect cellRect4 = default(CellRect);
                    Autotests_ColonyMaker.TryGetFreeRect(1, 1, out cellRect4);
                    GenSpawn.Spawn(pawn, cellRect4.CenterCell, Autotests_ColonyMaker.Map);
                    pawn.health.AddHediff(item8, null, null);
                }
            }
            if (flags.Contains(ColonyMakerFlag.Beds))
            {
                IEnumerable <ThingDef> source = from def in DefDatabase <ThingDef> .AllDefs
                                                where def.thingClass == typeof(Building_Bed)
                                                select def;
                int freeColonistsCount = Autotests_ColonyMaker.Map.mapPawns.FreeColonistsCount;
                int num2 = 0;
                while (num2 < freeColonistsCount)
                {
                    if (Autotests_ColonyMaker.TryMakeBuilding(source.RandomElement()) != null)
                    {
                        num2++;
                        continue;
                    }
                    Log.Message("Could not make beds.");
                    break;
                }
            }
            if (flags.Contains(ColonyMakerFlag.Stockpiles))
            {
                Designator_ZoneAddStockpile_Resources designator_ZoneAddStockpile_Resources = new Designator_ZoneAddStockpile_Resources();
                IEnumerator enumerator11 = Enum.GetValues(typeof(StoragePriority)).GetEnumerator();
                try
                {
                    while (enumerator11.MoveNext())
                    {
                        StoragePriority priority  = (StoragePriority)enumerator11.Current;
                        CellRect        cellRect5 = default(CellRect);
                        Autotests_ColonyMaker.TryGetFreeRect(7, 7, out cellRect5);
                        cellRect5 = cellRect5.ContractedBy(1);
                        designator_ZoneAddStockpile_Resources.DesignateMultiCell(cellRect5.Cells);
                        Zone_Stockpile zone_Stockpile = (Zone_Stockpile)Autotests_ColonyMaker.Map.zoneManager.ZoneAt(cellRect5.CenterCell);
                        zone_Stockpile.settings.Priority = priority;
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator11 as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.GrowingZones))
            {
                Zone_Growing dummyZone = new Zone_Growing(Autotests_ColonyMaker.Map.zoneManager);
                foreach (ThingDef item9 in from d in DefDatabase <ThingDef> .AllDefs
                         where d.plant != null && GenPlant.CanSowOnGrower(d, dummyZone)
                         select d)
                {
                    CellRect cellRect6 = default(CellRect);
                    if (!Autotests_ColonyMaker.TryGetFreeRect(6, 6, out cellRect6))
                    {
                        Log.Error("Could not get growing zone rect.");
                    }
                    cellRect6 = cellRect6.ContractedBy(1);
                    foreach (IntVec3 item10 in cellRect6)
                    {
                        Autotests_ColonyMaker.Map.terrainGrid.SetTerrain(item10, TerrainDefOf.Soil);
                    }
                    Designator_ZoneAdd_Growing designator_ZoneAdd_Growing = new Designator_ZoneAdd_Growing();
                    designator_ZoneAdd_Growing.DesignateMultiCell(cellRect6.Cells);
                    Zone_Growing zone_Growing = (Zone_Growing)Autotests_ColonyMaker.Map.zoneManager.ZoneAt(cellRect6.CenterCell);
                    zone_Growing.SetPlantDefToGrow(item9);
                }
                dummyZone.Delete();
            }
            Autotests_ColonyMaker.ClearAllHomeArea();
            Autotests_ColonyMaker.FillWithHomeArea(Autotests_ColonyMaker.overRect);
            DebugSettings.godMode            = godMode;
            Thing.allowDestroyNonDestroyable = false;
        }
Ejemplo n.º 3
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    this.$current = Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(() => GenPlant.AdjacentSowBlocker(this.job.plantDefToSow, this.TargetA.Cell, this.Map) != null).FailOn(() => !this.job.plantDefToSow.CanEverPlantAt(this.TargetLocA, this.Map));
                    if (!this.$disposing)
                    {
                        this.$PC = 1;
                    }
                    return(true);

                case 1u:
                    < MakeNewToils > c__AnonStorey.sowToil            = new Toil();
                    < MakeNewToils > c__AnonStorey.sowToil.initAction = delegate()
                    {
                        < MakeNewToils > c__AnonStorey.< > f__ref$0.$this.TargetThingA = GenSpawn.Spawn(< MakeNewToils > c__AnonStorey.< > f__ref$0.$this.job.plantDefToSow, <MakeNewToils> c__AnonStorey.< > f__ref$0.$this.TargetLocA, <MakeNewToils> c__AnonStorey.< > f__ref$0.$this.Map, WipeMode.Vanish);
Ejemplo n.º 4
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(() => GenPlant.AdjacentSowBlocker(this.job.plantDefToSow, this.TargetA.Cell, this.Map) != null).FailOn(() => !this.job.plantDefToSow.CanEverPlantAt(this.TargetLocA, this.Map)));

            Toil sowToil = new Toil();

            sowToil.initAction = delegate()
            {
                this.TargetThingA = GenSpawn.Spawn(this.job.plantDefToSow, this.TargetLocA, this.Map, WipeMode.Vanish);
                this.pawn.Reserve(this.TargetThingA, sowToil.actor.CurJob, 1, -1, null);
                Plant plant = (Plant)this.TargetThingA;
                plant.Growth = 0f;
                plant.sown   = true;
            };
            sowToil.tickAction = delegate()
            {
                Pawn actor = sowToil.actor;
                if (actor.skills != null)
                {
                    actor.skills.Learn(SkillDefOf.Plants, 0.0935f, false);
                }
                float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true);
                float num       = statValue;
                Plant plant     = this.Plant;
                if (plant.LifeStage != PlantLifeStage.Sowing)
                {
                    Log.Error(this.$this + " getting sowing work while not in Sowing life stage.", false);
                }
                this.sowWorkDone += num;
                if (this.sowWorkDone >= plant.def.plant.sowWork)
                {
                    plant.Growth = 0.05f;
                    this.Map.mapDrawer.MapMeshDirty(plant.Position, MapMeshFlag.Things);
                    actor.records.Increment(RecordDefOf.PlantsSown);
                    this.ReadyForNextToil();
                }
            };
            sowToil.defaultCompleteMode = ToilCompleteMode.Never;
            sowToil.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            sowToil.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            sowToil.WithEffect(EffecterDefOf.Sow, TargetIndex.A);
            sowToil.WithProgressBar(TargetIndex.A, () => this.sowWorkDone / this.Plant.def.plant.sowWork, true, -0.5f);
            sowToil.PlaySustainerOrSound(() => SoundDefOf.Interact_Sow);
            sowToil.AddFinishAction(delegate
            {
                if (this.TargetThingA != null)
                {
                    Plant plant = (Plant)sowToil.actor.CurJob.GetTarget(TargetIndex.A).Thing;
                    if (this.sowWorkDone < plant.def.plant.sowWork && !this.TargetThingA.Destroyed)
                    {
                        this.TargetThingA.Destroy(DestroyMode.Vanish);
                    }
                }
            });
            sowToil.activeSkill = (() => SkillDefOf.Plants);
            yield return(sowToil);

            yield break;
        }
Ejemplo n.º 5
0
 public override void TickLong()
 {
     this.CheckTemperatureMakeLeafless();
     if (base.Destroyed)
     {
         return;
     }
     if (GenPlant.GrowthSeasonNow(base.Position, base.Map))
     {
         float num  = this.growthInt;
         bool  flag = this.LifeStage == PlantLifeStage.Mature;
         this.growthInt += this.GrowthPerTick * 2000f;
         if (this.growthInt > 1f)
         {
             this.growthInt = 1f;
         }
         if (((!flag && this.LifeStage == PlantLifeStage.Mature) || (int)(num * 10f) != (int)(this.growthInt * 10f)) && this.CurrentlyCultivated())
         {
             base.Map.mapDrawer.MapMeshDirty(base.Position, MapMeshFlag.Things);
         }
         if (this.CanReproduceNow && Rand.MTBEventOccurs(this.def.plant.reproduceMtbDays, 60000f, 2000f))
         {
             GenPlantReproduction.TryReproduceFrom(base.Position, this.def, SeedTargFindMode.Reproduce, base.Map);
         }
     }
     if (!this.HasEnoughLightToGrow)
     {
         this.unlitTicks += 2000;
     }
     else
     {
         this.unlitTicks = 0;
     }
     this.ageInt += 2000;
     if (this.Dying)
     {
         Map  map                        = base.Map;
         bool isCrop                     = this.IsCrop;
         bool harvestableNow             = this.HarvestableNow;
         bool dyingBecauseExposedToLight = this.DyingBecauseExposedToLight;
         int  amount                     = Mathf.CeilToInt(this.CurrentDyingDamagePerTick * 2000f);
         base.TakeDamage(new DamageInfo(DamageDefOf.Rotting, amount, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
         if (base.Destroyed)
         {
             if (isCrop && this.def.plant.Harvestable && MessagesRepeatAvoider.MessageShowAllowed("MessagePlantDiedOfRot-" + this.def.defName, 240f))
             {
                 string key;
                 if (harvestableNow)
                 {
                     key = "MessagePlantDiedOfRot_LeftUnharvested";
                 }
                 else if (dyingBecauseExposedToLight)
                 {
                     key = "MessagePlantDiedOfRot_ExposedToLight";
                 }
                 else
                 {
                     key = "MessagePlantDiedOfRot";
                 }
                 Messages.Message(key.Translate(new object[]
                 {
                     this.Label
                 }).CapitalizeFirst(), new TargetInfo(base.Position, map, false), MessageTypeDefOf.NegativeEvent);
             }
             return;
         }
     }
     this.cachedLabelMouseover = null;
 }
Ejemplo n.º 6
0
        public override void Print(SectionLayer layer)
        {
            Vector3 a = this.TrueCenter();

            Rand.PushState();
            Rand.Seed = base.Position.GetHashCode();
            int num = Mathf.CeilToInt(this.growthInt * (float)this.def.plant.maxMeshCount);

            if (num < 1)
            {
                num = 1;
            }
            float   num2   = this.def.plant.visualSizeRange.LerpThroughRange(this.growthInt);
            float   num3   = this.def.graphicData.drawSize.x * num2;
            Vector3 vector = Vector3.zero;
            int     num4   = 0;

            int[] positionIndices = PlantPosIndices.GetPositionIndices(this);
            bool  flag            = false;

            for (int i = 0; i < positionIndices.Length; i++)
            {
                int num5 = positionIndices[i];
                if (this.def.plant.maxMeshCount == 1)
                {
                    vector = a + Gen.RandomHorizontalVector(0.05f);
                    float num6 = (float)base.Position.z;
                    if (vector.z - num2 / 2f < num6)
                    {
                        vector.z = num6 + num2 / 2f;
                        flag     = true;
                    }
                }
                else
                {
                    int num7         = 1;
                    int maxMeshCount = this.def.plant.maxMeshCount;
                    switch (maxMeshCount)
                    {
                    case 1:
                        num7 = 1;
                        goto IL_19E;

                    case 2:
                    case 3:
IL_13C:
                        if (maxMeshCount == 9)
                        {
                            num7 = 3;
                            goto IL_19E;
                        }
                        if (maxMeshCount == 16)
                        {
                            num7 = 4;
                            goto IL_19E;
                        }
                        if (maxMeshCount != 25)
                        {
                            Log.Error(this.def + " must have plant.MaxMeshCount that is a perfect square.");
                            goto IL_19E;
                        }
                        num7 = 5;
                        goto IL_19E;

                    case 4:
                        num7 = 2;
                        goto IL_19E;
                    }
                    goto IL_13C;
IL_19E:
                    float num8 = 1f / (float)num7;
                    vector     = base.Position.ToVector3();
                    vector.y   = this.def.Altitude;
                    vector.x  += 0.5f * num8;
                    vector.z  += 0.5f * num8;
                    int num9  = num5 / num7;
                    int num10 = num5 % num7;
                    vector.x += (float)num9 * num8;
                    vector.z += (float)num10 * num8;
                    float max = num8 * 0.3f;
                    vector += Gen.RandomHorizontalVector(max);
                }
                bool     @bool     = Rand.Bool;
                Material matSingle = this.Graphic.MatSingle;
                GenPlant.SetWindExposureColors(Plant.workingColors, this);
                Vector2  vector2 = new Vector2(num3, num3);
                Vector3  center  = vector;
                Vector2  size    = vector2;
                Material mat     = matSingle;
                bool     flipUv  = @bool;
                Printer_Plane.PrintPlane(layer, center, size, mat, 0f, flipUv, null, Plant.workingColors, 0.1f);
                num4++;
                if (num4 >= num)
                {
                    break;
                }
            }
            if (this.def.graphicData.shadowData != null)
            {
                Vector3 center2 = a + this.def.graphicData.shadowData.offset * num2;
                if (flag)
                {
                    center2.z = base.Position.ToVector3Shifted().z + this.def.graphicData.shadowData.offset.z;
                }
                center2.y -= 0.046875f;
                Vector3 volume = this.def.graphicData.shadowData.volume * num2;
                Printer_Shadow.PrintShadow(layer, center2, volume, Rot4.North);
            }
            Rand.PopState();
        }
        public bool CheckSpawnWildPlantAt(IntVec3 c, float plantDensity, float wholeMapNumDesiredPlants, bool setRandomGrowth = false)
        {
            bool result;

            if (plantDensity <= 0f || c.GetPlant(this.map) != null || c.GetCover(this.map) != null || c.GetEdifice(this.map) != null || this.map.fertilityGrid.FertilityAt(c) <= 0f || !GenPlant.SnowAllowsPlanting(c, this.map))
            {
                result = false;
            }
            else
            {
                bool cavePlants = this.GoodRoofForCavePlant(c);
                if (this.SaturatedAt(c, plantDensity, cavePlants, wholeMapNumDesiredPlants))
                {
                    result = false;
                }
                else
                {
                    this.CalculatePlantsWhichCanGrowAt(c, WildPlantSpawner.tmpPossiblePlants, cavePlants, plantDensity);
                    if (!WildPlantSpawner.tmpPossiblePlants.Any <ThingDef>())
                    {
                        result = false;
                    }
                    else
                    {
                        this.CalculateDistancesToNearbyClusters(c);
                        WildPlantSpawner.tmpPossiblePlantsWithWeight.Clear();
                        for (int i = 0; i < WildPlantSpawner.tmpPossiblePlants.Count; i++)
                        {
                            float value = this.PlantChoiceWeight(WildPlantSpawner.tmpPossiblePlants[i], c, WildPlantSpawner.distanceSqToNearbyClusters, wholeMapNumDesiredPlants, plantDensity);
                            WildPlantSpawner.tmpPossiblePlantsWithWeight.Add(new KeyValuePair <ThingDef, float>(WildPlantSpawner.tmpPossiblePlants[i], value));
                        }
                        KeyValuePair <ThingDef, float> keyValuePair;
                        if (!WildPlantSpawner.tmpPossiblePlantsWithWeight.TryRandomElementByWeight((KeyValuePair <ThingDef, float> x) => x.Value, out keyValuePair))
                        {
                            result = false;
                        }
                        else
                        {
                            Plant plant = (Plant)ThingMaker.MakeThing(keyValuePair.Key, null);
                            if (setRandomGrowth)
                            {
                                plant.Growth = Rand.Range(0.07f, 1f);
                                if (plant.def.plant.LimitedLifespan)
                                {
                                    plant.Age = Rand.Range(0, Mathf.Max(plant.def.plant.LifespanTicks - 50, 0));
                                }
                            }
                            GenSpawn.Spawn(plant, c, this.map, WipeMode.Vanish);
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 8
0
 public static void SetWindExposureColors(Color32[] colors, Plant plant)
 {
     colors[1].a = (colors[2].a = GenPlant.GetWindExposure(plant));
     colors[0].a = (colors[3].a = 0);
 }
        public static bool TryFindReproductionDestination(IntVec3 source, ThingDef plantDef, SeedTargFindMode mode, Map map, out IntVec3 foundCell)
        {
            float radius = -1f;

            switch (mode)
            {
            case SeedTargFindMode.Reproduce:
                radius = plantDef.plant.reproduceRadius;
                break;

            case SeedTargFindMode.MapGenCluster:
                radius = plantDef.plant.WildClusterRadiusActual;
                break;

            case SeedTargFindMode.MapEdge:
                radius = 40f;
                break;

            case SeedTargFindMode.Cave:
                radius = plantDef.plant.WildClusterRadiusActual;
                break;
            }
            int      num      = 0;
            int      num2     = 0;
            float    num3     = 0f;
            CellRect cellRect = CellRect.CenteredOn(source, Mathf.RoundToInt(radius));

            cellRect.ClipInsideMap(map);
            for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                {
                    IntVec3 c2    = new IntVec3(j, 0, i);
                    Plant   plant = c2.GetPlant(map);
                    if (plant != null && (mode != SeedTargFindMode.Cave || plant.def.plant.cavePlant))
                    {
                        num++;
                        if (plant.def == plantDef)
                        {
                            num2++;
                        }
                    }
                    num3 += c2.GetTerrain(map).fertility;
                }
            }
            float num4 = (float)((mode != SeedTargFindMode.Cave) ? map.Biome.plantDensity : 0.5);
            float num5 = num3 * num4;
            bool  flag = (float)num > num5;

            if ((float)num > num5 * 1.25)
            {
                foundCell = IntVec3.Invalid;
                return(false);
            }
            if (mode != 0 && mode != SeedTargFindMode.Cave)
            {
                BiomeDef curBiome = map.Biome;
                float    num6     = curBiome.AllWildPlants.Sum((ThingDef pd) => curBiome.CommonalityOfPlant(pd));
                float    num7     = curBiome.CommonalityOfPlant(plantDef) / num6;
                float    num8     = curBiome.CommonalityOfPlant(plantDef) * plantDef.plant.wildCommonalityMaxFraction / num6;
                float    num9     = num5 * num8;
                if ((float)num2 > num9)
                {
                    foundCell = IntVec3.Invalid;
                    return(false);
                }
                float num10 = num5 * num7;
                bool  flag2 = (float)num2 < num10 * 0.5;
                if (flag && !flag2)
                {
                    foundCell = IntVec3.Invalid;
                    return(false);
                }
            }
            Predicate <IntVec3> validator = delegate(IntVec3 c)
            {
                if (!plantDef.CanEverPlantAt(c, map))
                {
                    return(false);
                }
                if (plantDef.plant.cavePlant && !GenPlantReproduction.GoodRoofForCavePlantReproduction(c, map))
                {
                    return(false);
                }
                if (!GenPlant.SnowAllowsPlanting(c, map))
                {
                    return(false);
                }
                if (!source.InHorDistOf(c, radius))
                {
                    return(false);
                }
                if (!GenSight.LineOfSight(source, c, map, true, null, 0, 0))
                {
                    return(false);
                }
                return(true);
            };

            return(CellFinder.TryFindRandomCellNear(source, map, Mathf.CeilToInt(radius), validator, out foundCell));
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            _003CMakeNewToils_003Ec__Iterator0 _003CMakeNewToils_003Ec__Iterator = (_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_003a: stateMachine*/;

            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(() => GenPlant.AdjacentSowBlocker(_003CMakeNewToils_003Ec__Iterator._0024this.job.plantDefToSow, _003CMakeNewToils_003Ec__Iterator._0024this.TargetA.Cell, _003CMakeNewToils_003Ec__Iterator._0024this.Map) != null).FailOn(() => !_003CMakeNewToils_003Ec__Iterator._0024this.job.plantDefToSow.CanEverPlantAt(_003CMakeNewToils_003Ec__Iterator._0024this.TargetLocA, _003CMakeNewToils_003Ec__Iterator._0024this.Map)));

            /*Error: Unable to find new state assignment for yield return*/;
        }
Ejemplo n.º 11
0
        public override Job JobOnCell(Pawn pawn, IntVec3 c)
        {
            Map map = pawn.Map;

            if (c.IsForbidden(pawn))
            {
                return(null);
            }
            if (!GenPlant.GrowthSeasonNow(c, map))
            {
                return(null);
            }
            if (WorkGiver_Grower.wantedPlantDef == null)
            {
                WorkGiver_Grower.wantedPlantDef = WorkGiver_Grower.CalculateWantedPlantDef(c, map);
                if (WorkGiver_Grower.wantedPlantDef == null)
                {
                    return(null);
                }
            }
            List <Thing> thingList = c.GetThingList(map);
            bool         flag      = false;

            for (int i = 0; i < thingList.Count; i++)
            {
                Thing thing = thingList[i];
                if (thing.def == WorkGiver_Grower.wantedPlantDef)
                {
                    return(null);
                }
                if ((thing is Blueprint || thing is Frame) && thing.Faction == pawn.Faction)
                {
                    flag = true;
                }
            }
            if (flag)
            {
                Thing edifice = c.GetEdifice(map);
                if (edifice != null && !(edifice.def.fertility < 0.0))
                {
                    goto IL_00dc;
                }
                return(null);
            }
            goto IL_00dc;
IL_00dc:
            if (WorkGiver_Grower.wantedPlantDef.plant.cavePlant)
            {
                if (!c.Roofed(map))
                {
                    JobFailReason.Is(WorkGiver_GrowerSow.CantSowCavePlantBecauseUnroofedTrans);
                    return(null);
                }
                if (map.glowGrid.GameGlowAt(c, true) > 0.0)
                {
                    JobFailReason.Is(WorkGiver_GrowerSow.CantSowCavePlantBecauseOfLightTrans);
                    return(null);
                }
            }
            Plant plant = c.GetPlant(map);

            if (plant != null && plant.def.plant.blockAdjacentSow)
            {
                if (pawn.CanReserve(plant, 1, -1, null, false) && !plant.IsForbidden(pawn))
                {
                    return(new Job(JobDefOf.CutPlant, plant));
                }
                return(null);
            }
            Thing thing2 = GenPlant.AdjacentSowBlocker(WorkGiver_Grower.wantedPlantDef, c, map);

            if (thing2 != null)
            {
                Plant plant2 = thing2 as Plant;
                if (plant2 != null && pawn.CanReserve(plant2, 1, -1, null, false) && !plant2.IsForbidden(pawn))
                {
                    IPlantToGrowSettable plantToGrowSettable = plant2.Position.GetPlantToGrowSettable(plant2.Map);
                    if (plantToGrowSettable != null && plantToGrowSettable.GetPlantDefToGrow() == plant2.def)
                    {
                        goto IL_0211;
                    }
                    return(new Job(JobDefOf.CutPlant, plant2));
                }
                goto IL_0211;
            }
            if (WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Growing).Level < WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill)
            {
                return(null);
            }
            for (int j = 0; j < thingList.Count; j++)
            {
                Thing thing3 = thingList[j];
                if (thing3.def.BlockPlanting)
                {
                    if (!pawn.CanReserve(thing3, 1, -1, null, false))
                    {
                        return(null);
                    }
                    if (thing3.def.category == ThingCategory.Plant)
                    {
                        if (!thing3.IsForbidden(pawn))
                        {
                            return(new Job(JobDefOf.CutPlant, thing3));
                        }
                        return(null);
                    }
                    if (thing3.def.EverHaulable)
                    {
                        return(HaulAIUtility.HaulAsideJobFor(pawn, thing3));
                    }
                    return(null);
                }
            }
            if (WorkGiver_Grower.wantedPlantDef.CanEverPlantAt(c, map) && GenPlant.GrowthSeasonNow(c, map) && pawn.CanReserve(c, 1, -1, null, false))
            {
                Job job = new Job(JobDefOf.Sow, c);
                job.plantDefToSow = WorkGiver_Grower.wantedPlantDef;
                return(job);
            }
            return(null);

IL_0211:
            return(null);
        }