Another unimaginatively named idea from the mind of WMCoolmon

.
This is something I've had in the back of my mind for a few weeks...but only really fleshed it out while I was in the shower tonight (If you'll pardon the pun

)
First the TBL (timescript.tbl?)
#Timescripts
$Name: Example
;;Immediately show "Example script" for 10 seconds
0: [
--A lua script, note my double-dash comment.
--We can do some stuff here with scripting. For example:
grpc.text("Example script",0,0)
]
+Duration: 15 ;;Show text for 15 seconds
;;After 10 seconds of script activation...
10: [grpc.line(0,0,640,480)]
+Duration: 4.5 ;;...draw a line for 4.5 seconds
;;After 20 seconds of script activation...
20: [grpc.text("Goodbye!", 0, 0)]
+Duration: 2 ;;Say goodbye for 2 seconds (Don't seem too desperate!)
$End ;;End this one, so we can begin another
Pretty self-explanatory. Would obviously require more scripting functions to be really useful, however, the fun thing is that you could call a Timescript from a SEXP or a script relatively easily.
+Duration makes it extremely useful, because you can actually do graduated movement, assuming I pass a "tse" variable for the current timescript entry progress. (And assuming a setshipposition thingamajigger gets implemented).
;;Moves a ship forward from starting position at 15 m/s, presumeably in global coords.
15: [ShipHandle.setPosition(ShipHandle.getPosition("X"),ShipHandle.getPosition("Y"),ShipHandle.getPosition("Z")+15*fs2.getFrameTime()]
Even more fun...after thinking about this a bit, I've realized that the Lua VM probably does store global variable values between frames. So if, say, you made an animation script for a ship to do a jig...you could in theory make the TimeScript apply for multiple ships by setting a global ship handle variable used in the TimeScript before calling the TimeScript.
Now some data structs that could be improved on to allow multiple executions of the same timescript at once:
class TimescriptLib
{
private:
std::vector<Timescript> scripts;
public:
scriptid AddScript(script);
void ActivateScript(scriptid);
void DoFrame();
};
typdef struct Timescript
{
float activation_time; //Mission time of activation
int current_entry;
//"Static"
char name[NAME_LENGTH];
std::vector<TimeEntry> entries;
};
typedef struct TimeEntry
{
//Reusable variables
float activation_time; //This is relative to script activation time (ie 10 s past, rather than mission 2:10
float remaining_time;
//"Static" variables
float duration;
script_hook action;
};
Hopefully I'll think up a better name before I implement it.
