local hit_effects = require ("__base__.prototypes.entity.hit-effects")
local base_tile_sounds = require ("__base__.prototypes.tile.tile-sounds")
local space_age_tile_sounds = require ("__space-age__.prototypes.tile.tile-sounds")
local decorative_trigger_effects = require("__base__.prototypes.decorative.decorative-trigger-effects")

--lithium
local lithium_rock_tint = {1, 1, 1}
local lithium_rock_rectange = nil --{{0, 0}, {1, 1}}
local lithium_rock_map_colour = {168, 188, 211}

 -- collides with shallow water. Only use for things that would obscure the shore too much.
local function dec_shallow_collision()
  return {layers={doodad=true, water_tile=true}, colliding_with_tiles_only=true, not_colliding_with_itself=true}
end

local decal_tile_layer = 255
local decal_opacity_over_water = 0.4
local water_decal_opacity_over_water = 0.7

local function decorative_pictures(data)
  local file_path = data.file_path
  local count = data.count or 1
  local tint_as_overlay = data.tint_as_overlay or false
  local tint = data.tint or {1,1,1,1}
  local pictures = {}
  for i = 1, count do
    table.insert(pictures,
      util.sprite_load(file_path .. '-' .. string.format("%02i", i),
        {
          tint = tint,
          tint_as_overlay = tint_as_overlay,
          scale = 0.5
        }
      )
    )
  end
  return pictures
end

local function decorative_pictures_spritesheet(data)
  local sprite_data = require(data.path)
  local pictures = {}
  for i = 1, data.count or 1 do
    table.insert(pictures,
      util.sprite_load(data.path,
        {
          tint = data.tint,
          tint_as_overlay = data.tint_as_overlay,
          scale = data.scale or 0.5,
          x = (i-1) % sprite_data.line_length * sprite_data.width,
          y = math.floor((i-1) / sprite_data.line_length) * sprite_data.height
        }
      )
    )
  end
  return pictures
end

data:extend{

  ---ROCKY DECALS
  {
    name = "aqulio-ice-decal-blue-vesta",
    type = "optimized-decorative",
    order = "a[vulcanus]-b[decorative]-b[sand]",
    collision_box = {{-1.5, -1.5}, {1.5, 1.5}},
    collision_mask = {layers={water_tile=true, doodad=true}, colliding_with_tiles_only=true},
    render_layer = "decals",
    tile_layer = 220,
    autoplace = {
      order = "d[decal]-a",
      probability_expression = "min(1, random_penalty{x = x, y = y, seed = 1, source = 1, amplitude = 1/0.1} + aquilo_high_frequency_peaks / 2 )",
      tile_restriction = {"snow-crests", "snow-lumpy", "snow-patchy"}
    },
    pictures = get_decal_pictures("__space-age__/graphics/decorative/vulcanus-rock-decal/vulcanus-rock-decal-", "large-", 256, 5)
  },
  {
    name = "aqulio-snowy-decal-vesta",
    type = "optimized-decorative",
    order = "a[vulcanus]-b[decorative]",
    collision_box = {{-5, -5}, {5, 5}},
    collision_mask = {layers={water_tile=true}, colliding_with_tiles_only=true},
    render_layer = "decals",
    tile_layer = 220,
    walking_sound = base_tile_sounds.walking.pebble,
    autoplace = {
      order = "d[decal]-b",
      probability_expression = "min(1, random_penalty{x = x, y = y, seed = 1, source = 1, amplitude = 1/0.1} + 0.3 -aquilo_high_frequency_peaks / 2)",
      tile_restriction = {"ice-smooth", "ice-rough"}
    },
    pictures = get_decal_pictures("__space-age__/graphics/decorative/vulcanus-relief-decal/vulcanus-pumice-relief-", "", 1024, 19)
  },
  {
    name = "snow-drift-decal-vesta",
    type = "optimized-decorative",
    order = "a[fulgora]-b[decorative]",
    collision_box = {{-5, -5}, {5, 5}},
    collision_mask = {layers={water_tile=true}, colliding_with_tiles_only=true},
    render_layer = "decals",
    tile_layer = 255,
    autoplace =
    {
      order = "d[decal]-c",
      probability_expression = "min(1, random_penalty{x = x, y = y, seed = 1, source = 1, amplitude = 1/0.1} + 0.3 -aquilo_high_frequency_peaks / 2)"
    },
    pictures = get_decal_pictures("__space-age__/graphics/decorative/vulcanus-dune-decal/vulcanus-dune-decal-", "", 512, 20)
  },
--Vesta rocks
  {
    name = "vesta_rock_huge",
    type = "simple-entity",
    order = "a[aquilo]-b[decorative]",
    icon = "__space-age__/graphics/icons/huge-volcanic-rock.png",
--	collision_box = {{-2, -2}, {2, 2}},
    collision_box = {{-1.85, -1.25}, {1.85, 1.25}},
    selection_box = {{-1.85, -1.25}, {1.85, 1.25}},
    drawing_box_vertical_extension = 2,
    damaged_trigger_effect = hit_effects.rock(),
    max_health = 1500,
    collision_mask = {layers={ground_tile=true}, colliding_with_tiles_only=true},
    render_layer = "object",
    dying_trigger_effect = decorative_trigger_effects.big_rock(),
    map_color = lithium_rock_map_colour,
    count_as_rock_for_filtered_deconstruction = true,
    impact_category = "stone",
    minable =
    {
      mining_particle = "iron-ore-particle",
      mining_time = 2,
      results =
      {
        {type = "item", name = "stone",  amount_min = 2, amount_max = 6},
        {type = "item", name = "algea_nutrient_clump", amount_min = 0, amount_max = 2},
        {type = "item", name = "calcized-iron-plate", amount_min = 3, amount_max = 15},
        {type = "item", name = "calcized-copper-plate", amount_min = 1, amount_max = 8},
      },
    },
	mined_sound = { filename = "__base__/sound/deconstruct-bricks.ogg" },
    resistances =
    {
      {
        type = "poison",
        percent = 100
      }
    },
    autoplace = {
      order = "a[rock]-a[huge]",
      probability_expression = "vesta_icebergs * 0.015",
    },
    pictures =
    {
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_rock_huge/vesta-huge-1.png",
        width = 640,
        height = 310,
        scale = 0.5,
        shift = {0.65,-0.75}
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_rock_huge/vesta-huge-2.png",
        width = 640,
        height = 310,
        scale = 0.5,
        shift = {1.15,-0.75}
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_rock_huge/vesta-huge-3.png",
        width = 640,
        height = 310,
        scale = 0.5,
        shift = {0.95,-0.25}
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_rock_huge/vesta-huge-4.png",
        width = 640,
        height = 310,
        scale = 0.5,
        shift = {0.65,-0.75}
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_rock_huge/vesta-huge-5.png",
        width = 640,
        height = 310,
        scale = 0.5,
        shift = {0.65,-0.75}
      },
    }
  },
