The Modern Warfare Mod (MWM) has revolutionized the way anti-air units function in RTS games, realistically modeling them as much as possible within the permitted engine constraints of WiC.
Perhaps the most impressive eye popping experience of MWM is realistically modelling the radar-controlled Anti-Aircraft Artillery (AAA) units, or simply 'AA guns.' The portrait of AAA in MWM for WiC is not only impressive for its realism within the WiC community itself, but even exceeds the realism and expectations set forth by other modern military-themed games.
The technology or the "neat tricks" that MWM uses to achieve this is our PredictorFCS code. PredictorFCS is a set of procedural programming scripts using Python that are used for simulating fire control and guidance systems in World in Conflict (WiC).
WiC AAA Primer: How it used to work
The AAA units in vanilla, un-modded WiC are known as "Medium Anti-Air" (MAA) units. The MAA units have a fire-rate of 600 rounds per minute (that is, one bullet is fired every 0.1 second) and are pretty effective at tearing up air units. A General-ranked MAA unit will kill a helicopter with every single bullet scoring a precision sniping hit whenever a chopper enters its engagement radius.
Unfortunately, this is not very realistic. Regardless of whether you have the most superior fire control computer available, no anti-air gun is going to consistently hit fast-maneuvering air targets with such precision at a relatively medium fire rate of 600 rounds/min. Despite all the advances that have been made in digital technology and auto-cannons, even today's modern AAA's gain their probability of kill (pK) by using insane fire-rates. You won't find Phalanx CIWS guns shooting down incoming cruise missiles at only one round fired every 0.1 second, irrespective of how accurate its fire control technology is.
Chapter 1: First step in making AAA more realistic: Increase the Fire Rate (if only if it was that easy!)
Unfortunately, in WiC, all unit shooter weapons must be limited to 600 rounds/min in their fire-rate. Sure, you can use higher fire-rate and it will work just fine. But, the moment you try out your mod on a dedicated server with your online friends, the server will crash because the rate at which server updates its clients is limited to 10 frames per second, which translates to 0.1 second. So fire rates higher than 600 rounds/minute will crash the dedicated server in WiC.
This problem was impossible to fix in the early days of WiC modding, it became one of the "holy grails" of advanced WiC modders since the early days. It was simply marked as "game engine limited, cannot fix" for a while.
With MWM 2.0, all of this has changed. MW Mod has solved this holy grail of WiC by gaming the system, or more precisely, "cheating" the server software. Using PythonShooter API programming interface that Massive developers created for modders to use, MWM uses a new set of python scripts known as PredictorFCS.
The PredictorFCS generates insane fire-rates without crashing the server by using a programming logic called "buffered event handling" or "event polling." The actual AAA unit's Shooter weapon is configured to fire at rate of one round per 0.1 second as usual -- which is only 600 rounds per minute. However, every time a round is supposedly to be fired every 0.1 sec, instead of firing the bullet, PredictorFCS script intercepts the call and "games the system." When the script intercepts the firing sequence, instead of spitting out one bullet as usual, it invokes multiple weapon-fire calls while adding variance delay and spread to them. So instead of firing 1 bullet every 0.1 second, we're firing upwards of 8 bullets every 0.1 second. 8 bullets every 0.1 second translates to 80 bullets per second, which translates to 4,800 bullets per minute.
Since the generation of all 8 bullets at interval of 0.1 second happens all at once (hence, "buffered") on the dedicated server side, the server happily cruises along as if nothing happened. And we now have fire-rates as high as 6,000 rounds/minute on dedicated servers without crashing them ever!
There is more science to this than what's described though. In order to make the bullets form up a nice, natural looking "stream" of bullets just like in real-life, the Predictor python script adds random delay in milliseconds between each bullets launched in a single "buffered" call. It also adds slight random accuracy delay based on unit Shooter's accuracy rating for each bullet generated. We also created new graphical animation files that portray the bullets with nicer tracer and burnout effects to compliment the system.
Chapter 2: We now have insane fire-rates, but unfortunately they can't seem to shoot for crap!
One realistic feature that Battlefield Bad Company 2 (BFBC2) game implemented is simulated effect of ballistic physics. Unlike other games, bullets do not fly in straight line in BFBC2. Moreover, bullets also fly at much slower realistic muzzle velocities, where as in other games including WiC and COD4, bullets seem to fly at speed of light. Instead of calling them ballistic fire arms, we ought to call them lasers instead.
So, to make things feel more realistic, almost every projectile in the game has been slowed down in MWM 2.0 with realistically scaled values. For instance, in unmodded WiC, Medium Anti-Air bullets fly at a speed of 900 map units per second -- this means the bullet will cross from one side of the map to the other in do_Hometown in just one second. This is practically a rail-gun and that's exactly why whenever your helicopters fly into an MAA gun radius, it always gets shot at in an instant speed of light without noticeable misses. In MWM 2.0, AAA bullets travel at only 20% of unmodded WiC's MAA bullets!
When your bullets are flying at only 20% of what they used to fly, you suddenly run into a huge problem: the point of aim for your bullets is already too late to hit a moving helicopter. The classic rifle shooting rule of 'leading your target' comes to mind.
Chapter 3: How to accurately deal a deadly blow to even the fastest moving cruise missiles, not just helicopters... at only 20% of original bullet speed.
The Answer: Let's throw math at the problem :P
In new PredictorFCS 2.0 python script, we solve the problem of creating solid target leads by paying attention to our good old high school trigonometry math classes. We use the Law of Sines to do this.
Consider this example:
Our target is flying at position 'T' and we are shooting our gun from position 'G'. But since our target is moving, we have to aim ahead of him, thus the point of collision of our bullet with the target is the 'C', the point of interception.
The exact lengths of distances 'o' and 't' are not known, nor can the position of the interception point 'C' be pinpointed. However, the derivatives of lengths 'o' and 't', aka the speeds of the target and the AA gunner's muzzle velocity are known. Observe that, because when neither the AA gunner nor the target are accelerating, the triangle formed by them will be similar to the one above-- the sides will have the same ratio.
So, let's simplify this and assume that distances 'o' and 't' are equal to speed of their respective classes -- the moving speed of target is 'o' and the speed of projectile/bullet's flying time becomes the 't'.
Now, let's bust out our Law of Sines. The sine law asserts:
Using the law of sines, if we wanted to get the value of length 'a' in a triangle, we can do:
Now, let us go ahead and apply this law of sine to our pretty WiC triangle pictured above. You'll note that ''T, 'G' and 'C' are angles of our WiC scenario triangle, and 'c', 'o' and 't' are lengths of our fictional triangle -- which are the speeds of moving things involved. And we have this:
What this calculation gives us is the value to our angle 'G' -- the angle of turn, the angle of "aim" that the AA gunner has to make to aim his gun turret and point it to, in order to cause his bullets and the moving target to go into a spectacular mid-air collision.
So, there you have it. The partnership of artistic graphics, 1337 hax and trigonometric math producing a beautiful, yet deadly accurate as hell radar-directed anti-aircraft artillery (AAA) for World in Conflict. When you fly into that Vulcan's stream of fire, there's no escape.
Next time when you see your AA gun clearing the sky with such beautiful and ferocious display of violence and efficiency, just remember all the fancy math we've thrown into the thing behind-the-scenes :P