Announcement

Collapse
No announcement yet.

Strategy Game Command System

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Strategy Game Command System

    Since RTS Games are very popular and most of them need a proper command system, I thought it would be good to collect ideas and in the end provide
    a tutorial or documentation for UE4 to simply build one.

    Maybe all of you who are interested post and discuss about ideas.

    Let me begin:

    There is an interface: ICommandableActor
    It provides methods that commandable actors must implement.
    So every actor can implement a command in its own way, that's very good and dynamic.
    Those methods are:

    Code:
    TArray<FString> GetSortedSupportedCommandList(); // returns an array of strings which specify the name of the command they support (sorted (see next method) )
    
    bool IsCommandExecutionPossible(uint16 index); // specifies, whether the command with the given index can currently be executed (call regularly to set a disabled texture)
    bool IsCommandTargetValid(AActor* target, uint16 index) // same as above, changes cursor to forbidden or something like that
    void ExecuteCommand(uint16 index, AActor* target, FVector3 pos) // Executes the command at given index, target and position
    
    uint16 GetDefaultCommand(AActor* target) // returns the index of the default command executed on the given target (move on the ground, attack on enemies, repair on damaged structures,...)
    To the indices: The returned list is sorted by index. When the player clicks a command in the UI, the index of the command in the UI is retrieved and passed to the ExecuteCommand method.
    This method knows which function or command to execute and can do its things.

    Subclassing is easy, to extend the available commands, you retrieve the string array from the superclass and append your own ones.
    Execution or validation requests can be passed to superclass if it's its command. Methods then have to be virtual.

    These are my first thoughts on this, please respond, and give feedback.
    Thanks.

    Greetz
    Last edited by birdfreeyahoo; 05-05-2014, 01:55 AM.

    #2
    Good idea , maybe I can help...

    Comment


      #3
      The problem is you have to implement for each actor same commands, like Move, Attack, etc.

      There can be a base class: ABaseCommandable, which is simply a selectable actor.
      AMoveableActor can exist as base class, but no subclass AAttackableActor, because static defenses can attack but not move.
      You could maybe derive from classes which provide a standard function for its representating command, but since in the command you need access to actor functions, you would have to make that class inherit from actor.
      That would lead to a diamond of death.

      Comment


        #4
        Hmm, well I haven't worked with interfaces much. Here's my idea of making this work.
        We would use the functionality of the AI Controller, and make it so that when you click on a character (actor-pawn-character),
        it attaches a circle to it , so you know it is selected, then if you would order the character to move , we would just check if selected character is indeed in your team,
        if true , then call the function that moves the character to the clicked location.
        So MyController class would deal with what is being selected and make a decision about calling the correct functions from MyAIController.
        Anim Instance blueprints and MyAIController blueprints using the behavior system would define animation states, and what kind of unit-character would be.
        Static defenses, like towers could also be just Actor(no animations), pawn or character(Skel.Mesh and animations) that would search for enemy in range and spawn projectiles rotated towards enemy.

        Comment


          #5
          Im still at work so i can't go too far in details since i dont have Unreal installed on this computer.

          Generally speaking RTS always follow the lockstep model found in http://www.gamasutra.com/view/featur...8_network_.php even if this article is more than 10 years old. That always depends on the kind of RTS you wanna do but if you want multiplayer and many units in the battle ground it's the way to go. Lockstep is possible with UE4 but youll probably want to download the whole source to make things easier, you can begin by setting GUseFixedTimeStep to true and GFixedDeltaTime to the value you want in your game.

          To make the game stay in sync with everyone each lockstep will have to look at two things:
          Did it received every client's action for the next turn and did every client confirmed that they received our action

          As for actions you would probably want to use an interface to process actions, when the user will interact with your UI or keyboard action an instance of that action will be created and sent to the lockstep manager in a queue since only one action will be processed by lockstep turn and you dont want to skip any actions. Each action will then be sent to every player and a default NoAction will be sent in case the player did not perform any action in that lockstep turn.

          To make that working everything needs to be determinism since only the command is sent and each player will then calculate the pathfinding and everything else including physics.

          I hope it's give you some tips on where to look and how to do it
          Last edited by TiGuy; 05-06-2014, 08:24 PM.

          Comment


            #6
            Hey, sounds good, thanks for the tip

            Comment

            Working...
            X