Hard Light Productions Forums

Modding, Mission Design, and Coding => Help Wanted/Offering Help => Topic started by: krevett62 on January 28, 2018, 05:52:31 am

Title: Random mission generator
Post by: krevett62 on January 28, 2018, 05:52:31 am
Hi all, I'm currently trying to work on a random mission generator for our favorite game ;)
The goal is not to create very advanced mission involving many sexps, but to allow the creation of simple missions of 5 basic types, with simple sexps just for testing purpose.

As I don't have any coding skills I'm doing it using an excel sheet with a macro to generate the file. It's nothing spectacular for now but I'm able to generate a readable mission file for one type of mission (with just fighters for now).
The downside of this method is that you don't read vp's so data has to be entered beforehand (but the sheet already contains standard FS2 data as well as some custom).
All data in the lists are optional during mission generation so you can add multiple mod to the data tables and just select the data that will be used with userforms.

How it works:
The sheet contains a "Data" and a "Name" sheet that contains class names for weapons and ships by category, and names for wings/individual ships.
When you generate the file it prompts userforms to allow options and to select the savefile.
It then write to the file with parameters generated depending on the type of mission and difficulty.

I just started working on it yesterday but I can already generate a small "patrol" mission with one line briefing, enemy wings spawning after a timer elapsed, and directives appearing to destroy those wings.

Main functions are being implemented to add more variety, and many parameters are still not working.
It does not generate background for now but options are in to allow it at later time.

If people are interested to lend a helping hand I'd be happy to share it ;)
Title: Re: Random mission generator
Post by: potterman28wxcv on January 28, 2018, 07:14:42 am
Just imagine the possibilities if there was a way to include mission generation code (e.g. in Python, or another interpreted script language) directly within Freespace SCP.. You could vary the content of missions dynamically based on the results of the previous one, or actually have random generation integrated in a campaign, or play a mix of turn-based with real time battles.. In terms of modding it would be heaven.

I know it's a huge amount of work.. But a man can dream  :)
Title: Re: Random mission generator
Post by: wookieejedi on January 28, 2018, 10:34:28 am
Hi all, I'm currently trying to work on a random mission generator for our favorite game ;)
The goal is not to create very advanced mission involving many sexps, but to allow the creation of simple missions of 5 basic types, with simple sexps just for testing purpose.

As I don't have any coding skills I'm doing it using an excel sheet with a macro to generate the file. It's nothing spectacular for now but I'm able to generate a readable mission file for one type of mission (with just fighters for now).
The downside of this method is that you don't read vp's so data has to be entered beforehand (but the sheet already contains standard FS2 data as well as some custom).
All data in the lists are optional during mission generation so you can add multiple mod to the data tables and just select the data that will be used with userforms.

How it works:
The sheet contains a "Data" and a "Name" sheet that contains class names for weapons and ships by category, and names for wings/individual ships.
When you generate the file it prompts userforms to allow options and to select the savefile.
It then write to the file with parameters generated depending on the type of mission and difficulty.

I just started working on it yesterday but I can already generate a small "patrol" mission with one line briefing, enemy wings spawning after a timer elapsed, and directives appearing to destroy those wings.

Main functions are being implemented to add more variety, and many parameters are still not working.
It does not generate background for now but options are in to allow it at later time.

If people are interested to lend a helping hand I'd be happy to share it ;)

I would suggest using LUA, it will be immensely helpful in this endeavor, trust me. I did not know programming much beyond R and Excel but was able to pick up LUA and, over the past year, I have been able to integrate it with when-argument sexps to create something with random generation and player persistence (ie the player gains rank, fleet grows, previous missions affect next missions). If you would like I can give you some extra pointers that I found out the hard way.
Title: Re: Random mission generator
Post by: krevett62 on January 28, 2018, 11:00:33 am
Your system seems very interesting indeed but it's a different approach if i understand you're using the built-in lua system to alter existing missions and track player through a whole campaign. You still need to create a mission in fred and add random elements via scripting. I didn't thought about that.