-- Petrite Rocks
  {
    name = "vesta-petrite",
    type = "simple-entity",
    flags = {"placeable-neutral", "placeable-off-grid"},
    icon = "__skewer_planet_vesta_assets_2__/graphics/icons/petrite.png",
    subgroup = "grass",
    order = "b[decorative]-l[rock]-e[aquilo]-a[lithium-iceberg-big]",
    collision_mask =
    {
      layers=
      {
        item=true,
        object=true,
        player=true,
        water_tile=true
      },
    },
	mined_sound = { filename = "__base__/sound/deconstruct-bricks.ogg" },
    collision_box = {{-1.0, -0.75}, {1.0, 0.75}},
    selection_box = {{-1.0, -0.75}, {1.0, 0.75}},
    damaged_trigger_effect = hit_effects.rock(),
    render_layer = "object",
    max_health = 500,
    autoplace = {order = "a[rock]-a[huge]", probability_expression = "(aquilo_high_frequency_peaks - 0.8) * 0.1"},
    dying_trigger_effect = decorative_trigger_effects.big_rock(),
    minable =
    {
      mining_particle = "iron-ore-particle",
      mining_time = 1,
      results =
      {
        {type = "item", name = "ske_algea_clump_petrite",  amount_min = 2, amount_max = 6},
        {type = "item", name = "algea_nutrient_clump", amount_min = 0, amount_max = 1},
        {type = "item", name = "calcized-iron-plate", amount_min = 1, amount_max = 3},
        {type = "item", name = "calcized-copper-plate", amount_min = 1, amount_max = 3},
      },
    },
    resistances =
    {
      {
        type = "poison",
        percent = 100
      }
    },
    map_color = lithium_rock_map_colour,
    count_as_rock_for_filtered_deconstruction = true,
    mined_sound = sound_variations("__space-age__/sound/mining/mined-iceberg", 4, 0.7),
    mining_sound = sound_variations("__space-age__/sound/mining/axe-mining-iceberg", 7, 0.5),
    impact_category = "stone",
	
	
	
	
    pictures =
    {
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-01.png",
        width = 209,
        height = 138,
        shift = {0.304688, -0.4},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-02.png",
        width = 165,
        height = 129,
        shift = {0.0, 0.0390625},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-03.png",
        width = 151,
        height = 139,
        shift = {0.151562, 0.0},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-04.png",
        width = 216,
        height = 110,
        shift = {0.390625, 0.0},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-05.png",
        width = 154,
        height = 147,
        shift = {0.328125, 0.0703125},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-06.png",
        width = 154,
        height = 132,
        shift = {0.16875, -0.1},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-07.png",
        width = 193,
        height = 130,
        shift = {0.3, -0.2},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-08.png",
        width = 136,
        height = 117,
        shift = {0.0, 0.0},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-09.png",
        width = 157,
        height = 115,
        shift = {0.1, 0.0},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-10.png",
        width = 198,
        height = 153,
        shift = {0.325, -0.1},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-11.png",
        width = 190,
        height = 115,
        shift = {0.453125, 0.0},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-12.png",
        width = 229,
        height = 126,
        shift = {0.539062, -0.015625},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-13.png",
        width = 151,
        height = 125,
        shift = {0.0703125, 0.179688},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-14.png",
        width = 137,
        height = 117,
        shift = {0.160938, 0.0},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-15.png",
        width = 201,
        height = 141,
        shift = {0.242188, -0.195312},
        scale = 0.4
      },
      {
        filename = "__skewer_planet_vesta_assets_2__/graphics/decorative/vesta_petrite/stromatolite-16.png",
        width = 209,
        height = 154,
        shift = {0.351562, -0.1},
        scale = 0.4
      }
    },
    water_reflection =
      {
        pictures =
          {
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-01-effect-map.png",
              width = 96,
              height = 92,
              shift = {0.304688, -0.3},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-02-effect-map.png",
              width = 78,
              height = 92,
              shift = {0.0, 0.3},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-03-effect-map.png",
              width = 70,
              height = 91,
              shift = {0.151562, 0.1},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-04-effect-map.png",
              width = 88,
              height = 94,
              shift = {0.30625, 0.3},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-05-effect-map.png",
              width = 77,
              height = 92,
              shift = {0.328125, 0.0703125},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-06-effect-map.png",
              width = 77,
              height = 92,
              shift = {0.16875, 0.1},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-07-effect-map.png",
              width = 94,
              height = 93,
              shift = {0.3, 0.0},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-08-effect-map.png",
              width = 63,
              height = 93,
              shift = {0.0, 0.2},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-09-effect-map.png",
              width = 79,
              height = 93,
              shift = {0.1, 0.2},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-10-effect-map.png",
              width = 93,
              height = 93,
              shift = {0.325, -0.1},
              scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-11-effect-map.png",
              width = 95,
              height = 93,
              shift = {0.453125, 0.2},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-12-effect-map.png",
              width = 92,
              height = 92,
              shift = {0.3, 0.1},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-13-effect-map.png",
              width = 76,
              height = 93,
              shift = {0.0703125, 0.3},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-14-effect-map.png",
              width = 63,
              height = 93,
              shift = {0.160938, 0.2},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-15-effect-map.png",
              width = 101,
              height = 92,
              shift = {0.242188, -0.1},
            scale = 0.8
            },
            {
              filename = "__space-age__/graphics/entity/stromatolite/copper/stromatolite-16-effect-map.png",
              width = 88,
              height = 92,
              shift = {0.1, -0.1},
            scale = 0.8
            }
          }
      }
  },
