void CLaser::FireAtPoint(TraceResult &tr) { SetEndPos(tr.vecEndPos); if(m_pSprite) UTIL_SetOrigin(m_pSprite->pev, tr.vecEndPos); BeamDamage(&tr); DoSparks(GetStartPos(), tr.vecEndPos); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CEnvLaser::FireAtPoint( trace_t &tr ) { SetAbsEndPos( tr.endpos ); if ( m_pSprite ) { UTIL_SetOrigin( m_pSprite, tr.endpos ); } // Apply damage and do sparks every 1/10th of a second. if ( gpGlobals->curtime >= m_flFireTime + 0.1 ) { BeamDamage( &tr ); DoSparks( GetAbsStartPos(), tr.endpos ); } }
void EDeath::Process() { double &the_time = ztime->ztime; if(killme) return; if(the_time >= final_time) { killme = true; DoSparks(); return; } for(vector<EStandard*>::iterator i=extra_effects.begin(); i!=extra_effects.end(); i++) (*i)->Process(); }
//----------------------------------------------------------------------------- // Purpose: Turns the lightning on. If it is set for interval refiring, it will // begin doing so. If it is set to be continually on, it will do so. //----------------------------------------------------------------------------- void CEnvBeam::TurnOn( void ) { m_active = 1; if ( ServerSide() ) { RemoveEffects( EF_NODRAW ); DoSparks( GetAbsStartPos(), GetAbsEndPos() ); SetThink( &CEnvBeam::UpdateThink ); SetNextThink( gpGlobals->curtime ); SetFireTime( gpGlobals->curtime ); } else { SetThink( &CEnvBeam::StrikeThink ); SetNextThink( gpGlobals->curtime ); } }
void CLightning::Zap( const Vector &vecSrc, const Vector &vecDest ) { #if 1 MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY ); WRITE_BYTE( TE_BEAMPOINTS); WRITE_COORD(vecSrc.x); WRITE_COORD(vecSrc.y); WRITE_COORD(vecSrc.z); WRITE_COORD(vecDest.x); WRITE_COORD(vecDest.y); WRITE_COORD(vecDest.z); WRITE_SHORT( m_spriteTexture ); WRITE_BYTE( m_frameStart ); // framestart WRITE_BYTE( (int)pev->framerate); // framerate WRITE_BYTE( (int)(m_life*10.0) ); // life WRITE_BYTE( m_boltWidth ); // width WRITE_BYTE( m_noiseAmplitude ); // noise WRITE_BYTE( (int)pev->rendercolor.x ); // r, g, b WRITE_BYTE( (int)pev->rendercolor.y ); // r, g, b WRITE_BYTE( (int)pev->rendercolor.z ); // r, g, b WRITE_BYTE( pev->renderamt ); // brightness WRITE_BYTE( m_speed ); // speed MESSAGE_END(); #else MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY ); WRITE_BYTE(TE_LIGHTNING); WRITE_COORD(vecSrc.x); WRITE_COORD(vecSrc.y); WRITE_COORD(vecSrc.z); WRITE_COORD(vecDest.x); WRITE_COORD(vecDest.y); WRITE_COORD(vecDest.z); WRITE_BYTE(10); WRITE_BYTE(50); WRITE_BYTE(40); WRITE_SHORT(m_spriteTexture); MESSAGE_END(); #endif DoSparks( vecSrc, vecDest ); }
void CLightning::ToggleUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { if ( !ShouldToggle( useType, m_active ) ) return; if ( m_active ) { m_active = 0; pev->effects |= EF_NODRAW; pev->nextthink = 0; } else { m_active = 1; pev->effects &= ~EF_NODRAW; DoSparks( GetStartPos(), GetEndPos() ); if ( pev->dmg > 0 ) { pev->nextthink = gpGlobals->time; pev->dmgtime = gpGlobals->time; } } }
//----------------------------------------------------------------------------- // Purpose: // Input : &vecSrc - // &vecDest - //----------------------------------------------------------------------------- void CEnvBeam::Zap( const Vector &vecSrc, const Vector &vecDest ) { CBroadcastRecipientFilter filter; te->BeamPoints( filter, 0.0, &vecSrc, &vecDest, m_spriteTexture, 0, // No halo m_frameStart, (int)m_flFrameRate, m_life, m_boltWidth, m_boltWidth, // End width 0, // No fade m_noiseAmplitude, m_clrRender->r, m_clrRender->g, m_clrRender->b, m_clrRender->a, m_speed ); DoSparks( vecSrc, vecDest ); }
void ECannonDeath::Process() { double &the_time = ztime->ztime; if(killme) return; if(the_time >= final_time) { killme = true; DoSparks(); switch(object) { case ECANNONDEATH_GATLING: if(effect_list) effect_list->push_back((ZEffect*)(new ETurrentMissile(ztime, x, y, ex, ey, offset_time, ETURRENTMISSILE_GATLING))); break; case ECANNONDEATH_GUN: if(effect_list) effect_list->push_back((ZEffect*)(new ETurrentMissile(ztime, x, y, ex, ey, offset_time, ETURRENTMISSILE_GUN))); break; case ECANNONDEATH_HOWITZER: if(effect_list) effect_list->push_back((ZEffect*)(new ETurrentMissile(ztime, x, y, ex, ey, offset_time, ETURRENTMISSILE_HOWITZER))); break; case ECANNONDEATH_MISSILE: if(effect_list) effect_list->push_back((ZEffect*)(new ETurrentMissile(ztime, x, y, ex, ey, offset_time, ETURRENTMISSILE_MISSILE_CANNON))); break; default: killme = true; return; break; } return; } for(vector<EStandard*>::iterator i=extra_effects.begin(); i!=extra_effects.end(); i++) (*i)->Process(); }
//----------------------------------------------------------------------------- // Purpose: // Input : flags - // Output : int //----------------------------------------------------------------------------- int C_EntityDissolve::DrawModel( int flags ) { // See if we should draw if ( gpGlobals->frametime == 0 || m_bReadyToDraw == false ) return 0; C_BaseAnimating *pAnimating = GetMoveParent() ? GetMoveParent()->GetBaseAnimating() : NULL; if ( pAnimating == NULL ) return 0; matrix3x4_t *hitboxbones[MAXSTUDIOBONES]; if ( pAnimating->HitboxToWorldTransforms( hitboxbones ) == false ) return 0; studiohdr_t *pStudioHdr = modelinfo->GetStudiomodel( pAnimating->GetModel() ); if ( pStudioHdr == NULL ) return false; mstudiohitboxset_t *set = pStudioHdr->pHitboxSet( pAnimating->GetHitboxSet() ); if ( set == NULL ) return false; // Make sure the emitter is setup properly SetupEmitter(); // Get fade percentages for the effect float fadeInPerc = GetFadeInPercentage(); float fadeOutPerc = GetFadeOutPercentage(); float fadePerc = ( fadeInPerc >= 1.0f ) ? fadeOutPerc : fadeInPerc; Vector vecSkew = vec3_origin; // Do extra effects under certain circumstances if ( ( fadePerc < 0.99f ) && ( (m_nDissolveType == ENTITY_DISSOLVE_ELECTRICAL) || (m_nDissolveType == ENTITY_DISSOLVE_ELECTRICAL_LIGHT) ) ) { DoSparks( set, hitboxbones ); } // Skew the particles in front or in back of their targets vecSkew = CurrentViewForward() * ( 8.0f - ( ( 1.0f - fadePerc ) * 32.0f ) ); float spriteScale = ( ( gpGlobals->curtime - m_flStartTime ) / m_flFadeOutLength ); spriteScale = clamp( spriteScale, 0.75f, 1.0f ); // Cache off this material reference if ( g_Material_Spark == NULL ) { g_Material_Spark = ParticleMgr()->GetPMaterial( "effects/spark" ); } if ( g_Material_AR2Glow == NULL ) { g_Material_AR2Glow = ParticleMgr()->GetPMaterial( "effects/combinemuzzle2" ); } SimpleParticle *sParticle; for ( int i = 0; i < set->numhitboxes; ++i ) { Vector vecAbsOrigin, xvec, yvec; mstudiobbox_t *pBox = set->pHitbox(i); ComputeRenderInfo( pBox, *hitboxbones[pBox->bone], &vecAbsOrigin, &xvec, &yvec ); Vector offset; Vector xDir, yDir; xDir = xvec; float xScale = VectorNormalize( xDir ) * 0.75f; yDir = yvec; float yScale = VectorNormalize( yDir ) * 0.75f; int numParticles = clamp( 3.0f * fadePerc, 0.f, 3.f ); int iTempParts = 2; if ( m_nDissolveType == ENTITY_DISSOLVE_CORE ) { if ( m_bCoreExplode == true ) { numParticles = 15; iTempParts = 20; } } for ( int j = 0; j < iTempParts; j++ ) { // Skew the origin offset = xDir * Helper_RandomFloat( -xScale*0.5f, xScale*0.5f ) + yDir * Helper_RandomFloat( -yScale*0.5f, yScale*0.5f ); offset += vecSkew; if ( random->RandomInt( 0, 2 ) != 0 ) continue; sParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), g_Material_Spark, vecAbsOrigin + offset ); if ( sParticle == NULL ) return 1; sParticle->m_vecVelocity = Vector( Helper_RandomFloat( -4.0f, 4.0f ), Helper_RandomFloat( -4.0f, 4.0f ), Helper_RandomFloat( 16.0f, 64.0f ) ); if ( m_nDissolveType == ENTITY_DISSOLVE_CORE ) { if ( m_bCoreExplode == true ) { Vector vDirection = (vecAbsOrigin + offset) - m_vDissolverOrigin; VectorNormalize( vDirection ); sParticle->m_vecVelocity = vDirection * m_nMagnitude; } } if ( sParticle->m_vecVelocity.z > 0 ) { sParticle->m_uchStartSize = random->RandomFloat( 4, 6 ) * spriteScale; } else { sParticle->m_uchStartSize = 2 * spriteScale; } sParticle->m_flDieTime = random->RandomFloat( 0.4f, 0.5f ); // If we're the last particles, last longer if ( numParticles == 0 ) { sParticle->m_flDieTime *= 2.0f; sParticle->m_uchStartSize = 2 * spriteScale; sParticle->m_flRollDelta = Helper_RandomFloat( -4.0f, 4.0f ); if ( m_nDissolveType == ENTITY_DISSOLVE_CORE ) { if ( m_bCoreExplode == true ) { sParticle->m_flDieTime *= 2.0f; sParticle->m_flRollDelta = Helper_RandomFloat( -1.0f, 1.0f ); } } } else { sParticle->m_flRollDelta = Helper_RandomFloat( -8.0f, 8.0f ); } sParticle->m_flLifetime = 0.0f; sParticle->m_flRoll = Helper_RandomInt( 0, 360 ); float alpha = 255; sParticle->m_uchColor[0] = m_vEffectColor.x; sParticle->m_uchColor[1] = m_vEffectColor.y; sParticle->m_uchColor[2] = m_vEffectColor.z; sParticle->m_uchStartAlpha = alpha; sParticle->m_uchEndAlpha = 0; sParticle->m_uchEndSize = 0; } for ( int j = 0; j < numParticles; j++ ) { offset = xDir * Helper_RandomFloat( -xScale*0.5f, xScale*0.5f ) + yDir * Helper_RandomFloat( -yScale*0.5f, yScale*0.5f ); offset += vecSkew; sParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), g_Material_AR2Glow, vecAbsOrigin + offset ); if ( sParticle == NULL ) return 1; sParticle->m_vecVelocity = Vector( Helper_RandomFloat( -4.0f, 4.0f ), Helper_RandomFloat( -4.0f, 4.0f ), Helper_RandomFloat( -64.0f, 128.0f ) ); sParticle->m_uchStartSize = random->RandomFloat( 8, 12 ) * spriteScale; sParticle->m_flDieTime = 0.1f; sParticle->m_flLifetime = 0.0f; sParticle->m_flRoll = Helper_RandomInt( 0, 360 ); sParticle->m_flRollDelta = Helper_RandomFloat( -2.0f, 2.0f ); float alpha = 255; sParticle->m_uchColor[0] = m_vEffectColor.x; sParticle->m_uchColor[1] = m_vEffectColor.y; sParticle->m_uchColor[2] = m_vEffectColor.z; sParticle->m_uchStartAlpha = alpha; sParticle->m_uchEndAlpha = 0; sParticle->m_uchEndSize = 0; if ( m_nDissolveType == ENTITY_DISSOLVE_CORE ) { if ( m_bCoreExplode == true ) { Vector vDirection = (vecAbsOrigin + offset) - m_vDissolverOrigin; VectorNormalize( vDirection ); sParticle->m_vecVelocity = vDirection * m_nMagnitude; sParticle->m_flDieTime = 0.5f; } } } } return 1; }
void CLightning::StrikeThink( void ) { if ( m_life != 0 ) { if ( pev->spawnflags & SF_BEAM_RANDOM ) pev->nextthink = gpGlobals->time + m_life + RANDOM_FLOAT( 0, m_restrike ); else pev->nextthink = gpGlobals->time + m_life + m_restrike; } m_active = 1; if (FStringNull(m_iszEndEntity)) { if (FStringNull(m_iszStartEntity)) { RandomArea( ); } else { CBaseEntity *pStart = RandomTargetname( STRING(m_iszStartEntity) ); if (pStart != NULL) RandomPoint( pStart->pev->origin ); else ALERT( at_console, "env_beam: unknown entity \"%s\"\n", STRING(m_iszStartEntity) ); } return; } CBaseEntity *pStart = RandomTargetname( STRING(m_iszStartEntity) ); CBaseEntity *pEnd = RandomTargetname( STRING(m_iszEndEntity) ); if ( pStart != NULL && pEnd != NULL ) { if ( IsPointEntity( pStart ) || IsPointEntity( pEnd ) ) { if ( pev->spawnflags & SF_BEAM_RING) { // don't work return; } } MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY ); if ( IsPointEntity( pStart ) || IsPointEntity( pEnd ) ) { if ( !IsPointEntity( pEnd ) ) // One point entity must be in pEnd { CBaseEntity *pTemp; pTemp = pStart; pStart = pEnd; pEnd = pTemp; } if ( !IsPointEntity( pStart ) ) // One sided { WRITE_BYTE( TE_BEAMENTPOINT ); WRITE_SHORT( pStart->entindex() ); WRITE_COORD( pEnd->pev->origin.x); WRITE_COORD( pEnd->pev->origin.y); WRITE_COORD( pEnd->pev->origin.z); } else { WRITE_BYTE( TE_BEAMPOINTS); WRITE_COORD( pStart->pev->origin.x); WRITE_COORD( pStart->pev->origin.y); WRITE_COORD( pStart->pev->origin.z); WRITE_COORD( pEnd->pev->origin.x); WRITE_COORD( pEnd->pev->origin.y); WRITE_COORD( pEnd->pev->origin.z); } } else { if ( pev->spawnflags & SF_BEAM_RING) WRITE_BYTE( TE_BEAMRING ); else WRITE_BYTE( TE_BEAMENTS ); WRITE_SHORT( pStart->entindex() ); WRITE_SHORT( pEnd->entindex() ); } WRITE_SHORT( m_spriteTexture ); WRITE_BYTE( m_frameStart ); // framestart WRITE_BYTE( (int)pev->framerate); // framerate WRITE_BYTE( (int)(m_life*10.0) ); // life WRITE_BYTE( m_boltWidth ); // width WRITE_BYTE( m_noiseAmplitude ); // noise WRITE_BYTE( (int)pev->rendercolor.x ); // r, g, b WRITE_BYTE( (int)pev->rendercolor.y ); // r, g, b WRITE_BYTE( (int)pev->rendercolor.z ); // r, g, b WRITE_BYTE( pev->renderamt ); // brightness WRITE_BYTE( m_speed ); // speed MESSAGE_END(); DoSparks( pStart->pev->origin, pEnd->pev->origin ); if ( pev->dmg > 0 ) { TraceResult tr; UTIL_TraceLine( pStart->pev->origin, pEnd->pev->origin, dont_ignore_monsters, NULL, &tr ); BeamDamageInstant( &tr, pev->dmg ); } } }
//----------------------------------------------------------------------------- // Purpose: Strikes once for its configured lifetime. //----------------------------------------------------------------------------- void CEnvBeam::Strike( void ) { CBroadcastRecipientFilter filter; CBaseEntity *pStart = RandomTargetname( STRING(m_iszStartEntity) ); CBaseEntity *pEnd = RandomTargetname( STRING(m_iszEndEntity) ); if ( pStart == NULL || pEnd == NULL ) return; m_speed = (int)clamp( m_speed, 0, MAX_BEAM_SCROLLSPEED ); int pointStart = IsStaticPointEntity( pStart ); int pointEnd = IsStaticPointEntity( pEnd ); if ( pointStart || pointEnd ) { if ( m_spawnflags & SF_BEAM_RING ) { // don't work return; } te->BeamEntPoint( filter, 0.0, pointStart ? 0 : pStart->entindex(), pointStart ? &pStart->GetAbsOrigin() : NULL, pointEnd ? 0 : pEnd->entindex(), pointEnd ? &pEnd->GetAbsOrigin() : NULL, m_spriteTexture, 0, // No halo m_frameStart, (int)m_flFrameRate, m_life, m_boltWidth, m_boltWidth, // End width 0, // No fade m_noiseAmplitude, m_clrRender->r, m_clrRender->g, m_clrRender->b, m_clrRender->a, m_speed ); } else { if ( m_spawnflags & SF_BEAM_RING) { te->BeamRing( filter, 0.0, pStart->entindex(), pEnd->entindex(), m_spriteTexture, 0, // No halo m_frameStart, (int)m_flFrameRate, m_life, m_boltWidth, 0, // No spread m_noiseAmplitude, m_clrRender->r, m_clrRender->g, m_clrRender->b, m_clrRender->a, m_speed ); } else { te->BeamEnts( filter, 0.0, pStart->entindex(), pEnd->entindex(), m_spriteTexture, 0, // No halo m_frameStart, (int)m_flFrameRate, m_life, m_boltWidth, m_boltWidth, // End width 0, // No fade m_noiseAmplitude, m_clrRender->r, m_clrRender->g, m_clrRender->b, m_clrRender->a, m_speed ); } } DoSparks( pStart->GetAbsOrigin(), pEnd->GetAbsOrigin() ); if ( m_flDamage > 0 ) { trace_t tr; UTIL_TraceLine( pStart->GetAbsOrigin(), pEnd->GetAbsOrigin(), MASK_SOLID, NULL, COLLISION_GROUP_NONE, &tr ); BeamDamageInstant( &tr, m_flDamage ); } }
//----------------------------------------------------------------------------- // Purpose: Strikes once for its configured lifetime. //----------------------------------------------------------------------------- void CEnvBeam::Strike( void ) { CBroadcastRecipientFilter filter; CBaseEntity *pStart = RandomTargetname( STRING(m_iszStartEntity) ); CBaseEntity *pEnd = RandomTargetname( STRING(m_iszEndEntity) ); // if the end entity is missing, we use the Hammer-specified vector offset instead. bool bEndPointFromEntity = pEnd != NULL; if ( pStart == NULL || ( !bEndPointFromEntity && !HasEndPointHandle() ) ) return; Vector vEndPointLocation; if ( bEndPointFromEntity ) { vEndPointLocation = pEnd->GetAbsOrigin() ; } else { EntityToWorldSpace( m_vEndPointRelative, &vEndPointLocation ); } m_speed = clamp( m_speed, 0, MAX_BEAM_SCROLLSPEED ); bool pointStart = IsStaticPointEntity( pStart ); bool pointEnd = !bEndPointFromEntity || IsStaticPointEntity( pEnd ); if ( pointStart || pointEnd ) { if ( m_spawnflags & SF_BEAM_RING ) { // don't work return; } te->BeamEntPoint( filter, 0.0, pointStart ? 0 : pStart->entindex(), pointStart ? &pStart->GetAbsOrigin() : NULL, pointEnd ? 0 : pEnd->entindex(), pointEnd ? &vEndPointLocation : NULL, m_spriteTexture, 0, // No halo m_frameStart, (int)m_flFrameRate, m_life, m_boltWidth, m_boltWidth, // End width 0, // No fade m_noiseAmplitude, m_clrRender->r, m_clrRender->g, m_clrRender->b, m_clrRender->a, m_speed ); } else { if ( m_spawnflags & SF_BEAM_RING) { te->BeamRing( filter, 0.0, pStart->entindex(), pEnd->entindex(), m_spriteTexture, 0, // No halo m_frameStart, (int)m_flFrameRate, m_life, m_boltWidth, 0, // No spread m_noiseAmplitude, m_clrRender->r, m_clrRender->g, m_clrRender->b, m_clrRender->a, m_speed ); } else { te->BeamEnts( filter, 0.0, pStart->entindex(), pEnd->entindex(), m_spriteTexture, 0, // No halo m_frameStart, (int)m_flFrameRate, m_life, m_boltWidth, m_boltWidth, // End width 0, // No fade m_noiseAmplitude, m_clrRender->r, m_clrRender->g, m_clrRender->b, m_clrRender->a, m_speed ); } } DoSparks( pStart->GetAbsOrigin(), pEnd->GetAbsOrigin() ); if ( m_flDamage > 0 ) { trace_t tr; UTIL_TraceLine( pStart->GetAbsOrigin(), pEnd->GetAbsOrigin(), MASK_SOLID, NULL, COLLISION_GROUP_NONE, &tr ); BeamDamageInstant( &tr, m_flDamage ); } }