C2G

Revision as of 04:25, 9 June 2020 by Zrax (talk | contribs)

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:

THE FOLLOWING LEVEL
USES SOME REALLY
CLEVER TRICKS AND
IS GUARANTEED
TO BE ENJOYABLE
 
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.

Syntax

The syntax of the .c2m file appears to be a mix of Reverse Polish Notation expressions and simple statements. For example, to set the global "flags" variable to (reg1 + 42) * 3, you would write:

 reg1 42 + 3 * flags =

Other statements, such as "map" or "music" take a parameter after the keyword:

 map "somemap.c2m"

In addition, variables can be formatted into strings in script sections by placing the variable after a string with a printf-style format specifier:

 "flags = %ld" flags

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 this line at the beginning of the file (after the set name):

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, placed before calling the level's "map":

<#> 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:

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.

Timed levelset

C2G files make it possible to set a time limit for the entire levelset, rather than individual levels. In order to do this, the following code must be added to the beginning of the file, after the "game" directive:

ktime flags | flags =

Before the first level, this code will also be required:

<#> 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. After the time limit reaches 0, or if a level is skipped, all future levels will be untimed.

Exit choices

If a level has several exits, C2G scripting can be used to send the player to different levels depending on what exit is entered.

In order to do this, each level must be given a label starting with a pound (#) character. For example:

#bonuslevel
script
"Congratulations!"
"You have reached"
"the secret level!"
map "BonusLevel.c2m"

In the example above, the level BonusLevel.c2m as well as the preceding text are given the label "bonuslevel".

Exits are numbered in reading order, starting at 1; there does not appear to be any limit. In order to use the feature, after calling the "map" of the level containing the exits, a line similar to this will be required:

 <#> exit == do goto #label

Replace <#> with the exit number, and #label with the label name (including the #). For example:

map "ChooseYourFuture.c2m"
1 exit == do goto #end
2 exit == do goto #secret

#secret
map "SuperSecretFinalLevel.c2m"

#end
script
"This is the end."

In the example above, the game will load the level stored in the file ChooseYourFuture.c2m; if the player exits using the first exit in reading order, the game will then display the THIS IS THE END. message. If the player exits using the second exit, however, the game will load the level in the file SuperSecretFinalLevel.c2m instead, and the THIS IS THE END message will be displayed after the level has been solved.

If there are several players in the level, the exit used by the last player to finish the level will be the one used by the C2G script. If an invalid label is called, or no label is assigned for the exit that was used, the game will continue to work through the C2G file as it would normally.

Gender choices

C2G scripting can be used to send the player to different levels depending on whether they finished the level as Chip or Melinda. This will require setting up labels, similar to exit checkpoints.

After calling the appropriate level's "map", the following lines will be required:

male gender == do goto <#label>
female gender == do goto <#label>

Replace <#label> with the appropriate labels. The "male" line is for Chip, and the "female" line for Melinda; the order of the two lines can be changed.

If there are several players in the level, the gender of the last one to finish the level will be the one used by the C2G script. If an invalid label is called, or no line is specified for a specific gender, the game will continue to work through the C2G file as it would normally.

Goto

Goto can also be used in absence of a gender or exit check. For example:

map "NormalProgression.c2m"
#loop
map "DejaVu.c2m"
map "StuckInALoop.c2m"
goto #loop

In the example above, completing StuckInALoop.c2m will always take you back by one level to DejaVu.c2m.

Fake level numbers

C2G scripting can be used to assign specific numbers to levels. To do this, the following line must be added before calling the level's "map":

<#> level =

Replace <#> with the desired level number. This makes it possible to skip (nonexistent) levels and go backwards (for example, going from level 2 to 5 to 248 to 125). Any number can be specified, including four digit numbers (although this will be displayed in-game as 999) and 0. It is also possible to have several levels with the same number.

It is not required to specify numbers for all levels; if the line is absent, or an invalid value (such as a string of number) is given, the game will simply add 1 to the previous level's number. For example:

game "Jumping Around"
2 level =
map "Wheres1.c2m"
0 level =
map "Backwards.c2m"
8 level =
map "Jumping.c2m"
map "Normal.c2m"

In the example above, Normal.c2m will be level 9.

Speed

C2G scripting can be used to modify the speed at which the game is played. To do this, the following line must be added before calling the map:

 1 speed =

The number determines the speed, where 1 is normal speed; the upper limit is unknown. This flag will apply for all future levels; in order to restore normal speed, the flag must be called again before a later level.

Blocking flags

C2G scripting can be used to prevent bonus flags from being picked up. This will apply to the entire set, rather than individual levels.

The following line must be added at the beginning of the file (after the set's name):

 no_bonus flags | flags =

With this flag set, bonus flags become acting floor to Chip, Melinda, their mirrors and rovers. It has no impact on other monsters and blocks that would not normally pick up the flags.

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 =

added to the beginning of the file (after the set name) 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.

Comments box

Certain C2G scripts, notably ktools and speed can be placed inside a specific level file's comments field, and will apply to the level itself. To do this, the comments field must contain the following line:

[COM]

followed, on subsequent lines, by the C2G parameters.

Complete set of keywords

On September 19th, 2019, Joshua Bone posted a complete list of keywords that can or could be used in C2G scripting, including numbers and comparison operators. The function of some keywords in here is unknown, and some formerly did something but are now just gibberish to the engine (NO_L_DOORS for example).

MUSIC
GOTO
DO
==
<=
>=
!=
=
<
>
LEVEL
GENDER
EXIT
ENTER
SCORE
BONUS
MENU
CHIPS
START
MALE
FEMALE
MAP
SCRIPT
"
#
0
1
2
3
4
5
6
7
8
9
;
//
END
RESULT
REG1
REG2
REG3
REG4
FLAGS
EDIT
CHAIN
LINE
CHDIR
SCREEN
*
/
+
-
&&
&
||
|
%
^
REPLAY
CONTINUE
SILENT
KTIME
KTOOLS
TLEFT
TOOLS
KEYS
ART
WAV
RAND
SPEED
NO_BONUS
NO_L_DOORS
MAIN
GAME
DLC