function p.in_arcade()
    return ga_get_b("xar.player.arcade.inside")
end

function p.get_can_use(level, bp)
    return false
end

function p.get_use_msg(level, bp)
    if not bent_arcade_reset_door.door_is_shut(level, bp) then
        return "Touch to exit arcade"
    else
        return "^xff0000You have left the arcade"
    end
end

function p.on_touch(level, bp)
    p.payload(level, bp)
end

--Helper function.
--Can be called from other scripts.
function p.set_outside_arcade()
    --Setting ammo to what is was when entered the arcade.
    if p.in_arcade() then
        ga_play_sound("arcade_exit")
        local ammo1 = ga_get_i("xar.player.arcade.ammo.1")
        local ammo2 = ga_get_i("xar.player.arcade.ammo.2")
        local ammo3 = ga_get_i("xar.player.arcade.ammo.3")
        local ammo4 = ga_get_i("xar.player.arcade.ammo.4")
        local ammo5 = ga_get_i("xar.player.arcade.ammo.5")
        local ammo6 = ga_get_i("xar.player.arcade.ammo.6")
        local ammo7 = ga_get_i("xar.player.arcade.ammo.7")
        local ammo8 = ga_get_i("xar.player.arcade.ammo.8")
        local ammo9 = ga_get_i("xar.player.arcade.ammo.9")
        local ammo0 = ga_get_i("xar.player.arcade.ammo.0")
        --
        ga_set_i("xar.player.gun1.ammo", ammo1)
        ga_set_i("xar.player.gun2.ammo", ammo2)
        ga_set_i("xar.player.gun3.ammo", ammo3)
        ga_set_i("xar.player.gun4.ammo", ammo4)
        ga_set_i("xar.player.gun5.ammo", ammo5)
        ga_set_i("xar.player.gun6.ammo", ammo6)
        ga_set_i("xar.player.gun7.ammo", ammo7)
        ga_set_i("xar.player.gun8.ammo", ammo8)
        ga_set_i("xar.player.gun9.ammo", ammo9)
        ga_set_i("xar.player.gun0.ammo", ammo0)
    end
    
    --Setting to be not in the arcade.
    ga_set_b("xar.player.arcade.inside", false)
end

function p.payload(level, bp)
    p.set_outside_arcade()

    local vcp = std.bp_to_vcp(bp)
    for xi = 0,15 do
    for yi = 0,15 do
    for zi = 0,15 do
        local lbp = std.bp(xi,yi,zi)
        local bp2 = std.lbp_to_bp(vcp, lbp)
        --
        local block_type = ga_block_get(level, bp2)
        if( block_type == "ARCADE_DOOR_EXIT_SOLID" ) then
            --Removing the block.
            ga_block_change_perm(level, bp2, "ARCADE_DOOR_EXIT_EMPTY")
        end
        if( block_type == "ARCADE_DOOR_SHUT_EMPTY" ) then
            --Adding the block.
            ga_block_change_perm(level, bp2, "ARCADE_DOOR_SHUT_SOLID")
        end
    end end end
end
