# Non-Room Scripts Documentation

This document covers all scripts that are not room-specific, including core game systems, region scripts (shared interactions across multiple rooms), and interaction scripts (specific player actions).

---

# Core System Scripts

These define the fundamental game systems. They don't have player-facing interactions themselves but enable everything else.

---

## Main.sc (Script 0)

### High-Level Summary

Main.sc is the primary game script that initializes the Sierra game engine and defines global variables and procedures used throughout the game. It contains the KQ4 game instance and is loaded at game start.

### Technical Notes

- **Script Number**: 0
- **Purpose**: Global game state, initialization, system procedures
- **Loaded**: At game start, remains in memory

### Key Global Procedures

| Name | Behavior |
|------|----------|
| `KQ4` | Main game entry point |
| `proc0_8` | Saves player state before animations (view, loop, cel, script) |
| `proc0_9` | Restores player state after animations |
| `proc0_13` | Displays "You can't do that" message |
| `proc0_21` | Initializes a new game (resets all state) |

---

## Game.sc (Script 994)

### High-Level Summary

Game.sc defines the core Game class that manages the game loop, event handling, save/load functionality, and coordinates all game systems. It handles the main game loop and user input processing.

### Technical Notes

- **Script Number**: 994
- **Purpose**: Core game engine

### Game Class Behaviors

| Behavior | Description |
|----------|-------------|
| Game loop | Runs continuously, processing input and updating display |
| Save game | Saves current game state to disk |
| Restore game | Loads saved game from disk |
| Restart | Restarts game from beginning |
| Change score | Modifies player score |

---

## Feature.sc (Script 998)

### High-Level Summary

Feature.sc defines the fundamental object classes used throughout the game for interactive elements. These include Views (static objects), Actors (moving characters), and Props (animated objects).

### Technical Notes

- **Script Number**: 998
- **Purpose**: Base classes for all interactive objects

### Class Hierarchy

| Class | Description |
|-------|-------------|
| `Feature` | Base class for all interactive objects |
| `View` | Static interactive visual element |
| `Actor` | Moving character that can walk around |
| `Prop` | Animated object that stays in place |

---

## InvI.sc (Script 995)

### High-Level Summary

InvI.sc defines the inventory system. It handles items the player carries, displays the inventory window, and manages item ownership (player, room, NPCs).

### Technical Notes

- **Script Number**: 995
- **Purpose**: Inventory management

### Inventory Behaviors

| Behavior | Description |
|----------|-------------|
| Show inventory | Opens dialog showing all player-owned items |
| Select item | Click item to select it |
| Item ownership | Items can belong to player, room, or NPC |

---

## Sound.sc (Script 989)

### High-Level Summary

Sound.sc defines the Sound class for playing audio, including background music and sound effects. It manages playback, looping, and notifies scripts when sounds complete.

### Technical Notes

- **Script Number**: 989
- **Purpose**: Audio playback

### Sound Behaviors

| Behavior | Description |
|----------|-------------|
| Play sound | Play a sound effect or music |
| Loop | Sounds can loop (repeat) or play once |
| Callback | When sound finishes, can trigger a script |

---

## User.sc (Script 996)

### High-Level Summary

User.sc manages player input including keyboard, mouse, and joystick controls. It handles the text parser input and converts player actions to game commands.

### Technical Notes

- **Script Number**: 996
- **Purpose**: Input handling

### Input Behaviors

| Behavior | Description |
|----------|-------------|
| Point and click | Click to walk |
| Direction keys | Arrow keys for movement |
| Text parser | Type commands (look, take, etc.) |

---

## MenuBar.sc (Script 997)

### High-Level Summary

MenuBar.sc provides the in-game menu system with options for saving, restoring, restarting, and adjusting game settings.

### Technical Notes

- **Script Number**: 997
- **Purpose**: Menu system

### Menu Options

| Menu | Options |
|------|---------|
| Game | Restart, Save, Restore |
| Speed | Normal, Fast |
| Sound | On, Off |
| Help | Help, Keys |

---

## SysWindow.sc (Script 991)

