// vamp_act_ctwolf
#include "vampire_header"
void fnFollowMaster(object oPC)
{ // follow
  float fDist=GetDistanceBetween(oPC,OBJECT_SELF);
  if (fDist>4.0&&GetArea(oPC)==GetArea(OBJECT_SELF))
  {
    if (fDist>10.0) ActionMoveToObject(oPC,TRUE,1.0);
    else { ActionMoveToObject(oPC,FALSE,1.0); }
  }
  else if (GetArea(oPC)!=GetArea(OBJECT_SELF))
  { // teleport
    AssignCommand(OBJECT_SELF,ClearAllActions());
    AssignCommand(OBJECT_SELF,JumpToObject(oPC));
  } // teleport
  DelayCommand(8.0,fnFollowMaster(oPC));
} // fnFollowMaster()


void main()
{
   object oPC=GetPCSpeaker();
   if (!GetIsObjectValid(oPC)) oPC=OBJECT_SELF;
   object oT=GetLocalObject(oPC,"oTarget");
   int nXP=GetLocalInt(oPC,"nVampireXP");
   int nLevel=1+(nXP/5000);
   int nControl;
   int nBlood=GetLocalInt(oPC,"nBloodPool");
   float fCR=GetChallengeRating(oT);
   int nCR=FloatToInt(fCR);
   string sID=GetLocalString(oPC,"sTeamID");
   string sTID=GetLocalString(oT,"sTeamID");
   object oWP=GetWaypointByTag(sID+"_RESOURCES");
   object oTemp;
   if (sID!=sTID)
   { // not on your team
     if (nLevel>5) nLevel=5;
     nControl=nLevel+d20();
     nCR=nCR+d20();
     if (nControl>=nCR)
     { // control okay
       fnGiveVampXP(oPC,(FloatToInt(fCR)+1)*10);
       oTemp=GetObjectByTag(sID+"_PROXY");
       ChangeFaction(oT,oTemp);
       SetLocalString(oT,"sTeamID",sID);
       //DestroyObject(oTemp);
       AssignCommand(oT,ClearAllActions(TRUE));
       if (sTID=="")
       { // not a team - set to follow
         fnFollowMaster(oPC);
       } // not a team - set to follow
     } // control okay
     nBlood=nBlood-30;
     SetLocalInt(oPC,"nBloodPool",nBlood);
     if (nControl>=nCR)
        SendMessageToPC(oPC,"You manage to control the "+GetName(oT)+".");
     else { SendMessageToPC(oPC,"You cannot manage to control the "+GetName(oT)+".");}
     SendMessageToPC(oPC,"You spend 30 blood attempting to control.");
   }
   else
   { SendMessageToPC(oPC,GetName(oT)+" is already on your team."); }
}