plugins/include/sdktools_trace.inc
author Borja Ferrer <faluco@alliedmods.net>
Sun Jul 08 19:39:19 2007 +0000 (2007-07-08)
changeset 1075 6ebd28ffd880
child 1330 ab94316bb52b
permissions -rw-r--r--
added code for trace rays + natives
faluco@1075
     1
/**
faluco@1075
     2
 * vim: set ts=4 :
faluco@1075
     3
 * ===============================================================
faluco@1075
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
faluco@1075
     5
 * ===============================================================
faluco@1075
     6
 *
faluco@1075
     7
 *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
faluco@1075
     8
 * or modified under the Terms and Conditions of its License Agreement, which is found 
faluco@1075
     9
 * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
faluco@1075
    10
 * may change at any time.  To view the latest information, see:
faluco@1075
    11
 *   http://www.sourcemod.net/license.php
faluco@1075
    12
 *
faluco@1075
    13
 * Version: $Id$
faluco@1075
    14
 */
faluco@1075
    15
faluco@1075
    16
#if defined _sdktools_trace_included
faluco@1075
    17
 #endinput
faluco@1075
    18
#endif
faluco@1075
    19
#define _sdktools_trace_included
faluco@1075
    20
faluco@1075
    21
#define	CONTENTS_EMPTY			0		/**< No contents. */
faluco@1075
    22
#define	CONTENTS_SOLID			0x1		/**< an eye is never valid in a solid . */
faluco@1075
    23
#define	CONTENTS_WINDOW			0x2		/**< translucent, but not watery (glass). */
faluco@1075
    24
#define	CONTENTS_AUX			0x4
faluco@1075
    25
#define	CONTENTS_GRATE			0x8		/**< alpha-tested "grate" textures.  Bullets/sight pass through, but solids don't. */
faluco@1075
    26
#define	CONTENTS_SLIME			0x10
faluco@1075
    27
#define	CONTENTS_WATER			0x20
faluco@1075
    28
#define	CONTENTS_MIST			0x40
faluco@1075
    29
#define CONTENTS_OPAQUE			0x80		/**< things that cannot be seen through (may be non-solid though). */
faluco@1075
    30
#define	LAST_VISIBLE_CONTENTS		0x80
faluco@1075
    31
#define ALL_VISIBLE_CONTENTS 		(LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1))
faluco@1075
    32
#define CONTENTS_TESTFOGVOLUME		0x100
faluco@1075
    33
#define CONTENTS_UNUSED5		0x200
faluco@1075
    34
#define CONTENTS_UNUSED6		0x4000
faluco@1075
    35
#define CONTENTS_TEAM1			0x800		/**< per team contents used to differentiate collisions. */
faluco@1075
    36
#define CONTENTS_TEAM2			0x1000		/**< between players and objects on different teams. */
faluco@1075
    37
#define CONTENTS_IGNORE_NODRAW_OPAQUE	0x2000		/**< ignore CONTENTS_OPAQUE on surfaces that have SURF_NODRAW. */
faluco@1075
    38
#define CONTENTS_MOVEABLE		0x4000		/**< hits entities which are MOVETYPE_PUSH (doors, plats, etc) */
faluco@1075
    39
#define	CONTENTS_AREAPORTAL		0x8000		/**< remaining contents are non-visible, and don't eat brushes. */
faluco@1075
    40
#define	CONTENTS_PLAYERCLIP		0x10000
faluco@1075
    41
#define	CONTENTS_MONSTERCLIP		0x20000
faluco@1075
    42
faluco@1075
    43
/**
faluco@1075
    44
 * @section currents can be added to any other contents, and may be mixed
faluco@1075
    45
 */
faluco@1075
    46
#define	CONTENTS_CURRENT_0		0x40000
faluco@1075
    47
#define	CONTENTS_CURRENT_90		0x80000
faluco@1075
    48
#define	CONTENTS_CURRENT_180		0x100000
faluco@1075
    49
#define	CONTENTS_CURRENT_270		0x200000
faluco@1075
    50
#define	CONTENTS_CURRENT_UP		0x400000
faluco@1075
    51
#define	CONTENTS_CURRENT_DOWN		0x800000
faluco@1075
    52
faluco@1075
    53
/**
faluco@1075
    54
 * @endsection
faluco@1075
    55
 */
faluco@1075
    56
faluco@1075
    57
#define	CONTENTS_ORIGIN			0x1000000	/**< removed before bsping an entity. */
faluco@1075
    58
#define	CONTENTS_MONSTER		0x2000000	/**< should never be on a brush, only in game. */
faluco@1075
    59
#define	CONTENTS_DEBRIS			0x4000000
faluco@1075
    60
#define	CONTENTS_DETAIL			0x8000000	/**< brushes to be added after vis leafs. */
faluco@1075
    61
#define	CONTENTS_TRANSLUCENT		0x10000000	/**< auto set if any surface has trans. */
faluco@1075
    62
#define	CONTENTS_LADDER			0x20000000
faluco@1075
    63
