data.raw["storage-tank"]["storage-tank"].icon = "__boblogistics__/graphics/icons/storage-tank-1.png"
data.raw["storage-tank"]["storage-tank"].fast_replaceable_group = "pipe"
data.raw["storage-tank"]["storage-tank"].next_upgrade = "bob-storage-tank-2"

local storagetankbase = settings.startup["bobmods-logistics-storagetankbase"].value * 1000
data.raw["storage-tank"]["storage-tank"].fluid_box.volume = storagetankbase
table.insert(data.raw["storage-tank"]["storage-tank"].pictures.picture.sheets, 2, {
  filename = "__boblogistics__/graphics/entity/storage-tank/storage-tank-mask.png",
  priority = "extra-high",
  frames = 2,
  width = 219,
  height = 215,
  shift = util.by_pixel(-0.25, 3.75),
  scale = 0.5,
  tint = { r = 0.65, g = 0.2, b = 0.15 },
})

local function storage_tank_pictures(tint)
  local graphics = {
    picture = {
      sheets = {
        {
          filename = "__base__/graphics/entity/storage-tank/storage-tank.png",
          priority = "extra-high",
          frames = 2,
          width = 219,
          height = 215,
          shift = util.by_pixel(-0.25, 3.75),
          scale = 0.5,
        },
        {
          filename = "__boblogistics__/graphics/entity/storage-tank/storage-tank-mask.png",
          priority = "extra-high",
          frames = 2,
          width = 219,
          height = 215,
          shift = util.by_pixel(-0.25, 3.75),
          scale = 0.5,
          tint = tint,
        },
        {
          filename = "__base__/graphics/entity/storage-tank/storage-tank-shadow.png",
          priority = "extra-high",
          frames = 2,
          width = 291,
          height = 153,
          shift = util.by_pixel(29.75, 22.25),
          scale = 0.5,
          draw_as_shadow = true,
        },
      },
    },
    fluid_background = {
      filename = "__base__/graphics/entity/storage-tank/fluid-background.png",
      priority = "extra-high",
      width = 32,
      height = 15,
    },
    window_background = {
      filename = "__base__/graphics/entity/storage-tank/window-background.png",
      priority = "extra-high",
      width = 34,
      height = 48,
      scale = 0.5,
    },
    flow_sprite = {
      filename = "__base__/graphics/entity/pipe/fluid-flow-low-temperature.png",
      priority = "extra-high",
      width = 160,
      height = 20,
    },
    gas_flow = {
      filename = "__base__/graphics/entity/pipe/steam.png",
      priority = "extra-high",
      line_length = 10,
      width = 48,
      height = 30,
      frame_count = 60,
      animation_speed = 0.25,
      scale = 0.5,
    },
  }
  return graphics
end

local function storage_tank_all_pictures(tint)
  local graphics = {
    picture = {
      sheets = {
        {
          filename = "__boblogistics__/graphics/entity/storage-tank/storage-tank.png",
          priority = "extra-high",
          frames = 1,
          width = 219,
          height = 215,
          shift = util.by_pixel(-0.25, 3.75),
          scale = 0.5,
        },
        {
          filename = "__boblogistics__/graphics/entity/storage-tank/storage-tank-all-mask.png",
          priority = "extra-high",
          frames = 1,
          width = 219,
          height = 215,
          shift = util.by_pixel(-0.25, 3.75),
          scale = 0.5,
          tint = tint,
        },
        {
          filename = "__boblogistics__/graphics/entity/storage-tank/storage-tank-shadow.png",
          priority = "extra-high",
          frames = 1,
          width = 291,
          height = 153,
          shift = util.by_pixel(29.75, 22.25),
          scale = 0.5,
          draw_as_shadow = true,
        },
      },
    },
    fluid_background = {
      filename = "__base__/graphics/entity/storage-tank/fluid-background.png",
      priority = "extra-high",
      width = 32,
      height = 15,
    },
    window_background = {
      filename = "__base__/graphics/entity/storage-tank/window-background.png",
      priority = "extra-high",
      width = 34,
      height = 48,
      scale = 0.5,
    },
    flow_sprite = {
      filename = "__base__/graphics/entity/pipe/fluid-flow-low-temperature.png",
      priority = "extra-high",
      width = 160,
      height = 20,
    },
    gas_flow = {
      filename = "__base__/graphics/entity/pipe/steam.png",
      priority = "extra-high",
      line_length = 10,
      width = 48,
      height = 30,
      frame_count = 60,
      animation_speed = 0.25,
      scale = 0.5,
    },
  }

  return graphics
