public override void Update(GraphicsDevice device, WorldState world)
{
if (HideForCutaway && Level > 0)
{
if (!world.BuildMode && world.DynamicCutaway && Level == world.Level)
{
if (blueprint != null && renderInfo.Layer == WorldObjectRenderLayer.STATIC) blueprint.Damage.Add(new BlueprintDamage(BlueprintDamageType.OBJECT_GRAPHIC_CHANGE, TileX, TileY, Level, this));
DynamicCounter = 0; //keep windows and doors on the top floor on the dynamic layer.
}
if (Level != world.Level || world.BuildMode) CutawayHidden = false;
else
{
var tilePos = new Point((int)Math.Round(Position.X), (int)Math.Round(Position.Y));
if (tilePos.X >= 0 && tilePos.X < blueprint.Width && tilePos.Y >= 0 && tilePos.Y < blueprint.Height)
{
var wall = blueprint.Walls[Level - 1][tilePos.Y * blueprint.Width + tilePos.X];
var cutTest = new Point();
if (!CutawayTests.TryGetValue(AdjacentWall & wall.Segments, out cutTest))
{
CutawayTests.TryGetValue(wall.OccupiedWalls & wall.Segments, out cutTest);
}
var positions = new Point[] { tilePos, tilePos + cutTest };
var canContinue = true;
foreach (var pos in positions)
{
canContinue = canContinue && (pos.X >= 0 && pos.X < blueprint.Width && pos.Y >= 0 && pos.Y < blueprint.Height
&& blueprint.Cutaway[pos.Y * blueprint.Width + pos.X]);
if (!canContinue) break;
}
CutawayHidden = canContinue;
}
}
}
bool forceDynamic = ForceDynamic;
if (Container != null && Container is ObjectComponent)
{
forceDynamic = ((ObjectComponent)Container).ForceDynamic;
if (forceDynamic && renderInfo.Layer == WorldObjectRenderLayer.STATIC) blueprint.Damage.Add(new BlueprintDamage(BlueprintDamageType.OBJECT_GRAPHIC_CHANGE, TileX, TileY, Level, this));
}
if (renderInfo.Layer == WorldObjectRenderLayer.DYNAMIC && !forceDynamic && DynamicCounter++ > 120 && blueprint != null)
{
blueprint.Damage.Add(new BlueprintDamage(BlueprintDamageType.OBJECT_RETURN_TO_STATIC, TileX, TileY, Level, this));
}
}