HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Misc Trigger Questions

08-10-2006, 07:42 PM#1
st33m
Erm, sorry, news toic about some new and old problems.

A) Using Vexorians triangle function, I need to make 2 triangular regions, and preferably have them up at all times. Using them I want to pick everything and slow them.

Collapse JASS:
function GroupAddUnitsInTriangle_AngleCheck takes real angle, real angle1, real angle2, real PI2 returns boolean
 local real x
    if (angle1>angle2) then
        set x=angle1
        set angle1=angle2
        set angle2=x
    endif
    if (angle2-angle1>angle1 - (angle2-PI2)) then
        set angle2=angle2-PI2
        if (angle < bj_PI) then
            set angle=angle-PI2
        endif
        return (angle>=angle2) and (angle<=angle1)
    endif
 return (angle>=angle1) and (angle<=angle2)
endfunction

function GetRectThatLimitsTriangle takes real x1, real y1, real x2, real y2, real x3, real y3 returns rect
 local real maxx
 local real minx
    if (x1>x2) then
        if (x2>x3) then     //x1>x2>x3
            set maxx=x1
            set minx=x3
        elseif (x3>x1) then //x3>x1>x2
            set maxx=x3
            set minx=x2
        else                //x3>x1>x2
            set maxx=x1
            set minx=x2
        endif
    elseif (x1>x3) then //x2>x1>x3
        set maxx=x2
        set minx=x3
    elseif (x3>x2) then //x3>x2>x1
        set maxx=x3
        set minx=x1
    else                //x2>x3>x1
        set maxx=x2
        set minx=x1
    endif

    if (y1>y2) then
        if (y2>y3) then     //y1>y2>y3
            return Rect(minx,y3,maxx,y1)
        elseif (y3>y1) then //y3>y1>y2
            return Rect(minx,y2,maxx,y3)
        else                //y3>y1>y2
            return Rect(minx,y2,maxx,y1)
        endif
    elseif (y1>y3) then //y2>y1>y3
        return Rect(minx,y3,maxx,y2)
    elseif (y3>y2) then //y3>y2>y1
        return Rect(minx,y1,maxx,y3)
    endif
 //y2>y3>y1
 return Rect(minx,y1,maxx,y2)
endfunction

function GroupAddUnitsInTriangle takes group whichGroup, real x1, real y1, real x2, real y2, real x3, real y3 returns nothing
 local rect semi=GetRectThatLimitsTriangle(x1,y1,x2,y2,x3,y3)
 local group inrect=CreateGroup()
 local unit picked
 local real x
 local real y
 local real alpha=Atan2(y2-y1,x2-x1)
 local real beta =Atan2(y3-y1,x3-x1)
 local real gama =Atan2(y1-y2,x1-x2)
 local real delta=Atan2(y3-y2,x3-x2)
 local real PI2=bj_PI+bj_PI

    call GroupEnumUnitsInRect( inrect, semi,null)
    loop
        set picked=FirstOfGroup(inrect)
        exitwhen picked==null
        set x=GetUnitX(picked)
        set y=GetUnitY(picked)
        if IsUnitInGroup(picked,whichGroup) then
        elseif (GroupAddUnitsInTriangle_AngleCheck(Atan2(y-y1,x-x1),alpha,beta,PI2) and GroupAddUnitsInTriangle_AngleCheck( Atan2(y-y2,x-x2) ,gama,delta,PI2)) then
            call GroupAddUnit( whichGroup, picked)
        endif
        call GroupRemoveUnit(inrect,picked)
    endloop
 call RemoveRect(semi)
 call DestroyGroup(inrect)
 set whichGroup=null
 set picked=null
 set semi=null
 set inrect=null
endfunction

Trigger:
Pick Triangle Bottom
Collapse Events
Time - Every 0.30 seconds of game time
Conditions
Collapse Actions
Unit Group - Pick every unit in TempGroup and do (Unit - Set (Picked unit) movement speed to (Real((Custom value of (Picked unit)))))
Custom script: call DestroyGroup(udg_TempGroup)
Custom script: set udg_TempGroup = CreateGroup()
Custom script: call GroupAddUnitsInTriangle(udg_TempGroup,-4261.7,2395.3,-3757.3,-4263.9,1352.0,-3683.0)
Custom script: call GroupAddUnitsInTriangle(udg_TempGroup,3614.0,-3053.5,3679.5,3810.5,-2631.9,3831.5)
Collapse Unit Group - Pick every unit in TempGroup and do (Actions)
Collapse Loop - Actions
Unit - Set the custom value of (Picked unit) to (Integer((Default movement speed of (Picked unit))))
Unit - Set (Picked unit) movement speed to ((Real((Custom value of (Picked unit)))) / 2.00)