--Lichen spawns
  {
    name = "vesta-green-lettuce-lichen-1x1",
    type = "optimized-decorative",
    order = "XxX[decorative]-a[grass]-b[carpet]",
    collision_box = {{-0.5, -0.4}, {0.5, 0.4}},
    collision_mask = dec_shallow_collision(),
    walking_sound = base_tile_sounds.walking.carpet_grass,
    trigger_effect = decorative_trigger_effects.brown_carpet_grass(),
    render_layer = "decals",
    tile_layer = decal_tile_layer,
    opacity_over_water = decal_opacity_over_water,
    autoplace = {probability_expression = "(aquilo_high_frequency_peaks - 0.005) * 0.02"},
    pictures = decorative_pictures({count = 11, file_path = "__space-age__/graphics/decorative/green-lettuce-lichen-water/green-lettuce-lichen-1x1"})
  },
  {
    name = "vesta-green-lettuce-lichen-3x3",
    type = "optimized-decorative",
    order = "XxX[decorative]-a[grass]-b[carpet]",
    collision_box = {{-1, -0.8}, {1, 0.8}},
    collision_mask = dec_shallow_collision(),
    walking_sound = base_tile_sounds.walking.carpet_grass,
    trigger_effect = decorative_trigger_effects.brown_carpet_grass(),
    render_layer = "decals",
    tile_layer = decal_tile_layer,
    opacity_over_water = decal_opacity_over_water,
    autoplace = {probability_expression = "(aquilo_high_frequency_peaks - 0.015) * 0.03"},
    pictures = decorative_pictures({count = 12, file_path = "__space-age__/graphics/decorative/green-lettuce-lichen-water/green-lettuce-lichen-3x3"})
  },
  {
    name = "vesta-green-lettuce-lichen-6x6",
    type = "optimized-decorative",
    order = "XxX[decorative]-a[grass]-b[carpet]",
    collision_box = {{-2, -1.6}, {2, 1.6}},
    collision_mask = dec_shallow_collision(),
    walking_sound = base_tile_sounds.walking.carpet_grass,
    trigger_effect = decorative_trigger_effects.brown_carpet_grass(),
    render_layer = "decals",
    tile_layer = decal_tile_layer,
    opacity_over_water = decal_opacity_over_water,
    autoplace = {probability_expression = "(aquilo_high_frequency_peaks - 0.02) * 0.05"},
    pictures = decorative_pictures({count = 12, file_path = "__space-age__/graphics/decorative/green-lettuce-lichen-water/green-lettuce-lichen-6x6"})
  },  
 
}
