// ****************************************************************************
//
// Logic 6: Swampy's Checkpoint
//
// ****************************************************************************

#include "defines.txt"

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

  // The next 6 lines need only be in the first room of the game
 /* if ((prev_room_no == 1 ||    // just come from intro screen
      prev_room_no == 0)) {    // or just started game
    position(ego,120,140);
    status.line.on();
    accept.input();
  }*/

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

  animate.obj(o1);          // Blooderflies
  load.view(15);
  set.view(o1,15);
  ignore.objs(o1);
  position (o1, 70,109);
  wander(o1);
  draw(o1);

  animate.obj(o2);
  load.view(15);
  set.view(o2,15);
  ignore.objs(o2);
  position (o2, 80,80);
  wander(o2);
  draw(o2);

  animate.obj(o3);       // Swampy
  load.view(7);
  set.view(o3,7);
  position(o3,86,126);
  if (swampy_asleep) {
      set.loop(o3,1);
      }
  universe = 2;
  cycle.time(o3, universe);
  draw(o3);

  animate.obj(o4);   //Throwing Potions
  load.view(poison);
  load.view(sleep_potion);

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

  draw(ego);
  show.pic();
}



if (said("look")) {
  print("This is Swampy's Checkpoint.  Swampy is the troglodyte in the green loincloth.");
  print("At least you hope it's a loincloth.");
}

if (isset(ego_touching_signal_line) && (!isset(swampy_asleep))){
    print.at("Swampy: \"Hey!  You can't go past!\"",3,5,20);
    print("You're going to have to figure out another way through.");
    move.obj(o0,39,109,1,done_flag);
    }

if ((said("give","swampy","poison") ||
    said("give","guy","poison") ||
    said("give","poison","swampy") ||
    said("give","poison","guy") ||
    said("give","poison"))) {
     if (has("poison")){
       if (swampy_asleep) {
         print("Shhh...  don't wake him.");
         }
       else {
         drop("poison");
         set.view(o4,poison);
         temp_x=new_ego_x;
         temp_y=new_ego_y;
         temp_x+=10;
         temp_y-=10;
         position.v(o4,temp_x,temp_y);
         set.priority(o4,15);
         draw(o4);
         move.obj(o4,95,116,4,another_done_flag);
        }
      }
     else{print("You don't have any.");}
    }

if (another_done_flag) {
     erase(o4);
     print.at("Swampy: \"Mmm... that's good!  Got anymore?\"",3,5,20);
     reset(another_done_flag);
     }


if ((said("give","swampy","sleeping potion") ||
    said("give","guy","sleeping potion") ||
    said("give","sleeping potion","swampy") ||
    said("give","sleeping potion","guy") ||
    said("give","sleeping potion") ||
    said("feed","swampy","sleeping potion") ||
    said("feed","sleeping potion","swampy"))) {
     if (has("sleep potion")) {
      if (!swampy_asleep) {
      score++;
      drop("sleep potion");
       set.view(o4,sleep_potion);
         temp_x=new_ego_x;
         temp_y=new_ego_y;
         temp_x+=10;
         temp_y-=10;
         position.v(o4,temp_x,temp_y);
         set.priority(o4,15);
         draw(o4);
         move.obj(o4,95,116,4,yet_another_done_flag);
      }
      else {print("He's already asleep.");}
      }
     else {print("But you have none to give.");}
    }

if (yet_another_done_flag) {
      print("Swampy drinks the potion and nods off to sleep.");
      set(swampy_asleep);
      set.loop(o3,1);
      reset(yet_another_done_flag);
      erase(o4);
      }

if ((said("talk","swampy") ||
    said("talk","guy"))) {
    if (!swampy_asleep) {
    print.at("Swampy: \"Dang, girl...   Guarding this here checkpoint makes a man awful thirsty.\"",3,5,20);
    }
    else {
      print.at("Swampy: \"ZZZZZZZZZzzzz...\"",3,5,20);
    }
  }

if ((said("look","swampy") ||
    said("look","guy"))) {
    if (!swampy_asleep) {
     print("This is Swampy.  Swampy could squeeze blood from a stone.  Who knows what he could do to you if you crossed him.");
     }
    else {
       print("Awww,  wook at da widdle sweeping bay-bee.");
       }
    }

if ((said("look","loincloth") ||
    said("look","anyword","loincloth"))) {
      print("You'd rather not look too close.");
      }

if (said("look","spear")) {
    print("You try not to think of what he could do with that thing...  in any context.");
    }

if ((said("look","tree") ||
     said("climb","tree"))) {
   if (!swampy_asleep) {
    print("It would be too obvious trying to hide in the tree until Swampy went to sleep.");
    }
   else {
     print("There is nothing up there for you.");
     }
   }

if ((said("look","cliff") ||
     said("look","wall") ||
     said("look","rock"))) {
    print("A shallow cliff...  but still tall and smooth enough that you have no hope of climbing it.");
    }

if (said("look","checkpoint")) {
    print("It's not so much a checkpoint as it is an isolated area with a big tree and some kind of troglodyte...");
    print("But it IS the troglodyte's home.");
    }

if ((said("attack","swampy") ||
     said("attack","guy") ||
     said("attack","creature"))) {
          print("No, Swampy is actually your friend.  He only guards this checkpoint to make sure you don't cause trouble down in the village...  again.");
          print("Besides, he is a powerful fighter.");
          }

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

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

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

return();