Page 1 of 1

StrategyGame

Posted: Tue Feb 17, 2015 10:48 pm
by christian
https://docs.unrealengine.com/latest/IN ... index.html

An excellent reference project that Epic created. There's a lot to learn from here.

Re: StrategyGame

Posted: Wed Feb 18, 2015 3:45 pm
by christian
The Types header pattern. As seen in StrategyGame/Classes/StrategyTypes.h

This is where you define all your user defined types, enums, structs, delegates, etc.

It's as simple as adding a new header file (if you do this in Visual Studio, beware that it will be added to the Intermediate folder and will need to be relocated to the source folder for it not to be overwritten next time Unreal generates the solution), and including the generated #include and #pragma statements.

For example, here is a selection from StrategyTypes.h:

Code: Select all

#include "StrategyTypes.generated.h"

#pragma once

UENUM(BlueprintType)
namespace EStrategyTeam
{
	enum Type
	{
		Unknown,
		Player,
		Enemy,
		MAX
	};
}

namespace EGameKey
{
	enum Type
	{
		Tap,
		Hold,
		Swipe,
		SwipeTwoPoints,
		Pinch,
	};
}

namespace EGameplayState
{
	enum Type
	{
		Waiting,
		Playing,
		Finished,
	};
}

struct FPlayerData
{
	/** current resources */
	uint32 ResourcesAvailable;

	/** total resources gathered */
	uint32 ResourcesGathered;

	/** total damage done */
	uint32 DamageDone;

	/** HQ */
	TWeakObjectPtr<class AStrategyBuilding_Brewery> Brewery;

	/** player owned buildings list */
	TArray<TWeakObjectPtr<class AActor>> BuildingsList;
};

Re: StrategyGame

Posted: Fri Feb 27, 2015 6:21 pm
by christian
Keep in mind that this pattern should only be used for defining your most commonly used types. More specific types should be defined within their respective headers.

An example from StrategyInput.h

Code: Select all

#include "StrategyTypes.h"
#include "StrategyInput.generated.h"

DECLARE_DELEGATE_TwoParams(FOnePointActionSignature, const FVector2D&, float);
DECLARE_DELEGATE_ThreeParams(FTwoPointsActionSignature, const FVector2D&, const FVector2D&, float);

struct FActionBinding1P
{
	/** key to bind it to */
	EGameKey::Type Key;

	/** Key event to bind it to, e.g. pressed, released, dblclick */
	TEnumAsByte<EInputEvent> KeyEvent;

	/** action */
	FOnePointActionSignature ActionDelegate;
};

UCLASS()
class UStrategyInput : public UObject
{
	GENERATED_UCLASS_BODY()

public:

...