Constant Story     "Safe Demo^";
Constant Headline  "by Al the Game Designer^
                   with assistance from ~samyse~^^";

Constant DIAL_ERROR "You can't turn that to a number.";

Release 1;
Serial "000001";

Include "Parser";
Include "Verblib";
Include "Grammar";

[Initialise ;
location=SafeRoom;
lookmode=2;
"You are in a room with a safe. There are NO exits so you're stuck here.";];

Object SafeRoom "Safe Room"
with description
"You're stuck here in the safe room with only the safe for company.",
cant_go "You're stuck!",
has light
;

Object -> Safe "steel safe"
with name 'steel' 'safe' 'vault',

with description  [;
if (self has locked)
"The safe takes up most of the east wall of the room. There is a combination
dial in the center of the safe's door.  The safe is currently locked^^";

"The safe takes up most of the east wall of the room. There is a combination
dial in the center of the safe's door.  The safe is currently unlocked.^^";],

before [;
unlock:
if (ComboDial.success) "The safe is already unlocked.";
"You need to find the combination and  turn the dial in the
proper directions to the correct numbers.";

lock:
if (self has locked) "The safe is already locked!";
if (self hasnt locked && self has open)
{give self locked ~open;
ComboDial.success=false;
"You close the door, spin the dial and re-lock the safe.";};

if (self hasnt locked && self hasnt open)
{give self locked;
ComboDial.success=false;
"You spin the dial and re-lock the safe.";};

open: if (self has locked) "The safe is locked!";

playwith: "You feel ridiculous playing with the safe!";

take,push,pull,turn: "Superman you aint!";],

has container openable locked lockable static
;

Object -> ComboDial "combination dial"
with name 'dial',
description "A large dial numbered 0 to 99.",
combination 11 22 33,
howfar 0,
success false,
tleft  false,
tright false,
flag1  false,
flag2  false,
flag3  false,
num1 11,
num2 22,
num3 33,
new1 0,
new2 0,
new3 0,

before [;

TurnLeftTo, TurnRightTo:
if (ComboDial.success)
"You've already unlocked the safe. You don't need to do that again.";

if ((action == ##TurnRightTo && self.howfar % 2 == 0)
||  (action == ##TurnLeftTo && self.howfar % 2 == 1))
{if (second == self.&combination-->self.howfar)
{++self.howfar;
if (self.howfar >= self.#combination/2)
{give Safe ~locked;
"You near a loud CLICK. The safe is unlocked!";}
"Strange!  Nothing happened.  At least, nothing obvious happened.";}}

self.howfar = 0;
"Oops, you need to start over.";

take: "The dial is part of the door and I said about the safe:
You ain't Superman!";

read:
"There are lines and numbers on it which go from 0 to 99.";

playwith:
"You play with the dial causing it to spin like a roulette wheel.";

pull:
"Because of its tapered shape, you find that you cannot get a good
enough grip on it to pull it. Your fingers keep slipping off!";

push:
"Pushing the safe's dial accomplishes nothing!";

turn:
"Please phrase this as: TURN DIAL LEFT (OR) TURN DIAL RIGHT";

TurnLeft:
if (ComboDial.success)
"You've already unlocked the safe. You don't need to do that again.";
self.tleft=true;
self.tright=false;
"You turn the dial LEFT.^
Now you need to ~TURN DIAL TO ~ (00 TO 99).^";

TurnRight:
if (ComboDial.success)
"You've already unlocked the safe. You don't need to do that again.";
self.tright=true;
self.tleft=false;
"You turn the dial RIGHT.^
Now you need to ~TURN DIAL TO ~ (00 TO 99).^";

TurnTo:
if (ComboDial.success)
"You've already unlocked the safe. You don't need to do that again.";

if (self.flag1==false && second~=self.num1)
{self.new1=second;
"You turn the dial to the INCORRECT 1ST NUMBER of ",self.new1,".";};

if (self.flag1==false && self.tright && second== self.num1)
{self.flag1=true;
self.flag3=true;
"You turn the dial to the CORRECT 1ST NUMBER of ",self.num1,".";};

if (self.flag2==false && self.tleft && second ~=self.num2)
{self.new2=second;
self.flag1=false;
"You turn the dial to the INCORRECT 2nd NUMBER of ",self.new2,".";};

if (self.flag1==true && self.flag2==false && self.tleft && second ==self.num2)
{self.flag2=true;
self.new2=noun;
"You turn the dial to the CORRECT 2ND NUMBER of  ",self.num2,".";};

if(self.flag1 && self.flag2 && second~=self.num3)
{
self.flag1==false;
self.flag2==false;
self.flag3=false;
self.tleft=false;
self.tright=false;
ComboDial.success =false;  ! reset just to make sure
self.new3=second;
"You turn the dial to the INCORRECT 3rd NUMBER of ",self.new3,"^You need to start over.";};

if (self.flag1 && self.flag2 && self.tright && second==self.num3)
{self.flag3=true;
give Safe ~locked;
ComboDial.success=true;
"You hear a loud CLICK! The safe is unlocked.";};],
;

[PlaySub;
"You can't play that!";];

[PlayWithSub;
"You can't play with that!";];

[TurnLeftSub;
if (ComboDial.success)
"You've already unlocked the safe. You don't need to do that again.";
if (noun ~=ComboDial)  print_ret DIAL_ERROR;];

[TurnRightSub;
if (ComboDial.success)
"You've already unlocked the safe. You don't need to do that again.";
if (noun ~=ComboDial)  print_ret DIAL_ERROR;];

[TurnToSub;
if (noun ~=ComboDial) "You can only turn the safe dial to a number.";];

[TurnLeftToSub;
if (ComboDial.success)
"You've already unlocked the safe. You don't need to do that again.";
if (inp1 == 1) <<TurnLeftTo ComboDial noun>>;
print_ret DIAL_ERROR;];

[TurnRightToSub;
if (ComboDial.success)
"You've already unlocked the safe. You don't need to do that again.";
if (inp1 == 1) <<TurnRightTo ComboDial noun>>;
print_ret DIAL_ERROR;];

[ReadSub;
"You can't read that!";];


extend 'turn'      * noun 'left'                -> TurnLeft
                  * noun 'right'               -> TurnRight
                  * noun 'left'  'to' special  -> TurnLeftTo
                  * noun 'right' 'to' special  -> TurnRightTo
                  * noun 'to' special          -> TurnTo;


verb 'play'        *  noun                      -> Play
                  * 'with' noun                -> PlayWith;

extend  only 'read' replace  * noun             -> Read;

extend only 'lock'  replace  * noun             -> Lock;

extend only 'unlock' replace * noun             -> Unlock;