--The purpose of this function is to find a location
--to place the player after they shrink.
--It is trickly because certain chunks
--may not yet be loaded yet.
--
--Could be more fancy.
--Could check, after the shrinking,
--if the player is in a safe position
--(and if not then undo the shrink).
function p.update(txt)
    if not ga_get_b("var.movement.shrinking") then return end

    ga_print("game_shrink.update:")

    local level = ga_get_sys_i("game.player.level")

    --There is a quicker way to do this.
    for i=1,35 do
        local pos1 = std.bp(7,7,8-i)
        local pos2 = std.bp(7,7,8-i-1)
        local pos3 = std.bp(7,7,8-i-2)
        local bt1 = ga_block_get(level, pos1)
        local bt2 = ga_block_get(level, pos2)
        local bt3 = ga_block_get(level, pos3)
        ga_print("  " .. bt3)
        --
        if( bt1 == "NOT_LOADED" or
            bt2 == "NOT_LOADED" or
            bt3 == "NOT_LOADED" )
        then
            return
        end
        local solid1 = ga_bt_get_physically_solid(bt1)
        local solid2 = ga_bt_get_physically_solid(bt2)
        local solid3 = ga_bt_get_physically_solid(bt3)
        if( not solid1 and
            not solid2 and
            solid3 )
        then
            --Terminating the algorithm.
            local new_eye = std.block_center(pos1)
            ga_tele_same_level(new_eye)
            ga_set_b("var.movement.shrinking", false)
            return
        end
    end
end
