예제 #1
0
//------------------------------------------------------------------------
bool CVehicleSeatGroup::IsGroupEmpty()
{
	const TVehicleSeatVector::const_iterator seatsEnd = m_seats.end();
	for (TVehicleSeatVector::const_iterator ite = m_seats.begin(); ite != seatsEnd; ++ite)
	{
		CVehicleSeat* pSeat = *ite;
		if (!pSeat->IsFree(NULL))
			return false;
	}

	return true;
}
예제 #2
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 );
		}
	}
}
//------------------------------------------------------------------------
bool CVehicleViewFirstPerson::Init(IVehicleSeat* pISeat, const CVehicleParams& table)
{
	CVehicleSeat* pSeat = static_cast<CVehicleSeat*>(pISeat);

	if (!CVehicleViewBase::Init(pSeat, table))
		return false;

	if (CVehicleParams paramsTable = table.findChild(m_name))
	{	
		paramsTable.getAttr("offset", m_offset);
		paramsTable.getAttr("hidePlayer", m_hidePlayer);
		paramsTable.getAttr("hideVehicle", m_hideVehicle);
		paramsTable.getAttr("relativeToHorizon", m_relToHorizon);
		paramsTable.getAttr("followSpeed", m_speedRot);
		
		float viewFov;
		if(paramsTable.getAttr("fov", viewFov))
		{
			m_fov = DEG2RAD(viewFov);
		}

		m_sCharacterBoneName = paramsTable.getAttr("characterBone");
		string helperName = paramsTable.getAttr("helper");
	
		if (!helperName.empty())
		{ 
			if (helperName != "auto")
			{ 
				m_pHelper = m_pVehicle->GetHelper(helperName);
			}
			else 
			{
				// create a helper with default viewpos above sithelper    
				const string& seatName = pSeat->GetName();     
				helperName = seatName + string("_ghostview_pos");

				if (IVehicleHelper* pSitHelper = pSeat->GetSitHelper())
				{
					Matrix34 tm;
					pSitHelper->GetVehicleTM(tm);
					Vec3 pos = tm.GetTranslation() + Vec3(0,0,0.625); // player eye height

					m_pVehicle->AddHelper(helperName.c_str(), pos, tm.GetColumn1(), pSitHelper->GetParentPart());
					m_pHelper = m_pVehicle->GetHelper(helperName.c_str());
				}
			}

			if (!m_pHelper)
				GameWarning("[%s, seat %s]: view helper %s not found, using character head", m_pVehicle->GetEntity()->GetName(), m_pSeat->GetName().c_str(), helperName.c_str());
		}    

		string frame = paramsTable.getAttr("frameObject");
		if (!frame.empty())
		{
			// todo: aspect ratio?
			if (strstr(frame, ".cgf"))
				m_frameSlot = m_pVehicle->GetEntity()->LoadGeometry(-1, frame);
			else
				m_frameSlot = m_pVehicle->GetEntity()->LoadCharacter(-1, frame);

			if (m_frameSlot != -1)
			{
				m_pVehicle->GetEntity()->SetSlotFlags(m_frameSlot, m_pVehicle->GetEntity()->GetSlotFlags(m_frameSlot) &~ (ENTITY_SLOT_RENDER|ENTITY_SLOT_RENDER_NEAREST));    

				if (m_pHelper)
				{
					Matrix34 tm;
					m_pHelper->GetVehicleTM(tm);
					m_invFrame = tm.GetInverted();
					m_pVehicle->GetEntity()->SetSlotLocalTM(m_frameSlot, tm);
				}
			}
		}

		paramsTable.getAttr("frameObjectOffset", m_frameObjectOffset);
	}

	if (m_hideVehicle)
		m_hidePlayer = true;

	if (m_speedRot==0.f)
	{
		m_speedRot = 4.0f;

		if (IVehicleMovement* pMovement = m_pVehicle->GetMovement())
		{
			if (pMovement->GetMovementType() == IVehicleMovement::eVMT_Air)
			{
				m_speedRot *= 2.0f;
			}
		}
	}


	Reset();
	return true;
}
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;
	}
}