public virtual SketchEntity DeepCopy() { SketchEntity obj = (SketchEntity)Activator.CreateInstance(GetType()); obj.pos = pos; return(obj); }
private void PlaceBlueprint(SketchEntity entity, ThingDef preferredStuffIfNone) { SketchBuildable sketchBuildable; if ((sketchBuildable = entity as SketchBuildable) != null && !entity.IsSameSpawnedOrBlueprintOrFrame(entity.pos + base.Position, base.Map) && !entity.IsSpawningBlocked(entity.pos + base.Position, base.Map) && BuildCopyCommandUtility.FindAllowedDesignator(sketchBuildable.Buildable) != null) { SketchThing sketchThing; SketchTerrain sketchTerrain; if ((sketchThing = entity as SketchThing) != null && sketchThing.def.MadeFromStuff && sketchThing.stuff == null && preferredStuffIfNone != null && preferredStuffIfNone.stuffProps.CanMake(sketchThing.def)) { sketchThing.stuff = preferredStuffIfNone; entity.Spawn(entity.pos + base.Position, base.Map, Faction.OfPlayer, Sketch.SpawnMode.Blueprint); sketchThing.stuff = null; } else if ((sketchTerrain = entity as SketchTerrain) != null && sketchTerrain.stuffForComparingSimilar == null && preferredStuffIfNone != null) { sketchTerrain.stuffForComparingSimilar = preferredStuffIfNone; entity.Spawn(entity.pos + base.Position, base.Map, Faction.OfPlayer, Sketch.SpawnMode.Blueprint); sketchTerrain.stuffForComparingSimilar = null; } else { entity.Spawn(entity.pos + base.Position, base.Map, Faction.OfPlayer, Sketch.SpawnMode.Blueprint); } } }
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); } } }
public bool Remove(SketchEntity entity) { if (entity == null) { return(false); } if (!entities.Contains(entity)) { return(false); } entities.Remove(entity); RemoveFromCache(entity); return(true); }
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); } }
public override bool SameForSubtracting(SketchEntity other) { SketchTerrain sketchTerrain = other as SketchTerrain; if (sketchTerrain == null) { return(false); } if (sketchTerrain == this) { return(true); } if (IsSameOrSimilar(sketchTerrain.Buildable)) { return(pos == sketchTerrain.pos); } return(false); }
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); }
public static Building GetFirstAdjacentBuilding(SketchEntity entity, IntVec3 offset, List <Thing> monumentThings, Map map) { if (entity.IsSameSpawnedOrBlueprintOrFrame(entity.pos + offset, map)) { return(null); } foreach (IntVec3 edgeCell in entity.OccupiedRect.MovedBy(offset).ExpandedBy(1).EdgeCells) { if (edgeCell.InBounds(map)) { Building firstBuilding = edgeCell.GetFirstBuilding(map); if (firstBuilding != null && !monumentThings.Contains(firstBuilding) && (firstBuilding.Faction == null || firstBuilding.Faction == Faction.OfPlayer)) { return(firstBuilding); } } } return(null); }
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); } }
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); }
public bool Add(SketchEntity entity, bool wipeIfCollides = true) { if (entity == null) { throw new ArgumentNullException("entity"); } if (entities.Contains(entity)) { return(true); } if (wipeIfCollides) { WipeColliding(entity); } else if (WouldCollide(entity)) { return(false); } SketchTerrain sketchTerrain = entity as SketchTerrain; if (sketchTerrain != null && terrainAt.TryGetValue(sketchTerrain.pos, out SketchTerrain value)) { Remove(value); } SketchBuildable sketchBuildable = entity as SketchBuildable; if (sketchBuildable != null) { for (int num = cachedBuildables.Count - 1; num >= 0; num--) { if (sketchBuildable.OccupiedRect.Overlaps(cachedBuildables[num].OccupiedRect) && GenSpawn.SpawningWipes(sketchBuildable.Buildable, cachedBuildables[num].Buildable)) { Remove(cachedBuildables[num]); } } } entities.Add(entity); AddToCache(entity); return(true); }
private void Recache(SketchEntity entity) { RemoveFromCache(entity); AddToCache(entity); }
public abstract bool SameForSubtracting(SketchEntity other);