So, I glanced through most of the thread. Hopefully I didn't do anything wrong haha.
So, I based the "Merge" on the Destroyer Form from Obsidian Statues. This lets us have the UI of Gold/Lumber and Food. It will also say "not enough X" as expected.
To begin:
Begins Channeling is used in Merge Cast. This will allow us to prevent the spell cast and we can check if the player has an appropriate unit to merge with. If not, debug msg. If so, find the closest appropriate unit, call it the partner. The partner then receives an invisible unit target spell based on channel and is ordered to cast it on the unit who requested the merge.
The partner will now be walking toward our unit who requested the merge. During this time should a player try to send the request again, a debug msg will appear saying that someone is coming. If either should die en route, the merge will be cancelled (currently there is a debug msg). If the partner receives an order of anything but "stun," the merge will be cancelled (currently there is a debug msg).
When the partner gets close enough to cast the invisible unit target spell. We catch it again with Begins Channeling, then we remove the partner from the game and order the requesting unit to morph to the "Merged" unit.
As it stands now, it doesn't take into account the partner's HP at the time, the newly merged unit will have the HP of the requesting unit as it was the one who morphed. You can easily set the requester's HP to some combination/portion of the partner and requester's HP if desired.
If the partner "merges" while the requester is stunned, the partner will disappear and after the stun the requester will morph as expected. Only potential problem is that long stuns could look odd or if they lead to the requester dying the player will have lost both.
You'll have to decide if/how you want to address these issues.
You'll probably want/need to change my debug msgs to be player specific or if they are needed at all.
Let me know if you have any problems, as I could have made a mistake, I'll post the code so others can hopefully spot any potential issues.