Page 1 of 1

Possible to load galactic conquest from the mission list?

Posted: Sun Apr 17, 2011 8:39 pm
by Jaspo
If you look at the code below, look for where I've put in custom_gc_4 to see the concept I'm suggesting, but don't have the coding knowledge to even try to pull off (it would help if I knew what the "%s_%s",
in "geo1%s_%s", for example, is/does/references/means)
but if you could get this to work, it would open the door to having multiple custom GCs playable at once and maybe even online. Any suggestions?
Hidden/Spoiler:
[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]
EDIT: I forgot to mention what the code of this addme.lvl does as it currently stands:
mapname "..\\..\\data\\_lvl_pc\\custom_gc_4" appears in the menu, with a mode C1 mission availble for the "map"...but then trying to launch that "mission" results in a FATAL crash (of course, because the code for that part isn't correct, and that's where my scripting knowledge hits its current limit)

Re: Possible to load galactic conquest from the mission list

Posted: Mon Apr 18, 2011 9:32 pm
by [RDH]Zerted
The first %s is were the game puts the era code for the mission.
The second %s is where the game puts the game mode code for the mission.

geo1%s_%s -> geo1c_con

To add the GC's missions to the mission list, you need to know all the mission codes (geo1c_con). For those missions to work, you need to hope the custom GC doesn't do any extra map setup within the shell scripts.

Re: Possible to load galactic conquest from the mission list

Posted: Mon Apr 18, 2011 10:57 pm
by Jaspo
Ok, but the basic question here is, is it possible to put custom_gc_4.lvl in the mission list and load IT as a mission? The missions used by GC are already in the mission list, property of their respective maps.
Assuming I understood you correctly.

Edit: tried a new approach, that was to create a c1 mission script in the EGC folder which contains only 1 line of code:

ReadDataFile("custom_gc_4.lvl","custom_gc_4")

and it does work up to a point; it reads custom_gc_4.lvl, but then crashes to desktop, and a glance at the bf2 error log reveals why:

Sev 3: Unable to find level chunk "custom_gc_4"

So does that mean ReadDataFile() can only be used to load level data and not mission or other scripts?
If so, what function can be used to read scripts?
And, would I need to also add ReadDataFile("gal\\gal.lvl","whateverthenameoftheGClevelchunkis") to my custom script, if this approach is at all feasible?

Re: Possible to load galactic conquest from the mission list

Posted: Tue Dec 27, 2011 1:33 am
by [RDH]Zerted
You load lua scripts by doing ReadDataFile() on the lvl file then ScriptCB_DoFile() on the lua file. Quick Example:

funkyStuff.req

Code: Select all

ucft
{
  REQN
  {
    "script"
    "upisdown"
  }
}
Some other script file

Code: Select all

ReadDataFile("funkyStuff.lvl")
ScriptCB_DoFile("upisdown")
For some cGC maps you will need to recreate at least ScriptInit(). The shell does a lot of a GC map's initial setup (ScriptInit()) internally. If you run the map from the map selection screen, you will have to duplicate everything the shell used to do and do it inside the map's new mission script.

You didn't mention if this is your map or some random GC you downloaded online. If you don't have the map's source, it will be more difficult.

Re: Possible to load galactic conquest from the mission list

Posted: Tue Dec 27, 2011 11:23 pm
by Jaspo
Ah, it's my own, Extended Galactic Conquest.

But is multiplayer GC at all possible, even if not really feasible?

Re: Possible to load galactic conquest from the mission list

Posted: Wed Dec 28, 2011 2:02 am
by Firefang
Jaspo wrote:But is multiplayer GC at all possible, even if not really feasible?
You would have to redo many of the freeform scripts to recognize a host as the only one who can purchase anything and who controls all the fleet movements. Then create some way for people to connect to that kind of server. If it is possible, it would be a lot of work.