end

data:extend({
  {
    type = "storage-tank",
    name = "bob-storage-tank-2",
    icon = "__boblogistics__/graphics/icons/storage-tank-2.png",
    flags = { "placeable-player", "player-creation" },
    minable = { mining_time = 0.5, result = "bob-storage-tank-2" },
    max_health = 600,
    corpse = "medium-remnants",
    collision_box = { { -1.3, -1.3 }, { 1.3, 1.3 } },
    selection_box = { { -1.5, -1.5 }, { 1.5, 1.5 } },
    fluid_box = {
      volume = storagetankbase * 2,
      pipe_covers = pipecoverspictures(),
      pipe_connections = {
        { position = { -1, -1 }, direction = defines.direction.north },
        { position = { 1, 1 }, direction = defines.direction.east },
        { position = { 1, 1 }, direction = defines.direction.south },
        { position = { -1, -1 }, direction = defines.direction.west },
      },
      hide_connection_info = true,
    },
    two_direction_only = true,
    fast_replaceable_group = "pipe",
    next_upgrade = "bob-storage-tank-3",
    window_bounding_box = { { -0.125, 0.6875 }, { 0.1875, 1.1875 } },
    pictures = storage_tank_pictures({ r = 0.25, g = 0.45, b = 0.6 }),
    flow_length_in_ticks = 360,
    impact_category = "metal-large",
    working_sound = {
      sound = {
        filename = "__base__/sound/storage-tank.ogg",
        volume = 0.8,
      },
      max_sounds_per_prototype = 3,
    },
    circuit_connector = circuit_connector_definitions["storage-tank"],
    circuit_wire_max_distance = 10,
  },

  {
    type = "storage-tank",
    name = "bob-storage-tank-3",
    icon = "__boblogistics__/graphics/icons/storage-tank-3.png",
    flags = { "placeable-player", "player-creation" },
    minable = { mining_time = 0.5, result = "bob-storage-tank-3" },
    max_health = 700,
    corpse = "medium-remnants",
    collision_box = { { -1.3, -1.3 }, { 1.3, 1.3 } },
    selection_box = { { -1.5, -1.5 }, { 1.5, 1.5 } },
    fluid_box = {
      volume = storagetankbase * 3,
      pipe_covers = pipecoverspictures(),
      pipe_connections = {
        { position = { -1, -1 }, direction = defines.direction.north },
        { position = { 1, 1 }, direction = defines.direction.east },
        { position = { 1, 1 }, direction = defines.direction.south },
        { position = { -1, -1 }, direction = defines.direction.west },
      },
      hide_connection_info = true,
    },
    two_direction_only = true,
    fast_replaceable_group = "pipe",
    next_upgrade = "bob-storage-tank-4",
    window_bounding_box = { { -0.125, 0.6875 }, { 0.1875, 1.1875 } },
    pictures = storage_tank_pictures({ r = 0.7, g = 0.3, b = 0.68 }),
    flow_length_in_ticks = 360,
    impact_category = "metal-large",
    working_sound = {
      sound = {
        filename = "__base__/sound/storage-tank.ogg",
        volume = 0.8,
      },
      max_sounds_per_prototype = 3,
    },
    circuit_connector = circuit_connector_definitions["storage-tank"],
    circuit_wire_max_distance = 12.5,
  },

  {
    type = "storage-tank",
    name = "bob-storage-tank-4",
    icon = "__boblogistics__/graphics/icons/storage-tank-4.png",
    flags = { "placeable-player", "player-creation" },
    minable = { mining_time = 0.5, result = "bob-storage-tank-4" },
    max_health = 800,
    corpse = "medium-remnants",
    collision_box = { { -1.3, -1.3 }, { 1.3, 1.3 } },
    selection_box = { { -1.5, -1.5 }, { 1.5, 1.5 } },
    fluid_box = {
      volume = storagetankbase * 4,
      pipe_covers = pipecoverspictures(),
      pipe_connections = {
        { position = { -1, -1 }, direction = defines.direction.north },
        { position = { 1, 1 }, direction = defines.direction.east },
        { position = { 1, 1 }, direction = defines.direction.south },
        { position = { -1, -1 }, direction = defines.direction.west },
      },
      hide_connection_info = true,
    },
    two_direction_only = true,
    fast_replaceable_group = "pipe",
    window_bounding_box = { { -0.125, 0.6875 }, { 0.1875, 1.1875 } },
    pictures = storage_tank_pictures({ r = 0.2, g = 0.55, b = 0.2 }),
    flow_length_in_ticks = 360,
    impact_category = "metal-large",
    working_sound = {
      sound = {
        filename = "__base__/sound/storage-tank.ogg",
        volume = 0.8,
      },
      max_sounds_per_prototype = 3,
    },
    circuit_connector = circuit_connector_definitions["storage-tank"],
    circuit_wire_max_distance = 15,
  },
})

