plugins/include/entity_prop_stocks.inc
author Scott Ehlert <ds@alliedmods.net>
Thu Apr 07 14:51:56 2011 -0500 (2011-04-07)
changeset 3227 e97bc7be7477
parent 3220 5579fb7db416
child 3722 641ee592dda6
permissions -rw-r--r--
Triggering a build, perhaps.
     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 
   126 // Note: these are only for use with GetEntityFlags and SetEntityFlags
   127 //       and may not match the game's actual, internal m_fFlags values.
   128 // PLAYER SPECIFIC FLAGS FIRST BECAUSE WE USE ONLY A FEW BITS OF NETWORK PRECISION
   129 #define	FL_ONGROUND			(1 << 0)	// At rest / on the ground
   130 #define FL_DUCKING			(1 << 1)	// Player flag -- Player is fully crouched
   131 #define	FL_WATERJUMP			(1 << 2)	// player jumping out of water
   132 #define FL_ONTRAIN			(1 << 3)	// Player is _controlling_ a train, so movement commands should be ignored on client during prediction.
   133 #define FL_INRAIN			(1 << 4)	// Indicates the entity is standing in rain
   134 #define FL_FROZEN			(1 << 5)	// Player is frozen for 3rd person camera
   135 #define FL_ATCONTROLS			(1 << 6)	// Player can't move, but keeps key inputs for controlling another entity
   136 #define	FL_CLIENT			(1 << 7)	// Is a player
   137 #define FL_FAKECLIENT			(1 << 8)	// Fake client, simulated server side; don't send network messages to them
   138 // NOTE if you move things up, make sure to change this value
   139 #define PLAYER_FLAG_BITS		9
   140 // NON-PLAYER SPECIFIC (i.e., not used by GameMovement or the client .dll ) -- Can still be applied to players, though
   141 #define	FL_INWATER			(1 << 9)	// In water
   142 #define	FL_FLY				(1 << 10)	// Changes the SV_Movestep() behavior to not need to be on ground
   143 #define	FL_SWIM				(1 << 11)	// Changes the SV_Movestep() behavior to not need to be on ground (but stay in water)
   144 #define	FL_CONVEYOR			(1 << 12)
   145 #define	FL_NPC				(1 << 13)
   146 #define	FL_GODMODE			(1 << 14)
   147 #define	FL_NOTARGET			(1 << 15)
   148 #define	FL_AIMTARGET			(1 << 16)	// set if the crosshair needs to aim onto the entity
   149 #define	FL_PARTIALGROUND		(1 << 17)	// not all corners are valid
   150 #define FL_STATICPROP			(1 << 18)	// Eetsa static prop!		
   151 #define FL_GRAPHED			(1 << 19)	// worldgraph has this ent listed as something that blocks a connection
   152 #define FL_GRENADE			(1 << 20)
   153 #define FL_STEPMOVEMENT			(1 << 21)	// Changes the SV_Movestep() behavior to not do any processing
   154 #define FL_DONTTOUCH			(1 << 22)	// Doesn't generate touch functions, generates Untouch() for anything it was touching when this flag was set
   155 #define FL_BASEVELOCITY			(1 << 23)	// Base velocity has been applied this frame (used to convert base velocity into momentum)
   156 #define FL_WORLDBRUSH			(1 << 24)	// Not moveable/removeable brush entity (really part of the world, but represented as an entity for transparency or something)
   157 #define FL_OBJECT			(1 << 25)	// Terrible name. This is an object that NPCs should see. Missiles, for example.
   158 #define FL_KILLME			(1 << 26)	// This entity is marked for death -- will be freed by game DLL
   159 #define FL_ONFIRE			(1 << 27)	// You know...
   160 #define FL_DISSOLVING			(1 << 28)	// We're dissolving!
   161 #define FL_TRANSRAGDOLL			(1 << 29)	// In the process of turning into a client side ragdoll.
   162 #define FL_UNBLOCKABLE_BY_PLAYER	(1 << 30)	// pusher that can't be blocked by the player
   163 #define FL_FREEZING				(1 << 31)	// We're becoming frozen!
   164 #define FL_EP2V_UNKNOWN1		(1 << 31)	// Unknown
   165 // END entity flag #defines
   166 
   167 /**
   168  * Get an entity's flags.
   169  *
   170  * @note The game's actual flags are internally translated by SM
   171  *       to match the entity flags defined above as the actual values
   172  *       can differ per engine.
   173  *
   174  * @param entity	Entity index.
   175  * @return			Entity's flags, see entity flag defines above.
   176  * @error			Invalid entity index, or lack of mod compliance.
   177  */
   178 native GetEntityFlags(entity);
   179 
   180 /**
   181  * Sets an entity's flags.
   182  *
   183  * @note The entity flags as defined above are internally translated by SM
   184  *       to match the current game's expected value for the flags as
   185  *       the actual values can differ per engine.
   186  *
   187  * @param entity	Entity index.
   188  * @param flags		Entity flags, see entity flag defines above.
   189  * @noreturn
   190  * @error			Invalid entity index, or lack of mod compliance.
   191  */
   192 native SetEntityFlags(entity, flags);
   193 
   194 
   195 /**
   196  * Gets an entity's movetype.
   197  *
   198  * @param entity	Entity index.
   199  * @return			Movetype, see enum above.
   200  * @error			Invalid entity index, or lack of mod compliance.
   201  */
   202 stock MoveType:GetEntityMoveType(entity)
   203 {
   204 	static bool:gotconfig = false;
   205 	static String:datamap[32];
   206 	
   207 	if (!gotconfig)
   208 	{
   209 		new Handle:gc = LoadGameConfigFile("core.games");
   210 		new bool:exists = GameConfGetKeyValue(gc, "m_MoveType", datamap, sizeof(datamap));
   211 		CloseHandle(gc);
   212 		
   213 		if (!exists)
   214 		{
   215 			strcopy(datamap, sizeof(datamap), "m_MoveType");
   216 		}
   217 		
   218 		gotconfig = true;
   219 	}
   220 	
   221 	return MoveType:GetEntProp(entity, Prop_Data, datamap);
   222 }
   223 
   224 /**
   225  * Sets an entity's movetype.
   226  *
   227  * @param entity	Entity index.
   228  * @param mt		Movetype, see enum above.
   229  * @noreturn
   230  * @error			Invalid entity index, or lack of mod compliance.
   231  */
   232 stock SetEntityMoveType(entity, MoveType:mt)
   233 {
   234 	static bool:gotconfig = false;
   235 	static String:datamap[32];
   236 	
   237 	if (!gotconfig)
   238 	{
   239 		new Handle:gc = LoadGameConfigFile("core.games");
   240 		new bool:exists = GameConfGetKeyValue(gc, "m_MoveType", datamap, sizeof(datamap));
   241 		CloseHandle(gc);
   242 		
   243 		if (!exists)
   244 		{
   245 			strcopy(datamap, sizeof(datamap), "m_MoveType");
   246 		}
   247 		
   248 		gotconfig = true;
   249 	}
   250 	
   251 	SetEntProp(entity, Prop_Data, datamap, mt);
   252 }
   253 
   254 /**
   255  * Gets an entity's render mode.
   256  *
   257  * @param entity	Entity index.
   258  * @return			RenderMode value.
   259  * @error			Invalid entity index, or lack of mod compliance.
   260  */
   261 stock RenderMode:GetEntityRenderMode(entity)
   262 {
   263 	static bool:gotconfig = false;
   264 	static String:prop[32];
   265 	
   266 	if (!gotconfig)
   267 	{
   268 		new Handle:gc = LoadGameConfigFile("core.games");
   269 		new bool:exists = GameConfGetKeyValue(gc, "m_nRenderMode", prop, sizeof(prop));
   270 		CloseHandle(gc);
   271 		
   272 		if (!exists)
   273 		{
   274 			strcopy(prop, sizeof(prop), "m_nRenderMode");
   275 		}
   276 		
   277 		gotconfig = true;
   278 	}
   279 	
   280 	return RenderMode:GetEntProp(entity, Prop_Send, prop, 1);
   281 }
   282 
   283 /**
   284  * Sets an entity's render mode.
   285  *
   286  * @param entity	Entity index.
   287  * @param mode		RenderMode value.
   288  * @noreturn
   289  * @error			Invalid entity index, or lack of mod compliance.
   290  */
   291 stock SetEntityRenderMode(entity, RenderMode:mode)
   292 {
   293 	static bool:gotconfig = false;
   294 	static String:prop[32];
   295 	
   296 	if (!gotconfig)
   297 	{
   298 		new Handle:gc = LoadGameConfigFile("core.games");
   299 		new bool:exists = GameConfGetKeyValue(gc, "m_nRenderMode", prop, sizeof(prop));
   300 		CloseHandle(gc);
   301 		
   302 		if (!exists)
   303 		{
   304 			strcopy(prop, sizeof(prop), "m_nRenderMode");
   305 		}
   306 		
   307 		gotconfig = true;
   308 	}
   309 	
   310 	SetEntProp(entity, Prop_Send, prop, mode, 1);
   311 }
   312 
   313 /**
   314  * Gets an entity's render Fx.
   315  *
   316  * @param entity	Entity index.
   317  * @return			RenderFx value.
   318  * @error			Invalid entity index, or lack of mod compliance.
   319  */
   320 stock RenderFx:GetEntityRenderFx(entity)
   321 {
   322 	static bool:gotconfig = false;
   323 	static String:prop[32];
   324 	
   325 	if (!gotconfig)
   326 	{
   327 		new Handle:gc = LoadGameConfigFile("core.games");
   328 		new bool:exists = GameConfGetKeyValue(gc, "m_nRenderFX", prop, sizeof(prop));
   329 		CloseHandle(gc);
   330 		
   331 		if (!exists)
   332 		{
   333 			strcopy(prop, sizeof(prop), "m_nRenderFX");
   334 		}
   335 		
   336 		gotconfig = true;
   337 	}
   338 	
   339 	return RenderFx:GetEntProp(entity, Prop_Send, prop, 1);
   340 }
   341 
   342 /**
   343  * Sets an entity's render Fx.
   344  *
   345  * @param entity	Entity index.
   346  * @param fx		RenderFx value.
   347  * @noreturn
   348  * @error			Invalid entity index, or lack of mod compliance.
   349  */
   350 stock SetEntityRenderFx(entity, RenderFx:fx)
   351 {
   352 	static bool:gotconfig = false;
   353 	static String:prop[32];
   354 	
   355 	if (!gotconfig)
   356 	{
   357 		new Handle:gc = LoadGameConfigFile("core.games");
   358 		new bool:exists = GameConfGetKeyValue(gc, "m_nRenderFX", prop, sizeof(prop));
   359 		CloseHandle(gc);
   360 		
   361 		if (!exists)
   362 		{
   363 			strcopy(prop, sizeof(prop), "m_nRenderFX");
   364 		}
   365 		
   366 		gotconfig = true;
   367 	}
   368 	
   369 	SetEntProp(entity, Prop_Send, prop, fx, 1);
   370 }
   371 
   372 /**
   373  * Sets an entity's color.
   374  *
   375  * @param entity	Entity index
   376  * @param r 		Amount of red (0-255)
   377  * @param g 		Amount of green (0-255)
   378  * @param b 		Amount of blue (0-255)
   379  * @param a 		Amount of alpha (0-255)
   380  * @noreturn
   381  * @error			Invalid entity index, or lack of mod compliance.
   382  */
   383 stock SetEntityRenderColor(entity, r=255, g=255, b=255, a=255)
   384 {
   385 	static bool:gotconfig = false;
   386 	static String:prop[32];
   387 	
   388 	if (!gotconfig)
   389 	{
   390 		new Handle:gc = LoadGameConfigFile("core.games");
   391 		new bool:exists = GameConfGetKeyValue(gc, "m_clrRender", prop, sizeof(prop));
   392 		CloseHandle(gc);
   393 		
   394 		if (!exists)
   395 		{
   396 			strcopy(prop, sizeof(prop), "m_clrRender");
   397 		}
   398 		
   399 		gotconfig = true;
   400 	}
   401 	
   402 	new offset = GetEntSendPropOffs(entity, prop);
   403 	
   404 	if (offset <= 0)
   405 	{
   406 		ThrowError("SetEntityRenderColor not supported by this mod");
   407 	}
   408 	
   409 	SetEntData(entity, offset, r, 1, true);
   410 	SetEntData(entity, offset + 1, g, 1, true);
   411 	SetEntData(entity, offset + 2, b, 1, true);
   412 	SetEntData(entity, offset + 3, a, 1, true);
   413 }
   414 
   415 /**
   416  * Gets an entity's gravity.
   417  *
   418  * @param entity 	Entity index.
   419  * @return			Entity's m_flGravity value.
   420  * @error			Invalid entity index, or lack of mod compliance.
   421  */
   422 stock Float:GetEntityGravity(entity)
   423 {
   424 	static bool:gotconfig = false;
   425 	static String:datamap[32];
   426 	
   427 	if (!gotconfig)
   428 	{
   429 		new Handle:gc = LoadGameConfigFile("core.games");
   430 		new bool:exists = GameConfGetKeyValue(gc, "m_flGravity", datamap, sizeof(datamap));
   431 		CloseHandle(gc);
   432 		
   433 		if (!exists)
   434 		{
   435 			strcopy(datamap, sizeof(datamap), "m_flGravity");
   436 		}
   437 		
   438 		gotconfig = true;
   439 	}
   440 	
   441 	return GetEntPropFloat(entity, Prop_Data, datamap);
   442 }
   443 
   444 /**
   445  * Sets an entity's gravity.
   446  *
   447  * @param entity	Entity index.
   448  * @param amount	Gravity to set (default = 1.0, half = 0.5, double = 2.0).
   449  * @noreturn
   450  * @error			Invalid entity index, or lack of mod compliance.
   451  */
   452 stock SetEntityGravity(entity, Float:amount)
   453 {
   454 	static bool:gotconfig = false;
   455 	static String:datamap[32];
   456 	
   457 	if (!gotconfig)
   458 	{
   459 		new Handle:gc = LoadGameConfigFile("core.games");
   460 		new bool:exists = GameConfGetKeyValue(gc, "m_flGravity", datamap, sizeof(datamap));
   461 		CloseHandle(gc);
   462 		
   463 		if (!exists)
   464 		{
   465 			strcopy(datamap, sizeof(datamap), "m_flGravity");
   466 		}
   467 		
   468 		gotconfig = true;
   469 	}
   470 	
   471 	SetEntPropFloat(entity, Prop_Data, datamap, amount);
   472 }
   473 
   474 /**
   475  * Sets an entity's health
   476  *
   477  * @param entity	Entity index.
   478  * @param amount	Health amount.
   479  * @noreturn
   480  * @error			Invalid entity index, or lack of mod compliance.
   481  */
   482 stock SetEntityHealth(entity, amount)
   483 {
   484 	static bool:gotconfig = false;
   485 	static String:prop[32];
   486 	
   487 	if (!gotconfig)
   488 	{
   489 		new Handle:gc = LoadGameConfigFile("core.games");
   490 		new bool:exists = GameConfGetKeyValue(gc, "m_iHealth", prop, sizeof(prop));
   491 		CloseHandle(gc);
   492 		
   493 		if (!exists)
   494 		{
   495 			strcopy(prop, sizeof(prop), "m_iHealth");
   496 		}
   497 		
   498 		gotconfig = true;
   499 	}
   500 	
   501 	decl String:cls[64];
   502 	new PropFieldType:type;
   503 	new offset;
   504 	
   505 	if (!GetEntityNetClass(entity, cls, sizeof(cls)))
   506 	{
   507 		ThrowError("SetEntityHealth not supported by this mod: Could not get serverclass name");
   508 		return;
   509 	}
   510 	
   511 	offset = FindSendPropInfo(cls, prop, type);
   512 	
   513 	if (offset <= 0)
   514 	{
   515 		ThrowError("SetEntityHealth not supported by this mod");
   516 		return;
   517 	}
   518 	
   519 	/* Dark Messiah uses a float for the health instead an integer */
   520 	if (type == PropField_Float)
   521 	{
   522 		SetEntDataFloat(entity, offset, float(amount));
   523 	}
   524 	else
   525 	{
   526 		SetEntProp(entity, Prop_Send, prop, amount);
   527 	}
   528 }
   529 
   530 /**
   531  * Get's a users current pressed buttons
   532  *
   533  * @param client	Client index
   534  * @return			Bitsum of buttons
   535  * @error			Invalid client index, client not in game, 
   536  *					or lack of mod compliance.
   537  */
   538 stock GetClientButtons(client)
   539 {
   540 	static bool:gotconfig = false;
   541 	static String:datamap[32];
   542 	
   543 	if (!gotconfig)
   544 	{
   545 		new Handle:gc = LoadGameConfigFile("core.games");
   546 		new bool:exists = GameConfGetKeyValue(gc, "m_nButtons", datamap, sizeof(datamap));
   547 		CloseHandle(gc);
   548 		
   549 		if (!exists)
   550 		{
   551 			strcopy(datamap, sizeof(datamap), "m_nButtons");
   552 		}
   553 		
   554 		gotconfig = true;
   555 	}
   556 	
   557 	return GetEntProp(client, Prop_Data, datamap);
   558 }