How to activate selected units that match a randomly drawn chit

wiki > How To's > Activating units automatically

=How to activate selected units that match a randomly drawn chit=

The Problem
The Devil's Cauldron contains an interesting command structure. Each unit in the game belongs to a specific formation. Each formation has a specified leader counter and a matching Activation chit. Activations chits for all formations from both sides are randomly drawn from a Deck to determine the order of play. When the Activation Chit for a formation is drawn, then the leader and all units that belong to that formation are automatically 'activated' by displaying a yellow highlighting layer. This makes them easy to find on a busy mapboard. As each unit is moved, or given a command, then the yellow layer turns to Green to indicate that its turn has ended. A toolbar button deactivates all units at then of the turn.



Storing the information
The first stage is to store the name of the formation in the Activation chit and each of the counters belonging to the formation. I use Prototypes for this. For the 1st Parachute Brigade, 1st Airbourne Division, the prototype is named '1AB-1st Para Brigade' and just includes the single Marker trait with the marker named Formation equal to '1st Para Brigade':



Then, then we add the '1AB-1st Para Brigade' prototype to the 1 Para Activation Chit, the 1 Para leader (Brig. Lathbury) and each of the 1 Para units:



Highlight Layer Setup
The two highlight images are setup as 2 seperate layers in a prototype named 'canActivate'. Each layer is always active, but contains a transparent image for the first level and the highlight image as the second level. The 'canActivate' prototype is added to each 1 Para unit through the Protoype chain

Infantry-allied -> Mobile-allied -> Unit-allied -> Unit -> canActivate

and to the leader through

Leader-allied -> Leader -> canActivate



The yellow 'active' highlight is toggled by the Ctrl-A Activate command and the green 'done' highlight is toggled by the Ctrl-K Mark Action Done command.



Activation Chit Setup
Each Activation chit contains the Chit protoype which has a Global Key Command to Activate all highlight layers in units that have the same Formation marker. Here is the protoype:



So the Ctrl-A Activate all units in Formation command given to an Activation Chit counter causes all of the units in the same formation to be issued with the Ctrl-A Activate all units in Formation command.

The key to this working is the Matching Properties string:

CurrentMap=Map&&Formation=$Formation$

The first part CurrentMap=Map selects only counters on the map named 'Map', which is the name of the main map in this module. The second part Formation=$Formation$ selects only counters whose Formation property has the same value as the Formation property of the Activation Chit. Adding the $ signs around Formation causes the Formation property to be evaluated for the Activation Chit before being compared to any other counters. In this example, it is the equivalent of Formation=1st Para Brigade. Using $Formation$ allows the same Global Key Command to be used (via a prototype) for every Activation Chit.

Putting it all together
So the complete sequence runs:
 * A Chit is drawn from the cup and played.
 * The active player right-clicks on the chit and selects Ctrl A - Activate Units in Formation.
 * This sends Ctrl-A to all counters on the map named 'Map' that have a Marker name Formation with the same value as the Chit.
 * The Ctrl-A causes each of the counters to Activate its yellow highlight layer.
 * The two Trigger Action traits in the canActivate trait catch any commands issued to the counters and activate their green 'done' highlight layer.
 * At the end of the turn, the active player presses the 'Deactivate All Active' button which resets all activated highlights, ready for the next chit to be drawn.