120 lines
3.0 KiB
C++
120 lines
3.0 KiB
C++
// FILE : TaskSearchInHeli.h
|
|
// PURPOSE : Subtask of search used while in a heli
|
|
|
|
// File header
|
|
#include "Task/Combat/Subtasks/TaskSearchInHeli.h"
|
|
|
|
// Game headers
|
|
#include "Peds/Ped.h"
|
|
#include "task/Vehicle/TaskCar.h"
|
|
#include "vehicleAi/VehicleIntelligence.h"
|
|
#include "vehicleAi/task/TaskVehicleGoToHelicopter.h"
|
|
#include "Vehicles/heli.h"
|
|
#include "Vehicles/vehicle.h"
|
|
|
|
AI_OPTIMISATIONS()
|
|
|
|
//=========================================================================
|
|
// CTaskSearchInHeli
|
|
//=========================================================================
|
|
|
|
//TODO: To make this task more general, it should go to the position before launching the search behavior.
|
|
// However, this task is currently only launched from CTaskSearch, which takes care of going to the position.
|
|
|
|
CTaskSearchInHeli::Tunables CTaskSearchInHeli::sm_Tunables;
|
|
IMPLEMENT_COMBAT_TASK_TUNABLES(CTaskSearchInHeli, 0x9410823d);
|
|
|
|
CTaskSearchInHeli::CTaskSearchInHeli(const Params& rParams)
|
|
: CTaskSearchInVehicleBase(rParams)
|
|
{
|
|
SetInternalTaskType(CTaskTypes::TASK_SEARCH_IN_HELI);
|
|
}
|
|
|
|
CTaskSearchInHeli::~CTaskSearchInHeli()
|
|
{
|
|
}
|
|
|
|
#if !__FINAL
|
|
const char* CTaskSearchInHeli::GetStaticStateName(s32 iState)
|
|
{
|
|
Assert(iState >= State_Start && iState <= State_Finish);
|
|
static const char* aStateNames[] =
|
|
{
|
|
"State_Start",
|
|
"State_Search",
|
|
"State_Finish"
|
|
};
|
|
|
|
return aStateNames[iState];
|
|
}
|
|
#endif
|
|
|
|
CTask::FSM_Return CTaskSearchInHeli::UpdateFSM(const s32 iState, const FSM_Event iEvent)
|
|
{
|
|
FSM_Begin
|
|
|
|
FSM_State(State_Start)
|
|
FSM_OnUpdate
|
|
return Start_OnUpdate();
|
|
|
|
FSM_State(State_Search)
|
|
FSM_OnEnter
|
|
Search_OnEnter();
|
|
FSM_OnUpdate
|
|
return Search_OnUpdate();
|
|
|
|
FSM_State(State_Finish)
|
|
FSM_OnUpdate
|
|
return FSM_Quit;
|
|
|
|
FSM_End
|
|
}
|
|
|
|
CTask::FSM_Return CTaskSearchInHeli::Start_OnUpdate()
|
|
{
|
|
//Search for the target.
|
|
SetState(State_Search);
|
|
|
|
return FSM_Continue;
|
|
}
|
|
|
|
void CTaskSearchInHeli::Search_OnEnter()
|
|
{
|
|
//Calculate the flee offset.
|
|
Vector3 vFleeOffset(VEC3_ZERO);
|
|
vFleeOffset.x = ANGLE_TO_VECTOR_X(RtoD * m_Params.m_fDirection);
|
|
vFleeOffset.y = ANGLE_TO_VECTOR_Y(RtoD * m_Params.m_fDirection);
|
|
vFleeOffset.Scale(-sm_Tunables.m_FleeOffset);
|
|
|
|
//Calculate the flee position.
|
|
Vector3 vFleePosition = VEC3V_TO_VECTOR3(m_Params.m_vPosition) + vFleeOffset;
|
|
|
|
//Create the params.
|
|
sVehicleMissionParams params;
|
|
params.SetTargetPosition(vFleePosition);
|
|
params.m_iDrivingFlags = DF_DontTerminateTaskWhenAchieved|DF_AvoidTargetCoors;
|
|
params.m_fTargetArriveDist = 0.0f;
|
|
params.m_fCruiseSpeed = sm_Tunables.m_CruiseSpeed;
|
|
|
|
//Create the vehicle task.
|
|
CTask* pVehicleTask = rage_new CTaskVehicleGoToHelicopter(params, 0, -1.0f, sm_Tunables.m_MinHeightAboveTerrain);
|
|
|
|
//Create the task.
|
|
CTask* pTask = rage_new CTaskControlVehicle(GetVehicle(), pVehicleTask);
|
|
|
|
//Start the task.
|
|
SetNewTask(pTask);
|
|
}
|
|
|
|
CTask::FSM_Return CTaskSearchInHeli::Search_OnUpdate()
|
|
{
|
|
//Check if the sub-task has finished.
|
|
if(GetIsFlagSet(aiTaskFlags::SubTaskFinished))
|
|
{
|
|
//Finish the task.
|
|
SetState(State_Finish);
|
|
}
|
|
|
|
return FSM_Continue;
|
|
}
|