Skip to content

Commit

Permalink
Final touches to assignment submission
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisonv789 committed Apr 25, 2022
1 parent 5f6ded5 commit 859e327
Show file tree
Hide file tree
Showing 14 changed files with 354 additions and 26 deletions.
Binary file modified A2_Goals/Content/Blueprints/BP_Ship.uasset
Binary file not shown.
35 changes: 21 additions & 14 deletions A2_Goals/Source/A2_Goals/Private/Agents/Ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ AShip::AShip()
// Set this actor to call Tick() every frame.
PrimaryActorTick.bCanEverTick = true;
MoveSpeed = 100;
Tolerance = 1;
Tolerance = 5;
MovementDirection = FVector::ZeroVector;

// Set the default idles
Expand Down Expand Up @@ -439,8 +439,7 @@ void AShip::OnActionTick(float deltaTime)
// If we fail the action, change to the IDLE state and report that we abort
if (!isActionSuccessful)
{
ActionStateMachine->ChangeState(IDLE);
UE_LOG(LogTemp, Warning, TEXT("%s - Plan Aborted"), *GetName());
// Abort the plan
OnPlanAborted(currentAction);
}
}
Expand Down Expand Up @@ -468,6 +467,7 @@ void AShip::OnActionExit()

}


void AShip::OnBacktrackEnter()
{

Expand All @@ -486,7 +486,7 @@ void AShip::OnBacktrackTick(float deltaTime)
direction.Normalize();

// Add the direction to the current position (multiplied by a small multiple)
currentPosition += direction * deltaTime * MoveSpeed * 0.2;
currentPosition += direction * deltaTime * MoveSpeed * BacktrackSpeed;
SetActorLocation(currentPosition);

// Update the movement direction (to the reverse of it to look like its reversing)
Expand All @@ -507,6 +507,9 @@ void AShip::OnBacktrackTick(float deltaTime)
YPos = PrevYPos;
}

// Turn off requiring gold for replanning
LookForGold = false;

// Subtract a morale
Morale--;

Expand Down Expand Up @@ -606,19 +609,13 @@ TMap<FString, bool> AShip::GetGoalState()
}


void AShip::OnPlanFailed(TMap<FString, bool> failedGoalState)
{

}


void AShip::OnPlanAborted(GOAPAction* failedAction)
void AShip::OnPlanAborted(GOAPAction* failedAction) const
{

ActionStateMachine->ChangeState(IDLE);
UE_LOG(LogTemp, Warning, TEXT("%s - Plan Aborted"), *GetName());
}


// Called every frame
void AShip::Tick(float deltaTime)
{
Super::Tick(deltaTime);
Expand Down Expand Up @@ -680,6 +677,7 @@ FString AShip::GetShipName() const
return FString::Printf(TEXT("Ship #%02d: %s"), ShipNumber + 1, ToCStr(name));
}


EAgentState AShip::GetAgentState() const
{
return ActionStateMachine->GetCurrentState();
Expand All @@ -696,30 +694,35 @@ bool AShip::IsMoraleReached() const
return Morale > TargetMorale;
}


void AShip::DepositFruit(int num)
{
NumFruit -= num;
Level->TotalFruitCollected += num;
}


void AShip::DepositStone(int num)
{
NumStone -= num;
Level->TotalStoneCollected += num;
}


void AShip::DepositWood(int num)
{
NumWood -= num;
Level->TotalWoodCollected += num;
}


void AShip::DepositRum(int num)
{
NumMerchant -= num;
Level->TotalRumCollected += num;
}


void AShip::NotifyActorBeginOverlap(AActor* otherActor)
{
Super::NotifyActorBeginOverlap(otherActor);
Expand All @@ -739,6 +742,7 @@ void AShip::NotifyActorBeginOverlap(AActor* otherActor)
}
}


void AShip::NotifyActorEndOverlap(AActor* otherActor)
{
Super::NotifyActorEndOverlap(otherActor);
Expand All @@ -751,6 +755,7 @@ void AShip::NotifyActorEndOverlap(AActor* otherActor)
}
}


void AShip::CollectGold(AGold* gold)
{
Morale = 200;
Expand All @@ -759,13 +764,15 @@ void AShip::CollectGold(AGold* gold)
LookForGold = false;
}


void AShip::Track()
{
Level->TrackAgent(this);
IsTracked = true;
}


bool AShip::IsMerchant() const
{
return ResourceType == MERCHANT_RESOURCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CollectResourceAction : public GOAPAction
const int ResourceToGather = 50;

// How long does it take to gather treasure?
const float TimeToCollect = 0.2f;
const float TimeToCollect = 1.0f;

// How much resource has been gathered so far?
int ResourceGathered;
Expand Down
2 changes: 1 addition & 1 deletion A2_Goals/Source/A2_Goals/Public/Actions/CollectRumAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CollectRumAction : public GOAPAction
const int RumToCollect = 10;

// How long does it take to gather rum?
const float TimeToCollect = 0.2f;
const float TimeToCollect = 1.0f;

// How much rum has been gathered so far?
int RumGathered;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CollectTreasureAction : public GOAPAction
const int TreasureToGather = 1;

// How long does it take to gather treasure?
const float TimeToCollect = 0.2;
const float TimeToCollect = 1.0f;

// How many treasure have been gathered so far?
int TreasureGathered;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DepositResourceAction : public GOAPAction
int ResourcesToDeposit = 50;

// How long does it take to deposit treasure?
const float TimeToDeposit = 0.1f;
const float TimeToDeposit = 0.5f;

// How much resource has been deposited so far?
int ResourcesDeposited;
Expand Down
12 changes: 5 additions & 7 deletions A2_Goals/Source/A2_Goals/Public/Agents/Ship.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class A2_GOALS_API AShip : public AActor
UPROPERTY(EditAnywhere, Category = "Stats")
int RumThreshold = 1;

// The speed multiplier applied on the ship when reversing
UPROPERTY(EditAnywhere, Category = "Stats")
float BacktrackSpeed = 0.2;

// The previous X position before the current one
int PrevXPos;

Expand Down Expand Up @@ -268,17 +272,11 @@ class A2_GOALS_API AShip : public AActor
*/
TMap<FString, bool> GetGoalState ();

/**
* @brief A plan was unable to be found. Likely to idle for a bit
* @param failedGoalState The goal state mapping
*/
void OnPlanFailed (TMap<FString, bool> failedGoalState);

/**
* @brief A plan was aborted midway through an action
* @param failedAction The action that failed to execute
*/
void OnPlanAborted (GOAPAction* failedAction);
void OnPlanAborted (GOAPAction* failedAction) const;

/**
* @brief Called when an actor overlaps another actor
Expand Down
1 change: 0 additions & 1 deletion A2_Goals/Source/A2_Goals/Public/World/GridNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "CoreMinimal.h"
#include "GridType.h"
#include "Items/ResourceActor.h"

/**
* Stores information about a specific GridNode in the world
Expand Down
Loading

0 comments on commit 859e327

Please sign in to comment.