Expanding your Missions

If you've had Flight Simulator X for a while, all but the most incurious have probably tried a mission or two. If you haven't, now's the time – go try one out! Calling them 'missions' is probably a bit grand; they can be anything from a full storyline taking an hour or more to finish, down to a simple test taking only a few minutes. They can be a bit of harmless fun, or something that would test the skills of virtual pilots to the limit.

If you've tried any at all, chances are you've long since run out. Some of the braver among you might have tried writing your own missions. If not, you really should give it a go – I can thoroughly recommend trying the FSX Mission Editor for three good reasons: first, it makes life much easier for mission authors; second, it's free to try and lastly because I wrote it! Even with a tool like this (and there are others too), there are some things that are difficult or just impossible to do with the mission-writing commands that Microsoft supplied. Happily, they thought of that and allowed people to add their own commands to FSX' mission system. This article is about one such extension.

Don't run away just yet if you've never tried to write your own missions though. I'll discuss some of basics here before getting into any of the more advanced stuff that the SimVar extension can do.

Existing System

The standard mission system is part of the normal simulator package, there's nothing you need to do to enable it. For those who have never tried one, a 'mission' is basically a set of tasks which have to be completed, strung together with appropriate speech, scenery and computer-controlled vehicles. What with computers being the way they are, the mission is written in a rather complicated-looking language; happily, various tools are available which make this easier. One is even included as a standard part of FSX Deluxe.

Conceptually, a mission is made up of a collection of three different groups of things: Triggers, Actions and Other Stuff. These get linked together in a way which only allows the player to progress when they do the right things, in the right order.

A Trigger, for example, might be watching to see if the player has flown into a certain area, or is above a certain altitude, or has landed. An Action might be to show a message, or to make part of the plane fail, or to switch a Trigger on or off. The 'Other Stuff' could be bits of scenery that help to set the scene.

Microsoft provided a smallish set of these commands which let you control the simulated world to some degree. This was good because there weren't many to learn, but at the same time it was bad because it could get a little tricky working out how to make more complex sequences work. In their defence, it often was possible, but something that seemed logically simple could take a dozen commands to actually get working properly.

Limitations

On the other hand, some things simply couldn't be done. The best example is what Microsoft called a 'Property Trigger'; this simply means that the mission system is told to watch a certain property, usually of the player's plane, and do something when the property reaches a certain value. You might, for example, tell it to show a message if you get below 200 feet altitude or if the oil pressure is low. Now, if you read the mission author's manual that comes with FSX it lists many hundreds of different things that can be tested, covering every system in every type of aircraft, and all manner of environmental values such as air pressure and temperature, time, wind speeds etc. Fantastic – except that the Property Trigger only allows you to test about 40 of the nearly 900 possible values. An important part of my test mission was to test whether the landing lights were on, and I just couldn't do it.

I also found it was almost impossible to control the aircraft in many ways I wanted to. The standard mission commands allow you to make bits fail but not much else. However, if you've ever tried the flying lessons that come with FSX (under the Learning Center, if you've not found them already), the plane not only flew itself from time to time but the radios and autopilot were sometimes set for you. OK, so the simulator can do it but not from a mission – exactly where you might want to! You might want, for example, to write a long-haul mission where a co-pilot handles all of the radios for you. Surely this should be possible – but no.

Ways Round

I don't like taking no for an answer, especially when I can see that what I'm asking is perfectly achievable. I started looking through Microsoft's manuals on how to write extra commands for the mission system and it didn't look too tricky. What I decided eventually was that rather than creating specific commands for the things I wanted to check, I'd create a small number of powerful commands which would allow mission writers to access anything that the simulator allowed. That's a lot easier from my point of view, and a lot more flexible from the mission author's point of view, because you don't need to hope that the right command has been added. For example, if I'd added one command to check the landing lights, it would have been useless to check if the panel lights were on. It also allows the same extension code to be used across many different missions so that the 'helper' program, the one adding the extra commands, only needs to be installed once.

So, basically the SimVar extension allows a mission author full control over the simulation, to the limits of what Microsoft allowed, and far beyond the limits of the standard mission commands.

