Airships: Conquer the Skies
2017-05-28 14:29

Apart from improving boarders, Airships 9.2 also adds flying troops. This dev blog entry is about about the details of their code.

Flying troops means flying boarders like air dragoons, but also small flying units that can be launched from ships like biplanes. This might sound like an odd terminology: why is a biplane in the same category as an air sailor rather than an airship?

There are basically two types of units in terms of code: "airships", which are made of modules and can't overlap, and "troops" which are single objects, can overlap, and can go inside airships. So "airships" are airships, landships, buildings and monsters like dragons or giant spiders. "Troops" are ship crew, boarders, and now also small flyers like biplanes, air hussars and clockwork wasps.

The existing code for troops let them pop out of ships and move around outside by climbing across ships and jumping from ship to ship. They could shoot other troops while inside ships, but they couldn't use their weapons while outside. These new units needed to be able to fly around freely. They needed to be able to shoot ships, shoot each other, and be shot by ships while outside. And they needed new behaviour code to know where to move and what to shoot.


The basic movement code for flying troops is rather simpler than for walking ones: they have a current position and velocity, and accelerate towards the target point. I discovered that by adjusting the target point on the basis of remaining time until arrival, they nicely accelerate and decelerate to precisely get to the target. This adjustment worked so well that the movement felt unnaturally clean, so I added an "overshoot" parameter to reduce the adjustment and make the movement more real-looking.

The main difficulty for flying movement was avoiding the ground. While troops can fly past floating rocks, flying inside the ground looks wrong. But if they're targeting a small building, it's very possible that the direct line of flight would go through a hill. So they have to go above the hill rather than through it.

The system for ground avoidance looks both at the current location of the unit and at a location projected a bit into the future. If the ground is very close, the unit is forced to decelerate and pull up. If it's merely somewhat close, the unit can maintain its horizontal speed but is prevented from accelerating downwards. Both of these rules stop applying if the unit is very close to its target location.

The result is that if you have some triplanes moving towards a building, they will fly low but not too low above the ground, and only make a final dive down when they're pretty much at the target.

Another detail to make the movement of units more natural was to give them an initial launch velocity. An air hussar simply detaches and starts floating away, but a triplane obviously needs to take off at speed. After launching, the unit then gains increasing control over its movement in the space of a second or two. So the plane will take off in a straight line and then start curving towards its intended target.

Speaking of planes, there were two more movement details needed: one was simply preventing them from moving around inside ships. Remember that the code for triplane is basically the same as for an air sailor, and so unless told not to, it might start wandering around the ship, trying to fetch coal.

The other one was to give planes a minimum horizontal airspeed. With the basic movement code, a plane that needed to turn around would come to a complete stop, flip around, and slowly start accelerating again. This both looks wrong and makes them too vulnerable to being shot down. So the plane now keeps track of an internal x-velocity and rounds this up to a minimum speed for actual movement. When turning around, it will instantly go from its minimum speed in one direction to the same speed in the other direction.


Previously, ships could shoot other ships, and troops could shoot other troops inside the same ship. Both cases used the same shot objects, but I now had to refactor them to include several new scenarios: troops shooting ships, troops shooting other troops outside, and ships shooting troops.

That last case also required some new logic in weapon modules to decide when they would fire at troops instead of other ships. Weapon modules generally make up their own mind as to where to shoot anyway, and obviously having to tell them to target individual enemy planes or boarders would be a micromanagement nightmare.

I added a new parameter to weapons that indicated at what range they would fire on enemy troops. This is zero for larger weapons like cannons or rockets, but rifles, gatling guns, flak cannons, flamethrowers and grapeshot cannons I deemed small and flexible enough to target troops.

This does mean that if your ship has none of these weapons, it cannot shoot at incoming air units at all. However, it still can destroy the units' mothership and win the fight. Troops, even planes, don't count as having an undefeated ship in the battle, so if you blow up the plane's carrier, you win even if you're still being swarmed by a dozen planes you can't shoot down. You can't conquer a city with some planes, after all, and they'll run out of fuel soon enough.

A side effect of this new code is that ordinary boarders like marines and grenadiers can now also be shot down while moving towards ships, giving players more options to block boarding attempts.

Navigation and Targeting

With aerial units able to move around and shoot at things, they still need to know where to move and what to shoot.

In the case of flying boarders like giant bees or air dragoons, this is pretty simple: they move towards the closest entry point on the ship they want to board.

Flying attack units, on the other hand, do strafing runs. They pick a particular horizontal line across the target ship and fly past it, firing at the target. Then they turn around and do another run. In case their target is too close to the ground, they do a strafing run above it, as close down as they can get.

Biplanes, as specialized anti-air units, also directly intercept other flyers, moving to strafe them in preference to attacking ships.


With all of this implemented, there remains the work of carefully balancing these additions. Each new thing in the game has to fit within the available tactical options.

The intent is that Air Hussars are fairly powerful even against decently armoured enemy ships, but easy to shoot down. Triplanes are much harder to shoot, but their guns are weak against armour. Finally, Biplanes are even harder to shoot and even weaker against anything that has any armour at all, but excellent for shooting down other troops, both boarders and fliers.

So ships with enough anti-air weaponry should do well against fliers, but a lightly armoured ship only armed with cannons would be very vulnerable against them. As with anything in the game, fliers should be powerful in some situations and weak in others.

While I can require a coat of arms bonus for specific modules in strategic combat, in multiplayer, all modules are generally unlocked, so they still need to be balanced against each other. I can't lock away an overpowered option, so everything does have to be balanced against everything else.

The new release is currently in beta, and this balancing is ongoing. Currently, planes appear to be a bit too powerful, so they'll get downgraded in the next beta, and we'll see how that goes. Your input both in terms of balance and finding bugs is always appreciated.

The next release, 9.3, is planned to be about a few specific long-running quality of life issues: splash damage from explosions and explosive weapons, build queues in strategic mode, and maybe improvements to in-combat ship movement.