//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//   Logic 204:  Segues
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#include "defines.txt"

if (new_room) {

    if ((prev_room_no == 6 ||   //The Cliffs
         prev_room_no == 47)) { //Dream Castle Pit

        universe =  108; //Falling scene


        }

    if (prev_room_no == 9) { //The Plateau
        universe = 109; //Dodging Boulders
        //UPDATE PIC!!!!
        load.sound(16);
        sound(16,sound_flag);
        }

    if (prev_room_no == 15) { //Caves
        universe = 110; //Swimming scene
        }

    if (prev_room_no == 27) { //Fishing Hole
        universe = 111;
        }

    if ((prev_room_no == 5 ||
         prev_room_no == 40 ||
         prev_room_no == 65 ||
         prev_room_no == 85 ||
         prev_room_no == 108)) { //Dream Transition

         universe = 112;

         animate.obj(o1);
         load.view(0);
         set.view(o1,0);
         set.loop(o1,2);
         stop.motion(o1);

         if (prev_room_no == 5) {
             position(o1, 70, 167);
             }
             else {
                   position( o1, 70, 44);
                   }
       draw(o1);
       }

//if ((prev_room_no == 57 ||
//     prev_room_no == 58 ||
//     prev_room_no == 59)) {
//        universe=114;
//        }
if (prev_room_no != 65) {
 if (food_puzzle < 4) {
  if (food_puzzle == 2) {
    universe = 66;
    animate.obj(o1);
    load.view(124);
    set.view(o1, 124);
    position(o1,33,70);
    draw(o1);


    }

  if (escaped == 5 &&
    !open_office &&
    food_puzzle < 2) {
        animate.obj(o1);
        load.view(124);
        set.view(o1, 124);
        position(o1,70,70);
        draw(o1);
        universe= 66;
        }

  if (food_puzzle == 3) {
    universe = 64;
    }
  }
 }

  if (prev_room_no > 68 &&
       prev_room_no < 81) {
         universe = 115;
       }

  if (prev_room_no == 86) {
        universe = 116;
        }

timer1_a=0;

        load.pic(universe);
        draw.pic(universe);
        discard.pic(universe);

        prevent.input();

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

show.pic();
}

if (timer1_a == 50) {
    accept.input();
    }

if ((prev_room_no == 6 ||
     prev_room_no == 47)) { //The cliffs
    if (timer1_a<50) {
        timer1_a++;
        }
        else {
             print("Congratulations!  You've just proved the existence of gravity.");
             shake.screen(1);
             print("I hope you enjoyed the view on the way down.");
             death_type=1;
             }
    }

if (prev_room_no == 9) { //The Plateau
  if (timer1_a<50) {
      timer1_a++;
      }
  else {
    print("Boy, it sure is easier on the way down!");
    new.room(6);
    }

}

if (prev_room_no == 15) { //Caves
    if (timer1_a <  50) {
        timer1_a++;
        }
    else {
    new.room(11);
    }
  }

if (prev_room_no ==27) { //Fishing Hole
    if (timer1_a < 50) {
        timer1_a++;
        }
    else {
    new.room(27);
    }
   }

if (prev_room_no == 5) { //To Dream World
    get.posn(o1,temp_x,temp_y);
    if (temp_y > 44) {
        universe=1;
        set.dir(o1,universe);
        }
        else {
              accept.input();
              if (shattered) {
                  new.room(108);
                  }
              else {
                  new.room(40);
                  }
              }
        }

if ((prev_room_no == 40 ||
     prev_room_no == 65 ||
     prev_room_no == 85 ||
     prev_room_no == 108)) {
     get.posn(o1,temp_x,temp_y);
     if (temp_y<167) {
         universe=5;
         set.dir(o1,universe);
         }
         else {
               accept.input();
               new.room(5);
               }
         }

//if ((prev_room_no == 57 ||
//     prev_room_no == 58 ||
//     prev_room_no == 59)) {
//       if (timer1_a == 0) {
           //print("RUN AWAY!!!  RUN AWAY BEFORE THAT THING GETS YOU!!!");
//           timer1_a++;
  //         }
