diff --git a/Content/EnemyPawn_BP.uasset b/Content/EnemyPawn_BP.uasset index a4d1d94..8cf1cb0 100755 Binary files a/Content/EnemyPawn_BP.uasset and b/Content/EnemyPawn_BP.uasset differ diff --git a/Content/EnemySpawner_BP.uasset b/Content/EnemySpawner_BP.uasset index f28ad43..1aae810 100755 Binary files a/Content/EnemySpawner_BP.uasset and b/Content/EnemySpawner_BP.uasset differ diff --git a/Source/PresidentsBrigade/BasePawn.cpp b/Source/PresidentsBrigade/BasePawn.cpp index 6837128..33ebcc2 100755 --- a/Source/PresidentsBrigade/BasePawn.cpp +++ b/Source/PresidentsBrigade/BasePawn.cpp @@ -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 diff --git a/Source/PresidentsBrigade/BasePawn.h b/Source/PresidentsBrigade/BasePawn.h index 4f4a392..c2ef979 100755 --- a/Source/PresidentsBrigade/BasePawn.h +++ b/Source/PresidentsBrigade/BasePawn.h @@ -75,6 +75,8 @@ protected: const FHitResult& hit ); + virtual void handle_hit_internal(AActor* other_actor); + virtual UPawnMovementComponent* GetMovementComponent() const; UPROPERTY(EditAnywhere, Category="Player") diff --git a/Source/PresidentsBrigade/EnemyAIController.cpp b/Source/PresidentsBrigade/EnemyAIController.cpp index c33eefa..2ccc8d7 100755 --- a/Source/PresidentsBrigade/EnemyAIController.cpp +++ b/Source/PresidentsBrigade/EnemyAIController.cpp @@ -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(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; diff --git a/Source/PresidentsBrigade/EnemyAIController.h b/Source/PresidentsBrigade/EnemyAIController.h index b6d08b1..dcdd0ea 100755 --- a/Source/PresidentsBrigade/EnemyAIController.h +++ b/Source/PresidentsBrigade/EnemyAIController.h @@ -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; }; diff --git a/Source/PresidentsBrigade/EnemyPawn.cpp b/Source/PresidentsBrigade/EnemyPawn.cpp index b70c808..08670cd 100755 --- a/Source/PresidentsBrigade/EnemyPawn.cpp +++ b/Source/PresidentsBrigade/EnemyPawn.cpp @@ -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(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(); + } +} diff --git a/Source/PresidentsBrigade/EnemyPawn.h b/Source/PresidentsBrigade/EnemyPawn.h index f25072d..d2db373 100755 --- a/Source/PresidentsBrigade/EnemyPawn.h +++ b/Source/PresidentsBrigade/EnemyPawn.h @@ -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. diff --git a/Source/PresidentsBrigade/PresidentsBrigadeGameModeBase.cpp b/Source/PresidentsBrigade/PresidentsBrigadeGameModeBase.cpp index 0425168..96163d3 100755 --- a/Source/PresidentsBrigade/PresidentsBrigadeGameModeBase.cpp +++ b/Source/PresidentsBrigade/PresidentsBrigadeGameModeBase.cpp @@ -8,3 +8,7 @@ APresidentsBrigadeGameModeBase::APresidentsBrigadeGameModeBase() { } +void APresidentsBrigadeGameModeBase::PreInitializeComponents() +{ + Super::PreInitializeComponents(); +} diff --git a/Source/PresidentsBrigade/PresidentsBrigadeGameModeBase.h b/Source/PresidentsBrigade/PresidentsBrigadeGameModeBase.h index f86f369..4753dfa 100755 --- a/Source/PresidentsBrigade/PresidentsBrigadeGameModeBase.h +++ b/Source/PresidentsBrigade/PresidentsBrigadeGameModeBase.h @@ -16,4 +16,6 @@ class PRESIDENTSBRIGADE_API APresidentsBrigadeGameModeBase : public AGameModeBas public: APresidentsBrigadeGameModeBase(); + + virtual void PreInitializeComponents() override; }; diff --git a/todo.txt b/todo.txt index 73ae9ad..09361a1 100644 --- a/todo.txt +++ b/todo.txt @@ -19,6 +19,8 @@ xAdd art x Car models x Street shader xAdd HUD UI for single player. +Make boosting fun + - Enemy car ricochets after hitting player/president Add sounds Add juice Add muzzle on shoot