#define CONTENTS_HITBOX			0x40000000	/**< use accurate hitboxes on trace. */
faluco@1075
    64
faluco@1075
    65
/**
faluco@1075
    66
 * @section Trace masks.
faluco@1075
    67
 */
faluco@1075
    68
#define	MASK_ALL			(0xFFFFFFFF)
faluco@1075
    69
#define	MASK_SOLID			(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) 			/**< everything that is normally solid */
faluco@1075
    70
#define	MASK_PLAYERSOLID		(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) 	/**< everything that blocks player movement */
faluco@1075
    71
#define	MASK_NPCSOLID			(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER|CONTENTS_GRATE) /**< blocks npc movement */
faluco@1075
    72
#define	MASK_WATER			(CONTENTS_WATER|CONTENTS_MOVEABLE|CONTENTS_SLIME) 							/**< water physics in these contents */
faluco@1075
    73
#define	MASK_OPAQUE			(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_OPAQUE) 							/**< everything that blocks line of sight for AI, lighting, etc */
faluco@1075
    74
#define MASK_OPAQUE_AND_NPCS		(MASK_OPAQUE|CONTENTS_MONSTER)										/**< everything that blocks line of sight for AI, lighting, etc, but with monsters added. */
faluco@1075
    75
#define	MASK_VISIBLE			(MASK_OPAQUE|CONTENTS_IGNORE_NODRAW_OPAQUE) 								/**< everything that blocks line of sight for players */
faluco@1075
    76
#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. */
faluco@1075
    77
#define	MASK_SHOT			(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEBRIS|CONTENTS_HITBOX) 	/**< bullets see these as solid */
faluco@1075
    78
#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) */
faluco@1075
    79
#define MASK_SHOT_PORTAL		(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW) 							/**< hits solids (not grates) and passes through everything else */
faluco@1075
    80
#define MASK_SOLID_BRUSHONLY		(CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_WINDOW|CONTENTS_GRATE) 					/**< everything normally solid, except monsters (world+brush only) */
faluco@1075
    81
#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) */
faluco@1075
    82
#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) */
faluco@1075
    83
#define MASK_NPCWORLDSTATIC		(CONTENTS_SOLID|CONTENTS_WINDOW|CONTENTS_MONSTERCLIP|CONTENTS_GRATE) 					/**< just the world, used for route rebuilding */
faluco@1075
    84
#define MASK_SPLITAREAPORTAL		(CONTENTS_WATER|CONTENTS_SLIME) 									/**< These are things that can split areaportals */
faluco@1075
    85
faluco@1075
    86
/**
faluco@1075
    87
 * @endsection
faluco@1075
    88
 */
faluco@1075
    89
faluco@1075
    90
enum RayType
faluco@1075
    91
{
faluco@1075
    92
	RayType_EndPoint,	/**< The trace ray will go from the start position to the end position. */
faluco@1075
    93
	RayType_Infinite	/**< The trace ray will go from the start position to infinity using a direction vector. */
faluco@1075
    94
};
faluco@1075
    95
faluco@1075
    96
/**
faluco@1075
    97
 * Called on entity filtering.
faluco@1075
    98
 *
faluco@1075
    99
 * @param entity		Entity index.
faluco@1075
   100
 * @param contentsMask		Contents Mask.
faluco@1075
   101
 * @return			True to allow the current entity to be hit, otherwise false.
faluco@1075
   102
 */
faluco@1075
   103
functag TraceEntityFilter bool:public(entity, contentsMask);
faluco@1075
   104
faluco@1075
   105
/**
faluco@1075
   106
 * Get the contents mask and the entity index at the given position.
faluco@1075
   107
 *
faluco@1075
   108
 * @param pos			World position to test.
faluco@1075
   109
 * @param entindex		Entity index found at the given position (by reference).
faluco@1075
   110
 * @return			Contents mask.
faluco@1075
   111
 */
faluco@1075
   112
native TR_GetPointContents(const Float:pos[3], &entindex=-1);
faluco@1075
   113
faluco@1075
   114
/**
faluco@1075
   115
 * Get the point contents testing only the given entity index.
faluco@1075
   116
 *
faluco@1075
   117
 * @param entindex		Entity index to test.
faluco@1075
   118
 * @param pos			World position.
faluco@1075
   119
 * @return			Contents mask.
faluco@1075
   120
 */
faluco@1075
   121
native TR_GetPointContentsEnt(entindex, const Float:pos[3]);
faluco@1075
   122
faluco@1075
   123
/**
faluco@1075
   124
 * Starts up a new trace ray using a global trace result.
faluco@1075
   125
 *
faluco@1075
   126
 * @param pos			Starting position of the ray.
faluco@1075
   127
 * @param vec			Depending on RayType, it will be used as the ending point, or the direction angle.
faluco@1075
   128
 * @param flags			Trace flags.
faluco@1075
   129
 * @param rtype			Method to calculate the ray direction.
faluco@1075
   130
 * @noreturn
faluco@1075
   131
 */
faluco@1075
   132
native TR_TraceRay(const Float:pos[3], const Float:vec[3], flags, RayType:rtype);
faluco@1075
   133
