14. The complete game state and its lifecycle
Everything NetWars remembers, in one place: what each value means, its range and unit, where it lives in the original, and exactly what happens to it when a game starts, a level starts, you die, you respawn, you press Esc, you go back to the title screen or you change the universe. If your rebuild keeps these values and resets them at these moments, it will behave like the original between screens as well as inside a flight.
What "state" means here
The state of a program is everything it remembers from one moment to the next. The
original keeps all of it in about 150 global variables (named g_… in the
reconstructed source; the "source global" columns below give the name and its address
DG:xxxx in the data segment). Chapters 2 to 8 explain what the values do; this chapter
lists them all and says when each one is reset (given a fresh value) and when it is
kept (carried over from before).
One part of the state is not a variable at all: which screen is showing. In the original
the screen is simply the place in main's code where the program currently runs (a
loop inside a screen routine, or the flight loop). A rebuild should make it an explicit value; the
diagram below lists all the screens.
Units, as everywhere in this document: a world unit is the middle word of a 64-bit coordinate (chapter 3); directions are Q14 (16384 = 1.0); angles are steps of 1/2048 of a turn; "frames" are game frames (18.2 per second in single player, about 70 per second in multiplayer in our emulator measurements). Marks: O observed in a recorded run, D derived from the code but not watched. Every statement in the lifecycle tables is D (read from the reconstructed code, which is byte-identical to the original) unless it carries an O.
One naming trap: the ship's third axis is called "up" (axis c), but the renderer turns a positive camera y into a lower screen row, so things along +c appear below the centre of the view. "Up" is the name, "down on the screen" is where it points.
The whole state, grouped
Four groups: the session (things that outlive a single game), the player (your
ship and your stock of extras), the world (everything else that flies), and the
network (multiplayer bookkeeping). Purely technical values (the draw list, polygon filler,
video pages, the screen origin g_origin_x/y and the model shown on menu screens
g_menu_obj, both set up by each screen) are left out. One text buffer does carry state:
during initials entry the typed initials live in g_text_buf[0..3] from frame to frame
(the rank text is written from offset 4); it is emptied when the entry starts.
Session
| Value | Meaning | Type, range, unit | Source global |
|---|---|---|---|
| screen | which screen runs (title, attract, start level, level intro, flight, level complete, lobby, name entry; "Game Over" and "You were killed" are text drawn over the flight) | implicit (code position) | none: the position in main |
| mode | single player or multiplayer | 0 / 1 | g_multiplayer DG:2AE8 |
| spectator | watching a network game: never sends, cannot fire or be hit | 0 / 1 | g_spectator DG:2AE6 |
| slot | own player slot (PLAYER 1–4); 4 = "spectate" chosen in the lobby, then 0 | 0..3 (4 briefly) | g_player_index DG:2AEA |
| level | single-player level, counted from 0 (shown as level + 1) | 0.. (start menu offers 0..7) | g_level DG:BF88 |
| scores | score of each slot (single player: slot 0); peers' entries are written by their packets | 4 × 32-bit, 0..1,000,000 (wraps) | g_scores[4] DG:2AF2 |
| score text | the HUD text "SCORE: %6ld", re-formatted only when points are added and at a new game | string | g_score_text DG:BF8A |
| options | control (keyboard / mouse / reversed mouse), sound (none / PC speaker), graphics (Lines / Polygons), monochrome colours (/M) | flags; colours are 12 palette indices | g_mouse_enabled DG:2AC6, g_mouse_reversed DG:3BD9, g_sound_on DG:2ACA, g_wireframe DG:22AA, g_monochrome DG:22AC, g_colors[12] DG:2AA6; check marks in the menu records |
| universe | which of the 8 independent network games | 0..7 (shown 1..8) | g_universe DG:320C |
| high scores | ten scores, ascending (entry 0 = lowest), and their initials | 10 × 32-bit; 10 × 4 chars | g_hiscore_scores DG:2BCE, g_hiscore_initials DG:C02A |
| high-score entry | index of the new entry; characters typed so far | 0..9; 0..3 | g_hiscore_rank DG:BFB8, g_initials_len DG:2BF6 |
| attract page | which attract screen shows: −1 initials entry, 0 instructions, 1 high-score table | −1..1 | g_attract_page DG:2BF8 |
| menu bar | open menu, highlighted item, "a pull-down is open"; per menu its layout (column, hotkey, popup size) | ints | g_menu_cur DG:2CFE, g_menu_item DG:2D00, g_menu_open DG:2D02, menu records DG:2C02..2CCE |
| keyboard owner | 1: the game reads the key table (flight, level intro, level complete); 0: keys go through the BIOS (menus, name entry) | 0 / 1 | g_kbd_captured DG:3BC7 |
| pointer mode | mouse pointer shape and area: arrow over the whole screen, or flight box | 1 arrow / 2 box | g_mouse_mode DG:3BCB |
| timer ticks | 18.2 Hz ticks since the current frame (or page) began; used for pacing | int | g_tick_count DG:3BC9 |
| random generator | Borland rand() state; seeded once from the clock at start, never reseeded; used by collision tumbles and satellite positions | 32-bit seed | rtl_rand_seed DG:AEF8 |
| sound sequencer | the PC-speaker sound being played: tones left and next tone; a sound keeps playing across screen changes | words | g_snd_remaining DG:A2C0, g_snd_ptr DG:A2C2 |
| unused sound flag | cleared by Sound ▸ None, never read | int | g_sound_unused DG:2AC8 |
| program folder | where HISCORES.DAT is read and written | string | g_prog_dir DG:BB06 |
Player
| Value | Meaning | Type, range, unit | Source global |
|---|---|---|---|
| position | your ship (= camera) in the world | 3 × 64-bit; world unit = middle word | g_ship_position DG:22D2 |
| velocity | added to the position every frame while alive | 3 × 64-bit, world units per frame in the middle word | g_ship_velocity DG:2B02 |
| axes | forward (a), right (b), "up" (c, drawn downward on screen) | 3 × 3 Q14 | g_cam_axis_a/b/c DG:22BA/22C0/22C6 |
| turn rates | pitch, roll, yaw applied this frame | angle steps per frame; keyboard −24..24, mouse unbounded | g_pitch_rate DG:22CE, g_roll_rate DG:22CC, g_yaw_rate DG:22D0 |
| throttle | wanted forward speed (Shift +8, Ctrl −8 per frame) | 32-bit, −112..144 in steps of 8; world units per frame (doubled with extra thrust) | g_throttle DG:2AEC |
| body velocity | velocity along right, up, forward; recomputed every living frame | 3 × 16-bit, world units per frame | g_vel_body DG:C052 |
| shields | health; 0 = dead | 0..32 | g_shields DG:2AF0 |
| missiles | homing missiles in stock (single player) | 0..32 | g_missiles DG:2B8E |
| extra thrust | boost units; each strong correction step uses 1 | 0..4096 | g_extra_thrust DG:2B8C |
| fire power | powered shots left; each shot uses 1 | 0..256 | g_fire_power DG:2B8A |
| cloak | cloak frames left; cloak switched on (multiplayer only) | 0..512 frames; 0 / 1 | g_cloak_time DG:2B84, g_cloak_on DG:2B86 |
| death countdown | frames the death screen still ignores Enter | 0..64 | g_death_countdown DG:325A |
| killer | slot of the player who killed you; +4 = rammed | 0..7 | g_killer_index DG:3258 |
| collision immunity | frames without new collision damage after a bump | 0..8 | g_bump_immunity DG:B20E |
| tumble | frames of forced spin after a bump, and the decaying spin rates | 0..48; rates −48..48 | g_tumble DG:C05A, g_tumble_rates[3] DG:2B7A |
| fire cooldown | frames until held fire shoots again | 0..2 | g_fire_cooldown DG:2B88 |
| target lock | an alien is in the crosshair (set by the alien update) | 0 / 1 | g_have_target DG:2B90 |
| radar zoom | radar scale exponent (keypad + / −) | −6..2 | g_radar_zoom DG:2ACC |
| message | current HUD message text and frames left to show it | pointer; frames | g_message_ptr DG:BFAA, g_message_timer DG:2B82 |
| flash | background colour of the next frame (hit / collision flash) | palette index, 0 = none | g_flash_color DG:2AE4 |
| input latches | per key: held (81h) or "pressed since cleared" (01h); mouse button the same | 128 bytes; word | g_key_state[128] DG:3B47, g_mouse_click DG:3BD5 |
| mouse position | pointer position from the mouse driver | pixels | g_mouse_x DG:3BCD, g_mouse_y DG:3BCF |
| own status | what your packets say about you: 0 alive, −1 cloaked, 1 killed, 2 not in play | −1..2 | g_status_out DG:BFB2 |
World
| Value | Meaning | Type, range, unit | Source global |
|---|---|---|---|
| aliens | 8 alien slots (fields: next table) | 8 body records | g_aliens[8] DG:C388 |
| alien budgets | aliens of each type still to appear this level | 4 × 0..8 | g_alien_counts[4] DG:BABE |
| aliens left | aliens still to be removed; the level ends at 0 | 0..32 | g_aliens_left DG:BFB6 |
| alien limit | alien slots usable at once | 4..8 | g_alien_max DG:C306 |
| Pirate speed | type 1 maximum speed, rewritten per level | 500..1000 (raw speed) | g_alien_types[0].speed DG:31A2 |
| spawn rotation | side of the next alien (right, left, up, down); offset of the type search | counters, used & 3 | g_spawn_dir DG:C058, g_spawn_type_rot DG:C2FC |
| frame counter | frames since the flight began; aliens may appear every 64th, satellites every 128th | int | g_frame_count DG:BD46 |
| pods | 6 pods (type 1 = exists; state −1 exploding, 0 idle, 1 claimed, 2 towed, 3 returning) | 6 body records | g_pods[6] DG:CCF2 |
| pods left | pods still counted (bonus, mutants at 0) | 0..6 | g_pods_left DG:C708 |
| own shots | 8 laser shots: 0 free, 1..24 frames of life (+256 = powered), negative = exploding | 8 shot records | g_player_shots[8] DG:BD68 |
| alien shots | 8 alien laser shots: 0 free, else frames of life (24 at launch) | 8 shot records | g_alien_shots[8] DG:C912 |
| missiles | 4 player missiles, 4 alien missiles (type 0 = free, state −1 exploding) | 2 × 4 body records | g_player_missiles DG:CB32, g_enemy_missiles DG:C752 |
| own satellite | the one pick-up you own (type 0 none, 1..4 kind, −1 exploding) | body record | g_my_item DG:C28C |
| satellite counter | drives the kind cycle (counter & 3: 0 missiles/cloak, 1 thrust, 2 fire power, 3 shields) | int, +1 per satellite | g_satellite_counter DG:2B80 |
| explosions | each exploding body counts its age in its distance-exponent field; the particle count given to bodies created from now on | age 0..64; count 12 (Lines) or 38 (Polygons) | body dist_exp; g_explosion_particles DG:BABC |
| stars | 256 fixed directions; 64 drawn in Lines mode, 256 in Polygons mode | Q14 vectors, constant | g_stars[256] DG:2302 |
Fields of one alien
Every flying object is a body record (chapter 5); for an alien the fields mean:
| Field | Meaning | Set when the alien appears (alien_spawn) |
|---|---|---|
| type | 0 free slot; 1 Pirate, 2 Fighter, 3 Guardian, 4 Commander or mutant | type of the chosen budget; 4 if no pods are left |
| pos | position, 3 × 64-bit | your position + 16384 units along your right, left, "up" or "down" axis |
| fwd, right, up | orientation, Q14 | not set: kept from the slot's last alien (identity, facing +z, at level start) |
| pitch / roll / yaw rate | turn per frame | not set: kept (pitch and roll are 0 after a level start, yaw is never cleared) |
| state | behaviour state; −1 exploding | 0; 4 for a mutant |
| speed, max speed, accel, max turn | flight parameters | speed = max speed = type's speed; accel 0; max turn = type's turn |
| hit points | damage it can take | 2, 2, 4, 8 by type (mutant 8) |
| dist_exp | distance exponent (larger = nearer); explosion age while exploding | 0 |
| particles | explosion sparks | 12 or 38 (current value) |
| model | shape | type's model; mutant model if no pods are left |
| target | claimed pod (Pirate, Commander) | none |
| cam_x/y/z, dir, scr_x/y | render outputs | recomputed when it is drawn |
| visible | 0 not drawn, 1 drawn, 2 in the crosshair | not set, and not cleared by the level-start clear either: the renderer writes 0 or 1 each time the alien is drawn, the lock test writes 2; a stale 2 can survive in a free slot |
Network
| Value | Meaning | Type, range, unit | Source global |
|---|---|---|---|
| network open | the universe's 4 channels (IPX sockets) are open | 0 / 1 | g_net_open DG:324E |
| number of peers | other players listened to: 3 when playing, 4 when spectating | 3..4 | g_num_peers DG:2AE2 |
| peer slots, channels | which slot each peer index is; its channel; your own channel | 4 ints; socket words | g_peer_slot DG:D0B2, g_peer_socket DG:D082, g_my_socket DG:D4A8 |
| peer colours | radar colour per peer (slots 0, 1 light green; 2, 3 light blue) | palette indices | g_col_players[4] DG:2ABE |
| peer ships | one body per peer: position, axes, velocity (in the home field), type 1 = shown, state −1 = exploding | 4 body records | g_peer_ships[4] DG:C05C |
| liveness | frames of grace per peer: 4 after a packet, −1 per missed frame, 0 = inactive | 0..4 | g_peer_alive[4] DG:3250 |
| peer events | receive buffer of each peer's event record: 3 hit words, status, satellite event | 4 × 5 words | g_peer_events DG:D08A |
| peer shots | each peer's 8 shot flags (0 none, 1 fired, 2 powered, 3 exploding) and our local copies of those shots | 4 × 8 bytes; 4 × 8 shot records | g_peer_shots DG:BD48, g_remote_shots DG:B23C |
| peer satellites | each peer's satellite (type + position from its packet) | 4 body records | g_peer_items DG:BB86 |
| outgoing events | hit words (victim slot + 1, +256 powered), satellite event (owner + 1 taken, +256 shot) | 3 + 1 words | g_event_out[0..2] DG:BFAC, g_item_event_out DG:BFB4 (status: player table) |
| own shot flags | the 8 flags sent for your shots | 8 bytes 0..3 | g_my_shots DG:C2FE |
| names | name of each slot (15 characters + end mark); own one edited on the name screen, others from packets | 4 × 16 chars | g_player_names DG:325C |
| lobby slot taken | lobby frames left before a silent slot shows "Free" | 0..32 | g_slot_heard[4] DG:D4AA |
| kill message | the text "%s has been killed" | string | g_kill_msg DG:BAC6 |
| receive / send blocks | IPX control blocks and headers (technical) | — | g_ecbs DG:D12A, g_send_ecb DG:D0BE, headers |
Screens and the moves between them
This is chapter 2's screen diagram ("Screens are states") with every transition and the initialisation it runs. The letters in brackets name the routines spelled out under Exact rules: [N] new game, [L] level setup (single player) or life setup (multiplayer), [R] multiplayer respawn.
main in
src/main.c: title, restart
([N]) and level ([L]).Every transition
| From → to | Event | What runs, in order |
|---|---|---|
| start → title | program start | startup (below); then the title screen |
| title → exit | Esc; or Enter on Multi Player when IPX fails, then Esc | shutdown: network closed, handlers removed, text mode, exit |
| title → attract | Enter or click on Single Player | all 4 scores = 0; menu bar laid out again; Universe menu removed; slot 0, not spectating |
| title → lobby | Enter on Multi Player and the network opens | network opened (4 channels of the universe, lobby listens, "taken" counts 0); all 4 scores = 0; menu bar laid out; Universe menu added |
| attract → title | Esc, or Game ▸ Exit this mode | title screen |
| attract → start level | Enter, or Game ▸ Start new game | start-level menu: level = 0, camera reset |
| start level → attract | Esc | attract screens again (they do not reset their page) |
| start level → level intro | Enter or click | [N] new game, then [L] up to the introduction |
| level intro → flight | Enter or click | rest of [L]: throttle 0, aliens and missiles cleared, satellites cleared, frame counter 0, message off, keyboard captured, Esc latch cleared |
| level intro → attract | Esc | back to [N]'s start (score kept: it can still enter the table) |
| flight → level completed | no aliens left and shields > 0 (checked at the top of a frame) | bonus, shields +8 (max 32), camera and position reset |
| level completed → level intro | Enter or click | level + 1; [L] |
| level completed → attract | Esc | back to [N]'s start, score (with bonus) kept |
| flight → Game Over | shields reach 0 | death countdown 64; the world keeps running, your ship stops moving |
| Game Over → attract | after the 64 frames: at once if your score beats the lowest high score, else on Enter/click | shields = 32; then back to [N]'s start (attract inserts the high score) |
| Game Over → level completed | as above, but no aliens were left, e.g. you rammed the last alien with your last shield (it explodes, its explosion ends while you are dead) D | the next level follows although you died |
| flight (or Game Over) → attract | Esc (tested at the top of every frame, before the level-clear test) | your score = 0 (so it cannot enter the table); back to [N]'s start |
| flight → level completed with score 0 | Esc latched in the frame the last alien's explosion ends (so aliens left is 0 and shields > 0 when the loop ends) D | score = 0 by the Esc, then Level Completed adds only the bonus |
| lobby → title | Esc, or Game ▸ Exit this mode | title screen (the network stays open) |
| lobby → name screen | Enter or click on a slot nobody is heard on | leave the lobby (peer listens and send block set up for your slot); [N]; then [L] starts with the name screen |
| lobby → spectating | Enter on the spectate spot or Game ▸ Spectate current game | same, as spectator; spectators skip the name screen |
| name screen → lobby | Esc | end session (peer listens cancelled, lobby listens re-posted, "taken" counts 0); back to [N]'s start |
| name screen → flight | Enter or click | rest of [L], including player start at your slot's corner |
| flight → "You were killed" | shields reach 0 | status "killed", killer remembered, countdown 64 |
| "You were killed" → flight | Enter or click after the 64 frames | [R] respawn |
| flight (or "killed") → name screen | Esc | your score = 0; then [L] (name screen first) |
| spectating → lobby | Esc | end session; back to [N]'s start (the lobby) |
| lobby → lobby | Universe ▸ 1..8 | old channels closed, universe changed, new channels opened (all slots "Free"); failure ends the program |
Lifecycle of every value
The columns are the moments at which values change. Each describes what happens to the value over the whole move, from the last frame before it to the first frame after it:
- Start: the value when the title screen first appears.
- New game (SP): from the attract screens through Select Start Level, [N] and [L] to the first flight frame of the first level. This is also what happens after every death, Esc or abandoned level in single player.
- New level (SP): "Level Completed", then [L] with the introduction, to the first flight frame.
- Death (SP): from the frame your shields reach 0 until the frame loop ends.
- Flight (MP): from the name screen (or, for a spectator, the lobby) to the first flight frame: [L] in multiplayer. Joining from the lobby runs [N] first; where that differs it is said.
- Respawn (MP): Enter on "You were killed".
- Esc: what pressing Esc in flight does by itself, before the next screen's resets; the screens that follow (attract or name screen) are the "New game" or "Flight (MP)" columns.
- Title: going back to the title screen and leaving it again.
- Universe: choosing another universe in the lobby.
"kept" means nothing touches the value; red marks a value carried over that a fresh design would reset (a peculiarity of the original); "—" means the value plays no role there.
Session values
| Value | Start | New game (SP) | New level (SP) | Death (SP) | Flight (MP) | Respawn (MP) | Esc | Title | Universe |
|---|---|---|---|---|---|---|---|---|---|
| mode | 0 | kept (0) | kept | kept | kept (1) | kept | kept | 0 on entry; 1 if Multi Player is chosen and the network opens | kept |
| spectator | 0 | = 0 | kept | kept | set by the lobby: 1 spectate, 0 slot | kept | kept | kept | kept |
| slot | 0 | = 0 | kept | kept | lobby: = 0 on entry, then the chosen 0..3 (spectate: 4, then 0) | kept | kept | kept | kept |
| level | 0 | start menu: = 0, then the chosen 0..7 | +1 | kept | — | — | kept | kept | — |
| own score | 0 | = 0 (after the attract screens used the last one) | + pods left × (level + 1) × 1000 | kept | kept; joining from the lobby: = 0 (not for spectators) | kept | = 0 (not for spectators) | all 4 = 0 | kept |
| score text | empty | "SCORE: 0" | re-formatted with the bonus | kept | kept: after Esc it still shows the old score until the next points D | kept | kept (not re-formatted) | kept | — |
| peers' scores | 0 | — | — | — | written by every packet | same | — | all = 0 | kept |
| options | mouse if a driver answers, else keyboard; PC speaker on; Lines below a 386, else Polygons; /M colours | kept; changed only by the menu bar on the attract screens and in the lobby (Graphics takes effect at once; explosion size only at the next [L]). Choosing a mouse item without a mouse driver still sets mouse control: the pointer never moves, so steering stays neutral | kept | ||||||
| universe | 0 | kept | = chosen 0..7 | ||||||
| high scores | 1000, 2000 … 10000, no initials; replaced by HISCORES.DAT if present | attract: last score inserted if above entry 0 (lower ones shift down, the lowest drops out); initials typed; file written; score[0] = 0 | kept | kept | — | — | kept | kept | — |
| attract page | 0 | kept from the last visit (−1 for a new high score; 1 after initials) D | — | — | — | — | — | kept | — |
| menu bar | closed, menu 0, item 0 | kept between screens (a popup left open with Space is still open on the next menu screen D) | kept | ||||||
| menu layout | sizes 0 | kept | every time the title is left: texts, columns, hotkeys set; each popup's height grows by 12 per item (never reset) | kept | |||||
| keyboard owner | 0 | 0 on attract/start menu, 1 from the introduction on | 1 | 1 | 0 on the name screen, 1 in flight | 1 | 1 (until a BIOS screen sets 0) | 0 | 0 |
| pointer mode | arrow | arrow on attract; box from [N] on | box | box | box from [N] on | box | box | arrow (title, lobby, attract) | arrow |
Player values
| Value | Start | New game (SP) | New level (SP) | Death (SP) | Flight (MP) | Respawn (MP) | Esc | Title | Universe |
|---|---|---|---|---|---|---|---|---|---|
| position | (0, 0, 0) | = (0, 0, 0) | = (0, 0, 0) (Level Completed) | frozen (no movement while dead) | slot corner: 1 (0,0,0), 2 (0,0,2048), 3 (2048,0,2048), 4 (2048,0,0); spectator (0,0,0) O slots 1, 2 | +1024 units along your axis c ("up", drawn downward) | kept | = (0, 0, 0) | — |
| velocity | 0 | = 0 | = 0 | kept, not applied | = 0 | kept: the ship resumes its old drift until the controller brakes it to throttle 0 | kept | = 0 | — |
| axes | forward +z, right +x, up +y | reset; then the intro screen redraws about 70 times a second and rolls the camera by −16/2048 of a turn each time; nothing undoes this, so your first flight starts tilted by however long you looked at the intro O | same (reset by Level Completed, rolled by the introduction) O | still turn (steering works while dead) | heading per slot: 1 −x, 2 +z, 3 +x, 4 −z; spectator +z (the name screen's roll is overwritten) | kept | kept | reset (menus roll it again) | kept |
| turn rates | 0 | kept: with the keyboard a turn held at the end of the last flight continues and decays by 2 per frame | kept | updated as in flight | kept | kept | kept | kept | — |
| throttle | 0 | = 0 | = 0 | kept, not used | = 0 | = 0 | kept | kept | — |
| shields | 32 | = 32 | +8, at most 32 | 0; = 32 when Game Over ends (Enter or high score) | = 32 | = 32 | kept: Esc while dead leaves 0, and all sounds stay off until the next player start | kept | — |
| missiles | 0 | = 16 | kept | kept | = 0 (joining: 16, then 0) | kept | kept | kept | — |
| extra thrust | 0 | = 0 | kept | kept | = 0 | = 0 | kept | kept | — |
| fire power | 0 | = 0 | kept | kept | = 0 | = 0 | kept | kept | — |
| cloak time, cloak on | 0, 0 | = 0, 0 | kept (always 0 in SP) | kept | = 0, 0 | = 0, 0 | kept | kept | — |
| death countdown | 0 | kept (normally 0; Esc during the count leaves the rest, harmless) | kept | = 64, −1 per frame of the death screen | kept | 0 (ran out) | kept (Esc during the count leaves the rest) | kept | — |
| killer | 0 | — | — | — | kept | kept (set at each death) | kept | kept | — |
| collision immunity | 0 | kept: counts down only in flight, so up to 8 frames carry into the next flight | kept | counts down | kept | kept | kept | kept | — |
| tumble, tumble rates | 0 | kept: a tumble cut by Esc goes on for its remaining frames (up to 48) | kept | counts down | kept | kept | kept | kept | — |
| fire cooldown | 0 | kept; set to 0 when both fire button and Space are released, but only checked while alive | — | ||||||
| target lock | 0 | kept until the first alien update of the flight: a Caps Lock latched on the intro then fires a missile in frame 1 (the player is updated before the aliens), using one from stock; the aliens were just cleared, so it flies straight D | same | recomputed | kept: never recomputed in multiplayer, so the sight shows whatever the last single-player frame left D | kept | kept | kept | — |
| radar zoom | −1 | kept for the whole session | |||||||
| message text | none (not visible: the timer is 0) | kept; replaced whenever a new message starts | |||||||
| message timer | 0 | = 0 | = 0 | paused (counts only while alive) | = 0 | kept (resumes) | kept | kept | — |
| flash | 0 | used and set to 0 at the start of every flight frame | |||||||
| key latches | all 0 | Esc cleared at flight start; Esc and Enter cleared by the introduction; Space, Caps Lock, keypad ± latched on the introduction act in the first flight frame | Enter, Esc cleared by Level Completed and the introduction; others kept | Enter cleared during the countdown and on accept | Esc cleared at flight start; others kept | Enter cleared | Esc latch stays until the next flight start clears it | kept | — |
| mouse button latch | 0 | cleared on entering most screens and when used; the help page leaves a closing click latched | |||||||
| own status | 0 | — | — | — | 2 on the name screen (stale peer hits applied there can overwrite it with 1); = 0 at flight start | = 0 | kept (1 if dead, else 0 or −1) until the name screen sends 2 | kept | — |
Esc is tested at the top of every flight frame, also while "Game Over" is showing. It sets your score to 0, so pressing Esc during the 64-frame pause forfeits a score that would have entered the high-score table D. It also leaves the shields at 0 through the attract and start-level screens, where every sound request is ignored (the sound driver plays nothing while shields are 0), until the next game's player start gives 32 again (chapter 10).
World values
| Value | Start | New game (SP) | New level (SP) | Death (SP) | Flight (MP) | Respawn (MP) | Esc | Title | Universe |
|---|---|---|---|---|---|---|---|---|---|
| aliens | all free | all cleared: free, at (0,0,0), facing +z, pitch and roll 0, state 0 (yaw rate not cleared) | same | keep flying and shooting (they ignore a dead ship) | cleared (unused) | — | kept until the next clear | kept | — |
| reused alien slot | a new alien in a slot freed during the level keeps the previous alien's orientation and turn rates (see "Fields of one alien") | ||||||||
| alien budgets, aliens left, alien limit, Pirate speed | 0; Pirate speed 1000 (data) | set from the level (formula under [L]) | same | kept | — | — | kept | kept | — |
| spawn rotation | 0, 0 | = 0, 0 | = 0, 0 | kept | — | — | kept | kept | — |
| frame counter | 0 | = 0 (first flight frame is 1; first alien at frame 64) | = 0 | counts on | = 0 | kept | kept | kept | — |
| pods | none | all 6 exist, pods left = 6; placed at home (pod 0 −x, 1 −z, 2 +x, 3 +z, 4 −y, 5 +y, 1000 units out), idle, turn limit 128 | every 4th level (index 0, 4, 8 …) all 6 again; the existing ones back home, idle; lost ones stay lost | keep being attacked | exist but are not simulated | — | kept | kept | — |
| exploding pod at level end | a pod still exploding when the last alien is removed (shot by you, which is the easy way, or destroyed by a mutant) is put back home as a living pod, while "pods left" already counts it as lost D | ||||||||
| own shots | free | kept: shots in flight continue up to their 24 frames in the new flight | kept | keep flying | kept | kept | kept | kept | — |
| alien shots | free | kept (up to 24 frames) | kept | keep flying | kept | — | kept | kept | — |
| missiles (both kinds) | free | all freed | all freed | keep flying | all freed | — | kept | kept | — |
| own satellite | none | removed | removed | kept | removed | kept | kept | kept | — |
| satellite counter | 0 (first satellite: thrust) | kept for the whole session and across modes: the first pick-up of a game is the next kind of the cycle | |||||||
| explosion particles | 0 | 12 (Lines) or 38 (Polygons) | same, from the current mode | kept | same | kept | kept | kept | — |
| stars | constant; how many are drawn follows the Graphics option at once | ||||||||
Network values
| Value | Start | New game (SP) | New level (SP) | Death (SP) | Flight (MP) | Respawn (MP) | Esc | Title | Universe |
|---|---|---|---|---|---|---|---|---|---|
| network open | 0 | — | — | — | 1 | 1 | 1 | opened when Multi Player is chosen; going back to the title leaves it open (reopened on the next Multi Player); during a following single-player game the posted lobby listens still write names into the name table (harmless) D | closed, then opened for the new universe |
| peers, slots, channels, colours | 4 peers; colours all 10 | — (satellites clear iterates over the old peer count, harmless) | — | — | set on leaving the lobby (3 peers playing, 4 spectating) | kept | kept | kept | kept until the next lobby exit |
| peer ships | none shown | — | — | — | player start: all 4 hidden, explosion size set, ship models given by slot; shown again on a packet with status ≤ 0 | kept | kept | kept | kept |
| liveness | 0 | — | — | — | = 0 on leaving the lobby; 4 on a packet, −1 per missed frame | kept | kept (the name screen keeps syncing) | kept | kept |
| peer events (receive buffer) | 0 | — | — | — | never cleared: the last packet's hit words are applied again every frame without a new packet O run #24 | kept | kept | kept | kept |
| peer shot flags, local copies | 0 | — | — | — | never cleared; a copy ends when its flag returns to 0 | kept | kept | kept | kept |
| peer satellites | none | cleared (harmless) | cleared | — | cleared | kept | kept | kept | kept |
| outgoing hit and satellite words | 0 | — | — | — | cleared at the start of each own-shot update (every flight frame, not for spectators); a hit found in frame N is sent at the top of frame N + 1 | kept | kept: a hit or pick-up made in the frame before Esc is sent again in every name-screen packet. The victim applies hit words whatever the sender's status, so every packet takes 1–2 shields and re-arms its 64-frame death countdown: it cannot leave its death screen until the shooter is back in flight and the words are cleared; a satellite word removes the owner's satellite every frame D | kept | kept |
| own shot flags | 0 | follow the own shots (kept with them) | |||||||
| names | all empty | — | — | — | lobby: overwritten by names heard; name screen: own name edited from length 0 (the first key replaces an old name; Backspace cannot shorten it) | kept | kept | kept | kept (new packets overwrite) |
| lobby "taken" counts | 0 | — | — | — | = 0 when the network opens and when a session ends; 32 on a lobby packet, −1 per lobby frame | — | — | kept | = 0 |
Exact rules: the initialisation routines in order
The pseudocode follows the original's order exactly. Names in parentheses are the source
routines; numbers are decimal unless written 0x…. reset_orientation is used so often
that it comes first.
reset_orientation() (player_reset_orientation, src/players.c)
axis_a = (0, 0, 16384); axis_b = (16384, 0, 0); axis_c = (0, 16384, 0)
position = (0, 0, 0); velocity = (0, 0, 0) all 64 bits of every component
player_start() (player_start, src/players.c)
reset_orientation()
throttle = 0; shields = 32
if single player: return
for i in 0..3: peer_ship[i].type = 0; peer_ship[i].particles = explosion_particles
if spectator: peer_ship[i].model = ship_model[i] for i in 0..3; return
slot 0: axis_a = (-16384,0,0); axis_b = (0,0,16384); axis_c = a x b = (0,16384,0)
slot 1: position.z = 2048 (orientation as reset: +z)
slot 2: axis_a = (16384,0,0); axis_b = (0,0,-16384); axis_c = (0,16384,0); position = (2048, 0, 2048)
slot 3: axis_a = (0,0,-16384); axis_b = (-16384,0,0); axis_c = (0,16384,0); position.x = 2048
peer_ship[0..2].model = ship models of the other three slots, in slot order
aliens_clear() (src/aliens.c)
for each of the 8 aliens: type = 0; pos = 0; fwd = +z, right = +x, up = +y;
pitch_rate = 0; roll_rate = 0; state = 0 (yaw_rate kept)
for each of the 4 player missiles and 4 alien missiles: type = 0
satellites_clear() (src/satellite.c)
own satellite: type = 0; axes reset; particles = 12
for i in 0 .. number_of_peers-1: peer satellite i: type = 0; model = shields model;
axes reset; particles = 12
pods_reset() (src/pods.c)
for each of the 6 pods: type = 1 (state is not touched)
pods_left = 6
pods_place() (src/pods.c)
for each pod with type > 0:
axes reset; pos = (pod_x[i], pod_y[i], pod_z[i]) / 4 world units
(tables ±4000 → ±1000 units: pod 0 −x, 1 −z, 2 +x, 3 +z, 4 −y, 5 +y); home = pos
state = 0; model = pod; max_turn = 128; accel = 0; speed = 0
particles = explosion_particlesPROGRAM START (main, src/main.c)
seed the random generator from the clock; select the built-in texts
for each argument starting with '/': look only at the next character, upper-cased
'M': monochrome = 1; colours = {8,7,15,7,15,15,7,7,7,15,15,7}
'?' or 'H': print the version banner and exit
program folder = argv[0] up to and including the last '\' (else ".\")
no EGA/VGA → message, exit; no 32 KB buffer → message, exit
mouse_enabled = (mouse driver answers); check "Normal Mouse" if so, else "Keyboard"
check "PC Speaker"
if CPU below 386: check "Lines", wireframe = 1 else check "Polygons"
load HISCORES.DAT over the built-in table (if the file opens)
graphics mode 640x350, show both pages once
install keyboard, mouse (if enabled) and timer handlers
mouse position = screen centre - (4, 4)
model size exponents: ships, aliens, mutant, pod = 1; title model A = 2
shift title model B's vertices by (+464, +384)
TITLE (label `title`)
title screen (game_mode_menu): arrow pointer; BIOS keyboard; reset_orientation;
multiplayer = 0 (Single Player preselected); loop until a choice:
Esc → shutdown; Enter on Multi Player → open the network (failure → error page,
Esc → shutdown)
scores[0..3] = 0
lay out the menu bar (menu_build; each popup's height grows by 12 per item)NEW GAME (label `restart`)
reset_orientation()
if multiplayer:
menu bar gets the Universe menu
lobby: arrow pointer, BIOS keyboard, slot = 0 … (Esc → TITLE)
free slot chosen: spectator = 0; spectate chosen: slot = 0, spectator = 1
leave the lobby (net_start_session): cancel lobby listens; set peers, slots,
channels, radar colours; liveness[i] = 0; post peer listens; build send block
else:
menu bar without Universe; slot = 0; spectator = 0
repeat:
attract screens (Esc → TITLE): arrow pointer, BIOS keyboard, empty the BIOS
key buffer; if scores[0] > lowest high score: insert it, page = -1 (initials)
until the start-level menu returns Enter
(start-level menu: reset_orientation; level = 0; level chosen 0..7)
if not spectator: scores[slot] = 0
score_text = "SCORE: " + score 0 right-aligned in 6 characters
cloak_time = 0; cloak_on = 0
missiles = 16; fire_power = 0; extra_thrust = 0
player_start()
pods_reset()
pointer becomes the flight boxLEVEL (label `level`)
explosion_particles = wireframe ? 12 : 38
if multiplayer:
if not spectator:
name screen: BIOS keyboard; reset_orientation; status_out = 2;
name length counter = 0; every frame: post listens, send state,
synchronise with peers
Esc → end session; NEW GAME Enter → continue
else:
if (level AND 3) == 0: pods_reset()
pods_place()
alien_max = 4; if level > 12: alien_max = min(level - 8, 8)
counts[0] = 8 Pirates
pirate_speed = 500; if level > 7: pirate_speed = min((level - 7) * 100 + 500, 1000)
counts[1] = 2 * level Fighters
counts[2] = level > 1 ? 2 * (level - 1) : 0 Guardians
counts[3] = level > 3 ? 2 * (level - 3) : 0 Commanders
aliens_left = 0
for i in 0..3: counts[i] = min(counts[i], 8); aliens_left += counts[i]
if pods_left == 0: counts = {0, 0, 0, aliens_left} all mutants
spawn_dir = 0; spawn_type_rot = 0
level introduction: keyboard captured; Esc, Enter, click latches cleared;
camera rolled -16 per intro frame (Esc → NEW GAME)
if multiplayer: player_start() else: throttle = 0
aliens_clear()
satellites_clear()
frame_count = 0; message_timer = 0
if multiplayer:
cloak_time = 0; cloak_on = 0; missiles = 0; fire_power = 0; extra_thrust = 0
status_out = 0
keyboard captured = 1; key[Esc] = 0
→ frame loop (chapter 17)
Worked example: level 6 (index 5): counts 8, 10 → 8, 8, 4; aliens left 28; at most 4 at once; Pirate speed 500. Level 14 (index 13): 8, 8, 8, 8 = 32 aliens, 5 at once, Pirate speed min(1100, 1000) = 1000. Level 1: 8 Pirates only O (run #4).
AFTER THE FRAME LOOP
(Esc broke it: if not spectator, scores[slot] = 0 was done inside the loop)
if spectator: end session; NEW GAME (back to the lobby)
if multiplayer: LEVEL (name screen, new life)
if shields == 0: NEW GAME (Esc while dead)
if aliens_left > 0: NEW GAME (death or Esc)
if level_completed() returns Esc: NEW GAME
LEVEL
level_completed() (level_complete, src/screens.c)
keyboard captured
add_score((level + 1) * pods_left * 1000) 32-bit; wraps above 1,000,000
shields = min(shields + 8, 32)
menu model = pod, 3000 units ahead
reset_orientation()
key[Enter] = 0; key[Esc] = 0; click = 0
loop: Enter or click → level = level + 1; return Enter; Esc → return Esc
death screen, every frame while shields == 0 (player_dead_screen, src/screens.c)
draw "Game Over" or "You were killed by " + name[killer AND 3]
if death_countdown > 0: key[Enter] = 0; click = 0; death_countdown -= 1; return stay
if single player and scores[0] > high_scores[0]: shields = 32; return leave
draw "Press ENTER to restart"; no Enter and no click: return stay
shields = 32; sound 4; key[Enter] = 0; click = 0
if single player: return leave
[R] RESPAWN (multiplayer, stays in the frame loop):
throttle = 0; status_out = 0; cloak_time = 0; cloak_on = 0
fire_power = 0; extra_thrust = 0
position += axis_c * 1024 units (score, missiles, velocity, axes,
return stay rates, killer, immunity, tumble kept)Whatever kills you sets shields to 0 and the death countdown to 64 in the same frame. In multiplayer a peer's hit also sets status 1 and the killer to that peer's slot; ramming a peer sets the killer to its slot + 4. The flight continues: you can still turn, but no longer thrust, fire, cloak or move, and aliens, their shots and missiles ignore you.
For a rebuild
Keep all of this in one explicit object instead of scattered globals, so that "reset" is a visible operation:
GameState {
session: { screen, mode, spectator, slot, level, scores[4], options,
universe, highScores[10], attractPage, menu, input }
player: { pos, vel, axes, rates, throttle, shields, missiles, extraThrust,
firePower, cloakTime, cloakOn, deathCountdown, killer,
bumpImmunity, tumble, tumbleRates, fireCooldown, haveTarget,
radarZoom, message, flash, status }
world: { aliens[8], alienBudget[4], aliensLeft, alienMax, pirateSpeed,
spawnDir, spawnTypeRot, frame, pods[6], podsLeft,
shots[8], alienShots[8], missiles[4], alienMissiles[4],
satellite, satelliteCounter, explosionParticles }
network: { open, peers[]: { slot, ship, alive, events, shots[8], satellite },
outEvents, myShotFlags, names[4], slotHeard[4] }
}
Write [N], [L], player start and [R] as functions that do exactly the steps above, in that order. Then decide, for each red cell, whether your version keeps the original's carry-over. A reasonable split:
- Keep (they shape how the game plays): kept shields, missiles, thrust and fire power between levels; the satellite cycle shared by the session; the per-level pod rule; the radar zoom surviving everything; new aliens keeping the old orientation (cheap and harmless).
- Fix (they are accidents): the rolled camera at level start, shots, tumble and immunity carried into the next flight, stale key latches, the stale target lock in multiplayer, the score text after Esc, the re-applied hit and satellite words, the growing menu popups, the name editor starting at length 0, sounds silenced after Esc while dead, the revived exploding pod.
Chapter 20, Authentic and Modern modes, turns this into two switchable modes: Authentic keeps every carry-over listed here; Modern fixes the second list.