Exemple #1
0
void CFlowVehicleTurret::ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo)
{
	CFlowVehicleBase::ProcessEvent(event, pActInfo); // handles eFE_SetEntityId

	if (event == eFE_Activate)
	{
		if (IsPortActive(pActInfo, eIn_Trigger))
		{
			bool bSuccess = false;

			const string seatName = GetPortString(pActInfo, eIn_Seat);
			Vec3         aimPos   = GetPortVec3(pActInfo, eIn_AimPos);

			CVehicle* pVehicle = static_cast<CVehicle*>(GetVehicle());
			if (pVehicle)
			{
				CVehicleSeat* pSeat = static_cast<CVehicleSeat*>(pVehicle->GetSeatById(pVehicle->GetSeatId(seatName)));
				if (pSeat)
				{
					TVehicleSeatActionVector &seatActions = pSeat->GetSeatActions();
					for (TVehicleSeatActionVector::iterator ite = seatActions.begin(); ite != seatActions.end(); ++ite)
					{
						IVehicleSeatAction*             pSeatAction         = ite->pSeatAction;
						CVehicleSeatActionRotateTurret* pActionRotateTurret = CAST_VEHICLEOBJECT(CVehicleSeatActionRotateTurret, pSeatAction);
						if (pActionRotateTurret)
						{
							if (!aimPos.IsZero())
							{
								pActionRotateTurret->SetAimGoal(aimPos);
							}
							bSuccess = true;
							break;
						}
					}
				}
			}
			ActivateOutput( pActInfo, eOut_Success, bSuccess );
		}
	}
}
void CFlowNode_AISequenceAction_VehicleRotateTurret::ProcessEvent(IFlowNode::EFlowEvent event, IFlowNode::SActivationInfo* pActInfo)
{
	if (!pActInfo->pEntity)
		return;

	switch(event)
	{
	case eFE_Activate:
		{
			m_actInfo = *pActInfo;
			m_stopFlowGraphNodeFromGettingUpdatedWhenSequenceActionFinishesOrCancels = true;
			m_pActionRotateTurret = NULL;

			if (IsPortActive(pActInfo, InputPort_Start))
			{
				if (const AIActionSequence::SequenceId assignedSequenceId = GetAssignedSequenceId())
				{
					gEnv->pAISystem->GetSequenceManager()->RequestActionStart(assignedSequenceId, pActInfo->myID);
					m_actInfo.pGraph->SetRegularlyUpdated(m_actInfo.myID, true);
				}
			}
		}
		break;

	case eFE_Update:
		{
			if (m_pActionRotateTurret)
			{
				float pitch, yaw;
				m_pActionRotateTurret->GetRemainingAnglesToAimGoalInDegrees(pitch, yaw);
				if (fabsf(pitch) <= m_pitchThreshold && fabs(yaw) <= m_yawThreshold)
				{
					FinishSequenceActionAndActivateOutputPort(OutputPort_Done);
				}
			}
		}
		break;
	}
}
void CFlowNode_AISequenceAction_VehicleRotateTurret::HandleSequenceEvent(AIActionSequence::SequenceEvent sequenceEvent)
{
	switch(sequenceEvent)
	{
	case AIActionSequence::StartAction:
		{
			if (!m_actInfo.pEntity)
			{
				// the entity has gone for some reason, at least make sure the action gets finished properly and the FG continues
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			assert(gEnv && gEnv->pGame && gEnv->pGame->GetIGameFramework() && gEnv->pGame->GetIGameFramework()->GetIActorSystem());
			IActor* pActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_actInfo.pEntity->GetId());

			// ensure the FG entity is an IActor
			if (!pActor)
			{
				CRY_ASSERT_MESSAGE(0, "no compatible entity was provided");
				CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s failed to enter vehicle (no compatible entity was provided)", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			// get the vehicle the actor is linked to
			IVehicle* pVehicle = pActor->GetLinkedVehicle();
			if (!pVehicle)
			{
				CRY_ASSERT_MESSAGE(0, "agent is not linked to a vehicle");
				CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s is not linked to a vehicle", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			// get the seat the actor is sitting on
			CVehicleSeat* pSeat = static_cast<CVehicleSeat*>(pVehicle->GetSeatForPassenger(m_actInfo.pEntity->GetId()));
			if (!pSeat)
			{
				CRY_ASSERT_MESSAGE(0, "agent is not sitting in the vehicle it is linked to");
				CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s is not sitting in the vehicle it is linked to", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			// scan for the seat-action that allows rotating the turret
			TVehicleSeatActionVector& seatActions = pSeat->GetSeatActions();
			for (TVehicleSeatActionVector::iterator it = seatActions.begin(); it != seatActions.end(); ++it)
			{
				IVehicleSeatAction* pSeatAction = it->pSeatAction;
				if ((m_pActionRotateTurret = CAST_VEHICLEOBJECT(CVehicleSeatActionRotateTurret, pSeatAction)))
				{
					break;
				}
			}

			// ensure the vehicle-seat provided the correct action
			if (!m_pActionRotateTurret)
			{
				CRY_ASSERT_MESSAGE(0, "a CVehicleSeatActionRotateTurret is not provided by the vehicle or someone else in the vehicle has reserved that action already.");
				CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s could not find a CVehicleSeatActionRotateTurret or that action is already reserved by someone else", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			m_pitchThreshold = GetPortFloat(&m_actInfo, InputPort_ThresholdPitch);
			m_yawThreshold = GetPortFloat(&m_actInfo, InputPort_ThresholdYaw);

			Vec3 aimPos = GetPortVec3(&m_actInfo, InputPort_AimPos);
			m_pActionRotateTurret->SetAimGoal(aimPos);
		}
		break;

	case AIActionSequence::SequenceStopped:
		{
			if (m_pActionRotateTurret)
			{
				// cancel the rotation action
				m_pActionRotateTurret->SetAimGoal(Vec3Constants<float>::fVec3_Zero);
				m_pActionRotateTurret = NULL;
			}
		}
		break;
	}
}