LUA 3.2 in Freelancer’s Real-Time Cutscenes
When I was (much) younger, I spent an embarrassingly large amount of time playing a game called Freelancer. Freelancer was released in 2003 by Digital Anvil, then a subsidiary of Microsoft and had, up until very late in it’s development, been headed up by Chris Roberts. It had been in production for around four years prior to its release, making it, in more way than one, a spiritual precursor to Star Citizen.
Freelancer’s real-time cutscene engine takes something called thorn as its input. For a long time, no-one really looked into this too deeply, but it turns out that thorn is actually an old version (3.2) of the scripting language Lua. It also turns out that thorn.dll has complete filesystem access as well as the complete math library packaged with it. On top of this, you can execute completely arbitrary code within the cutscene scripts themselves!
This is terrible from a security perspective (malware in minecraft skin packs anyone?) but it lets us do some pretty interesting things in the cutscenes which aren’t touched on in the vanilla game.
These include day/night cycles on planetscapes using
date() and adjusting ambient lighting parameters accordingly, randomizing or dynamically adjusting the script based on input from
readfrom() and even dynamically creating groups of objects, effects and paths by inserting entries into the entities and events tables (Freelancer does this very effectively in the ‘main’ game engine, but it used to be a huge pain to make asteroid fields of any size in cut-scenes).
So far however, the most useful thing that’s been managed with it is to make scripting a bit more user friendly: most notably converting Freelancer’s notoriously scary-looking orientation matrix into a nice easy-to-adjust Euler xyz-style parameter that can be quickly changed on the fly without the need for online calculators.
Despite being very old, Freelancer still has a small, but active community of players and has some really rather interesting stuff up and coming. I’m rather holding out for a little renaissance and having an excuse to make some more neat scenes for my favorite 17 year old game.
Note: The lua helper functions mentioned in this post aren’t quite ready to go live yet, but they should be on my Github in a couple of weeks! I’ll update the post when I commit them.