Advertisement
Guest User

rts unit interface

a guest
Mar 11th, 2021
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.34 KB | None | 0 0
  1. #pragma once
  2.  
  3. /*
  4. * All RTSDK classes interact with 'units' via this interface, this is to allow the entire RTSUnit class to be swapped out!
  5. * There may be situations where you do not want to make every interactive object a full 'character' pawn, such as obstacles
  6. * By implementing this or an interface derived from this the unreal actor becomes a 'unit' as far as the framework is concerned
  7. * See RTSUnit class for a basic game agnostic implementation of this interface, Public/Units/RTSUnit.h
  8. *
  9. * Arguments are standard unreal game framework classes, you can pass around your derived classes this way with casting within implementations
  10. * For example stat modifiers take a responsible UObject to handle it long term (such as expiring, doing effects over time, etc)
  11. * in RTSDK's unit implementation this is done by RTSStatusEffect actor components, but it could be anything implementing RTSStatusEffectInterface!
  12. *
  13. * Derived interfaces can extend this with game specific accessors, setters, helpers, actions and events without breaking RTSDK
  14. *
  15. * Please note that ue4 blueprintable interfaces do not like having their functions called directly in c++. You have to use the static Execute_ function
  16. * if you call these functions directly in c++ it will throw an exception with a message that you should not do this.
  17. * This makes it a little harder to intellisense it and is a bit longer to type but results in a lot of power for blueprint classes,
  18. * which can override the function entirely, or call your native implementation via super and add functionality on top with visual scripts.
  19. *
  20. * For example getting a unit's icon is done like so,
  21. * UMaterialInterface* icon = IRTSUnitInterface::Execute_GetUnitIcon(PointerToAUnit);
  22. * rather than
  23. * UMaterialInterface* icon = GetUnitIcon();
  24. *
  25. * Implementing the function in c++ requires an override to the _Implementation auto generated virtual function
  26. * UMaterialInterface* GetUnitIcon();
  27. * is implemented by this, in the h file
  28. * virtual UMaterialInterface* GetUnitIcon_Implementation() override;
  29. * which would then be defined in the cpp file as
  30. * UMaterialInterface* ARTSUnit::GetUnitIcon_Implementation();
  31. *
  32. * Another thing to note is that a BlueprintNativeEvent with no return value can only be used on the blueprint event graph, it won't go inside functions!
  33. * As such, all functions in this interface at least return a bool, so they are all implemented in blueprint as a separate function graph.
  34. *
  35. * You can return void in derived interfaces to make events for the blueprint class' event graph, this is just a choice made for consistency.
  36. * In these cases the boolean returns true for success, you can therefore report failure (for whatever reason) with a return of false in your implementation.
  37. *
  38. * Finally, BlueprintNativeEvent functions need blueprint safe arguments and return types,
  39. * if you derive this interface class and your new methods and their native implementations are causing compile errors
  40. * look at the generated header and cpp files and see what arguments UnrealHeaderTool has given them.
  41. *
  42. * For example, FText arguments will become const FText& arguments when it generates the Execute_ and _Implementation functions
  43. */
  44.  
  45. #include "Game/RTSDKMinimal.h"
  46. #include "RTSUnitInterface.generated.h"
  47.  
  48. DECLARE_DYNAMIC_MULTICAST_DELEGATE(FRTSTestSignature);
  49.  
  50. UINTERFACE(Blueprintable)
  51. class RTSDK_API URTSUnitInterface : public UInterface
  52. {
  53.     GENERATED_UINTERFACE_BODY()
  54. };
  55.  
  56. class RTSDK_API IRTSUnitInterface
  57. {
  58.     GENERATED_IINTERFACE_BODY()
  59. public:
  60.    
  61.     /*Get this units display name*/
  62.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  63.         FText GetUnitDisplayName();
  64.  
  65.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  66.         bool SetUnitDisplayName(const FText& NewName);
  67.  
  68.     /*Get this units command page*/
  69.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  70.         FRTSCommandPageInfo GetUnitCommandPage(APlayerState* InPlayer);
  71.  
  72.     /*
  73.     * Whether the player should be able to target this at all, for context commands or mouseover for information
  74.     * 3D picking will look for actors implementing this interface, then actors that return true when passed the player's state
  75.     * the best target will become the player's target unit
  76.     */
  77.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  78.         uint8 ShouldBeTargetedByPlayer(APlayerState* InPlayer);
  79.  
  80.     /*
  81.     * Whether units should be able to target this unit when searching for targets.
  82.     * The unit that is searching for targets is passed as argument. This makes it conditional on a case by case basis eg stealth mechanics
  83.     */
  84.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  85.         uint8 ShouldUnitBeTargetedByUnit(AActor* InUnit);
  86.  
  87.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  88.         uint8 ShouldUnitBeSelectedByPlayer(APlayerState* InPlayer);
  89.  
  90.     /*Get this units icon*/
  91.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  92.         UMaterialInterface* GetUnitIcon();
  93.  
  94.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  95.         bool SetUnitIcon(UMaterialInterface* NewIcon);
  96.  
  97.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  98.         int32 GetUnitTeamIndex();
  99.  
  100.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  101.         int32 GetUnitForceIndex();
  102.  
  103.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  104.         bool SetUnitTeamIndex(int NewIndex);
  105.  
  106.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  107.         bool SetUnitForceIndex(int NewIndex);
  108.  
  109.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  110.         float GetFinalUnitStat(FName StatName, bool ForceUpdate = false);
  111.  
  112.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  113.         float GetBaseUnitStat(FName StatName);
  114.  
  115.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  116.         bool SetBaseUnitStat(FName StatName, float NewBase);
  117.  
  118.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  119.     FRTSStatInfo GetStatInfoForUnitStat(FName TargetStat);
  120.  
  121.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  122.         bool AddUnitStat(FName TargetStat, const FText& DisplayName, const FText& TooltipText, UMaterialInterface* Icon, bool CanGoNegative, float BaseValue);
  123.  
  124.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  125.         bool AddUnitStatModifier(FName TargetStat, UObject* TargetObject);
  126.  
  127.     /*removes any modifiers to sight radius done by the specified effect, returns the number of effects*/
  128.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  129.         bool RemoveUnitStatModifier(FName TargetStat, UObject* TargetObject);
  130.  
  131.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  132.         bool UpdateUnitStat(FName TargetStat);
  133.  
  134.     UPROPERTY(BlueprintAssignable, Category = "RTS Unit Interface")
  135.     static FRTSTestSignature ReceiveTestEvent;
  136.  
  137.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  138.         uint8 GetFriendlyPlayerContextCommandUnitAbilityType(APlayerState* InPlayer);
  139.  
  140.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  141.         uint8 GetEnemyPlayerContextCommandUnitAbilityType(APlayerState* InPlayer);
  142.  
  143.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  144.         uint8 GetNeutralPlayerContextCommandUnitAbilityType(APlayerState* InPlayer);
  145.  
  146.     //add an on update stat event, investigate multicast delegates via interface and rig up move speed check to it, not on tick, same with sight radius
  147.  
  148.     //ASSUMING DIRECT CONTROL!
  149.     //Pass a player controller into this to possess this RTSUnit using unreal game framework controller-pawn possession
  150.     //Existing RTSUnitAIControllers will be retained in the pointer 'UnitAIController', but is ejected from control
  151.     //Call UnpossessRTSUnit to return control to the unit AI.
  152.     //only works on server!
  153.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  154.     bool PossessUnit(AController* NewController);
  155.  
  156.     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "RTS Unit Interface")
  157.     bool UnPossessUnit();
  158. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement