public override SketchEntity DeepCopy() { SketchTerrain obj = (SketchTerrain)base.DeepCopy(); obj.def = def; obj.stuffForComparingSimilar = stuffForComparingSimilar; return(obj); }
public bool AddTerrain(TerrainDef def, IntVec3 pos, bool wipeIfCollides = true) { SketchTerrain sketchTerrain = new SketchTerrain(); sketchTerrain.def = def; sketchTerrain.pos = pos; return(Add(sketchTerrain, wipeIfCollides)); }
public bool IsPart(Thing thing) { if (!base.Spawned) { return(false); } if (!sketch.OccupiedRect.MovedBy(base.Position).Contains(thing.Position)) { return(false); } sketch.ThingsAt(thing.Position - base.Position, out SketchThing singleResult, out List <SketchThing> multipleResults); if (singleResult != null && IsPartInternal(singleResult)) { return(true); } if (multipleResults != null) { for (int i = 0; i < multipleResults.Count; i++) { if (IsPartInternal(multipleResults[i])) { return(true); } } } if (thing.def.entityDefToBuild != null) { SketchTerrain sketchTerrain = sketch.SketchTerrainAt(thing.Position - base.Position); if (sketchTerrain != null && IsPartInternal(sketchTerrain)) { return(true); } } return(false); bool IsPartInternal(SketchBuildable b) { BuildableDef buildable = b.Buildable; if (thing.def != buildable && thing.def.entityDefToBuild != buildable) { return(false); } if (b.GetSpawnedBlueprintOrFrame(b.pos + base.Position, base.Map) == thing) { return(true); } SketchThing sketchThing; if ((sketchThing = (b as SketchThing)) != null && sketchThing.GetSameSpawned(sketchThing.pos + base.Position, base.Map) == thing) { return(true); } return(false); } }
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); } } }
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 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); }
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); } }