Player Handle

The ARTSPlayerHandle is a companion class to player controller, that exists for both humand and AI players, and unlike player controller is replicated to all players (like the player state class). As such, we use it to centralise logic that is common for both human and AI controllers, and needs to be known to all clients in game. This includes resource management, entity orders, etc.

Entity selection

The player handle holds an array of selected units, and also provides utility functions to select and deselect new entities:

const TArray<ARTSEntityHandle*>& GetSelectedHandles() const;
void TrySelectActors(const TArray<AActor*>& Actors);
void SelectHandles(const TArray<ARTSEntityHandle*>& EntityHandles);
void AddHandlesToSelection(const TArray<ARTSEntityHandle*>& EntityHandles);
void DeselectAllHandles();
void DeselectHandle(ARTSEntityHandle* Handle);
bool IsAnyHandleSelected() const;
ARTSEntityHandle* GetFirstSelectedHandle() const;
ARTSEntityHandle* GetHighestPriorityHandle() const;
/** Ensures that only buildings or only units are selected at the same time, we don't allow mixing them */
void SanitizeSelectedHandles();

Limited and reviable entities

Since number-limited entities (such as heroes or heroic units) are handled per player, the player handle is a good class to centralise the logic. These are the reference functions:

// Logic for player limits on hero and limited unit purchase
bool CanLimitedEntityBeProduced(URTSEntityConfig* EntityConfig) const;
void NotifyLimitedEntityPurchased(URTSEntityConfig* EntityConfig);
void NotifyLimitedEntityDead(URTSEntityConfig* EntityConfig);
bool CanHeroBePurchased(URTSEntityConfig* HeroConfig) const;
bool IsHeroAlive(URTSEntityConfig* HeroConfig) const;
TOptional<FRTSHeroRevivalInfo> GetHeroRevivalInfo(URTSEntityConfig* HeroConfig) const;
void NotifyHeroAlive(ARTSEntityHandle* HeroHandle);
void NotifyHeroDead(ARTSHero* Hero);

Resources

Player Handle is the actor to which player resources component is attached, so that we can access per-player resources from any client.