void LSQRSelfTest() { SparseMatrix A; Vector b; { int m=5,n=3,nnz=10; A.resize(m,n); b.resize(m); RandomSparseMatrix(A,nnz,1); RandomVector(b,1); cout<<"Overconstrained test"<<endl; TestLSQR(A,b); } { int m=3,n=5,nnz=10; A.resize(m,n); b.resize(m); RandomSparseMatrix(A,nnz,1); RandomVector(b,1); cout<<"Underconstrained test"<<endl; TestLSQR(A,b); } }
void C_Func_Dust::AttemptSpawnNewParticle() { // Find a random spot inside our bmodel. static int nTests=10; for( int iTest=0; iTest < nTests; iTest++ ) { Vector vPercent = RandomVector( 0, 1 ); Vector vTest = WorldAlignMins() + (WorldAlignMaxs() - WorldAlignMins()) * vPercent; int contents = enginetrace->GetPointContents_Collideable( GetCollideable(), vTest ); if( contents & CONTENTS_SOLID ) { CFuncDustParticle *pParticle = (CFuncDustParticle*)m_Effect.AddParticle( 10, m_hMaterial, vTest ); if( pParticle ) { pParticle->m_vVelocity = RandomVector( -m_SpeedMax, m_SpeedMax ); pParticle->m_vVelocity.z -= m_FallSpeed; pParticle->m_flLifetime = 0; pParticle->m_flDieTime = RemapVal( rand(), 0, RAND_MAX, m_LifetimeMin, m_LifetimeMax ); if( m_DustFlags & DUSTFLAGS_SCALEMOTES ) pParticle->m_flSize = RemapVal( rand(), 0, RAND_MAX, m_flSizeMin/10000.0f, m_flSizeMax/10000.0f ); else pParticle->m_flSize = RemapVal( rand(), 0, RAND_MAX, m_flSizeMin, m_flSizeMax ); pParticle->m_Color = m_Color; } break; } } }
void initialize(int N, int nz, Random R) { /* initialize vector multipliers and storage for result */ /* y = A*x; */ x = RandomVector(N, R); y = (double*) malloc(sizeof(double)*N); #if 0 // initialize square sparse matrix // // for this test, we create a sparse matrix with M/nz nonzeros // per row, with spaced-out evenly between the begining of the // row to the main diagonal. Thus, the resulting pattern looks // like // +-----------------+ // +* + // +*** + // +* * * + // +** * * + // +** * * + // +* * * * + // +* * * * + // +* * * * + // +-----------------+ // // (as best reproducible with integer artihmetic) // Note that the first nr rows will have elements past // the diagonal. #endif int nr = nz/N; /* average number of nonzeros per row */ int anz = nr *N; /* _actual_ number of nonzeros */ val = RandomVector(anz, R); col = (int*) malloc(sizeof(int)*nz); row = (int*) malloc(sizeof(int)*(N+1)); int r=0; int cycles=1; row[0] = 0; for (int r=0; r<N; r++) { /* initialize elements for row r */ int rowr = row[r]; int step = r/ nr; int i=0; row[r+1] = rowr + nr; if (step < 1) step = 1; /* take at least unit steps */ for (i=0; i<nr; i++) col[rowr+i] = i*step; } }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- bool CWeaponG43::Reload( void ) { bool fRet; float fCacheTime = m_flNextSecondaryAttack; fRet = DefaultReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD ); if ( fRet ) { // Undo whatever the reload process has done to our secondary // attack timer. We allow you to interrupt reloading to fire // a grenade. m_flNextSecondaryAttack = GetOwner()->m_flNextAttack = fCacheTime; WeaponSound( RELOAD ); CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); CEffectData data; data.m_vOrigin = pOwner->WorldSpaceCenter() + RandomVector( 0, 0 ); data.m_vAngles = QAngle( 90, random->RandomInt( 0, 360 ), 0 ); data.m_nEntIndex = entindex(); DispatchEffect( "ClipEject", data ); } return fRet; }
//----------------------------------------------------------------------------- // Purpose: Callback to create a sparkle effect on the client // Input : &data - information about the effect //----------------------------------------------------------------------------- void SparkleCallback( const CEffectData &data ) { // Create a simple particle emitter CSmartPtr<CSimpleEmitter> pSparkleEmitter = CSimpleEmitter::Create( "Sparkle" ); if ( pSparkleEmitter == NULL ) return; // Make local versions of our passed in data Vector origin = data.m_vOrigin; float scale = data.m_flScale; // Set our sort origin to make the system cull properly pSparkleEmitter->SetSortOrigin( origin ); // Find the material handle we wish to use for these particles PMaterialHandle hMaterial = pSparkleEmitter->GetPMaterial( "effects/yellowflare" ); SimpleParticle *pParticle; // Make a group of particles in the world for ( int i = 0; i < 64; i++ ) { // Create a particle pParticle = pSparkleEmitter->AddSimpleParticle( hMaterial, origin ); if ( pParticle == NULL ) return; // Set our sizes pParticle->m_uchStartSize = (unsigned char) scale; pParticle->m_uchEndSize = 0; // Set our roll pParticle->m_flRoll = random->RandomFloat( 0, 2*M_PI ); pParticle->m_flRollDelta = random->RandomFloat( -DEG2RAD( 180 ), DEG2RAD( 180 ) ); // Set our color pParticle->m_uchColor[0] = 255; // Red pParticle->m_uchColor[1] = 255; // Green pParticle->m_uchColor[2] = 255; // Blue // Set our alpha pParticle->m_uchStartAlpha = 0; pParticle->m_uchEndAlpha = 255; // Create a random vector Vector velocity = RandomVector( -1.0f, 1.0f ); VectorNormalize( velocity ); // Find a random speed for the particle float speed = random->RandomFloat( 4.0f, 8.0f ) * scale; // Build and set the velocity of the particle pParticle->m_vecVelocity = velocity * speed; // Declare our lifetime pParticle->m_flDieTime = 1.0f; } }
void CTripwireGrenade::MakeRope( void ) { SetThink( RopeBreakThink ); // Delay first think slightly so rope has time // to appear if person right in front of it SetNextThink( gpGlobals->curtime + 1.0f ); // Create hook for end of tripwire m_pHook = (CTripwireHook*)CBaseEntity::Create( "tripwire_hook", GetLocalOrigin(), GetLocalAngles() ); if (m_pHook) { Vector vShootVel = 800*(m_vecDir + Vector(0,0,0.3)+RandomVector(-0.01,0.01)); m_pHook->SetVelocity( vShootVel, vec3_origin); m_pHook->SetOwnerEntity( this ); m_pHook->m_hGrenade = this; m_pRope = CRopeKeyframe::Create(this,m_pHook,0,0); if (m_pRope) { m_pRope->m_Width = 1; m_pRope->m_RopeLength = 3; m_pRope->m_Slack = 100; CPASAttenuationFilter filter( this,"TripwireGrenade.ShootRope" ); EmitSound( filter, entindex(),"TripwireGrenade.ShootRope" ); } } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CAntlionGrub::CreateNugget( void ) { CGrubNugget *pNugget = (CGrubNugget *) CreateEntityByName( "item_grubnugget" ); if ( pNugget == NULL ) return; Vector vecOrigin; Vector vecForward; GetAttachment( LookupAttachment( "glow" ), vecOrigin, &vecForward ); // Find out what size to make this nugget! int nDenomination = GetNuggetDenomination(); pNugget->SetDenomination( nDenomination ); pNugget->SetAbsOrigin( vecOrigin ); pNugget->SetAbsAngles( RandomAngle( 0, 360 ) ); DispatchSpawn( pNugget ); IPhysicsObject *pPhys = pNugget->VPhysicsGetObject(); if ( pPhys ) { Vector vecForward; GetVectors( &vecForward, NULL, NULL ); Vector vecVelocity = RandomVector( -35.0f, 35.0f ) + ( vecForward * -RandomFloat( 50.0f, 75.0f ) ); AngularImpulse vecAngImpulse = RandomAngularImpulse( -100.0f, 100.0f ); pPhys->AddVelocity( &vecVelocity, &vecAngImpulse ); } }
//========================================================= // Ejecuta una acción al momento que el modelo hace // la animación correspondiente. //========================================================= void CWeapon357::Operator_HandleAnimEvent(animevent_t *pEvent, CBaseCombatCharacter *pOperator) { CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); switch( pEvent->event ) { #ifndef CLIENT_DLL case EVENT_WEAPON_RELOAD: { CEffectData data; // Emit six spent shells for ( int i = 0; i < 6; i++ ) { data.m_vOrigin = pOwner->WorldSpaceCenter() + RandomVector( -4, 4 ); data.m_vAngles = QAngle( 90, random->RandomInt( 0, 360 ), 0 ); data.m_nEntIndex = entindex(); DispatchEffect( "ShellEject", data ); } break; } #endif } }
void DropMoney( const Vector &vecOrigin, int amount, CBasePlayer * pTaker ) { Vector offsetVec = RandomVector(-4.0, 4.0); offsetVec.z = abs(offsetVec.z); //Vector newOrigin = vecOrigin + RandomVector(-4,4); Vector newOrigin = vecOrigin + offsetVec; CItemMoney * money = (CItemMoney*)CBaseEntity::Create( "item_money", newOrigin, vec3_angle ); if ( money ) { CPASAttenuationFilter filter( pTaker ); pTaker->EmitSound( filter, pTaker->entindex(), "Grenade_Molotov.Detonate" ); money->ChangeTeam( pTaker->GetTeamNumber() ); money->m_iAmount = amount; money->m_taker = pTaker; //================================================================================== // ItemMoney is not a VPhysObject so, the following is actually dead code... for now //================================================================================== //IPhysicsObject *pPhysicsObject = money->VPhysicsGetObject(); //if ( pPhysicsObject ) //{ // Vector vel = RandomVector( -64.0f, 64.0f ); // vel.z = abs(vel.z); // AngularImpulse angImp = RandomAngularImpulse( -300.0f, 300.0f ); // // Angular velocity is always applied in local space in vphysics // AngularImpulse localAngImp; // pPhysicsObject->WorldToLocalVector( &localAngImp, angImp ); // pPhysicsObject->AddVelocity( &vel, &localAngImp ); //} } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_ObjectEMPGenerator::ClientThink( void ) { // Add particles at the target. float flCur = gpGlobals->frametime; while ( m_ParticleEvent.NextEvent( flCur ) ) { Vector vPos = WorldSpaceCenter( ); Vector vOffset = RandomVector( -1, 1 ); VectorNormalize( vOffset ); vPos += vOffset * RandomFloat( 0, 50 ); SimpleParticle *pParticle = m_pEmitter->AddSimpleParticle( m_hParticleMaterial, vPos ); if ( pParticle ) { // Move the points along the path. pParticle->m_vecVelocity.Init(); pParticle->m_flRoll = 0; pParticle->m_flRollDelta = 0; pParticle->m_flDieTime = 0.4f; pParticle->m_flLifetime = 0; pParticle->m_uchColor[0] = 255; pParticle->m_uchColor[1] = 255; pParticle->m_uchColor[2] = 255; pParticle->m_uchStartAlpha = 32; pParticle->m_uchEndAlpha = 0; pParticle->m_uchStartSize = 6; pParticle->m_uchEndSize = 4; pParticle->m_iFlags = 0; } } }
void C_MovieExplosion::Update(float fTimeDelta) { if(!m_pParticleMgr) return; m_EmitterLifetime += fTimeDelta; if(m_EmitterLifetime > EXPLOSION_EMITTER_LIFETIME) return; m_EmitterAlpha = (float)sin(m_EmitterLifetime * 3.14159f / EXPLOSION_EMITTER_LIFETIME); // Simulate the emitters and have them spit out particles. for(int iEmitter=0; iEmitter < NUM_MOVIEEXPLOSION_EMITTERS; iEmitter++) { MovieExplosionEmitter *pEmitter = &m_Emitters[iEmitter]; pEmitter->m_Pos = pEmitter->m_Pos + pEmitter->m_Velocity * fTimeDelta; pEmitter->m_Velocity = pEmitter->m_Velocity * 0.9; float tempDelta = fTimeDelta; while(pEmitter->m_ParticleSpawn.NextEvent(tempDelta)) { StandardParticle_t *pParticle = (StandardParticle_t*)m_ParticleEffect.AddParticle( sizeof(StandardParticle_t), m_iFireballMaterial); if(pParticle) { pParticle->m_Pos = pEmitter->m_Pos; pParticle->m_Velocity = pEmitter->m_Velocity * 0.2f + RandomVector(-20, 20); } } } }
//----------------------------------------------------------------------------- // Purpose: Creates an instance of this entity //----------------------------------------------------------------------------- CTFFlameEntity *CTFFlameEntity::Create( const Vector &vecOrigin, const QAngle &vecAngles, CBaseEntity *pOwner, int iDmgType, float flDmgAmount ) { CTFFlameEntity *pFlame = static_cast<CTFFlameEntity*>( CBaseEntity::Create( "tf_flame", vecOrigin, vecAngles, pOwner ) ); if ( !pFlame ) return NULL; // Initialize the owner. pFlame->SetOwnerEntity( pOwner ); pFlame->m_hAttacker = pOwner->GetOwnerEntity(); CBaseEntity *pAttacker = (CBaseEntity *) pFlame->m_hAttacker; if ( pAttacker ) { pFlame->m_iAttackerTeam = pAttacker->GetTeamNumber(); } // Set team. pFlame->ChangeTeam( pOwner->GetTeamNumber() ); pFlame->m_iDmgType = iDmgType; pFlame->m_flDmgAmount = flDmgAmount; // Setup the initial velocity. Vector vecForward, vecRight, vecUp; AngleVectors( vecAngles, &vecForward, &vecRight, &vecUp ); float velocity = tf_flamethrower_velocity.GetFloat(); pFlame->m_vecBaseVelocity = vecForward * velocity; pFlame->m_vecBaseVelocity += RandomVector( -velocity * tf_flamethrower_vecrand.GetFloat(), velocity * tf_flamethrower_vecrand.GetFloat() ); pFlame->m_vecAttackerVelocity = pOwner->GetOwnerEntity()->GetAbsVelocity(); pFlame->SetAbsVelocity( pFlame->m_vecBaseVelocity ); // Setup the initial angles. pFlame->SetAbsAngles( vecAngles ); return pFlame; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponStriderBuster::Detonate( void ) { CBaseEntity *pVictim = GetOwnerEntity(); if ( !m_bDud && pVictim ) { // Kill the strider (with magic effect) CBasePlayer *pPlayer = AI_GetSinglePlayer(); CTakeDamageInfo info( pPlayer, this, RandomVector( -100.0f, 100.0f ), GetAbsOrigin(), pVictim->GetHealth(), DMG_GENERIC ); pVictim->TakeDamage( info ); gamestats->Event_WeaponHit( ToBasePlayer( pPlayer ), true, GetClassname(), info ); // Tracker 62293: There's a bug where the inflictor/attacker are reversed when calling TakeDamage above so the player never gets // credit for the strider buster kills. The code has a bunch of assumptions lower level, so it's safer to just fix it here by // crediting a kill to the player directly. gamestats->Event_PlayerKilledOther( pPlayer, pVictim, info ); } m_OnDetonate.FireOutput( this, this ); // Explode if ( !m_bDud ) { CreateDestroyedEffect(); EmitSound( "Weapon_StriderBuster.Detonate" ); } else { DispatchParticleEffect( "striderbuster_explode_dummy_core", GetAbsOrigin(), GetAbsAngles() ); EmitSound( "Weapon_StriderBuster.Dud_Detonate" ); } // Go to bits! Shatter( pVictim ); }
//----------------------------------------------------------------------------- // Purpose: Trail smoke //----------------------------------------------------------------------------- void CASW_Shotgun_Pellet_Predicted::ClientThink( void ) { return; CSmartPtr<CSimpleEmitter> pEmitter = CSimpleEmitter::Create( "CASW_Shotgun_Pellet_Predicted::Effect" ); PMaterialHandle hSphereMaterial = pEmitter->GetPMaterial( "sprites/chargeball" ); // Add particles at the target. float flCur = gpGlobals->frametime; while ( m_ParticleEvent.NextEvent( flCur ) ) { Vector vecOrigin = GetAbsOrigin() + RandomVector( -2,2 ); pEmitter->SetSortOrigin( vecOrigin ); SimpleParticle *pParticle = (SimpleParticle *) pEmitter->AddParticle( sizeof(SimpleParticle), hSphereMaterial, vecOrigin ); if ( pParticle == NULL ) return; pParticle->m_flLifetime = 0.0f; pParticle->m_flDieTime = random->RandomFloat( 0.1f, 0.3f ); pParticle->m_uchStartSize = random->RandomFloat(2,4); pParticle->m_uchEndSize = pParticle->m_uchStartSize + 2; pParticle->m_vecVelocity = vec3_origin; pParticle->m_uchStartAlpha = 128; pParticle->m_uchEndAlpha = 0; pParticle->m_flRoll = random->RandomFloat( 180, 360 ); pParticle->m_flRollDelta = random->RandomFloat( -1, 1 ); pParticle->m_uchColor[0] = 128; pParticle->m_uchColor[1] = 128; pParticle->m_uchColor[2] = 128; } }
NpLine NonIntersectingLine(const NpTetrahedron& t) { // Find a point outside the tetrahedron double u0, u1, u2; do { u0 = NpRand(-10.0, 10.0); u1 = NpRand(-10.0, 10.0); u2 = NpRand(-10.0, 10.0); } while ((u0 >= 0.0) && (u0 <= 1.0) && (u1 >= 0.0) && (u1 <= 1.0) && (u2 >= 0.0) && (u1 <= 1.0) && (u0+u1+u2 >= 0.0) && (u0+u1+u2 <= 1.0)); NpVector tetrahedronPt = t.TetrahedronPoint(u0, u1, u2); // Find a random direction NpVector dir = RandomVector(NpVector(-1, -1, -1), NpVector(1, 1, 1)); // Generate two points on the line double t0 = NpRand(-10.0, 0.0); NpVector linePt0 = tetrahedronPt + t0*dir; double t1 = NpRand(0.0, 10.0); NpVector linePt1 = tetrahedronPt + t1*dir; return NpLine(linePt0, linePt1); }
NpTetrahedron RandomTetrahedron(const NpVector& min, const NpVector& max) { NpTetrahedron tetra(RandomVector(min, max), RandomVector(min, max), RandomVector(min, max), RandomVector(min, max)); double vol = (tetra.v[0]-tetra.v[1]) * ((tetra.v[0]-tetra.v[2]) ^ (tetra.v[0]-tetra.v[3])); if (vol < 0) { NpVector tmp(tetra.v[2]); tetra.v[2] = tetra.v[3]; tetra.v[3] = tmp; } return tetra; }
void C_Func_Dust::AttemptSpawnNewParticle() { // Find a random spot inside our bmodel. static int nTests=10; for( int iTest=0; iTest < nTests; iTest++ ) { Vector vPercent = RandomVector( 0, 1 ); double x = rand() % 6000-3000; double y = rand() % 6000-3000; double z = rand() % 600; double x_distance = (x); double y_distance = y; double distance = sqrt((x_distance*x_distance) + (y_distance*y_distance)); int now = gpGlobals->curtime; //Vector vTest = WorldAlignMins() + (WorldAlignMaxs() - WorldAlignMins()) * vPercent; Vector vTest = Vector(x,y,z); int contents = enginetrace->GetPointContents_Collideable( GetCollideable(), vTest ); if( contents & CONTENTS_SOLID ) { PMaterialHandle my_hMaterial = m_Effect.GetPMaterial( "particle/particle_smokegrenade1" );; CFuncDustParticle *pParticle = (CFuncDustParticle*)m_Effect.AddParticle( 10, my_hMaterial, vTest ); if( pParticle ) { pParticle->m_vVelocity = RandomVector( -m_SpeedMax, m_SpeedMax ); pParticle->m_vVelocity.z -= m_FallSpeed; pParticle->m_flLifetime = 0; pParticle->m_flDieTime = RemapVal( rand(), 0, RAND_MAX, m_LifetimeMin, m_LifetimeMax ); if( m_DustFlags & DUSTFLAGS_SCALEMOTES ) pParticle->m_flSize = RemapVal( rand(), 0, RAND_MAX, m_flSizeMin/10000.0f, m_flSizeMax/10000.0f ); else pParticle->m_flSize = RemapVal( rand(), 0, RAND_MAX, m_flSizeMin, m_flSizeMax ); pParticle->m_Color = m_Color; } break; } } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CObjectSentrygun::MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType ) { trace_t tmptrace; tmptrace.endpos = tr.endpos + RandomVector(-10,10); // Sentryguns are perfectly accurate, but this doesn't look good for tracers. // Add a little noise to them, but not enough so that it looks like they're missing. BaseClass::MakeTracer( vecTracerSrc, tmptrace, iTracerType ); }
//----------------------------------------------------------------------------- // Purpose: // Input : &info - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- void CNPC_CombineShot::Event_Killed(const CTakeDamageInfo &info) { // Don't bother if we've been told not to, or the player has a megaphyscannon if ( combine_shot_spawn_health.GetBool() == false || PlayerHasMegaPhysCannon() ) { BaseClass::Event_Killed( info ); return; } CBasePlayer *pPlayer = ToBasePlayer( info.GetAttacker() ); if ( !pPlayer ) { CPropVehicleDriveable *pVehicle = dynamic_cast<CPropVehicleDriveable *>( info.GetAttacker() ) ; if ( pVehicle && pVehicle->GetDriver() && pVehicle->GetDriver()->IsPlayer() ) { pPlayer = assert_cast<CBasePlayer *>( pVehicle->GetDriver() ); } } if ( pPlayer != NULL ) { CHalfLife2 *pHL2GameRules = static_cast<CHalfLife2 *>(g_pGameRules); // Attempt to drop health if ( pHL2GameRules->NPC_ShouldDropHealth( pPlayer ) ) { DropItem( "item_healthvial", WorldSpaceCenter()+RandomVector(-4,4), RandomAngle(0,360) ); pHL2GameRules->NPC_DroppedHealth(); } if ( HasSpawnFlags( SF_COMBINE_NO_GRENADEDROP ) == false ) { // Attempt to drop a grenade if ( pHL2GameRules->NPC_ShouldDropGrenade( pPlayer ) ) { DropItem( "weapon_frag", WorldSpaceCenter()+RandomVector(-4,4), RandomAngle(0,360) ); pHL2GameRules->NPC_DroppedGrenade(); } } } BaseClass::Event_Killed( info ); }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void HunterDamageCallback( const CEffectData &data ) { CSmartPtr<CSimple3DEmitter> pGlassEmitter = CSimple3DEmitter::Create( "HunterDamage" ); if ( pGlassEmitter == NULL ) return; pGlassEmitter->SetSortOrigin( data.m_vOrigin ); // Handle increased scale const float flMaxSpeed = 400.0f; const float flMinSpeed = 50.0f; float flAngularSpray = 1.0f; // Setup our collision information pGlassEmitter->m_ParticleCollision.Setup( data.m_vOrigin, &data.m_vNormal, flAngularSpray, flMinSpeed, flMaxSpeed, 600.0f, 0.2f ); Vector dir, end; int numFlecks = 32; Particle3D *pFleckParticle; Vector spawnOffset; //Dump out flecks for ( int i = 0; i < numFlecks; i++ ) { spawnOffset = data.m_vOrigin + RandomVector( -32.0f, 32.0f ); pFleckParticle = (Particle3D *) pGlassEmitter->AddParticle( sizeof(Particle3D), g_Mat_Fleck_Antlion[random->RandomInt(0,1)], spawnOffset ); if ( pFleckParticle == NULL ) break; pFleckParticle->m_flLifeRemaining = random->RandomFloat( 2.0f, 3.0f ); dir[0] = data.m_vNormal[0] + random->RandomFloat( -flAngularSpray, flAngularSpray ); dir[1] = data.m_vNormal[1] + random->RandomFloat( -flAngularSpray, flAngularSpray ); dir[2] = data.m_vNormal[2] + random->RandomFloat( -flAngularSpray, flAngularSpray ); pFleckParticle->m_uchSize = random->RandomInt( 3, 8 ); pFleckParticle->m_vecVelocity = dir * random->RandomFloat( flMinSpeed, flMaxSpeed); pFleckParticle->m_vAngles = RandomAngle( 0, 360 ); pFleckParticle->m_flAngSpeed = random->RandomFloat( -800, 800 ); unsigned char color = 255; pFleckParticle->m_uchFrontColor[0] = color; pFleckParticle->m_uchFrontColor[1] = color; pFleckParticle->m_uchFrontColor[2] = color; pFleckParticle->m_uchBackColor[0] = color * 0.25f; pFleckParticle->m_uchBackColor[1] = color * 0.25f; pFleckParticle->m_uchBackColor[2] = color * 0.25f; } }
void ShootMe() { CASW_Player *pPlayer = ToASW_Player(UTIL_GetCommandClient()); if ( pPlayer->GetMarine() ) { CTakeDamageInfo dmgInfo( pPlayer, pPlayer, 3, DMG_BULLET ); Vector vecDir = RandomVector(-1, 1); trace_t tr; pPlayer->GetMarine()->DispatchTraceAttack( dmgInfo, vecDir, &tr ); } }
//----------------------------------------------------------------------------- // Purpose: Client-side think function for the entity //----------------------------------------------------------------------------- void C_Sparkler::ClientThink( void ) { // We must have a valid emitter if ( m_hEmitter == NULL ) return; // We must be allowed to emit particles by the server if ( m_bEmit == false ) return; SimpleParticle *pParticle; float curTime = gpGlobals->frametime; // Add as many particles as required this frame while ( m_tParticleTimer.NextEvent( curTime ) ) { // Create the particle pParticle = m_hEmitter->AddSimpleParticle( m_hMaterial, GetAbsOrigin() ); if ( pParticle == NULL ) return; // Setup our size pParticle->m_uchStartSize = (unsigned char) m_flScale; pParticle->m_uchEndSize = 0; // Setup our roll pParticle->m_flRoll = random->RandomFloat( 0, 2*M_PI ); pParticle->m_flRollDelta = random->RandomFloat( -DEG2RAD( 180 ), DEG2RAD( 180 ) ); // Set our color pParticle->m_uchColor[0] = 255; pParticle->m_uchColor[1] = 255; pParticle->m_uchColor[2] = 255; // Setup our alpha values pParticle->m_uchStartAlpha = 255; pParticle->m_uchEndAlpha = 255; // Obtain a random direction Vector velocity = RandomVector( -1.0f, 1.0f ); VectorNormalize( velocity ); // Obtain a random speed float speed = random->RandomFloat( 4.0f, 8.0f ) * m_flScale; // Set our velocity pParticle->m_vecVelocity = velocity * speed; // Die in a short range of time pParticle->m_flDieTime = random->RandomFloat( 0.25f, 0.5f ); } }
// Do part of our effect void ClientThink( void ) { // Update our effects if ( m_bActive && gpGlobals->frametime != 0.0f && ( random->RandomInt( 0, 5 ) == 0 ) ) { Vector vecOrigin; QAngle vecAngles; GetAttachment( 1, vecOrigin, vecAngles ); Vector vForward; AngleVectors( vecAngles, &vForward ); Vector vEnd = vecOrigin - vForward * 1.0f; // Inner beams BeamInfo_t beamInfo; beamInfo.m_vecStart = vEnd; Vector offset = RandomVector( -6, 2 ); offset += Vector(2,2,2); beamInfo.m_vecEnd = vecOrigin + offset; beamInfo.m_pStartEnt= cl_entitylist->GetEnt( BEAMENT_ENTITY( entindex() ) ); beamInfo.m_pEndEnt = cl_entitylist->GetEnt( BEAMENT_ENTITY( entindex() ) ); beamInfo.m_nStartAttachment = 1; beamInfo.m_nEndAttachment = 2; beamInfo.m_nType = TE_BEAMTESLA; beamInfo.m_pszModelName = "sprites/physbeam.vmt"; beamInfo.m_flHaloScale = 0.0f; beamInfo.m_flLife = 0.01f; beamInfo.m_flWidth = random->RandomFloat( 0.5f, 2.0f ); beamInfo.m_flEndWidth = 0; beamInfo.m_flFadeLength = 0.0f; beamInfo.m_flAmplitude = random->RandomFloat( 1, 2 ); beamInfo.m_flBrightness = 255.0; beamInfo.m_flSpeed = 0.0; beamInfo.m_nStartFrame = 0.0; beamInfo.m_flFrameRate = 1.0f; beamInfo.m_flRed = 255.0f;; beamInfo.m_flGreen = 255.0f; beamInfo.m_flBlue = 255.0f; beamInfo.m_nSegments = 8; beamInfo.m_bRenderable = true; beamInfo.m_nFlags = (FBEAM_ONLYNOISEONCE|FBEAM_SHADEOUT); beams->CreateBeamPoints( beamInfo ); } }
//----------------------------------------------------------------------------- // Purpose: Burn targets around us //----------------------------------------------------------------------------- void CRagdollBoogie::BoogieThink( void ) { CRagdollProp *pRagdoll = dynamic_cast< CRagdollProp* >( GetMoveParent() ); if ( !pRagdoll ) { UTIL_Remove( this ); return; } float flMagnitude = m_flMagnitude; if ( m_flBoogieLength != 0 ) { float dt = gpGlobals->curtime - m_flStartTime; if ( dt >= m_flBoogieLength ) { // Don't remove while suppressed... this helps if we try to start another boogie if ( m_nSuppressionCount == 0 ) { UTIL_Remove( this ); } SetThink( NULL ); return; } if ( dt < 0 ) { SetNextThink( gpGlobals->curtime + random->RandomFloat( 0.1, 0.2f ) ); return; } flMagnitude = SimpleSplineRemapVal( dt, 0.0f, m_flBoogieLength, m_flMagnitude, 0.0f ); } #ifndef _XBOX if ( m_nSuppressionCount == 0 ) { ragdoll_t *pRagdollPhys = pRagdoll->GetRagdoll( ); for ( int j = 0; j < pRagdollPhys->listCount; ++j ) { float flMass = pRagdollPhys->list[j].pObject->GetMass(); float flForce = m_flMagnitude * flMass; Vector vecForce; vecForce = RandomVector( -flForce, flForce ); pRagdollPhys->list[j].pObject->ApplyForceCenter( vecForce ); } } #endif // !_XBOX SetNextThink( gpGlobals->curtime + random->RandomFloat( 0.1, 0.2f ) ); }
//----------------------------------------------------------------------------- // Purpose: If someone damaged, me shoot of my missiles and die // Input : // Output : //----------------------------------------------------------------------------- void CTripwireGrenade::Event_Killed( const CTakeDamageInfo &info ) { if (m_iHealth > 0) { // Fire missiles and blow up for (int i=0;i<6;i++) { Vector vTargetPos = GetAbsOrigin() + RandomVector(-600,600); FireMissile(vTargetPos); } BreakRope(); UTIL_Remove(this); } }
//----------------------------------------------------------------------------- // Purpose: Burn targets around us //----------------------------------------------------------------------------- void CEntityDissolve::ElectrocuteThink( void ) { CRagdollProp *pRagdoll = dynamic_cast< CRagdollProp* >( GetMoveParent() ); if ( !pRagdoll ) return; ragdoll_t *pRagdollPhys = pRagdoll->GetRagdoll( ); for ( int j = 0; j < pRagdollPhys->listCount; ++j ) { Vector vecForce; vecForce = RandomVector( -2400.0f, 2400.0f ); pRagdollPhys->list[j].pObject->ApplyForceCenter( vecForce ); } SetContextThink( &CEntityDissolve::ElectrocuteThink, gpGlobals->curtime + random->RandomFloat( 0.1, 0.2f ), s_pElectroThinkContext ); }
//----------------------------------------------------------------------------- // Purpose: // Input : &data - //----------------------------------------------------------------------------- void WheelDustCallback( const CEffectData &data ) { CSmartPtr<CSimpleEmitter> pSimple = CSimpleEmitter::Create( "dust" ); pSimple->SetSortOrigin( data.m_vOrigin ); pSimple->SetNearClip( 32, 64 ); SimpleParticle *pParticle; Vector offset; //FIXME: Better sampling area offset = data.m_vOrigin + ( data.m_vNormal * data.m_flScale ); //Find area ambient light color and use it to tint smoke Vector worldLight = WorldGetLightForPoint( offset, true ); //Throw puffs offset.Random( -(data.m_flScale*16.0f), data.m_flScale*16.0f ); offset.z = 0.0f; offset += data.m_vOrigin + ( data.m_vNormal * data.m_flScale ); pParticle = (SimpleParticle *) pSimple->AddParticle( sizeof(SimpleParticle), g_Mat_DustPuff[0], offset ); if ( pParticle != NULL ) { pParticle->m_flLifetime = 0.0f; pParticle->m_flDieTime = random->RandomFloat( 0.25f, 0.5f ); pParticle->m_vecVelocity = RandomVector( -1.0f, 1.0f ); VectorNormalize( pParticle->m_vecVelocity ); pParticle->m_vecVelocity[2] += random->RandomFloat( 16.0f, 32.0f ) * (data.m_flScale*2.0f); int color = random->RandomInt( 100, 150 ); pParticle->m_uchColor[0] = 16 + ( worldLight[0] * (float) color ); pParticle->m_uchColor[1] = 8 + ( worldLight[1] * (float) color ); pParticle->m_uchColor[2] = ( worldLight[2] * (float) color ); pParticle->m_uchStartAlpha = random->RandomInt( 64.0f*data.m_flScale, 128.0f*data.m_flScale ); pParticle->m_uchEndAlpha = 0; pParticle->m_uchStartSize = random->RandomInt( 16, 24 ) * data.m_flScale; pParticle->m_uchEndSize = random->RandomInt( 32, 48 ) * data.m_flScale; pParticle->m_flRoll = random->RandomInt( 0, 360 ); pParticle->m_flRollDelta = random->RandomFloat( -2.0f, 2.0f ); } }
//----------------------------------------------------------------------------- // Purpose: // Input : flPerc - //----------------------------------------------------------------------------- void C_MortarShell::AddExplodingParticles( float flPerc ) { SimpleParticle *sParticle; Vector offset; float radius = 48.0f * flPerc; float flCur = gpGlobals->frametime; // Anime ground effects while ( m_ParticleEvent.NextEvent( flCur ) ) { offset.x = random->RandomFloat( -radius, radius ); offset.y = random->RandomFloat( -radius, radius ); offset.z = random->RandomFloat( -8.0f, 8.0f ); offset += GetAbsOrigin(); sParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_pEmitter->GetPMaterial( "effects/spark" ), offset ); if ( sParticle == NULL ) return; sParticle->m_vecVelocity = RandomVector( -1.0f, 1.0f ) + Vector( 0, 0, 1 ); sParticle->m_vecVelocity *= ( 750.0f * flPerc ); sParticle->m_uchStartSize = random->RandomFloat( 2, 4 ) * flPerc; sParticle->m_flDieTime = random->RandomFloat( 0.25f, 0.5f ); sParticle->m_flLifetime = 0.0f; sParticle->m_flRoll = Helper_RandomInt( 0, 360 ); float alpha = 255 * flPerc; sParticle->m_flRollDelta = Helper_RandomFloat( -8.0f * flPerc, 8.0f * flPerc ); sParticle->m_uchColor[0] = alpha; sParticle->m_uchColor[1] = alpha; sParticle->m_uchColor[2] = alpha; sParticle->m_uchStartAlpha = alpha; sParticle->m_uchEndAlpha = 0; sParticle->m_uchEndSize = 0; } }
void CreateHairballCallback() { for ( int i=0; i < 20; i++ ) { C_Hairball *pHairball = new C_Hairball; pHairball->Init(); // Put it a short distance in front of the player. C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return; Vector vForward; AngleVectors( pPlayer->GetAbsAngles(), &vForward ); pHairball->SetLocalOrigin( pPlayer->GetAbsOrigin() + vForward * 300 + RandomVector( 0, 100 ) ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeapon357::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) { switch( pEvent->event ) { case EVENT_WEAPON_PISTOL_FIRE: { Vector vecShootOrigin, vecShootDir; vecShootOrigin = pOperator->Weapon_ShootPosition(); CAI_BaseNPC *npc = pOperator->MyNPCPointer(); ASSERT(npc != NULL); vecShootDir = npc->GetActualShootTrajectory(vecShootOrigin); CSoundEnt::InsertSound(SOUND_COMBAT | SOUND_CONTEXT_GUNFIRE, pOperator->GetAbsOrigin(), SOUNDENT_VOLUME_PISTOL, 0.2, pOperator, SOUNDENT_CHANNEL_WEAPON, pOperator->GetEnemy()); WeaponSound(SINGLE_NPC); pOperator->FireBullets(1, vecShootOrigin, vecShootDir, VECTOR_CONE_PRECALCULATED, MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 2); pOperator->DoMuzzleFlash(); m_iClip1 = m_iClip1 - 1; } case EVENT_WEAPON_RELOAD: { CBasePlayer *pOwner = ToBasePlayer(GetOwner()); CEffectData data; // Emit six spent shells for (int i = 0; i < 6; i++) { data.m_vOrigin = pOwner->WorldSpaceCenter() + RandomVector(-4, 4); data.m_vAngles = QAngle(90, random->RandomInt(0, 360), 0); data.m_nEntIndex = entindex(); DispatchEffect("ShellEject", data); } } break; default: BaseClass::Operator_HandleAnimEvent(pEvent, pOperator); break; } }