public static SymbolsImage GetCellImage(IAreaMapCell cell) { if (cell == null) { return(EmptyImage); } var objectsImages = cell.Objects .Where(obj => obj.IsVisible) .OrderBy(obj => obj.ZIndex) .Select(GetObjectImage) .Where(img => img != null) .ToArray(); var image = objectsImages.FirstOrDefault(); if (image == null) { return(EmptyImage); } foreach (var objectImage in objectsImages.Skip(1)) { image = CombineImages(image, objectImage); } image = LightLevelManager.ApplyLightLevel(image, cell.LightLevel); return(ApplyObjectEffects(cell, image)); }
public bool CheckRequirements(IAreaMapCell cell) { if (requirements.Count == 0) { return(true); } return(requirements.All(requirement => requirement(cell))); }
private void ApplyOilyStatus(IAreaMapCell cell) { var destroyableObjects = cell.Objects.OfType <IDestroyableObject>(); foreach (var destroyable in destroyableObjects) { destroyable.Statuses.Add(new OilyObjectStatus()); } }
private void DrawMagicEnergy(int x, int y, IAreaMapCell cell) { if (cell == null) { return; } Surface.Print(x, y, new ColoredString(cell.MagicEnergyLevel().ToString(), Color.Blue, Color.Black)); Surface.Print(x, y + 1, new ColoredString(cell.MagicDisturbanceLevel().ToString(), Color.Blue, Color.Black)); }
private void DrawCell(int mapX, int mapY, IAreaMapCell cell) { var image = CellImageHelper.GetCellImage(cell); var realX = mapX * Program.MapCellImageSize; var realY = mapY * Program.MapCellImageSize; Surface.DrawImage(realX, realY, image, DefaultForegroundColor, DefaultBackgroundColor); DrawDebugData(realX, realY, cell); }
private void DrawTemperature(int x, int y, IAreaMapCell cell) { if (cell == null) { return; } var value = cell.Temperature() / 10; Surface.Print(x, y, new ColoredString(value.ToString(), Color.Red, Color.Black)); }
private void DrawLightLevel(int x, int y, IAreaMapCell cell) { if (cell == null) { return; } var value = (int)cell.LightLevel; Surface.Print(x, y, new ColoredString(value.ToString(), Color.Yellow, Color.Black)); }
private void ProcessFreezing(Point position, IAreaMapCell cell) { var missingTemperature = Configuration.FreezingPoint - cell.Temperature(); var volumeToRaiseTemp = (int)Math.Floor(missingTemperature * Configuration.FreezingTemperatureMultiplier); var volumeToFreeze = Math.Min(volumeToRaiseTemp, Volume); var heatGain = (int)Math.Floor(volumeToFreeze / Configuration.FreezingTemperatureMultiplier); cell.Environment.Cast().Temperature += heatGain; Volume -= volumeToFreeze; CurrentGame.Map.AddObject(position, CreateIce(volumeToFreeze)); }
private void ProcessBurning(IAreaMapCell cell) { if (cell.Temperature() < BurningTemperature) { var temperatureDiff = BurningTemperature - cell.Temperature(); var temperatureChange = Math.Min(temperatureDiff, heatSpeed); cell.Environment.Cast().Temperature += temperatureChange; } var burnedVolume = (int)Math.Ceiling(cell.Temperature() * burningRate); Volume -= burnedVolume; }
private void ApplyShockToCell(int value, IAreaMapCell cell, Point position) { var heat = value * heatMultiplier; cell.Environment.Cast().Temperature += heat; var destroyableObjects = cell.Objects.OfType <IDestroyableObject>(); foreach (var destroyable in destroyableObjects) { destroyable.Damage(position, value, Element.Electricity); CurrentGame.Journal.Write(new EnvironmentDamageMessage(destroyable, value, Element.Electricity), destroyable); } }
private void DrawDebugData(int realX, int realY, IAreaMapCell cell) { if (Settings.Current.DebugDrawTemperature) { DrawTemperature(realX, realY, cell); } if (Settings.Current.DebugDrawLightLevel) { DrawLightLevel(realX, realY + 1, cell); } if (Settings.Current.DebugDrawMagicEnergy) { DrawMagicEnergy(realX, realY + 1, cell); } }
private void ProcessBoiling(Point position, IAreaMapCell cell) { var excessTemperature = cell.Temperature() - Configuration.BoilingPoint; var volumeToLowerTemp = (int)Math.Floor(excessTemperature * Configuration.EvaporationTemperatureMultiplier); var volumeToBecomeSteam = Math.Min(volumeToLowerTemp, Volume); var heatLoss = (int)Math.Floor(volumeToBecomeSteam * Configuration.EvaporationTemperatureMultiplier); cell.Environment.Cast().Temperature -= heatLoss; Volume -= volumeToBecomeSteam; var steamVolume = volumeToBecomeSteam * Configuration.EvaporationMultiplier; cell.Environment.Cast().Pressure += steamVolume * Configuration.Steam.PressureMultiplier; CurrentGame.Map.AddObject(position, CreateSteam(steamVolume)); }
public IAreaMapCell[][] GetMapPart(Point position, int radius) { var startIndexX = position.X - radius; var startIndexY = position.Y - radius; var visionDiameter = radius * 2 + 1; var result = new IAreaMapCell[visionDiameter][]; for (var y = 0; y < visionDiameter; y++) { result[y] = new IAreaMapCell[visionDiameter]; for (var x = 0; x < visionDiameter; x++) { result[y][x] = TryGetCell(startIndexX + x, startIndexY + y); } } return(result); }
public AreaMapFragment GetVisibleArea() { if (cachedVisibleArea != null) { return(cachedVisibleArea); } var visibleArea = VisibilityHelper.GetVisibleArea(Player.VisibilityRange, PlayerPosition); if (visibleArea == null) { return(null); } if (Player.VisibilityRange == Player.MaxVisibilityRange) { return(visibleArea); } var visibilityDifference = Player.MaxVisibilityRange - Player.VisibilityRange; var visibleAreaDiameter = Player.MaxVisibilityRange * 2 + 1; var result = new IAreaMapCell[visibleAreaDiameter][]; for (int y = 0; y < visibleAreaDiameter; y++) { result[y] = new IAreaMapCell[visibleAreaDiameter]; } for (int y = 0; y < visibleArea.Height; y++) { for (int x = 0; x < visibleArea.Width; x++) { var visibleAreaY = y + visibilityDifference; var visibleAreaX = x + visibilityDifference; result[visibleAreaY][visibleAreaX] = visibleArea.GetCell(x, y); } } cachedVisibleArea = new AreaMapFragment(result, visibleAreaDiameter, visibleAreaDiameter); return(cachedVisibleArea); }
private static void UpdateCellLightLevel(IAreaMap map, IAreaMapCell cell, Point position) { var lights = cell.Objects.OfType <ILightObject>() .SelectMany(lightObject => lightObject.LightSources) .Where(source => source.IsLightOn && source.LightPower > LightLevel.Darkness) .ToArray(); if (lights.Length == 0) { return; } var maxLightPower = lights.Max(light => light.LightPower); cell.LightLevel = (LightLevel)Math.Max((int)cell.LightLevel, (int)maxLightPower); SpreadLightLevel(map, Point.GetPointInDirection(position, Direction.North), maxLightPower); SpreadLightLevel(map, Point.GetPointInDirection(position, Direction.South), maxLightPower); SpreadLightLevel(map, Point.GetPointInDirection(position, Direction.West), maxLightPower); SpreadLightLevel(map, Point.GetPointInDirection(position, Direction.East), maxLightPower); }
private static SymbolsImage ApplyObjectEffects(IAreaMapCell cell, SymbolsImage image) { var bigObject = cell.Objects.OfType <IDestroyableObject>().FirstOrDefault(obj => obj.BlocksMovement); if (bigObject == null || !bigObject.ObjectEffects.Any()) { return(image); } var latestEffect = bigObject.ObjectEffects .OfType <ObjectEffect>() .Where(rec => rec.CreatedAt + DamageMarksLifeTime > DateTime.Now) .OrderByDescending(obj => obj.CreatedAt) .FirstOrDefault(); if (latestEffect == null) { return(image); } var effectImage = latestEffect.GetEffectImage(image.Width, image.Height, ImagesStorage.Current); return(SymbolsImage.Combine(image, effectImage)); }
public static int MaxMagicEnergyLevel(this IAreaMapCell cell) { return(cell.Environment.MaxMagicEnergyLevel()); }
public static int MagicDisturbanceLevel(this IAreaMapCell cell) { return(cell.Environment.MagicDisturbanceLevel()); }
public static int Pressure(this IAreaMapCell cell) { return(cell.Environment.Pressure()); }
public static int Temperature(this IAreaMapCell cell) { return(cell.Environment.Temperature()); }
public bool CheckRequirements(int x, int y, IAreaMapCell cell) { return(pattern[y][x].CheckRequirements(cell)); }
private IDestroyableObject GetTarget(IAreaMapCell cell) { return(cell.Objects.OfType <IDestroyableObject>().FirstOrDefault(targetStrategy.IsTarget)); }
private static bool RequirementIsAny(IAreaMapCell cell) { return(true); }
private static bool RequirementIsEmpty(IAreaMapCell cell) { return(cell.Objects.All(obj => obj is FloorObject)); }
private static bool RequirementNotBlocking(IAreaMapCell cell) { return(!cell.BlocksMovement); }
private static bool RequirementIsWall(IAreaMapCell cell) { return(cell.BlocksEnvironment && !cell.Objects.OfType <DoorBase>().Any()); }
private bool GetIfCellContainsWet(IAreaMapCell cell) { return(cell.Objects.OfType <IDestroyableObject>() .Any(obj => obj.Statuses.Contains(WetObjectStatus.StatusType))); }
private bool GetIfCellConductsElectricity(IAreaMapCell cell) { return(GetIfCellContainsWater(cell) || GetIfCellContainsWet(cell)); }
private bool GetIfCellContainsWater(IAreaMapCell cell) { return(cell.Objects.OfType <WaterLiquid>().Any()); }