// ****************************************************************************
//
// Logic 3: Garbage dump
//
// ****************************************************************************

#include "defines.txt"
#define door o1
#define lever o2
#define man o3
#define corpse o4

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

  if (prev_room_no == 249) {
   position(ego,12,156); set(f255);
   reset(f254);
  }

  if (prev_room_no == 246) {
    position(ego,79,150); set(f254);
  }

  draw(ego);
  show.pic();

  animate.obj(door);
  load.view(3);
  set.view(door,3);
  set.cel(door,1);
  set.priority(door,13);
  stop.cycling(door);
  ignore.objs(door);
  position(door,8,140);
  draw(door);

  animate.obj(lever);
  load.view(18);
  set.view(lever,18);
  set.loop(lever,1);
  set.cel(lever,0);
  stop.cycling(lever);
  set.priority(lever,13);
  ignore.objs(lever);
  position(lever,66,127);
  draw(lever);

  animate.obj(man);
  set.view(man,18);
  set.loop(man,0);
  set.cel(man,0);
  stop.cycling(man);
  ignore.blocks(man);
  ignore.objs(man);
  set.priority(man,11);
  position(man,98,94);
  draw(man);

  load.view(0);
  set.view(ego,0);

  animate.obj(corpse);
  load.view(13);
  set.view(corpse,13);
  stop.cycling(corpse);
  ignore.blocks(corpse);
  set.priority(corpse,13);
  position(corpse,69,150);

  reset(f252); reset(f251); reset(f250); reset(f249);
}

if (f255) {
  set.loop(door,1); ego_dir = 0;
  erase(ego); program.control();
}
else {
  set.loop(door,0);
  if (!f254) {
    player.control();
  }
}

if (f253) {
  set.cel(door,0);
}
else {
  set.cel(door,1);
}

if (posn(ego,0,132,80,149)) { //behind garbage truck
  set.priority(ego,12);
}
else {
  if (posn(ego,83,120,120,131)) {
    set.priority(ego,12);
  }
  else {release.priority(ego);}
}

if ((said("open","door") || said("open","truck"))) {
  if (posn(ego,0,156,32,167)) {
    toggle(f253);
  }
  else {
    print("You're not close enough.");
  }
}

if (said("get in","rol")) {
  if (posn(ego,0,156,32,167)) {
    if (f253) {
      draw(ego);
      ego_dir = 0; toggle(f255);
    }
    else {
      print("The door's closed.");
    }
  }
  else {
    print("You're not close enough.");
  }
}

if ((said("drive","rol") || said("use","car") || said("move","car"))) {
  if ((f255) && (!f253)) {
    new.room(249);
  }
  else {
    print("Maybe you should be in some kind of vehicle first.");
  }
}

if (f254) {
  if (!f251) {
    if (!f249) {
      set(f249);
      set.loop(corpse,0);
      v255 = 5; cycle.time(corpse,v255);
      start.cycling(corpse); ego_dir = 7; stop.motion(ego); program.control();
    }
  }
  draw(corpse);
}
else {
  if (!isset(f252) && !isset(trash_corpse)) {
    if (ego_touching_signal_line) {
      set(f252); print("As you pass the back of the truck, you hear a strange rustling noise.");
    }
  }
}

if (trash_corpse) {
  reset(f254); reset(f251); reset(f249);
  set.loop(corpse,1); set.cel(corpse,4); stop.cycling(corpse);
  draw(corpse);
}

if (said("look","corpse")) {
  if (f254) {
    print("It is reaching for you, grasping ravenously.  You can sense an evil presence inside its empty eye sockets, yet it seems human.");
  }
  else {
    if (trash_corpse) {
      print("The corpse's torso lies motionless on the pavement.  Its threat is over.  For now.");
    }
    else {print("There is nothing like that here.");}
  }
}

if ((said("pull","lever","rol") || said("activate","lever","rol") || said("activate","back truck","rol"))) {
  if ((f254) && (!f251)) {
    print("You desperately pull the lever, thereby activating the trash compactor.");
    score ++; set.cel(lever,1);
    v255 = 4; cycle.time(corpse,v255); set.loop(corpse,1);
    end.of.loop(corpse,trash_corpse); player.control();
  }
  else {
    print("I don't understand your request.");
  }
}

if (said("talk","corpse")) {
  if (f254) {
    print("It's more interested in eating your face, I'd imagine.");
  }
  else {
    reset(input_parsed);
  }
}

if (said("look","fence")) {
  print("The fence keeps all intruders from entering the dump, thereby protecting all the dirty treasures within.");
}

if ((said("look","building") || said("look","booth"))) {
  print("Sal Beardley is inside the control booth.  He opens and closes the gate from there.");
}

if ((said("look","back truck","rol") || said("open","back truck") || said("look","trash"))) {
  if (posn(ego,66,144,88,155)) {
    if ((!trash_corpse) && (!f254)) {
      print("Ok.");
      new.room(246);
    }
    else {
      print("You have no need.");
    }
  }
  else {
    print("You're not close enough.");
  }
}

if (said("look","truck")) {
  print("Your truck is worthy transportation.  The trash compactor in the back is operated by a lever.");
}

if (said("look","lever")) {
  print("The lever on the back of your truck operates the trash compactor.");
}

if ((said("talk","man","rol") || said("deposit","trash","rol") || said("talk","person","rol"))) {
  v255 = 6; cycle.time(man,v255);
  if (trash_corpse) {
    print.at("YOU: 'What was that thing, Sal?'",2,2,32);
  }
  end.of.loop(man,f250); stop.motion(ego); program.control();
}

if (f250) {
  reset(f250); player.control();  set.cel(man,0);
  if (trash_corpse) {
    print.at("SAL: 'A man, or at least, it used to be a man.  You're new in Memory...'",2,3,30);
    print.at("SAL: 'You don't know about this town yet.  The dead don't stay dead.  It's best just to learn to live with it.'",2,3,30);
    print.at("YOU: 'What you tell me is most troubling.'",2,3,30);
    print.at("YOU: 'I've lost interest in garbage, Sal.  That killer corpse really put things into perspective.'",2,3,30);
    print.at("YOU: 'I'm going to put a stop to this!'",2,3,30);
  }
  else {
    if (f254) {
      print.at("SAL: 'You're not bringing that zombie into this dump while I'm on duty, John.'",2,3,32);
    }
    else {
      print.at("SAL: 'Before I let you in, check the back of your truck, John.  I heard a strange noise.'",2,3,32);
    }
  }
}

if (said("look","ground")) {
  print("The ground holds firm.  Now that's craftsmanship.");
}

if ((said("look") || said("look","dump"))) {
  print("This is the city dump.  Headquarters for a garbage man such as yourself.");
}

if ((said("look","man") || said("look","person"))) {
  print("It's Sal Beardley.  He works at the dump, opening the gate and so forth.");
}

return();