My generator on the other way don't start from an existing mission but attempts to create a .fs2 file from scratch.
Taking both method might lead to intersting things ^^ for now i focus on getting playable random missions with the generator, then i'll perhaps look into lua.
Title: Re: Random mission generator
Post by: wookieejedi on January 28, 2018, 11:03:46 am
Your system seems very interesting indeed but it's a different approach if i understand you're using the built-in lua system to alter existing missions and track player through a whole campaign. You still need to create a mission in fred and add random elements via scripting. I didn't thought about that.

My generator on the other way don't start from an existing mission but attempts to create a .fs2 file from scratch.
Taking both method might lead to intersting things ^^ for now i focus on getting playable random missions with the generator, then i'll perhaps look into lua.

I probably didn't explain that well...my bad. My generator uses lua to create a new mission each time (ie new .fs2 file). And it uses a template, thus once the mission is created nothing has to be changed and it can be played directly. If Excel works for you then I would say go with it! To each their own :)
Title: Re: Random mission generator
Post by: krevett62 on January 28, 2018, 11:07:54 am
Ok i understand better, well your idea is probably better as it allows more things to be done (as lua can access much more data related to the game).
But i'll need to learn lua more seriously if i have the time ^^
Title: Re: Random mission generator
Post by: wookieejedi on January 28, 2018, 11:14:01 am
Ok i understand better, well your idea is probably better as it allows more things to be done (as lua can access much more data related to the game).
But i'll need to learn lua more seriously if i have the time ^^

Excel might work better for allowing someone else to use it though, especially if macro buttons are used. It all really just depends on your ultimate goal for the generator I think. Mine is more of a self sustained black box, whereas I think you  want yours to me more available as a tool to the public?
Title: Re: Random mission generator
Post by: krevett62 on January 28, 2018, 11:54:20 am
Well for now it's a simple entertainment, i'll see how far it can go and perhaps release it if i find it useful.

For now it's not really functionnal (it generates only a mission with a bunch of fighter wings spawning at random time to random place within an ally's range, directive to destroy spawning wings and a random background. All ship classes are set random from a list you choose from before generating the mission) but i'd like to be able to make escort and assault missions.
Also by using lists to select from you can add as much ship and weapons classes as you want (you can choose to select them or not if they appear in the mod you intent to run the mission with).

And as i said in my first post if someone is willing to help i can share the unprotected file (i try to comment the code as much as i can) there's no secret and still much much work to do ;)
Title: Re: Random mission generator
Post by: wookieejedi on January 28, 2018, 01:36:49 pm
Well for now it's a simple entertainment, i'll see how far it can go and perhaps release it if i find it useful.

For now it's not really functionnal (it generates only a mission with a bunch of fighter wings spawning at random time to random place within an ally's range, directive to destroy spawning wings and a random background. All ship classes are set random from a list you choose from before generating the mission) but i'd like to be able to make escort and assault missions.
Also by using lists to select from you can add as much ship and weapons classes as you want (you can choose to select them or not if they appear in the mod you intent to run the mission with).

And as i said in my first post if someone is willing to help i can share the unprotected file (i try to comment the code as much as i can) there's no secret and still much much work to do ;)

Nice. That's a good feature, and I wish you the best of luck with your progress!
Title: Re: Random mission generator
Post by: AdmiralRalwood on January 29, 2018, 09:57:39 am
I have an incomplete random mission generator written in python... somewhere... it was very, very simple. To be honest, the most advanced part of it was the squadron name generator, intended for the briefing.
Title: Re: Random mission generator
Post by: wookieejedi on January 29, 2018, 11:52:19 am
Nice. Writing the custom briefing generator based on script generated ships selection, system name, enemy and friendly strength, and mission objectives made me realize how simple the sentences had to be in order to be modular  :lol:
Title: Re: Random mission generator
Post by: krevett62 on January 30, 2018, 06:52:14 am
Well after 3 days here's a sample mission file generated with it.
A bit buggy but can be opened without errors in FRED and in FSO.

Still missing many things I'm currently working on (briefing and debriefing sections as well as global success and failure events for now don't pay attention to these ^^), but wing writing and directives are working as intended.

