/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Data/Samples/RTS/CppSource/RTSPlugin/AI/MoveToPositionUtility.cpp
52 строки
2 KB
Jan Krassnigg
C++ Project Generation now also builds stand-alone game exe (#1465)
30 дек 2024, 12:59
Не верифицирован
30 дек 2024, 12:59
d369e9b
Код
Авторство
О чём код?
#include <RTSPlugin/RTSPluginPCH.h> #include <RTSPlugin/AI/MoveToPositionUtility.h> #include <RTSPlugin/Components/UnitComponent.h> #include <RTSPlugin/GameState/RTSGameState.h> void RtsMoveToPositionAiUtility::Activate(ezGameObject* pOwnerObject, ezComponent* pOwnerComponent) {} void RtsMoveToPositionAiUtility::Deactivate(ezGameObject* pOwnerObject, ezComponent* pOwnerComponent) { RtsUnitComponent* pUnit = static_cast<RtsUnitComponent*>(pOwnerComponent); RtsMsgStopNavigation msg; pOwnerObject->SendMessage(msg); } void RtsMoveToPositionAiUtility::Execute(ezGameObject* pOwnerObject, ezComponent* pOwnerComponent, ezTime now) { RtsUnitComponent* pUnit = static_cast<RtsUnitComponent*>(pOwnerComponent); RtsMsgNavigateTo msg; msg.m_vTargetPosition = pUnit->m_vAssignedPosition; pOwnerObject->SendMessage(msg); // shoot at close by enemies pUnit->AttackClosestEnemey(7.0f, 10.0f); } double RtsMoveToPositionAiUtility::ComputePriority(ezGameObject* pOwnerObject, ezComponent* pOwnerComponent) const { RtsUnitComponent* pUnit = static_cast<RtsUnitComponent*>(pOwnerComponent); if (pUnit->m_UnitMode == RtsUnitMode::MoveToPosition) { // always follow the move command with high priority return 1000; } if (pUnit->m_UnitMode == RtsUnitMode::GuardLocation) { // return to assigned position when strayed too far from it float fDistSqr = (pOwnerObject->GetGlobalPosition().GetAsVec2() - pUnit->m_vAssignedPosition).GetLengthSquared(); // don't participate at all, when very close to the target // otherwise this often gets activated and executes the shoot at action if (fDistSqr > ezMath::Square(3.0f)) return fDistSqr; } return 0; }