// ****************************************************************************
//
// Logic 21: Bathroom
//
// ****************************************************************************

#include "defines.txt"
#define door o1
#define vomit o2
#define corpse o3
#define stall1 o4
#define stall2 o5
#define stall3 o6

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

  if (prev_room_no == 22) {
    position(ego,132,102);
    reset(f243); reset(f254);
  }

  reset(f254);

  if ((prev_room_no == 247 || isset(toilet_head)))  {
    reset(m1_attacks);
    set(bathroom_zombie);
    animate.obj(corpse);
    load.view(34);
    set.view(corpse,34);
    set.loop(corpse,4);
    stop.cycling(corpse);
    position(corpse,64,95);
    observe.objs(corpse);
    stop.motion(corpse);
    draw(corpse);

    animate.obj(vomit);
    load.view(37);
    set.view(vomit,37);
    set.loop(vomit,1);
    stop.cycling(vomit);
    ignore.objs(vomit);
    set.priority(vomit,4);
    position(vomit,49,95);
    draw(vomit);

    if (!isset(phone_sheriff)) {
      print("You need to report this to the sheriff!  Someone had to decapitate that man!");
    }
  }

  if (prev_room_no == 239) {
    position(ego,73,88); reset(f243);
    program.control(); set(toilet_head);
    prevent.input();
    move.obj(ego,49,95,1,f254);
  }

  draw(ego);
  show.pic();

  animate.obj(door);
  load.view(38);
  set.view(door,38);
  set.loop(door,3);
  position(door,139,104);
  stop.cycling(door);
  set.priority(door,4);
  ignore.objs(door);
  draw(door);

  animate.obj(stall1);
  load.view(36);
  set.view(stall1,36);
  set.loop(stall1,0);
  position(stall1,55,87);
  stop.cycling(stall1);
  draw(stall1);

  animate.obj(stall2);
  set.view(stall2,36);
  set.loop(stall2,0);
  position(stall2,70,87);
  stop.cycling(stall2);
  draw(stall2);

  animate.obj(stall3);
  set.view(stall3,36);
  if ((toilet_head) && (bathroom_zombie)) {
    set.loop(stall3,0);
  }
  else {
    set.loop(stall3,1);
  }
  position(stall3,85,87);
  stop.cycling(stall3);
  draw(stall3);

}

if (f240) {
  set.cel(stall1,1);
  ignore.objs(stall1);
}
else {
  set.cel(stall1,0);
  observe.objs(stall1);
}

if (f241) {
  set.cel(stall2,1);
  ignore.objs(stall2);
}
else {
  set.cel(stall2,0);
  observe.objs(stall2);
}

if (f242) {
  set.cel(stall3,1);
  ignore.objs(stall3);
}
else {
  set.cel(stall3,0);
  observe.objs(stall3);
}

if (said("open","door")) {
  if (posn(ego,53,82,66,90)) {
    toggle(f240);
  }
  else {
    if (posn(ego,68,82,81,90)) {
      toggle(f241);
    }
    else {
      if (posn(ego,83,82,96,90)) {
        if (toilet_head) {
          toggle(f242);
        }
        else {
          print("No!  There's someone in that stall.");
        }
      }
      else {
        print("Get closer to one of the stalls.");
      }
    }
  }
}

if (posn(ego,129,97,144,108)) {
  set.cel(door,1);
}
else {
  set.cel(door,0);
}

if (posn(ego,70,83,81,86) && !isset(toilet_head)) {
  print("Holy God!"); print("It looks like someone forgot to flush.");
  new.room(239);
}

if (f254) {
  reset(f254);
  erase(ego);
  animate.obj(vomit);
  load.view(37);
  set.view(vomit,37);
  set.loop(vomit,0);
  set.cel(vomit,0);
  v255 = 3;
  cycle.time(vomit,v255);
  ignore.objs(vomit);
  position(vomit,49,95);
  end.of.loop(vomit,f243);
  draw(vomit);

  set(f242);
}

if (f243) {
  reset(f243);
  set.loop(stall3,0);

  animate.obj(corpse);
  load.view(35);
  set.view(corpse,35);
  v255 = 5;
  cycle.time(corpse,v255);
  v255 = 5;
  step.time(corpse,v255);
  position(corpse,88,87);
  move.obj(corpse,62,95,1,m1_attacks);
  draw(corpse);
}

if (m1_attacks) {
  accept.input();
  player.control();
  set.loop(vomit,1);
  draw(ego);
  stop.motion(corpse);
  monster = 6;
  scenery = 3;
  set(cant_run);
  set(surprised);
  new.room(247);
}

if (said("look","stall")) {
  print("The stalls are lined up on the back wall.");
}

if (said("look","toilet")) {
  if (posn(ego,55,82,66,87)) {
    print("Nothing odd about this one.");
  }
  else {
    if (posn(ego,70,82,81,87)) {
      print("No.  You're not looking in there again.  That was revolting.");
    }
    else {
      if (posn(ego,85,82,96,87)) {
        print("The wall behind the toilet has been splashed with blood.");
      }
      else {
        print("You're not close enough.");
      }
    }
  }
}

if (said("look","mirror")) {
  if (posn(ego,6,82,43,130)) {
    print("Yes, it is true that you are handsome... and rugged.");
  }
  else {
    print("You're not close enough.");
  }
}

if ((said("look","trashcan") || said("look","trash"))) {
  print("Empty...");
}

if (said("look","towel")) {
  print("There is a paper towel dispenser next to the sink.");
}

if (said("take","towel")) {
  print("You don't need a towel.");
}

if (said("look","corpse")) {
  if (toilet_head) {
    print("The headless corpse lies motionless on the floor.  That was a close one.");
  }
  else {
    print("What are you talking about?");
  }
}

if ((said("look","man") || said("look","character"))) {
  if (toilet_head) {
    print("That is not a man.  It's a monster.");
  }
  else {
    print("It's considered impolite to leer underneath the door of a bathroom stall.");
  }
}

if (said("look","vomit")) {
  if (toilet_head) {
    print("You can't help but feel proud of your achievement.");
  }
  else {
    reset(input_parsed);
  }
}

if (said("take","vomit")) {
  if (toilet_head) {
    print("No.  What possible use could that have?");
  }
  else {
    reset(input_parsed);
  }
}

if (said("look","ground")) {
  print("Smooth, smooth tile.");
}

if (said("look","sink")) {
  if (posn(ego,6,82,43,130)) {
    print("Very clean.  Impressive.");
  }
  else {
    if (posn(ego,100,82,124,92)) {
      print("The urinal smells nice, due to the urinal cake.  But smells can be deceiving.  It may surprise you to learn that people pee in this contraption.");
    }
    else {
      print("You're not close enough.");
    }
  }
}

if (said("pee")) {
  print("You're not in the mood.");
}

if ((said("wash") || said("wash","hands"))) {
  print("No.  You have an aversion to washing your hands.  Your father always told you that only cowards wash their hands and that any man who'll be killed by little germs doesn't deserve to live anyway.");
}

if ((said("look") || said("look","room") || said("look","bathroom"))) {
  print("You are in the restroom.  The stalls are on the back wall.");
}

if (said("smell","rol")) {
  print("Whoo... someone light a match.");
}

if (f3) {
  new.room(22);
}

return();