### High-Level Summary

SysWindow.sc defines the window and dialog classes used for displaying text, menus, and UI elements throughout the game.

### Technical Notes

- **Script Number**: 991
- **Purpose**: Window/dialog management

---

## Cycle.sc (Script 987)

### High-Level Summary

Cycle.sc defines animation cycle classes that control how sprites animate - forward, reverse, ping-pong, and walking cycles.

### Technical Notes

- **Script Number**: 987
- **Purpose**: Animation definitions

---

## Class_255_0.sc (Script 255)

### High-Level Summary

Class_255_0.sc contains low-level kernel procedures that interface with the SCI engine for graphics, sound, file I/O, and memory operations.

### Technical Notes

- **Script Number**: 255
- **Purpose**: Kernel interface

---

# Region Scripts

Region scripts provide shared interactions that apply to multiple rooms. They're loaded via `setRegions:` in room scripts.

---

## BeachReg.sc (Script 503)

### High-Level Summary

BeachReg.sc handles beach and ocean interactions. It applies to all coastal/beach rooms and provides responses for looking at and interacting with ocean, beach terrain, and swimming.

### Synonyms

- ocean = seawater = ocean

### Look Description

This region handles various beach-related look commands.

### Interactions

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look in/under ocean/water` (on land) | "You see a small island in the distance." |
| Documented | Look | `look in/under ocean/water` (swimming) | "You are underwater now." |
| Documented | Look | `look ocean/water` | "The endless ocean stretches out before you." |
| Documented | Look | `look fish` (has fish) | Shows the fish item |
| Documented | Look | `look fish` (no fish) | "You don't see any fish in the water." |
| Documented | Look | `look beach` | "The sandy beach is clean and smooth." |
| Documented | Look | `look sky` (day) | "The sky is blue and clear." |
| Documented | Look | `look sky` (night) | "The night sky is dark and full of stars." |
| Documented | Look | `look dirt/ground` | "You see only sand." |
| Documented | Look | `look boulder` | "A large boulder sits on the beach." |
| Documented | Look | `look forest` | "Dense forest grows right up to the beach." |
| Documented | Look | `look grass` | "Grass grows near the forest's edge." |
| Documented | Look | `look bush` | "Small bushes grow near the treeline." |
| Documented | Look | `look flora/blossom` | "Beautiful tropical flowers grow here." |
| Documented | Get | `get flora/blossom` | "The blossoms are too pretty to pick." |
| Documented | Get | `get water` | "You have no reason to carry water." |
| Documented | Action | `drink` (on land) | "You shouldn't drink seawater." |
| Documented | Action | `drink` (swimming, valid terrain) | Player drinks from the ocean, displays message |
| Documented | Action | `bathe/dive/wade` (not in ocean room) | "This isn't the right place to do that." |
| Documented | Action | `bathe/dive/wade` (in ocean room) | Player enters water |
| Documented | Action | `fish` / `capture fish` (in ocean room) | "You need a fishing pole to catch fish." |
| Documented | Action | `fish` / `capture fish` (has pole) | Player attempts to fish |

### Scripts

| Status | Behavior Type | Name | Trigger | Behavior |
|--------|--------------|------|---------|----------|
| Documented | Interaction | `drinking` | Player types "drink" while swimming in valid terrain | Plays drinking animation, player view changes to drinking sprite, shows message, then returns to swimming |

### Technical Notes

- **Script Number**: 503
- **Applies to**: Beach rooms (1, 8, 13, 25, 33-41, etc.)
- **Synonyms**: ocean = seawater = ocean

---

## Forest Region.sc (Script 508)

### High-Level Summary

Forest Region.sc provides forest-related interactions for rooms in forest areas. It also randomly spawns a raven that flies across the screen.

### Look Description

This region handles forest terrain and scenery.

### Interactions

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look boulder` | "A large boulder sits among the trees." |
| Documented | Look | `look dirt/ground` | "The ground is covered with leaves and dirt." |
| Documented | Look | `look grass` | "Green grass grows beneath the trees." |
| Documented | Look | `look bush` | "Thick bushes grow throughout the forest." |
| Documented | Look | `look flora` | "Tropical flora grows in the shade." |
| Documented | Look | `look blossom` | "Exotic blossoms grow on the forest floor." |
| Documented | Look | `look forest` | "The dense forest surrounds you." |
| Documented | Look | `look crow/bird` (raven present) | "A large black crow flies overhead." |
| Documented | Look | `look crow/bird` (no raven) | "You don't see any birds." |
| Documented | Action | `climb boulder` | "You can't climb that." |
| Documented | Get | `get blossom` | "You shouldn't pick the blossoms." |
| Documented | Action | `climb forest` | "You can't climb the forest!" |
| Documented | Talk | `converse crow` (raven present) | "The crow caws at you." |
| Documented | Talk | `converse crow` (no raven) | "There's no one to talk to." |
| Documented | Action | `capture/kiss crow` (raven present) | "You can't catch the crow." |
| Documented | Action | `capture/kiss crow` (no raven) | "There's nothing here." |

