How NetWars Works Chapter 14 of 21, plus appendices

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

ValueMeaningType, range, unitSource global
screenwhich 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
modesingle player or multiplayer0 / 1g_multiplayer DG:2AE8
spectatorwatching a network game: never sends, cannot fire or be hit0 / 1g_spectator DG:2AE6
slotown player slot (PLAYER 1–4); 4 = "spectate" chosen in the lobby, then 00..3 (4 briefly)g_player_index DG:2AEA
levelsingle-player level, counted from 0 (shown as level + 1)0.. (start menu offers 0..7)g_level DG:BF88
scoresscore of each slot (single player: slot 0); peers' entries are written by their packets4 × 32-bit, 0..1,000,000 (wraps)g_scores[4] DG:2AF2
score textthe HUD text "SCORE: %6ld", re-formatted only when points are added and at a new gamestringg_score_text DG:BF8A
optionscontrol (keyboard / mouse / reversed mouse), sound (none / PC speaker), graphics (Lines / Polygons), monochrome colours (/M)flags; colours are 12 palette indicesg_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
universewhich of the 8 independent network games0..7 (shown 1..8)g_universe DG:320C
high scoresten scores, ascending (entry 0 = lowest), and their initials10 × 32-bit; 10 × 4 charsg_hiscore_scores DG:2BCE, g_hiscore_initials DG:C02A
high-score entryindex of the new entry; characters typed so far0..9; 0..3g_hiscore_rank DG:BFB8, g_initials_len DG:2BF6
attract pagewhich attract screen shows: −1 initials entry, 0 instructions, 1 high-score table−1..1g_attract_page DG:2BF8
menu baropen menu, highlighted item, "a pull-down is open"; per menu its layout (column, hotkey, popup size)intsg_menu_cur DG:2CFE, g_menu_item DG:2D00, g_menu_open DG:2D02, menu records DG:2C02..2CCE
keyboard owner1: the game reads the key table (flight, level intro, level complete); 0: keys go through the BIOS (menus, name entry)0 / 1g_kbd_captured DG:3BC7
pointer modemouse pointer shape and area: arrow over the whole screen, or flight box1 arrow / 2 boxg_mouse_mode DG:3BCB
timer ticks18.2 Hz ticks since the current frame (or page) began; used for pacingintg_tick_count DG:3BC9
random generatorBorland rand() state; seeded once from the clock at start, never reseeded; used by collision tumbles and satellite positions32-bit seedrtl_rand_seed DG:AEF8
sound sequencerthe PC-speaker sound being played: tones left and next tone; a sound keeps playing across screen changeswordsg_snd_remaining DG:A2C0, g_snd_ptr DG:A2C2
unused sound flagcleared by Sound ▸ None, never readintg_sound_unused DG:2AC8
program folderwhere HISCORES.DAT is read and writtenstringg_prog_dir DG:BB06

Player