Having said that, there are a collection of other, more specific commands to do things that would have been tricky to do any other way. I'll describe some of them later.

New Commands

So, what are the actual new commands? There aren't very many, in fact less than twenty, but they expose pretty much every feature of the simulator. I'll cover some of the specific ones first, because they're simpler.

Simple Controls

To start with the simplest ones, they allow you to change the simulation rate, and time of day. Simple indeed, but perhaps more important than you might think. Have you ever flown a mission which has a long flight section where not much happens? Have you ever use the rate control to speed time up to cover that 20 minute stretch in five minutes? It's the obvious thing to do. Here's the problem: you complete the long flight and get three messages in a row telling you what to do next, and then you fly into an area which makes the next part of the mission start, then something else happens. All at four or eight times faster than real-time. So, you don't get to hear all the instructions and before you know it you've failed the mission because you flew into a forbidden area. Well, using the first of the extra commands you can prevent this by telling the sim to go back into real-time flying before doing anything important.

There are other commands to deal with displaying messages, creating a very controlled fuel leak and a new camera view which makes sure that two different planes are in view at the same time.

More Complex Controls

Another group allow you to change the simulated environment. You can change the weather during a mission instead of just choosing a theme which lasts for the whole time. One thing that there's been a lot of interest in is controlling AI – that is, computer-controlled – aircraft. The standard mission system lets you set up AI which follow a pre-set path in the mission, or record a flight and play it back during a mission. That's fine up to a point, but what if you need a plane to do something in relation to the player's plane? It's all very well assuming that the player's following your expected path exactly, but chances are they're not. You end up with messages like “Now follow the Cessna to your left” when in fact it's on the right, or three thousand feet below, or twenty miles away.

Well, SimVar gets round this by letting you tell AI planes to fly to a point relative to the player, and even to try and stay there. That means you can have a 'wingman' in your missions; maybe an instructor, or a guide, or a border patrol plane which follows you as you weave around trying to lose it.

Remembering things

One thing I wanted to do right from the start was to get Flight Simulator to remember what had happened in one mission and use it to change what happens in another. That would let people create storylines, built up over several missions, where each could change itself slightly depending on the player's choices in previous missions.

To start with, SimVar lets you remember things inside a single mission. You can set a flag which says “the player went along route 1” or “the player went along route 2”, for example, and there's no limit to what you can get it to remember. Later in the same mission, you can get it to check any of these values and choose to do one thing or another based on what happened earlier.

The next trick is that anything you set in this way gets saved to disk when the mission is finished. By using another new command you can get another mission to read that file when it starts. This means that anything you set in one mission can be read in another, giving the possibility of a continuing storylines! Even better, the file that stores the settings can be used to change the mission briefings too.

Imagine your first mission lets the player land at one of three different airports. By saving some indication of which airport was used, the second mission can be set to start at the correct airport. The mission briefing for the second mission can even say “Take off from <insert airport name here>, fly towards...”!

With the newest version of the SimVar extension, you can also make sure that the file that stores these values isn't changed between missions by cheats.

Examples

So, what's this like in practise? How easy is it to use? Well, I'd say it was just as easy as using any of the other mission commands, and considerably easier if you're using the FSX Mission Editor! Remember though, it's still perfectly possible to use the original Microsoft tools. I'll use some screenshots here from the visual editor, simply because it's easier to understand.

Let's see some specific examples of how to control things that are impossible without using this extension.

Cockpit Control

Here's a nice simple one to start with. All the new commands are sent as CustomActions. This is a special type of action which FSX doesn't do anything with itself, it just asks around to see if anything else wants to deal with it. You can put anything you like into a CustomAction, and that's how SimVar gets it's instructions.

This one uses the EVENT command to tune the NAV1 radio:

Those of you familiar with the CustomAction command will know that it only has one bit of information passed to it, the “PayloadString”. If you look in the Attributes window in this screenshot, you'll see several more which are obviously specific to the EVENT command. Where did they come from? They're a feature of FSXME. It allows you to define templates for CustomAction commands for any extension, not just SimVar, so that they're easier to read. In this case, the important ones are labelled “AI Plane”, “Event Name” and “Data”.

