// ****************************************************************************
//
// Logic 16: Cemetery A1
//
// ****************************************************************************

#include "defines.txt"
#define zombie o1
#define ghoul o2
#define man o3
#define door o4
#define window o5
#define tool o6

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

  if (prev_room_no == 20) {
    position(ego,41,92);
  }

  draw(ego);
  show.pic();

  if (!isset(cemetery_zombie2)) {
    animate.obj(zombie);
    load.view(22);
    set.view(zombie,22);
    if (prev_room_no == 247) {
      if (prev_monster == 1) {
        reset(m1_attacks);
        position.v(zombie,v244,v245);
        if (monster == 0) {
          set(cemetery_zombie2);
          load.view(28);
          set.view(zombie,28);
          set.loop(zombie,4);
          stop.motion(zombie);
        }
        else {
          get.posn(ego,v254,v255);
          if (v254 > v244) {
            v254 = 0; v255 = 240;
            reposition(ego,v255,v254);
          }
          else {
            v254 = 0; v255 = 16;
            reposition(ego,v255,v254);
          }
        }
      }
      else {
        position.v(zombie,v244,v245);
      }
    }
    else {
      position(zombie,28,94);
    }
    draw(zombie);
  }
  if (!isset(cemetery_zombie2) && (alerted)) {
    v255 = 3; step.time(zombie,v255);
    v255 = 4; cycle.time(zombie,v255);
    ignore.objs(zombie);
    follow.ego(zombie,6,m1_attacks);
  }

  if (!isset(cemetery_ghoul)) {
    animate.obj(ghoul);
    load.view(9);
    set.view(ghoul,9);
    if (prev_room_no == 247) {
      if (prev_monster == 2) {
        reset(m2_attacks);
        position.v(ghoul,v246,v247);
        if (monster == 0) {
          set(cemetery_ghoul);
          load.view(10);
          set.view(ghoul,10);
          set.loop(ghoul,4);
          stop.motion(ghoul);
        }
        else {
          get.posn(ego,v254,v255);
          if (v254 > v246) {
            v254 = 0; v255 = 240;
            reposition(ego,v255,v254);
          }
          else {
            v254 = 0; v255 = 16;
            reposition(ego,v255,v254);
          }
        }
      }
      else {
        position.v(ghoul,v246,v247);
      }
    }
    else {
      position(ghoul,24,103);
    }
    draw(ghoul);
  }
  if (!isset(cemetery_ghoul) && (alerted)) {
    v255 = 2; step.time(ghoul,v255);
    v255 = 4; cycle.time(ghoul,v255);
    ignore.objs(ghoul);
    follow.ego(ghoul,6,m2_attacks);
  }

  if (!isset(alerted)) {
    v255 = 4; cycle.time(zombie,v255);
    cycle.time(ghoul,v255);
    set.loop(ghoul,1); set.loop(zombie,1);
    set.cel(ghoul,2);
    stop.motion(zombie);
    stop.motion(ghoul);
    start.cycling(ghoul); start.cycling(zombie);
  }

  animate.obj(man);
  load.view(33);
  set.view(man,33);
  ignore.blocks(man);
  position(man,5,99);
  v255 = 3;
  cycle.time(man,v255);
  if (!isset(alerted)) {
    set.loop(man,0);
    start.cycling(man);
  }
  draw(man);

  animate.obj(door);
  load.view(38);
  set.view(door,38);
  set.loop(door,0);
  stop.cycling(door);
  position(door,39,90);
  draw(door);

  animate.obj(window);
  set.view(window,38);
  set.loop(window,1);
  stop.cycling(window);
  ignore.objs(window);
  ignore.blocks(window);
  ignore.horizon(window);
  position(window,68,70);
  draw(window);

  v255 = 16;
if (obj.in.room("knife",v255)) {
  animate.obj(tool);
  load.view(40);
  set.view(tool,40);
  set.loop(tool,0);
  stop.cycling(tool);
  ignore.objs(tool);
  position(tool,86,84);
  draw(tool);
}

}

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

if (shed_window) {
  set.cel(window,1);
}
else {
  set.cel(window,0);
}

if (posn(ego,0,75,115,135) && (!isset(alerted))) {
  set(alerted);  print("They saw you!");
  release.loop(ghoul); release.loop(zombie);
  v255 = 3; step.time(zombie,v255);
  v255 = 2; step.time(ghoul,v255);
  ignore.objs(zombie); ignore.objs(ghoul);
  follow.ego(ghoul,6,m2_attacks);
  follow.ego(zombie,6,m1_attacks);
}