ValueMeaningType, range, unitSource global
positionyour ship (= camera) in the world3 × 64-bit; world unit = middle wordg_ship_position DG:22D2
velocityadded to the position every frame while alive3 × 64-bit, world units per frame in the middle wordg_ship_velocity DG:2B02
axesforward (a), right (b), "up" (c, drawn downward on screen)3 × 3 Q14g_cam_axis_a/b/c DG:22BA/22C0/22C6
turn ratespitch, roll, yaw applied this frameangle steps per frame; keyboard −24..24, mouse unboundedg_pitch_rate DG:22CE, g_roll_rate DG:22CC, g_yaw_rate DG:22D0
throttlewanted 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 velocityvelocity along right, up, forward; recomputed every living frame3 × 16-bit, world units per frameg_vel_body DG:C052
shieldshealth; 0 = dead0..32g_shields DG:2AF0
missileshoming missiles in stock (single player)0..32g_missiles DG:2B8E
extra thrustboost units; each strong correction step uses 10..4096g_extra_thrust DG:2B8C
fire powerpowered shots left; each shot uses 10..256g_fire_power DG:2B8A
cloakcloak frames left; cloak switched on (multiplayer only)0..512 frames; 0 / 1g_cloak_time DG:2B84, g_cloak_on DG:2B86
death countdownframes the death screen still ignores Enter0..64g_death_countdown DG:325A
killerslot of the player who killed you; +4 = rammed0..7g_killer_index DG:3258
collision immunityframes without new collision damage after a bump0..8g_bump_immunity DG:B20E
tumbleframes of forced spin after a bump, and the decaying spin rates0..48; rates −48..48g_tumble DG:C05A, g_tumble_rates[3] DG:2B7A
fire cooldownframes until held fire shoots again0..2g_fire_cooldown DG:2B88
target lockan alien is in the crosshair (set by the alien update)0 / 1g_have_target DG:2B90
radar zoomradar scale exponent (keypad + / −)−6..2g_radar_zoom DG:2ACC
messagecurrent HUD message text and frames left to show itpointer; framesg_message_ptr DG:BFAA, g_message_timer DG:2B82
flashbackground colour of the next frame (hit / collision flash)palette index, 0 = noneg_flash_color DG:2AE4
input latchesper key: held (81h) or "pressed since cleared" (01h); mouse button the same128 bytes; wordg_key_state[128] DG:3B47, g_mouse_click DG:3BD5
mouse positionpointer position from the mouse driverpixelsg_mouse_x DG:3BCD, g_mouse_y DG:3BCF
own statuswhat your packets say about you: 0 alive, −1 cloaked, 1 killed, 2 not in play−1..2g_status_out DG:BFB2

World

ValueMeaningType, range, unitSource global
aliens8 alien slots (fields: next table)8 body recordsg_aliens[8] DG:C388
alien budgetsaliens of each type still to appear this level4 × 0..8g_alien_counts[4] DG:BABE
aliens leftaliens still to be removed; the level ends at 00..32g_aliens_left DG:BFB6
alien limitalien slots usable at once4..8g_alien_max DG:C306
Pirate speedtype 1 maximum speed, rewritten per level500..1000 (raw speed)g_alien_types[0].speed DG:31A2
spawn rotationside of the next alien (right, left, up, down); offset of the type searchcounters, used & 3g_spawn_dir DG:C058, g_spawn_type_rot DG:C2FC
frame counterframes since the flight began; aliens may appear every 64th, satellites every 128thintg_frame_count DG:BD46
pods6 pods (type 1 = exists; state −1 exploding, 0 idle, 1 claimed, 2 towed, 3 returning)6 body recordsg_pods[6] DG:CCF2
pods leftpods still counted (bonus, mutants at 0)0..6g_pods_left DG:C708
own shots8 laser shots: 0 free, 1..24 frames of life (+256 = powered), negative = exploding8 shot recordsg_player_shots[8] DG:BD68
alien shots8 alien laser shots: 0 free, else frames of life (24 at launch)8 shot recordsg_alien_shots[8] DG:C912
missiles4 player missiles, 4 alien missiles (type 0 = free, state −1 exploding)2 × 4 body recordsg_player_missiles DG:CB32, g_enemy_missiles DG:C752
own satellitethe one pick-up you own (type 0 none, 1..4 kind, −1 exploding)body recordg_my_item DG:C28C
satellite counterdrives the kind cycle (counter & 3: 0 missiles/cloak, 1 thrust, 2 fire power, 3 shields)int, +1 per satelliteg_satellite_counter DG:2B80
explosionseach exploding body counts its age in its distance-exponent field; the particle count given to bodies created from now onage 0..64; count 12 (Lines) or 38 (Polygons)body dist_exp; g_explosion_particles DG:BABC
stars256 fixed directions; 64 drawn in Lines mode, 256 in Polygons modeQ14 vectors, constantg_stars[256] DG:2302

