Experimental commit -- no clue what's here

This commit is contained in:
Sara Montecino 2024-01-02 19:40:23 -08:00
parent 7ba7379699
commit 4c88c7da5c
11 changed files with 71 additions and 7 deletions

Binary file not shown.

Binary file not shown.

View File

@ -71,6 +71,13 @@ void ABasePawn::handle_hit(
// Update current health. // Update current health.
current_health -= damage_class_map[other_class]; 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 UPawnMovementComponent* ABasePawn::GetMovementComponent() const

View File

@ -75,6 +75,8 @@ protected:
const FHitResult& hit const FHitResult& hit
); );
virtual void handle_hit_internal(AActor* other_actor);
virtual UPawnMovementComponent* GetMovementComponent() const; virtual UPawnMovementComponent* GetMovementComponent() const;
UPROPERTY(EditAnywhere, Category="Player") UPROPERTY(EditAnywhere, Category="Player")

View File

@ -4,6 +4,7 @@
#include "EnemyAIController.h" #include "EnemyAIController.h"
#include "EngineUtils.h" #include "EngineUtils.h"
#include "DrawDebugHelpers.h" #include "DrawDebugHelpers.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Util.h" #include "Util.h"
#define LogInfo(Msg) Util::log_info(TEXT("AEnemyIController"), Msg) #define LogInfo(Msg) Util::log_info(TEXT("AEnemyIController"), Msg)
@ -17,7 +18,7 @@ void AEnemyAIController::Tick(float delta_time)
{ {
case state_t::init: case state_t::init:
president = get_president(); president = get_president();
if (president) if (UKismetSystemLibrary::IsValid(president))
{ {
current_state = state_t::wait; current_state = state_t::wait;
} }
@ -31,7 +32,7 @@ void AEnemyAIController::Tick(float delta_time)
} }
break; break;
case state_t::target: case state_t::target:
if (!president) if (!UKismetSystemLibrary::IsValid(president))
{ {
current_state = state_t::init; current_state = state_t::init;
} }
@ -39,26 +40,28 @@ void AEnemyAIController::Tick(float delta_time)
{ {
FVector target_location = president->get_location(); FVector target_location = president->get_location();
const ABasePawn* local_pawn = Cast<ABasePawn>(GetPawn()); const ABasePawn* local_pawn = Cast<ABasePawn>(GetPawn());
if (local_pawn) if (UKismetSystemLibrary::IsValid(local_pawn))
{ {
FVector current_location = local_pawn->get_location(); FVector current_location = local_pawn->get_location();
starting_location = current_location;
FVector between = target_location - current_location; FVector between = target_location - current_location;
between = FVector(between.X, between.Y, 0); between = FVector(between.X, between.Y, 0);
between.Normalize(); between.Normalize();
FVector extended = (between * overshoot_multiplier) + target_location; FVector extended = (between * overshoot_multiplier) + target_location;
MoveToLocation(extended); MoveToLocation(extended);
current_state = state_t::moving; current_state = state_t::moving_attack;
} }
else else
{ {
// This will be cleaned up shortly. // This will be cleaned up shortly.
current_state = state_t::dead; current_state = state_t::dead;
} }
} }
break; break;
case state_t::moving: case state_t::moving_attack:
case state_t::moving_retreat:
if (move_completed) if (move_completed)
{ {
move_completed = false; 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) void AEnemyAIController::OnMoveCompleted(FAIRequestID request_id, const FPathFollowingResult& result)
{ {
move_completed = true; move_completed = true;

View File

@ -18,6 +18,7 @@ class PRESIDENTSBRIGADE_API AEnemyAIController : public AAIController
public: public:
virtual void Tick(float delta_time) override; virtual void Tick(float delta_time) override;
void redirect_target();
protected: protected:
virtual void OnMoveCompleted(FAIRequestID request_id, const FPathFollowingResult& result) override; virtual void OnMoveCompleted(FAIRequestID request_id, const FPathFollowingResult& result) override;
@ -42,7 +43,8 @@ private:
init, init,
wait, wait,
target, target,
moving, moving_attack,
moving_retreat,
dead dead
}; };
@ -67,4 +69,9 @@ private:
* Time spent in waiting. * Time spent in waiting.
*/ */
float waiting_time; float waiting_time;
/**
* Starting location.
*/
FVector starting_location;
}; };

View File

@ -3,6 +3,11 @@
#include "EnemyPawn.h" #include "EnemyPawn.h"
#include "Pickup.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() void AEnemyPawn::BeginPlay()
{ {
@ -33,3 +38,25 @@ void AEnemyPawn::destroy_self()
ABasePawn::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();
}
}

View File

@ -18,6 +18,7 @@ class PRESIDENTSBRIGADE_API AEnemyPawn : public ABasePawn
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
virtual void destroy_self() override; virtual void destroy_self() override;
virtual void handle_hit_internal(AActor* other_actor) override;
/** /**
* Pickup class to spawn on death. * Pickup class to spawn on death.

View File

@ -8,3 +8,7 @@ APresidentsBrigadeGameModeBase::APresidentsBrigadeGameModeBase()
{ {
} }
void APresidentsBrigadeGameModeBase::PreInitializeComponents()
{
Super::PreInitializeComponents();
}

View File

@ -16,4 +16,6 @@ class PRESIDENTSBRIGADE_API APresidentsBrigadeGameModeBase : public AGameModeBas
public: public:
APresidentsBrigadeGameModeBase(); APresidentsBrigadeGameModeBase();
virtual void PreInitializeComponents() override;
}; };

View File

@ -19,6 +19,8 @@ xAdd art
x Car models x Car models
x Street shader x Street shader
xAdd HUD UI for single player. xAdd HUD UI for single player.
Make boosting fun
- Enemy car ricochets after hitting player/president
Add sounds Add sounds
Add juice Add juice
Add muzzle on shoot Add muzzle on shoot