const int SMATRIX_PUZZLE_ALLOW_INPUT_WITH_EX1_BUTTON = 1; //Set to anything > 0 to allow Link to input password by standing on combos and pressing Ex1.
const int CF_SMATRIX_PUZZLE_PIECE = 98;//Combo flag to be places on combos that are a part of a puzzle.
const int SFX_SMATRIX_PUZZLE_COMBO_CHANGE = 16; //Sound to play, when changing password combos by standing on combos and pressing A.
const int SFX_SMATRIX_PUZZLE_SOLVED = 27; //Sound to play, when correct password is inputed.
//Password lock Script 5: The Sum of all things.
//Checks all flagged combos, takes difference between combo ID and FFC combo ID. Results are added together.
//If total sum matches FFC`s D0, secrets are triggered.
//1. Set up sequence of combos to for digits, followed by combo that looks like 1st combo in the sequence and cycles to that combo.
//2. Import and compile the script. It requires ffcscript.zh in addition to default libraries.
//3. Build the combination lock in it`s solved state. Flag every combo consisting the puzzle with CF_SMATRIX_PUZZLE_PIECE.
//4. Place FFC anywhere in the screen. Assign the script to it and combo to first combo from step 1.
//5. Set "Run at Screen Init" and "Only Visible to Lens of Truth" flags.
// D0 - Target sum.
// D1 - Set to > 0 to disallow input by standing on puzzle combos and pressing Ex1, forcing to use different methods of changing combos.
// D2 - Set to > 0 to count 1st combo from step 1 as "1", instead of "0" for total and count up.
// D3 - screen layer to define puzzle solution. Use layer, other then 0, if you don`t want changes to layer 0.
// D4 - tile rotating animation
ffc script MatrixSumPuzzle{
void run (int sumsol, int noautoinput, int offbyone, int layer, int rot){
if (Screen->State[ST_SECRET]) Quit();
//Process creating puzzle solution and resetting combination lock.
// int solution[176];
int sum = 0;
int origcmb = this->Data;
this->Data = FFCS_INVISIBLE_COMBO;
int offset = 0;
while(true){
if ((SMATRIX_PUZZLE_ALLOW_INPUT_WITH_EX1_BUTTON >0)&&(noautoinput==0)){
if (Link->PressEx1){//Process Auto-input
int cmb = ComboAt(CenterLinkX(), CenterLinkY()+offset);
if (ComboFI(cmb, CF_SMATRIX_PUZZLE_PIECE)){
Game->PlaySound(SFX_SMATRIX_PUZZLE_COMBO_CHANGE);
Screen->ComboD[cmb]++;
if (rot>0){
int origcmb = Screen->ComboD[cmb]-1;
Screen->ComboD[cmb]=FFCS_INVISIBLE_COMBO;
for (int i=0; i<15; i++){
Screen->DrawCombo(1, ComboX(cmb), ComboY(cmb), origcmb, 1, 1, Screen->ComboC[cmb], -1, -1, ComboX(cmb),ComboY(cmb), 6*i, 1, 0, false, OP_OPAQUE);
Waitframe();
}
Screen->ComboD[cmb]=origcmb+1;
}
}
}
}
sum=0;
for (int i=0;i<176;i++){
if (!ComboFI(i, CF_SMATRIX_PUZZLE_PIECE)) continue;
sum+=Screen->ComboD[i]-origcmb;
if (offbyone>0)sum++;
}
if (sum==sumsol){
Game->PlaySound(SFX_SMATRIX_PUZZLE_SOLVED);
Screen->TriggerSecrets();
Screen->State[ST_SECRET]=true;
Quit();
}
//debug
// debugValue(1, sum);
Waitframe();
}
}
}
// void DebugSolution(int solution, int origcmb){
// for (int i=0; i<176; i++){
// if (solution[i]<0) continue;
// if ((Screen->ComboD[i] == (origcmb + solution[i])))Screen->DrawInteger(2, ComboX(i), ComboY(i),0, 1,0 , -1, -1, solution[i], 0, OP_OPAQUE);
// }
// }