wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-12-2009, 04:43 PM   #1
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default IsUnitOnRect

Collapse JASS:
library IsUnitOnRect
//**
//* IsUnitOnRect returns true if the unit's collision circle
//* ------------ interesects with a rect.
//*              
//*              Useful for example, in a "enter rect" event
//*              it will return true, unlike blizz' RectContainsUnit
//*
//* probably slower than RectContainsUnit
//*
//*******************************************************************

//=================================================================
    function IsUnitOnRect takes unit u, rect r returns boolean
     local real x =GetUnitX(u)
     local real y =GetUnitY(u)
     local real mx = GetRectMaxX(r)
     local real nx = GetRectMinX(r)
     local real my = GetRectMaxY(r)
     local real ny = GetRectMinY(r)
        if (nx <= x) and (x <= mx) and (ny <= y) and (y <= my) then
            return true
        endif
        if(x>mx) then
            set x=mx
        elseif(x<nx) then
            set x=nx
        endif
        if(y>my) then
            set y=my
        elseif(y<ny) then
            set y=ny
        endif
        return IsUnitInRangeXY(u,x,y,0.0)
    endfunction


endlibrary
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-12-2009, 04:51 PM   #2
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

Why four times :
Collapse JASS:
exitwhen ( IsUnitInRangeOfSegment(u, nx,ny, nx,my, 0) )
Troll-Brain is offline   Reply With Quote
Old 04-12-2009, 04:57 PM   #3
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

take a closer look.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 04-12-2009, 05:06 PM   #4
fX_
User
 
fX_'s Avatar
 
Join Date: Jan 2007
Posts: 528

Submissions (2)

fX_ will become famous soon enough (38)fX_ will become famous soon enough (38)

Default

y not use 'if or or or or or' instead of loop. i think or evaluates each condition 1 by 1 and terminates evaluation upon finding a true condition; and it is more 'to the point'

is it that u just wanted it the conditions to be enumerated more clearly?
fX_ is offline   Reply With Quote
Old 04-12-2009, 05:10 PM   #5
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

ok my bad, variables' name are nearly the same :p
Troll-Brain is offline   Reply With Quote
Old 04-12-2009, 05:14 PM   #6
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

Quote:
Originally Posted by fX_
y not use 'if or or or or or' instead of loop. i think or evaluates each condition 1 by 1 and terminates evaluation upon finding a true condition; and it is more 'to the point'

is it that u just wanted it the conditions to be enumerated more clearly?
The long line required by a bunch of ors would give me nightmares, and a bunch of if-then-elses would make more lines, so I used this.

Edit: code got shorter.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 04-12-2009, 07:42 PM   #7
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

That's a clever way to mesh 4 checks together without a bunch of ugly if/thens.
__________________
Rising_Dusk is offline   Reply With Quote
Old 04-12-2009, 09:25 PM   #8
peq
User
 
peq's Avatar
 
Join Date: Jul 2006
Posts: 57

peq has little to show at this moment (4)

Default

Quote:
Originally Posted by Rising_Dusk
That's a clever way to mesh 4 checks together without a bunch of ugly if/thens.

imho using a loop which will never loop is not clever. loops are ment to loop

and i think it is useless to use IsUnitInRangeOfSegment for checking if a unit is in a rect. I think this does the same:

Collapse JASS:
function IsUnitAtRect takes unit u, rect r returns boolean
    local real x =GetUnitX(u)
    local real y =GetUnitY(u)
    local real maxx = GetRectMaxX(r)
    local real minx = GetRectMinX(r)
    local real maxy = GetRectMaxY(r)
    local real miny = GetRectMinY(r)
    if x > maxx then
        set x = maxx
    elseif x < minx then
        set x = minx
    endif
    if y > maxy then
        set y = maxy
    elseif y < miny then
        set y = miny
    endif
    return IsUnitInRange(u, x, y, 0.)    
endfunction
peq is offline   Reply With Quote
Old 04-12-2009, 10:22 PM   #9
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

... No, it isn't even close to doing the same.

Edit: darn I forgot rects are always paralel to the x and y axis.

Edit: Updated.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 04-12-2009, 11:15 PM   #10
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Vex, you should probably remove the library requirement of IsUnitInRangeOfSegment() since you don't use it anymore.
__________________
Rising_Dusk is offline   Reply With Quote
Old 04-12-2009, 11:30 PM   #11
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

probably.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 04-12-2009, 11:54 PM   #12
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Quote:
Originally Posted by Vexorian
Requires: IsUnitInRangeOfSegment
This shouldn't be in the first post anymore. Also, I think the function name IsUnitInRect() would flow better with WC3 naming conventions.
__________________
Rising_Dusk is offline   Reply With Quote
Old 04-12-2009, 11:56 PM   #13
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

Technically the unit is not necessarily in the rect, half of its collision circle could be outside. Not sure if At is a much better choice though.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 04-12-2009, 11:57 PM   #14
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Well, I think 'in' makes more sense intuitively, even if it doesn't necessarily describe it perfectly.
__________________
Rising_Dusk is offline   Reply With Quote
Old 04-13-2009, 05:08 AM   #15
FriendlyPsycho
User
 
FriendlyPsycho's Avatar
 
Join Date: Feb 2009
Posts: 109

Submissions (1)

FriendlyPsycho is on a distinguished road (12)

Default

IsUnitOnRect() probably? I was thinking of circles when you and Rising_Dusk were having the name discussion. In = inside the radius of the circle, On = exactly at the radius of the circle.
__________________
" YOU RAGE, YOU LOSE! "
FriendlyPsycho is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 01:40 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services