Fields of one alien

Every flying object is a body record (chapter 5); for an alien the fields mean:

FieldMeaningSet when the alien appears (alien_spawn)
type0 free slot; 1 Pirate, 2 Fighter, 3 Guardian, 4 Commander or mutanttype of the chosen budget; 4 if no pods are left
posposition, 3 × 64-bityour position + 16384 units along your right, left, "up" or "down" axis
fwd, right, uporientation, Q14not set: kept from the slot's last alien (identity, facing +z, at level start)
pitch / roll / yaw rateturn per framenot set: kept (pitch and roll are 0 after a level start, yaw is never cleared)
statebehaviour state; −1 exploding0; 4 for a mutant
speed, max speed, accel, max turnflight parametersspeed = max speed = type's speed; accel 0; max turn = type's turn
hit pointsdamage it can take2, 2, 4, 8 by type (mutant 8)
dist_expdistance exponent (larger = nearer); explosion age while exploding0
particlesexplosion sparks12 or 38 (current value)
modelshapetype's model; mutant model if no pods are left
targetclaimed pod (Pirate, Commander)none
cam_x/y/z, dir, scr_x/yrender outputsrecomputed when it is drawn
visible0 not drawn, 1 drawn, 2 in the crosshairnot 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

ValueMeaningType, range, unitSource global
network openthe universe's 4 channels (IPX sockets) are open0 / 1g_net_open DG:324E
number of peersother players listened to: 3 when playing, 4 when spectating3..4g_num_peers DG:2AE2
peer slots, channelswhich slot each peer index is; its channel; your own channel4 ints; socket wordsg_peer_slot DG:D0B2, g_peer_socket DG:D082, g_my_socket DG:D4A8
peer coloursradar colour per peer (slots 0, 1 light green; 2, 3 light blue)palette indicesg_col_players[4] DG:2ABE
peer shipsone body per peer: position, axes, velocity (in the home field), type 1 = shown, state −1 = exploding4 body recordsg_peer_ships[4] DG:C05C
livenessframes of grace per peer: 4 after a packet, −1 per missed frame, 0 = inactive0..4g_peer_alive[4] DG:3250
peer eventsreceive buffer of each peer's event record: 3 hit words, status, satellite event4 × 5 wordsg_peer_events DG:D08A
peer shotseach peer's 8 shot flags (0 none, 1 fired, 2 powered, 3 exploding) and our local copies of those shots4 × 8 bytes; 4 × 8 shot recordsg_peer_shots DG:BD48, g_remote_shots DG:B23C
peer satelliteseach peer's satellite (type + position from its packet)4 body recordsg_peer_items DG:BB86
outgoing eventshit words (victim slot + 1, +256 powered), satellite event (owner + 1 taken, +256 shot)3 + 1 wordsg_event_out[0..2] DG:BFAC, g_item_event_out DG:BFB4 (status: player table)
own shot flagsthe 8 flags sent for your shots8 bytes 0..3g_my_shots DG:C2FE
namesname of each slot (15 characters + end mark); own one edited on the name screen, others from packets4 × 16 charsg_player_names DG:325C
lobby slot takenlobby frames left before a silent slot shows "Free"0..32g_slot_heard[4] DG:D4AA
kill messagethe text "%s has been killed"stringg_kill_msg DG:BAC6
receive / send blocksIPX 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.

