From 95e8efc67036d7269cdfb9d4da9d515639488874 Mon Sep 17 00:00:00 2001 From: a1batross Date: Sun, 14 Feb 2016 22:18:00 +0300 Subject: [PATCH] Rework smoke grenade, fix various bugs --- cl_dll/events/ev_cs16.cpp | 18 +++++----- cl_dll/events/event_createsmoke.cpp | 52 +++++++++++++++++------------ cl_dll/events/event_decal_reset.cpp | 6 +++- cl_dll/hud/hud_msg.cpp | 10 +++--- 4 files changed, 52 insertions(+), 34 deletions(-) diff --git a/cl_dll/events/ev_cs16.cpp b/cl_dll/events/ev_cs16.cpp index 296f1f3..b3626df 100644 --- a/cl_dll/events/ev_cs16.cpp +++ b/cl_dll/events/ev_cs16.cpp @@ -39,6 +39,7 @@ #include static int tracerCount[ 32 ]; +extern float g_flRoundTime; extern "C" char PM_FindTextureType( char *name ); @@ -556,15 +557,16 @@ void EV_TrainPitchAdjust( event_args_t *args ) } } -int EV_TFC_IsAllyTeam( int iTeam1, int iTeam2 ) +void EV_CS16Client_KillEveryRound( TEMPENTITY *te, float frametime, float current_time ) { - return 0; -} - -void EV_Dummy( struct event_args_s *args ) -{ - gEngfuncs.pEventAPI->EV_WeaponAnimation( 1, 1 ); - return; + if( g_flRoundTime > te->entity.curstate.fuser4 ) + { + // Mark it die on next TempEntUpdate + te->die = 0.0f; + // Set null renderamt, so it will be invisible now + // Also it will die immediately, if FTEMP_FADEOUT was set + te->entity.curstate.renderamt = 0; + } } void RemoveBody(TEMPENTITY *te, float frametime, float current_time) diff --git a/cl_dll/events/event_createsmoke.cpp b/cl_dll/events/event_createsmoke.cpp index 37e825b..7cbb6cc 100644 --- a/cl_dll/events/event_createsmoke.cpp +++ b/cl_dll/events/event_createsmoke.cpp @@ -29,28 +29,31 @@ #include "com_model.h" +#define SMOKE_CLOUDS 10 + +void EV_Smoke_FadeOut( struct tempent_s *te, float frametime, float currenttime ) +{ + if( te->entity.curstate.renderamt > 0 && currenttime >= te->entity.curstate.fuser3 ) + { + te->entity.curstate.renderamt = 255.0f - (currenttime - te->entity.curstate.fuser3) * te->entity.baseline.renderamt ; + if( te->entity.curstate.renderamt < 0 ) te->entity.curstate.renderamt = 0; + } + EV_CS16Client_KillEveryRound(te, frametime, currenttime ); +} + void EV_CreateSmoke(event_args_s *args) { - static bool init = false; - static const model_t *pGasModel; TEMPENTITY *pTemp; - if(!init) + if( !args->bparam2 ) //first explosion { - int iGasSprite = SPR_Load("sprites/gas_puff_01.spr"); - pGasModel = gEngfuncs.GetSpritePointer(iGasSprite); - init = true; - } + const model_t *pGasModel = gEngfuncs.GetSpritePointer(SPR_Load("sprites/gas_puff_01.spr")); - if( !args->bparam2 ) // first explosion - { - Vector org; - - for( int i = 0; i < 10; i++ ) + for( int i = 0; i < SMOKE_CLOUDS; i++ ) { // randomize smoke cloud position - org = args->origin; + Vector org = args->origin; org.x += gEngfuncs.pfnRandomFloat(-100.0f, 100.0f); org.y += gEngfuncs.pfnRandomFloat(-100.0f, 100.0f); org.z += 30; @@ -59,26 +62,33 @@ void EV_CreateSmoke(event_args_s *args) if( pTemp ) { // don't die when animation is ended - pTemp->flags |= (FTENT_FADEOUT | FTENT_SPRANIMATELOOP | FTENT_COLLIDEWORLD); - pTemp->die = gEngfuncs.GetClientTime() + 40.0f; - pTemp->entity.curstate.framerate = 4.0f; + pTemp->flags |= (FTENT_SPRANIMATELOOP | FTENT_COLLIDEWORLD | FTENT_CLIENTCUSTOM); + pTemp->die = gEngfuncs.GetClientTime() + 30.0f; + pTemp->callback = EV_Smoke_FadeOut; + pTemp->entity.curstate.fuser3 = gEngfuncs.GetClientTime() + 15.0f; // start fading after 15 sec + pTemp->entity.curstate.fuser4 = gEngfuncs.GetClientTime(); // entity creation time + + pTemp->entity.curstate.renderamt = 255; pTemp->entity.curstate.rendermode = kRenderTransTexture; - pTemp->entity.curstate.renderfx = kRenderFxNone; pTemp->entity.curstate.scale = 5.0f; + // make it move slowly pTemp->entity.baseline.origin.x = gEngfuncs.pfnRandomLong(-5, 5); pTemp->entity.baseline.origin.y = gEngfuncs.pfnRandomLong(-5, 5); + pTemp->entity.baseline.renderamt = 18; } } } else // second and other { - static int iSmokeSprite = gEngfuncs.pEventAPI->EV_FindModelIndex( "sprites/black_smoke4.spr" ); - - pTemp = gEngfuncs.pEfxAPI->R_DefaultSprite( args->origin, iSmokeSprite, 4.0f ); + pTemp = gEngfuncs.pEfxAPI->R_DefaultSprite( args->origin, gEngfuncs.pEventAPI->EV_FindModelIndex( "sprites/black_smoke4.spr" ), 6.0f ); if( pTemp ) { + pTemp->flags |= (FTENT_CLIENTCUSTOM | FTENT_COLLIDEWORLD); + pTemp->callback = EV_CS16Client_KillEveryRound; + pTemp->entity.curstate.fuser4 = gEngfuncs.GetClientTime(); + pTemp->entity.curstate.rendermode = kRenderTransTexture; pTemp->entity.curstate.renderfx = kRenderFxNone; pTemp->entity.curstate.rendercolor.r = gEngfuncs.pfnRandomLong(210, 230); @@ -86,7 +96,7 @@ void EV_CreateSmoke(event_args_s *args) pTemp->entity.curstate.rendercolor.b = gEngfuncs.pfnRandomLong(210, 230); pTemp->entity.curstate.renderamt = gEngfuncs.pfnRandomLong(180, 200); - pTemp->entity.baseline.origin[0] = gEngfuncs.pfnRandomLong(0, 10); + pTemp->entity.baseline.origin[0] = gEngfuncs.pfnRandomLong(10, 30); } } } diff --git a/cl_dll/events/event_decal_reset.cpp b/cl_dll/events/event_decal_reset.cpp index 3b536c4..6ad2d6c 100644 --- a/cl_dll/events/event_decal_reset.cpp +++ b/cl_dll/events/event_decal_reset.cpp @@ -29,10 +29,14 @@ #include +float g_flRoundTime = 0.0f; + void EV_DecalReset(event_args_s *args) { - int decalnum = floor(gEngfuncs.pfnGetCvarFloat("r_decals")); + int decalnum = (int)(gEngfuncs.pfnGetCvarFloat("r_decals")); for( int i = 0; i < decalnum; i++ ) gEngfuncs.pEfxAPI->R_DecalRemoveAll(i); + + g_flRoundTime = gEngfuncs.GetClientTime(); } diff --git a/cl_dll/hud/hud_msg.cpp b/cl_dll/hud/hud_msg.cpp index 3d3b29a..cbc6898 100644 --- a/cl_dll/hud/hud_msg.cpp +++ b/cl_dll/hud/hud_msg.cpp @@ -32,6 +32,8 @@ #define MAX_CLIENTS 32 +extern float g_flRoundTime; + /// USER-DEFINED SERVER MESSAGE HANDLERS int CHud :: MsgFunc_ResetHUD(const char *pszName, int iSize, void *pbuf ) @@ -79,13 +81,13 @@ int CHud :: MsgFunc_InitHUD( const char *pszName, int iSize, void *pbuf ) g_iFreezeTimeOver = 0; - for( int i = 0; i < MAX_PLAYERS; i++ ) - { - g_PlayerExtraInfo[i].frags = 0; - } + memset( g_PlayerExtraInfo, 0, sizeof(g_PlayerExtraInfo) ); ResetRain(); + // reset round time + g_flRoundTime = 0.0f; + return 1; }