//----------------------------------------------------------------------------- // Computes render info for a spotlight //----------------------------------------------------------------------------- void C_BeamSpotLight::ComputeRenderInfo() { // Fade out spotlight end if past MAX length. if ( m_flSpotlightCurLength > 2*m_flSpotlightMaxLength ) { SetRenderAlpha( 0 ); m_hSpotlight->SetFadeLength( m_flSpotlightMaxLength ); } else if ( m_flSpotlightCurLength > m_flSpotlightMaxLength ) { SetRenderAlpha( (1-((m_flSpotlightCurLength-m_flSpotlightMaxLength)/m_flSpotlightMaxLength)) ); m_hSpotlight->SetFadeLength( m_flSpotlightMaxLength ); } else { SetRenderAlpha( 1.0 ); m_hSpotlight->SetFadeLength( m_flSpotlightCurLength ); } // Adjust end width to keep beam width constant float flNewWidth = m_flSpotlightGoalWidth * (m_flSpotlightCurLength / m_flSpotlightMaxLength); flNewWidth = clamp(flNewWidth, 0, MAX_BEAM_WIDTH ); m_hSpotlight->SetEndWidth(flNewWidth); if ( m_bHasDynamicLight ) { // <<TODO>> - magic number 1.8 depends on sprite size m_flLightScale = 1.8*flNewWidth; if ( m_flLightScale > 0 ) { const color24 c = GetRenderColor(); float a = GetRenderAlpha() / 255.0f; ColorRGBExp32 color; color.r = c.r * a; color.g = c.g * a; color.b = c.b * a; color.exponent = 0; if ( color.r == 0 && color.g == 0 && color.b == 0 ) return; // Deal with the environment light if ( !m_pDynamicLight || (m_pDynamicLight->key != index) ) { m_pDynamicLight = effects->CL_AllocDlight( index ); assert (m_pDynamicLight); } //m_pDynamicLight->flags = DLIGHT_NO_MODEL_ILLUMINATION; m_pDynamicLight->radius = m_flLightScale*3.0f; m_pDynamicLight->origin = GetAbsOrigin() + Vector(0,0,5); m_pDynamicLight->die = gpGlobals->curtime + 0.05f; m_pDynamicLight->color = color; } } }
// // Throw a chunk // void CGib::Spawn( const char *szGibModel ) { SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); SetFriction(0.55); // deading the bounce a bit // sometimes an entity inherits the edict from a former piece of glass, // and will spawn using the same render FX or m_nRenderMode! bad! SetRenderAlpha( 255 ); m_nRenderMode = kRenderNormal; m_nRenderFX = kRenderFxNone; // hopefully this will fix the VELOCITY TOO LOW crap m_takedamage = DAMAGE_EVENTS_ONLY; SetSolid( SOLID_BBOX ); AddSolidFlags( FSOLID_NOT_STANDABLE ); SetCollisionGroup( COLLISION_GROUP_DEBRIS ); SetModel( szGibModel ); SetNextThink( gpGlobals->curtime + 4 ); m_lifeTime = 25; SetTouch ( &CGib::BounceGibTouch ); m_bForceRemove = false; m_material = matNone; m_cBloodDecals = 5;// how many blood decals this gib can place (1 per bounce until none remain). }
//========================================================= // WaitTillLand - in order to emit their meaty scent from // the proper location, gibs should wait until they stop // bouncing to emit their scent. That's what this function // does. //========================================================= void CGib::WaitTillLand ( void ) { if (!IsInWorld()) { UTIL_Remove( this ); return; } if ( GetAbsVelocity() == vec3_origin ) { SetRenderAlpha( 255 ); m_nRenderMode = kRenderTransTexture; if ( GetMoveType() != MOVETYPE_VPHYSICS ) { AddSolidFlags( FSOLID_NOT_SOLID ); } SetLocalAngularVelocity( vec3_angle ); SetNextThink( gpGlobals->curtime + m_lifeTime ); SetThink ( &CGib::SUB_FadeOut ); if ( GetSprite() ) { CSprite *pSprite = dynamic_cast<CSprite*>( GetSprite() ); if ( pSprite ) { //Adrian - Why am I doing this? Check InitPointGib for the answer! if ( m_lifeTime == 0 ) m_lifeTime = random->RandomFloat( 1, 3 ); pSprite->FadeAndDie( m_lifeTime ); } } if ( GetFlame() ) { CEntityFlame *pFlame = dynamic_cast< CEntityFlame*>( GetFlame() ); if ( pFlame ) { pFlame->SetLifetime( 1.0f ); } } // If you bleed, you stink! if ( m_bloodColor != DONT_BLEED ) { // ok, start stinkin! // FIXME: It's too easy to fill up the sound queue with all these meat sounds // CSoundEnt::InsertSound ( SOUND_MEAT, GetAbsOrigin(), 384, 25 ); } } else { // wait and check again in another half second. SetNextThink( gpGlobals->curtime + 0.5f ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CSprite::ExpandThink( void ) { float frametime = gpGlobals->curtime - m_flLastTime; SetSpriteScale( m_flSpriteScale + m_flSpeed * frametime ); int sub = (int)(m_iHealth * frametime); if ( sub > GetRenderAlpha() ) { SetRenderAlpha( 0 ); Remove( ); } else { SetRenderAlpha( GetRenderAlpha() - sub ); SetNextThink( gpGlobals->curtime ); m_flLastTime = gpGlobals->curtime; } }
SporeExplosion::SporeExplosion( void ) { m_flSpawnRate = 100.0f; m_flParticleLifetime = 1.0f; m_flStartSize = 1.0f; m_flEndSize = 0.0f; m_flSpawnRadius = 16.0f; SetRenderColor( 255, 255, 255 ); SetRenderAlpha( 255 ); m_bEmit = true; m_bDisabled = false; }
SporeTrail::SporeTrail( void ) { m_vecEndColor.GetForModify().Init(); m_flSpawnRate = 100.0f; m_flParticleLifetime = 1.0f; m_flStartSize = 1.0f; m_flEndSize = 0.0f; m_flSpawnRadius = 16.0f; SetRenderColor( 255, 255, 255 ); SetRenderAlpha( 255 ); }
void C_Prop_ASW_Fade::ClientThink() { BaseClass::ClientThink(); C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer(); if (!pPlayer) { return; } C_ASW_Marine *pMarine = pPlayer->GetViewMarine(); bool bFade = pPlayer->GetASWControls() == 1 && pMarine && pMarine->GetAbsOrigin().z <= m_vecFadeOrigin.z; byte target = bFade ? m_nFadeOpacity : m_nNormalOpacity; byte prev = bFade ? m_nNormalOpacity : m_nFadeOpacity; if (bFade != m_bFaded) { m_bFaded = bFade; m_flInterpStart = gpGlobals->curtime - fabs((m_nFadeOpacity != m_nNormalOpacity) ? asw_fade_duration.GetFloat() * (GetRenderAlpha() - prev) / (m_nFadeOpacity - m_nNormalOpacity) : asw_fade_duration.GetFloat()); m_flInterpStart = MAX(0, m_flInterpStart); } if ( pPlayer->GetASWControls() != m_iLastControls || pMarine != m_hLastMarine.Get() ) { m_iLastControls = pPlayer->GetASWControls(); m_hLastMarine = pMarine; m_flInterpStart = 0; SetRenderAlpha(target); return; } if (m_flInterpStart + asw_fade_duration.GetFloat() <= gpGlobals->curtime) { SetRenderAlpha(target); } else if (m_flInterpStart > 0) { SetRenderAlpha(Lerp((gpGlobals->curtime - m_flInterpStart) / asw_fade_duration.GetFloat(), prev, target)); } }
//------------------------------------------------------------------------------ // Purpose : // Input : // Output : //------------------------------------------------------------------------------ void CGrenadeEnergy::Animate( void ) { float flLifeLeft = 1-(gpGlobals->curtime - m_flLaunchTime)/ENERGY_GRENADE_LIFETIME; if (flLifeLeft < 0) { SetRenderAlpha( 0 ); SetThink(NULL); UTIL_Remove(this); } SetNextThink( gpGlobals->curtime + 0.01f ); QAngle angles; VectorAngles( GetAbsVelocity(), angles ); SetLocalAngles( angles ); SetNextThink( gpGlobals->curtime + 0.1f ); StudioFrameAdvance( ); SetRenderAlpha( flLifeLeft ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- CBaseViewModel::CBaseViewModel() { #if defined( CLIENT_DLL ) // NOTE: We do this here because the color is never transmitted for the view model. m_nOldAnimationParity = 0; m_EntClientFlags |= ENTCLIENTFLAG_ALWAYS_INTERPOLATE; RenderWithViewModels( true ); #endif SetRenderColor( 255, 255, 255 ); SetRenderAlpha( 255 ); // View model of this weapon m_sVMName = NULL_STRING; // Prefix of the animations that should be used by the player carrying this weapon m_sAnimationPrefix = NULL_STRING; m_nViewModelIndex = 0; m_nAnimationParity = 0; }
void CASW_Broadcast_Camera::Spawn( void ) { BaseClass::Spawn(); SetMoveType( MOVETYPE_NOCLIP ); SetSolid( SOLID_NONE ); // Remove model & collisions SetRenderAlpha( 0 ); // The engine won't draw this model if this is set to 0 and blending is on m_nRenderMode = kRenderTransTexture; m_state = USE_OFF; m_initialSpeed = m_flSpeed; if ( m_acceleration == 0 ) m_acceleration = 500; if ( m_deceleration == 0 ) m_deceleration = 500; DispatchUpdateTransmitState(); }
void CBaseGrenadeConcussion::Spawn( void ) { // point sized, solid, bouncing SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); SetSolid( SOLID_BBOX ); SetCollisionGroup( COLLISION_GROUP_PROJECTILE ); SetModel( "models/weapons/w_grenade.mdl" ); // BUG: wrong model UTIL_SetSize(this, vec3_origin, vec3_origin); // contact grenades arc lower SetGravity( UTIL_ScaleForGravity( 400 ) ); // use a lower gravity for grenades to make them easier to see QAngle angles; VectorAngles(GetAbsVelocity(), angles ); SetLocalAngles( angles ); m_nRenderFX = kRenderFxGlowShell; SetRenderColor( 200, 200, 20 ); SetRenderAlpha( 255 ); // make NPCs afaid of it while in the air SetThink( &CBaseGrenadeConcussion::FallThink ); SetNextThink( gpGlobals->curtime ); // Tumble in air QAngle vecAngVel( random->RandomFloat ( -100, -500 ), 0, 0 ); SetLocalAngularVelocity( vecAngVel ); // Explode on contact SetTouch( &CBaseGrenadeConcussion::ExplodeConcussion ); m_flDamage = 80; // Allow player to blow this puppy up in the air m_takedamage = DAMAGE_YES; }
void C_ASW_Order_Arrow::RefreshArrow() { m_fCreatedTime = gpGlobals->curtime; SetRenderAlpha( 128 ); SetRenderFX( kRenderFxFadeOut, m_fCreatedTime + ASW_ORDER_ARROW_SOLID_TIME, ASW_ORDER_ARROW_FADE_TIME ); }
void C_SDKRagdoll::ClientThink( void ) { SetNextClientThink( CLIENT_THINK_ALWAYS ); if ( m_bFadingOut == true ) { int iAlpha = GetRenderAlpha(); int iFadeSpeed = 600.0f; iAlpha = MAX( iAlpha - ( iFadeSpeed * gpGlobals->frametime ), 0 ); SetRenderMode( kRenderTransAlpha ); //SetRenderColorA( iAlpha ); SetRenderAlpha( iAlpha ); if ( iAlpha == 0 ) { Release(); } return; } for( int iClient = 1; iClient <= gpGlobals->maxClients; ++iClient ) { C_SDKPlayer *pEnt = static_cast< C_SDKPlayer *> ( UTIL_PlayerByIndex( iClient ) ); if(!pEnt || !pEnt->IsPlayer()) continue; if ( m_hPlayer == NULL ) continue; if ( pEnt->entindex() == m_hPlayer->entindex() ) continue; if ( pEnt->GetHealth() <= 0 ) continue; #if defined ( SDK_USE_PRONE ) if ( pEnt->m_Shared.IsProne() == false ) continue; #endif Vector vTargetOrigin = pEnt->GetAbsOrigin(); Vector vMyOrigin = GetAbsOrigin(); Vector vDir = vTargetOrigin - vMyOrigin; if ( vDir.Length() > cl_ragdoll_pronecheck_distance.GetInt() ) continue; SetNextClientThink( CLIENT_THINK_ALWAYS ); m_bFadingOut = true; return; } //Tony; this is kind of silly, because.. whats the point of fading out? // if the player is looking at us, delay the fade if ( IsRagdollVisible() ) { StartFadeOut( 5.0 ); return; } if ( m_fDeathTime > gpGlobals->curtime ) return; Release(); // Die }
bool CStatueProp::CreateVPhysicsFromHitBoxes( CBaseAnimating *pInitBaseAnimating ) { if ( !pInitBaseAnimating ) return false; // Use the current animation sequence and cycle CopyAnimationDataFrom( pInitBaseAnimating ); // Copy over any render color color24 colorRender = pInitBaseAnimating->GetRenderColor(); SetRenderColor( colorRender.r, colorRender.g, colorRender.b ); SetRenderAlpha( pInitBaseAnimating->GetRenderAlpha() ); // Get hitbox data CStudioHdr *pStudioHdr = GetModelPtr(); if ( !pStudioHdr ) return false; mstudiohitboxset_t *set = pStudioHdr->pHitboxSet( m_nHitboxSet ); if ( !set ) return false; Vector position; QAngle angles; // Make enough pointers to convexes for each hitbox CPhysConvex **ppConvex = new (CPhysConvex*[ set->numhitboxes ]); float flTotalVolume = 0.0f; float flTotalSurfaceArea = 0.0f; for ( int i = 0; i < set->numhitboxes; i++ ) { // Get the hitbox info mstudiobbox_t *pbox = set->pHitbox( i ); GetBonePosition( pbox->bone, position, angles ); // Accumulate volume and area Vector flDimentions = pbox->bbmax - pbox->bbmin; flTotalVolume += flDimentions.x * flDimentions.y * flDimentions.z; flTotalSurfaceArea += 2.0f * ( flDimentions.x * flDimentions.y + flDimentions.x * flDimentions.z + flDimentions.y * flDimentions.z ); // Get angled min and max extents Vector vecMins, vecMaxs; VectorRotate( pbox->bbmin, angles, vecMins ); VectorRotate( pbox->bbmax, angles, vecMaxs ); // Get the corners in world space Vector vecMinCorner = position + vecMins; Vector vecMaxCorner = position + vecMaxs; // Get the normals of the hitbox in world space Vector vecForward, vecRight, vecUp; AngleVectors( angles, &vecForward, &vecRight, &vecUp ); vecRight = -vecRight; // Convert corners and normals to local space Vector vecCornerLocal[ 2 ]; Vector vecNormalLocal[ 3 ]; matrix3x4_t matToWorld = EntityToWorldTransform(); VectorITransform( vecMaxCorner, matToWorld, vecCornerLocal[ 0 ] ); VectorITransform( vecMinCorner, matToWorld, vecCornerLocal[ 1 ] ); VectorIRotate( vecForward, matToWorld, vecNormalLocal[ 0 ] ); VectorIRotate( vecRight, matToWorld, vecNormalLocal[ 1 ] ); VectorIRotate( vecUp, matToWorld, vecNormalLocal[ 2 ] ); // Create 6 planes from the local oriented hit box data float pPlanes[ 4 * 6 ]; for ( int iPlane = 0; iPlane < 6; ++iPlane ) { int iPlaneMod2 = iPlane % 2; int iPlaneDiv2 = iPlane / 2; bool bOdd = ( iPlaneMod2 == 1 ); // Plane Normal pPlanes[ iPlane * 4 + 0 ] = vecNormalLocal[ iPlaneDiv2 ].x * ( bOdd ? -1.0f : 1.0f ); pPlanes[ iPlane * 4 + 1 ] = vecNormalLocal[ iPlaneDiv2 ].y * ( bOdd ? -1.0f : 1.0f ); pPlanes[ iPlane * 4 + 2 ] = vecNormalLocal[ iPlaneDiv2 ].z * ( bOdd ? -1.0f : 1.0f ); // Plane D pPlanes[ iPlane * 4 + 3 ] = ( vecCornerLocal[ iPlaneMod2 ].x * vecNormalLocal[ iPlaneDiv2 ].x + vecCornerLocal[ iPlaneMod2 ].y * vecNormalLocal[ iPlaneDiv2 ].y + vecCornerLocal[ iPlaneMod2 ].z * vecNormalLocal[ iPlaneDiv2 ].z ) * ( bOdd ? -1.0f : 1.0f ); } // Create convex from the intersection of these planes ppConvex[ i ] = physcollision->ConvexFromPlanes( pPlanes, 6, 0.0f ); } // Make a single collide out of the group of convex boxes CPhysCollide *pPhysCollide = physcollision->ConvertConvexToCollide( ppConvex, set->numhitboxes ); delete[] ppConvex; // Create the physics object objectparams_t params = g_PhysDefaultObjectParams; params.pGameData = static_cast<void *>( this ); int nMaterialIndex = physprops->GetSurfaceIndex( "ice" ); // use ice material IPhysicsObject* p = physenv->CreatePolyObject( pPhysCollide, nMaterialIndex, GetAbsOrigin(), GetAbsAngles(), ¶ms ); Assert( p != NULL ); // Set velocity Vector vecInitialVelocity = pInitBaseAnimating->GetAbsVelocity(); p->SetVelocity( &vecInitialVelocity, NULL ); // Compute mass float flMass; float flDensity, flThickness; physprops->GetPhysicsProperties( nMaterialIndex, &flDensity, &flThickness, NULL, NULL ); // Make it more hollow flThickness = MIN ( 1.0f, flThickness + 0.5f ); if ( flThickness > 0.0f ) { flMass = flTotalSurfaceArea * flThickness * CUBIC_METERS_PER_CUBIC_INCH * flDensity; } else { // density is in kg/m^3, volume is in in^3 flMass = flTotalVolume * CUBIC_METERS_PER_CUBIC_INCH * flDensity; } // Mass is somewhere between the original and if it was all ice p->SetMass( flMass ); // Yes, gravity p->EnableGravity( true ); // Use this as our vphysics VPhysicsSetObject( p ); SetSolid( SOLID_VPHYSICS ); AddSolidFlags( FSOLID_CUSTOMRAYTEST | FSOLID_CUSTOMBOXTEST ); SetMoveType( MOVETYPE_VPHYSICS ); if ( pInitBaseAnimating != this ) { // Transfer children from the init base animating TransferChildren( pInitBaseAnimating, this ); CBaseEntity *pChild = FirstMoveChild(); while ( pChild ) { CEntityFreezing *pFreezing = dynamic_cast<CEntityFreezing*>( pChild ); if ( pFreezing ) { pFreezing->FinishFreezing(); } pChild = pChild->NextMovePeer(); } } return true; }
//----------------------------------------------------------------------------- // Purpose: Burn targets around us //----------------------------------------------------------------------------- void CEntityFlame::FlameThink( void ) { // Assure that this function will be ticked again even if we early-out in the if below. SetNextThink( gpGlobals->curtime + FLAME_DAMAGE_INTERVAL ); if ( !m_hEntAttached.Get() ) { UTIL_Remove( this ); return; } if ( m_hEntAttached->GetFlags() & FL_TRANSRAGDOLL ) { SetRenderAlpha( 0 ); return; } CAI_BaseNPC *pNPC = m_hEntAttached->MyNPCPointer(); if ( pNPC && !pNPC->IsAlive() ) { UTIL_Remove( this ); // Notify the NPC that it's no longer burning! pNPC->Extinguish(); return; } if ( m_hEntAttached->GetWaterLevel() > 0 ) { Vector mins, maxs; mins = m_hEntAttached->WorldSpaceCenter(); maxs = mins; maxs.z = m_hEntAttached->WorldSpaceCenter().z; maxs.x += 32; maxs.y += 32; mins.z -= 32; mins.x -= 32; mins.y -= 32; UTIL_Bubbles( mins, maxs, 12 ); } // See if we're done burning, or our attached ent has vanished if ( m_flLifetime < gpGlobals->curtime || m_hEntAttached == NULL ) { EmitSound( "General.StopBurning" ); m_bPlayingSound = false; SetThink( &CEntityFlame::SUB_Remove ); SetNextThink( gpGlobals->curtime + 0.5f ); // Notify anything we're attached to if ( m_hEntAttached ) { CBaseCombatCharacter *pAttachedCC = m_hEntAttached->MyCombatCharacterPointer(); if( pAttachedCC ) { // Notify the NPC that it's no longer burning! pAttachedCC->Extinguish(); } } return; } if ( m_hEntAttached ) { CBaseEntity *pAttacker = m_hAttacker ? m_hAttacker : this; // Do radius damage ignoring the entity I'm attached to. This will harm things around me. RadiusDamage( CTakeDamageInfo( this, pAttacker, m_fFlameRadiusDmgPerSecond * FLAME_DAMAGE_INTERVAL, DMG_BURN ), GetAbsOrigin(), m_flSize/2, CLASS_NONE, m_hEntAttached ); // Directly harm the entity I'm attached to. This is so we can precisely control how much damage the entity // that is on fire takes without worrying about the flame's position relative to the bodytarget (which is the // distance that the radius damage code uses to determine how much damage to inflict) m_hEntAttached->TakeDamage( CTakeDamageInfo( this, pAttacker, m_fFlameDmgPerSecond * FLAME_DAMAGE_INTERVAL, DMG_BURN | DMG_DIRECT ) ); if( !m_hEntAttached->IsNPC() && hl2_episodic.GetBool() ) { const float ENTITYFLAME_MOVE_AWAY_DIST = 24.0f; // Make a sound near my origin, and up a little higher (in case I'm on the ground, so NPC's still hear it) CSoundEnt::InsertSound( SOUND_MOVE_AWAY, GetAbsOrigin(), ENTITYFLAME_MOVE_AWAY_DIST, 0.1f, this, SOUNDENT_CHANNEL_REPEATED_DANGER ); CSoundEnt::InsertSound( SOUND_MOVE_AWAY, GetAbsOrigin() + Vector( 0, 0, 48.0f ), ENTITYFLAME_MOVE_AWAY_DIST, 0.1f, this, SOUNDENT_CHANNEL_REPEATING ); } } else { RadiusDamage( CTakeDamageInfo( this, this, m_fFlameRadiusDmgPerSecond * FLAME_DAMAGE_INTERVAL, DMG_BURN ), GetAbsOrigin(), m_flSize/2, CLASS_NONE, NULL ); } FireSystem_AddHeatInRadius( GetAbsOrigin(), m_flSize/2, 2.0f ); }