예제 #1
0
        private bool CanSpawnAt(IntVec3 c, Map map)
        {
            if (!c.Standable(map) || c.Fogged(map) || map.fertilityGrid.FertilityAt(c) < ThingDefOf.Plant_Ambrosia.plant.fertilityMin || !c.GetRoom(map).PsychologicallyOutdoors || c.GetEdifice(map) != null || !PlantUtility.GrowthSeasonNow(c, map))
            {
                return(false);
            }
            Plant plant = c.GetPlant(map);

            if (plant != null && plant.def.plant.growDays > 10f)
            {
                return(false);
            }
            List <Thing> thingList = c.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                if (thingList[i].def == ThingDefOf.Plant_Ambrosia)
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
        public override void Print(SectionLayer layer)
        {
            Vector3 a = this.TrueCenter();

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

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

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

            foreach (int num5 in positionIndices)
            {
                if (def.plant.maxMeshCount == 1)
                {
                    center = a + Gen.RandomHorizontalVector(0.05f);
                    float num6 = base.Position.z;
                    if (center.z - num2 / 2f < num6)
                    {
                        center.z = num6 + num2 / 2f;
                        flag     = true;
                    }
                }
                else
                {
                    int num7 = 1;
                    switch (def.plant.maxMeshCount)
                    {
                    case 1:
                        num7 = 1;
                        break;

                    case 4:
                        num7 = 2;
                        break;

                    case 9:
                        num7 = 3;
                        break;

                    case 16:
                        num7 = 4;
                        break;

                    case 25:
                        num7 = 5;
                        break;

                    default:
                        Log.Error(def + " must have plant.MaxMeshCount that is a perfect square.");
                        break;
                    }
                    float num8 = 1f / (float)num7;
                    center    = base.Position.ToVector3();
                    center.y  = def.Altitude;
                    center.x += 0.5f * num8;
                    center.z += 0.5f * num8;
                    int num9  = num5 / num7;
                    int num10 = num5 % num7;
                    center.x += (float)num9 * num8;
                    center.z += (float)num10 * num8;
                    float max = num8 * 0.3f;
                    center += Gen.RandomHorizontalVector(max);
                }
                bool     @bool     = Rand.Bool;
                Material matSingle = Graphic.MatSingle;
                PlantUtility.SetWindExposureColors(workingColors, this);
                Printer_Plane.PrintPlane(size: new Vector2(num3, num3), layer: layer, center: center, mat: matSingle, rot: 0f, flipUv: @bool, uvs: null, colors: workingColors, topVerticesAltitudeBias: 0.1f, uvzPayload: this.HashOffset() % 1024);
                num4++;
                if (num4 >= num)
                {
                    break;
                }
            }
            if (def.graphicData.shadowData != null)
            {
                Vector3 center2 = a + def.graphicData.shadowData.offset * num2;
                if (flag)
                {
                    center2.z = base.Position.ToVector3Shifted().z + def.graphicData.shadowData.offset.z;
                }
                center2.y -= 0.0454545468f;
                Vector3 volume = def.graphicData.shadowData.volume * num2;
                Printer_Shadow.PrintShadow(layer, center2, volume, Rot4.North);
            }
            Rand.PopState();
        }
예제 #3
0
        public bool CheckSpawnWildPlantAt(IntVec3 c, float plantDensity, float wholeMapNumDesiredPlants, bool setRandomGrowth = false)
        {
            if (plantDensity <= 0f || c.GetPlant(this.map) != null || c.GetCover(this.map) != null || c.GetEdifice(this.map) != null || this.map.fertilityGrid.FertilityAt(c) <= 0f || !PlantUtility.SnowAllowsPlanting(c, this.map))
            {
                return(false);
            }
            bool cavePlants = this.GoodRoofForCavePlant(c);

            if (this.SaturatedAt(c, plantDensity, cavePlants, wholeMapNumDesiredPlants))
            {
                return(false);
            }
            this.CalculatePlantsWhichCanGrowAt(c, WildPlantSpawner.tmpPossiblePlants, cavePlants, plantDensity);
            if (!WildPlantSpawner.tmpPossiblePlants.Any <ThingDef>())
            {
                return(false);
            }
            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))
            {
                return(false);
            }
            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);
            return(true);
        }
        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);
            }
            Autotests_ColonyMaker.overRect = new CellRect(Autotests_ColonyMaker.Map.Center.x - 50, Autotests_ColonyMaker.Map.Center.z - 50, 100, 100);
            Autotests_ColonyMaker.DeleteAllSpawnedPawns();
            GenDebug.ClearArea(Autotests_ColonyMaker.overRect, Find.CurrentMap);
            if (flags.Contains(ColonyMakerFlag.Animals))
            {
                foreach (PawnKindDef pawnKindDef in from k in DefDatabase <PawnKindDef> .AllDefs
                         where k.RaceProps.Animal
                         select k)
                {
                    CellRect cellRect;
                    if (!Autotests_ColonyMaker.TryGetFreeRect(6, 3, out cellRect))
                    {
                        return;
                    }
                    cellRect = cellRect.ContractedBy(1);
                    foreach (IntVec3 c in cellRect)
                    {
                        Autotests_ColonyMaker.Map.terrainGrid.SetTerrain(c, TerrainDefOf.Concrete);
                    }
                    GenSpawn.Spawn(PawnGenerator.GeneratePawn(pawnKindDef, null), cellRect.Cells.ElementAt(0), Autotests_ColonyMaker.Map, WipeMode.Vanish);
                    IntVec3 intVec = cellRect.Cells.ElementAt(1);
                    Pawn    p      = (Pawn)GenSpawn.Spawn(PawnGenerator.GeneratePawn(pawnKindDef, null), intVec, Autotests_ColonyMaker.Map, WipeMode.Vanish);
                    HealthUtility.DamageUntilDead(p);
                    Corpse       thing        = (Corpse)intVec.GetThingList(Find.CurrentMap).First((Thing t) => t is Corpse);
                    CompRottable compRottable = thing.TryGetComp <CompRottable>();
                    if (compRottable != null)
                    {
                        compRottable.RotProgress += 1200000f;
                    }
                    if (pawnKindDef.RaceProps.leatherDef != null)
                    {
                        GenSpawn.Spawn(pawnKindDef.RaceProps.leatherDef, cellRect.Cells.ElementAt(2), Autotests_ColonyMaker.Map, WipeMode.Vanish);
                    }
                    if (pawnKindDef.RaceProps.meatDef != null)
                    {
                        GenSpawn.Spawn(pawnKindDef.RaceProps.meatDef, cellRect.Cells.ElementAt(3), Autotests_ColonyMaker.Map, WipeMode.Vanish);
                    }
                }
            }
            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 k2 = Autotests_ColonyMaker.overRect.minZ; k2 < Autotests_ColonyMaker.overRect.maxZ; k2++)
                {
                    for (int l = Autotests_ColonyMaker.overRect.minX; l < Autotests_ColonyMaker.overRect.maxX; l += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(l, 0, k2));
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.PowerPlants))
            {
                List <ThingDef> list = new List <ThingDef>
                {
                    ThingDefOf.SolarGenerator,
                    ThingDefOf.WindTurbine
                };
                for (int m = 0; m < 8; m++)
                {
                    if (Autotests_ColonyMaker.TryMakeBuilding(list[m % list.Count]) == null)
                    {
                        Log.Message("Could not make solar generator.", false);
                        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.", false);
                        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 thingDef in enumerable)
                {
                    Thing thing3 = Autotests_ColonyMaker.TryMakeBuilding(thingDef);
                    if (thing3 == null)
                    {
                        Log.Message("Could not make worktable: " + thingDef.defName, false);
                        break;
                    }
                    Building_WorkTable building_WorkTable = thing3 as Building_WorkTable;
                    if (building_WorkTable != null)
                    {
                        foreach (RecipeDef recipe in building_WorkTable.def.AllRecipes)
                        {
                            building_WorkTable.billStack.AddBill(recipe.MakeNewBill());
                        }
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.AllBuildings))
            {
                IEnumerable <ThingDef> enumerable2 = from def in DefDatabase <ThingDef> .AllDefs
                                                     where def.category == ThingCategory.Building && def.BuildableByPlayer
                                                     select def;
                foreach (ThingDef thingDef2 in enumerable2)
                {
                    if (thingDef2 != ThingDefOf.PowerConduit)
                    {
                        if (Autotests_ColonyMaker.TryMakeBuilding(thingDef2) == null)
                        {
                            Log.Message("Could not make building: " + thingDef2.defName, false);
                            break;
                        }
                    }
                }
            }
            CellRect rect;

            if (!Autotests_ColonyMaker.TryGetFreeRect(33, 33, out rect))
            {
                Log.Error("Could not get wallable rect", false);
            }
            rect = rect.ContractedBy(1);
            if (flags.Contains(ColonyMakerFlag.AllItems))
            {
                List <ThingDef> itemDefs = (from def in DefDatabase <ThingDef> .AllDefs
                                            where DebugThingPlaceHelper.IsDebugSpawnable(def, false) && def.category == ThingCategory.Item
                                            select def).ToList <ThingDef>();
                Autotests_ColonyMaker.FillWithItems(rect, itemDefs);
            }
            else if (flags.Contains(ColonyMakerFlag.ItemsRawFood))
            {
                List <ThingDef> list2 = new List <ThingDef>();
                list2.Add(ThingDefOf.RawPotatoes);
                Autotests_ColonyMaker.FillWithItems(rect, list2);
            }
            if (flags.Contains(ColonyMakerFlag.Filth))
            {
                foreach (IntVec3 loc in rect)
                {
                    GenSpawn.Spawn(ThingDefOf.Filth_Dirt, loc, Autotests_ColonyMaker.Map, WipeMode.Vanish);
                }
            }
            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 c2 in cellRect2.EdgeCells)
                {
                    designator_Build2.DesignateSingleCell(c2);
                }
            }
            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;
                if (!Autotests_ColonyMaker.TryGetFreeRect(30, 30, out cellRect3))
                {
                    Log.Error("Could not get free rect for fire.", false);
                }
                ThingDef plant_TreeOak = ThingDefOf.Plant_TreeOak;
                foreach (IntVec3 loc2 in cellRect3)
                {
                    GenSpawn.Spawn(plant_TreeOak, loc2, Autotests_ColonyMaker.Map, WipeMode.Vanish);
                }
                foreach (IntVec3 center in cellRect3)
                {
                    if (center.x % 7 == 0 && center.z % 7 == 0)
                    {
                        GenExplosion.DoExplosion(center, Find.CurrentMap, 3.9f, DamageDefOf.Flame, null, -1, -1f, null, 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 def3 = (from d in DefDatabase <DamageDef> .AllDefs
                                      where d.ExternalViolenceFor(null)
                                      select d).RandomElement <DamageDef>();
                    col.TakeDamage(new DamageInfo(def3, 10f, 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsDiseased))
            {
                foreach (HediffDef def2 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;
                    Autotests_ColonyMaker.TryGetFreeRect(1, 1, out cellRect4);
                    GenSpawn.Spawn(pawn, cellRect4.CenterCell, Autotests_ColonyMaker.Map, WipeMode.Vanish);
                    pawn.health.AddHediff(def2, null, 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;
                for (int num = 0; num < freeColonistsCount; num++)
                {
                    if (Autotests_ColonyMaker.TryMakeBuilding(source.RandomElement <ThingDef>()) == null)
                    {
                        Log.Message("Could not make beds.", false);
                        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())
                    {
                        object          obj      = enumerator11.Current;
                        StoragePriority priority = (StoragePriority)obj;
                        CellRect        cellRect5;
                        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);
                Autotests_ColonyMaker.Map.zoneManager.RegisterZone(dummyZone);
                foreach (ThingDef plantDefToGrow in from d in DefDatabase <ThingDef> .AllDefs
                         where d.plant != null && PlantUtility.CanSowOnGrower(d, dummyZone)
                         select d)
                {
                    CellRect cellRect6;
                    if (!Autotests_ColonyMaker.TryGetFreeRect(6, 6, out cellRect6))
                    {
                        Log.Error("Could not get growing zone rect.", false);
                    }
                    cellRect6 = cellRect6.ContractedBy(1);
                    foreach (IntVec3 c3 in cellRect6)
                    {
                        Autotests_ColonyMaker.Map.terrainGrid.SetTerrain(c3, TerrainDefOf.Soil);
                    }
                    Designator_ZoneAdd_Growing designator_ZoneAdd_Growing = new Designator_ZoneAdd_Growing();
                    designator_ZoneAdd_Growing.DesignateMultiCell(cellRect6.Cells);
                    Zone_Growing zone_Growing = Autotests_ColonyMaker.Map.zoneManager.ZoneAt(cellRect6.CenterCell) as Zone_Growing;
                    if (zone_Growing != null)
                    {
                        zone_Growing.SetPlantDefToGrow(plantDefToGrow);
                    }
                }
                dummyZone.Delete();
            }
            Autotests_ColonyMaker.ClearAllHomeArea();
            Autotests_ColonyMaker.FillWithHomeArea(Autotests_ColonyMaker.overRect);
            DebugSettings.godMode            = godMode;
            Thing.allowDestroyNonDestroyable = false;
        }
예제 #5
0
 public override void TickLong()
 {
     CheckTemperatureMakeLeafless();
     if (base.Destroyed)
     {
         return;
     }
     if (PlantUtility.GrowthSeasonNow(base.Position, base.Map))
     {
         float num  = growthInt;
         bool  num2 = LifeStage == PlantLifeStage.Mature;
         growthInt += GrowthPerTick * 2000f;
         if (growthInt > 1f)
         {
             growthInt = 1f;
         }
         if (((!num2 && LifeStage == PlantLifeStage.Mature) || (int)(num * 10f) != (int)(growthInt * 10f)) && CurrentlyCultivated())
         {
             base.Map.mapDrawer.MapMeshDirty(base.Position, MapMeshFlag.Things);
         }
     }
     if (!HasEnoughLightToGrow)
     {
         unlitTicks += 2000;
     }
     else
     {
         unlitTicks = 0;
     }
     ageInt += 2000;
     if (Dying)
     {
         Map  map                        = base.Map;
         bool isCrop                     = IsCrop;
         bool harvestableNow             = HarvestableNow;
         bool dyingBecauseExposedToLight = DyingBecauseExposedToLight;
         int  num3                       = Mathf.CeilToInt(CurrentDyingDamagePerTick * 2000f);
         TakeDamage(new DamageInfo(DamageDefOf.Rotting, num3));
         if (base.Destroyed)
         {
             if (isCrop && def.plant.Harvestable && MessagesRepeatAvoider.MessageShowAllowed("MessagePlantDiedOfRot-" + def.defName, 240f))
             {
                 string key = harvestableNow ? "MessagePlantDiedOfRot_LeftUnharvested" : ((!dyingBecauseExposedToLight) ? "MessagePlantDiedOfRot" : "MessagePlantDiedOfRot_ExposedToLight");
                 Messages.Message(key.Translate(GetCustomLabelNoCount(includeHp: false)), new TargetInfo(base.Position, map), MessageTypeDefOf.NegativeEvent);
             }
             return;
         }
     }
     cachedLabelMouseover = null;
     if (def.plant.dropLeaves)
     {
         MoteLeaf moteLeaf = MoteMaker.MakeStaticMote(Vector3.zero, base.Map, ThingDefOf.Mote_Leaf) as MoteLeaf;
         if (moteLeaf != null)
         {
             float   num4       = def.plant.visualSizeRange.LerpThroughRange(growthInt);
             float   treeHeight = def.graphicData.drawSize.x * num4;
             Vector3 b          = Rand.InsideUnitCircleVec3 * LeafSpawnRadius;
             moteLeaf.Initialize(base.Position.ToVector3Shifted() + Vector3.up * Rand.Range(LeafSpawnYMin, LeafSpawnYMax) + b + Vector3.forward * def.graphicData.shadowData.offset.z, Rand.Value * 2000.TicksToSeconds(), b.z > 0f, treeHeight);
         }
     }
 }
 internal bool <> m__0(ThingDef d)
 {
     return(d.plant != null && PlantUtility.CanSowOnGrower(d, this.dummyZone));
 }
예제 #7
0
 public static void SetWindExposureColors(Color32[] colors, Plant plant)
 {
     colors[1].a = (colors[2].a = PlantUtility.GetWindExposure(plant));
     colors[0].a = (colors[3].a = 0);
 }
예제 #8
0
        public static void MakeColony(params ColonyMakerFlag[] flags)
        {
            bool godMode = DebugSettings.godMode;

            DebugSettings.godMode            = true;
            Thing.allowDestroyNonDestroyable = true;
            if (usedCells == null)
            {
                usedCells = new BoolGrid(Map);
            }
            else
            {
                usedCells.ClearAndResizeTo(Map);
            }
            overRect = new CellRect(Map.Center.x - 50, Map.Center.z - 50, 100, 100);
            DeleteAllSpawnedPawns();
            GenDebug.ClearArea(overRect, Find.CurrentMap);
            if (flags.Contains(ColonyMakerFlag.Animals))
            {
                foreach (PawnKindDef item in DefDatabase <PawnKindDef> .AllDefs.Where((PawnKindDef k) => k.RaceProps.Animal))
                {
                    if (!TryGetFreeRect(6, 3, out CellRect result))
                    {
                        return;
                    }
                    result = result.ContractedBy(1);
                    foreach (IntVec3 item2 in result)
                    {
                        Map.terrainGrid.SetTerrain(item2, TerrainDefOf.Concrete);
                    }
                    GenSpawn.Spawn(PawnGenerator.GeneratePawn(item), result.Cells.ElementAt(0), Map);
                    IntVec3 intVec = result.Cells.ElementAt(1);
                    HealthUtility.DamageUntilDead((Pawn)GenSpawn.Spawn(PawnGenerator.GeneratePawn(item), intVec, Map));
                    CompRottable compRottable = ((Corpse)intVec.GetThingList(Find.CurrentMap).First((Thing t) => t is Corpse)).TryGetComp <CompRottable>();
                    if (compRottable != null)
                    {
                        compRottable.RotProgress += 1200000f;
                    }
                    if (item.RaceProps.leatherDef != null)
                    {
                        GenSpawn.Spawn(item.RaceProps.leatherDef, result.Cells.ElementAt(2), Map);
                    }
                    if (item.RaceProps.meatDef != null)
                    {
                        GenSpawn.Spawn(item.RaceProps.meatDef, result.Cells.ElementAt(3), Map);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ConduitGrid))
            {
                Designator_Build designator_Build = new Designator_Build(ThingDefOf.PowerConduit);
                for (int i = overRect.minX; i < overRect.maxX; i++)
                {
                    for (int j = overRect.minZ; j < overRect.maxZ; j += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(i, 0, j));
                    }
                }
                for (int l = overRect.minZ; l < overRect.maxZ; l++)
                {
                    for (int m = overRect.minX; m < overRect.maxX; m += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(m, 0, l));
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.PowerPlants))
            {
                List <ThingDef> list = new List <ThingDef>
                {
                    ThingDefOf.SolarGenerator,
                    ThingDefOf.WindTurbine
                };
                for (int n = 0; n < 8; n++)
                {
                    if (TryMakeBuilding(list[n % list.Count]) == null)
                    {
                        Log.Message("Could not make solar generator.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Batteries))
            {
                for (int num = 0; num < 6; num++)
                {
                    Thing thing = TryMakeBuilding(ThingDefOf.Battery);
                    if (thing == null)
                    {
                        Log.Message("Could not make battery.");
                        break;
                    }
                    ((Building_Battery)thing).GetComp <CompPowerBattery>().AddEnergy(999999f);
                }
            }
            if (flags.Contains(ColonyMakerFlag.WorkTables))
            {
                foreach (ThingDef item3 in DefDatabase <ThingDef> .AllDefs.Where((ThingDef def) => typeof(Building_WorkTable).IsAssignableFrom(def.thingClass)))
                {
                    Thing thing2 = TryMakeBuilding(item3);
                    if (thing2 == null)
                    {
                        Log.Message("Could not make worktable: " + item3.defName);
                        break;
                    }
                    Building_WorkTable building_WorkTable = thing2 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))
            {
                foreach (ThingDef item4 in DefDatabase <ThingDef> .AllDefs.Where((ThingDef def) => def.category == ThingCategory.Building && def.BuildableByPlayer))
                {
                    if (item4 != ThingDefOf.PowerConduit && TryMakeBuilding(item4) == null)
                    {
                        Log.Message("Could not make building: " + item4.defName);
                        break;
                    }
                }
            }
            if (!TryGetFreeRect(33, 33, out CellRect result2))
            {
                Log.Error("Could not get wallable rect");
            }
            result2 = result2.ContractedBy(1);
            if (flags.Contains(ColonyMakerFlag.AllItems))
            {
                List <ThingDef> itemDefs = DefDatabase <ThingDef> .AllDefs.Where((ThingDef def) => DebugThingPlaceHelper.IsDebugSpawnable(def) && def.category == ThingCategory.Item).ToList();

                FillWithItems(result2, itemDefs);
            }
            else if (flags.Contains(ColonyMakerFlag.ItemsRawFood))
            {
                List <ThingDef> list2 = new List <ThingDef>();
                list2.Add(ThingDefOf.RawPotatoes);
                FillWithItems(result2, list2);
            }
            if (flags.Contains(ColonyMakerFlag.Filth))
            {
                foreach (IntVec3 item5 in result2)
                {
                    GenSpawn.Spawn(ThingDefOf.Filth_Dirt, item5, Map);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ItemsWall))
            {
                CellRect         cellRect          = result2.ExpandedBy(1);
                Designator_Build designator_Build2 = new Designator_Build(ThingDefOf.Wall);
                designator_Build2.SetStuffDef(ThingDefOf.WoodLog);
                foreach (IntVec3 edgeCell in cellRect.EdgeCells)
                {
                    designator_Build2.DesignateSingleCell(edgeCell);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsMany))
            {
                MakeColonists(15, overRect.CenterCell);
            }
            else if (flags.Contains(ColonyMakerFlag.ColonistOne))
            {
                MakeColonists(1, overRect.CenterCell);
            }
            if (flags.Contains(ColonyMakerFlag.Fire))
            {
                if (!TryGetFreeRect(30, 30, out CellRect result3))
                {
                    Log.Error("Could not get free rect for fire.");
                }
                ThingDef plant_TreeOak = ThingDefOf.Plant_TreeOak;
                foreach (IntVec3 item6 in result3)
                {
                    GenSpawn.Spawn(plant_TreeOak, item6, Map);
                }
                foreach (IntVec3 item7 in result3)
                {
                    if (item7.x % 7 == 0 && item7.z % 7 == 0)
                    {
                        GenExplosion.DoExplosion(item7, Find.CurrentMap, 3.9f, DamageDefOf.Flame, null);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsHungry))
            {
                DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.food.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsTired))
            {
                DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.rest.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsInjured))
            {
                DoToColonists(0.4f, delegate(Pawn col)
                {
                    DamageDef def2 = DefDatabase <DamageDef> .AllDefs.Where((DamageDef d) => d.ExternalViolenceFor(null)).RandomElement();
                    col.TakeDamage(new DamageInfo(def2, 10f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsDiseased))
            {
                foreach (HediffDef item8 in DefDatabase <HediffDef> .AllDefs.Where((HediffDef d) => d.hediffClass != typeof(Hediff_AddedPart) && (d.HasComp(typeof(HediffComp_Immunizable)) || d.HasComp(typeof(HediffComp_GrowthMode)))))
                {
                    Pawn pawn = PawnGenerator.GeneratePawn(Faction.OfPlayer.def.basicMemberKind, Faction.OfPlayer);
                    TryGetFreeRect(1, 1, out CellRect result4);
                    GenSpawn.Spawn(pawn, result4.CenterCell, Map);
                    pawn.health.AddHediff(item8);
                }
            }
            if (flags.Contains(ColonyMakerFlag.Beds))
            {
                IEnumerable <ThingDef> source = DefDatabase <ThingDef> .AllDefs.Where((ThingDef def) => def.thingClass == typeof(Building_Bed));

                int freeColonistsCount = Map.mapPawns.FreeColonistsCount;
                for (int num2 = 0; num2 < freeColonistsCount; num2++)
                {
                    if (TryMakeBuilding(source.RandomElement()) == null)
                    {
                        Log.Message("Could not make beds.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Stockpiles))
            {
                Designator_ZoneAddStockpile_Resources designator_ZoneAddStockpile_Resources = new Designator_ZoneAddStockpile_Resources();
                foreach (StoragePriority value in Enum.GetValues(typeof(StoragePriority)))
                {
                    TryGetFreeRect(7, 7, out CellRect result5);
                    result5 = result5.ContractedBy(1);
                    designator_ZoneAddStockpile_Resources.DesignateMultiCell(result5.Cells);
                    ((Zone_Stockpile)Map.zoneManager.ZoneAt(result5.CenterCell)).settings.Priority = value;
                }
            }
            if (flags.Contains(ColonyMakerFlag.GrowingZones))
            {
                Zone_Growing dummyZone = new Zone_Growing(Map.zoneManager);
                Map.zoneManager.RegisterZone(dummyZone);
                foreach (ThingDef item9 in DefDatabase <ThingDef> .AllDefs.Where((ThingDef d) => d.plant != null && PlantUtility.CanSowOnGrower(d, dummyZone)))
                {
                    if (!TryGetFreeRect(6, 6, out CellRect result6))
                    {
                        Log.Error("Could not get growing zone rect.");
                    }
                    result6 = result6.ContractedBy(1);
                    foreach (IntVec3 item10 in result6)
                    {
                        Map.terrainGrid.SetTerrain(item10, TerrainDefOf.Soil);
                    }
                    new Designator_ZoneAdd_Growing().DesignateMultiCell(result6.Cells);
                    (Map.zoneManager.ZoneAt(result6.CenterCell) as Zone_Growing)?.SetPlantDefToGrow(item9);
                }
                dummyZone.Delete();
            }
            ClearAllHomeArea();
            FillWithHomeArea(overRect);
            DebugSettings.godMode            = godMode;
            Thing.allowDestroyNonDestroyable = false;
        }
예제 #9
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;

            foreach (int num5 in positionIndices)
            {
                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;
                        break;

                    default:
                        if (maxMeshCount != 9)
                        {
                            if (maxMeshCount != 16)
                            {
                                if (maxMeshCount != 25)
                                {
                                    Log.Error(this.def + " must have plant.MaxMeshCount that is a perfect square.", false);
                                }
                                else
                                {
                                    num7 = 5;
                                }
                            }
                            else
                            {
                                num7 = 4;
                            }
                        }
                        else
                        {
                            num7 = 3;
                        }
                        break;

                    case 4:
                        num7 = 2;
                        break;
                    }
                    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;
                PlantUtility.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, (float)(this.HashOffset() % 1024));
                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();
        }
예제 #10
0
 public override void TickLong()
 {
     this.CheckTemperatureMakeLeafless();
     if (base.Destroyed)
     {
         return;
     }
     if (PlantUtility.GrowthSeasonNow(base.Position, base.Map, false))
     {
         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.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  num2                       = Mathf.CeilToInt(this.CurrentDyingDamagePerTick * 2000f);
         base.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)num2, 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
         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.GetCustomLabelNoCount(false)
                 }).CapitalizeFirst(), new TargetInfo(base.Position, map, false), MessageTypeDefOf.NegativeEvent, true);
             }
             return;
         }
     }
     this.cachedLabelMouseover = null;
     if (this.def.plant.dropLeaves)
     {
         MoteLeaf moteLeaf = MoteMaker.MakeStaticMote(Vector3.zero, base.Map, ThingDefOf.Mote_Leaf, 1f) as MoteLeaf;
         if (moteLeaf != null)
         {
             float   num3       = this.def.plant.visualSizeRange.LerpThroughRange(this.growthInt);
             float   treeHeight = this.def.graphicData.drawSize.x * num3;
             Vector3 b          = Rand.InsideUnitCircleVec3 * Plant.LeafSpawnRadius;
             moteLeaf.Initialize(base.Position.ToVector3Shifted() + Vector3.up * Rand.Range(Plant.LeafSpawnYMin, Plant.LeafSpawnYMax) + b + Vector3.forward * this.def.graphicData.shadowData.offset.z, Rand.Value * 2000.TicksToSeconds(), b.z > 0f, treeHeight);
         }
     }
 }