Unfortunatly, this only works for one triangle.

B) A while ago I tried to come up with a Chain Lightning style spell in GUI. Purpose of this was to have it based on stats. I came up with:

Trigger:
Chain Storm
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Chain Storm
Collapse Actions
Unit Group - Add (Target unit of ability being cast) to ChainStormTargets
Set StormWitchInt = (Intelligence of (Triggering unit) (Include bonuses))
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Level of Chain Storm for (Triggering unit)) Equal to 1
Collapse Then - Actions
Unit - Cause (Triggering unit) to damage (Target unit of ability being cast), dealing (2.00 x (Real(StormWitchInt))) damage of attack type Spells and damage type Normal
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Collapse Then - Actions
Unit - Create 1 Dummy Unit for (Owner of (Triggering unit)) at (Position of (Target unit of ability being cast)) facing Default building facing degrees
Collapse Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) of type Dummy Unit) and do (Actions)
Collapse Loop - Actions
Unit - Add Chain Storm (Dummy) to (Last created unit)
Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
Collapse Unit Group - Pick every unit in (Units within 500.00 of (Position of (Target unit of ability being cast)) matching ((((Target unit of ability being cast) belongs to an enemy of (Owner of (Triggering unit))) Equal to True) and (((Target unit of ability being cast) is in ChainStormTargets) Eq and do (Actions)
Collapse Loop - Actions
Unit - Order (Last created unit) to Orc Far Seer - Chain Lightning (Picked unit)
Unit - Cause (Triggering unit) to damage (Target unit of ability being cast), dealing (2.00 x (Real(StormWitchInt))) damage of attack type Spells and damage type Normal
Unit Group - Add (Target unit of ability being cast) to ChainStormTargets
Unit Group - Remove all units of ChainStormTargets from ChainStormTargets
Else - Actions
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Level of Chain Storm for (Triggering unit)) Equal to 2
Collapse Then - Actions
Unit - Cause (Triggering unit) to damage (Target unit of ability being cast), dealing (2.00 x (Real(StormWitchInt))) damage of attack type Spells and damage type Normal
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Collapse Then - Actions
Unit - Create 2 Dummy Unit for (Owner of (Triggering unit)) at (Position of (Target unit of ability being cast)) facing Default building facing degrees
Collapse Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) of type Dummy Unit) and do (Actions)
Collapse Loop - Actions
Unit - Add Chain Storm (Dummy) to (Last created unit)
Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
Collapse Unit Group - Pick every unit in (Units within 500.00 of (Position of (Target unit of ability being cast)) matching ((((Target unit of ability being cast) belongs to an enemy of (Owner of (Triggering unit))) Equal to True) and (((Target unit of ability being cast) is in ChainStormTargets) Eq and do (Actions)
Collapse Loop - Actions
Unit - Order (Last created unit) to Orc Far Seer - Chain Lightning (Picked unit)
Unit - Cause (Triggering unit) to damage (Target unit of ability being cast), dealing (2.00 x (Real(StormWitchInt))) damage of attack type Spells and damage type Normal
Unit Group - Add (Target unit of ability being cast) to ChainStormTargets
Unit Group - Remove all units of ChainStormTargets from ChainStormTargets
Else - Actions
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Level of Chain Storm for (Triggering unit)) Equal to 3
Collapse Then - Actions
Unit - Cause (Triggering unit) to damage (Target unit of ability being cast), dealing (2.00 x (Real(StormWitchInt))) damage of attack type Spells and damage type Normal
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Collapse Then - Actions
Unit - Create 3 Dummy Unit for (Owner of (Triggering unit)) at (Position of (Target unit of ability being cast)) facing Default building facing degrees
Collapse Unit Group - Pick every unit in (Units owned by (Owner of (Triggering unit)) of type Dummy Unit) and do (Actions)
Collapse Loop - Actions
Unit - Add Chain Storm (Dummy) to (Last created unit)
Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
Collapse Unit Group - Pick every unit in (Units within 500.00 of (Position of (Target unit of ability being cast)) matching ((((Target unit of ability being cast) belongs to an enemy of (Owner of (Triggering unit))) Equal to True) and (((Target unit of ability being cast) is in ChainStormTargets) Eq and do (Actions)
Collapse Loop - Actions
Unit - Order (Last created unit) to Orc Far Seer - Chain Lightning (Picked unit)
Unit - Cause (Triggering unit) to damage (Target unit of ability being cast), dealing (2.00 x (Real(StormWitchInt))) damage of attack type Spells and damage type Normal
Unit Group - Add (Target unit of ability being cast) to ChainStormTargets
Unit Group - Remove all units of ChainStormTargets from ChainStormTargets
Else - Actions
Else - Actions

Unfortunatly, this doesnt work. Any ideas?
08-10-2006, 07:54 PM#2
Vexorian
I heard my triangle function is not as fast as it could be. Dunno about better versions though.

I would check if TempGroup exists before destroying it the first time.

There is no reason for the triangle function to not work for more than one triangle. I used it in the cone template twice so it must be something else
08-10-2006, 07:59 PM#3
blu_da_noob
Note: The movement speed modifying native is somewhat screwy. I suggest you use abilities to reduce movespeed.
08-10-2006, 08:23 PM#4
st33m
Quote:
Originally Posted by Vexorian
I heard my triangle function is not as fast as it could be. Dunno about better versions though.

I would check if TempGroup exists before destroying it the first time.

There is no reason for the triangle function to not work for more than one triangle. I used it in the cone template twice so it must be something else
I would check the TempGroup thing, but it works for one half, so I dont think thats the problem.

Quote:
Originally Posted by blu_da_noob
Note: The movement speed modifying native is somewhat screwy. I suggest you use abilities to reduce movespeed.
Okay, I'll try that, but I'm thinking it's not registering units in the top triangle. BUT I will try it.
08-11-2006, 08:53 PM#5
st33m
Sorry to double post, am I allowed to?

Well I'm updating the information I have on this problem, so I hope so. If not, sorry.

OK, so I tried blu's suggestion, and while interesting, it didnt really help.

The problem IS that it's not counting the second set of coordinates.

So... any ideas on how to fix that?
08-11-2006, 09:53 PM#6
Vexorian
Try playing special effects on the 6 points of the triangle to confirm that the coordinates are correct.
08-11-2006, 10:33 PM#7
st33m
Okay Vex, I tried that. It's all correct.

However something weird did happen. It's not related to the new triggers, but a few buildings I placed moved...

EDIT: Actually. I have no idea why they are doing that. Is there any reasons for buildings to move for no reason?
08-11-2006, 11:25 PM#8
Vexorian
when you play a lot of special effects, weird things like that happen.

The only other things I can think about right now are:
- Is the second triangle kind of small? It would only count units as being there if their origins are in the triangle, not if their collision size is inside the triangle.
- Try updating the triangle function, I remember that an old version didn't work too well. Find the newest at wc3jass.com
08-12-2006, 12:06 AM#9
st33m
No, the triangles are (about) each a quarter of the map.

Will doa bout the updating thing. Thanks.
08-12-2006, 03:55 AM#10
st33m
Okay, sorry to double post again.

I tried updating the triangle function, but still no good. This is getting bad. I tried seperating the triggers into 2 triggers, that didnt work. Then I tried working with abilities, that didnt work. Still need help.
08-12-2006, 04:00 AM#11
Vexorian
Try killing the picked units instead of changing the speed (so you can notice if they are really getting picked up) If not then I guess I'll need the map to see if it is actually a bug with the triangle function although I've seen it working with many different triangle variations.
08-12-2006, 04:31 AM#12
PipeDream
found this lying around in my jass folder. different way to check if a point is in a triangle. probably untested.
Collapse JASS:
//Uses a lot of real subtraction which the warcraft engine has issues with
//x1,y1,x2,y2,x3,y3 define triangle vertices
//px,py is the point in question
//Computes area of triangle and three sub triangles made from vertices to point
//If area of sub triangles is greater than area of test triangle, the point is outside

function IsPointInTri takes real x1, real y1, real x2, real y2, real x3, real y3, real px, real py returns boolean
//	local real ux = x2-x1	//u is vector from 1 to 2
//	local real uy = y2-y1
//	local real vx = x3-x1	//v is vector from 1 to 3
//	local real vy = y3-y1
    local real ax = px-x1    //a is vector from p to 1
    local real ay = py-y1
    local real bx = px-x2    //b is vector from p to 2
    local real by = py-y2
    local real cx = px-x3    //c is vector from p to 3
    local real cy = py-y3
//A = 1/2 | u cross v |
//Drop factor of 1/2 since we're doing a comparison
    local real area_tri = (x2-x1)*(y3-y1)-(y2-y1)*(x3-x1)
    local real area1 = ax*by-ay*bx    //area between 1 2 p
    local real area2 = bx*cy-by*cx    //area between 2 3 p
    local real area3 = cx*ay-cy*ax    //area between 3 1 p
    if area_tri < 0. then
        set area_tri = -area_tri
    endif
    if area1 < 0. then
        set area1 = -area1
    endif
    if area2 < 0. then
        set area2 = -area2
    endif
    if area3 < 0. then
        set area3 = -area3
    endif
    return area1+area2+area3 <= area_tri*1.001    //some TOL for rounding
endfunction
08-12-2006, 04:34 AM#13
st33m
Quote:
Originally Posted by Vexorian
Try killing the picked units instead of changing the speed (so you can notice if they are really getting picked up) If not then I guess I'll need the map to see if it is actually a bug with the triangle function although I've seen it working with many different triangle variations.

Tested. It is definatly not tracking the second triangle. I'll PM you the map if you would like, however I listed all the triggers that would affect it.
08-12-2006, 03:17 PM#14
Vexorian
But I need a testing environment, I cannot test a function by just reading it. So pm me the map
08-13-2006, 03:28 PM#15
Vexorian
Pipedream's method is better and faster so this is a better working version of the triangle function:

Collapse JASS:
function GetRectThatLimitsTriangle takes real x1, real y1, real x2, real y2, real x3, real y3 returns rect
 local real maxx
 local real minx
    if (x1>x2) then
        if (x2>x3) then     //x1>x2>x3
            set maxx=x1
            set minx=x3
        elseif (x3>x1) then //x3>x1>x2
            set maxx=x3
            set minx=x2
        else                //x3>x1>x2
            set maxx=x1
            set minx=x2
        endif
    elseif (x1>x3) then //x2>x1>x3
        set maxx=x2
        set minx=x3
    elseif (x3>x2) then //x3>x2>x1
        set maxx=x3
        set minx=x1
    else                //x2>x3>x1
        set maxx=x2
        set minx=x1
    endif

    if (y1>y2) then
        if (y2>y3) then     //y1>y2>y3
            return Rect(minx,y3,maxx,y1)
        elseif (y3>y1) then //y3>y1>y2
            return Rect(minx,y2,maxx,y3)
        else                //y3>y1>y2
            return Rect(minx,y2,maxx,y1)
        endif
    elseif (y1>y3) then //y2>y1>y3
        return Rect(minx,y3,maxx,y2)
    elseif (y3>y2) then //y3>y2>y1
        return Rect(minx,y1,maxx,y3)
    endif
 //y2>y3>y1
 return Rect(minx,y1,maxx,y2)
endfunction

//Uses a lot of real subtraction which the warcraft engine has issues with
//x1,y1,x2,y2,x3,y3 define triangle vertices
//px,py is the point in question
//Computes area of triangle and three sub triangles made from vertices to point
//If area of sub triangles is greater than area of test triangle, the point is outside
function GroupAddUnitsInTriangle takes group whichGroup, real x1, real y1, real x2, real y2, real x3, real y3 returns nothing
 local rect semi=GetRectThatLimitsTriangle(x1,y1,x2,y2,x3,y3)
 local group inrect=CreateGroup()
 local unit picked
 local real x
 local real y
 local real ax //a is vector from p to 1
 local real ay
 local real bx //b is vector from p to 2
 local real by
 local real cx    //c is vector from p to 3
 local real cy
//A = 1/2 | u cross v |
//Drop factor of 1/2 since we're doing a comparison
    local real area_tri = (x2-x1)*(y3-y1)-(y2-y1)*(x3-x1)
    local real area1
    local real area2
    local real area3


 
 

    call GroupEnumUnitsInRect( inrect, semi,null)
    loop
        set picked=FirstOfGroup(inrect)
        exitwhen picked==null
        if IsUnitInGroup(picked,whichGroup) then
        else
            set x=GetUnitX(picked)
            set y=GetUnitY(picked)
            set ax=x-x1
            set ay=y-y1
            set bx=x-x2
            set by=y-y2
            set cx=x-x3
            set cy=y-y3
            set area_tri = (x2-x1)*(y3-y1)-(y2-y1)*(x3-x1)
            set area1 = ax*by-ay*bx    //area between 1 2 p
            set area2 = bx*cy-by*cx    //area between 2 3 p
            set area3 = cx*ay-cy*ax    //area between 3 1 p
            if area_tri < 0. then
                set area_tri = -area_tri
            endif
            if area1 < 0. then
                set area1 = -area1
            endif
            if area2 < 0. then
                set area2 = -area2
            endif
            if area3 < 0. then
                set area3 = -area3
            endif
            if (area1+area2+area3 <= area_tri*1.001) then    //some TOL for rounding
                 call GroupAddUnit(whichGroup,picked)
            endif
        endif
        call GroupRemoveUnit(inrect,picked)
    endloop
 call RemoveRect(semi)
 call DestroyGroup(inrect)
 set whichGroup=null
 set picked=null
 set semi=null
 set inrect=null
endfunction