// 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( pickup_class, location, FRotator(0,0,0), spawnParameters ); } ABasePawn::destroy_self(); } void AEnemyPawn::handle_hit_internal(AActor* other) { const AEnemyPawn* is_enemy = Cast(other); if (is_enemy) { return; } const ABasePawn* other_pawn = Cast(other); if (other_pawn) { AEnemyAIController* controller = Cast(GetController()); if (!controller) { LogError("EnemyAIController not used!"); return; } controller->redirect_target(); } }