| 08-08-2011, 08:44 PM | #1 |
Hey, Basically what I am trying to do is detect when a unit leaves a COP, re-writing someone else's GUI triggers into vJass. I am a programmer, but this task is my first experience with Warcraft III triggering. At the moment, rectangular regions are created at every COP, but obviously a rectangle is a poor approximation to a circle. Having read another topic, I gather that a region is a collection on "cells", which I presume are squares, but I have no idea how big a cell is, and whether it is possible to create a collection of cells to be a better approximation to a circle. I see there is a RegionAddCell method which could presumably be used to create a better approximation, but if I am going to get this done I may as well ask here and get it done properly, rather than trying my own way and creating some kind of botch job. All of the regions are created and bound to event handlers when the map initializes, so it is not overly important if it takes a long time to create each region as it will only happen once, at the start. Unfortunately my knowledge in what is possible in WE is woefully lacking. Cheers |
| 08-08-2011, 10:41 PM | #2 |
I personally prefer periodically enumerating units in range/rect to using triggers with unit-enters-region events, but if you're already stuck with doing it that way that's not a problem. For an approximation of a circle, I would suggest using RegionAddRect to add multiple overlapping rects to your region, each constructed in such a way that the circle we are approximating is its circumscribed circle. Something like this: JASS:local rect r local region rg=CreateRegion() local real radius=1024.0 // the radius of the circle we are approximating local real angle=(bj_PI/2)-(bj_PI/20) // 90 degrees minus half our step loop exitwhen angle<0.0 set r=Rect(-Cos(angle)*radius, -Sin(angle)*radius, Cos(angle)*radius, Sin(angle)*radius) call RegionAddRect(rg,r) call RemoveRect(r) set angle=angle-bj_PI/10 // 5 steps per quarter circle endloop set r=null |
| 08-08-2011, 10:48 PM | #3 |
RegionAddCell() adds the 32x32 cell in which the specified coordinates belong (you can see the cells when you open the WE - the smallest ones (marked with grey lines) are 32x32, the medium-sized ones (marked with white lines) are 128x128, while the biggest ones (marked with yellow lines) are 512x512). Just answering what Anitarf didn't... |
| 08-08-2011, 10:59 PM | #4 | |
Quote:
Thanks very much for the code. One question, do rects map flawlessly to regions, or are regions confined to a collection of XxX (X by X) squares? I don't know if I have explained what I mean well, ask if you don't understand. |
| 08-08-2011, 11:01 PM | #5 | |
Quote:
|
| 08-09-2011, 10:05 AM | #6 | |
Quote:
JASS:scope regtest initializer Init globals timer tim=CreateTimer() endglobals private function callback takes nothing returns boolean call BJDebugMsg(R2S(TimerGetElapsed(tim))) return false endfunction private function Init takes nothing returns nothing local trigger t=CreateTrigger() local integer i=1 local rect r=Rect(100,-500, 500,500) local region rg=CreateRegion() call RegionAddRect(rg, r) call TriggerRegisterEnterRegion(t, rg, Condition(function callback)) loop exitwhen i>12 call IssuePointOrder(CreateUnit(Player(0), 'hfoo', -i*3, -500+i*75, 0), "move", 250, -500+i*75) set i=i+1 endloop call TimerStart(tim, 10.0, false, null) endfunction endscope |
