Creating Commands queue for an RTS

I’m currently working on RTS. I’ve searched this topic, but I can’t seem to be able to find a lot of discussions about it.

How would you go about creating commands queue for an RTS? My RTS currently is blueprints only and I might create a basic stack interface in C++ for this.

Currently:
I want to create an array of structs.
Each struct has this info:
Vector: To hold location for movement/patrol
Actor: If it was follow/Attack command
Enum that holds these commands: Attack/Stop/Hold/Patrol/Move/spell
Spell number: 1-4

This is just theory crafting. I’m not sure how to implement it. Behavior trees could do good with this. I’m not sure. Any ideas?

Look at ZeroMQ - ZeroMQ | C++ - and see if that works for you.

This is an old thread, but this answer is not helpful. ZeroMQ is a networking fabric, and doesn’t solve the original question at all. I’m reading this old thread because I’m looking for best practices in how to build a queue of commands in game logic / blueprints. (I think I know how to do it with an array and a custom blueprint structure type, but checking other examples are always good!)

This sounds very similar to a separate question answered here.

Adding onto the link in the comments…

The core of your problem is you’re going to need a way to define a type that can be organised and called on with parameters with some concept of priority.

First, you want a base “command” type.
There are design patterns you could look to for this sort of thing, but I would avoid looking into those as they will probably result in confusion and unnecessary code.
Keep it simple!
You need a type, we’ll call it RTSCommand.
Your RTSCommand will have an int run() (return 0 for success, other for error), and an int priority.

Each of your commands will be a subclass of RTSCommand.
For example I might have a RTSTrainCommand which will train a unit.
You probably want to add a unit type, so add a text property to the class that is the URL to the Blueprint that is to be spawned after training is complete.
Then your run() function will start a timer and spawn the Blueprint specified in the URL at timeout.

Only thing left is to discuss priority.
Let’s say I add another thing to the queue.
You can add to the end of a list of RTSCommand and that will get the job done nicely, but for a more flexible implementation I’d use the priority value.
The priority queue structure in the standard library works in Unreal C++ at least on Windows machines, but even if it doesn’t it’s very cheap and simple to traverse a small list and figure out which item has the highest priority number.

Make sense? :slight_smile:
For more complicated implementations, you can look to how the C++ standard library does threading, but you’ll be going down one hell of a rabbit hole.