by shilinski » January 20th, 2021, 4:35 am
There is another approach that does not require zones.
Your force field (FF) piece knows (pixel-wise) where it is on the board via the properties CurrentX and CurrentY. I assume it has an area of effect, which could be defined by a box around the center. Suppose it's a square that is 200 pixels on a side, so its boundaries are defined by CurrentX + 100 and CurrentX - 100, and likewise for CurrentY. It then is a matter of determining if a unit (say, a soldier) has a location via its CurrentX and CurrentY that is inside that box. That is, the soldier's (FF CurrentX - 100) <= (soldier's CurrentX) <= (FF CurrentX +100), and likewise for the CurrentY's.
There are actually two ways to accomplish this.
In the first way, the FF piece saves its CurrentX and CurrentY (or possibly more simply the box's 4 boundaries) in global properties. Note that every time it moves, it must update those properties. A soldier piece can then simply compare its position with those properties. The down side to this approach is if you have many FF pieces, you would need a set of global properties for each one.
The second way is to store a soldier's CurrentX and CurrentY in global properties (say, soldierX and soldierY) and then ask the FF pieces if any of them has those coordinates in their boxes. I'd do this with a global key command. To answer, we need a third global property where the FF pieces would deposit their answer either by counting "yes" votes or setting a property to true (never to false because it could erase an earlier yes).
To implement this, the soldier piece would need a trigger trait that did the following:
Zero / clear the answer global property.
Store the soldier's CurrentX and CurrentY in soldierX and soldierY.
Send a GKC to all FF pieces. Each FF would either increment or set to true the answer property if the check proved true.
It's not that difficult, I think.