Experimental commit -- no clue what's here
This commit is contained in:
parent
7ba7379699
commit
4c88c7da5c
Binary file not shown.
Binary file not shown.
@ -71,6 +71,13 @@ void ABasePawn::handle_hit(
|
||||
// Update current health.
|
||||
current_health -= damage_class_map[other_class];
|
||||
}
|
||||
|
||||
handle_hit_internal(other_actor);
|
||||
}
|
||||
|
||||
void ABasePawn::handle_hit_internal(AActor* other_actor)
|
||||
{
|
||||
// do nothing by default;
|
||||
}
|
||||
|
||||
UPawnMovementComponent* ABasePawn::GetMovementComponent() const
|
||||
|
@ -75,6 +75,8 @@ protected:
|
||||
const FHitResult& hit
|
||||
);
|
||||
|
||||
virtual void handle_hit_internal(AActor* other_actor);
|
||||
|
||||
virtual UPawnMovementComponent* GetMovementComponent() const;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="Player")
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "EnemyAIController.h"
|
||||
#include "EngineUtils.h"
|
||||
#include "DrawDebugHelpers.h"
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
#include "Util.h"
|
||||
|
||||
#define LogInfo(Msg) Util::log_info(TEXT("AEnemyIController"), Msg)
|
||||
@ -17,7 +18,7 @@ void AEnemyAIController::Tick(float delta_time)
|
||||
{
|
||||
case state_t::init:
|
||||
president = get_president();
|
||||
if (president)
|
||||
if (UKismetSystemLibrary::IsValid(president))
|
||||
{
|
||||
current_state = state_t::wait;
|
||||
}
|
||||
@ -31,7 +32,7 @@ void AEnemyAIController::Tick(float delta_time)
|
||||
}
|
||||
break;
|
||||
case state_t::target:
|
||||
if (!president)
|
||||
if (!UKismetSystemLibrary::IsValid(president))
|
||||
{
|
||||
current_state = state_t::init;
|
||||
}
|
||||
@ -39,26 +40,28 @@ void AEnemyAIController::Tick(float delta_time)
|
||||
{
|
||||
FVector target_location = president->get_location();
|
||||
const ABasePawn* local_pawn = Cast<ABasePawn>(GetPawn());
|
||||
if (local_pawn)
|
||||
if (UKismetSystemLibrary::IsValid(local_pawn))
|
||||
{
|
||||
FVector current_location = local_pawn->get_location();
|
||||
starting_location = current_location;
|
||||
|
||||
FVector between = target_location - current_location;
|
||||
between = FVector(between.X, between.Y, 0);
|
||||
between.Normalize();
|
||||
FVector extended = (between * overshoot_multiplier) + target_location;
|
||||
|
||||
MoveToLocation(extended);
|
||||
current_state = state_t::moving;
|
||||
current_state = state_t::moving_attack;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This will be cleaned up shortly.
|
||||
current_state = state_t::dead;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case state_t::moving:
|
||||
case state_t::moving_attack:
|
||||
case state_t::moving_retreat:
|
||||
if (move_completed)
|
||||
{
|
||||
move_completed = false;
|
||||
@ -73,6 +76,15 @@ void AEnemyAIController::Tick(float delta_time)
|
||||
}
|
||||
}
|
||||
|
||||
void AEnemyAIController::redirect_target()
|
||||
{
|
||||
if (current_state == moving_attack)
|
||||
{
|
||||
MoveToLocation(starting_location);
|
||||
current_state = moving_retreat;
|
||||
}
|
||||
}
|
||||
|
||||
void AEnemyAIController::OnMoveCompleted(FAIRequestID request_id, const FPathFollowingResult& result)
|
||||
{
|
||||
move_completed = true;
|
||||
|
@ -18,6 +18,7 @@ class PRESIDENTSBRIGADE_API AEnemyAIController : public AAIController
|
||||
public:
|
||||
virtual void Tick(float delta_time) override;
|
||||
|
||||
void redirect_target();
|
||||
protected:
|
||||
virtual void OnMoveCompleted(FAIRequestID request_id, const FPathFollowingResult& result) override;
|
||||
|
||||
@ -42,7 +43,8 @@ private:
|
||||
init,
|
||||
wait,
|
||||
target,
|
||||
moving,
|
||||
moving_attack,
|
||||
moving_retreat,
|
||||
dead
|
||||
};
|
||||
|
||||
@ -67,4 +69,9 @@ private:
|
||||
* Time spent in waiting.
|
||||
*/
|
||||
float waiting_time;
|
||||
|
||||
/**
|
||||
* Starting location.
|
||||
*/
|
||||
FVector starting_location;
|
||||
};
|
||||
|
@ -3,6 +3,11 @@
|
||||
|
||||
#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()
|
||||
{
|
||||
@ -33,3 +38,25 @@ void AEnemyPawn::destroy_self()
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ class PRESIDENTSBRIGADE_API AEnemyPawn : public ABasePawn
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
virtual void destroy_self() override;
|
||||
virtual void handle_hit_internal(AActor* other_actor) override;
|
||||
|
||||
/**
|
||||
* Pickup class to spawn on death.
|
||||
|
@ -8,3 +8,7 @@ APresidentsBrigadeGameModeBase::APresidentsBrigadeGameModeBase()
|
||||
{
|
||||
}
|
||||
|
||||
void APresidentsBrigadeGameModeBase::PreInitializeComponents()
|
||||
{
|
||||
Super::PreInitializeComponents();
|
||||
}
|
||||
|
@ -16,4 +16,6 @@ class PRESIDENTSBRIGADE_API APresidentsBrigadeGameModeBase : public AGameModeBas
|
||||
|
||||
public:
|
||||
APresidentsBrigadeGameModeBase();
|
||||
|
||||
virtual void PreInitializeComponents() override;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user