// ****************************************************************************
//
// Logic 40:  Crystal Maze
//
// ****************************************************************************

#include "defines.txt"

if (new_room) {

  if (!shattered) {
    if (has("eye of newt")){
      universe=41;
      load.pic(universe);   //visible maze
      draw.pic(universe);
      discard.pic(universe);
      }
    else {
      universe=40;
      load.pic(universe);
      draw.pic(universe);  //invisible maze
      discard.pic(universe);
      }
    }

else {
   if (has("eye of newt")) {
      universe=141;
      load.pic(universe);
      draw.pic(universe);
      discard.pic(universe);
      }
   else {
      universe=140;
      load.pic(universe);
      draw.pic(universe);
      discard.pic(universe);
      }

   load.view(131);
   set.view(ego,131);
   }

  set.horizon(37);

  if (golden_caul==3) {
      animate.obj(o1); //real cauldron shard
      animate.obj(o2); //fake cauldron shard
      load.view(132);
      set.view(o1,132);
      set.view(o2,132);
      position(o1,12,61);
      position(o2,135,48);
      ignore.objs(o1);
      ignore.objs(o2);
      draw(o1);
      draw(o2);
      }

// Check what room the player came from and position them on the
// screen accordingly here, e.g:
 if (prev_room_no !=42) {
   position(ego,72,163);
 }
 else {
   position(ego,145,75);
   }

  load.sound(18);
  sound(18, sound_flag);

  draw(ego);
  show.pic();
}

if (said("look")) {
  print("This is a maze-like cavern created with invisible crystals.");
  if (has("eye of newt")) {
      print("The Eye of Newt allows you to see the outline of the maze.");
      }
  if (golden_caul == 3) {
      print("You see two different Golden Cauldron fragments!!");
      }
}

if (said("look","wall")) {
    print("Well, no, you can't see the walls because they are invisible.");
    }

if (said("look","crystal")) {
    print("These lovely pastel crystals must have grown inside the dreams of a master jeweller.");
    }

if (said("get","crystal")) {
    print("They are diamond-hard and fused together.  You cannot move them.");
    }

if ((said("get","fragment") ||
     said("get","shard"))) {
  if (golden_caul == 3) {
    distance(ego,o1, range);
    distance(ego,o2, universe);
    if (range > universe) {
        if (universe <= 5) {
            print("As you pick up the fragment it dissolves.");
            print("It was a FAKE!");
            erase(o2);
            }
        else {
            print("Your arms are too short.");
            }
        }
    else {
        if (range <= 5) {
            print("You pick up the fragment.");
            print("Your hand tingles a little...  this must be the true fragment!");
            erase(o1);
            score++;
            golden_caul++;
            }
        else {
            print("Your arms, they are too short.");
            }
        }
      }
    else {
        print("Nope.");
        }

  }

if ((said("look","fragment") ||
     said("look","shard"))) {
     if (golden_caul == 3) {
         print("You see two shards!  Which is the real shard?");
         }
     else {
         show.obj(gold_shard);
         }
     }

if (ego_edge_code == right_edge) {    // ego touching right edge of screen
  load.view(0);
  set.view(ego,0);
  if (shattered) {
      new.room(108);
      }
  else {
     new.room(42);
     }
}

if (ego_edge_code == bottom_edge) {   // ego touching bottom edge of screen
  load.view(0);
  set.view(ego,0);
  if (shattered) {
      new.room(108);
      }
  else {
      new.room(204);
      }
}

if (sound_flag) {
    sound(18, sound_flag);
    }

return();