 
   accept: (other_unit) -> @model.accept(other_unit.model)
 
-  update: () ->
-
-  fight_missile: (missile, destroy_area) -> 0
+  max_depend_point: 9
+  defend: (missile, destroy_area) -> 0
+
+class MapUnit2DForBrick extends MapUnit2D
+  current_frames: () -> [{x: 0, y: 240}]
+  defend: (missile, destroy_area) ->
+    # cut self into pieces
+    pieces = @area.sub(destroy_area)
+    _.each(pieces, (piece) =>
+      @model.battle_field.add_terrain(BrickTerrain, piece)
+    )
+    @model.destroy()
+    # return cost of destroy
+    1
+
+class MapUnit2DForIron extends MapUnit2D
+  current_frames: () -> [{x: 80, y: 240}]
+  defend: (missile, destroy_area) ->
+    return @max_depend_point if missile.power < 2
+    double_destroy_area = destroy_area.multiply(missile.direction, 1)
+    pieces = @area.sub(double_destroy_area)
+    _.each(pieces, (piece) =>
+      @model.battle_field.add_terrain(IronTerrain, piece)
+    )
+    @model.destroy()
+    2
+
+class MapUnit2DForIce extends MapUnit2D
+  layer: 0
+  current_frames: () -> [{x: 40, y: 240}]
+
+class MapUnit2DForGrass extends MapUnit2D
+  layer: 2
+  current_frames: () -> [{x: 120, y: 240}]
+
+class MapUnit2DForWater extends MapUnit2D
+  layer: 0
+  current_frames: () -> [{x: 160, y: 240}]
+
+class MapUnit2DForHome extends MapUnit2D
+  current_frames: () ->
+    if @model.is_defeated then [{x: 240, y: 240}] else [{x: 200, y: 240}]
+  defend: (missile, destroy_area) ->
+    @model.is_defeated = true
+    @max_depend_point
 
 class MovableMapUnit2D extends MapUnit2D
   origin_x: 'center'

    (@y1 < (a * area.x2 + b) < @y2) or
    (@y1 < (c - a * area.x1) < @y2) or
    (@y1 < (c - a * area.x2) < @y2)
  collide: (area) ->
    # fast method
    return false if (@x2 <= area.x1 or @y2 <= area.y1 or @x1 >= area.x2 or @y1 >= area.y2)
    # slow method
    @has_intersection(area)
  joint: (area) ->
    new MapArea2D(_.max(area.x1, @x1), _.max(area.y1, @y1), _.min(area.x2, @x2), _.min(area.y2, @y2))
  space_sub: (area) ->
    joint_area = @joint(area)
    candidates = [
      new MapArea2D(@x1, @y1, @x2, joint_area.y1),
      new MapArea2D(@x1, joint_area.y2, @x2, @y2),
      new MapArea2D(@x1, joint_area.y1, joint_area.x1, joint_area.y2),
      new MapArea2D(joint_area.x2, joint_area.y1, @x2, joint_area.y2)
    ]
    _.select(candidates, (candidate_area) -> candidate_area.is_valid_area())
  is_valid_area: () ->
    @x2 > @x1 and @y2 > @y1

class Map2D
  max_x: 520

class Tank extends MovableBattleFieldObject
  accept: (battle_field_object) ->
    (battle_field_object instanceof Missile) and (battle_field_object.parent is this)

  life: 1
  set_life: (@life) ->
  dead: -> @life <= 0
  power: 1
  level: 1
  max_missile: 1
  missiles: []
  update_level: (@level) ->
    switch @level
      when 1
        @power = 1
        @max_missile = 1
      when 2
        @power = 2
        @max_missile = 2

  ship: false
  update_ship: (@ship) ->

  guard: false
  update_guard: (@guard) ->

  fire: () ->
    if _.size(@missiles) < @max_missile
      missile = @battle_field.add_missile(this)
      @missiles.push(missile)

  integration: (delta_time) ->
    super(delta_time)
    @fire() for command in _.select(@commands, (command) -> command.type == "fire")

  missile_born_area: () -> @view.missile_born_area()

  delete_missile: (missile) ->
    @missiles = _.without(@missiles, missile)

