Example #1
0
        public bool AnyThingOutOfBounds(Map map, IntVec3 pos, SpawnPosType posType = SpawnPosType.Unchanged)
        {
            IntVec3 offset = GetOffset(pos, posType);

            for (int i = 0; i < entities.Count; i++)
            {
                SketchThing sketchThing = entities[i] as SketchThing;
                if (sketchThing == null)
                {
                    continue;
                }
                if (sketchThing.def.size == IntVec2.One)
                {
                    if (!(entities[i].pos + offset).InBounds(map))
                    {
                        return(true);
                    }
                }
                else
                {
                    foreach (IntVec3 item in sketchThing.OccupiedRect)
                    {
                        if (!(item + offset).InBounds(map))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Example #2
0
        public bool CanBeSeenOver(IntVec3 c)
        {
            SketchThing sketchThing = EdificeAt(c);

            if (sketchThing != null)
            {
                return(sketchThing.def.Fillage != FillCategory.Full);
            }
            return(true);
        }
Example #3
0
        public override SketchEntity DeepCopy()
        {
            SketchThing obj = (SketchThing)base.DeepCopy();

            obj.def        = def;
            obj.stuff      = stuff;
            obj.stackCount = stackCount;
            obj.rot        = rot;
            obj.quality    = quality;
            obj.hitPoints  = hitPoints;
            return(obj);
        }
Example #4
0
        private void AddToCache(SketchEntity entity)
        {
            occupiedRectDirty = true;
            SketchBuildable sketchBuildable = entity as SketchBuildable;

            if (sketchBuildable != null)
            {
                cachedBuildables.Add(sketchBuildable);
            }
            SketchThing sketchThing = entity as SketchThing;

            if (sketchThing != null)
            {
                if (sketchThing.def.building != null && sketchThing.def.building.isEdifice)
                {
                    foreach (IntVec3 item in sketchThing.OccupiedRect)
                    {
                        edificeAt[item] = sketchThing;
                    }
                }
                foreach (IntVec3 item2 in sketchThing.OccupiedRect)
                {
                    SketchThing value2;
                    if (thingsAt_multiple.TryGetValue(item2, out List <SketchThing> value))
                    {
                        value.Add(sketchThing);
                    }
                    else if (thingsAt_single.TryGetValue(item2, out value2))
                    {
                        thingsAt_single.Remove(item2);
                        List <SketchThing> list = new List <SketchThing>();
                        list.Add(value2);
                        list.Add(sketchThing);
                        thingsAt_multiple.Add(item2, list);
                    }
                    else
                    {
                        thingsAt_single.Add(item2, sketchThing);
                    }
                }
                cachedThings.Add(sketchThing);
            }
            else
            {
                SketchTerrain sketchTerrain = entity as SketchTerrain;
                if (sketchTerrain != null)
                {
                    terrainAt[sketchTerrain.pos] = sketchTerrain;
                    cachedTerrain.Add(sketchTerrain);
                }
            }
        }
Example #5
0
        public bool AddThing(ThingDef def, IntVec3 pos, Rot4 rot, ThingDef stuff = null, int stackCount = 1, QualityCategory?quality = null, int?hitPoints = null, bool wipeIfCollides = true)
        {
            SketchThing sketchThing = new SketchThing();

            sketchThing.def        = def;
            sketchThing.stuff      = stuff;
            sketchThing.pos        = pos;
            sketchThing.rot        = rot;
            sketchThing.stackCount = stackCount;
            sketchThing.quality    = quality;
            sketchThing.hitPoints  = hitPoints;
            return(Add(sketchThing, wipeIfCollides));
        }
Example #6
0
        private void RemoveFromCache(SketchEntity entity)
        {
            occupiedRectDirty = true;
            SketchBuildable sketchBuildable = entity as SketchBuildable;

            if (sketchBuildable != null)
            {
                cachedBuildables.Remove(sketchBuildable);
            }
            SketchThing sketchThing = entity as SketchThing;

            if (sketchThing != null)
            {
                if (sketchThing.def.building != null && sketchThing.def.building.isEdifice)
                {
                    foreach (IntVec3 item in sketchThing.OccupiedRect)
                    {
                        if (edificeAt.TryGetValue(item, out SketchThing value) && value == sketchThing)
                        {
                            edificeAt.Remove(item);
                        }
                    }
                }
                foreach (IntVec3 item2 in sketchThing.OccupiedRect)
                {
                    SketchThing value3;
                    if (thingsAt_multiple.TryGetValue(item2, out List <SketchThing> value2))
                    {
                        value2.Remove(sketchThing);
                    }
                    else if (thingsAt_single.TryGetValue(item2, out value3) && value3 == sketchThing)
                    {
                        thingsAt_single.Remove(item2);
                    }
                }
                cachedThings.Remove(sketchThing);
                return;
            }
            SketchTerrain sketchTerrain = entity as SketchTerrain;

            if (sketchTerrain != null)
            {
                if (terrainAt.TryGetValue(sketchTerrain.pos, out SketchTerrain value4) && value4 == sketchTerrain)
                {
                    terrainAt.Remove(sketchTerrain.pos);
                }
                cachedTerrain.Remove(sketchTerrain);
            }
        }
Example #7
0
        public override bool SameForSubtracting(SketchEntity other)
        {
            SketchThing sketchThing = other as SketchThing;

            if (sketchThing == null)
            {
                return(false);
            }
            if (sketchThing == this)
            {
                return(true);
            }
            if (def == sketchThing.def && stuff == sketchThing.stuff && stackCount == sketchThing.stackCount && pos == sketchThing.pos && rot == sketchThing.rot && quality == sketchThing.quality)
            {
                return(hitPoints == sketchThing.hitPoints);
            }
            return(false);
        }
Example #8
0
        public void WipeColliding(SketchEntity entity)
        {
            if (!WouldCollide(entity))
            {
                return;
            }
            SketchThing sketchThing = entity as SketchThing;

            if (sketchThing != null)
            {
                WipeColliding(sketchThing.def, sketchThing.pos, sketchThing.rot);
                return;
            }
            SketchTerrain sketchTerrain = entity as SketchTerrain;

            if (sketchTerrain != null)
            {
                WipeColliding(sketchTerrain.def, sketchTerrain.pos);
            }
        }
Example #9
0
        public bool WouldCollide(SketchEntity entity)
        {
            if (entities.Contains(entity))
            {
                return(false);
            }
            SketchThing sketchThing = entity as SketchThing;

            if (sketchThing != null)
            {
                return(WouldCollide(sketchThing.def, sketchThing.pos, sketchThing.rot));
            }
            SketchTerrain sketchTerrain = entity as SketchTerrain;

            if (sketchTerrain != null)
            {
                return(WouldCollide(sketchTerrain.def, sketchTerrain.pos));
            }
            return(false);
        }
Example #10
0
        public void ThingsAt(IntVec3 pos, out SketchThing singleResult, out List <SketchThing> multipleResults)
        {
            List <SketchThing> value2;

            if (thingsAt_single.TryGetValue(pos, out SketchThing value))
            {
                singleResult    = value;
                multipleResults = null;
            }
            else if (thingsAt_multiple.TryGetValue(pos, out value2))
            {
                singleResult    = null;
                multipleResults = value2;
            }
            else
            {
                singleResult    = null;
                multipleResults = null;
            }
        }
Example #11
0
        public bool AllowsPlacingBlueprint(BuildableDef buildable, IntVec3 pos, Rot4 rot, ThingDef stuff)
        {
            Rot4 rot2 = rot;

            if (!base.Spawned)
            {
                return(true);
            }
            CellRect newRect = GenAdj.OccupiedRect(pos, rot2, buildable.Size);

            if (!sketch.OccupiedRect.MovedBy(base.Position).Overlaps(newRect))
            {
                return(true);
            }
            bool collided = false;

            foreach (IntVec3 item in newRect)
            {
                sketch.ThingsAt(item - base.Position, out SketchThing singleResult, out List <SketchThing> multipleResults);
                if (singleResult != null && CheckEntity(singleResult))
                {
                    return(true);
                }
                if (multipleResults != null)
                {
                    for (int i = 0; i < multipleResults.Count; i++)
                    {
                        if (CheckEntity(multipleResults[i]))
                        {
                            return(true);
                        }
                    }
                }
                SketchTerrain sketchTerrain = sketch.SketchTerrainAt(item - base.Position);
                if (sketchTerrain != null && CheckEntity(sketchTerrain))
                {
                    return(true);
                }
            }
            return(!collided);

            bool CheckEntity(SketchBuildable entity)
            {
                if (entity.IsSameSpawned(entity.pos + base.Position, base.Map))
                {
                    return(false);
                }
                if (entity.OccupiedRect.MovedBy(base.Position).Overlaps(newRect))
                {
                    collided = true;
                }
                SketchThing sketchThing = entity as SketchThing;

                if (entity.OccupiedRect.MovedBy(base.Position).Equals(newRect) && IsSameOrSimilar(entity) && (stuff == null || entity.Stuff == null || stuff == entity.Stuff))
                {
                    if (sketchThing != null && !(sketchThing.rot == rot2) && !(sketchThing.rot == rot2.Opposite))
                    {
                        return(!sketchThing.def.rotatable);
                    }
                    return(true);
                }
                return(false);
            }

            bool IsSameOrSimilar(SketchBuildable entity)
            {
                SketchTerrain sketchTerrain2;

                if (buildable == entity.Buildable || ((sketchTerrain2 = (entity as SketchTerrain)) != null && sketchTerrain2.IsSameOrSimilar(buildable)))
                {
                    return(true);
                }
                return(false);
            }
        }