data:extend({
  {
    type = "storage-tank",
    name = "bob-storage-tank-all-corners",
    icon = "__boblogistics__/graphics/icons/storage-tank-all-corners-1.png",
    flags = { "placeable-player", "player-creation" },
    minable = { mining_time = 0.5, result = "bob-storage-tank-all-corners" },
    max_health = 500,
    corpse = "medium-remnants",
    collision_box = { { -1.3, -1.3 }, { 1.3, 1.3 } },
    selection_box = { { -1.5, -1.5 }, { 1.5, 1.5 } },
    fluid_box = {
      volume = storagetankbase,
      pipe_covers = pipecoverspictures(),
      pipe_connections = {
        { position = { -1, -1 }, direction = defines.direction.north },
        { position = { 1, -1 }, direction = defines.direction.north },
        { position = { -1, 1 }, direction = defines.direction.south },
        { position = { 1, 1 }, direction = defines.direction.south },
        { position = { -1, -1 }, direction = defines.direction.west },
        { position = { -1, 1 }, direction = defines.direction.west },
        { position = { 1, -1 }, direction = defines.direction.east },
        { position = { 1, 1 }, direction = defines.direction.east },
      },
      hide_connection_info = true,
    },
    fast_replaceable_group = "pipe",
    next_upgrade = "bob-storage-tank-all-corners-2",
    window_bounding_box = { { -0.125, 0.6875 }, { 0.1875, 1.1875 } },
    pictures = storage_tank_all_pictures({ r = 0.65, g = 0.2, b = 0.15 }),
    flow_length_in_ticks = 360,
    impact_category = "metal-large",
    working_sound = {
      sound = {
        filename = "__base__/sound/storage-tank.ogg",
        volume = 0.8,
      },
      match_volume_to_activity = true,
      max_sounds_per_prototype = 3,
    },
    circuit_connector = circuit_connector_definitions["storage-tank"],
    circuit_wire_max_distance = default_circuit_wire_max_distance,
  },
  {
    type = "storage-tank",
    name = "bob-storage-tank-all-corners-2",
    icon = "__boblogistics__/graphics/icons/storage-tank-all-corners-2.png",
    flags = { "placeable-player", "player-creation" },
    minable = { mining_time = 0.5, result = "bob-storage-tank-all-corners-2" },
    max_health = 600,
    corpse = "medium-remnants",
    collision_box = { { -1.3, -1.3 }, { 1.3, 1.3 } },
    selection_box = { { -1.5, -1.5 }, { 1.5, 1.5 } },
    fluid_box = {
      volume = storagetankbase * 2,
      pipe_covers = pipecoverspictures(),
      pipe_connections = {
        { position = { -1, -1 }, direction = defines.direction.north },
        { position = { 1, -1 }, direction = defines.direction.north },
        { position = { -1, 1 }, direction = defines.direction.south },
        { position = { 1, 1 }, direction = defines.direction.south },
        { position = { -1, -1 }, direction = defines.direction.west },
        { position = { -1, 1 }, direction = defines.direction.west },
        { position = { 1, -1 }, direction = defines.direction.east },
        { position = { 1, 1 }, direction = defines.direction.east },
      },
      hide_connection_info = true,
    },
    fast_replaceable_group = "pipe",
    next_upgrade = "bob-storage-tank-all-corners-3",
    window_bounding_box = { { -0.125, 0.6875 }, { 0.1875, 1.1875 } },
    pictures = storage_tank_all_pictures({ r = 0.25, g = 0.45, b = 0.6 }),
    flow_length_in_ticks = 360,
    impact_category = "metal-large",
    working_sound = {
      sound = {
        filename = "__base__/sound/storage-tank.ogg",
        volume = 0.8,
      },
      max_sounds_per_prototype = 3,
    },
    circuit_connector = circuit_connector_definitions["storage-tank"],
    circuit_wire_max_distance = 10,
  },

  {
    type = "storage-tank",
    name = "bob-storage-tank-all-corners-3",
    icon = "__boblogistics__/graphics/icons/storage-tank-all-corners-3.png",
    flags = { "placeable-player", "player-creation" },
    minable = { mining_time = 0.5, result = "bob-storage-tank-all-corners-3" },
    max_health = 700,
    corpse = "medium-remnants",
    collision_box = { { -1.3, -1.3 }, { 1.3, 1.3 } },
    selection_box = { { -1.5, -1.5 }, { 1.5, 1.5 } },
    fluid_box = {
      volume = storagetankbase * 3,
      pipe_covers = pipecoverspictures(),
      pipe_connections = {
        { position = { -1, -1 }, direction = defines.direction.north },
        { position = { 1, -1 }, direction = defines.direction.north },
        { position = { -1, 1 }, direction = defines.direction.south },
        { position = { 1, 1 }, direction = defines.direction.south },
        { position = { -1, -1 }, direction = defines.direction.west },
        { position = { -1, 1 }, direction = defines.direction.west },
        { position = { 1, -1 }, direction = defines.direction.east },
        { position = { 1, 1 }, direction = defines.direction.east },
      },
      hide_connection_info = true,
    },
    fast_replaceable_group = "pipe",
    next_upgrade = "bob-storage-tank-all-corners-4",
    window_bounding_box = { { -0.125, 0.6875 }, { 0.1875, 1.1875 } },
    pictures = storage_tank_all_pictures({ r = 0.7, g = 0.3, b = 0.68 }),
    flow_length_in_ticks = 360,
    impact_category = "metal-large",
    working_sound = {
      sound = {
        filename = "__base__/sound/storage-tank.ogg",
        volume = 0.8,
      },
      max_sounds_per_prototype = 3,
    },
    circuit_connector = circuit_connector_definitions["storage-tank"],
    circuit_wire_max_distance = 12.5,
  },

  {
    type = "storage-tank",
    name = "bob-storage-tank-all-corners-4",
    icon = "__boblogistics__/graphics/icons/storage-tank-all-corners-4.png",
    flags = { "placeable-player", "player-creation" },
    minable = { mining_time = 0.5, result = "bob-storage-tank-all-corners-4" },
    max_health = 800,
    corpse = "medium-remnants",
    collision_box = { { -1.3, -1.3 }, { 1.3, 1.3 } },
    selection_box = { { -1.5, -1.5 }, { 1.5, 1.5 } },
    fluid_box = {
      volume = storagetankbase * 4,
      pipe_covers = pipecoverspictures(),
      pipe_connections = {
        { position = { -1, -1 }, direction = defines.direction.north },
        { position = { 1, -1 }, direction = defines.direction.north },
        { position = { -1, 1 }, direction = defines.direction.south },
        { position = { 1, 1 }, direction = defines.direction.south },
        { position = { -1, -1 }, direction = defines.direction.west },
        { position = { -1, 1 }, direction = defines.direction.west },
        { position = { 1, -1 }, direction = defines.direction.east },
        { position = { 1, 1 }, direction = defines.direction.east },
      },
      hide_connection_info = true,
    },
    fast_replaceable_group = "pipe",
    window_bounding_box = { { -0.125, 0.6875 }, { 0.1875, 1.1875 } },
    pictures = storage_tank_all_pictures({ r = 0.2, g = 0.55, b = 0.2 }),
    flow_length_in_ticks = 360,
    impact_category = "metal-large",
    working_sound = {
      sound = {
        filename = "__base__/sound/storage-tank.ogg",
        volume = 0.8,
      },
      max_sounds_per_prototype = 3,
    },
    circuit_connector = circuit_connector_definitions["storage-tank"],
    circuit_wire_max_distance = 15,
  },
})
