-------------------------------------------------------------------------------
class 'GlobalToolTarget'
-------------------------------------------------------------------------------

function GlobalToolTarget:__init(level_name, tool_name, target_name)
    self.level_name = level_name
    self.tool_name = tool_name
    self.target_name = target_name
end
-------------------------------------------------------------------------------

function GlobalToolTarget:IsUsed()
    local state, value = GenerateToolTargedUsed(self.tool_name, self.target_name, self.level_name)
    return HasGameState(state, value)
end
-------------------------------------------------------------------------------

function GlobalToolTarget:IsUsedInLocation(location_name)
    if location_name == self.level_name then
        return IsUsed()
    end
    
    return false
end
-------------------------------------------------------------------------------

function GenerateToolTargedUsed(tool_name, target_name, level_name)
    if not level_name then
        level_name = current_scene:getPlayField():getName()
    end

    local value = level_name..': tool_name('..tool_name..') target_name('..target_name..')'
    return TOOL_TARGET_USED, value
end
-------------------------------------------------------------------------------

function IsToolAllGlobalTargetsUsed(tool_name, inv)
    local info   = inv.tools[tool_name]
    
    assert(info)
    
    if info.additional_info.global_targets ~= nil then
        for _, globalTarget in ipairs(info.additional_info.global_targets) do
            if not globalTarget:IsUsed() then
                return false
            end
        end
    end
    
    return true
end
--------------------------------------------------------------------------------

function IsToolTargetUsed(tool_name, target_name, level_name)
    local state, value = GenerateToolTargedUsed(tool_name, target_name, level_name)
    return HasGameState(state, value)
end