//       if (timer1_a<15) {
//           timer1_a++;
//           }
//           else {
//             if (ego_dir == 1) { ego_dir = 5; }
//             else { if (ego_dir == 5) { ego_dir = 1; }}
//             if (ego_dir == 2) { ego_dir = 6; }
//             else { if (ego_dir == 6) { ego_dir = 2; }}
//             if (ego_dir == 3) { ego_dir = 7; }
//             else { if (ego_dir == 7) { ego_dir = 3; }}
//             if (ego_dir == 4) { ego_dir = 8; }
//             else { if (ego_dir == 8) { ego_dir = 4; }}
//             new.room.v(range);
//           }
//      }

if (prev_room_no != 65) {
  if (escaped==5 &&
    !open_office &&
    food_puzzle < 2) {
     if (!more_done_flag) {
      print("Nursie: \"What's that ruckus out there?!\"");
      move.obj(o1,33,70,1,done_flag);
      set(more_done_flag);
      }
     if (done_flag) {
       print("Nursie: \"AAAAAUUUUUGGGGHHH!!!!\"");
       erase(o1);
       reset(done_flag);
       set(open_office);
       reset(more_done_flag);
       accept.input();
       new.room.v(prev_room_no);
       }
     }

if (food_puzzle == 2) {
    if (!more_done_flag) {
     load.view(food_tray);
     add.to.pic(food_tray,0,0,85,75,9,9);
        print("Nursie: \"Those LUNATICS!!!  I'll deal with them later.  Right now, I need a snack.\"");
        print("Nursie: \"Oh, the orderly brought my third lunch.  I wonder when he did that?\"");
        print("Nursie: \"Oh, well.  It's like my mother always said, \'Eat now, and...\'.  Well, I guess I forgot the rest.\"");
        move.obj(o1,80,70,1,done_flag);
        set(more_done_flag);
        }
    if (done_flag) {
        print(">Munch, munch, munch<");
        print("Nursie: \"This food tastes so strange...\"");
        print("so...  strange...");
        print(">SNORE<");
        reset(more_done_flag);
        reset(done_flag);
        food_puzzle = 3;
         //   if(open_office) {
         //      print("open_office is set");
         //      }
         //   else {
         //      print("open_office has been reset");
               set(open_office);
         //      }
        accept.input();
        new.room(62);
        }
    }

if (food_puzzle == 3) {
    if (timer1_a == 0) {
        print("With Nursie passed out in a plate of hospital food, the inmates rise up and put the Orderly to THE MACHINE!");
        timer1_a++;
        animate.obj(o1);  //orderly
        animate.obj(o2); //inmate
        animate.obj(o3); //inmate
        animate.obj(o4); //switch
        load.view(111); //orderly
        load.view(120); //inmate
        load.view(65); //switch
        set.view(o1, 111);
        set.view(o2, 120);
        set.view(o3, 120);
        set.view(o4, 65);
        set.cel(o4, 0);
        stop.cycling(o4);
        position(o4, 46, 122);

        position(o1, 69, 100);
        position(o2, 38, 120);
        position(o3, 80, 120);

        draw(o1);
        draw(o2);
        draw(o3);
        draw(o4);
        }

   if (timer1_a == 25) {
       set.cel(o4, 1);
       wander(o2);
       wander(o3);

       }
   if (timer1_a == 30) {
       erase(o1);

       }
   if (timer1_a == 35) {
       draw(o1);

       }
   if (timer1_a == 40) {
       erase(o1);

       }
   if (timer1_a == 45) {
       draw(o1);

       }
   if (timer1_a == 55) {
       erase(o1);

       }
   if (timer1_a == 75) {
       print("The reign of terror is over!!!");
       food_puzzle = 4;
       accept.input();
       score+=5;
       new.room(67);
    }
    timer1_a++;
  }
}

  if (prev_room_no > 68 &&
       prev_room_no < 81) {
          if (timer1_a == 50) {
              print("You have perished in the depths of the earth.");
              death_type = 1;
              }
          else {
              timer1_a++;
              }
       }

  if (prev_room_no == 86) {
      if (timer1_a == 50) {
          print("The Dream King has defeated you and cast you into the Realm of Nightmare for a very, VERY long time.");
          death_type = 1;
          }
      else {
          timer1_a++;
          }
     }


return();