### Scripts

| Status | Behavior Type | Name | Trigger | Behavior |
|--------|--------------|------|---------|----------|
| Documented | Background | `ravenActions` | Raven animation completes | Removes raven actor from screen |

### Technical Notes

- **Script Number**: 508
- **Applies to**: Forest rooms (5, 9-12, 27-30, etc.)
- **Feature**: 20% chance of raven flying across screen on room entry

---

## GhostWander.sc (Script 603)

### High-Level Summary

GhostWander.sc handles the haunted house ghost encounters. It manages multiple ghost characters (miser, lady, lord, boy) that appear in various rooms throughout the haunted house area. Each ghost can give the player items.

### Synonyms

- room = cottage

### Look Description

This region manages ghostly encounters in and around the haunted house.

### Ghost Encounters

| Ghost | Rooms | Item Given | Score | Description |
|-------|-------|------------|-------|-------------|
| Miser | 66, 61, 58 | Chain (item 13) | +2 | Appears with chain, gives it to player |
| Lady | 60 | - | - | Wanders, no items |
| Lord | 68, 67, 64 | Potion (item 29) | +2 | Appears with potion |
| Boy | 63 | Harp (item 30) | +2 | Appears with harp |

### Interactions (Miser Ghost)

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look chain` | "The chain the miser always wore..." |
| Documented | Get | `get chain` | "You can't take it." |
| Documented | Inventory | `deliver chain` (has chain, ghost present) | Ghost accepts chain, gives player +2 score, advances to next ghost |
| Documented | Talk | `converse` | "You try to speak to the spirit..." |
| Documented | Look | `look` | "You see a ghost!" |
| Documented | Action | `kiss` | "You can't kiss a ghost!" |
| Documented | Action | `capture/get` | "You can't catch a ghost!" |
| Documented | Action | `kill` | "Ghosts can't be killed!" |
| Documented | Action | `help` | "Please help me..." |

### Interactions (Other Ghosts)

Similar interactions apply for lady, lord, and boy ghosts with their respective items.

### Scripts

| Status | Behavior Type | Name | Trigger | Behavior |
|--------|--------------|------|---------|----------|
| Documented | Interaction | `babyScript` | Continuous | Ghost wanders between rooms, no items |
| Documented | Interaction | `miserScript` | Continuous | Miser ghost appears, accepts chain, gives item |
| Documented | Interaction | `ladyScript` | Continuous | Lady ghost appears, no items |
| Documented | Interaction | `lordScript` | Continuous | Lord ghost appears with potion, gives item |
| Documented | Interaction | `boyScript` | Continuous | Boy ghost appears with harp, gives item |

### Technical Notes

- **Script Number**: 603
- **Applies to**: Haunted house rooms (17, 60-68)
- **Global Variables**: global133 (current ghost room), global134 (ghost type), global135 (active flag), global225 (encounter active)

---

## CemReg.sc (Script 505)

### High-Level Summary

CemReg.sc provides cemetery and graveyard interactions.

### Look Description

Handles cemetery-related look commands.

### Interactions

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look tombstone/grave` | "An old tombstone marks a forgotten grave." |
| Documented | Look | `look crypt` | "An ancient crypt looms before you." |

