void AWalkerAIController::TryPauseMovement(const bool bItWasRunOver) { if ((Status != EWalkerStatus::Paused) && (Status != EWalkerStatus::RunOver)) { auto MoveRequestID = GetCurrentMoveRequestID(); if (MoveRequestID == FAIRequestID()) { // equals invalid request. LOG_AI_WALKER(Error, "has invalid move ID"); } else { if (!PauseMove(MoveRequestID)) { LOG_AI_WALKER(Error, "is unable to pause movement"); } else { LOG_AI_WALKER(Log, "paused"); Status = (bItWasRunOver ? EWalkerStatus::RunOver : EWalkerStatus::Paused); } } } }
void AWalkerAIController::TryResumeMovement() { if (Status != EWalkerStatus::Moving) { auto MoveRequestID = GetCurrentMoveRequestID(); if (MoveRequestID == FAIRequestID()) { // equals invalid request. LOG_AI_WALKER(Error, "has invalid move ID"); } else { if (!ResumeMove(MoveRequestID)) { LOG_AI_WALKER(Error, "is unable to resume movement"); } else { LOG_AI_WALKER(Log, "resuming movement"); Status = EWalkerStatus::Moving; } } } }
void AWalkerAIController::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); if (Status != EWalkerStatus::RunOver) { switch (GetMoveStatus()) { case EPathFollowingStatus::Idle: case EPathFollowingStatus::Waiting: LOG_AI_WALKER(Warning, "is stuck!"); Status = EWalkerStatus::Stuck; break; case EPathFollowingStatus::Paused: LOG_AI_WALKER(Log, "is paused"); TryResumeMovement(); break; }; } }
void AWalkerAIController::OnPawnTookDamage( AActor *DamagedActor, float Damage, const UDamageType *DamageType, AController *InstigatedBy, AActor *DamageCauser) { LOG_AI_WALKER(Warning, "has been run over"); constexpr bool bItWasRunOver = true; TryPauseMovement(bItWasRunOver); Status = EWalkerStatus::RunOver; }
void AWalkerAIController::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); TimeInState+=DeltaSeconds; if (Status != EWalkerStatus::RunOver) { switch (GetMoveStatus()) { default: break; case EPathFollowingStatus::Idle: //case EPathFollowingStatus::Waiting: //<-- incomplete path LOG_AI_WALKER(Warning, "is stuck!"); ChangeStatus(EWalkerStatus::Stuck); break; case EPathFollowingStatus::Paused: if(TimeInState>WALKER_MAX_TIME_PAUSED){ LOG_AI_WALKER(Log, "is paused, trying resume movement"); TryResumeMovement(); } break; }; } }