minicook/Source/minicook/OvenPawn.h
Stefan Stefanov b01e9b5891 Added new dials to the oven, added material for the fire with offset
Migrated some assets from another repo, added new float curves and actions.

Created new material with twinkling over time and gradient color.

Added knobs and button needles to the oven
2023-11-15 00:27:10 +02:00

157 lines
No EOL
4.7 KiB
C++

// Stefan Stefanov 2023
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Misc/DateTime.h"
#include "Misc/Timespan.h"
#include "Engine/DataTable.h"
#include "OvenCookspot.h"
#include "OvenPawn.generated.h"
// todo(stefan): Revisit this meal struct, not all fields are needed/make sense. Good enough for now.
USTRUCT()
struct FMeal : public FTableRowBase
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Meal", meta=(Tooltip = "The ID of the meal recipe"))
int32 ID{-1};
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Meal", meta=(Tooltip = "The name of the meal recipe"))
FText MealName = FText::FromString("DefaultMealName");
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Meal",
meta=(Tooltip = "The target value of 'heat' for the perfect cooking temperature"))
double TargetHeat{0.5};
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Meal",
meta=(Tooltip =
"The half-range of the target value of the cooking temperature, e.g. if @param TargetHeat is 0.5 and @param HalfHeatRange is 0.1, anything between 0.4 and 0.6 is perfect heat"
))
double HeatHalfRange{0.1};
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Meal",
meta=(Tooltip = "The total cooking time for this meal recipe, in milliseconds"))
double TotalCookingTimeMS{5000.0};
};
struct FCookingStats
{
int32 TotalCookedMeals{0};
int32 TotalTimeUndercookedMS{0};
int32 TotalTimeOvercookedMS{0};
};
struct FCookstove
{
// MealID from the data table
int32 CurrentMealID{-1};
FMeal Meal;
// When the meal started cooking
FDateTime StartTime;
// and when it should be done cooking
FDateTime EndTime;
bool CurrentlyCooking{false};
// Should always be in the range [0.0, 1.0]
double TargetHeat{0.5};
double HeatHalfRange{0.15};
double CurrentHeat{0.0};
double UndercookedMultiplier{1.0};
double OvercookedMultiplier{1.0};
double ScoreMultiplier{1.0};
FCookingStats CookingStats{};
TObjectPtr<AOvenCookspot> OvenCookstoveActor;
/**
* @brief Given a @param DataTablePtr and a @param MealID, configure the cookstove to start cooking the meal.
* @return Returns whether we found a meal with the provided @param MealID and successfully started cooking it.
*/
auto Setup(const UDataTable *DataTablePtr,
const int32 MealID,
const double InUndercookedMultiplier,
const double InOvercookedMultiplier,
const double InScoreMultiplier) -> bool;
static auto GetMealFromTable(const UDataTable *DataTablePtr, int32 MealID) -> FMeal;
auto SetCookingTime(const FTimespan CookingTimespan) -> void;
/**
* @brief Updates the cookstove for this tick, if a meal is cooking, updates the stats for it and if it finishes it calculates the score, etc...
* @param DeltaTime Time between N-1 and N-2 frames in milliseconds.
* @param PlayerScore Takes in the current player score in case a meal gets finished and the score must be returned.
*/
auto Update(const float DeltaTime, int32 &PlayerScore) -> void;
/**
* @brief Returns the remaining cooking time.
*/
auto GetRemainingCookingTime() const -> FTimespan;
/**
* @brief Check if the currently cooked meal is done cooking.
*/
auto IsMealDone() const -> bool;
/**
* @brief Finishes up cooking the current meal, setting up the necessary stats and state.
* @return Returns the calculated score based on the stats of the cooked meal.
*/
auto FinishMeal() -> int32;
};
UCLASS()
class MINICOOK_API AOvenPawn : public APawn
{
GENERATED_BODY()
public:
AOvenPawn();
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(class UInputComponent *PlayerInputComponent) override;
auto TrySpawningNewRandomMeal() -> bool;
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
double ScoreMultiplier{1.0};
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
double UndercookedMultiplier{1.0};
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
double OvercookedMultiplier{1.0};
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Oven Settings")
int32 CurrentPlayerScore{0};
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
TSubclassOf<AOvenCookspot> CookstovePrefab;
// ReSharper disable once CppUE4ProbableMemoryIssuesWithUObject
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
TObjectPtr<UDataTable> RecipesDataTable;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
TArray<TObjectPtr<AActor>> CookspotLocations;
private:
// An array of all the cookstoves, from left to right on the screen.
TArray<FCookstove> Cookstoves;
};