### Technical Notes

- **Script Number**: 505
- **Applies to**: Cemetery rooms (16, 18)

---

## MeadReg.sc (Script 506)

### High-Level Summary

MeadReg.sc provides meadow and grass interactions.

### Look Description

Handles meadow-related look commands.

### Interactions

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look grass` | "Green grass carpets this lovely meadowland." |
| Documented | Look | `look flower/flora/blossom` | "Colorful wildflowers grow in the meadow." |

### Technical Notes

- **Script Number**: 506
- **Applies to**: Meadow rooms (2, 14, 20, 26)
- **Synonyms**: flora = flora = blossom

---

## Gull Region.sc (Script 509)

### High-Level Summary

Gull Region.sc handles seagull interactions in coastal areas.

### Look Description

Handles seagull look commands.

### Interactions

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look gull/bird` | "A seagull flies overhead." |
| Documented | Action | `talk gull` | "The gull ignores you." |
| Documented | Action | `capture/kiss gull` | "You can't catch the bird." |

### Technical Notes

- **Script Number**: 509
- **Applies to**: Beach/coastal rooms

---

## Mountain Region.sc (Script 510)

### High-Level Summary

Mountain Region.sc handles mountain area interactions.

### Look Description

Handles mountain terrain look commands.

### Interactions

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look cliff/rock` | "Steep cliffs rise before you." |
| Documented | Look | `look snow` | "Snow caps the distant peaks." |

### Technical Notes

- **Script Number**: 510
- **Applies to**: Mountain rooms (30, 79)

---

## Ocean Region.sc (Script 512)

### High-Level Summary

Ocean Region.sc handles open ocean interactions.

### Look Description

Handles ocean look commands.

### Interactions

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look ocean/sea` | "The endless ocean stretches to the horizon." |
| Documented | Look | `look ship` | "A ship sails in the distance." |

### Technical Notes

- **Script Number**: 512
- **Applies to**: Ocean rooms (31, 32)

---

## Ogre's Region.sc (Script 507)

### High-Level Summary

Ogre's Region.sc handles ogre cottage exterior interactions.

### Synonyms

- room = cottage

### Look Description

Handles ogre cottage look commands.

### Interactions

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look cottage/house` | "A run-down cottage stands here." |

### Technical Notes

- **Script Number**: 507
- **Applies to**: Ogre cottage rooms (4, 49)

---

## RiverReg.sc (Script 514)

### High-Level Summary

RiverReg.sc handles river and bridge interactions.

### Look Description

Handles river look commands.

### Interactions

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look river` | "A wide river flows by." |
| Documented | Look | `look bridge` | "A wooden bridge crosses the river." |

### Technical Notes

- **Script Number**: 514
- **Applies to**: River rooms (21, 25)

---

## SwampReg.sc (Script 515)

### High-Level Summary

SwampReg.sc handles swamp interactions.

### Look Description

Handles swamp look commands.

### Interactions

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look swamp` | "A murky swamp surrounds you." |
| Documented | Look | `look mist/fog` | "A thick mist hangs over the water." |

### Technical Notes

- **Script Number**: 515
- **Applies to**: Swamp rooms (77, 78)

---

## Water Region.sc (Script 516)

### High-Level Summary

Water Region.sc handles still water (lake/pond) interactions.

### Look Description

Handles water look commands.

### Interactions

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look water/lake/pond` | "Still water reflects the sky." |

### Technical Notes

- **Script Number**: 516
- **Applies to**: Lake/pond rooms (15, 36, 38)

---

## Woods Region.sc (Script 517)

### High-Level Summary

Woods Region.sc handles deep woods interactions.

### Look Description

Handles woods look commands.

### Interactions

| Status | Behavior Type | Command | Response |
|--------|--------------|---------|----------|
| Documented | Look | `look woods/trees` | "Ancient trees tower above you." |

### Technical Notes

- **Script Number**: 517
- **Applies to**: Deep woods rooms

---

