C2G
C2G files are a file extension used by Chip's Challenge 2. Despite the C2G extension, C2G files are plain text and can be edited with any text editor.
While individual levels are stored in C2M files, C2G files arrange these levels in levelsets. C2G files can also be used to specify music tracks, text between levels, and several forms of advanced scripting.
The official set does not use any advanced C2G features, nor did Chuck Sommerville provide any documentation; there are several features that have not yet been discovered by the community.
Basic usage
Set name
The first line of the C2G file must absolutely specify the set's name. Such lines must begin with the "game" directive, followed by the set's name in quotes. For example:
game "Levelset Name"
In the above example, the levelset will be known "Levelset Name" in Chip's Challenge 2's "Load Level Set" window.
Levels
Most of the C2G file consists of loading individual C2M files. This is done using the "map" directive, followed by the file name/path in quotes. For example:
map "ShortLevel.c2m"
In the example above, the game engine will load the level stored in the file ShortLevel.c2m in the same directory as the C2G file.
It is also possible to specify custom directories for C2M files.
map "1-20\VeryLongLevel.c2m"
In the example above, the game will load the level stored in the file VeryLongLevel.c2m in the 1-20 subfolder of the folder where the C2G file is stored.
map "..\crazy-levels\OrdinaryLevel.c2m"
In the example above, the game will go back one directory, enter the crazy-levels folder and load the level stored in the file OrdinaryLevel.c2m
Music
If music is to be played during a specific level, it must be specified in the C2G file; otherwise there will be silence. Only files in MP3 format are supported.
Music is using the "music" directive; followed by the file name/path in quotes, and then, on the same line, the level file. Advanced paths can be specified, like with level files.
After the track is finished, the game will fall silent; this can be avoided by using the + symbol before the path (but inside the quotes). For example:
music "+..\music\DeletingLife.mp3" map "21-40\IntenseDodging.c2m"
In the example above, the game will load the level in the file IntenseDodging.c2m in the 21-40 subfolder. It will also go back one directory, enter the music folder, and play the track DeletingLife.mp3. After playback has finished, it will start playing again.
Comments
A semicolon (;) can be placed at the end of any line in a C2G file. Any text after the semicolon will be ignored by the engine. This can allow the designer to write notes in the C2G file. For example:
music "+..\music\DeletingLife.mp3" map "21-40\IntenseDodging.c2m" ; Intense music for an intense level
In the example above, the text "Intense music for an intense level" will be ignored by the game; the level and music specified will be loaded normally.
Text
C2G files make it possible to put text, between levels, as well as at the beginning and end of the set. This is done using the "script" directive, followed by up to 10 lines of text. All text must be between quotes, and lines may not be longer than 20 characters (excluding the quotes). It is possible to put blank lines by simply putting a space inside the quotes. For example:
script "The following level" "uses some really" "clever tricks and" ; some are also evil "is guaranteed" "to be enjoyable." " " "Have fun!" map "AwesomeLevel.c2m"
In the example above, the text will be displayed in-game like this:
HAVE FUN!
The text "some are also evil" is a comment and will not be displayed. After the text is displayed, the game will then load the level in the file AwesomeLevel.c2m
Advanced scripting
In addition to the features described above, C2G files can support some additional keywords that provide extra features. Note that any information beyond this point may be incomplete or inaccurate.
Score
The following line, when inserted in a "script"
"%ld" score
will print the player's current total score for the set.
Permanently change directory
By default, C2G files will look for files to be loaded in the same directory as the C2G file itself. This can be changed by the
chdir
directive. This will apply for any future files to be loaded (although custom paths can still be specified, like described above).
Keeping items across levels
C2G files can make it possible to allow the player to keep items and keys across levels.
In order to do this, the C2G script needs the line:
ktools flags | flags =
This allows the player to keep tools (and keys) into the next level, instead of the key and tool inventories being reset like normal. With this flag set, the player can set up his inventories in one level and keep them into the next.
Alternatively, the set designer can use the C2G script to preset the player's inventories explicitly. This can be done with the following code:
<#> keys = ; to preset the key inventory <#> tools = ; to preset the tools inventory
For each inventory, "<#>" is a 4-byte number in which each byte represents a different inventory slot. Its value can be calculated as follows:
(tool 1 code OR red key count)
+ (tool 2 code OR blue key count) * 256 + (tool 3 code OR yellow key count) * 65,536 + (tool 4 code OR green key count) * 16,777,216 Or if you know hexadecimal, just write it out as a hex integer in little-endian order, then convert to decimal - CC2 does not read hex literals.
Here are the number codes for items:
- 1: suction boots
- 2: skates
- 3: fire boots
- 4: flippers
- 5: time bomb
- 6: helmet
- 7: hiking boots
- 8: lightning bolt
- 9: bowling ball
- 10: yellow teleport
- 11: railroad sign
- 12: steel foil
- 13: secret eye
- 14: bribe
- 15: speed boots
- 16: hook
For example, a key inventory with 1 yellow key and 2 red keys can be set with
65538 keys =
and a tool inventory with flippers in slot 1 and a yellow teleport in slot 2 can be set with
2564 tools =
Note that tool codes > 16 will be reduced to a value <= 16, and key counts > 9 will be reduced to 9. These limits do not apply when either inventory is carried over from the previous level.
Something similar can also be done with the "tool" keyword.
Time levelset
C2G files make it possible to set a time limit for the entire levelset, rather than individual levels. This is done with the following code:
ktime flags | flags = <#> tleft =
Replace "<#>" with the desired time limit for the set. This will ignore any time limits set for individual levels. Time limits will be carried over from one level to the next, and restarting the level does not reset the time limit. Time bonuses and time penalties can still be used. It is currently unknown what happens when the time limit reaches 0.
Editor
The following line
edit
will open the game's built-in editor.
Automatic replays
The following lines
1 level = 50 highspeed = continue replay | silent | flags =
will cause the game to automatically replay the recorded solutions for all levels in the set, in extremely high speed. This can be used to quickly verify that all levels are solvable and have recorded replays.