public static void DamageToPlantOnArea(this IZone zone, Area area, double damage) { var w = area.Width / 2; var h = area.Height / 2; var maxd = w * w + h * h; var cx = area.Center.X; var cy = area.Center.Y; for (var y = area.Y1; y <= area.Y2; y++) { for (var x = area.X1; x <= area.X2; x++) { var dx = cx - x; var dy = cy - y; var d = dx * dx + dy * dy; var m = 1.0 - ((double)d / maxd); var dmg = damage * m; zone.DamageToPlant(x, y, dmg); } } }
/// <summary> /// /// Heart of terraforming. /// /// checks terrain conditions for the terraforming operation /// simply ignores invalid tiles /// damages plants if there are any on the area /// /// all good => modify terrain /// /// </summary> /// <param name="zone"></param> /// <param name="terrain"></param> /// <param name="tileAction"></param> protected void ProcessAreaHelper(IZone zone, Action <int, int> tileAction) { zone.ForEachAreaInclusive(TerraformArea, (x, y) => { var controlInfo = zone.Terrain.Controls.GetValue(x, y); if (controlInfo.IsAnyTerraformProtected) { return; } var blockingInfo = zone.Terrain.Blocks.GetValue(x, y); if (blockingInfo.NonNaturally) { return; } var plantInfo = zone.Terrain.Plants.GetValue(x, y); if (plantInfo.type != PlantType.NotDefined) { //do plant damage zone.DamageToPlant(x, y, _plantDamage); return; } tileAction(x, y); }); }
public static void DamageToPlantOnArea(this IZone zone, DamageInfo damageInfo) { var area = Area.FromRadius(damageInfo.sourcePosition, (int)damageInfo.Range); var damage = damageInfo.damages.Sum(d => d.value); var rangeFar = (int)damageInfo.Range; double originX = damageInfo.sourcePosition.intX; double originY = damageInfo.sourcePosition.intY; for (var y = area.Y1; y <= area.Y2; y++) { for (var x = area.X1; x <= area.X2; x++) { var mult = MathHelper.DistanceFalloff(0, rangeFar, originX, originY, x, y); var finalDamage = mult * damage; if (finalDamage > 0) { zone.DamageToPlant(x, y, finalDamage); } } } }