## regPan.sc (Script 523)

### High-Level Summary

regPan.sc handles Pan (the satyr) interactions in the meadow. This is the region that manages the satyr encounter.

### Technical Notes

- **Script Number**: 523
- **Applies to**: Room 2 (Meadow)
- **See Room 2 documentation for full interactions**

---

## Other Region Scripts

| Script | Number | Purpose |
|--------|--------|---------|
| gfReg.sc | 511 | Generic feature region |
| sForReg.sc | 518 | Additional forest interactions |
| regBFCastle.sc | 519 | Blue fairy castle |
| regDwarfHouse.sc | 521 | Seven dwarfs cottage |
| regOgreHouse.sc | 522 | Additional ogre interactions |
| regTroll.sc | 524 | Troll cave interactions |
| regUnicorn.sc | 525 | Unicorn interactions |
| rg600.sc | 600 | Baby ghost (additional) |

---

# Interaction Scripts

These scripts are triggered by specific player actions.

---

## PlayFlute.sc (Script 304)

### High-Level Summary

PlayFlute.sc handles the action of playing the magic flute. It shows Rosella playing the flute animation and plays flute music.

### Scripts

| Status | Behavior Type | Name | Trigger | Behavior |
|--------|--------------|------|---------|----------|
| Documented | Interaction | `playFlute` | Player uses flute item | Player plays flute animation with music, can attract Pan in room 2 |

### Technical Notes

- **Script Number**: 304
- **Used in**: Room 2 (Meadow) - requires flute item
- **Sound**: Plays music 77

---

## ShootBow.sc (Script 306)

### High-Level Summary

ShootBow.sc handles using the bow and arrow for hunting.

### Technical Notes

- **Script Number**: 306
- **Used for**: Hunting gameplay

---

## ReadBook.sc (Script 307)

### High-Level Summary

ReadBook.sc displays book/scroll content for reading.

### Technical Notes

- **Script Number**: 307
- **Used for**: Reading lore documents

---

## WearCrown.sc (Script 308)

### High-Level Summary

WearCrown.sc handles wearing the magic crown.

### Technical Notes

- **Script Number**: 308
- **Used for**: Crown transformation puzzles

---

## openPbox.sc (Script 309)

### High-Level Summary

openPbox.sc handles puzzle box interactions.

### Technical Notes

- **Script Number**: 309
- **Used for**: Puzzle solving

---

## PlayIt.sc (Script 305)

### High-Level Summary

PlayIt.sc is a generic "play" command handler for various instruments.

### Technical Notes

- **Script Number**: 305
- **Used for**: Playing various items

---

## Avoid.sc (Script 601)

### High-Level Summary

Avoid.sc provides NPC obstacle avoidance AI.

### Technical Notes

- **Script Number**: 601
- **Used by**: NPCs that need to avoid obstacles

---

## Jump.sc (Script 900)

### High-Level Summary

Jump.sc handles player jump mechanics.

### Technical Notes

- **Script Number**: 900
- **Used for**: Jump movement

---

# Special/Cutscene Scripts

---

## Intro.sc (Script 120)

### High-Level Summary

Intro.sc is the game introduction - King Graham's dream sequence where the wizard appears and sends Rosella on her quest.

### Look Description

The intro shows King Graham's dream/vision with animated sequences.

### Scripts

| Status | Behavior Type | Name | Trigger | Behavior |
|--------|--------------|------|---------|----------|
| Documented | Interaction | `introSc` | Game start | Main intro sequence with animated characters |
| Documented | Interaction | `stopKing` | Animation cue | Stops king animation |
| Documented | Interaction | `stopQueen` | Animation cue | Stops queen animation |
| Documented | Interaction | `stopSon` | Animation cue | Stops son animation |
| Documented | Interaction | `stopRosella` | Animation cue | Stops Rosella animation |
| Documented | Interaction | `checkHang` | Timer | Checks for key press to skip intro |

### Intro Sequence

1. King walks into throne room
2. Sits on throne
3. Wizard appears in fire
4. Wizard tells of needed quest
5. Vision of Daventry
6. Transition to room 221

