------------------------------------------------------------------------------ -- Challenges ------------------------------------------------------------------------------ gChallenges = {} MAYHEM_TITLE = "loc@CHALLENGE_MAYHEM" HUNTED_TITLE = "loc@CHALLENGE_HUNTED" FETCH_TITLE = "loc@CHALLENGE_FETCH" MAYHEM_DESCRIPTION = "loc@MAYHEM_DESCRIPTION_DESTROY_AS" HUNTED_DESCRIPTION = "loc@HUNTED_DESCRIPTION_PICK_UP" FETCH_DESCRIPTION = "loc@FETCH_DESCRIPTION_PICK_UP" ------------------------------------------------------------------------------ -- Lee ------------------------------------------------------------------------------ gChallenges["ch_lee_mayhem"] = { level="lee", file = "lee.xml", layers="ch_lee_mayhem", title=MAYHEM_TITLE, desc=MAYHEM_DESCRIPTION, unlockMission="lee_computers", } gChallenges["ch_lee_hunted"] = { level="lee", file = "lee.xml", layers="ch_lee_hunted", title=HUNTED_TITLE, desc=HUNTED_DESCRIPTION, unlockMission="caveisland_dishes", } gChallenges["ch_lee_fetch"] = { level="lee", file = "lee.xml", layers="ch_lee_fetch", title=FETCH_TITLE, desc=FETCH_DESCRIPTION, unlockMission="lee_login", } ------------------------------------------------------------------------------ -- Marina ------------------------------------------------------------------------------ gChallenges["ch_marina_mayhem"] = { level="marina", file = "marina.xml", layers="ch_marina_mayhem", title=MAYHEM_TITLE, desc=MAYHEM_DESCRIPTION, unlockMission="lee_computers", } gChallenges["ch_marina_hunted"] = { level="marina", file = "marina.xml", layers="ch_marina_hunted", title=HUNTED_TITLE, desc=HUNTED_DESCRIPTION, unlockMission="caveisland_dishes", } gChallenges["ch_marina_fetch"] = { level="marina", file = "marina.xml", layers="ch_marina_fetch", title=FETCH_TITLE, desc=FETCH_DESCRIPTION, unlockMission="lee_login", } ------------------------------------------------------------------------------ -- Mansion ------------------------------------------------------------------------------ gChallenges["ch_mansion_mayhem"] = { level="mansion", file = "mansion.xml", layers="ch_mansion_mayhem", title=MAYHEM_TITLE, desc=MAYHEM_DESCRIPTION, unlockMission="lee_computers", } gChallenges["ch_mansion_hunted"] = { level="mansion", file = "mansion.xml", layers="ch_mansion_hunted", title=HUNTED_TITLE, desc=HUNTED_DESCRIPTION, unlockMission="caveisland_dishes", } gChallenges["ch_mansion_fetch"] = { level="mansion", file = "mansion.xml", layers="ch_mansion_fetch", title=FETCH_TITLE, desc=FETCH_DESCRIPTION, unlockMission="lee_login", } ------------------------------------------------------------------------------ -- Cave Island ------------------------------------------------------------------------------ gChallenges["ch_caveisland_mayhem"] = { level="caveisland", file = "caveisland.xml", layers="ch_caveisland_mayhem", title=MAYHEM_TITLE, desc=MAYHEM_DESCRIPTION, unlockMission="lee_computers", } gChallenges["ch_caveisland_hunted"] = { level="caveisland", file = "caveisland.xml", layers="ch_caveisland_hunted", title=HUNTED_TITLE, desc=HUNTED_DESCRIPTION, unlockMission="caveisland_dishes", } gChallenges["ch_caveisland_fetch"] = { level="caveisland", file = "caveisland.xml", layers="ch_caveisland_fetch", title=FETCH_TITLE, desc=FETCH_DESCRIPTION, unlockMission="lee_login", } ------------------------------------------------------------------------------ -- Frustrum ------------------------------------------------------------------------------ gChallenges["ch_frustrum_mayhem"] = { level="frustrum", file = "frustrum.xml", layers="ch_frustrum_mayhem", title=MAYHEM_TITLE, desc=MAYHEM_DESCRIPTION, unlockMission="lee_computers", } gChallenges["ch_frustrum_hunted"] = { level="frustrum", file = "frustrum.xml", layers="ch_frustrum_hunted", title=HUNTED_TITLE, desc=HUNTED_DESCRIPTION, unlockMission="caveisland_dishes", } gChallenges["ch_frustrum_fetch"] = { level="frustrum", file = "frustrum.xml", layers="ch_frustrum_fetch", title=FETCH_TITLE, desc=FETCH_DESCRIPTION, unlockMission="lee_login", } ------------------------------------------------------------------------------ -- Mall ------------------------------------------------------------------------------ gChallenges["ch_mall_mayhem"] = { level="mall", file = "mall.xml", layers="ch_mall_mayhem", title=MAYHEM_TITLE, desc=MAYHEM_DESCRIPTION, unlockMission="lee_computers", } gChallenges["ch_mall_hunted"] = { level="mall", file = "mall.xml", layers="ch_mall_hunted", title=HUNTED_TITLE, desc=HUNTED_DESCRIPTION, unlockMission="caveisland_dishes", } gChallenges["ch_mall_fetch"] = { level="mall", file = "mall.xml", layers="ch_mall_fetch", title=FETCH_TITLE, desc=FETCH_DESCRIPTION, unlockMission="lee_login", } ------------------------------------------------------------------------------ -- Carib ------------------------------------------------------------------------------ gChallenges["ch_carib_mayhem"] = { level="carib", file = "carib.xml", layers="ch_carib_mayhem", title=MAYHEM_TITLE, desc=MAYHEM_DESCRIPTION, unlockMission="carib_alarm", } gChallenges["ch_carib_hunted"] = { level="carib", file = "carib.xml", layers="ch_carib_hunted", title=HUNTED_TITLE, desc=HUNTED_DESCRIPTION, unlockMission="carib_alarm", } gChallenges["ch_carib_fetch"] = { level="carib", file = "carib.xml", layers="ch_carib_fetch", title=FETCH_TITLE, desc=FETCH_DESCRIPTION, unlockMission="carib_alarm", } ------------------------------------------------------------------------------ -- Factory ------------------------------------------------------------------------------ gChallenges["ch_factory_mayhem"] = { level="factory", file = "factory.xml", layers="ch_factory_mayhem", title=MAYHEM_TITLE, desc=MAYHEM_DESCRIPTION, unlockMission="factory_espionage", } gChallenges["ch_factory_hunted"] = { level="factory", file = "factory.xml", layers="ch_factory_hunted", title=HUNTED_TITLE, desc=HUNTED_DESCRIPTION, unlockMission="factory_espionage", } gChallenges["ch_factory_fetch"] = { level="factory", file = "factory.xml", layers="ch_factory_fetch", title=FETCH_TITLE, desc=FETCH_DESCRIPTION, unlockMission="factory_espionage", } --Return list of challenges for level, sorted alphabetically with unlocked first function getChallengesForLevel(level) local ret = {} local locked = {} for id, ch in pairs(gChallenges) do if ch.level == level then if isChallengeUnlocked(id) then ret[#ret+1] = id else locked[#locked+1] = id end end end table.sort(ret, function(a,b) return gChallenges[a].title < gChallenges[b].title end) table.sort(locked, function(a,b) return gChallenges[a].title < gChallenges[b].title end) for i=1,#locked do ret[#ret+1] = locked[i] end return ret end function isChallengeUnlocked(id) local c = gChallenges[id] if c.unlockMission then return GetInt("savegame.mission." .. c.unlockMission .. ".score") > 0 end return true end function getChallengeScore(id) return GetInt("savegame.challenge." .. id .. ".score") end function getChallengeStars(id) return GetInt("savegame.challenge." .. id .. ".stars") end function getChallengeType(id) local challengeType = GetString("savegame.challenge." .. id .. ".type") if challengeType == "" then if string.find(gChallenges[id].layers, "hunted") then challengeType = "hunted" elseif string.find(gChallenges[id].layers, "mayhem") then challengeType = "mayhem" elseif string.find(gChallenges[id].layers, "fetch") then challengeType = "fetch" end end return challengeType end function getChallengeTimeleft(id) local timeleft = GetFloat("savegame.challenge." .. id .. ".timeleft") if timeleft ~= 0 then timeleft = math.ceil(timeleft*100)/100 elseif string.find(gChallenges[id].layers, "fetch") then local result = {} local scoredetails = GetString("savegame.challenge." .. id .. ".scoredetails") for parameter in string.gmatch(scoredetails, '%d+') do result[#result+1] = parameter end timeleft = result[2] end return timeleft end function getScoreDescription(score, challengeType, timeLeft) local scoreDetailsString = "" if score > 0 then if challengeType == "hunted" then if score == 1 then scoreDetailsString = GetTranslatedStringByKey("TXT_SCORE_ONE_CHEST") else scoreDetailsString = GetTranslatedStringByKey("TXT_SCORE_CHESTS," .. score) end elseif challengeType == "mayhem" then scoreDetailsString = GetTranslatedStringByKey("TXT_SCORE_VOXELS," .. score) elseif challengeType == "fetch" then local timeLeftString = string.format("%.1f", timeLeft) scoreDetailsString = GetTranslatedStringByKey("TXT_SCORE_TARGETS," .. math.floor(score)) .."\n" .. GetTranslatedStringByKey("TXT_SCORE_SECONDS_LEFT," .. timeLeftString) end end return scoreDetailsString end