- Joined
- Jun 20, 2012
- Messages
- 195
Hello hivers, Is there a way to know if there's a nearby tree around a unit?
// where x, y mark coords while filter being a filter function - check for "trees-only"
set tree = GetClosestDestructable(x, y, Filter(function filter))
Bannar said:You could make use of GetClosestWidget with destructable-module on.
Use "pick every destructible in range of point" and check if they are trees.
32 or something. I forget.limit of how many boss?
Depends. Nothing stops you stacking 1,000 Destructible objects into that tiny area next to common sense. If you are sure that your map does not have a high density and if it does not really mater if results are not 100% perfect (who cares if in 1-2 spots it picks something that is not the closest in a tiny area?) then it is certainly not a problem. However if you were doing something like finding the nearest trees to harvest from a building out of all trees on the map then this limit is a huge problem.I don't think that would occur if my radius is only as big as 350 right?
32 or something. I forget.
64 is Max amount of Dest Enum AFAIR. Rest are dismissed.
function RegisterDestDeathInRegionEnum takes nothing returns nothing
set bj_destInRegionDiesCount = bj_destInRegionDiesCount + 1
if (bj_destInRegionDiesCount <= bj_MAX_DEST_IN_REGION_EVENTS) then
call TriggerRegisterDeathEvent(bj_destInRegionDiesTrig, GetEnumDestructable())
endif
endfunction
function TriggerRegisterDestDeathInRegionEvent takes trigger trig, rect r returns event
set bj_destInRegionDiesTrig = trig
set bj_destInRegionDiesCount = 0
call EnumDestructablesInRect(r, null, function RegisterDestDeathInRegionEnum)
return trig
endfunction
constant integer bj_MAX_DEST_IN_REGION_EVENTS = 64
If such limit would restrict all of enum functions, then all of my dest-related resources were trash.Have you even read the lib's description? You can choose varienty of function (related to dest, item, unit and group), thus you could call for example: GetClosestDestructableInRange. By specifing radius value, you can check if a e.g tree exists within circle 10000.0 units away from point "p". Read before posting false opinions.This is a useful library, but AFAIK it just finds the closest widget, or in the OP's case, the closest tree / destructable. The meaning of "nearby," however, is tied to a quantity, namely, how close is nearby? If the closest tree is 10000.0 units away, then that definitely is not nearby (unless the map involves Godzilla-esque giants).
^ Just Detailing the idea, I am not sure whether from this works but it's worth to try :
- Actions
- Set YourUnit_Point = (Position of (Triggering unit))
- Destructible - Pick every destructible within 256.00 of YourUnit_Point and do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- (Picked destructible) Equal to No destructible
- Then - Actions
- - Your Trigger -
- Else - Actions
- Actions
- Set YourUnit_Point = (Position of (Triggering unit))
- Destructible - Pick every destructible within 256.00 of YourUnit_Point and do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- ((Picked destructible) is alive) Equal to True
- Then - Actions
- Else - Actions
- Actions
- Set YourUnit_Point = (Position of (Triggering unit))
- Destructible - Pick every destructible within 256.00 of YourUnit_Point and do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- (Distance between YourUnit_Point and (Position of (Picked destructible))) Less than or equal to 256.00
- Then - Actions
- Else - Actions
- Actions
- Set TreeType = Ashenvale Tree Wall
- Set YourUnit = (Triggering unit)
- Set YourUnitPoint = (Position of YourUnit)
- Set DestructibleCounter = 0
- Destructible - Pick every destructible within 256.00 of YourUnitPoint and do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- (Destructible-type of (Picked destructible)) Equal to TreeType
- Then - Actions
- Set DestructibleCounter = (DestructibleCounter + 1)
- Else - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- DestructibleCounter Greater than 0
- Then - Actions
- - Setting Boolean that you found a tree -
- Else - Actions
- - Setting Boolean that you didn't find a tree -
Gah this is why I hate WC3 GUI so much... At least in SC2 they give you the raw natives not wrapped in transparent wrappers that do stuff you clearly do not want them to.It is not true. The limit is none. Limit exists only if you use TriggerRegisterDestDeathInRegionEvent:
It is not true. The limit is none. Limit exists only if you use TriggerRegisterDestDeathInRegionEvent:
And the most important part:JASS:function RegisterDestDeathInRegionEnum takes nothing returns nothing set bj_destInRegionDiesCount = bj_destInRegionDiesCount + 1 if (bj_destInRegionDiesCount <= bj_MAX_DEST_IN_REGION_EVENTS) then call TriggerRegisterDeathEvent(bj_destInRegionDiesTrig, GetEnumDestructable()) endif endfunction function TriggerRegisterDestDeathInRegionEvent takes trigger trig, rect r returns event set bj_destInRegionDiesTrig = trig set bj_destInRegionDiesCount = 0 call EnumDestructablesInRect(r, null, function RegisterDestDeathInRegionEnum) return trig endfunction
constant integer bj_MAX_DEST_IN_REGION_EVENTS = 64
If such limit would restrict all of enum functions, then all of my dest-related resources were trash.
Have you even read the lib's description? You can choose varienty of function (related to dest, item, unit and group), thus you could call for example: GetClosestDestructableInRange. By specifing radius value, you can check if a e.g tree exists within circle 10000.0 units away from point "p". Read before posting false opinions.
Yeh it is only 10 years old... How many 10 year old games are still supported?War3 lost support quickly in general.
Bannar said:Have you even read the lib's description? You can choose varienty of function (related to dest, item, unit and group), thus you could call for example: GetClosestDestructableInRange. By specifing radius value, you can check if a e.g tree exists within circle 10000.0 units away from point "p". Read before posting false opinions.
jondrean said:Gcw is not useful in this case.
Bannar said:JASS:// where x, y mark coords while filter being a filter function - check for "trees-only" set tree = GetClosestDestructable(x, y, Filter(function filter))
edo494 said:you know you can check the distance from the x, y points and the tree,
GetClosestDestructableInRange
which was unfortunately absent from the example you gave . sethmachine said:I believe jonhysone's GUI will work for your need (I think the fourth one works correctly).
edo494 said:only the last one will work afaik, because if you try to enumerate trees, there is no way you will get "No destructable" in enumeration, if you dont pick any trees, it will not run the loop body even once, so the last approach is the only correct one
function IsTree_impl takes nothing returns boolean
return IsTree(GetEnumDestructable())
//I imagine you pass in enum destructable
//there is resource for this
endfunction
function IsTreeNearby takes real x, real y, real nearby returns boolean
local destructable d = GetClosestDestructable(x, y, Filter(function IsTree))
local real xDist = 0
local real yDist = 0
if (d == null) then
return false
endif
set xDist = GetDestructableX(d) - x
set yDist = GetDestructableY(d) - y
return nearby * nearby < (xDist * xDist + yDist * yDist)
endfunction
As I pointed out, this just returns the closest tree, but the OP wants to tell whether a tree is nearby
native EnumDestructablesInRect takes rect r, boolexpr filter, code actionFunc returns nothing
You can provide both, filter and code function.static method istree takes nothing returns boolean
return IsDestructableTree(GetFilterDestructable())
endmethod
// some random print function
call print("closest tree: ", GetClosestDestructable(x, y, Filter(function thistype.istree)))