Things I'm currently working on:
*write briefing and debriefing sections
*add individual ships to missions for variety (code already written, must add random names ^^) as well as sentry guns for assault (base type)
*generate other types of missions (assault, escord and defend are my priorities)
*add more arrival events sexp types
*generate working goals ("success" and "failure" sexps events)
*better random background generator (not my top priority for now)
*other ideas i'll find while working ;)


Edit: BTW I know some of you have some imagination ^^ I'm after a list of names (friendly ans hostile alike) for single ships (cruisers, transports, capital or installation)


[attachment stolen by Russian hackers]
Title: Re: Random mission generator
Post by: HLD_Prophecy on January 30, 2018, 01:08:32 pm
Wow, this looks like an intriguing and entertaining idea. You're good with coding krevett!  :yes:
Title: Re: Random mission generator
Post by: krevett62 on January 30, 2018, 01:50:33 pm
Thanks but i'm not that good you know just looking here and there learning some tricks but i'm not a serious scripter (my former school course is about physics and chemistry nothing about computers lol) anyway you're right its intriguing and entertaining that's why i'm playing with that ^^
Title: Re: Random mission generator
Post by: krevett62 on January 31, 2018, 12:09:43 am
Ok i've encountered a little problem. It probably has to do with the way I write data to the file but it really bugs me out ^^

Let me explain, if I generate a file fresh from the generator and play it directly in FSO, first I can't select my ship/weapons as wings are blanked out in the selection screen (but I can press continue and play with the default ship that was assigned without knowing wich it is). And second arrival cues of wings don't work at all, every ship is here from start and directives to destroy them don't appear.

However, if I open the file in FRED first and just save it under the editor (without even doing anything to it), everything works as intended.

What bugs me out is that there must be a formatting error somewhere, but then why does FRED opens the file without even complaining? Or perhaps a missing important line?

Here is an example (I post the files because copying the text is too long for the forum):
Mission-Copie.fs2 is the untouched generated file
Mission. fs2 is just Mission-Copie.fs2 opened in FRED and saved immediately (without opening a single menu)

Mission.fs2 works as it should but not the original (but it is read by FRED, wings, arrival cues, everything is there). Does anyone sees where the problem lies (someone who knows how mission files are parsed by the FSO engine).

I'm probably missing to write an important line somewhere...

Edit: added the generator in it's current state if someone is curious (there's no readme but I tried to comment the code as much as I could) please bear in mind that I still have some functions to add and the random thing for now is just putting values to test the functions (only patrol and escort options are valid).

[attachment stolen by Russian hackers]
Title: Re: Random mission generator
Post by: karajorma on January 31, 2018, 02:07:35 am
FRED is pretty good about correcting errors. There are lots of differences between the generated mission and the one you have resaved in FRED.

Nothing immediately leaps out at me as the cause of the problem but I did notice you have been writing the arrival cues for ships in wings as true. If you set those to false you can now loadout your ships. But they don't appear by default so that is only half of the problem solved.
Title: Re: Random mission generator
Post by: krevett62 on January 31, 2018, 03:55:16 am
Well indeed I will take a look at the arrival cues.
Main differences include subsystem listing but it does not prevent the ships from using their turrets with default weapons listed in the tbl (as far as I have tested).
Thanks for taking a bit of your time to look at the mission ;)
Title: Re: Random mission generator
Post by: krevett62 on January 31, 2018, 10:56:01 am
Well I feel silly to not have seen this before, thanks karajorma! Settings arrival cue to false for ships that belong to wings solved all the problems ^^ (In fact wings had their arrival cue already set so the second part was not really a problem)
Title: Re: Random mission generator
Post by: woutersmits on February 02, 2018, 03:23:26 pm
nice job
make it so it generates story campaign
Title: Re: Random mission generator
Post by: wookieejedi on February 02, 2018, 04:20:40 pm
nice job
make it so it generates story campaign

So this is quite difficult...I would suggest if you want a story campaign generator, perhaps try making one yourself?
Title: Re: Random mission generator
Post by: potterman28wxcv on February 04, 2018, 07:27:54 am
nice job
make it so it generates story campaign

