/*
       -= SEER - C-Scripting engine v 0.94a =-
State      : under implementation
Author     : Przemyslaw Podsiadly
             email: ppodsiad@elka.pw.edu.pl
             WWW:   http://home.elka.pw.edu.pl/~ppodsiad/seer
File:exlfrodo.sc
Desc:character script for Frodo
*/

#title Frodo
#author Theur

#include "exlotr.sh"

string goal="wait";

void handleEvent(Event& e)
{
 switch(e.nr)
 {
  case evUnable:
       say("What am I to do? I can't %s!",goal);break;
  case evNotice:
       say("I have noticed %s. I'll leave it where it lies.",evNoticeWhat(e));break;
  case evHear:
       say("I have heard %s",evHearWhat(e));break;
  case evAttacked:
       say("I've been suddenly attacked by %s",evAttackedBy(e));break;
  default:say("What am I doing here?");
 }
}


void waitForFriends()
{bool Sam=false,Merry=false,Pippin=false;
 Event e;

 goal="meet Sam, Merry and Pippin";
 while((!Sam||!Merry||!Pippin))
 {
  act(e,actWait);

  if (e==evMeet)//maybe we meet one of them
  {
   string name=evMeetWhom(e)->name;
   if (name=="Sam") Sam=true;
   else
   if (name=="Merry") Merry=true;
   else
   if (name=="Pippin") Pippin=true;
   say("Hello %s!",name);
  }
  else
   handleEvent(e);
 }
 WAIT;//give control to system
 say("So we are all here. Let's go to Rivendell!");

}

void goToRivendell()
{Event e;

 goal="reach Rivendell";
 while ((goToPlace(e,"Rivendell")),e!=evSuccess)
 {handleEvent(e);
 }
 say("I have reached Rivendell!");

 goal="find door";
 Place *p=getPlace("Rivendell:Door");
 while (goTo(e,p),e!=evSuccess)
 {handleEvent(e);
 }
 say("I have found the door!");

 goal="open door";
 while (act(e,actOpen,p),e!=evSuccess)
 {if (e==evUnable)
  {say("The door seems locked!");return;
  }
  handleEvent(e);
 }
 say("I open the door and I'm in.");
 WAIT;
}

void live()
{
 waitForFriends();
 goToRivendell();

 tellTo("Merry","Go rest!");
 tellTo("Sam","Go rest!");
 tellTo("Pippin","Go rest!");
 WAIT;//give Pippin the chance to respond, normally we would wait
 //till Pippin says something or leaves
 say("Here I can rest with Bilbo, Elrond and others...");
}
