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