You should note the spell requirements in the code comments as well as the post itself, and the requirements in the post should have links to resource threads. The code could also use a brief description of the spell.
The spell should pick the nearest valid unit when selecting the next target instead of a random one.
Why are you using units instead of effects for the wines?
Don't use squareRoot, compare the squares instead since that's more efficient. The "size" of the projectile should be a calibrateable constant.
d.tx and d.ty could have been local variables instead of struct members.
Instead of using globals and GetFilterUnit in the target calibration function, you should use a wrapper to pass this information to the calibration function as parameters.
It would be more efficient if you kept a static xecast in a private global variable instead of creating one every time.