faluco@1075
   134
/**
faluco@1075
   135
 * Starts up a new trace ray using a global trace result and a customized trace ray filter.
faluco@1075
   136
 *
faluco@1075
   137
 * @param pos			Starting position of the ray.
faluco@1075
   138
 * @param vec			Depending on RayType, it will be used as the ending point, or the direction angle.
faluco@1075
   139
 * @param flags			Trace flags.
faluco@1075
   140
 * @param rtype			Method to calculate the ray direction.
faluco@1075
   141
 * @param filter		Function to use as a filter.
faluco@1075
   142
 * @noreturn
faluco@1075
   143
 */
faluco@1075
   144
native TR_TraceRayFilter(const Float:pos[3], const Float:vec[3], flags, RayType:rtype, TraceEntityFilter:filter);
faluco@1075
   145
faluco@1075
   146
/**
faluco@1075
   147
 * Starts up a new trace ray using a new trace result.
faluco@1075
   148
 *
faluco@1075
   149
 * @param pos			Starting position of the ray.
faluco@1075
   150
 * @param vec			Depending on RayType, it will be used as the ending point, or the direction angle.
faluco@1075
   151
 * @param flags			Trace flags.
faluco@1075
   152
 * @param rtype			Method to calculate the ray direction.
faluco@1075
   153
 * @return			Ray trace handle.
faluco@1075
   154
 * @note Traces are closed with CloseHandle().
faluco@1075
   155
 */
faluco@1075
   156
native Handle:TR_TraceRayEx(const Float:pos[3], const Float:vec[3], flags, RayType:rtype);
faluco@1075
   157
faluco@1075
   158
/**
faluco@1075
   159
 * Starts up a new trace ray using a new trace result and a customized trace ray filter.
faluco@1075
   160
 *
faluco@1075
   161
 * @param pos			Starting position of the ray.
faluco@1075
   162
 * @param vec			Depending on RayType, it will be used as the ending point, or the direction angle.
faluco@1075
   163
 * @param flags			Trace flags.
faluco@1075
   164
 * @param rtype			Method to calculate the ray direction.
faluco@1075
   165
 * @param filter		Function to use as a filter.
faluco@1075
   166
 * @return			Ray trace handle.
faluco@1075
   167
 * @note Traces are closed with CloseHandle().
faluco@1075
   168
 */
faluco@1075
   169
native Handle:TR_TraceRayFilterEx(const Float:pos[3], const Float:vec[3], flags, RayType:rtype, TraceEntityFilter:filter);
faluco@1075
   170
faluco@1075
   171
/**
faluco@1075
   172
 * Returns the time fraction from a trace result (1.0 means no collision).
faluco@1075
   173
 *
faluco@1075
   174
 * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
faluco@1075
   175
 * @return			Time fraction value of the trace.
faluco@1075
   176
 * @error			Invalid Handle.
faluco@1075
   177
 */
faluco@1075
   178
native Float:TR_GetFraction(Handle:hndl=INVALID_HANDLE);
faluco@1075
   179
faluco@1075
   180
/**
faluco@1075
   181
 * Returns the collision position of a trace result.
faluco@1075
   182
 *
faluco@1075
   183
 * @param pos			Vector buffer to store data in.
faluco@1075
   184
 * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
faluco@1075
   185
 * @noreturn
faluco@1075
   186
 * @error			Invalid Handle.
faluco@1075
   187
 */
faluco@1075
   188
native TR_GetEndPosition(Float:pos[3], Handle:hndl=INVALID_HANDLE);
faluco@1075
   189
faluco@1075
   190
/**
faluco@1075
   191
 * Returns the entity index that collided with the trace.
faluco@1075
   192
 *
faluco@1075
   193
 * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
faluco@1075
   194
 * @return			Entity index or -1 for no collision.
faluco@1075
   195
 * @error			Invalid Handle.
faluco@1075
   196
 */
faluco@1075
   197
native TR_GetEntityIndex(Handle:hndl=INVALID_HANDLE);
faluco@1075
   198
faluco@1075
   199
/**
faluco@1075
   200
 * Returns if there was any kind of collision along the trace ray.
faluco@1075
   201
 *
faluco@1075
   202
 * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
faluco@1075
   203
 * @return			True if any collision found, otherwise false.
faluco@1075
   204
 * @error			Invalid Handle.
faluco@1075
   205
 */
faluco@1075
   206
native bool:TR_DidHit(Handle:hndl=INVALID_HANDLE);
faluco@1075
   207
faluco@1075
   208
/**
faluco@1075
   209
 * Returns in which body hit group the trace collided if any.
faluco@1075
   210
 *
faluco@1075
   211
 * @param hndl			A trace Handle, or INVALID_HANDLE to use a global trace result.
faluco@1075
   212
 * @return			Body hit group.
faluco@1075
   213
 * @error			Invalid Handle.
faluco@1075
   214
 */
faluco@1075
   215
native TR_GetHitGroup(Handle:hndl=INVALID_HANDLE);