//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void CNPC_GroundTurret::Shoot() { FireBulletsInfo_t info; Vector vecSrc = EyePosition(); Vector vecDir; GetVectors( &vecDir, NULL, NULL ); for( int i = 0 ; i < 1 ; i++ ) { info.m_vecSrc = vecSrc; if( i > 0 || !GetEnemy()->IsPlayer() ) { // Subsequent shots or shots at non-players random GetVectors( &info.m_vecDirShooting, NULL, NULL ); info.m_vecSpread = m_vecSpread; } else { // First shot is at the enemy. info.m_vecDirShooting = GetActualShootTrajectory( vecSrc ); info.m_vecSpread = VECTOR_CONE_PRECALCULATED; } info.m_iTracerFreq = 1; info.m_iShots = 1; info.m_pAttacker = this; info.m_flDistance = MAX_COORD_RANGE; info.m_iAmmoType = m_iAmmoType; FireBullets( info ); } // Do the AR2 muzzle flash CEffectData data; data.m_nEntIndex = entindex(); data.m_nAttachmentIndex = LookupAttachment( "eyes" ); data.m_flScale = 1.0f; data.m_fFlags = MUZZLEFLASH_COMBINE; DispatchEffect( "MuzzleFlash", data ); EmitSound( "NPC_FloorTurret.ShotSounds", m_ShotSounds ); if( IsX360() ) { m_flTimeNextShoot = gpGlobals->curtime + 0.2; } else { m_flTimeNextShoot = gpGlobals->curtime + 0.09; } }
//----------------------------------------------------------------------------- // 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 ); } }
void CNPC_GMan::RunTask( const Task_t *pTask ) { switch( pTask->iTask ) { case TASK_WAIT: // look at who I'm talking to if (m_flTalkTime > gpGlobals->curtime && m_hTalkTarget != NULL) { AddLookTarget( m_hTalkTarget->GetAbsOrigin(), 1.0, 2.0 ); } // look at player, but only if playing a "safe" idle animation else if (m_hPlayer != NULL && (GetSequence() == 0 || IsInC5A1()) ) { AddLookTarget( m_hPlayer->EyePosition(), 1.0, 3.0 ); } else { // Just center the head forward. Vector forward; GetVectors( &forward, NULL, NULL ); AddLookTarget( GetAbsOrigin() + forward * 12.0f, 1.0, 1.0 ); SetBoneController( 0, 0 ); } BaseClass::RunTask( pTask ); break; } SetBoneController( 0, 0 ); BaseClass::RunTask( pTask ); }
//------------------------------------------------------------------------------ Vector C_BeamSpotLight::SpotlightCurrentPos(void) { QAngle angles = GetAbsAngles(); GetVectors( &m_vSpotlightDir, NULL, NULL ); Vector position = GetAbsOrigin(); int cacheIndex = -1; if ( m_pCache ) { cacheIndex = int( angles[m_nRotationAxis] * float(NUM_CACHE_ENTRIES) * (1.0f / 360.0f)) & (NUM_CACHE_ENTRIES - 1); if ( m_pCache[cacheIndex].IsValidFor(GetAbsOrigin()) ) { return position + m_vSpotlightDir * m_pCache[cacheIndex].m_radius; } } // Get beam end point. Only collide with solid objects, not npcs trace_t tr; UTIL_TraceLine( position, position + (m_vSpotlightDir * 2 * m_flSpotlightMaxLength), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr ); if ( cacheIndex >= 0 ) { m_pCache[cacheIndex].Cache(position, tr); } return tr.endpos; }
bool C_EnvProjectedTexture::IsWithinFarZ(float flLightFOV) { //No need to check camera space lights for visibility, as they should always be close enough to the player. if (m_bCameraSpace) return true; //Trace forward to the nearest opaque brush face Vector vForward; GetVectors(&vForward, NULL, NULL); Vector vTraceStart = GetAbsOrigin(); Vector vTraceEnd = GetAbsOrigin() + vForward; trace_t tr; CTraceFilterWorldOnly filter; UTIL_TraceLine(vTraceStart, vTraceEnd, CONTENTS_SOLID && CONTENTS_OPAQUE, &filter, &tr); //Test to see if the player is close enough to the light to actually see the light's projection. This is based entirely on it's FarZ. C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if (pPlayer) { Vector vDistance; VectorSubtract(tr.endpos, pPlayer->EyePosition(), vDistance); float fDistance = vDistance.LengthSqr(); //If distance is greater than the light's FarZ, cease to render. //FarZ determines how far away a light can be seen by the player, AND how far the light travels from it's source in stock Valve code. if (fDistance > Square(m_flFarZ + flLightFOV * 10)) return false; } return true; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPropAPC::FireRocket( void ) { if ( m_flRocketTime > gpGlobals->curtime ) return; // If we're still firing the salvo, fire quickly m_iRocketSalvoLeft--; if ( m_iRocketSalvoLeft > 0 ) { m_flRocketTime = gpGlobals->curtime + ROCKET_DELAY_TIME; } else { // Reload the salvo m_iRocketSalvoLeft = ROCKET_SALVO_SIZE; m_flRocketTime = gpGlobals->curtime + random->RandomFloat( ROCKET_MIN_BURST_PAUSE_TIME, ROCKET_MAX_BURST_PAUSE_TIME ); } Vector vecRocketOrigin; GetRocketShootPosition( &vecRocketOrigin ); static float s_pSide[] = { 0.966, 0.866, 0.5, -0.5, -0.866, -0.966 }; Vector forward; GetVectors( &forward, NULL, NULL ); Vector vecDir; CrossProduct( Vector( 0, 0, 1 ), forward, vecDir ); vecDir.z = 1.0f; vecDir.x *= s_pSide[m_nRocketSide]; vecDir.y *= s_pSide[m_nRocketSide]; if ( ++m_nRocketSide >= 6 ) { m_nRocketSide = 0; } VectorNormalize( vecDir ); Vector vecVelocity; VectorMultiply( vecDir, ROCKET_SPEED, vecVelocity ); QAngle angles; VectorAngles( vecDir, angles ); CAPCMissile *pRocket = (CAPCMissile *)CAPCMissile::Create( vecRocketOrigin, angles, vecVelocity, this ); pRocket->IgniteDelay(); if ( m_hSpecificRocketTarget ) { pRocket->AimAtSpecificTarget( m_hSpecificRocketTarget ); m_hSpecificRocketTarget = NULL; } else if ( m_strMissileHint != NULL_STRING ) { pRocket->SetGuidanceHint( STRING( m_strMissileHint ) ); } EmitSound( "PropAPC.FireRocket" ); m_OnFiredMissile.FireOutput( this, this ); }
void _L1TXX( short xpos, short ypos, char _WCI86FAR * str, /*========*/ struct xycoord _WCI86FAR * concat, struct xycoord _WCI86FAR * extent ) /* Inquire the extents of the character drawing parallelogram and return the concatenation point. The concatenation point is the same as the drawing point if it cannot be calculated exactly. */ { short hor; /* horizontal alignment */ short vert; /* vertical alignment */ struct xycoord up; /* character up vector */ struct xycoord base; /* character base line vector */ struct xycoord space; /* spacing between characters */ struct xycoord length; /* horizontal side of parallelogram */ struct xycoord height; /* vertical side of parallelogram */ struct xycoord trans; /* translation for parallelogram */ GetVectors( &base, &up ); GetAlignment( &hor, &vert ); CalcSpacing( &base, &up, &space ); CalcSides( &length, &height, &base, &up, &space, str ); CalcTranslation( &trans, &length, &height, &up, hor, vert ); CalcCorners( extent, &length, &height, &trans, xpos, ypos ); if( _TextSettings.txpath == _PATH_RIGHT || _TextSettings.txpath == _PATH_LEFT ) { CalcConcat( concat, &length, &space, xpos, ypos, hor, vert ); } else { CalcConcat( concat, &height, &space, xpos, ypos, hor, vert ); } }
void CNPC_Ichthyosaur::DragVictim( float moveDist ) { Vector mins, maxs; float width; mins = WorldAlignMins(); maxs = WorldAlignMaxs(); width = ( maxs.y - mins.y ) * 0.5f; Vector forward, up; GetVectors( &forward, NULL, &up ); Vector newPos = GetAbsOrigin() + ( (forward+(up*0.25f)) * ( moveDist + width + DRAG_OFFSET ) ); trace_t tr; AI_TraceEntity( this, m_pVictim->GetAbsOrigin(), newPos, MASK_NPCSOLID, &tr ); if ( ( tr.fraction == 1.0f ) && ( tr.m_pEnt != this ) ) { UTIL_SetOrigin( m_pVictim, tr.endpos ); } else { ReleaseVictim(); } }
void CASW_Rocket::Explode( void ) { // Don't explode against the skybox. Just pretend that // the missile flies off into the distance. Vector forward; GetVectors( &forward, NULL, NULL ); trace_t tr; UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + forward * 16, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); m_takedamage = DAMAGE_NO; SetSolid( SOLID_NONE ); if( tr.fraction == 1.0 || !(tr.surface.flags & SURF_SKY) ) { bool bHitCreature = tr.m_pEnt && tr.m_pEnt->IsNPC(); DoExplosion(!bHitCreature); } //UTIL_Remove( this ); SetTouch( NULL ); SetMoveType( MOVETYPE_NONE ); SetSolid( SOLID_NONE ); SetNextThink( gpGlobals->curtime + 0.2f ); SetThink( &CASW_Rocket::SUB_Remove ); }
void CNPC_Zombine::ReleaseGrenade( Vector vPhysgunPos ) { if ( HasGrenade() == false ) return; Vector vDir = vPhysgunPos - m_hGrenade->GetAbsOrigin(); VectorNormalize( vDir ); Activity aActivity; Vector vForward, vRight; GetVectors( &vForward, &vRight, NULL ); float flDotForward = DotProduct( vForward, vDir ); float flDotRight = DotProduct( vRight, vDir ); bool bNegativeForward = false; bool bNegativeRight = false; if ( flDotForward < 0.0f ) { bNegativeForward = true; flDotForward = flDotForward * -1; } if ( flDotRight < 0.0f ) { bNegativeRight = true; flDotRight = flDotRight * -1; } if ( flDotRight > flDotForward ) { if ( bNegativeRight == true ) aActivity = (Activity)ACT_ZOMBINE_GRENADE_FLINCH_WEST; else aActivity = (Activity)ACT_ZOMBINE_GRENADE_FLINCH_EAST; } else { if ( bNegativeForward == true ) aActivity = (Activity)ACT_ZOMBINE_GRENADE_FLINCH_BACK; else aActivity = (Activity)ACT_ZOMBINE_GRENADE_FLINCH_FRONT; } AddGesture( aActivity ); DropGrenade( vec3_origin ); if ( IsSprinting() ) { StopSprint(); } else { Sprint(); } }
void CNPC_CombineDropship::DoRotorWash( void ) { Vector vecForward; GetVectors( &vecForward, NULL, NULL ); Vector vecRotorHub = GetAbsOrigin() + vecForward * -64; DrawRotorWash( DROPSHIP_WASH_ALTITUDE, vecRotorHub ); }
//--------------------------------------------------------- // A different bounce behavior for the citizen-modified mine. Detonates at the top of its apex, // and does not attempt to track enemies. //--------------------------------------------------------- void CBounceBomb::CavernBounceThink() { SetNextThink( gpGlobals->curtime + 0.1 ); StudioFrameAdvance(); IPhysicsObject *pPhysicsObject = VPhysicsGetObject(); if ( pPhysicsObject != NULL ) { const float MINE_MAX_JUMP_HEIGHT = 78; // Figure out how much headroom the mine has, and hop to within a few inches of that. trace_t tr; UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + Vector( 0, 0, MINE_MAX_JUMP_HEIGHT ), MASK_SHOT, this, COLLISION_GROUP_INTERACTIVE, &tr ); float height; if( tr.m_pEnt && tr.m_pEnt->VPhysicsGetObject() ) { // Physics object resting on me. Jump as hard as allowed to try to knock it away. height = MINE_MAX_JUMP_HEIGHT; } else { height = tr.endpos.z - GetAbsOrigin().z; height -= BOUNCEBOMB_RADIUS; if ( height < 0.1 ) height = 0.1; } float time = sqrt( height / (0.5 * sv_gravity.GetFloat()) ); float velocity = sv_gravity.GetFloat() * time; // or you can just AddVelocity to the object instead of ApplyForce float force = velocity * pPhysicsObject->GetMass(); Vector up; GetVectors( NULL, NULL, &up ); pPhysicsObject->Wake(); pPhysicsObject->ApplyForceCenter( up * force ); if( m_hNearestNPC ) { Vector vecPredict = m_hNearestNPC->GetSmoothedVelocity(); pPhysicsObject->ApplyForceCenter( vecPredict * (pPhysicsObject->GetMass() * 0.65f) ); } pPhysicsObject->ApplyTorqueCenter( AngularImpulse( random->RandomFloat( 15, 40 ), random->RandomFloat( 15, 40 ), random->RandomFloat( 30, 60 ) ) ); EmitSound( "NPC_CombineMine.Hop" ); SetThink( &CBounceBomb::ExplodeThink ); SetNextThink( gpGlobals->curtime + 0.33f ); } }
//----------------------------------------------------------------------------- // Purpose: Create danger sounds in front of the vehicle. //----------------------------------------------------------------------------- void CASW_PropJeep::CreateDangerSounds( void ) { QAngle dummy; GetAttachment( "Muzzle", m_vecGunOrigin, dummy ); if ( m_flDangerSoundTime > gpGlobals->curtime ) return; QAngle vehicleAngles = GetLocalAngles(); Vector vecStart = GetAbsOrigin(); Vector vecDir, vecRight; GetVectors( &vecDir, &vecRight, NULL ); const float soundDuration = 0.25; float speed = m_VehiclePhysics.GetHLSpeed(); // Make danger sounds ahead of the jeep if ( fabs(speed) > 120 ) { Vector vecSpot; float steering = m_VehiclePhysics.GetSteering(); if ( steering != 0 ) { if ( speed > 0 ) { vecDir += vecRight * steering * 0.5; } else { vecDir -= vecRight * steering * 0.5; } VectorNormalize(vecDir); } const float radius = speed * 0.4; // 0.3 seconds ahead of the jeep vecSpot = vecStart + vecDir * (speed * 0.3f); CSoundEnt::InsertSound( SOUND_DANGER, vecSpot, radius, soundDuration, this, 0 ); CSoundEnt::InsertSound( SOUND_PHYSICS_DANGER, vecSpot, radius, soundDuration, this, 1 ); //NDebugOverlay::Box(vecSpot, Vector(-radius,-radius,-radius),Vector(radius,radius,radius), 255, 0, 255, 0, soundDuration); #if 0 trace_t tr; // put sounds a bit to left and right but slightly closer to Jeep to make a "cone" of sound // in front of it vecSpot = vecStart + vecDir * (speed * 0.5f) - vecRight * speed * 0.5; UTIL_TraceLine( vecStart, vecSpot, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); CSoundEnt::InsertSound( SOUND_DANGER, vecSpot, 400, soundDuration, this, 1 ); vecSpot = vecStart + vecDir * (speed * 0.5f) + vecRight * speed * 0.5; UTIL_TraceLine( vecStart, vecSpot, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); CSoundEnt::InsertSound( SOUND_DANGER, vecSpot, 400, soundDuration, this, 2); #endif } m_flDangerSoundTime = gpGlobals->curtime + 0.1; }
void CNPC_Hydra::Spawn() { Precache(); BaseClass::Spawn(); SetModel( "models/Hydra.mdl" ); SetHullType(HULL_HUMAN); SetHullSizeNormal(); SetSolid( SOLID_BBOX ); AddSolidFlags( FSOLID_NOT_STANDABLE ); SetMoveType( MOVETYPE_STEP ); SetBloodColor( BLOOD_COLOR_RED ); ClearEffects(); m_iHealth = 20; m_flFieldOfView = -1.0;// indicates the width of this NPC's forward view cone ( as a dotproduct result ) m_NPCState = NPC_STATE_NONE; GetVectors( NULL, NULL, &m_vecOutward ); SetAbsAngles( QAngle( 0, 0, 0 ) ); m_vecChain.Set( 0, GetAbsOrigin( ) - m_vecOutward * 32 ); m_vecChain.Set( 1, GetAbsOrigin( ) + m_vecOutward * 16 ); m_vecHeadGoal = m_vecChain[1] + m_vecOutward * HYDRA_OUTWARD_BIAS; m_vecHeadDir = Vector( 0, 0, 1 ); // init bones HydraBone bone; bone.flActualLength = 0.0f; bone.vecGoalPos = Vector(0.0f, 0.0f, 0.0f); bone.vecPos = GetAbsOrigin( ) - m_vecOutward * HYDRA_INWARD_BIAS; m_body.AddToTail( bone ); bone.vecPos = m_vecChain[1]; m_body.AddToTail( bone ); bone.vecPos = m_vecHeadGoal; m_body.AddToTail( bone ); bone.vecPos = m_vecHeadGoal + m_vecHeadDir; m_body.AddToTail( bone ); m_idealSegmentLength = sv_hydraSegmentLength.GetFloat(); for (int i = 2; i < CHAIN_LINKS; i++) { m_vecChain.Set( i, m_vecChain[i-1] ); } m_seed = random->RandomFloat( 0.0, 2000.0 ); NPCInit(); m_takedamage = DAMAGE_NO; }
//----------------------------------------------------------------------------- // Purpose: Try to encourage Alyx not to use her weapon at point blank range, // but don't prevent her from defending herself if cornered. // Input : flDot - // flDist - // Output : int //----------------------------------------------------------------------------- int CWeaponAlyxGun::WeaponRangeAttack1Condition( float flDot, float flDist ) { #ifdef HL2_EPISODIC if( flDist < m_fMinRange1 ) { // If Alyx is not able to fire because an enemy is too close, start a timer. // If the condition persists, allow her to ignore it and defend herself. The idea // is to stop Alyx being content to fire point blank at enemies if she's able to move // away, without making her defenseless if she's not able to move. float flTime; if( m_flTooCloseTimer == TOOCLOSETIMER_OFF ) { m_flTooCloseTimer = gpGlobals->curtime; } flTime = gpGlobals->curtime - m_flTooCloseTimer; if( flTime > ALYX_TOOCLOSETIMER ) { // Fake the range to allow Alyx to shoot. flDist = m_fMinRange1 + 1.0f; } } else { m_flTooCloseTimer = TOOCLOSETIMER_OFF; } int nBaseCondition = BaseClass::WeaponRangeAttack1Condition( flDot, flDist ); // While in a vehicle, we extend our aiming cone (this relies on COND_NOT_FACING_ATTACK // TODO: This needs to be rolled in at the animation level if ( GetOwner()->IsInAVehicle() ) { Vector vecRoughDirection = ( GetOwner()->GetEnemy()->WorldSpaceCenter() - WorldSpaceCenter() ); Vector vecRight; GetVectors( NULL, &vecRight, NULL ); bool bRightSide = ( DotProduct( vecRoughDirection, vecRight ) > 0.0f ); float flTargetDot = ( bRightSide ) ? -0.7f : 0.0f; if ( nBaseCondition == COND_NOT_FACING_ATTACK && flDot >= flTargetDot ) { nBaseCondition = COND_CAN_RANGE_ATTACK1; } } return nBaseCondition; #else return BaseClass::WeaponRangeAttack1Condition( flDot, flDist ); #endif//HL2_EPISODIC }
inline bool CNPC_Portal_FloorTurret::OnSide( void ) { if ( GetWaterLevel() > 0 ) return true; Vector up; GetVectors( NULL, NULL, &up ); return ( DotProduct( up, Vector(0,0,1) ) < 0.5f ); }
//----------------------------------------------------------------------------- // Purpose: Get shoot position of BCC at an arbitrary position // Input : // Output : //----------------------------------------------------------------------------- Vector CRebelZombie::Weapon_ShootPosition( ) { Vector right; GetVectors( NULL, &right, NULL ); // FIXME: rename this "estimated" since it's not based on animation // FIXME: the orientation won't be correct when testing from arbitary positions for arbitary angles return GetAbsOrigin() + REBEL_ZOMBIE_GUN_STANDING_POSITION + right * 8; }
//--------------------------------------------------------- //--------------------------------------------------------- void CBounceBomb::UpdateLight( bool bTurnOn, unsigned int r, unsigned int g, unsigned int b, unsigned int a ) { if( bTurnOn ) { Assert( a > 0 ); // Throw the old sprite away if( m_hSprite ) { UTIL_Remove( m_hSprite ); m_hSprite.Set( NULL ); } if( !m_hSprite.Get() ) { Vector up; GetVectors( NULL, NULL, &up ); // Light isn't on. m_hSprite = CSprite::SpriteCreate( "sprites/glow01.vmt", GetAbsOrigin() + up * 10.0f, false ); CSprite *pSprite = (CSprite *)m_hSprite.Get(); if( m_hSprite ) { pSprite->SetParent( this ); pSprite->SetTransparency( kRenderTransAdd, r, g, b, a, kRenderFxNone ); pSprite->SetScale( 0.35, 0.0 ); } } else { // Update color CSprite *pSprite = (CSprite *)m_hSprite.Get(); pSprite->SetTransparency( kRenderTransAdd, r, g, b, a, kRenderFxNone ); } } if( !bTurnOn ) { if( m_hSprite ) { UTIL_Remove( m_hSprite ); m_hSprite.Set( NULL ); } } if ( !m_hSprite ) { m_LastSpriteColor.SetRawColor( 0 ); } else { m_LastSpriteColor.SetColor( r, g, b, a ); } }
//----------------------------------------------------------------------------- // Spawn! //----------------------------------------------------------------------------- void CEnvHeadcrabCanister::Spawn( void ) { Precache(); BaseClass::Spawn(); // Do we have a position to launch from? if ( m_iszLaunchPositionName != NULL_STRING ) { // It doesn't have any real presence at first. SetSolid( SOLID_NONE ); m_vecImpactPosition = GetAbsOrigin(); m_bIncomingSoundStarted = false; m_bLanded = false; m_bHasDetonated = false; m_bOpened = false; } else if ( !HasSpawnFlags( SF_START_IMPACTED ) ) { // It doesn't have any real presence at first. SetSolid( SOLID_NONE ); if ( !HasSpawnFlags( SF_LAND_AT_INITIAL_POSITION ) ) { Vector vecForward; GetVectors( &vecForward, NULL, NULL ); vecForward *= -1.0f; trace_t trace; UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + vecForward * 10000, MASK_NPCWORLDSTATIC, this, COLLISION_GROUP_NONE, &trace ); m_vecImpactPosition = trace.endpos; } else { m_vecImpactPosition = GetAbsOrigin(); } m_bIncomingSoundStarted = false; m_bLanded = false; m_bHasDetonated = false; m_bOpened = false; } else { m_bHasDetonated = true; m_bIncomingSoundStarted = true; m_bOpened = false; m_vecImpactPosition = GetAbsOrigin(); Landed(); } }
//----------------------------------------------------------------------------- // Is the vgui screen backfacing? //----------------------------------------------------------------------------- bool C_VGuiScreen::IsBackfacing( const Vector &viewOrigin ) { // Compute a ray from camera to center of the screen.. Vector cameraToScreen; VectorSubtract( GetAbsOrigin(), viewOrigin, cameraToScreen ); // Figure out the face normal Vector zaxis; GetVectors( NULL, NULL, &zaxis ); // The actual backface cull return (DotProduct( zaxis, cameraToScreen ) > 0.0f); }
//----------------------------------------------------------------------------- // Purpose: // Input : velocity - //----------------------------------------------------------------------------- void CNPC_Ichthyosaur::AddSwimNoise( Vector *velocity ) { Vector right, up; GetVectors( NULL, &right, &up ); float lNoise, vNoise; lNoise = LATERAL_NOISE_MAX * sin( gpGlobals->curtime * LATERAL_NOISE_FREQ ); vNoise = VERTICAL_NOISE_MAX * sin( gpGlobals->curtime * VERTICAL_NOISE_FREQ ); (*velocity) += ( right * lNoise ) + ( up * vNoise ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CAntlionGrub::SpawnSquashedGrub( void ) { // If we're already invisible, we're done if ( GetEffects() & EF_NODRAW ) return; Vector vecUp; GetVectors( NULL, NULL, &vecUp ); CBaseEntity *pGib = CreateRagGib( ANTLIONGRUB_SQUASHED_MODEL, GetAbsOrigin(), GetAbsAngles(), vecUp * 16.0f ); if ( pGib ) { pGib->AddEffects( EF_NOSHADOW ); } }
//------------------------------------------------------------------------------ // Purpose : // Input : // Output : //------------------------------------------------------------------------------ void CAI_Hint::Spawn( void ) { // Cache off the forward vector GetVectors( &m_vecForward, NULL, NULL ); if( m_nodeFOV != 360 ) { // As a micro-optimization, leave the FOV at 360 to save us // a dot product later when checking node FOV. m_nodeFOV = cos( DEG2RAD(m_nodeFOV/2) ); } SetSolid( SOLID_NONE ); }
void C_CFPlayer::PostThink() { if ( IsAlive() && (GetFlags() & FL_ONGROUND) && m_bPowerjump ) StopPowerjump(); BaseClass::PostThink(); Instructor_Think(); for (int i = 1; i < gpGlobals->maxClients; i++) { C_BasePlayer *pPlayer = UTIL_PlayerByIndex( i ); if (!pPlayer) continue; C_CFPlayer* pCFPlayer = ToCFPlayer(pPlayer); if (CFGameRules()->PlayerRelationship(this, pCFPlayer) == GR_TEAMMATE) continue; // Far enemies are not important. if ((EyePosition() - pCFPlayer->WorldSpaceCenter()).Length() > 500) continue; trace_t result; CTraceFilterNoNPCsOrPlayer traceFilter( NULL, COLLISION_GROUP_NONE ); UTIL_TraceLine( EyePosition(), pCFPlayer->WorldSpaceCenter(), MASK_VISIBLE_AND_NPCS, &traceFilter, &result ); if (result.fraction != 1.0f) //if (!pPlayer->IsVisible(pCFTarget)) // This is unfortunately a server-only function, though I'd love to use it here. continue; m_flLastEnemySeen = gpGlobals->curtime; break; } if (!IsInFollowMode() || !ShouldLockFollowModeView()) { Vector vecForward; GetVectors(&vecForward, NULL, NULL); if (m_flLastCameraTargetTime == 0) { if (!GetRecursedTarget()) m_hLastCameraTarget = NULL; m_vecLastCameraTarget = m_vecLastTargetPosition = EyePosition() + vecForward*100; } } }
//----------------------------------------------------------------------------- // Causes the helicopter to immediately accelerate to its desired velocity //----------------------------------------------------------------------------- void CBaseHelicopter::InputMoveTopSpeed( inputdata_t &inputdata ) { Vector vecVelocity; ComputeActualTargetPosition( GetMaxSpeed(), 1.0f, 0.0f, &vecVelocity, false ); vecVelocity -= GetAbsOrigin(); float flLength = VectorNormalize( vecVelocity ); if (flLength < 1e-3) { GetVectors( &vecVelocity, NULL, NULL ); } vecVelocity *= GetMaxSpeed(); SetAbsVelocity( vecVelocity ); }
void on_notebook1_switch_page (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer user_data) { char ar[500]; extern char my_arena[]; /* need to fix these TODO *btw: the idea is this: if you click on the diag screen you get if(my_mode==-1) my_mode=page_num; printf("::::%d\n",my_mode); */ GetCurrentArena(ar); if(page_num == 0) { if(my_mode==1) return; my_mode=1; if(strcmp(ar,"")!=0) { Vector("",""); } return; } if(page_num==1) { if(my_mode==2) return; my_mode=2; if(strcmp(ar,"")==0) { Vector(my_arena,""); GetVectors(my_arena); } return; } if(page_num==2) { //if(my_mode==2) // my_mode=-1; GetMetrics(); } }
//----------------------------------------------------------------------------- // Purpose: Attaches the grub to the surface underneath its abdomen //----------------------------------------------------------------------------- void CNPC_AntlionGrub::AttachToSurface( void ) { // Get our downward direction Vector vecForward, vecRight, vecDown; GetVectors( &vecForward, &vecRight, &vecDown ); vecDown.Negate(); // Trace down to find a surface trace_t tr; UTIL_TraceLine( WorldSpaceCenter(), WorldSpaceCenter() + (vecDown*256.0f), MASK_NPCSOLID, this, COLLISION_GROUP_NONE, &tr ); if ( tr.fraction < 1.0f ) { // Move there UTIL_SetOrigin( this, tr.endpos, false ); } }
// Атака зажигательными гранатами. Отключена. Для включения см. комментарий в ф-ции Spawn() // See the function and the and of npc_cremator.h void CNPC_Cremator::ThrowIncendiaryGrenade( void ) { Vector vecStart; GetAttachment( "anim_attachment_LH", vecStart ); Vector forward, up, right, vecThrow; GetVectors( &forward, &right, &up ); vecThrow = forward * 450 + up * 175 + right * random->RandomFloat(-15, 5); CGrenadeIncendiary *pIncendiary = (CGrenadeIncendiary*)Create( "grenade_incendiary", vecStart, vec3_angle, this ); pIncendiary->SetAbsVelocity( vecThrow ); pIncendiary->SetGravity( 1.5f ); pIncendiary->SetLocalAngularVelocity( RandomAngle( -400, 400 ) ); pIncendiary->SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_CUSTOM ); }
void CKeepUpright::Spawn() { // align the object's local Z axis m_localTestAxis.Init( 0, 0, 1 ); // Use our Up axis so mapmakers can orient us arbitrarily GetVectors( NULL, NULL, &m_worldGoalAxis ); SetMoveType( MOVETYPE_NONE ); if ( m_spawnflags & SF_KEEPUPRIGHT_START_INACTIVE ) { m_bActive = false; } else { m_bActive = true; } }
//----------------------------------------------------------------------------- // Purpose: Get our conditions for a melee attack // Input : flDot - // flDist - // Output : int //----------------------------------------------------------------------------- int CNPC_Ichthyosaur::MeleeAttack1Conditions( float flDot, float flDist ) { Vector predictedDir = ( (GetEnemy()->GetAbsOrigin()+(GetEnemy()->GetSmoothedVelocity())) - GetAbsOrigin() ); float flPredictedDist = VectorNormalize( predictedDir ); Vector vBodyDir; GetVectors( &vBodyDir, NULL, NULL ); float flPredictedDot = DotProduct( predictedDir, vBodyDir ); if ( flPredictedDot < 0.8f ) return COND_NOT_FACING_ATTACK; if ( ( flPredictedDist > ( GetAbsVelocity().Length() * 0.5f) ) && ( flDist > 128.0f ) ) return COND_TOO_FAR_TO_ATTACK; return COND_CAN_MELEE_ATTACK1; }