User Tools

Site Tools


4rpl:commands:getunits

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
4rpl:commands:getunits [2021/09/13 19:09] Grabz4rpl:commands:getunits [2024/03/21 18:05] (current) – Fixed minor conflation of UID with GUID qople
Line 9: Line 9:
 Returns list of units in range of a given position. The returned list is sorted so that the first item in the list is the closest.\\  Returns list of units in range of a given position. The returned list is sorted so that the first item in the list is the closest.\\ 
  
-:!**Note:** The difference between this API and [[GetUnitsInRange]] is this API takes 'unitType' parameter By specifying a unitTypeless units are searched over resulting in potentially higher performanceFurthermoreGetUnits can search for any units regardless of whether they occupy spaceso units that are in flight can be found this way as well\\  +  ? unitType: 
-GetUnits takes a unit type and from that it will internally find all units of that type.  It then enumerates those units and checks if they are in range and if they match the state filtersSo GetUnits can be used to find any unit (airmapor neither). This method can be more performant than GetUnitsInRange if the unit being searched is not found in large quantities on the map.+  a string indicating the [[unit types|unit type]]((Unit Type can also be the GUID of CMOD)) to returnIf empty string ("")then all units are searched
 +  ? startPos: 
 +  : a V3 (vector3) indicating the point to search outwards from. 
 +  ? range: 
 +  : a floating point number that is the maximum distance from startPos. 
 +  ? isSquare: 
 +  : a boolean. It means to check in a square rather than a circle around startPosFor 3D checksthe vertical displacement is also checked (so the range is effectivly a cube rather than a sphere). :!: __Bug__: if isSquare is true, then the startPos vector will ignore the Z-value. 
 +  ? is3D: 
 +  : a boolean. It determines if a true 3d distance is used for range, or if only the X and Z components (2D) distance calculation is used. 
 +  ? requireLOS: 
 +  : a boolean indicating if terrain line of sight is required. 
 +  ? enemyState: 
 +  : an int (either 0,1,2). 0 = ignore enemy status. 1 = Only find units that are enemies2 = Only find units that are not enemies. 
 +  ? builtState: 
 +  : an int (either 0,1,2). 0 = ignore built state. 1 = Only find units that are built2 = Only find units that are not built. 
 +  ? imperviousState: 
 +  : an int (either 0,1,2). 0 = ignore impervious state. 1 = Only find units that are not impervious. 2 = Only find units that are impervious. Things like ore deposits are impervious.
  
-  * **unitType:** a string indicating the [[unit types|unit type]]((Unit Type can also be the UID of a CMOD)) to return. If empty string (""), then all units are searched.\\ +For short range searches refer to the [[cw4:4rpl_unit_search_analysis|unit search analysis]] to see how the different parameters interact with finding units in a short range.
-  * **startPos:** a V3 (vector3) indicating the point to search outwards from.\\ +
-  * **range:** a floating point number that is the maximum distance from startPos.\\ +
-  * **isSquare:** a boolean. It means to check in a square rather than a circle around startPos. For 3D checks, the vertical displacement is also checked (so the range is effectivly a cube rather than a sphere). \\ +
-  * **is3D:** a boolean. It determines if a true 3d distance is used for range, or if only the X and Z components (2D) distance calculation is used.\\ +
-  * **requireLOS:** a boolean indicating if terrain line of sight is required.\\ +
-  * **enemyState:** an int (either 0,1,2). 0 = ignore enemy status. 1 = Only find units that are enemies. 2 = Only find units that are not enemies.\\ +
-  * **builtState:** an int (either 0,1,2). 0 = ignore built state. 1 = Only find units that are built. 2 = Only find units that are not built.\\ +
-  * **imperviousState:** an int (either 0,1,2). 0 = ignore impervious state. 1 = Only find units that are not impervious. 2 = Only find units that are impervious. Things like ore deposits are impervious.\\+
  
 ===== Examples ===== ===== Examples =====
Line 39: Line 47:
 </code> </code>
  
-=== Usage Notes === +=== Notes === 
-[[GetUnits]] takes a unit type and from that it will internally find all units of that type.  It then enumerates those units and checks if they are in range and if they match the state filters.  So [[GetUnits]] can be used to find any unit (air, map, or neither). [[GetUnitsInRange]] doesn't take a unit type.  It just searches in a range around the specified coordinates.  It only finds units that leave a footprint on the map.  So it won'work for flying units (or land based units that are moving).+  ** The difference between this API and [[GetUnitsInRange]] is this API takes a 'unitType' parameter.  By specifying a unitType, fewer units are searched over resulting in potentially higher performance. Furthermore, GetUnits can search for any units regardless of whether they occupy space, so units that are in flight can be found this way as well. 
 +  .. GetUnits takes a unit type and from that it will internally find all units of that type.  It then enumerates those units and checks if they are in range and if they match the state filters. So GetUnits can be used to find any unit (air, map, or neither). This method can be more performant than GetUnitsInRange if the unit being searched is not found in large quantities on the map. 
 +  * 2D square search is currently broken and will find all units as long as they are close enough on X-axis, disregarding the Z-axisDo not use this combination of parameters.  
 + 
 +  * The units "ern" and "pterosaur" will be picked up by a search looking for non-enemy built **non-impervious** units. If you need to avoid picking up those see if GetUnitsInRange is a more appropriate method (it doesn'pick up units in the air). If not, you may have to manually clean those from the list.
  
  
 === See Also === === See Also ===
-  * [[4rpl:commands:getunitsinrange]]+  * [[GetUnitsInRange]]
  
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
4rpl/commands/getunits.1631574541.txt.gz · Last modified: 2021/09/13 19:09 by Grabz