SINGLE PLAYER MULTIPLAYER Program start Exit to DOS Title: Select Game Mode Instructions ⇄ high scores(initials entry first after a top-ten game) Select Start Level 1–8 Level n (introduction) Flight Game Over(drawn over the running flight) Level n Completed Lobby: pick a slot or spectate(Universe menu here) Type your name (score board) Flight You were killed by …(drawn over the running flight) Flight (spectating) Esc Single Player Esc / Exit this mode Enter Esc Enter → [N], [L] Enter (end of [L]) shields 0 last alien gone,still alive Enter:level + 1, [L] Esc(score kept) Esc Esc (score 0) after 64 frames: at once if the score enters the table, else on Enter Multi Player Esc / Exit this mode slot → [N] Esc Enter (rest of [L]) shields 0 Enter → [R] Esc (score 0) Spectate → [N], [L] Esc → back to the lobby [N] new game · [L] level setup (SP) / life setup (MP) · [R] respawn · red: flight screen · dashed grey: text over the flight Not drawn: F1 help and pull-down menus; a death after the last alien, or Esc as it goes, also leads to "Level Completed".
Every screen of NetWars and every way between them, with the initialisation each move runs. The labels follow main in src/main.c: title, restart ([N]) and level ([L]).

Every transition

From → toEventWhat runs, in order
start → titleprogram startstartup (below); then the title screen
title → exitEsc; or Enter on Multi Player when IPX fails, then Escshutdown: network closed, handlers removed, text mode, exit
title → attractEnter or click on Single Playerall 4 scores = 0; menu bar laid out again; Universe menu removed; slot 0, not spectating
title → lobbyEnter on Multi Player and the network opensnetwork opened (4 channels of the universe, lobby listens, "taken" counts 0); all 4 scores = 0; menu bar laid out; Universe menu added
attract → titleEsc, or Game ▸ Exit this modetitle screen
attract → start levelEnter, or Game ▸ Start new gamestart-level menu: level = 0, camera reset
start level → attractEscattract screens again (they do not reset their page)
start level → level introEnter or click[N] new game, then [L] up to the introduction
level intro → flightEnter or clickrest of [L]: throttle 0, aliens and missiles cleared, satellites cleared, frame counter 0, message off, keyboard captured, Esc latch cleared
level intro → attractEscback to [N]'s start (score kept: it can still enter the table)
flight → level completedno aliens left and shields > 0 (checked at the top of a frame)bonus, shields +8 (max 32), camera and position reset
level completed → level introEnter or clicklevel + 1; [L]
level completed → attractEscback to [N]'s start, score (with bonus) kept
flight → Game Overshields reach 0death countdown 64; the world keeps running, your ship stops moving
Game Over → attractafter the 64 frames: at once if your score beats the lowest high score, else on Enter/clickshields = 32; then back to [N]'s start (attract inserts the high score)
Game Over → level completedas 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) Dthe next level follows although you died
flight (or Game Over) → attractEsc (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 0Esc latched in the frame the last alien's explosion ends (so aliens left is 0 and shields > 0 when the loop ends) Dscore = 0 by the Esc, then Level Completed adds only the bonus
lobby → titleEsc, or Game ▸ Exit this modetitle screen (the network stays open)
lobby → name screenEnter or click on a slot nobody is heard onleave the lobby (peer listens and send block set up for your slot); [N]; then [L] starts with the name screen
lobby → spectatingEnter on the spectate spot or Game ▸ Spectate current gamesame, as spectator; spectators skip the name screen
name screen → lobbyEscend session (peer listens cancelled, lobby listens re-posted, "taken" counts 0); back to [N]'s start
name screen → flightEnter or clickrest of [L], including player start at your slot's corner
flight → "You were killed"shields reach 0status "killed", killer remembered, countdown 64
"You were killed" → flightEnter or click after the 64 frames[R] respawn
flight (or "killed") → name screenEscyour score = 0; then [L] (name screen first)
spectating → lobbyEscend session; back to [N]'s start (the lobby)
lobby → lobbyUniverse ▸ 1..8old 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:

"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

ValueStartNew game (SP)New level (SP)Death (SP)Flight (MP)Respawn (MP)EscTitleUniverse
mode0kept (0)keptkeptkept (1)keptkept0 on entry; 1 if Multi Player is chosen and the network openskept
spectator0= 0keptkeptset by the lobby: 1 spectate, 0 slotkeptkeptkeptkept
slot0= 0keptkeptlobby: = 0 on entry, then the chosen 0..3 (spectate: 4, then 0)keptkeptkeptkept
level0start menu: = 0, then the chosen 0..7+1kept——keptkept—
own score0= 0 (after the attract screens used the last one)+ pods left × (level + 1) × 1000keptkept; joining from the lobby: = 0 (not for spectators)kept= 0 (not for spectators)all 4 = 0kept
score textempty"SCORE: 0"re-formatted with the bonuskeptkept: after Esc it still shows the old score until the next points Dkeptkept (not re-formatted)kept—
peers' scores0———written by every packetsame—all = 0kept
optionsmouse if a driver answers, else keyboard; PC speaker on; Lines below a 386, else Polygons; /M colourskept; 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 neutralkept
universe0kept= chosen 0..7
high scores1000, 2000 … 10000, no initials; replaced by HISCORES.DAT if presentattract: last score inserted if above entry 0 (lower ones shift down, the lowest drops out); initials typed; file written; score[0] = 0keptkept——keptkept—
attract page0kept from the last visit (−1 for a new high score; 1 after initials) D—————kept—
menu barclosed, menu 0, item 0kept between screens (a popup left open with Space is still open on the next menu screen D)kept
menu layoutsizes 0keptevery time the title is left: texts, columns, hotkeys set; each popup's height grows by 12 per item (never reset)kept
keyboard owner00 on attract/start menu, 1 from the introduction on110 on the name screen, 1 in flight11 (until a BIOS screen sets 0)00
pointer modearrowarrow on attract; box from [N] onboxboxbox from [N] onboxboxarrow (title, lobby, attract)arrow

Player values

ValueStartNew game (SP)New level (SP)Death (SP)Flight (MP)Respawn (MP)EscTitleUniverse
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)—
velocity0= 0= 0kept, not applied= 0kept: the ship resumes its old drift until the controller brakes it to throttle 0kept= 0—
axesforward +z, right +x, up +yreset; 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 Osame (reset by Level Completed, rolled by the introduction) Ostill 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)keptkeptreset (menus roll it again)kept
turn rates0kept: with the keyboard a turn held at the end of the last flight continues and decays by 2 per framekeptupdated as in flightkeptkeptkeptkept—
throttle0= 0= 0kept, not used= 0= 0keptkept—
shields32= 32+8, at most 320; = 32 when Game Over ends (Enter or high score)= 32= 32kept: Esc while dead leaves 0, and all sounds stay off until the next player startkept—
missiles0= 16keptkept= 0 (joining: 16, then 0)keptkeptkept—
extra thrust0= 0keptkept= 0= 0keptkept—
fire power0= 0keptkept= 0= 0keptkept—
cloak time, cloak on0, 0= 0, 0kept (always 0 in SP)kept= 0, 0= 0, 0keptkept—
death countdown0kept (normally 0; Esc during the count leaves the rest, harmless)kept= 64, −1 per frame of the death screenkept0 (ran out)kept (Esc during the count leaves the rest)kept—
killer0———keptkept (set at each death)keptkept—
collision immunity0kept: counts down only in flight, so up to 8 frames carry into the next flightkeptcounts downkeptkeptkeptkept—
tumble, tumble rates0kept: a tumble cut by Esc goes on for its remaining frames (up to 48)keptcounts downkeptkeptkeptkept—
fire cooldown0kept; set to 0 when both fire button and Space are released, but only checked while alive—
target lock0kept 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 Dsamerecomputedkept: never recomputed in multiplayer, so the sight shows whatever the last single-player frame left Dkeptkeptkept—
radar zoom−1kept for the whole session
message textnone (not visible: the timer is 0)kept; replaced whenever a new message starts
message timer0= 0= 0paused (counts only while alive)= 0kept (resumes)keptkept—
flash0used and set to 0 at the start of every flight frame
key latchesall 0Esc cleared at flight start; Esc and Enter cleared by the introduction; Space, Caps Lock, keypad ± latched on the introduction act in the first flight frameEnter, Esc cleared by Level Completed and the introduction; others keptEnter cleared during the countdown and on acceptEsc cleared at flight start; others keptEnter clearedEsc latch stays until the next flight start clears itkept—
mouse button latch0cleared on entering most screens and when used; the help page leaves a closing click latched
own status0———2 on the name screen (stale peer hits applied there can overwrite it with 1); = 0 at flight start= 0kept (1 if dead, else 0 or −1) until the name screen sends 2kept—
Quirk: Esc on the Game Over screen

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

