// ****************************************************************************
//
// Logic 10: River Rapids
//
// ****************************************************************************

#include "defines.txt"

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

  if (prev_room_no == 11) {
      position(ego, 74, 44);
      }

  if (prev_room_no==12) {
      position(ego, 146,110);
      }
  animate.obj(o2);  //handle
  load.view(handle);
  set.view(o2,handle);
  position(o2,50,123);
  stop.cycling(o2);
  set.priority(o2,13);

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

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

  animate.obj(o6);         //foam
  load.view(16);
  set.view(o6,16);
  universe=5;
  cycle.time(o6,universe);
  universe=1;
  step.size(o6,universe);
  position(o6,70,165);
  ignore.objs(o6);
  wander(o6);
  draw(o6);

  animate.obj(o7);
  load.view(16);
  set.view(o7,16);
  set.cel(o7,2);
  universe=4;
  cycle.time(o7,universe);
  universe=1;
  step.size(o7,universe);
  ignore.objs(o7);
  position(o7,85,165);
  wander(o7);
  draw(o7);

  animate.obj(o8);
  load.view(16);
  set.view(o8,16);
  set.cel(o8,5);
  universe=5;
  cycle.time(o8,universe);
  universe=1;
  step.size(o7,universe);
  ignore.objs(o8);
  position(o8,100,165);
  wander(o8);
  draw(o8);

  if (handle_fixed) {

     draw(o2);
     }

  animate.obj(o3);
  load.view(12);
  set.view(o3,12);
  position(o3,69,122);
  universe=3;
  cycle.time(o3,universe);
  set.priority(o3,8);

  if (bridge_down) {
  set.cel(o3,4);
  stop.cycling(o3);
  draw(o3);
  }

  random(0,6,temp_x);
  if (temp_x==0 &&
      !has("eye of newt")) {
      animate.obj(o9);
      load.view(19);
      set.view(o9,19);
      position(o9,142,76);
      ignore.objs(o9);
      set.priority(o9,4);
      draw(o9);
      }


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

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


if (said("look")) {
  print("You are at the river crossing.");
  if (!bridge_down) {
       print("There's usually a bridge here, but it's missing.");
       }
}

if (said("look","river")) {
    print("These cool, blue waters flow from under the rock-face to the north, down the waterfall, and into the bay.");
    }

if (said("look","bank")) {
    print("Hot, yellow sand and decayed fish carcasses.");
    print("A veritable bouquet.");
      if (temp_x==0 &&
          !has("eye of newt")) {
             print("There's a little newt on the east bank.");
             }
    }

if (said("look","newt") &&
    temp_x==0 &&
    !has("eye of newt")) {
       print("He's sunning himself on that little patch of rock.");
       }

if ((said("look","thing") ||
     said("look","handle") ||
     said("look","hole"))) {
     if (handle_fixed) {
         print("The handle has been fixed.");
         }
     else {
         print("If you're referring to the thing I think you're referring...");
         print("That would be the switch, which is supposed to have a handle sticking out of it.");
         }
     }

if (said("look","bridge")) {
        print("Yep, Mama Houngan's Patent Collapsible Relapsible Bridge is quite a modern miracle.");
        }

if (said("look","spray")) {
        print("Spraying foam cascades in majestic mounds before the water falls down the side of the cliff.");
        }

if (said("get","sand")) {
    print("As if representing some philosophical axiom, the sand runs through your fingers.");
    }

if (said("swim")) {
       print("Oh, no.  The water is way too rapid here to swim safely.");
       }

if ((said("jump") ||
    said("jump","rol"))) {
       print("It is too far to jump to the other side.");
       }

if ((said("fix","bridge") ||
     said("fix","handle") ||
     said("put","handle","handle") ||
     said("install","handle"))) {
     distance(ego,o2,universe);
     if (obj.in.box(ego,35,100,75,140)){
     if (!handle_fixed) {
         if (has("handle")) {
             drop("handle");
             print("You deftly install the handle.");
             print("What skill!");
             set(handle_fixed);
             score+=1;
             new.room(10);
             }
         else {
             print("Don't have it.  Can't do it.");
             }
          }
     else {
         print("Yes, well, it's already fixed, innit?");
         }
     }
     else {
         print("Your arms aren't long enough.");
         }
   }

if ((said("use","handle") ||
     said("use","bridge") ||
     said("push","handle") ||
     said("pull","handle"))){
    distance(ego,o2,universe);
    if (obj.in.box(ego,35,110,65,140)){
    if (handle_fixed) {
        if (!bridge_down) {
        set(bridge_down);
        draw(o3);
        start.cycling(o3);
        end.of.loop(o3,done_flag);
        }
        else {
           reset(bridge_down);
           reverse.loop(o3,done_flag);
           erase(o3);
           }
        }
    else {
       print("You'll have to fix it before you can use it!");
       }
    }
    else {
       print("Your arms are too short.");
       }
  }

if (bridge_down) {
     set.cel(o2,1);
     }
  else {
     set.cel(o2,0);
     }

if (ego_touching_signal_line &&
    !bridge_down) {
       print("Too deep!");
       move.obj(ego, 66, 102,2,done_flag);
       }

if (said("get","newt")) {
    distance(o9,ego, universe);
    if (universe<=10) {
        print("You ravage the little beastie, munch on him, and save an eye for later.");
        get("eye of newt");
        new.room(10);
        }
    else {
        print("Summertime daylight...");
        print("You should know by now, my friend...");
        print("Your arms are too short.");
        }
    }


if (ego_edge_code == left_edge) {
  new.room(7);
  }

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

if (ego_edge_code == horizon_edge) {
  new.room(11);
  }


return();