plSceneObject* plCameraModifier1::GetSubject()
{
    if (GetBrain())
        return GetBrain()->GetSubject();
    else
        return fSubObj;
}   
void plCameraModifier1::SetSubject(plSceneObject* pObj)
{ 
    if (GetBrain())
        GetBrain()->SetSubject(pObj); 
    else 
        fSubObj = pObj; 
}
Exemple #3
0
AI::ActionState::Enum A_OpenDoor::Update(AI::ActionInstance* inst, double time)
{
	if (GetBrain()->GetMemory()->IsGoToIdle())
	{
		GetBrain()->GetFSM()->ChangeState("GoNear");
		GetBrain()->GetMemory()->SetGoToGoing();
	}
	else if (GetBrain()->GetMemory()->IsGoToArrived())
	{
		auto gtc = GetBrain()->GetOwner()->GetLayer()
			->FindEntity("terrain")->GetC<GridTerrainComponent>();

		gtc->SetEnvironment(
			_doorLocation.first, _doorLocation.second, Environment::NONE);

		GetBrain()->GetMemory()->Remove(
			_doorType, _doorLocation.first, _doorLocation.second);

		GetBrain()->GetMemory()->UseKey(
			Environment::Enum(Environment::KEY_S + 
			(_doorType - Environment::DOOR_S)));

		return AI::ActionState::SUCCEED;
	}
	else if (GetBrain()->GetMemory()->IsGoToFailed())
	{
		return AI::ActionState::FAILED;
	}

	return AI::ActionState::RUN;
}
Exemple #4
0
void A_OpenDoor::Init(AI::ActionInstance* inst)
{
	_doorLocation = GetBrain()->GetMemory()
		->GetAnyOpenableDoor(_doorType);
	auto gtc = GetBrain()->GetOwner()->GetLayer()
		->FindEntity("terrain")->GetC<GridTerrainComponent>();
	glm::vec3 goalPos; goalPos.y = 0.0f;
	gtc->GetAIWorld()->Dequantize(
		_doorLocation.first, _doorLocation.second, 
		goalPos.x, goalPos.z);

	GetBrain()->GetMemory()->SetGotoPos(goalPos);
	GetBrain()->GetMemory()->ResetGoTo();
}
Exemple #5
0
std::vector<AI::Precondition> A_OpenDoor::GetPrecons(
	const std::vector<AI::Precondition>& effects)
{
	if (GetBrain()->GetMemory()->HasAnyDoor())
	{
		AI::Precondition hasKey(AI::WorldState::HasMatchingKey);
		AI::Precondition::Var keytype;
		keytype.env = 
			Environment::MatchingKey(GetBrain()->GetMemory()->GetDoor());
		hasKey.AddVar(keytype);
		return{ hasKey };
	}

	AI::Precondition knowDoor(AI::WorldState::KnowsAnyMatchingDoorAndKey);
	return{ knowDoor };
}
void plCameraModifier1::AddTarget(plSceneObject* so)
{
    fTarget = so;
    if( plVirtualCam1::Instance() )
        plVirtualCam1::Instance()->AddCameraLoaded(so);
    fFrom = (so->GetWorldToLocal().GetTranslate());
    if (GetBrain())
    {
        if (fTarget->GetCoordinateInterface())
            GetBrain()->AddTarget();
        else
            fUpdateBrainTarget = true; // update the brain later
    }
    if (GetKey())
    {   
        plgDispatch::Dispatch()->RegisterForExactType(plEvalMsg::Index(), GetKey());
    }
}
int CAIButeMgr::GetBrainIDByName(const char *szName)
{
	for ( int iBrainID = 0 ; iBrainID < m_cBrainID ; iBrainID++ )
	{
		if ( !strcmp(szName, GetBrain(iBrainID)->szName) )
		{
			return iBrainID;
		}
	}

	return -1;
}
void plCameraModifier1::Pop()
{
    if (fAnimated)
    {
        if (fStopAnimOnPop)
        {
            plAnimCmdMsg* pMsg = new plAnimCmdMsg;
            pMsg->SetCmd(plAnimCmdMsg::kStop);
            pMsg->SetBCastFlag(plMessage::kPropagateToModifiers);
            pMsg->AddReceiver(GetTarget()->GetKey());
            if (GetBrain() && GetBrain()->GetSubject())
                pMsg->AddReceiver(GetBrain()->GetSubject()->GetKey());
            pMsg->Send();       
        }
        if (fResetAnimOnPop)
        {
            plAnimCmdMsg* pMsg = new plAnimCmdMsg;
            pMsg->SetCmd(plAnimCmdMsg::kGoToBegin);
            pMsg->SetBCastFlag(plMessage::kPropagateToModifiers);
            pMsg->AddReceiver(GetTarget()->GetKey());
            if (GetBrain() && GetBrain()->GetSubject())
                pMsg->AddReceiver(GetBrain()->GetSubject()->GetKey());
            pMsg->Send();
        }
    }
    if (fBrain)
        fBrain->Pop();
    if (GetKey()) // the reason we might not have a key is a special run-time POA which doesn't need to receive messages...
    {       
        plgDispatch::Dispatch()->UnRegisterForExactType(plMouseEventMsg::Index(), GetKey());
    }
}   
void plCameraModifier1::Push(bool recenter)
{
    if (fAnimated)
    {
        if (fStartAnimOnPush)
        {
            plAnimCmdMsg* pMsg = new plAnimCmdMsg;
            pMsg->SetCmd(plAnimCmdMsg::kRunForward);
            pMsg->SetBCastFlag(plMessage::kPropagateToModifiers);
            pMsg->AddReceiver(GetTarget()->GetKey());
            if (GetBrain() && GetBrain()->GetSubject())
                pMsg->AddReceiver(GetBrain()->GetSubject()->GetKey());
            pMsg->Send();
        }
    }
    if (fBrain)
        fBrain->Push(recenter);


    if (GetKey())
    {   
        plgDispatch::Dispatch()->RegisterForExactType(plMouseEventMsg::Index(), GetKey());
    }
}
Exemple #10
0
//--------------------------- HandleMessage -----------------------------------
//-----------------------------------------------------------------------------
bool Raven_Bot::HandleMessage(const Telegram& msg)
{
  //first see if the current goal accepts the message
  if (GetBrain()->HandleMessage(msg)) return true;
 
  //handle any messages not handles by the goals
  switch(msg.Msg)
  {
  case Msg_TakeThatMF:

    //just return if already dead or spawning
    if (isDead() || isSpawning()) return true;

    //the extra info field of the telegram carries the amount of damage
    ReduceHealth(DereferenceToType<int>(msg.ExtraInfo));

    //if this bot is now dead let the shooter know
    if (isDead())
    {
      Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY,
                              ID(),
                              msg.Sender,
                              Msg_YouGotMeYouSOB,
                              NO_ADDITIONAL_INFO);
    }

    return true;

  case Msg_YouGotMeYouSOB:
    
    IncrementScore();
    
    //the bot this bot has just killed should be removed as the target
    m_pTargSys->ClearTarget();

    return true;

  case Msg_GunshotSound:

    //add the source of this sound to the bot's percepts
    GetSensoryMem()->UpdateWithSoundSource((Raven_Bot*)msg.ExtraInfo);

    return true;

  case Msg_UserHasRemovedBot:
    {

      Raven_Bot* pRemovedBot = (Raven_Bot*)msg.ExtraInfo;

      GetSensoryMem()->RemoveBotFromMemory(pRemovedBot);

      //if the removed bot is the target, make sure the target is cleared
      if (pRemovedBot == GetTargetSys()->GetTarget())
      {
        GetTargetSys()->ClearTarget();
      }

      return true;
    }
  case Msg_IWasKilledAndIHadWeapons:
  {

	  GraveMarkers::GraveRecord* pGrave = (GraveMarkers::GraveRecord*)msg.ExtraInfo;

	  GetSensoryMem()->AddGraveToMemory(pGrave);

	  return true;
  }


  default: return false;
  }
}
void plCameraModifier1::Update()
{
    // update the brain

    // this freeze thing is a useful debugging tool...  
    if (plVirtualCam1::Instance()->freeze)
        return;
    
    if (GetBrain())
    {
        if (fUpdateBrainTarget && fTarget->GetCoordinateInterface()) // if we need to update the brain and the target is loaded
        {
            fUpdateBrainTarget = false;
            GetBrain()->AddTarget(); // update the brain's target
        }

        bool moveInSub = !(GetBrain()->HasFlag(plCameraBrain1::kIgnoreSubworldMovement));

        if (moveInSub && GetBrain()->GetSubject())
        {
            plKey worldKey = nil;

            // First check if this is a physical.  If so, grab the subworld from that
            if (GetBrain()->GetSubject()->GetSimulationInterface())
            {
                plPhysical* phys = GetBrain()->GetSubject()->GetSimulationInterface()->GetPhysical();
                if (phys)
                    worldKey = phys->GetWorldKey();
            }
            // Also, check if this is an avatar.  They don't have physicals, you
            // have to ask the avatar controller for the subworld key.
            if (!worldKey)
            {
                plKey subject = plKey(GetBrain()->GetSubject()->GetKey());
                plArmatureMod* armMod = plAvatarMgr::FindAvatar(subject);
                if (armMod && armMod->GetController() )
                    worldKey = armMod->GetController()->GetSubworld();
            }

            if (worldKey)
            {
                // this picks up and moves the camera to it's previous subworld coordinate (so the subworld isn't moving out from underneath us)
                hsMatrix44 l2w, w2l;
                plSceneObject* so = plSceneObject::ConvertNoRef(worldKey->ObjectIsLoaded());
                if (so)
                {
                    l2w = so->GetLocalToWorld();
                    w2l = so->GetWorldToLocal();

                    if (fInSubLastUpdate)
                    {
                        if (!(fLastSubPos == fFrom && fLastSubPOA == fAt))
                        {
                            SetTargetPos(l2w * fLastSubPos);
                            SetTargetPOA(l2w * fLastSubPOA);
                        }
                    }
                    else
                    {
                        fInSubLastUpdate = true;
                    }
                    GetBrain()->Update();
                    fLastSubPos = w2l * GetTargetPos();
                    fLastSubPOA = w2l * GetTargetPOA();
                }
                return;
            }
            else
            {
                fInSubLastUpdate = false;
            }
        }
        GetBrain()->Update();
        fLastSubPos = GetTargetPos();
        fLastSubPOA = GetTargetPOA();
    }
}   
bool plCameraModifier1::MsgReceive(plMessage* msg)
{
    if (GetBrain())
        GetBrain()->MsgReceive(msg);
        
    plCameraMsg* pCamMsg = plCameraMsg::ConvertNoRef(msg);
    if (pCamMsg)
    {
        if (pCamMsg->Cmd(plCameraMsg::kAddFOVKeyframe))
        {
            hsRefCnt_SafeRef(msg);
            fFOVInstructions.Append(pCamMsg);
            return true;
        }
        else
        if (pCamMsg->Cmd(plCameraMsg::kSetAnimated))
        {
            fAnimated = true;
            return true;
        }
    }
    plEventCallbackMsg* pEventMsg = plEventCallbackMsg::ConvertNoRef(msg);
    if (pEventMsg)
    {
        double time = (double)fFOVInstructions[pEventMsg->fIndex]->GetConfig()->fAccel;
        double time2 = (double)pEventMsg->fEventTime;
        time = hsABS(time - time2);
        float h = fFOVInstructions[pEventMsg->fIndex]->GetConfig()->fFOVh;
        if (GetBrain())
            GetBrain()->SetFOVGoal(h, time);
    }

    plAnimCmdMsg* pAnimMsg = plAnimCmdMsg::ConvertNoRef(msg);
    if (pAnimMsg)
    {
        hsRefCnt_SafeRef(msg);
        msg->ClearReceivers();
        msg->AddReceiver(msg->GetSender());
        fMessageQueue.Append(msg);
        return true;
    }
    plGenRefMsg* pRefMsg = plGenRefMsg::ConvertNoRef(msg);
    if (pRefMsg )
    {
        if( pRefMsg->GetContext() & (plRefMsg::kOnCreate | plRefMsg::kOnRequest) )
        {
            if (pRefMsg->fType == kRefBrain)
            {
                plCameraBrain1* pBrain = plCameraBrain1::ConvertNoRef(pRefMsg->GetRef());
                if (pBrain)
                {
                    pBrain->SetCamera(this);
                    fBrain = pBrain;
                    if (fSubObj)
                        fBrain->SetSubject(fSubObj);
                }
            }
            else
            if (pRefMsg->fType == kRefCallbackMsg && fMessageQueue[pRefMsg->fWhich] != nil)
            {
                
                plgDispatch::MsgSend(fMessageQueue[pRefMsg->fWhich]);
                fMessageQueue[pRefMsg->fWhich] = nil;
            }
        }
        else if( pRefMsg->GetContext() & (plRefMsg::kOnDestroy | plRefMsg::kOnRemove) )
        {
            plCameraBrain1* pBrain = (plCameraBrain1*)(pRefMsg->GetRef());
            if (fBrain == pBrain)
                fBrain = nil;
        }
        return true;
     }
    return plSingleModifier::MsgReceive(msg);
}
bool plCameraModifier1::GetFaded()
{
    if (GetBrain())
        return GetBrain()->GetFaded();
    return false;
}
bool plCameraModifier1::SetFaded(bool b)
{
    if (GetBrain())
        return GetBrain()->SetFaded(b);
    return false;
}