#include "tools.lua" #include "missions.lua" #include "challenges.lua" function syncActivities(missionId, isStart, isEnd) local availActivities = {} local notAvailActivities = {} local forceUnlockLevels = GetBool("options.game.sandbox.unlocklevels") local availLevels = {} local availMissions = {} local hasScoreMissions = {} local mission = gMissions[missionId] local hasOptional = mission and mission.required < mission.primary + mission.secondary local completedCampaign = true for id, m in pairs(gMissions) do if GetBool("savegame.mission."..id) then availMissions[id] = true if id ~= "mall_intro" and id ~= "factory_espionage" then availLevels[m.level] = true end local score = GetInt("savegame.mission."..id..".score") if score > 0 then hasScoreMissions[id] = true end if score < m.primary + m.secondary then completedCampaign = false end else completedCampaign = false end end if availMissions[missionId] then local score = GetInt("savegame.mission."..missionId..".score") if score < mission.required then table.insert(availActivities, missionId) end if score < mission.primary + mission.secondary then if hasOptional then table.insert(availActivities, missionId.."_opt") end end end if missionId == "lee_computers" and availMissions[missionId] then table.insert(availActivities, "sandbox") end if missionId == "lee_computers" and hasScoreMissions[missionId] then table.insert(availActivities, "challenges") end if missionId == "mansion_race" and availMissions[missionId] then table.insert(availActivities, "challenge_mansion_race") end for id, c in pairs(gChallenges) do local isAvail = hasScoreMissions[c.unlockMission] and (availLevels[c.level] or forceUnlockLevels) if isAvail and (c.unlockMission == missionId or (mission and mission.level == c.level)) then for stars = 1, 5 do table.insert(availActivities, id.."_"..stars) end end end local availActivitiesStr = table.concat(availActivities, " ") if availActivitiesStr ~= "" then ActivityAvailabilityChange(availActivitiesStr, "", false) end if missionId == "mansion_race" then -- managed in racetrack.lua elseif mission then local score = GetInt("savegame.mission."..missionId..".score") if isStart and not completedCampaign then if score < mission.required then ActivityStart(missionId) elseif hasOptional and score < mission.primary + mission.secondary then ActivityStart(missionId.."_opt") end elseif isEnd then if score >= mission.required then ActivityEnd(missionId) table.insert(notAvailActivities, missionId) end if hasOptional and score >= mission.primary + mission.secondary then ActivityEnd(missionId.."_opt") table.insert(notAvailActivities, missionId.."_opt") end if completedCampaign then ActivityEnd("campaign") table.insert(notAvailActivities, "campaign") end end elseif string.sub(missionId, 1, 3) == "ch_" then if isStart then local stars = GetInt("savegame.challenge."..missionId..".stars") if stars < 5 then stars = stars + 1 end ActivityStart(missionId.."_"..stars) elseif isEnd then -- managed in syncChallengeActivities end elseif not GetBool("level.campaign") then if isStart then ActivityStart("sandbox") elseif isEnd then ActivityEnd("sandbox") end end local notAvailActivitiesStr = table.concat(notAvailActivities, " ") if notAvailActivitiesStr ~= "" then ActivityAvailabilityChange("", notAvailActivitiesStr, false) end end function syncChallengeActivities(challengeId, stars, oldStars) if stars > oldStars then for i = oldStars + 1, stars do ActivityEnd(challengeId.."_"..i) end end local completedChallenges = true for id, c in pairs(gChallenges) do local score = GetInt("savegame.challenge."..id..".stars") if score < 5 then completedChallenges = false end end if completedChallenges then ActivityEnd("challenges") end end function syncModActivities() if HasKey("game.mod") then local usedModKey = "savegame.usedmods."..GetString("game.mod") if not HasKey(usedModKey) then local usedMods = ListKeys("savegame.usedmods") local usedModsCount = #usedMods if usedModsCount < 25 then if usedModsCount == 9 then ActivityEnd("usedmods_10") end if usedModsCount == 24 then ActivityEnd("usedmods_25") ActivityEnd("usedmods") end SetBool(usedModKey, true) end end end end function syncCustomToolsActivities() local tools = ListKeys("game.tool") local usedCustomTools = ListKeys("savegame.usedcustomtools") local usedCustomToolsCount = #usedCustomTools for i=1,#tools do local toolId = tools[i] if not gTools[toolId] then local usedCustomToolKey = "savegame.usedcustomtools."..toolId if usedCustomToolsCount < 25 and not HasKey(usedCustomToolKey) then if usedCustomToolsCount == 9 then ActivityEnd("usedcustomtools_10") end if usedCustomToolsCount == 24 then ActivityEnd("usedcustomtools_25") ActivityEnd("usedcustomtools") end SetBool(usedCustomToolKey, true) usedCustomToolsCount = usedCustomToolsCount + 1 end end end end function resetActivities() local availActivities = {} local unavailActivities = {} local completedCampaignActivities = {} local completedChallengeActivities = {} local forceUnlockLevels = GetBool("options.game.sandbox.unlocklevels") local availLevels = {} local availMissions = {} local hasScoreMissions = {} local function addAvail(id, isAvail) if isAvail then table.insert(availActivities, id) else table.insert(unavailActivities, id) end end local completedCampaign = true for id, mission in pairs(gMissions) do local isAvail = GetBool("savegame.mission."..id) local hasOptional = mission.required < mission.primary + mission.secondary local isComplete = false local isCompleteOptional = false if isAvail then availMissions[id] = true if id ~= "mall_intro" and id ~= "factory_espionage" then availLevels[mission.level] = true end local score = GetInt("savegame.mission."..id..".score") if score > 0 then hasScoreMissions[id] = true end if score >= mission.required then table.insert(completedCampaignActivities, id) isComplete = true end if score >= mission.primary + mission.secondary then if hasOptional then table.insert(completedCampaignActivities, id.."_opt") isCompleteOptional = true end else completedCampaign = false end else completedCampaign = false end addAvail(id, isAvail and not isComplete) if hasOptional then addAvail(id.."_opt", isAvail and not isCompleteOptional) end end addAvail("campaign", not completedCampaign) addAvail("challenge_mansion_race", GetBool("savegame.mission.mansion_race")) addAvail("sandbox", GetBool("savegame.mission.lee_computers") or forceUnlockLevels) local hasFetch = false local hasMayhem = false local hasHunted = false local completedChallenges = true for id, c in pairs(gChallenges) do local isAvail = hasScoreMissions[c.unlockMission] and (availLevels[c.level] or forceUnlockLevels) local score = GetInt("savegame.challenge."..id..".stars") if score < 5 then completedChallenges = false end for stars = 1, 5 do addAvail(id.."_"..stars, isAvail) if isAvail and score >= stars then table.insert(completedChallengeActivities, id.."_"..stars) end end if isAvail then if string.sub(id, -6, -1) == "_fetch" then hasFetch = true end if string.sub(id, -7, -1) == "_mayhem" then hasMayhem = true end if string.sub(id, -7, -1) == "_hunted" then hasHunted = true end end end addAvail("challenge_fetch", hasFetch) addAvail("challenge_mayhem", hasMayhem) addAvail("challenge_hunted", hasHunted) addAvail("challenges", not completedChallenges and GetInt("savegame.mission.lee_computers.score") > 0) ---local usedMods = ListKeys("savegame.usedmods") ---local completedUsedMods10 = #usedMods >= 10 ---local completedUsedMods = #usedMods >= 25 ---addAvail("usedmods_10", not completedUsedMods10) ---addAvail("usedmods_25", not completedUsedMods) ---addAvail("usedmods", not completedUsedMods) ---local usedCustomTools = ListKeys("savegame.usedcustomtools") ---local completedUsedCustomTools10 = #usedCustomTools >= 10 ---local completedUsedCustomTools = #usedCustomTools >= 25 ---addAvail("usedcustomtools_10", not completedUsedCustomTools10) ---addAvail("usedcustomtools_25", not completedUsedCustomTools) ---addAvail("usedcustomtools", not completedUsedCustomTools) ActivityTerminate() ActivityAvailabilityChange(table.concat(availActivities, " "), table.concat(unavailActivities, " "), true) if not completedCampaign then ActivityResume("campaign", table.concat(completedCampaignActivities, " ")) end if not completedChallenges then ActivityResume("challenges", table.concat(completedChallengeActivities, " ")) end ---if not completedUsedMods10 then --- ActivityResume("usedmods", "") ---elseif not completedUsedMods then --- ActivityResume("usedmods", "usedmods_10") ---end ---if not completedUsedCustomTools10 then --- ActivityResume("usedcustomtools", "") ---elseif not completedUsedCustomTools then --- ActivityResume("usedcustomtools", "usedcustomtools_10") ---end end