Exemple #1
0
 public static Thing SpawnModded(Thing newThing, IntVec3 loc, Rot4 rot)
 {
     if (!loc.InBounds())
     {
         Log.Error(string.Concat(new object[]
         {
             "Tried to spawn ",
             newThing,
             " out of bounds at ",
             loc,
             "."
         }));
         return(null);
     }
     GenSpawn.WipeExistingThings(loc, rot, newThing.def, false);
     if (newThing.def.randomizeRotationOnSpawn)
     {
         newThing.Rotation = Rot4.Random;
     }
     else
     {
         newThing.Rotation = rot;
     }
     newThing.SetPositionDirect(IntVec3.Invalid);
     newThing.Position = loc;
     newThing.SpawnSetup();
     if (newThing.stackCount == 0)
     {
         Log.Error("Spawned thing with 0 stackCount: " + newThing);
         newThing.Destroy(DestroyMode.Vanish);
         return(null);
     }
     if (newThing.def.GetType() != typeof(Thingdef_AlienRace))
     {
         return(newThing);
     }
     else
     {
         AlienPawn alienpawn2 = newThing as AlienPawn;
         alienpawn2.SpawnSetupAlien(alienpawn2);
         if (alienpawn2.TryGetComp <CompImmuneToAge>() != null)
         {
             alienpawn2.health.hediffSet.Clear();
             PawnTechHediffsGenerator.GeneratePartsAndImplantsFor(alienpawn2);
         }
         Log.Message(alienpawn2.kindDef.race.ToString());
         return(alienpawn2);
     }
 }
Exemple #2
0
        public static Thing SpawnModded(Thing newThing, IntVec3 loc, Map map, Rot4 rot)
        {
            bool  flag = map == null;
            Thing result;

            if (flag)
            {
                Log.Error("Tried to spawn " + newThing + " in a null map.");
                result = null;
            }
            else
            {
                bool flag2 = !loc.InBounds(map);
                if (flag2)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Tried to spawn ",
                        newThing,
                        " out of bounds at ",
                        loc,
                        "."
                    }));
                    result = null;
                }
                else
                {
                    bool spawned = newThing.Spawned;
                    if (spawned)
                    {
                        Log.Error("Tried to spawn " + newThing + " but it's already spawned.");
                        result = newThing;
                    }
                    else
                    {
                        GenSpawn.WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish);
                        bool randomizeRotationOnSpawn = newThing.def.randomizeRotationOnSpawn;
                        if (randomizeRotationOnSpawn)
                        {
                            newThing.Rotation = Rot4.Random;
                        }
                        else
                        {
                            newThing.Rotation = rot;
                        }
                        newThing.Position = loc;
                        ThingUtility.UpdateRegionListers(IntVec3.Invalid, loc, map, newThing);
                        map.thingGrid.Register(newThing);
                        newThing.SpawnSetup(map);
                        bool spawned2 = newThing.Spawned;
                        if (spawned2)
                        {
                            bool flag3 = newThing.stackCount == 0;
                            if (flag3)
                            {
                                Log.Error("Spawned thing with 0 stackCount: " + newThing);
                                newThing.Destroy(DestroyMode.Vanish);
                                result = null;
                                return(result);
                            }
                        }
                        else
                        {
                            ThingUtility.UpdateRegionListers(loc, IntVec3.Invalid, map, newThing);
                            map.thingGrid.Deregister(newThing, true);
                        }
                        bool flag4 = newThing.def.GetType() != typeof(Thingdef_AlienRace);
                        if (flag4)
                        {
                            result = newThing;
                        }
                        else
                        {
                            AlienPawn alienPawn = newThing as AlienPawn;
                            alienPawn.SpawnSetupAlien();
                            result = alienPawn;
                        }
                    }
                }
            }
            return(result);
        }