Reclaiming Behaviours

How do I make a unit spend all its time reclaiming things?

From the sounds of it, you should make use of the behaviour system. Units have behaviours attached to them depending on the type of unit. Most construction units only have the taskqueuebehaviour, but here it sounds like you need to implement a reclaimbehaviour.

How Behaviours Control Units

When a unit is idle, or a behaviour yields control ( e.g. your reclaim behaviour when it’s decided it can take a break or there is nothing left to do ), all the behaviours in a unit are ranked by priority, they’re each asked, “do you need to do anything?” and “what is your current priority?”. The highest ranking behaviour is then handed full control of the unit, to do as it pleases until such a time it relinquishes control or the unit finishes a task. At this point the behaviour may say “I did my stuff but there’s more to do”, and return a high priority to keep control. A “run away” or escape behaviour may trigger this process and declare it has a huge priority and give an order to run away

For centralised systems, implement a module that organises and commands units, and give the units a behaviour that acts as a proxy. This is how attacking works, an attack behaviour tells the module that this unit is an attacker, and it’s ready to go. The module then decides to group attackers together, and send them off on their business. At this point the attack behaviour tells the module it is now attacking and unavailable for skirmishes, and sets about sending the unit off to the enemy and takes control of that unit as the primary behaviour ( high priority behaviour! we have stuff to kill ).

When enemy units in that area are dead the attack behaviour sets its priority to low and yields control of the unit, and pings the attack module to say it’s now available for attacking. Other behaviours attached to the unit then have the opportunity to do things. Otherwise the unit becomes idle.

If you really, really wanted to use taskqueues for this, I would modify the taskqueuebehavior to detect when ‘yield’ is returned. In the task queue you can then signal to a reclaim behaviour to do its job and raise its priority, but I don’t recommend doing any of this, it’s kind of hackish

 

Originally posted and modified from this post on the spring forums