AI Plane” is left blank. This tells SimVar to do whatever it is that needs done to the player's plane, rather than any computer-controlled plane. The “Event Name” comes straight from Microsoft's SDK documentation (here to be precise) , and tells the simulator to tune a radio. The last, “Data”, is a little more vague.

Because the “Event Name” can be set to one of many hundreds of different events, the “Data” value can mean lots of different things. In this case it is a radio frequency but other events might want a true/false value as 1 or 0, an engine number, a percentage or even not use it at all. The value here, 0x1010, corresponds to a radio frequency. Unfortunately this isn't one of the better documented parts of the SDK. I'll skip the exact reasons why for now, but the value of “0x1010” corresponds to a frequency of 110.10 MHz.

So, this specific command tunes the NAV1 radio to 110.10 MHz. However, the EVENT command is much more powerful than this. Because you can use any of the events listed in the SDK, you can control almost every aspect of the aircraft with this one command. Although that means a slightly higher learning curve, I believe it's better this way than adding hundreds of individual commands to control different things. Some of the more obvious ones are tuning the radios, setting the autopilot, controlling the GPS or the engines.

AI Control

Here's a more interesting one. Anyone who's tried to use AI (computer-controlled) aircraft in a mission will know that they can only be set of along predefined paths. Sometimes that might be OK, but what if you want them to interact with the player? If they've flown off on a slightly different route, the AI planes will be in the wrong place. SimVar gives you a way to fix this.

The AI aircraft itself is the green box at the top of the screenshot – this is completely standard FSX mission material. The 'special sauce' is the SimVar command in pink at the bottom. It looks as though there's lots to understand, but it's simpler than it appears. You tell it whether to maintain position or to intercept the target plane, what plane to control and what plane to target, whether to update the position or not, and how far away it is supposed to get.

This gives quite a bit of flexibility. Let's see what this particular command does.

The AI with the tail number of “N71FS” is told to maintain position relative to “N208BC”. That means that once it gets close, it will try to match speed and direction as well as position. Next, it's told to update the position it's heading for once a second so that as N208BC flies around, N71FS will follow it. Last, it's given an “Offset X” value of -100 meters – that's 100 meters to the left. In short, N71FS will follow N208BC wherever it goes, trying to stay 100m to the left of it at all times.

What else could you do? Of course, you could tell it to follow the player instead of another AI. You could tell it to intercept instead of maintain position, so that it just flies as fast as it can to a point in space (think of a guided missile). If you had “Set Once” instead of “Update once per second”, N71FS would act as an unguided missile, flying straight towards wherever N208BC happened to be when the command was issued.

You can of course tell things to stop following something too, and return control to FSX so that it can fly the AI plane off to a known location, maybe to an airport to land.



















New Tests

One of the more important missing features of the original Microsoft commands is the ability to test any aspect of the simulation. They provide a command called a “PropertyTrigger” which allows you to test less than forty things. These are the most common things, for example altitude, airspeed or heading, but if you wanted to check something else you were out of luck. What if you want to check that the lights are on, or the autopilot is enabled, or the player's cheating by using slew mode?

Enter the SimVar IF command. Similar to the EVENT command, this allows you to check one of nearly 800 different values – almost everything that the simulation allows. The full list is here. You can check things in different ways – equal, greater than etc. - and, unlike the original command, you can have “IF … THEN … ELSE” sequences. There's really not much more to it than that, but as with the EVENT command I wanted to open the full power of the simulator as simply as possible.





Remembering Things

That seems like an odd thing to want to do. What do I mean by “Remembering things”?

Well, let's say your mission has two possible ways to finish it, and the player decides which to follow early on. Rather than writing the same ending twice, you might want to use the same ending but only change some of the speech. Or, you might want to remember the time it took to do something, or the altitude the player was at at a certain point, or pretty much anything else you can think of. (There's more to it than this, bear with me!)

SimVar provides a PROFILE command, which allows you – or FSX, to be precise – to remember things. Think of a profile setting as a sticky-note with a name, which you can refer back to later. Most simply, you can set a profile value with a known meaning, such as “Route 1” or “Route 2”. Here's where the powerful part comes in: you can then use that profile value in most SimVar commands later in the mission. How would that look? Let's think about the changing messages.

