plugins/include/entity_prop_stocks.inc
author Kyle Sanderson <kyle.leet@gmail.com>
Thu Jul 18 19:40:42 2013 -0400 (2013-07-18)
changeset 3953 ea7a34452243
parent 3722 641ee592dda6
child 3967 ceafb87d38a7
permissions -rw-r--r--
Make compile.sh set working dir to own dir (bug 5710, r=psychonic).
     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 _entity_prop_stocks_included
    34  #endinput
    35 #endif
    36 #define _entity_prop_stocks_included
    37 
    38 enum MoveType
    39 {
    40 	MOVETYPE_NONE = 0,			/**< never moves */
    41 	MOVETYPE_ISOMETRIC,			/**< For players */
    42 	MOVETYPE_WALK,				/**< Player only - moving on the ground */
    43 	MOVETYPE_STEP,				/**< gravity, special edge handling -- monsters use this */
    44 	MOVETYPE_FLY,				/**< No gravity, but still collides with stuff */
    45 	MOVETYPE_FLYGRAVITY,		/**< flies through the air + is affected by gravity */
    46 	MOVETYPE_VPHYSICS,			/**< uses VPHYSICS for simulation */
    47 	MOVETYPE_PUSH,				/**< no clip to world, push and crush */
    48 	MOVETYPE_NOCLIP,			/**< No gravity, no collisions, still do velocity/avelocity */
    49 	MOVETYPE_LADDER,			/**< Used by players only when going onto a ladder */
    50 	MOVETYPE_OBSERVER,			/**< Observer movement, depends on player's observer mode */
    51 	MOVETYPE_CUSTOM,			/**< Allows the entity to describe its own physics */
    52 };
    53 
    54 enum RenderMode
    55 {	
    56 	RENDER_NORMAL,			/**< src */
    57 	RENDER_TRANSCOLOR,		/**< c*a+dest*(1-a) */
    58 	RENDER_TRANSTEXTURE,	/**< src*a+dest*(1-a) */
    59 	RENDER_GLOW,			/**< src*a+dest -- No Z buffer checks -- Fixed size in screen space */
    60 	RENDER_TRANSALPHA,		/**< src*srca+dest*(1-srca) */
    61 	RENDER_TRANSADD,		/**< src*a+dest */
    62 	RENDER_ENVIRONMENTAL,	/**< not drawn, used for environmental effects */
    63 	RENDER_TRANSADDFRAMEBLEND, /**< use a fractional frame value to blend between animation frames */
    64 	RENDER_TRANSALPHAADD,	/**< src + dest*(1-a) */
    65 	RENDER_WORLDGLOW,		/**< Same as kRenderGlow but not fixed size in screen space */
    66 	RENDER_NONE,			/**< Don't render. */
    67 };
    68 
    69 enum RenderFx
    70 {	
    71 	RENDERFX_NONE = 0, 
    72 	RENDERFX_PULSE_SLOW, 
    73 	RENDERFX_PULSE_FAST, 
    74 	RENDERFX_PULSE_SLOW_WIDE, 
    75 	RENDERFX_PULSE_FAST_WIDE, 
    76 	RENDERFX_FADE_SLOW, 
    77 	RENDERFX_FADE_FAST, 
    78 	RENDERFX_SOLID_SLOW, 
    79 	RENDERFX_SOLID_FAST, 	   
    80 	RENDERFX_STROBE_SLOW, 
    81 	RENDERFX_STROBE_FAST, 
    82 	RENDERFX_STROBE_FASTER, 
    83 	RENDERFX_FLICKER_SLOW, 
    84 	RENDERFX_FLICKER_FAST,
    85 	RENDERFX_NO_DISSIPATION,
    86 	RENDERFX_DISTORT,			/**< Distort/scale/translate flicker */
    87 	RENDERFX_HOLOGRAM,			/**< kRenderFxDistort + distance fade */
    88 	RENDERFX_EXPLODE,			/**< Scale up really big! */
    89 	RENDERFX_GLOWSHELL,			/**< Glowing Shell */
    90 	RENDERFX_CLAMP_MIN_SCALE,	/**< Keep this sprite from getting very small (SPRITES only!) */
    91 	RENDERFX_ENV_RAIN,			/**< for environmental rendermode, make rain */
    92 	RENDERFX_ENV_SNOW,			/**<  "        "            "    , make snow */
    93 	RENDERFX_SPOTLIGHT,			/**< TEST CODE for experimental spotlight */
    94 	RENDERFX_RAGDOLL,			/**< HACKHACK: TEST CODE for signalling death of a ragdoll character */
    95 	RENDERFX_PULSE_FAST_WIDER,
    96 	RENDERFX_MAX
    97 };
    98 
    99 // These defines are for client button presses.
   100 #define IN_ATTACK		(1 << 0)
   101 #define IN_JUMP			(1 << 1)
   102 #define IN_DUCK			(1 << 2)
   103 #define IN_FORWARD		(1 << 3)
   104 #define IN_BACK			(1 << 4)
   105 #define IN_USE			(1 << 5)
   106 #define IN_CANCEL		(1 << 6)
   107 #define IN_LEFT			(1 << 7)
   108 #define IN_RIGHT		(1 << 8)
   109 #define IN_MOVELEFT		(1 << 9)
   110 #define IN_MOVERIGHT		(1 << 10)
   111 #define IN_ATTACK2		(1 << 11)
   112 #define IN_RUN			(1 << 12)
   113 #define IN_RELOAD		(1 << 13)
   114 #define IN_ALT1			(1 << 14)
   115 #define IN_ALT2			(1 << 15)
   116 #define IN_SCORE		(1 << 16)   	// Used by client.dll for when scoreboard is held down
   117 #define IN_SPEED		(1 << 17)	// Player is holding the speed key
   118 #define IN_WALK			(1 << 18)	// Player holding walk key
   119 #define IN_ZOOM			(1 << 19)	// Zoom key for HUD zoom
   120 #define IN_WEAPON1		(1 << 20)	// weapon defines these bits
   121 #define IN_WEAPON2		(1 << 21)	// weapon defines these bits
   122 #define IN_BULLRUSH		(1 << 22)
   123 #define IN_GRENADE1		(1 << 23)	// grenade 1
   124 #define IN_GRENADE2		(1 << 24)	// grenade 2
   125 #define IN_ATTACK3		(1 << 25)
   126 
   127 // Note: these are only for use with GetEntityFlags and SetEntityFlags
   128 //       and may not match the game's actual, internal m_fFlags values.
   129 // PLAYER SPECIFIC FLAGS FIRST BECAUSE WE USE ONLY A FEW BITS OF NETWORK PRECISION
   130 #define	FL_ONGROUND			(1 << 0)	// At rest / on the ground
   131 #define FL_DUCKING			(1 << 1)	// Player flag -- Player is fully crouched
   132 #define	FL_WATERJUMP			(1 << 2)	// player jumping out of water
   133 #define FL_ONTRAIN			(1 << 3)	// Player is _controlling_ a train, so movement commands should be ignored on client during prediction.
   134 #define FL_INRAIN			(1 << 4)	// Indicates the entity is standing in rain
   135 #define FL_FROZEN			(1 << 5)	// Player is frozen for 3rd person camera
   136 #define FL_ATCONTROLS			(1 << 6)	// Player can't move, but keeps key inputs for controlling another entity
   137 #define	FL_CLIENT			(1 << 7)	// Is a player
   138 #define FL_FAKECLIENT			(1 << 8)	// Fake client, simulated server side; don't send network messages to them
   139 // NOTE if you move things up, make sure to change this value
   140 #define PLAYER_FLAG_BITS		9
   141 // NON-PLAYER SPECIFIC (i.e., not used by GameMovement or the client .dll ) -- Can still be applied to players, though
   142 #define	FL_INWATER			(1 << 9)	// In water
   143 #define	FL_FLY				(1 << 10)	// Changes the SV_Movestep() behavior to not need to be on ground
   144 #define	FL_SWIM				(1 << 11)	// Changes the SV_Movestep() behavior to not need to be on ground (but stay in water)
   145 #define	FL_CONVEYOR			(1 << 12)
   146 #define	FL_NPC				(1 << 13)
   147 #define	FL_GODMODE			(1 << 14)
   148 #define	FL_NOTARGET			(1 << 15)
   149 #define	FL_AIMTARGET			(1 << 16)	// set if the crosshair needs to aim onto the entity
   150 #define	FL_PARTIALGROUND		(1 << 17)	// not all corners are valid
   151 #define FL_STATICPROP			(1 << 18)	// Eetsa static prop!		
   152 #define FL_GRAPHED			(1 << 19)	// worldgraph has this ent listed as something that blocks a connection
   153 #define FL_GRENADE			(1 << 20)
   154 #define FL_STEPMOVEMENT			(1 << 21)	// Changes the SV_Movestep() behavior to not do any processing
   155 #define FL_DONTTOUCH			(1 << 22)	// Doesn't generate touch functions, generates Untouch() for anything it was touching when this flag was set
   156 #define FL_BASEVELOCITY			(1 << 23)	// Base velocity has been applied this frame (used to convert base velocity into momentum)
   157 #define FL_WORLDBRUSH			(1 << 24)	// Not moveable/removeable brush entity (really part of the world, but represented as an entity for transparency or something)
   158 #define FL_OBJECT			(1 << 25)	// Terrible name. This is an object that NPCs should see. Missiles, for example.
   159 #define FL_KILLME			(1 << 26)	// This entity is marked for death -- will be freed by game DLL
   160 #define FL_ONFIRE			(1 << 27)	// You know...
   161 #define FL_DISSOLVING			(1 << 28)	// We're dissolving!
   162 #define FL_TRANSRAGDOLL			(1 << 29)	// In the process of turning into a client side ragdoll.
   163 #define FL_UNBLOCKABLE_BY_PLAYER	(1 << 30)	// pusher that can't be blocked by the player
   164 #define FL_FREEZING				(1 << 31)	// We're becoming frozen!
   165 #define FL_EP2V_UNKNOWN1		(1 << 31)	// Unknown
   166 // END entity flag #defines
   167 
   168 /**
   169  * Get an entity's flags.
   170  *
   171  * @note The game's actual flags are internally translated by SM
   172  *       to match the entity flags defined above as the actual values
   173  *       can differ per engine.
   174  *
   175  * @param entity	Entity index.
   176  * @return			Entity's flags, see entity flag defines above.
   177  * @error			Invalid entity index, or lack of mod compliance.
   178  */
   179 native GetEntityFlags(entity);
   180 
   181 /**
   182  * Sets an entity's flags.
   183  *
   184  * @note The entity flags as defined above are internally translated by SM
   185  *       to match the current game's expected value for the flags as
   186  *       the actual values can differ per engine.
   187  *
   188  * @param entity	Entity index.
   189  * @param flags		Entity flags, see entity flag defines above.
   190  * @noreturn
   191  * @error			Invalid entity index, or lack of mod compliance.
   192  */
   193 native SetEntityFlags(entity, flags);
   194 
   195 
   196 /**
   197  * Gets an entity's movetype.
   198  *
   199  * @param entity	Entity index.
   200  * @return			Movetype, see enum above.
   201  * @error			Invalid entity index, or lack of mod compliance.
   202  */
   203 stock MoveType:GetEntityMoveType(entity)
   204 {
   205 	static bool:gotconfig = false;
   206 	static String:datamap[32];
   207 	
   208 	if (!gotconfig)
   209 	{
   210 		new Handle:gc = LoadGameConfigFile("core.games");
   211 		new bool:exists = GameConfGetKeyValue(gc, "m_MoveType", datamap, sizeof(datamap));
   212 		CloseHandle(gc);
   213 		
   214 		if (!exists)
   215 		{
   216 			strcopy(datamap, sizeof(datamap), "m_MoveType");
   217 		}
   218 		
   219 		gotconfig = true;
   220 	}
   221 	
   222 	return MoveType:GetEntProp(entity, Prop_Data, datamap);
   223 }
   224 
   225 /**
   226  * Sets an entity's movetype.
   227  *
   228  * @param entity	Entity index.
   229  * @param mt		Movetype, see enum above.
   230  * @noreturn
   231  * @error			Invalid entity index, or lack of mod compliance.
   232  */
   233 stock SetEntityMoveType(entity, MoveType:mt)
   234 {
   235 	static bool:gotconfig = false;
   236 	static String:datamap[32];
   237 	
   238 	if (!gotconfig)
   239 	{
   240 		new Handle:gc = LoadGameConfigFile("core.games");
   241 		new bool:exists = GameConfGetKeyValue(gc, "m_MoveType", datamap, sizeof(datamap));
   242 		CloseHandle(gc);
   243 		
   244 		if (!exists)
   245 		{
   246 			strcopy(datamap, sizeof(datamap), "m_MoveType");
   247 		}
   248 		
   249 		gotconfig = true;
   250 	}
   251 	
   252 	SetEntProp(entity, Prop_Data, datamap, mt);
   253 }
   254 
   255 /**
   256  * Gets an entity's render mode.
   257  *
   258  * @param entity	Entity index.
   259  * @return			RenderMode value.
   260  * @error			Invalid entity index, or lack of mod compliance.
   261  */
   262 stock RenderMode:GetEntityRenderMode(entity)
   263 {
   264 	static bool:gotconfig = false;
   265 	static String:prop[32];
   266 	
   267 	if (!gotconfig)
   268 	{
   269 		new Handle:gc = LoadGameConfigFile("core.games");
   270 		new bool:exists = GameConfGetKeyValue(gc, "m_nRenderMode", prop, sizeof(prop));
   271 		CloseHandle(gc);
   272 		
   273 		if (!exists)
   274 		{
   275 			strcopy(prop, sizeof(prop), "m_nRenderMode");
   276 		}
   277 		
   278 		gotconfig = true;
   279 	}
   280 	
   281 	return RenderMode:GetEntProp(entity, Prop_Send, prop, 1);
   282 }
   283 
   284 /**
   285  * Sets an entity's render mode.
   286  *
   287  * @param entity	Entity index.
   288  * @param mode		RenderMode value.
   289  * @noreturn
   290  * @error			Invalid entity index, or lack of mod compliance.
   291  */
   292 stock SetEntityRenderMode(entity, RenderMode:mode)
   293 {
   294 	static bool:gotconfig = false;
   295 	static String:prop[32];
   296 	
   297 	if (!gotconfig)
   298 	{
   299 		new Handle:gc = LoadGameConfigFile("core.games");
   300 		new bool:exists = GameConfGetKeyValue(gc, "m_nRenderMode", prop, sizeof(prop));
   301 		CloseHandle(gc);
   302 		
   303 		if (!exists)
   304 		{
   305 			strcopy(prop, sizeof(prop), "m_nRenderMode");
   306 		}
   307 		
   308 		gotconfig = true;
   309 	}
   310 	
   311 	SetEntProp(entity, Prop_Send, prop, mode, 1);
   312 }
   313 
   314 /**
   315  * Gets an entity's render Fx.
   316  *
   317  * @param entity	Entity index.
   318  * @return			RenderFx value.
   319  * @error			Invalid entity index, or lack of mod compliance.
   320  */
   321 stock RenderFx:GetEntityRenderFx(entity)
   322 {
   323 	static bool:gotconfig = false;
   324 	static String:prop[32];
   325 	
   326 	if (!gotconfig)
   327 	{
   328 		new Handle:gc = LoadGameConfigFile("core.games");
   329 		new bool:exists = GameConfGetKeyValue(gc, "m_nRenderFX", prop, sizeof(prop));
   330 		CloseHandle(gc);
   331 		
   332 		if (!exists)
   333 		{
   334 			strcopy(prop, sizeof(prop), "m_nRenderFX");
   335 		}
   336 		
   337 		gotconfig = true;
   338 	}
   339 	
   340 	return RenderFx:GetEntProp(entity, Prop_Send, prop, 1);
   341 }
   342 
   343 /**
   344  * Sets an entity's render Fx.
   345  *
   346  * @param entity	Entity index.
   347  * @param fx		RenderFx value.
   348  * @noreturn
   349  * @error			Invalid entity index, or lack of mod compliance.
   350  */
   351 stock SetEntityRenderFx(entity, RenderFx:fx)
   352 {
   353 	static bool:gotconfig = false;
   354 	static String:prop[32];
   355 	
   356 	if (!gotconfig)
   357 	{
   358 		new Handle:gc = LoadGameConfigFile("core.games");
   359 		new bool:exists = GameConfGetKeyValue(gc, "m_nRenderFX", prop, sizeof(prop));
   360 		CloseHandle(gc);
   361 		
   362 		if (!exists)
   363 		{
   364 			strcopy(prop, sizeof(prop), "m_nRenderFX");
   365 		}
   366 		
   367 		gotconfig = true;
   368 	}
   369 	
   370 	SetEntProp(entity, Prop_Send, prop, fx, 1);
   371 }
   372 
   373 /**
   374  * Sets an entity's color.
   375  *
   376  * @param entity	Entity index
   377  * @param r 		Amount of red (0-255)
   378  * @param g 		Amount of green (0-255)
   379  * @param b 		Amount of blue (0-255)
   380  * @param a 		Amount of alpha (0-255)
   381  * @noreturn
   382  * @error			Invalid entity index, or lack of mod compliance.
   383  */
   384 stock SetEntityRenderColor(entity, r=255, g=255, b=255, a=255)
   385 {
   386 	static bool:gotconfig = false;
   387 	static String:prop[32];
   388 	
   389 	if (!gotconfig)
   390 	{
   391 		new Handle:gc = LoadGameConfigFile("core.games");
   392 		new bool:exists = GameConfGetKeyValue(gc, "m_clrRender", prop, sizeof(prop));
   393 		CloseHandle(gc);
   394 		
   395 		if (!exists)
   396 		{
   397 			strcopy(prop, sizeof(prop), "m_clrRender");
   398 		}
   399 		
   400 		gotconfig = true;
   401 	}
   402 	
   403 	new offset = GetEntSendPropOffs(entity, prop);
   404 	
   405 	if (offset <= 0)
   406 	{
   407 		ThrowError("SetEntityRenderColor not supported by this mod");
   408 	}
   409 	
   410 	SetEntData(entity, offset, r, 1, true);
   411 	SetEntData(entity, offset + 1, g, 1, true);
   412 	SetEntData(entity, offset + 2, b, 1, true);
   413 	SetEntData(entity, offset + 3, a, 1, true);
   414 }
   415 
   416 /**
   417  * Gets an entity's gravity.
   418  *
   419  * @param entity 	Entity index.
   420  * @return			Entity's m_flGravity value.
   421  * @error			Invalid entity index, or lack of mod compliance.
   422  */
   423 stock Float:GetEntityGravity(entity)
   424 {
   425 	static bool:gotconfig = false;
   426 	static String:datamap[32];
   427 	
   428 	if (!gotconfig)
   429 	{
   430 		new Handle:gc = LoadGameConfigFile("core.games");
   431 		new bool:exists = GameConfGetKeyValue(gc, "m_flGravity", datamap, sizeof(datamap));
   432 		CloseHandle(gc);
   433 		
   434 		if (!exists)
   435 		{
   436 			strcopy(datamap, sizeof(datamap), "m_flGravity");
   437 		}
   438 		
   439 		gotconfig = true;
   440 	}
   441 	
   442 	return GetEntPropFloat(entity, Prop_Data, datamap);
   443 }
   444 
   445 /**
   446  * Sets an entity's gravity.
   447  *
   448  * @param entity	Entity index.
   449  * @param amount	Gravity to set (default = 1.0, half = 0.5, double = 2.0).
   450  * @noreturn
   451  * @error			Invalid entity index, or lack of mod compliance.
   452  */
   453 stock SetEntityGravity(entity, Float:amount)
   454 {
   455 	static bool:gotconfig = false;
   456 	static String:datamap[32];
   457 	
   458 	if (!gotconfig)
   459 	{
   460 		new Handle:gc = LoadGameConfigFile("core.games");
   461 		new bool:exists = GameConfGetKeyValue(gc, "m_flGravity", datamap, sizeof(datamap));
   462 		CloseHandle(gc);
   463 		
   464 		if (!exists)
   465 		{
   466 			strcopy(datamap, sizeof(datamap), "m_flGravity");
   467 		}
   468 		
   469 		gotconfig = true;
   470 	}
   471 	
   472 	SetEntPropFloat(entity, Prop_Data, datamap, amount);
   473 }
   474 
   475 /**
   476  * Sets an entity's health
   477  *
   478  * @param entity	Entity index.
   479  * @param amount	Health amount.
   480  * @noreturn
   481  * @error			Invalid entity index, or lack of mod compliance.
   482  */
   483 stock SetEntityHealth(entity, amount)
   484 {
   485 	static bool:gotconfig = false;
   486 	static String:prop[32];
   487 	
   488 	if (!gotconfig)
   489 	{
   490 		new Handle:gc = LoadGameConfigFile("core.games");
   491 		new bool:exists = GameConfGetKeyValue(gc, "m_iHealth", prop, sizeof(prop));
   492 		CloseHandle(gc);
   493 		
   494 		if (!exists)
   495 		{
   496 			strcopy(prop, sizeof(prop), "m_iHealth");
   497 		}
   498 		
   499 		gotconfig = true;
   500 	}
   501 	
   502 	decl String:cls[64];
   503 	new PropFieldType:type;
   504 	new offset;
   505 	
   506 	if (!GetEntityNetClass(entity, cls, sizeof(cls)))
   507 	{
   508 		ThrowError("SetEntityHealth not supported by this mod: Could not get serverclass name");
   509 		return;
   510 	}
   511 	
   512 	offset = FindSendPropInfo(cls, prop, type);
   513 	
   514 	if (offset <= 0)
   515 	{
   516 		ThrowError("SetEntityHealth not supported by this mod");
   517 		return;
   518 	}
   519 	
   520 	/* Dark Messiah uses a float for the health instead an integer */
   521 	if (type == PropField_Float)
   522 	{
   523 		SetEntDataFloat(entity, offset, float(amount));
   524 	}
   525 	else
   526 	{
   527 		SetEntProp(entity, Prop_Send, prop, amount);
   528 	}
   529 }
   530 
   531 /**
   532  * Get's a users current pressed buttons
   533  *
   534  * @param client	Client index
   535  * @return			Bitsum of buttons
   536  * @error			Invalid client index, client not in game, 
   537  *					or lack of mod compliance.
   538  */
   539 stock GetClientButtons(client)
   540 {
   541 	static bool:gotconfig = false;
   542 	static String:datamap[32];
   543 	
   544 	if (!gotconfig)
   545 	{
   546 		new Handle:gc = LoadGameConfigFile("core.games");
   547 		new bool:exists = GameConfGetKeyValue(gc, "m_nButtons", datamap, sizeof(datamap));
   548 		CloseHandle(gc);
   549 		
   550 		if (!exists)
   551 		{
   552 			strcopy(datamap, sizeof(datamap), "m_nButtons");
   553 		}
   554 		
   555 		gotconfig = true;
   556 	}
   557 	
   558 	return GetEntProp(client, Prop_Data, datamap);
   559 }