// ****************************************************************************
//
// Logic 44: Gates to the Castle
//
// ****************************************************************************

#include "defines.txt"

if (new_room) {
  load.pic(room_no);
  draw.pic(room_no);
  discard.pic(room_no);
  set.horizon(37);



// Check what room the player came from and position them on the
// screen accordingly here, e.g:
 if (prev_room_no == 45) {
   position(ego,44,72);
   ego_dir = 5;
 }

 if ((prev_room_no == 46 ||
      prev_room_no == 48)) {
          load.view(0);
          set.view(ego,0);
          position(ego,69,156);
          ego_dir=0;
          set.loop(ego,2);
          }

  if (prev_room_no == 108) {
      position(ego, 80, 150);
      }

if (prev_room_no == 103) {
    position(ego, 144,160);
    new_ego_x = 160;
    }

if (prev_room_no == 104) {
    position(ego, 4, 160);
    new_ego_x = 160;
    }

  load.view(0);
  load.view(2);

  animate.obj(o1); //Guards
  animate.obj(o2);
  if (!guards_asleep) {
    load.view(107);
    set.view(o1,107);
    set.view(o2,107);
    set.loop(o1,2);
    set.loop(o2,2);
    }
  else {
    load.view(125);
    set.view(o1,125);
    set.view(o2,125);
    }
  position(o1,28,151);
  position(o2,109,151);
  universe = 2;
  cycle.time(o1, universe);
  cycle.time(o2, universe);
  draw(o1);
  draw(o2);

  load.view(sleep_bombs);
  load.view(4); //Poof

  draw(ego);
  show.pic();

  reset(done_flag);
  reset(more_done_flag);
  reset(bridge_switch);
  set(gate_switch);
  reset(is_zombie);

  load.sound(17);
  sound(17, sound_flag);
}



if (said("look")) {
  print("This is the gate to the castle.");
}

if (said("look","gate")) {
    print("Despite its rickety appearance, you think it could support you, and there seems to be a hole near the top.");
    }

if (said("look","guards")) {
   if (!guards_asleep) {
    print("They're a mean-looking bunch.  I don't think they'll let you past.");
    }
   else {
     print("Sleep, little guards.");
     }
   }

if (said("look","hole")) {
    print("There's a hole in the gate.  If you could just climb up there...");
    }



if (said("look","wall")) {
    print("Despite millenia of decay, it remains impenetrable.  This is the only way in.");
    }

if (said("talk","guards")) {
    if (!guards_asleep) {
        print("Guard #1: \"None shall pass!\"");
        print("Guard #2: \"That's right, no one!\"");
        print("VG: \"Oh, you guys don't mind if I just pop in for a bit, do you?\"");
        print("Guard #1: \"Just a minute?\"");
        print("VG: \"Totally, I'll be gone before anyone notices.\"");
        print("Guard #2: \"Well, I don't think that would be too big of a deal.\"");
        print("Guard #1: \"Oh, wait!  I just remembered something.\"");
        print("VG: \"What's that?\"");
        print("Both Guards: \"NONE SHALL PASS!\"");
        }
    else {
        print("Ssshh!  Don't wake the little dreamers.");
        }
    }

if (said("attack","guards")) {
    if (!guards_asleep) {
        print("You're kidding, right?");
        print("These are the Dream King's Elite Guard.");
        print("They will mess you UP!");
        }
    else {
        print("No, you'll wake them and have to start all over.");
        }
    }



if (said("give","guards","sleeping potion")) {
    print("Guard #1: \"Oh, we're not going to fall for that one.\"");
    print("Guard #2: \"Yeah, go try your tricks elsewhere.\"");
    }

if ((said("throw","sleep bombs","guards") ||
     said("use","sleep bombs","guards")   ||
     said("throw","sleep bombs")  ||
     said("use","sleep bombs") ||
     said("drop","sleep bombs") ||
     said("attack","guards","sleep bombs"))) {
          if (has("sleep bombs")) {
              if (!guards_asleep) {
                  print("You throw the sleep bombs");
                  drop("sleep bombs");
                  score++;
                  animate.obj(o3);

                  set.view(o3,sleep_bombs);
                  set.priority(o3,15);
                  ignore.objs(o3);
                  temp_y=new_ego_y;
                  temp_y+=10;
                  position.v(o3,new_ego_x,temp_y);

                  draw(o3);
                  get.posn(o2,temp_x,temp_y);
                  move.obj.v(o3,temp_x,temp_y,2,done_flag);
                  }
              else {
                  print("Don't waste your time, they're already asleep!");
                  }
              }
          else {
               print("You don't have the proper equipment!");
               }
          }

if (done_flag) {
    reset(done_flag);
    set.view(o3, 4);
    set.cel(o3, 0);
    end.of.loop(o3, more_done_flag);
    }


if (more_done_flag) {
    reset(more_done_flag);
    erase(o3);
//    animate.obj(o3);
//    load.view(74);
    set.view(o3,sleep_bombs);
//    set.priority(o3,15);
//    ignore.objs(o3);
    temp_y=new_ego_y;
    temp_y+=10;
    position.v(o3,new_ego_x,temp_y);
    draw(o3);
    get.posn(o1,temp_x,temp_y);
    move.obj.v(o3,temp_x,temp_y,2,really_done_flag);
    }

if (really_done_flag) {
    reset(really_done_flag);
    set.view(o3, 4);
    set.cel(o3, 0);
    end.of.loop(o3, penultimate_done_flag);
    }

if (penultimate_done_flag) {
    erase(o3);
    set(guards_asleep);
    reset(penultimate_done_flag);
    new.room(44);
    }

if (new_ego_y<150 &&
    !guards_asleep) {
    print("Guard #1: \"Halt!  None shall enter!\"");
    print("Guard #2: \"Yeah!  None shall enter!\"");
    ego_dir=5;
    }

if ((said("climb","gate") ||
     said("open","gate") ||
     said("get","hole"))) {
          print("It won't open...  you may have to climb.  To do that, just use the directional keys.");
          }

if (ego_on_water) {
    set.view(ego,2);
    }
else {
    set.view(ego,0);
    }


if (ego_touching_signal_line) {  // ego touching horizon
  if (shattered) {
      new.room(108);
      }
  else {
      new.room(45);
      }
}

if (ego_edge_code == bottom_edge) {   // ego touching bottom edge of screen

  if (shattered) {
      new.room(108);
      }
  else {
      new.room(43);
      }
}

if (ego_edge_code == right_edge) { // ego touching right edge
  new.room(103);
  }

if (ego_edge_code == left_edge) {// ego touching left edge
  new.room(104);
  }

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

return();