You cannot natively just get the full training queue at any given time, but you
can detect when a unit is added to a build queue, when a unit is cancelled, and when a unit is successfully trained. This method to keep track of the queue has been compiled into a system by IcemanBo:
TrainingDetection
However, I wouldn't suggest using that system at all. A much better solution is to passively morph the training structure via Bear Form. This will allow it to keep training, keep its train queue, and keep control group hotkeys! Cool, right? It has one problem: there's no
direct way to get the unit that is doing the training in the
Unit - A unit finishes training a unit event. There,
Triggering Unit gets you the trained unit, not the training one. This is annoying, but there are workarounds... and you would run into this exact problem anyway if you tried to use the system I linked in a
finishes training event. The best solution for this is to search a small radius around the trained unit and pick the closest unit that satisfies the following conditions. which in most cases will get the right training unit.
- Is a building
- Is owned by the same player that owns the trained unit
- Is alive
- Optional: is the specific unit-type of the building you want to morph (less computationally complex but only works if you tell the trigger which types of units you're looking for in the first place)
Now about the morph itself. Normally you might think to use Chaos or Metamorphosis, but those are not viable options. Chaos can be wonky with units' stats so it's generally better to avoid it if you can; Metamorphosis has a finite duration and it interrupts current orders when used. You can trick the game into morphing passively, though, with an ability based on the Druid of the Claw's Bear Form.
Instead of putting Barracks2 as the "alternate form" unit and Barracks as the "normal form unit", we will switch them so that when we give the ability to the building the game thinks it's already morphed into its alt form! Then when we remove the Bear Form ability from the building immediately after adding it to it the building will morph "back" into the the "normal form unit", which is really your new building type! Trigger looks like:
-
Events
-
Unit - A unit trains a unit
-
Conditions
-
(Unit-type of (Triggering Unit)) equal to YOUR_TYPE
-
Actions
-
Set Shortest = RADIUS
-
Set Trainer = (No unit)
-
Set TP1 = (Position of (Triggering Unit)) //TP1 is a point variable used to clean a point leak here
-
Custom script: set bj_wantDestroyGroup = true //this auto-cleans a group leak in the line below this one
-
Unit Group - Pick every unit in (Units within RADIUS of TP Matching (Unit-type of (Matching unit) equal to YOUR_TRAINING_TYPE) and (Owner of (Matching Unit) equal to Owner of (Triggering Unit)) and (Life of (Matching Unit) Greater than 0.405)) and do (Actions)
-
Loop - Actions
-
Set TP2 = (Position of (Picked Unit))
-
Set Dist = Distance between TP1 and TP2
-
Custom script: call RemoveLocation(udg_TP2) //change the variable name here to udg_ plus whatever you call it
-
If (All conditions are true) then do (then actions) else do (Else actions)
-
If - Conditions
-
Dist less than or equal to Shortest
-
Then - Actions
-
Set Trainer = (Picked Unit)
-
Set Shortest = Dist
-
Else - Actions
-
Custom script: call RemoveLocation(udg_TP1) //change the variable name here too to udg_ plus whatever you call it
-
Unit - Add BEAR_ABIL to Trainer
-
Unit - Remove BEAR_ABIL from Trainer