Snippet Units in sector

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Sector:
Imagine a cake, the round type,
cut it into pieces, taking care to cut through the center,
take one piece,
look at it from the top.
That's a sector.

Still not seeing it? Here's an image.


JASS:
library FILTERS initializer Init
globals
    boolexpr FILTER_True
endglobals
private function ReturnTrue takes nothing returns boolean
    return true
endfunction
private function Init takes nothing returns nothing
    set FILTER_True = Condition(function ReturnTrue)
endfunction
endlibrary
JASS:
// whichGroup: the group the units will be added to
// xc, yc: the starting point, sort of like the center of the circle
// facing: the direction the "middle" of the sector goes to, in radians
// radius: the "length" of the sector
// angle: the maximum opening angle of the sector, in radians
// filter: the condition function to apply to the units in the sector.
function GroupEnumUnitsInSector takes group whichGroup,real xc,real yc,real facing,real radius,real angle,boolexpr filter returns nothing
    local group g = CreateGroup()
    local unit u
    local real x
    local real y
    local real x1
    local real y1
    local real x2
    local real y2

    call GroupEnumUnitsInRange(g, xc, yc, radius, filter)

    set angle = angle * 0.5
    set x1 = Cos(facing - angle)
    set y1 = Sin(facing - angle)
    set x2 = Cos(facing + angle)
    set y2 = Sin(facing + angle)

    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        call GroupRemoveUnit(g, u)

        set x = GetUnitX(u) - xc
        set y = GetUnitY(u) - yc
        if y * x1 >= x * y1 and y * x2 <= x * y2 then
            call GroupAddUnit(whichGroup, u)
        endif
    endloop

    call DestroyGroup(g)
    set g = null
endfunction

// point: the starting point, sort of like the center of the circle
// facing: the direction the "middle" of the sector goes to, in degrees
// radius: the "length" of the sector
// angle: the maximum opening angle of the sector, in degrees
// filter: the condition function to apply to the units in the sector. Pass null for all units
function GetUnitsInSector takes location point,real facing,real radius,real angle,boolexpr filter returns group
    local group g = CreateGroup()
    if filter == null then
        set filter = FILTER_True
    endif
    call GroupEnumUnitsInSector(g, GetLocationX(point), GetLocationY(point), facing * bj_DEGTORAD, radius, angle * bj_DEGTORAD, filter)
    return g
endfunction



Yes, I actually think it works...

The demo map is simple to use, select the Blood Mage, move somewhere, press "escape".
The list of names you get would be the units within 400 distance and 60 degrees in front.
Yes, it includes the Mage... that's because the filter function simply picks anything...
 

Attachments

  • UnitsInSector_Demo_AceHart.w3x
    14.8 KB · Views: 357

Samael88

Evil always finds a way
Reaction score
181
Thanks Acehart:) This will really come in handy:D
Keep up the good work:thup:

Edit: Does this require vJass or is it standard Jass?
 

Dameon

"All the power in the world resides in the eyes"
Reaction score
127
So put simply this enables you to chose unit's in certain view points, mainly in front, to the left, to the right and behind. I would have never thought of doing a trigger like this but I can think of a lot of uses for it, thanks ace.

By the way is this possible in MUI?
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
Refreshingly simple and useful, good job, thanks for sharing.

A small question if you don't mind.
As I see it ReturnTrue serves as the conditions when the group is created. That make sense, but how about letting the players give their own set of conditions? You could always take another boolexpr parameter. Obviously one could always simply loop and use If/Then/Else action, but I believe just giving boolexpr parameter would ease things.

Do correct me if I'm wrong.
 

Don

Rise with the Fallens!
Reaction score
52
Nice system, this surely will make it into one of my map, i love it, good job!
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Just the sector functions, or the library too?


The library is only there to provide "FILTER_True".
Unfortunately, that means you need NewGen.

Alternatively, if you don't want, or can not, use NewGen, add a function like
JASS:
function ReturnTrue takes nothing returns boolean
    return true
endfunction


And replace "FILTER_True" with "Condition(function ReturnTrue)".
 

black.sheep

Active Member
Reaction score
24
So is supposed to look like this? Tell me what im doing wrong
Code:
function GetUnitsInSector takes location point,real facing,real radius,real angle,boolexpr filter returns group
    local group g = CreateGroup()
    if filter == null then
        Condition(function ReturnTrue)
    endif
    call GroupEnumUnitsInSector(g, GetLocationX(point), GetLocationY(point), facing * bj_DEGTORAD, radius, angle * bj_DEGTORAD, filter)
    return g
endfunction

function ReturnTrue takes nothing returns boolean
    return true
endfunction
 

Viikuna

No Marlo no game.
Reaction score
265
Your function creates groups every time its called, so its slower than it should be + it leaks.

This should be fixxed. I suggest to make it require GroupUtils, and use ENUM_GROUP for GroupEnum calls..

Also in that GetUnitsInSector function you should replace CreateGroup with NewGroup.


edit. Ok, this is thread pretty old. Just noticed. Well, anyways, I kinda wonder if AceHart is still around..
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top