/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Data/Samples/RTS/CppSource/RTSPlugin/AI/GuardLocationUtility.cpp
44 строки
1 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/GuardLocationUtility.h> #include <RTSPlugin/Components/UnitComponent.h> void RtsGuardLocationAiUtility::Activate(ezGameObject* pOwnerObject, ezComponent* pOwnerComponent) {} void RtsGuardLocationAiUtility::Deactivate(ezGameObject* pOwnerObject, ezComponent* pOwnerComponent) {} void RtsGuardLocationAiUtility::Execute(ezGameObject* pOwnerObject, ezComponent* pOwnerComponent, ezTime now) { RtsUnitComponent* pUnit = static_cast<RtsUnitComponent*>(pOwnerComponent); // shoot at close by enemies ezGameObject* pEnemy = pUnit->AttackClosestEnemey(7.0f, 10.0f); if (pEnemy) { ezVec3 vDiff = pEnemy->GetGlobalPosition() - pOwnerObject->GetGlobalPosition(); if (vDiff.GetLengthSquared() > ezMath::Square(5.0f)) { vDiff.Normalize(); // harass the enemy when it moves away RtsMsgNavigateTo msg; msg.m_vTargetPosition = pOwnerObject->GetGlobalPosition().GetAsVec2() + vDiff.GetAsVec2(); pOwnerObject->SendMessage(msg); } } } double RtsGuardLocationAiUtility::ComputePriority(ezGameObject* pOwnerObject, ezComponent* pOwnerComponent) const { RtsUnitComponent* pUnit = static_cast<RtsUnitComponent*>(pOwnerComponent); if (pUnit->m_UnitMode == RtsUnitMode::GuardLocation) { return 10.0f; } return 0; }