if (alerted) {
  if ((cemetery_ghoul) && (cemetery_zombie2)) {
    set.loop(man,1);
    stop.cycling(man); ignore.blocks(man);
    reposition.to(man,12,99);
  }
  else {
    set.loop(man,0);
    set.cel(man,4);
    stop.cycling(man);
  }
}

if (m1_attacks) {
  stop.motion(zombie);
  get.posn(zombie,v244,v245);
  get.posn(ghoul,v246,v247);
  prev_monster = 1;
  monster = 4;
  scenery = 1;
  new.room(247);
}

if (m2_attacks) {
  stop.motion(ghoul);
  get.posn(ghoul,v246,v247);
  get.posn(zombie,v244,v245);
  prev_monster = 2;
  monster = 1;
  scenery = 1;
  new.room(247);
}

if (said("take","knife")) {
  v255 = 16;
  if (obj.in.room("knife",v255)) {
    if (posn(ego,80,77,95,88)) {
      print("Ok."); get("knife"); score++;
      set(got_tool);
      erase(tool);
    }
    else {
      print("You're not close enough.");
    }
  }
  else {
    reset(input_parsed);
  }
}

if (said("look","knife")) {
  v255 = 16;
  if (obj.in.room("knife",v255)) {
    print("The knife is lying where it landed after you threw it out the window.");
  }
  else {
    reset(input_parsed);
  }
}

if (said("open","door")) {
  if (posn(ego,32,90,54,96)) {
    toggle(f245);
  }
  else {
    print("You're not close enough.");
  }
}

if (said("open","window")) {
  if (posn(ego,70,76,84,90)) {
    toggle(shed_window);
  }
  else {
    print("You're not close enough.");
  }
}

if (said("look","window")) {
  if (shed_window) {
    print("The window to the toolshed is open.");
  }
  else {
    print("The shed's window is closed.");
  }
}

if (said("look","shed")) {
  print("The cemetery's toolshed is where the caretaker keeps his tools, of course.");
}

if (said("look","man")) {
  if (!isset(alerted)) {
    print("The caretaker is fighting for his life.  Two zombies have descended upon him.");
  }
  else {
    if ((!isset(cemetery_zombie2) || !isset(cemetery_ghoul))) {
      print("He's watching you to see what happens next with the zombies.");
    }
    else {
      print("The caretaker looks relieved.  The zombies have temporarily been defeated.");
    }
  }
}

if (said("talk","man")) {
  if ((!isset(cemetery_zombie2) || !isset(cemetery_ghoul))) {
    print("Conversation isn't a top priority right now, seeing as how there are flesh-rending zombies on the loose.");
  }
  else {
    if (posn(ego,0,91,30,110)) {
      print("The caretaker says, 'Well done.  Your zombie killing ability reminds me of myself in my younger days.'");
      print("'I'll talk to you more later, in the full version.'");
    }
    else {
      print("You're too far away.");
    }
  }
}

if ((said("talk","man","shovel") || said("talk","shovel"))) {
  if ((!isset(cemetery_zombie2) || !isset(cemetery_ghoul))) {
    print("Conversation isn't a top priority right now, seeing as how there are flesh-rending zombies on the loose.");
  }
  else {
    if (posn(ego,0,91,30,110)) {
      print("'This shovel is my livelihood.  You can't have it (especially in the demo).'");
    }
    else {
      print("You're too far away.");
    }
  }
}

if (said("get","shovel","rol")) {
  print("You should ask nicely.");
}

if (said("look","shovel")) {
  print("The caretaker holds a shovel.  You suspect such a shovel could prove useful on your mission.");
}

if (said("look","tree")) {
  print("The tree is just that: a tree.");
}

if (said("look","corpse")) {
  if ((!isset(cemetery_zombie2) || !isset(cemetery_ghoul))) {
    print("Looks like trouble.");
  }
  else {
    print("There are no zombies here.");
  }
}

if (said("look","fence")) {
  print("The fence is high and made up of bars.  It reminds you of a prison.");
}

if (said("look","monument")) {
  print("You're not interested.  They're all the same in death.");
}

if ((said("look","ground") || said("look","grave"))) {
  print("The ground hides many things here.  Not the least of which is hordes of dead people.  They're all probably scratching at their coffins, eager to dig their gnashing teeth  into your throat and clutching claws into your eyesockets.");
  print("On second thought, you'd prefer not to think about it.");
}

if ((said("look") || said("look","cemetery"))) {
  print("Be careful.  A cemetery isn't the safest place to be when the dead are restless.");
}

if (ego_edge_code == 3) {
  new.room(17);
}

if (ego_edge_code == right_edge) {
  new.room(15);
}

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

return();