[code]-- recursively merges the second given table into the first given table
function MergeTables( mission, newFlags )
--for each table entry,
local array = type({})
for key,value in pairs(newFlags) do
--check for nested tables
if type(value) == array then
--mission must have this key as a table too
if type(mission[key]) ~= array then
mission[key] = {}
end
--merge these two tables recursively
MergeTables(mission[key], value)
else
--the key is a simple variable, so simply store it
mission[key] = value
end
end
end
--Search through the missionlist to find a map that matches mapName,
--then insert the new flags into said entry.
--Use this when you know the map already exists, but this content patch is just
--adding new gamemodes (otherwise you should just add whole new entries to the missionlist)
function AddNewGameModes(missionList, mapName, newFlags)
for i, mission in missionList do
if mission.mapluafile == mapName then
MergeTables(mission, newFlags)
end
end
end
AddNewGameModes(sp_missionselect_listbox_contents, "geo1%s_%s", {era_g = 1, mode_con_g = 1,})
AddNewGameModes(sp_missionselect_listbox_contents, "dea1%s_%s", {era_g = 1, mode_c1_g = 1,})
--insert totally new maps here:
local sp_n = 0
local mp_n = 0
sp_n = table.getn(sp_missionselect_listbox_contents)
sp_missionselect_listbox_contents[sp_n+1] = { isModLevel = 1, mapluafile = "EGC%s_%s", era_g = 1, mode_assault_g = 1,}
mp_n = table.getn(mp_missionselect_listbox_contents)
mp_missionselect_listbox_contents[mp_n+1] = sp_missionselect_listbox_contents[sp_n+1]
sp_missionselect_listbox_contents[sp_n+2] = { isModLevel = 0, mapluafile = "..\\..\\data\\_lvl_pc\\custom_gc_4.lvl", era_g = 1, mode_c1_g = 1}
mp_n = table.getn(mp_missionselect_listbox_contents)
mp_missionselect_listbox_contents[mp_n+2] = sp_missionselect_listbox_contents[sp_n+2]
-- associate this mission name with the current downloadable content directory
-- (this tells the engine which maps are downloaded, so you need to include all new mission lua's here)
-- first arg: mapluafile from above
-- second arg: mission script name
-- third arg: level memory modifier. the arg to LuaScript.cpp: DEFAULT_MODEL_MEMORY_PLUS(x)
AddDownloadableContent("EGC","EGCg_Diet Dr. Pepper",4)
AddDownloadableContent("geo1","geo1g_con",4)
AddDownloadableContent("dea1","dea1g_c1",4)
AddDownloadableContent("..\\..\\data\\_lvl_pc\\custom_gc_4.lvl","custom_gc_4",4)
-- all done
newEntry = nil
n = nil
-- Now load our core.lvl into the shell to add our localize keys
ReadDataFile("..\\..\\addon\\EGC\\data\\_LVL_PC\\core.lvl")
[/code]