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:
| Table | Slots | Record | Where used |
|---|---|---|---|
| your laser shots | 8 | shot | both modes |
| alien laser shots | 8 | shot | single player |
| aliens | 8 (only the first 4 to 8 are used, depending on the level) | body | single player |
| alien missiles | 4 | body | single player |
| your missiles | 4 | body | single player |
| pods | 6 | body | single player |
| your satellite | 1 | body | both modes |
| other players' ships | 3 (4 for a spectator) | body | multiplayer |
| other players' satellites | 3 (4 for a spectator) | body | multiplayer |
| other players' laser shots | 8 each, for 3 players (4 for a spectator) | shot | multiplayer |
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:
| Group | Fields | Meaning |
|---|---|---|
| identity | type | 0 = 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 flies | position | 64-bit fixed point (chapter 3) |
| forward, right, "up" | its own three Q14 axes; it always flies along forward | |
| pitch, roll, yaw rates; speed | how much it turns and how far it moves each frame (speed ÷ 4 world units) | |
| abilities | maximum speed, maximum turn rate, acceleration, hit points | from its kind's table or fixed values, set when it appears (chapter 7) |
| behaviour | state, target, home | the 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) |
| looks | model, explosion particle count | which 3-D shape to draw (chapter 9) and how many sparks its explosion has |
| seen from you | distance exponent, direction, camera coordinates, screen position, visible | recomputed 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
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:
- 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.
- 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.
- 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.
- 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.
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:
- your laser shots against aliens, enemy missiles, pods and satellites (a box test around the shot, chapter 6);
- a missile against its one target;
- an alien against the one pod it has claimed (to grab or destroy it, chapter 7).
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:
- the aliens' "how near is the player?" rules run before they move, so they read the values left by the previous frame;
- your missile launcher is part of your ship's update, which comes first in the frame, so it also sees the previous frame's lock;
- the radar is drawn at the end of the frame and sees this frame's values.
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.
- How many sparks: aliens, pods and other players' ships have 38 in Polygons mode and 12 in Lines mode; missiles and satellites always have 12.
- Where: an explosion is drawn only while every coordinate difference to it is below about 32,770 units and it is in front of you (within about 63° of the view direction); its age keeps counting when it is not drawn.
- Depth: in Polygons mode the sparks are sorted together with the faces of the models, but as if they were twice as far away; chapter 9 explains the drawing order and its oddities.
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:
- Ships: position, orientation and velocity are written straight into the body by the network code every time a packet arrives (chapter 8). Between packets nothing moves them. The packet's status word decides whether the ship is shown (alive or cloaked), starts exploding (killed) or is hidden (not in play); a cloaked ship is not drawn but still shows on the radar and can still ram you. A ship whose packets stop for 4 frames is removed.
- Shots: the packet does not carry shot positions, only a flag per shot ("fired", "fired powered", "exploding", "none"). When a new "fired" appears, this machine starts its own copy 64 units along the other ship's "up" axis from its position, with its velocity plus 1024 units forward, and flies it locally. The copy is only for showing; it can never hit you. Whether a shot hit anybody is decided by the shooter's machine (chapter 6). A copy's explosion ring stays until the owner's flag returns to "none".
- Satellites: the owner's packet carries the kind and position; this machine draws it and lets you collect or shoot it, and reports that to the owner, who then removes or explodes the original (chapter 8).
Where an explosion's age starts (it then counts up by 1 per frame):
| Event | Starting age |
|---|---|
| alien destroyed by a shot, by ramming or by your missile | 1 |
| enemy missile (hitting you or shot down), satellite, pod shot by you | 0 |
| your missile on hitting its target | 1, and drawn at once in the same frame |
| pod destroyed by a Commander | its current display exponent |
| other player's ship killed | 3 (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.
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.