ValueStartNew game (SP)New level (SP)Death (SP)Flight (MP)Respawn (MP)EscTitleUniverse
aliensall freeall cleared: free, at (0,0,0), facing +z, pitch and roll 0, state 0 (yaw rate not cleared)samekeep flying and shooting (they ignore a dead ship)cleared (unused)—kept until the next clearkept—
reused alien slota 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 speed0; Pirate speed 1000 (data)set from the level (formula under [L])samekept——keptkept—
spawn rotation0, 0= 0, 0= 0, 0kept——keptkept—
frame counter0= 0 (first flight frame is 1; first alien at frame 64)= 0counts on= 0keptkeptkept—
podsnoneall 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 128every 4th level (index 0, 4, 8 …) all 6 again; the existing ones back home, idle; lost ones stay lostkeep being attackedexist but are not simulated—keptkept—
exploding pod at level enda 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 shotsfreekept: shots in flight continue up to their 24 frames in the new flightkeptkeep flyingkeptkeptkeptkept—
alien shotsfreekept (up to 24 frames)keptkeep flyingkept—keptkept—
missiles (both kinds)freeall freedall freedkeep flyingall freed—keptkept—
own satellitenoneremovedremovedkeptremovedkeptkeptkept—
satellite counter0 (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 particles012 (Lines) or 38 (Polygons)same, from the current modekeptsamekeptkeptkept—
starsconstant; how many are drawn follows the Graphics option at once

Network values

ValueStartNew game (SP)New level (SP)Death (SP)Flight (MP)Respawn (MP)EscTitleUniverse
network open0———111opened 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) Dclosed, then opened for the new universe
peers, slots, channels, colours4 peers; colours all 10— (satellites clear iterates over the old peer count, harmless)——set on leaving the lobby (3 peers playing, 4 spectating)keptkeptkeptkept until the next lobby exit
peer shipsnone shown———player start: all 4 hidden, explosion size set, ship models given by slot; shown again on a packet with status ≤ 0keptkeptkeptkept
liveness0———= 0 on leaving the lobby; 4 on a packet, −1 per missed framekeptkept (the name screen keeps syncing)keptkept
peer events (receive buffer)0———never cleared: the last packet's hit words are applied again every frame without a new packet O run #24keptkeptkeptkept
peer shot flags, local copies0———never cleared; a copy ends when its flag returns to 0keptkeptkeptkept
peer satellitesnonecleared (harmless)cleared—clearedkeptkeptkeptkept
outgoing hit and satellite words0———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 + 1keptkept: 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 Dkeptkept
own shot flags0follow the own shots (kept with them)
namesall 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)keptkeptkeptkept (new packets overwrite)
lobby "taken" counts0———= 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.

Exact rules: small routines
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_particles
Exact rules: program start and title
PROGRAM 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)
Exact rules: [N] new game
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 box
Exact rules: [L] level setup (single player) and life setup (multiplayer)
LEVEL                                     (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).

Exact rules: end of the frame loop, Level Completed, death and respawn
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)
Exact rules: what a death sets

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

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:

Chapter 20, Authentic and Modern modes, turns this into two switchable modes: Authentic keeps every carry-over listed here; Modern fixes the second list.