//////////////////////////////////////////////////////////////////////
// Sailing The Seas of Cheese
// The boat travel script
//////////////////////////////////////////////////////////////////////
// By Deva Bryson Winblood.  12/06/2003
//////////////////////////////////////////////////////////////////////
void fnMoveArmy(object oPC,object oDest)
{ // move me and my army
  int nC=1;
  object oNPC=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oPC,nC);
  string sID=GetLocalString(oPC,"sTeamID");
  while(oNPC!=OBJECT_INVALID)
  { // move NPC
    if (GetLocalString(oNPC,"sTeamID")==sID)
    { // jump this person
      AssignCommand(oNPC,ClearAllActions(TRUE));
      AssignCommand(oNPC,JumpToObject(oDest));
    } // jump this person
    nC++;
    oNPC=GetNearestCreature(CREATURE_TYPE_IS_ALIVE,TRUE,oPC,nC);
  } // move NPC
  AssignCommand(oPC,ClearAllActions(TRUE));
  AssignCommand(oPC,JumpToObject(oDest));
} // fnMoveArmy()


void main()
{
   object oPC=GetPCSpeaker();
   object oMe=OBJECT_SELF;
   if (oPC==OBJECT_INVALID) oPC=oMe;
   int nDest=GetLocalInt(oPC,"nBoatDest");
   int nTravelState=GetLocalInt(oPC,"nBoatState");
   float fSpeed=10.0;
   string sTag;
   object oWP;
   switch(nTravelState)
   { // switch
     case 0: { // set sail
       if (nDest==0)
       { // return elben
         oWP=GetWaypointByTag("BOAT_2");
       } // return elben
       else
       { // normal
         oWP=GetWaypointByTag("BOAT_1");
       } // normal
       fnMoveArmy(oPC,oWP);
       SetLocalInt(oPC,"nBoatState",1);
       break;
     } // set sail
     case 1: { // first destination
       if (nDest==2)
       { // myth
         if (d4()<3)
         { // pirates
           fSpeed=60.0;
           SetLocalInt(oPC,"nBoatState",2);
         } // pirates
         else
         { // no pirates
           fSpeed=180.0;
           SetLocalInt(oPC,"nBoatState",4);
         } // no pirates
       } // myth
       else
       { // other
         fSpeed=120.0;
         SetLocalInt(oPC,"nBoatState",4);
       } // other
       break;
     } // first destination
     case 2: { // pirates
       sTag=GetTag(GetArea(oPC));
       if (sTag!="AtSeaPirates"&&sTag!="TheRealmofShadows"&&sTag!="ThePlaneofInBetween")
       { // move to pirates
         oWP=GetWaypointByTag("BOAT_3");
         fnMoveArmy(oPC,oWP);
       } // move to pirates
       else if (sTag!="TheRealmofShadows"&&sTag!="ThePlaneofInBetween")
       { // not dead
         oWP=GetNearestObjectByTag("PIRATE",oPC,1);
         if (oWP==OBJECT_INVALID)
         { // pirates defeated
           fSpeed=30.0;
           SetLocalInt(oPC,"nBoatState",3);
         } // pirates defeated
       } // not dead
       else { SetLocalInt(oPC,"nBoatState",-1); }
       break;
     } // pirates
     case 3: { // 2nd destination
       oWP=GetWaypointByTag("BOAT_2");
       fnMoveArmy(oPC,oWP);
       fSpeed=120.0;
       SetLocalInt(oPC,"nBoatState",4);
       break;
     } // 2nd destination
     case 4: { // arrive at destination
       if (nDest==0)
        oWP=GetWaypointByTag("BOAT_ELBEN");
       else if (nDest==1) oWP=GetWaypointByTag("BOAT_DRAGONS");
       else if (nDest==2) oWP=GetWaypointByTag("BOAT_MYTH");
       fnMoveArmy(oPC,oWP);
       SetLocalInt(oPC,"nBoatState",-1);
       break;
     } // arrive at destination
   } // switch
   if (nTravelState!=-1) DelayCommand(fSpeed,ExecuteScript("sailing_script",oPC));
}