ChannelDigger.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using OpenSim.Region.Environment.Interfaces;
  3. using OpenSim.Region.Environment.Modules.World.Terrain;
  4. using OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes;
  5. namespace OpenSim.Region.Modules.Terrain.Extensions.DefaultEffects.Effects
  6. {
  7. public class ChannelDigger : ITerrainEffect
  8. {
  9. private readonly int num_h = 4;
  10. private readonly int num_w = 4;
  11. private readonly ITerrainFloodEffect raiseFunction = new RaiseArea();
  12. private readonly ITerrainFloodEffect smoothFunction = new SmoothArea();
  13. #region ITerrainEffect Members
  14. public void RunEffect(ITerrainChannel map)
  15. {
  16. FillMap(map, 15);
  17. BuildTiles(map, 7);
  18. SmoothMap(map, 3);
  19. }
  20. #endregion
  21. private void SmoothMap(ITerrainChannel map, int rounds)
  22. {
  23. Boolean[,] bitmap = new bool[map.Width,map.Height];
  24. for (int x = 0; x < map.Width; x++)
  25. {
  26. for (int y = 0; y < map.Height; y++)
  27. {
  28. bitmap[x, y] = true;
  29. }
  30. }
  31. for (int i = 0; i < rounds; i++)
  32. {
  33. smoothFunction.FloodEffect(map, bitmap, 1.0);
  34. }
  35. }
  36. private void FillMap(ITerrainChannel map, double val)
  37. {
  38. for (int x = 0; x < map.Width; x++)
  39. for (int y = 0; y < map.Height; y++)
  40. map[x, y] = val;
  41. }
  42. private void BuildTiles(ITerrainChannel map, double height)
  43. {
  44. int channelWidth = (int) Math.Floor((map.Width / num_w) * 0.8);
  45. int channelHeight = (int) Math.Floor((map.Height / num_h) * 0.8);
  46. int channelXOffset = (map.Width / num_w) - channelWidth;
  47. int channelYOffset = (map.Height / num_h) - channelHeight;
  48. for (int x = 0; x < num_w; x++)
  49. {
  50. for (int y = 0; y < num_h; y++)
  51. {
  52. int xoff = ((channelXOffset + channelWidth) * x) + (channelXOffset / 2);
  53. int yoff = ((channelYOffset + channelHeight) * y) + (channelYOffset / 2);
  54. Boolean[,] bitmap = new bool[map.Width,map.Height];
  55. for (int dx = 0; dx < channelWidth; dx++)
  56. {
  57. for (int dy = 0; dy < channelHeight; dy++)
  58. {
  59. bitmap[dx + xoff, dy + yoff] = true;
  60. }
  61. }
  62. raiseFunction.FloodEffect(map, bitmap, height);
  63. }
  64. }
  65. }
  66. }
  67. }