### Keyboard Controls

| Key | Action |
|-----|--------|
| F2 | Toggle sound |
| Return | Restart game |

### Technical Notes

- **Script Number**: 120
- **Runs**: At game start before first room

---

## CopyProtect.sc (Script 701)

### High-Level Summary

CopyProtect.sc is the original copy protection screen. It asks players to identify a picture from the manual.

### Technical Notes

- **Script Number**: 701
- **Purpose**: Anti-piracy (can be bypassed in modern ports)
- **Mechanism**: Randomly selects 1 of 79 pictures to ask about

---

## EndMusic.sc (Script 710)

### High-Level Summary

EndMusic.sc plays the ending music sequence.

### Technical Notes

- **Script Number**: 710
- **Runs**: At game completion

---

## DebugMenu.sc (Script 999)

### High-Level Summary

DebugMenu.sc provides developer testing options (removed in release).

### Technical Notes

- **Script Number**: 999
- **Purpose**: Developer testing only

---

# Utility Scripts

---

## KQ4Music.sc (Script 988)

### High-Level Summary

KQ4Music.sc contains music-related definitions.

### Technical Notes

- **Script Number**: 988

---

## TimeOut.sc (Script 903)

### High-Level Summary

TimeOut.sc manages time limit mechanics.

### Technical Notes

- **Script Number**: 903

---

## Gauge.sc (Script 989)

### High-Level Summary

Gauge.sc manages status bar display.

### Technical Notes

- **Script Number**: 989

---

## Notes.sc (Script 901)

### High-Level Summary

Notes.sc handles in-game notes/documents.

### Technical Notes

- **Script Number**: 901

---

## Extra.sc (Script 902)

### High-Level Summary

Extra.sc contains miscellaneous additional content.

### Technical Notes

- **Script Number**: 902

---

# Script Number Reference

| Number | File | Category |
|--------|------|----------|
| 0 | Main.sc | Core |
| 255 | Class_255_0.sc | Core |
| 120 | Intro.sc | Cutscene |
| 304 | PlayFlute.sc | Interaction |
| 305 | PlayIt.sc | Interaction |
| 306 | ShootBow.sc | Interaction |
| 307 | ReadBook.sc | Interaction |
| 308 | WearCrown.sc | Interaction |
| 309 | openPbox.sc | Interaction |
| 503 | BeachReg.sc | Region |
| 505 | CemReg.sc | Region |
| 506 | MeadReg.sc | Region |
| 507 | Ogre's Region.sc | Region |
| 508 | Forest Region.sc | Region |
| 509 | Gull Region.sc | Region |
| 510 | MountReg.sc | Region |
| 511 | gfReg.sc | Region |
| 512 | Ocean Region.sc | Region |
| 514 | RiverReg.sc | Region |
| 515 | SwampReg.sc | Region |
| 516 | WaterReg.sc | Region |
| 517 | Woods Region.sc | Region |
| 518 | sForReg.sc | Region |
| 519 | regBFCastle.sc | Region |
| 521 | regDwarfHouse.sc | Region |
| 522 | regOgreHouse.sc | Region |
| 523 | regPan.sc | Region |
| 524 | regTroll.sc | Region |
| 525 | regUnicorn.sc | Region |
| 600 | rg600.sc | Region |
| 601 | Avoid.sc | Utility |
| 603 | GhostWander.sc | Region |
| 701 | CopyProtect.sc | Cutscene |
| 710 | EndMusic.sc | Cutscene |
| 900 | Jump.sc | Utility |
| 901 | Notes.sc | Utility |
| 902 | Extra.sc | Utility |
| 987 | Cycle.sc | Core |
| 988 | KQ4Music.sc | Core |
| 989 | Sound.sc / Gauge.sc | Core |
| 991 | SysWindow.sc | Core |
| 994 | Game.sc | Core |
| 995 | InvI.sc | Core |
| 996 | User.sc | Core |
| 997 | MenuBar.sc | Core |
| 998 | Feature.sc | Core |
| 999 | DebugMenu.sc | Utility |
