How NetWars Works Chapter 5 of 13, plus appendices

5. The objects of the world

Everything that flies in NetWars, apart from your own ship, lives in a handful of fixed-size tables. This chapter lists them, shows the one record shape almost all of them share, and walks through the life of an object from appearing to exploding. The rules of each kind (how aliens think, how missiles home) come in chapters 6 and 7.

No new, no delete: fixed tables

A 1993 game could not afford to create and destroy objects freely in memory. NetWars reserves every object it will ever need when it starts, in fixed tables (arrays) of slots. An object "appears" when a free slot is filled in and "disappears" when the slot is marked free again. This also sets hard limits that are part of the game rules:

TableSlotsRecordWhere used
your laser shots8shotboth modes
alien laser shots8shotsingle player
aliens8 (only the first 4 to 8 are used, depending on the level)bodysingle player
alien missiles4bodysingle player
your missiles4bodysingle player
pods6bodysingle player
your satellite1bodyboth modes
other players' ships3 (4 for a spectator)bodymultiplayer
other players' satellites3 (4 for a spectator)bodymultiplayer
other players' laser shots8 each, for 3 players (4 for a spectator)shotmultiplayer

When a table is full, the action simply does not happen: a ninth laser shot is not fired, a fifth missile is not launched, and if no alien slot is free when the next alien is due, none appears this time; the next try is 64 frames later. Your own ship is not in any table; its state (chapter 4) is kept separately, because it is also the camera.

Stars are not objects at all. They are 256 fixed directions (64 in Lines mode), infinitely far away: they turn with your view but never move as you fly (chapter 9).

One shape for everything solid: the body

Aliens, missiles, pods, satellites and other players' ships all use the same record, called a body in this document (body in include/netwars.h). Not every kind uses every field, but the shape is shared, so the same code can move, draw and explode any of them. Grouped by purpose:

