Last time we wrote about combat, everybody got very excited about entrenching and trenches and gabions and spikes and shooting. Hooray for that. The brief, as I understood it from David “Accurate Simulation of Grain Silo” Baumgart, is the following:
- Combat should be tactical and positional. Your entrenchments matter, your set up matters, and it is a tactical, positional sort of warfare.
- Combat should be character-driven. How your soldiers approach a task depends on the relative efficiency of whoever is running the show, and of the soldiers themselves.
- Combat should be pretty slow, really. Let’s have battles that feel like battles! (Many games have a problem where you send 30 dwarves to attack a Forgotten Beast and it’s all over in a blur of particles or ASCII.) No, let’s give the people what they ask for.
- Pip pip, what ho, etc.
As the technical director, when some sort of a system comes up, I usually take a first swing at it before it gets passed on to somebody else, or I keep working at it. This sort of tends to be how I contribute to the design – by brute force implementing whatever I think things should be, but knowing that I won’t get any art for it if David doesn’t like it. It is this heady triptych of unresolved creative tension that makes Gaslamp Games into the swirling beehive of … bees… that it is today.
Daniel’s instructions came in the form of three words: “Novyrus. Meat. Turret.” In other words, get a bunch of gabions, fill it with Novyrus’s Weepingest, and get the obstruction and cover stuff working. Also, digging some trenches.
Translating instructions into something that could be considered “code” in a dim light, we are left with the following set of exciting problems:
1. What *is* cover, mathematically speaking, and how is it defined?
2. What happens when I shoot a bullet? (In the current simulation, bullets hit any target automatically.)
3. What do we do about trenches?
After some programming, here are the answers.
1. The notion of cover is that it takes two forms. First, a form you can shoot through, and second, a form that obstructs everything (for instance, being in a building.) If a bullet goes through an obstructed square, that’s it, you’re done. We can optionally (depending on the lunacy of the person slash organism doing the shooting and the size of the bullet slash moon fungus dispenser) choose to shoot the obstruction anyway, in which case it can get a message indicating that “hey, it’s been shot by This Flamethrower Here” and, well, react accordingly by being lit on fire (or not.) Bullets can go through a covered square, with some probability (say, 25% probability assuming that the fishman can actually hold a gun with his grubby little flipper-hands) Otherwise, the bullet goes into the structure and gets the message, “hey, you’ve been shot by This Gun Here.” Note: we record whether or not we passed through a cover point on the way here. This will be explained in part 2.
2. When I shoot a bullet, we do Bresenham’s line algorithm because Tradition.
Since we have to do this over a network, we make sure to use the integerized version of Bresenham because, well, that way we avoid Exciting Floating Point Errors. This is so you can shoot your friends in multiplayer and have the bullet end up in the right place. If the bullet hits an obstruction, we send a message to the obstruction saying “hey, you’re an obstruction, you get the message.” We also have some probability of the bullet going through cover, or not going through cover. Finally, the bullet hits the object. If the object is a soldier, the soldier may be kneeling behind cover, or completely prone. This depends on a number of factors, including the utility of not being shot and the mood of the commander.
I told you before in part 1 that we have to record if a bullet went through cover, and where. If the bullet went through cover, and if I am prone, it had better not hit the soldier at all! In this position the soldier obviously can’t fire, but it might be a good idea to keep your wounds flat on the ground until the barber shows up with the Field Leeches.
Note that this does not apply to certain weapons such as The Eye Laser of Quaggaroth, which has its own rules due to Floating Forty Feet Above The Ground. Melee weaponry also requires that somebody be directly adjacent to it.
Note, also, that cover can be considered a perfectly valid target. It may be more useful, depending on the unblocked targets lying around, to be able to destroy cover than anything else.
3. Trenching is… a bit of a mess. Way back when, Mr. Whitman implemented our terrain engine using marching cubes based on voxels. He was then sealed into a tree by his law professors. The voxels themselves turned out to be a pain, because we were storing a 512x512x64 world or something with a lot of floats, but I converted it to use a sparse voxel representation a few weeks ago and a lot of our memory problems went away. This is Good News for those of you with older computers; we have now gone from 1.6 gigabytes of space in a standard gameplay down to under 700 megabytes, and we have not yet begun to fight.
So, yes. Back to marching cubes. In general, this looks fine – except when you want an exact, sharp hole like a trench. You will notice in our trailer that there are places where this causes Fun (during the Digging of the Idol out of the Ground Scene.) So right now we can make a trench that looks like a trench just fine, but because the Marching Cubes algorithm doesn’t support sharp transitions very well, it has nice soft edges.
I’m… not sure what to do about this, to be honest. Still thinking this one through. The correct solution is to implement what is called Dual Contouring, but this is a Pain and involves solving some linear equations that I really, really don’t want to have to get solvers for. Plus, there is the ongoing problem of supporting real time updates, and Keeping It All Cached, and all that. So… hmm. Everquest Next does it, though, so it is possible. The other option is to try to detect where the trench is and do either CSG or some kind of hackneyed reprojection step to get perfectly flat edges, or to try one of the other marching-cube-alikes such as, uh, I think it’s called Cubical Marching Squares. Still, for now we will have rounded trenches and we will see if we can survive.
So, yes. Combat! We’re shooting things. For the Empire!