plugins/include/sdktools_trace.inc
author David Anderson <dvander@alliedmods.net>
Sun Aug 25 14:04:01 2013 -0700 (2013-08-25)
changeset 4080 38650aa82c76
parent 2780 4b04744461ac
permissions -rw-r--r--
Fix build.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     9  * This program is free software; you can redistribute it and/or modify it under
    10  * the terms of the GNU General Public License, version 3.0, as published by the
    11  * Free Software Foundation.
    12  * 
    13  * This program is distributed in the hope that it will be useful, but WITHOUT
    14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    16  * details.
    17  *
    18  * You should have received a copy of the GNU General Public License along with
    19  * this program.  If not, see <http://www.gnu.org/licenses/>.
    20  *
    21  * As a special exception, AlliedModders LLC gives you permission to link the
    22  * code of this program (as well as its derivative works) to "Half-Life 2," the
    23  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    24  * by the Valve Corporation.  You must obey the GNU General Public License in
    25  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    26  * this exception to all derivative works.  AlliedModders LLC defines further
    27  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    28  * or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #if defined _sdktools_trace_included
    34  #endinput
    35 #endif
    36 #define _sdktools_trace_included
    37 
    38 #define	CONTENTS_EMPTY			0		/**< No contents. */
    39 #define	CONTENTS_SOLID			0x1		/**< an eye is never valid in a solid . */
    40 #define	CONTENTS_WINDOW			0x2		/**< translucent, but not watery (glass). */
    41 #define	CONTENTS_AUX			0x4
    42 #define	CONTENTS_GRATE			0x8		/**< alpha-tested "grate" textures.  Bullets/sight pass through, but solids don't. */
    43 #define	CONTENTS_SLIME			0x10
    44 #define	CONTENTS_WATER			0x20
    45 #define	CONTENTS_MIST			0x40
    46 #define CONTENTS_OPAQUE			0x80		/**< things that cannot be seen through (may be non-solid though). */
    47 #define	LAST_VISIBLE_CONTENTS	0x80
    48 #define ALL_VISIBLE_CONTENTS 	(LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1))
    49 #define CONTENTS_TESTFOGVOLUME	0x100
    50 #define CONTENTS_UNUSED5		0x200
    51 #define CONTENTS_UNUSED6		0x4000
    52 #define CONTENTS_TEAM1			0x800		/**< per team contents used to differentiate collisions. */
    53 #define CONTENTS_TEAM2			0x1000		/**< between players and objects on different teams. */
    54 #define CONTENTS_IGNORE_NODRAW_OPAQUE	0x2000		/**< ignore CONTENTS_OPAQUE on surfaces that have SURF_NODRAW. */
    55 #define CONTENTS_MOVEABLE		0x4000		/**< hits entities which are MOVETYPE_PUSH (doors, plats, etc) */
    56 #define	CONTENTS_AREAPORTAL		0x8000		/**< remaining contents are non-visible, and don't eat brushes. */
    57 #define	CONTENTS_PLAYERCLIP		0x10000
    58 #define	CONTENTS_MONSTERCLIP	0x20000
    59 
    60 /**
    61  * @section currents can be added to any other contents, and may be mixed
    62  */
    63 #define	CONTENTS_CURRENT_0		0x40000
    64 #define	CONTENTS_CURRENT_90		0x80000
    65 #define	CONTENTS_CURRENT_180	0x100000
    66 #define	CONTENTS_CURRENT_270	0x200000
    67 #define	CONTENTS_CURRENT_UP		0x400000
    68 #define	CONTENTS_CURRENT_DOWN	0x800000
    69 
    70 /**
    71  * @endsection
    72  */
    73 
    74 #define	CONTENTS_ORIGIN			0x1000000	/**< removed before bsping an entity. */
    75 #define	CONTENTS_MONSTER		0x2000000	/**< should never be on a brush, only in game. */
    76 #define	CONTENTS_DEBRIS			0x4000000
    77 #define	CONTENTS_DETAIL			0x8000000	/**< brushes to be added after vis leafs. */
    78 #define	CONTENTS_TRANSLUCENT	0x10000000	/**< auto set if any surface has trans. */
    79 #define	CONTENTS_LADDER			0x20000000
    80 #define CONTENTS_HITBOX			0x40000000	/**< use accurate hitboxes on trace. */
    81 
    82 /**
    83  * @section Trace masks.
    84  */
    85 #define	MASK_ALL				(0xFFFFFFFF)
    86 #define	MASK_SOLID				(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) 			/**< everything that is normally solid */
    87 #define	MASK_PLAYERSOLID		(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) 	/**< everything that blocks player movement */
    88 #define	MASK_NPCSOLID			(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< blocks npc movement */
    89 #define	MASK_WATER				(CONTENTS_WATER|CONTENTS_MOVEABLE|CONTENTS_SLIME) 							/**< water physics in these contents */
    90 #define	MASK_OPAQUE				(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_OPAQUE) 							/**< everything that blocks line of sight for AI, lighting, etc */
    91 #define MASK_OPAQUE_AND_NPCS	(MASK_OPAQUE|CONTENTS_MONSTER)										/**< everything that blocks line of sight for AI, lighting, etc, but with monsters added. */
    92 #define	MASK_VISIBLE			(MASK_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE) 								/**< everything that blocks line of sight for players */
    93 #define MASK_VISIBLE_AND_NPCS	(MASK_OPAQUE_AND_NPCS|CONTENTS_IGNORE_NODRAW_OPAQUE) 							/**< everything that blocks line of sight for players, but with monsters added. */
    94 #define	MASK_SHOT				(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX) 	/**< bullets see these as solid */
    95 #define MASK_SHOT_HULL			(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_GRATE) 	/**< non-raycasted weapons see this as solid (includes grates) */
    96 #define MASK_SHOT_PORTAL		(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW) 							/**< hits solids (not grates) and passes through everything else */
    97 #define MASK_SOLID_BRUSHONLY	(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE) 					/**< everything normally solid, except monsters (world+brush only) */
    98 #define MASK_PLAYERSOLID_BRUSHONLY	(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_PLAYERCLIP|CONTENTS_GRATE) 			/**< everything normally solid for player movement, except monsters (world+brush only) */
    99 #define MASK_NPCSOLID_BRUSHONLY	(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) 			/**< everything normally solid for npc movement, except monsters (world+brush only) */
   100 #define MASK_NPCWORLDSTATIC		(CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) 					/**< just the world, used for route rebuilding */
   101 #define MASK_SPLITAREAPORTAL	(CONTENTS_WATER|CONTENTS_SLIME) 									/**< These are things that can split areaportals */
   102 
   103 /**
   104  * @endsection
   105  */
   106 
   107 enum RayType
   108 {
   109 	RayType_EndPoint,	/**< The trace ray will go from the start position to the end position. */
   110 	RayType_Infinite	/**< The trace ray will go from the start position to infinity using a direction vector. */
   111 };
   112 
   113 funcenum TraceEntityFilter
   114 {
   115 	/**
   116 	 * Called on entity filtering.
   117 	 *
   118 	 * @param entity		Entity index.
   119  	 * @param contentsMask	Contents Mask.
   120  	 * @return				True to allow the current entity to be hit, otherwise false.
   121  	 */
   122 	bool:public(entity, contentsMask),
   123 	
   124 	/**
   125 	 * Called on entity filtering.
   126 	 *
   127 	 * @param entity		Entity index.
   128  	 * @param contentsMask	Contents Mask.
   129  	 * @param data			Data value, if used.
   130  	 * @return				True to allow the current entity to be hit, otherwise false.
   131  	 */
   132 	bool:public(entity, contentsMask, any:data),
   133 };
   134 
   135 /**
   136  * Get the contents mask and the entity index at the given position.
   137  *
   138  * @param pos			World position to test.
   139  * @param entindex		Entity index found at the given position (by reference).
   140  * @return				Contents mask.
   141  */
   142 native TR_GetPointContents(const Float:pos[3], &entindex=-1);
   143 
   144 /**
   145  * Get the point contents testing only the given entity index.
   146  *
   147  * @param entindex		Entity index to test.
   148  * @param pos			World position.
   149  * @return				Contents mask.
   150  */
   151 native TR_GetPointContentsEnt(entindex, const Float:pos[3]);
   152 
   153 /**
   154  * Starts up a new trace ray using a global trace result.
   155  *
   156  * @param pos			Starting position of the ray.
   157  * @param vec			Depending on RayType, it will be used as the
   158  *						ending point, or the direction angle.
   159  * @param flags			Trace flags.
   160  * @param rtype			Method to calculate the ray direction.
   161  * @noreturn
   162  */
   163 native TR_TraceRay(const Float:pos[3],
   164 				   const Float:vec[3],
   165 				   flags,
   166 				   RayType:rtype);
   167 				   
   168 /**
   169  * Starts up a new trace hull using a global trace result.
   170  *
   171  * @param pos			Starting position of the ray.
   172  * @param vec			Ending position of the ray.
   173  * @param mins			Hull minimum size.
   174  * @param maxs			Hull maximum size.
   175  * @param flags			Trace flags.
   176  * @noreturn
   177  */
   178 native TR_TraceHull(const Float:pos[3],
   179 					const Float:vec[3],
   180 					const Float:mins[3],
   181 					const Float:maxs[3],
   182 					flags);
   183 
   184 /**
   185  * Starts up a new trace ray using a global trace result and a customized 
   186  * trace ray filter.
   187  *
   188  * Calling TR_Trace*Filter or TR_Trace*FilterEx from inside a filter 
   189  * function is currently not allowed and may not work.
   190  *
   191  * @param pos			Starting position of the ray.
   192  * @param vec			Depending on RayType, it will be used as the ending 
   193  *						point, or the direction angle.
   194  * @param flags			Trace flags.
   195  * @param rtype			Method to calculate the ray direction.
   196  * @param filter		Function to use as a filter.
   197  * @param data			Arbitrary data value to pass through to the filter 
   198  *						function.
   199  * @noreturn
   200  */
   201 native TR_TraceRayFilter(const Float:pos[3],
   202 						 const Float:vec[3],
   203 						 flags,
   204 						 RayType:rtype,
   205 						 TraceEntityFilter:filter,
   206 						 any:data=0);
   207 						 
   208 /**
   209  * Starts up a new trace hull using a global trace result and a customized 
   210  * trace ray filter.
   211  *
   212  * Calling TR_Trace*Filter or TR_Trace*FilterEx from inside a filter 
   213  * function is currently not allowed and may not work.
   214  *
   215  * @param pos			Starting position of the ray.
   216  * @param vec			Depending on RayType, it will be used as the ending 
   217  *						point, or the direction angle.
   218  * @param mins			Hull minimum size.
   219  * @param maxs			Hull maximum size.
   220  * @param flags			Trace flags.
   221  * @param filter		Function to use as a filter.
   222  * @param data			Arbitrary data value to pass through to the filter 
   223  *						function.
   224  * @noreturn
   225  */
   226 native TR_TraceHullFilter(const Float:pos[3],
   227 						  const Float:vec[3],
   228 						  const Float:mins[3],
   229 						  const Float:maxs[3],
   230 						  flags,
   231 						  TraceEntityFilter:filter,
   232 						  any:data=0);
   233 
   234 /**
   235  * Starts up a new trace ray using a new trace result.
   236  *
   237  * @param pos			Starting position of the ray.
   238  * @param vec			Depending on RayType, it will be used as the ending 
   239  *						point, or the direction angle.
   240  * @param flags			Trace flags.
   241  * @param rtype			Method to calculate the ray direction.
   242  * @return				Ray trace handle, which must be closed via CloseHandle().
   243  */
   244 native Handle:TR_TraceRayEx(const Float:pos[3],
   245 							const Float:vec[3],
   246 							flags,
   247 							RayType:rtype);
   248 							
   249 /**
   250  * Starts up a new trace hull using a new trace result.
   251  *
   252  * @param pos			Starting position of the ray.
   253  * @param vec			Ending position of the ray.
   254  * @param mins			Hull minimum size.
   255  * @param maxs			Hull maximum size.
   256  * @param flags			Trace flags.
   257  * @return				Ray trace handle, which must be closed via CloseHandle().
   258  */
   259 native Handle:TR_TraceHullEx(const Float:pos[3],
   260 							 const Float:vec[3],
   261 							 const Float:mins[3],
   262 							 const Float:maxs[3],
   263 							 flags);
   264 
   265 /**
   266  * Starts up a new trace ray using a new trace result and a customized 
   267  * trace ray filter.
   268  *
   269  * Calling TR_Trace*Filter or TR_TraceRay*Ex from inside a filter 
   270  * function is currently not allowed and may not work.
   271  *
   272  * @param pos			Starting position of the ray.
   273  * @param vec			Depending on RayType, it will be used as the ending 
   274  *						point, or the direction angle.
   275  * @param flags			Trace flags.
   276  * @param rtype			Method to calculate the ray direction.
   277  * @param filter		Function to use as a filter.
   278  * @param data			Arbitrary data value to pass through to the filter function.
   279  * @return				Ray trace handle, which must be closed via CloseHandle().
   280  */
   281 native Handle:TR_TraceRayFilterEx(const Float:pos[3], 
   282 								  const Float:vec[3],
   283 								  flags, 
   284 								  RayType:rtype, 
   285 								  TraceEntityFilter:filter,
   286 								  any:data=0);
   287 								  
   288 /**
   289  * Starts up a new trace hull using a new trace result and a customized 
   290  * trace ray filter.
   291  *
   292  * Calling TR_Trace*Filter or TR_Trace*FilterEx from inside a filter 
   293  * function is currently not allowed and may not work.
   294  *
   295  * @param pos			Starting position of the ray.
   296  * @param vec			Ending position of the ray.
   297  * @param mins			Hull minimum size.
   298  * @param maxs			Hull maximum size.
   299  * @param flags			Trace flags.
   300  * @param filter		Function to use as a filter.
   301  * @param data			Arbitrary data value to pass through to the filter function.
   302  * @return				Ray trace handle, which must be closed via CloseHandle().
   303  */
   304 native Handle:TR_TraceHullFilterEx(const Float:pos[3], 
   305 								   const Float:vec[3],
   306 								   const Float:mins[3],
   307 								   const Float:maxs[3],
   308 								   flags, 
   309 								   TraceEntityFilter:filter,
   310 								   any:data=0);
   311 
   312 /**
   313  * Returns the time fraction from a trace result (1.0 means no collision).
   314  *
   315  * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
   316  * @return				Time fraction value of the trace.
   317  * @error				Invalid Handle.
   318  */
   319 native Float:TR_GetFraction(Handle:hndl=INVALID_HANDLE);
   320 
   321 /**
   322  * Returns the collision position of a trace result.
   323  *
   324  * @param pos			Vector buffer to store data in.
   325  * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
   326  * @noreturn
   327  * @error				Invalid Handle.
   328  */
   329 native TR_GetEndPosition(Float:pos[3], Handle:hndl=INVALID_HANDLE);
   330 
   331 /**
   332  * Returns the entity index that collided with the trace.
   333  *
   334  * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
   335  * @return				Entity index or -1 for no collision.
   336  * @error				Invalid Handle.
   337  */
   338 native TR_GetEntityIndex(Handle:hndl=INVALID_HANDLE);
   339 
   340 /**
   341  * Returns if there was any kind of collision along the trace ray.
   342  *
   343  * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
   344  * @return				True if any collision found, otherwise false.
   345  * @error				Invalid Handle.
   346  */
   347 native bool:TR_DidHit(Handle:hndl=INVALID_HANDLE);
   348 
   349 /**
   350  * Returns in which body hit group the trace collided if any.
   351  *
   352  * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
   353  * @return				Body hit group.
   354  * @error				Invalid Handle.
   355  */
   356 native TR_GetHitGroup(Handle:hndl=INVALID_HANDLE);
   357 
   358 /**
   359  * Find the normal vector to the collison plane of a trace.
   360  *
   361  * @param hndl		A trace Handle, or INVALID_HANDLE to use a global trace result.
   362  * @param normal	Vector buffer to store the vector normal to the collision plane
   363  * @noreturn
   364  * @error			Invalid Handle
   365  */
   366 native TR_GetPlaneNormal(Handle:hndl, Float:normal[3]);
   367 
   368 /**
   369  * Tests a point to see if it's outside any playable area
   370  *
   371  * @param pos		Vector buffer to store data in.
   372  * @return		True if outside world, otherwise false.
   373  */
   374 native TR_PointOutsideWorld(Float:pos[3]);