This picture shows just that. It's using exactly the same IF command as you would use with simulation variables (altitude, autopilot controls etc.) but now it's checking a profile value instead. Based on what you set “MyRoute” to earlier in the mission, the player would get one or the other of the two messages. This particular example could actually be done in other ways using the standard commands, the idea is just to have a simple example.

Let's add a little extra to it. A Profile value doesn't have to be set to a known value (such as “Route 1”). It can be set to the value of a simulation variable, or another profile value. How does that help? Well, you can base decisions later in the mission on what the player was doing earlier. You might want to disable a bonus section of the mission if the player used autopilot earlier, for example. There are some more things, though, that really make the Profile values stand out.

First, you can do arithmetic with them. Want to work out the average time over several flight segments? Sure thing. The total amount of time spent on the ground? No problem. Experienced mission designers might be thinking “Pah! You can do that with TimerTriggers and CounterTriggers”. True, but only up to a point. Let's say you have varying degrees of success in a mission. My test mission had you collecting up to 20 people while under fire at a remote airfield. The longer you stayed on the ground, the more people you rescued. Let's say you want to give a different medal for different numbers of people rescued. With a CounterTrigger, you'd need lots of different triggers. More triggers means more to go wrong, and more to test, and a more complicated mission. Using a profile value you can simply say “Rescued = Rescued + 1”, and then later “IF Rescued < 7 THEN (show a message saying 'hopeless')”.

The second thing you can do with a profile value is share it with another mission. This opens up a world of possibilities; you can string a storyline out across many missions, but have each mission alter the way it works based on what happened in earlier missions. Let's say you record the amount of fuel left at the end of mission 1. At the start of mission 2, you can use the EVENT command to set the fuel levels to be the same. And because the EVENT command has control over almost anything, there's very little you can't change in this way. You could start at different airports, change the weather or time, cause aircraft system failures... whatever you can think of. I've used it a couple of times to create a high-score, where the best time over a circuit gets recorded.

Which leads neatly onto another great feature of the PROFILE command. When it records the values, they are stored in a plain XML file along with the mission. With some suitable editing, you can use these values in the mission briefing! I won't go into the exact details, but in short you can create an XSL file which formats the XML any way you want, and then include the XML in your mission briefing using an IFRAME. Here's an example:


Finally

This is just a taster of what you can do with the SimVar extension. Although there aren't that many new commands, they've been designed to give you as much power as possible over the entire simulator, so that the only limit is what you can dream up to do with it. If you've never tried writing your own missions, don't worry if the last half of this appeared pretty technical; it's aimed at experienced designers. Try getting started with a basic mission first and come back to the extension when you start to feel that the standard commands are limiting you.

If you've got a few missions under your belt already, why not take a look at the extension and see what it could do for you? There must have been occasions when you wanted to do something which just turned out not to be possible. It won't cost you anything and you might be able to enhance your missions in ways you'd not thought possible. Download the example missions (link below) and see how they're put together. Finally, please drop in to the support forums and ask any questions. There's a lot of scope in the extension that's not immediately visible!

SimVar Extension Details

List of Commands

Command

What it Does

IF

Test any SimVar

SET

Set any writeable SimVar

DEBUG

Switch the extension's debug messages on or off

PROFILE

Set an internal variable

SAVEONFAIL

Save the profile even if the mission fails

SAVEONCHANGE

Save the profile every time any value changes

UNIQUEID

Set a secret value which will stop the profile from being reloaded if it's manually changed

FUELLEAK

Start or stop a controlled fuel leak

MESSAGE

Display a small text message on screen

FXTRACK

Attach a visual effect to the player or an AI

METAR

Set local or global weather

GETWX

Print the METAR string for a given weather station to the debug window

WXSTATION

Create a new weather station

EVENT

Send a simulator event

WHEN

Make a mission action happen when a particular key is pressed

PROFILENAME

Set the name of the file to store the mission profile in

WPT

Set dynamic waypoints relative to the player or an AI

SIMRATE

Set the simulation speed

SIMTIME

Set the time and optionally the day of the year

TARGETCAM

Force a cinematic camera to show two aircraft in the same view