# [Module Design Problem] Add zone to a piece

Hi, everyone ,

I have encountered a real difficulty in making a vassal module, in this module, a piece/unit shall function
as a force field generator, when other units move into this force field area, they should gain 1 defense point
and when they leave this area they lose 1 DP, I am aware that this can be realized when you have a zone
on a map but this zone is fixed on game map. However, in this situation the field generator can move around
on map and there is no way you can attach a zone or an area to a single piece, nor you can create or delete a
zone during your game. I was wondering if there is a way to solve it, it really puzzles me for a long time.

Thanks.

I would have your force field units update a global property to 0 or 1 whenever they leave or enter a given Zone or - for finer tuning - grid location. Use “execute command for all units ending movement on this map” for that. You would need a unique global property for each such zone or grid location (with a name tied to the given zone or grid location, for example Red_FF for a zone called “Red”). Then all your other units use a Calculated Property to calculate DP adding 1 to base DP if \$CurrentZone\$_FF = 1.

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.