Skip to content

Commit

Permalink
Added RandomMissionOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
Hampo committed Jul 3, 2024
1 parent 49b1693 commit 8ce3ffe
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Randomiser/Meta.ini
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,15 @@ Tooltip=Randomises the case of all text in the game.
Page=Chaos Randomisations
Group=Text

[Setting]
Name=RandomMissionOrder
Title=Random Mission Order
Type=TickBox
Default=0
Tooltip=Randomises all the mission order per level.
Page=Chaos Randomisations
Group=Missions

; Car pools - I hate this


Expand Down
65 changes: 65 additions & 0 deletions Randomiser/Resources/Modules/Chaos/RandomMissionOrder.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
local math_random = math.random
local string_match = string.match
local table_concat = table.concat
local table_remove = table.remove
local tonumber = tonumber

local RandomMissionOrder = Module("Random Mission Order", "RandomMissionOrder")

local MissionOrder = {}

if Settings[RandomMissionOrder.Setting] then
for level=1,7 do
MissionOrder[level] = {}

local Missions = {1, 2, 3, 4, 5, 6, 7}
for mission=1,7 do
local index = math_random(#Missions)
MissionOrder[level][mission] = Missions[index]
table_remove(Missions, index)
end
end
print("Random mission order:")
for level=1,7 do
print("", "Level " .. level .. ":", table_concat(MissionOrder[level], ", "))
end
end

RandomMissionOrder:AddP3DHandler("art/frontend/scrooby/resource/txtbible/srr2.p3d", function(Path, P3DFile)
local FrontendTextBible = P3DFile:GetChunk(P3D.Identifiers.Frontend_Text_Bible)
if not FrontendTextBible then
return false
end

for FrontendLanguage in FrontendTextBible:GetChunks(P3D.Identifiers.Frontend_Language) do
for level=1,7 do
local MissionTitles = {}
for mission=1,7 do
MissionTitles[mission] = FrontendLanguage:GetValueFromName("MISSION_TITLE_L" .. level .. "_M" .. mission)
end

for mission=1,7 do
FrontendLanguage:SetValue("MISSION_TITLE_L" .. level .. "_M" .. mission, MissionTitles[MissionOrder[level][mission]])
end
end
end

return true
end)

RandomMissionOrder:AddLevelHandler(function(LevelNumber, LevelLoad, LevelInit)
local functions = LevelLoad.Functions
for i=1,#functions do
local func = functions[i]
if func.Name:lower() == "addmission" then
local MissionNumber = tonumber(string_match(func.Arguments[1], "m(%d)"))
if MissionOrder[LevelNumber][MissionNumber] then
func.Arguments[1] = "m" .. MissionOrder[LevelNumber][MissionNumber]
end
end
end

return true
end)

return RandomMissionOrder
1 change: 1 addition & 0 deletions Randomiser/Resources/Modules/General/SettingsInfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ local AudioVisualSettings = {
local ChaosSettings = {
[1 << 1] = Settings.RandomText,
[1 << 2] = Settings.RandomTextCase,
[1 << 3] = Settings.RandomMissionOrder,
}

local GameplayN = 0
Expand Down

0 comments on commit 8ce3ffe

Please sign in to comment.