presidents-brigade/Source/PresidentsBrigade/EnemyPawn.cpp
2024-01-02 19:40:23 -08:00

63 lines
1.3 KiB
C++
Executable File

// Fill out your copyright notice in the Description page of Project Settings.
#include "EnemyPawn.h"
#include "Pickup.h"
#include "Util.h"
#include "EnemyAIController.h"
#define LogInfo(Msg) Util::log_info(TEXT("EnemyPawn"), Msg)
#define LogError(Msg) Util::log_error(TEXT("EnemyPawn"), Msg)
void AEnemyPawn::BeginPlay()
{
Super::BeginPlay();
/*
* Initialize random stream.
*/
random.Initialize(FMath::Rand());
}
void AEnemyPawn::destroy_self()
{
const bool drop_pickup = random.GetFraction() > .5;
if (drop_pickup)
{
FVector location = get_location() + FVector(100, 100, 0);
FActorSpawnParameters spawnParameters;
spawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
APickup* pickup = GetWorld()->SpawnActor<APickup>(
pickup_class,
location,
FRotator(0,0,0),
spawnParameters
);
}
ABasePawn::destroy_self();
}
void AEnemyPawn::handle_hit_internal(AActor* other)
{
const AEnemyPawn* is_enemy = Cast<AEnemyPawn>(other);
if (is_enemy)
{
return;
}
const ABasePawn* other_pawn = Cast<ABasePawn>(other);
if (other_pawn)
{
AEnemyAIController* controller = Cast<AEnemyAIController>(GetController());
if (!controller)
{
LogError("EnemyAIController not used!");
return;
}
controller->redirect_target();
}
}