GroupFieldsMeaning
identitytype0 = free slot; otherwise the kind within its table (alien kind 1–4, missile kind 1–2, satellite kind 1–4, 1 for pods and ships)
where and how it fliesposition64-bit fixed point (chapter 3)
forward, right, "up"its own three Q14 axes; it always flies along forward
pitch, roll, yaw rates; speedhow much it turns and how far it moves each frame (speed ÷ 4 world units)
abilitiesmaximum speed, maximum turn rate, acceleration, hit pointsfrom its kind's table or fixed values, set when it appears (chapter 7)
behaviourstate, target, homethe step its little program is in (for example "attack", "retreat", "tow the pod"; −1 = exploding); a link to another body (a missile's target, the pod an alien has claimed and the alien that claimed a pod); a pod's home position (for other players' ships the network writes their velocity into this otherwise unused field)
looksmodel, explosion particle countwhich 3-D shape to draw (chapter 9) and how many sparks its explosion has
seen from youdistance exponent, direction, camera coordinates, screen position, visiblerecomputed every frame when the drawing code looks at the body, even if it is off screen (below)

Shots are lighter

A laser shot has no model, no steering and no hit points, so it gets a smaller record: a state, a position, a velocity and three axes. The state packs the shot's life: while flying it is the number of frames left (starting at 24) plus a flag for a powered shot (one fired while you had extra fire power from a satellite; it does double damage); while exploding it is a negative number that counts up to 0, during which a small ring is drawn. Your shots move by their own velocity (your ship's velocity at the moment of firing plus 1024 units per frame forward); alien shots move 1024 units per frame along their forward axis and do not explode, they just vanish (chapter 6).

The life of a body

free slot alive AI, move, draw exploding state −1, age counts up to 64 spawn / launch / place destroyed explosion over: type = 0 vanishes (escaped, picked up, out of range, its player left)
Every body goes through the same three states. Satellites mark "exploding" with type −1 instead of state −1.

Every frame, for every live body

Each kind has its own update routine (chapter 2, step 7). Most kinds follow one pattern; satellites (which only spin) and other players' ships (whose numbers come from the network) skip the move step:

  1. Decide (its "AI"): look at where you, a pod or the target are, and set its turn rates, speed and state. Chapter 7 describes each kind's rules.
  2. Move (object_move, src/render.c): turn by the three rates, exactly like your ship (pitch, roll, yaw, each rotate-and-rebuild, chapter 4), then advance along forward by speed ÷ 4 units.
  3. See and touch (render_object): compute where the body is as seen from your ship and, if it is in view, put its faces into this frame's draw list (chapter 9). The same step also answers is it touching you? That is the case when its display distance exponent (larger = nearer) is 7 or more and you are not inside the 8 frames of bump immunity after a collision. The answer is computed even when the body is not drawn.
  4. React on a touch, depending on the kind (details in chapters 6 and 7):
    • an alien rammed while you have shields: you lose a shield and are bumped (chapter 4), the alien loses a hit point;
    • another player's ship: the same, decided by each machine for itself (nothing is sent);
    • a satellite: you get its pick-up;
    • a pod: nothing; pods never touch you.
    Enemy missiles use their own, wider test instead: they hit at display exponent 6 or more, ignore the bump immunity, cost a shield and explode, but do not bump you.

There is no general collision system

Note that collision with you is decided by the drawing code, with the same rough cube-shaped measure that decides how big the model looks. Apart from those tests against you, the only contacts in the whole game are:

Aliens pass straight through each other and through every other pod.

What the body remembers about you

The see-and-touch step leaves its results in the body: its direction from you, its display distance exponent, its coordinates in your camera frame, its screen position, and a "visible" flag: 0 = not on screen, 1 = on screen. After drawing, the alien code sets 2 for a live alien that sits inside the crosshair window used for missile lock (chapter 6); such an alien does not have to be on screen. Later code reuses these values instead of computing them again. Mind the timing:

Explosions

An explosion is not a separate object; it is the last state of a body. When a body is destroyed its state becomes −1 and the distance exponent field is reused as the explosion's age, going up by 1 each frame. Destroyed aliens keep drifting along their old course while they explode; missiles, pods and satellites stay where they are; an exploding ship of another player keeps following its packets. The explosion draws a cloud of small discs flying outward from the body's position along fixed directions. Spark number i is drawn while the age is at most 64 − i, so the cloud thins out from the end of the list. When the age passes 64 the slot is freed.

Other players' objects are copies

In multiplayer the three "other players" tables are not simulated in the usual sense. Each other player's computer is the authority for its own ship, shots and satellite, and this machine only shows copies:

Details for an exact rebuild

Where an explosion's age starts (it then counts up by 1 per frame):

EventStarting age
alien destroyed by a shot, by ramming or by your missile1
enemy missile (hitting you or shot down), satellite, pod shot by you0
your missile on hitting its target1, and drawn at once in the same frame
pod destroyed by a Commanderits current display exponent
other player's ship killed3 (the "has been killed" message appears then)

Pods are freed at age 64 (not above). Explosions of copies of other players' satellites and shots end only when the owner's packets say so.

Effects of the update order (chapter 2, step 7): your shots are tested before the aliens move, so they hit where the aliens were at the end of the previous frame; aliens update before the pods, so a towed pod follows its captor's new position; an alien shot fired during the AI step moves its first 1024 units in the same frame. Within a table, slots are handled from first to last: the first free slot is used, and your missile locks onto the first alien marked 2.

For a rebuild

Fixed tables are not required, but keep the limits: 8 shots, 4 missiles, 8 aliens with 4 to 8 in flight, one satellite per player. They are game rules (how fast you can shoot, how many enemies attack at once), not just memory sizes.

Keep the per-frame pattern decide → move → see-and-touch → react, in the table order of chapter 2. Keep collision with the player tied to the same nearness tests the original uses (display exponent ≥ 7, ≥ 6 for enemy missiles), and do not add collisions between other objects that the original never had.