-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added in the action to deposit resources at the home base
- Loading branch information
1 parent
9b39d28
commit 16a2211
Showing
17 changed files
with
268 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
A2_Goals/Source/A2_Goals/Private/Actions/DepositResourceAction.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/** | ||
* FIT3094 ASSIGNMENT 2 - GOAL PLANNING | ||
* Author: Harrison Verrios | ||
*/ | ||
|
||
#include "Actions/DepositResourceAction.h" | ||
|
||
#include "Agents/Ship.h" | ||
#include "Items/ResourceActor.h" | ||
#include "World/GridNode.h" | ||
|
||
DepositResourceAction::DepositResourceAction(EGridType resourceType, int resourcesToDeposit) | ||
{ | ||
// Reset the action | ||
DepositResourceAction::Reset(); | ||
|
||
// Update the number of the resources to deposit | ||
ResourcesToDeposit = resourcesToDeposit; | ||
|
||
// Updates the resource type | ||
SetResourceType(resourceType); | ||
} | ||
|
||
|
||
DepositResourceAction::~DepositResourceAction() | ||
{ | ||
// Nothing currently | ||
} | ||
|
||
|
||
void DepositResourceAction::Reset() | ||
{ | ||
// Ensure the in range is false | ||
SetInRange(false); | ||
Target = nullptr; | ||
ResourcesDeposited = 0; | ||
ActionTime = 0.0; | ||
} | ||
|
||
|
||
bool DepositResourceAction::IsActionDone() | ||
{ | ||
// Return whether or not the treasure is complete | ||
return ResourcesDeposited >= ResourcesToDeposit; | ||
} | ||
|
||
|
||
bool DepositResourceAction::CheckProceduralPreconditions(AShip* ship) | ||
{ | ||
// Ensure the ship exists | ||
if (!ship) | ||
return false; | ||
|
||
// Calculate the nearest resource | ||
GridNode* goalNode = ship->Level->CalculateNearestGoal(ship->XPos, ship->YPos, HOME); | ||
|
||
// Check if the resource exists | ||
if (!goalNode || !goalNode->ResourceAtLocation) | ||
return false; | ||
|
||
// Get the target | ||
Target = goalNode->ResourceAtLocation; | ||
|
||
// Get the distance to the target | ||
const FVector distance = ship->GetActorLocation() - Target->GetActorLocation(); | ||
|
||
// Check if the distance is less than some amount | ||
// TODO update with some actual collision system | ||
SetInRange(distance.Size() <= 5); | ||
|
||
// Return a success | ||
return true; | ||
} | ||
|
||
|
||
bool DepositResourceAction::PerformAction(AShip* ship, float deltaTime) | ||
{ | ||
// Add the current time to the count | ||
ActionTime += deltaTime; | ||
|
||
// Get the resource actor | ||
AResourceActor* resourceActor = Cast<AResourceActor>(Target); | ||
|
||
// Check if the resource is invalid | ||
if (!resourceActor) | ||
return false; | ||
|
||
// Check the action time | ||
if (ActionTime >= TimeToDeposit) | ||
{ | ||
// Increase the resource gathered based on the type | ||
switch (ResourceType) | ||
{ | ||
case WOOD_RESOURCE: | ||
ship->NumWood--; | ||
break; | ||
case STONE_RESOURCE: | ||
ship->NumStone--; | ||
break; | ||
case FRUIT_RESOURCE: | ||
ship->NumFruit--; | ||
break; | ||
|
||
// No default case | ||
default: | ||
break; | ||
} | ||
|
||
// Increase the current resource gathered | ||
ResourcesDeposited++; | ||
|
||
// Reset the time | ||
ActionTime = 0.0; | ||
|
||
// If action is done, reset target and morale | ||
if (IsActionDone()) | ||
{ | ||
// Remove the target | ||
Target = nullptr; | ||
|
||
// Decrease the morale | ||
ship->Morale--; | ||
} | ||
} | ||
|
||
// Return a success | ||
return true; | ||
} | ||
|
||
|
||
bool DepositResourceAction::RequiresInRange() | ||
{ | ||
// This must be next to or on top of the agent | ||
return true; | ||
} | ||
|
||
|
||
void DepositResourceAction::SetResourceType(EGridType resourceType) | ||
{ | ||
ResourceType = resourceType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
A2_Goals/Source/A2_Goals/Public/Actions/DepositResourceAction.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* FIT3094 ASSIGNMENT 2 - GOAL PLANNING | ||
* Author: Harrison Verrios | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Actions/GOAPAction.h" | ||
#include "World/GridType.h" | ||
|
||
/** | ||
* @brief An action that attempts to deposit some resource at the home base | ||
*/ | ||
class DepositResourceAction : public GOAPAction | ||
{ | ||
/************************************************************/ | ||
|
||
// The resource looking for | ||
EGridType ResourceType; | ||
|
||
// How much resources will be deposited | ||
int ResourcesToDeposit = 50; | ||
|
||
// How long does it take to deposit treasure? | ||
const float TimeToDeposit = 0.1f; | ||
|
||
// How much resource has been deposited so far? | ||
int ResourcesDeposited; | ||
|
||
// How much time has elapsed inside of this action? | ||
float ActionTime; | ||
|
||
|
||
/************************************************************/ | ||
|
||
/** | ||
* @brief Resets the action status | ||
*/ | ||
virtual void Reset() override; | ||
|
||
|
||
/************************************************************/ | ||
public: | ||
|
||
/** | ||
* @brief Deposits some resource of some type | ||
* @param resourceType The type of resource to look for | ||
*/ | ||
DepositResourceAction(EGridType resourceType, int resourcesToDeposit); | ||
|
||
/** | ||
* @brief Default destructor | ||
*/ | ||
virtual ~DepositResourceAction() override; | ||
|
||
/** | ||
* @brief Returns whether the action is completed or not | ||
* @return A success flag | ||
*/ | ||
virtual bool IsActionDone() override; | ||
|
||
/** | ||
* @brief Checks if the current preconditions are valid | ||
* @param ship A reference to the ship agent | ||
* @return A state flag for the conditions | ||
*/ | ||
virtual bool CheckProceduralPreconditions(AShip* ship) override; | ||
|
||
/** | ||
* @brief Performs the action on a particular agent | ||
* @param ship A reference to the ship agent | ||
* @param deltaTime The current time difference for the action to run at | ||
* @return A success flag for the action | ||
*/ | ||
virtual bool PerformAction(AShip* ship, float deltaTime) override; | ||
|
||
/** | ||
* @brief Whether or not the action requires something in range | ||
* @return In Range flag | ||
*/ | ||
virtual bool RequiresInRange() override; | ||
|
||
/** | ||
* @brief Updates the resource type to look for | ||
* @param resourceType A new resource grid type | ||
*/ | ||
void SetResourceType(EGridType resourceType); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters