#define _CS_SHOP_DEFENSE IMAGE PRICE TERRAIN TEXT
    [buyable]
        price={PRICE}
        name=_{TEXT}
        subtitle=_"current: <span color='$tmp_defense_{TERRAIN}_color'>$tmp_defense_{TERRAIN}|%</span>, max: <span color='#33ff33'>60%</span>"
        image={IMAGE}

        [preshow]
            {VARIABLE tmp_defense_{TERRAIN} 100}
            {VARIABLE_OP tmp_defense_{TERRAIN} add -$tmp_defense_store.defense.{TERRAIN}|}

            {_CS_COLOR_PERCENTAGE tmp_defense_{TERRAIN} tmp_defense_{TERRAIN}_color}
        [/preshow]

        [postshow]
            {CLEAR_VARIABLE tmp_defense_{TERRAIN}}
            {CLEAR_VARIABLE tmp_defense_{TERRAIN}_color}
        [/postshow]

        [have_all_if]
            [variable]
                name=tmp_defense_{TERRAIN}
                greater_than_equal_to=60
            [/variable]

            [or]
                [variable]
                    name={CS_SIDEVAR defup_left $side_number}
                    equals=0
                [/variable]
            [/or]
        [/have_all_if]

        [command]
            [object]
                silent=yes
                [effect]
                    apply_to=defense
                    replace=no
                    [defense]
                        {TERRAIN}=-10
                    [/defense]
                [/effect]
            [/object]

            {CS_SIDEVAR_OP defup_left $side_number add -1}
        [/command]
    [/buyable]
#enddef

[section]
    name=_"Defenses"
    image="icons/shield_polished.png"
    tf_order=500

    [indicator]
        name=_"Training left"
        value=${CS_SIDEVAR defup_left $side_number}
    [/indicator]

    [preshow]
        [store_unit]
            [filter]
                side=$side_number
                x,y=$x1,$y1
            [/filter]

            variable=tmp_defense_store
        [/store_unit]
    [/preshow]

    [postshow]
        {CLEAR_VARIABLE tmp_defense_store}
    [/postshow]

    [show_if]
        [variable]
            name=unit.advances_to
            equals=""
        [/variable]
    [/show_if]

    {_CS_SHOP_DEFENSE "terrain/flat/road-clean.png" 
        20 flat       "+10% flat defense"}

    {_CS_SHOP_DEFENSE "terrain/forest/forested-deciduous-summer-hills-tile.png" 
        15 forest     "+10% forest defense"}

    {_CS_SHOP_DEFENSE "terrain/hills/regular.png"
        20 hills      "+10% hills defense"}

    {_CS_SHOP_DEFENSE "terrain/mountains/basic-tile.png"
        15 mountains  "+10% mountains defense"}

    {_CS_SHOP_DEFENSE "terrain/sand/desert-oasis.png"
        15 sand       "+10% sand defense"}

    {_CS_SHOP_DEFENSE "terrain/frozen/snow.png"
        10 frozen     "+10% frozen defense"}

    {_CS_SHOP_DEFENSE "terrain/cave/wall-rough-tile.png"
        15 cave       "+10% cave defense"}

    {_CS_SHOP_DEFENSE    "terrain/water/coast-tile.png"
        15 shallow_water "+10% shallow water defense"}

    {_CS_SHOP_DEFENSE "terrain/castle/castle-tile.png"
        15 castle     "+10% castle defense"}

    {_CS_SHOP_DEFENSE "terrain/forest/mushrooms-beam-tile.png"
        15 fungus     "+10% fungus defense"}
[/section]