So this is quite difficult...I would suggest if you want a story campaign generator, perhaps try making one yourself?
That looks like actual research to be honest. Procedural story generation.
Title: Re: Random mission generator
Post by: woutersmits on February 04, 2018, 07:33:53 am
if mission generator its posseble then campgen too with story it will be nice if soo
Title: Re: Random mission generator
Post by: karajorma on February 04, 2018, 07:44:17 am
I'm sure you can generate a story at random. Generating a good story is another matter.
Title: Re: Random mission generator
Post by: krevett62 on February 04, 2018, 07:56:58 am
Indeed producing a good story would be really hard.
Already getting a passable random mission is a hard task so making a campaign is really out of scope ^^

Edit: and i'm probably lacking the writing skills needed to do such a thing...

Edit: btw the generator has improved quite a bit (in functions and possibilities) but is still lacking input for mission generation (i focus first on getting things doable and then generating something from existing functions become easy)
Patrol, escort and assault should now be possible (just need to add random data to these functions), more orders are possible for wings and individual ships and a success event is now added depending on the goals of the mission.
Title: Re: Random mission generator
Post by: Novachen on February 04, 2018, 08:09:14 am
I am not sure, why you need a story campaign generator... it do not look like we are lacking campaigns here.

I would say... play some auto generated missions in a row and imagine a story to it yourself ^^. This works in several other games with its skirmish modes for years.
Title: Re: Random mission generator
Post by: potterman28wxcv on February 04, 2018, 08:32:31 am
if mission generator its posseble then campgen too with story it will be nice if soo
Generating a campaign with story randomly is as hard as generating a random book. You can generate a random campaign just like you can generate random sentences of gibberish ; but generating a proper story is far more complicated than it might look. We're not talking of random generation anymore, but more of grammar and linguistics, as well as sentence semantics.. Maybe Google will achieve it one day.. But for now it's not possible.
Title: Re: Random mission generator
Post by: Bryan See on February 04, 2018, 09:57:29 am
What about AI and machine learning? Will this solve this problem?
Title: Re: Random mission generator
Post by: The E on February 04, 2018, 09:59:25 am
What about AI and machine learning? Will this solve this problem?

No. You are welcome to try though.
Title: Re: Random mission generator
Post by: Bryan See on February 04, 2018, 11:18:14 am
Yeah. If I can do it through AI, then it would be better.
Title: Re: Random mission generator
Post by: karajorma on February 04, 2018, 11:25:16 am
Go for it, but make your own thread for it. Leave this one to the mission generator.
Title: Re: Random mission generator
Post by: Bryan See on February 04, 2018, 11:36:38 am
Yeah. Maybe in the scripting section. And that would be good for "procedural" missions.
Title: Re: Random mission generator
Post by: wookieejedi on February 04, 2018, 11:39:18 am
Yeah. Maybe in the scripting section. And that would be good for "procedural" missions.

I am sure people would be happy to tell you their thoughts about a set of scripts you post there  :)

As for this generator I am glad to hear you are making good progress, krevett62! It's always cool to see others working on similar projects with different approaches!
Title: Re: Random mission generator
Post by: Bryan See on February 04, 2018, 12:05:51 pm
Yeah. Maybe in the scripting section. And that would be good for "procedural" missions.

I am sure people would be happy to tell you their thoughts about a set of scripts you post there  :)

As for this generator I am glad to hear you are making good progress, krevett62! It's always cool to see others working on similar projects with different approaches!
Thanks for that.
Title: Re: Random mission generator
Post by: Nightmare on February 04, 2018, 01:12:13 pm
This looks really interesting. :)

If you're still looking for ship names, you can take a look at wikipedias category sites, like "Category: Greek mythology".
Title: Re: Random mission generator
Post by: krevett62 on February 04, 2018, 01:20:32 pm
Thanks for the idea i'll take a look in fact i'm searching for names with various styles (but nothing is locked the generator is made so that the user can add or replace existing data with his own)