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 bent_arcade_reset_door.door_is_shut(level, bp) then
        return "^xff0000You are in the arcade"
    else
        return "Touch to enter 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_inside_arcade()
    --Dealing with ammo.
    if not p.in_arcade() then
        ga_play_sound("arcade_enter")
        --
        local ammo1 = ga_get_i("xar.player.gun1.ammo")
        local ammo2 = ga_get_i("xar.player.gun2.ammo")
        local ammo3 = ga_get_i("xar.player.gun3.ammo")
        local ammo4 = ga_get_i("xar.player.gun4.ammo")
        local ammo5 = ga_get_i("xar.player.gun5.ammo")
        local ammo6 = ga_get_i("xar.player.gun6.ammo")
        local ammo7 = ga_get_i("xar.player.gun7.ammo")
        local ammo8 = ga_get_i("xar.player.gun8.ammo")
        local ammo9 = ga_get_i("xar.player.gun9.ammo")
        local ammo0 = ga_get_i("xar.player.gun0.ammo")
        --
        ga_set_i("xar.player.arcade.ammo.1", ammo1)
        ga_set_i("xar.player.arcade.ammo.2", ammo2)
        ga_set_i("xar.player.arcade.ammo.3", ammo3)
        ga_set_i("xar.player.arcade.ammo.4", ammo4)
        ga_set_i("xar.player.arcade.ammo.5", ammo5)
        ga_set_i("xar.player.arcade.ammo.6", ammo6)
        ga_set_i("xar.player.arcade.ammo.7", ammo7)
        ga_set_i("xar.player.arcade.ammo.8", ammo8)
        ga_set_i("xar.player.arcade.ammo.9", ammo9)
        ga_set_i("xar.player.arcade.ammo.0", ammo0)
    end

    --Setting that is now inside arcade.
    ga_set_b("xar.player.arcade.inside", true)
end

function p.payload(level, bp)
    p.set_inside_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_ENTER_SOLID" ) then
            --Removing the block.
            ga_block_change_perm(level, bp2, "ARCADE_DOOR_ENTER_EMPTY")
        end
        if( block_type == "ARCADE_DOOR_SHUT_EMPTY" ) then
            --Adding the block.
            ga_block_change_perm(level, bp2, "ARCADE_DOOR_SHUT_SOLID")
        end
        -- local bent_type = ga_bent_get_type(level, bp2)
        -- if( bent_type == "bent_arcade_enter" ) then
        --     --Removing the arcade box.
        --     ga_bent_remove_perm(level, bp2)
        -- end
    end end end
end
