本文整理汇总了C++中RANDOM_FLOAT函数的典型用法代码示例。如果您正苦于以下问题:C++ RANDOM_FLOAT函数的具体用法?C++ RANDOM_FLOAT怎么用?C++ RANDOM_FLOAT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RANDOM_FLOAT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeGrunt
CBaseMonster *COsprey :: MakeGrunt( Vector vecSrc )
{
CBaseEntity *pEntity;
CBaseMonster *pGrunt;
TraceResult tr;
UTIL_TraceLine( vecSrc, vecSrc + Vector( 0, 0, -4096.0), dont_ignore_monsters, ENT(pev), &tr);
if ( tr.pHit && Instance( tr.pHit )->pev->solid != SOLID_BSP)
return NULL;
for (int i = 0; i < m_iUnits; i++)
{
if (m_hGrunt[i] == NULL || !m_hGrunt[i]->IsAlive())
{
if (m_hGrunt[i] != NULL && m_hGrunt[i]->pev->rendermode == kRenderNormal)
{
m_hGrunt[i]->SUB_StartFadeOut( );
}
pEntity = Create( "monster_human_grunt", vecSrc, pev->angles );
pGrunt = pEntity->MyMonsterPointer( );
pGrunt->pev->movetype = MOVETYPE_FLY;
pGrunt->pev->velocity = Vector( 0, 0, RANDOM_FLOAT( -196, -128 ) );
pGrunt->SetActivity( ACT_GLIDE );
CBeam *pBeam = CBeam::BeamCreate( "sprites/rope.spr", 10 );
pBeam->PointEntInit( vecSrc + Vector(0,0,112), pGrunt->entindex() );
pBeam->SetFlags( BEAM_FSOLID );
pBeam->SetColor( 255, 255, 255 );
pBeam->SetThink( SUB_Remove );
pBeam->pev->nextthink = gpGlobals->time + -4096.0 * tr.flFraction / pGrunt->pev->velocity.z + 0.5;
// ALERT( at_console, "%d at %.0f %.0f %.0f\n", i, m_vecOrigin[i].x, m_vecOrigin[i].y, m_vecOrigin[i].z );
pGrunt->m_vecLastPosition = m_vecOrigin[i];
m_hGrunt[i] = pGrunt;
return pGrunt;
}
}
// ALERT( at_console, "none dead\n");
return NULL;
}
示例2: UTIL_Ricochet
void CBigMomma::TraceAttack(entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType)
{
if(ptr->iHitgroup != 1)
{
// didn't hit the sack?
if(pev->dmgtime != gpGlobals->time || (RANDOM_LONG(0, 10) < 1))
{
UTIL_Ricochet(ptr->vecEndPos, RANDOM_FLOAT(1, 2));
pev->dmgtime = gpGlobals->time;
}
flDamage = 0.1; // don't hurt the monster much, but allow bits_COND_LIGHT_DAMAGE to be generated
}
else if(gpGlobals->time > m_painSoundTime)
{
m_painSoundTime = gpGlobals->time + RANDOM_LONG(1, 3);
EMIT_SOUND_ARRAY_DYN(CHAN_VOICE, pPainSounds);
}
CBaseMonster::TraceAttack(pevAttacker, flDamage, vecDir, ptr, bitsDamageType);
}
示例3: Think
void CXenTree :: Think( void )
{
float flInterval = StudioFrameAdvance();
pev->nextthink = gpGlobals->time + 0.1;
DispatchAnimEvents( flInterval );
switch( GetActivity() )
{
case ACT_MELEE_ATTACK1:
if ( m_fSequenceFinished )
{
SetActivity( ACT_IDLE );
pev->framerate = RANDOM_FLOAT( 0.6, 1.4 );
}
break;
default:
case ACT_IDLE:
break;
}
}
示例4: switch
void CBiorifle::WeaponIdle( void )
{
if ( m_flTimeWeaponIdle > gpGlobals->time )
return;
int iAnim;
switch ( RANDOM_LONG( 0, 2 ))
{
case 0:
iAnim = BIORIFLE_IDLE2;
break;
case 1:
iAnim = BIORIFLE_IDLE3;
break;
case 2:
iAnim = BIORIFLE_IDLE;
break;
}
SendWeaponAnim( iAnim );
m_flTimeWeaponIdle = gpGlobals->time + RANDOM_FLOAT (10, 15);
}
示例5: HandleAnimEvent
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
void CHellKnight :: HandleAnimEvent( MonsterEvent_t *pEvent )
{
switch( pEvent->event )
{
case HKNIGHT_IDLE_SOUND:
if( m_Activity == ACT_RUN )
CheckForCharge ();
if( RANDOM_FLOAT( 0.0f, 1.0f ) < 0.1f )
EMIT_SOUND( edict(), CHAN_VOICE, "hknight/idle.wav", 1.0, ATTN_IDLE );
break;
case HKNIGHT_SHOT_SPIKES:
ShootSpike( atof( pEvent->options ));
break;
case HKNIGHT_MELEE_ATTACK:
AI_Melee ();
break;
default:
CQuakeMonster::HandleAnimEvent( pEvent );
break;
}
}
示例6: Use
void CTriggerHurt :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
if (useType == USE_TOGGLE)
{
if(m_iState) useType = USE_OFF;
else useType = USE_ON;
}
if (useType == USE_ON)
{
pev->solid = SOLID_TRIGGER;
gpGlobals->force_retouch++;
UTIL_SetOrigin( this, pev->origin );
if (pev->button & DMG_RADIATION) SetNextThink( RANDOM_FLOAT(0.0, 0.5) );
m_iState = STATE_ON;
}
else if (useType == USE_OFF)
{
pev->solid = SOLID_NOT;
UTIL_SetOrigin( this, pev->origin );
if (pev->button & DMG_RADIATION) DontThink();
m_iState = STATE_OFF;
}
else if (useType == USE_SET)
{
pev->dmg = value;//set dmg level
}
else if (useType == USE_RESET)
{
pev->dmg = 0;//reset dmg level
}
else if (useType == USE_SHOWINFO)
{
DEBUGHEAD;
ALERT( at_console, "State: %s, Dmg value %g\n", GetStringForState( GetState()), pev->dmg );
PrintStringForDamage( pev->button );
}
}
示例7: UpdateSpot
void CRpg::WeaponIdle(void)
{
UpdateSpot();
if (m_flTimeWeaponIdle > UTIL_GlobalTimeBase()) return;
if (m_iClip && !m_iOverloadLevel)
{
int iAnim;
float flRand = RANDOM_FLOAT(0, 1);
if (flRand <= 0.75)
{
iAnim = RPG_IDLE;
m_flTimeWeaponIdle = UTIL_GlobalTimeBase() + 6.3;
}
else
{
iAnim = RPG_IDLE2;
m_flTimeWeaponIdle = UTIL_GlobalTimeBase() + 6.3;
}
SendWeaponAnim(iAnim);
}
}
示例8: PlayEmptySound
void Cawp::PrimaryAttack()
{
if (m_pPlayer->pev->waterlevel == 3 || m_iClip <= 0)
{
PlayEmptySound( );
m_flNextPrimaryAttack = gpGlobals->time + 0.5;
return;
}
m_iClip--;
m_iFiredAmmo++;
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
UTIL_MakeVectors(m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle);
m_pPlayer->FireMagnumBullets(m_pPlayer->GetGunPosition(), gpGlobals->v_forward, VECTOR_CONE_0DEGREES, 16384, BULLET_338Magnum, m_pPlayer->pev);
FX_FireGun(m_pPlayer->pev->v_angle, m_pPlayer->entindex(), (m_pPlayer->m_fHeavyArmor)?AWP_FIRE_SOLID:AWP_FIRE, m_pPlayer->m_fHeavyArmor?1:0, FIREGUN_AWP );
SetThink( shellcasing );
(m_pPlayer->m_fHeavyArmor)?pev->nextthink = gpGlobals->time + 0.6:pev->nextthink = gpGlobals->time + 1.15;
(m_pPlayer->m_fHeavyArmor)?m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.2:m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.8;
m_flTimeWeaponIdle = gpGlobals->time + RANDOM_FLOAT (8, 12);
}
示例9: tag
/*
=========================
HUD_StudioEvent
The entity's studio model description indicated an event was
fired during this frame, handle the event by it's tag ( e.g., muzzleflash, sound )
=========================
*/
void HUD_StudioEvent( const struct mstudioevent_s *event, const struct cl_entity_s *entity )
{
switch( event->event )
{
case 5001:
gEngfuncs.pEfxAPI->R_MuzzleFlash( (float *)&entity->attachment[0], Q_atoi( event->options ));
break;
case 5011:
gEngfuncs.pEfxAPI->R_MuzzleFlash( (float *)&entity->attachment[1], Q_atoi( event->options ));
break;
case 5021:
gEngfuncs.pEfxAPI->R_MuzzleFlash( (float *)&entity->attachment[2], Q_atoi( event->options ));
break;
case 5031:
gEngfuncs.pEfxAPI->R_MuzzleFlash( (float *)&entity->attachment[3], Q_atoi( event->options ));
break;
case 5002:
gEngfuncs.pEfxAPI->R_SparkEffect( (float *)&entity->attachment[0], Q_atoi( event->options ), -100, 100 );
break;
case 5004: // client side sound
gEngfuncs.pfnPlaySoundByNameAtLocation( (char *)event->options, 1.0, (float *)&entity->attachment[0] );
break;
case 5005: // client side sound with random pitch
gEngfuncs.pEventAPI->EV_PlaySound( entity->index, (float *)&entity->attachment[0], CHAN_WEAPON, (char *)event->options,
RANDOM_FLOAT( 0.7f, 0.9f ), ATTN_NORM, 0, 85 + RANDOM_LONG( 0, 0x1f ));
break;
case 5050: // Special event for displacer
HUD_DrawBeam();
break;
case 5060:
HUD_EjectShell( event, entity );
break;
default:
ALERT( at_error, "Unknown event %i with options %i\n", event->event, event->options );
break;
}
}
示例10: EMIT_SOUND_DYN
BOOL CMP5::Deploy( )
{
// m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1.3; //delay before fire
EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/weapon_deploy.wav", RANDOM_FLOAT(0.95, 1.0), ATTN_NORM, 0, 93 + RANDOM_LONG(0,0xF));
if ( m_fDefaultAnim == SILENCER_OFF_FULLAUTO || m_fDefaultAnim == SILENCER_OFF_SEMI )
{
if (!FStringNull (v_model) )
{
m_pPlayer->pev->viewmodel = v_model;
// m_pPlayer->pev->weaponmodel = p_model;
SendWeaponAnim( A2_DEPLOY, 1, 0 );
return TRUE;
}
else
return DefaultDeploy("models/weapons/MP5/v_MP5.mdl", "models/weapons/MP5/p_MP5.mdl", A2_DEPLOY, "mp5", 3.50f ); //"mp5a4", 3.50f );
}
else
{
if (!FStringNull (v_model) )
{
m_pPlayer->pev->viewmodel = v_model;
// m_pPlayer->pev->weaponmodel = p_model;
SendWeaponAnim( SD2_DEPLOY, 1, 0 );
return TRUE;
}
else
return DefaultDeploy("models/weapons/MP5/v_MP5.mdl", "models/weapons/MP5/p_MP5_2.mdl", SD2_DEPLOY, "mp5", 3.50f );
}
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
// return DefaultDeploy("models/weapons/MP5/v_MP5.mdl", "models/weapons/MP5/p_MP5.mdl", A2_DEPLOY, "mp5a4" );
}
示例11: StartFire
void CGauss::WeaponIdle( void )
{
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
return;
if (m_fInAttack != 0)
{
StartFire();
m_fInAttack = 0;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0;
}
else
{
int iAnim;
switch ( RANDOM_LONG( 0, 2 ) )
{
case 0:
iAnim = GAUSS_IDLE;
break;
case 1:
iAnim = GAUSS_IDLE2;
break;
default:
case 2:
iAnim = GAUSS_FIDGET;
break;
}
SendWeaponAnim( iAnim );
m_flTimeWeaponIdle = gpGlobals->time + RANDOM_FLOAT ( 10, 15 );
}
}
示例12: HandleAnimEvent
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
void CSoldier :: HandleAnimEvent( MonsterEvent_t *pEvent )
{
switch( pEvent->event )
{
case ARMY_SHOOT:
MonsterFire();
break;
case ARMY_END_ATTACK:
m_fInAttack = TRUE;
m_fAttackFinished = TRUE;
break;
case ARMY_DROP_BACKPACK:
ammo_shells = 5;
CWeaponBox::DropBackpack( this, 0 );
break;
case ARMY_IDLE_SOUND:
if( RANDOM_FLOAT( 0.0f, 1.0f ) < 0.2f )
EMIT_SOUND( edict(), CHAN_VOICE, "soldier/idle.wav", 1.0, ATTN_IDLE );
break;
default:
CQuakeMonster::HandleAnimEvent( pEvent );
break;
}
}
示例13: MonsterPain
void CHellKnight :: MonsterPain( CBaseEntity *pAttacker, float flDamage )
{
if( pev->pain_finished > gpGlobals->time )
return;
EMIT_SOUND( edict(), CHAN_VOICE, "hknight/pain1.wav", 1.0, ATTN_NORM );
if(( gpGlobals->time - pev->pain_finished ) > 5 )
{
// allways go into pain frame if it has been a while
m_iAIState = STATE_PAIN;
SetActivity( ACT_BIG_FLINCH );
pev->pain_finished = gpGlobals->time + 1;
return;
}
if( RANDOM_FLOAT( 0.0f, 30.0f ) > flDamage )
return; // didn't flinch
m_iAIState = STATE_PAIN;
SetActivity( ACT_BIG_FLINCH );
pev->pain_finished = gpGlobals->time + 1;
}
示例14: PLAYBACK_EVENT_FULL
// Grenade launcher
void CBasePlayer::W_FireGrenade(int iQuadSound)
{
PLAYBACK_EVENT_FULL(FEV_NOTHOST, edict(), m_usGrenade, 0, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, iQuadSound, 0, 0, 0);
if(gpGlobals->deathmatch != 4)
*m_pCurrentAmmo -= 1;
// Get initial velocity
UTIL_MakeVectors(pev->v_angle);
Vector vecVelocity;
if(pev->v_angle.x)
{
vecVelocity = gpGlobals->v_forward * 600 + gpGlobals->v_up * 200 + RANDOM_FLOAT(-1, 1) * gpGlobals->v_right * 10 + RANDOM_FLOAT(-1, 1) * gpGlobals->v_up * 10;
}
else
{
vecVelocity = GetAutoaimVector(AUTOAIM_5DEGREES);
vecVelocity = vecVelocity * 600;
vecVelocity.z = 200;
}
// Create the grenade
CQuakeRocket *pRocket = CQuakeRocket::CreateGrenade(pev->origin, vecVelocity, this);
}
示例15: SendWeaponAnim
void CTripmine::WeaponIdle( void )
{
if (m_flTimeWeaponIdle > gpGlobals->time)
return;
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0)
{
SendWeaponAnim( TRIPMINE_DRAW );
}
else
{
RetireWeapon();
return;
}
int iAnim;
float flRand = RANDOM_FLOAT(0, 1);
if (flRand <= 0.25)
{
iAnim = TRIPMINE_IDLE1;
m_flTimeWeaponIdle = gpGlobals->time + 90.0 / 30.0;
}
else if (flRand <= 0.75)
{
iAnim = TRIPMINE_IDLE2;
m_flTimeWeaponIdle = gpGlobals->time + 60.0 / 30.0;
}
else
{
iAnim = TRIPMINE_FIDGET;
m_flTimeWeaponIdle = gpGlobals->time + 100.0 / 30.0;
}
SendWeaponAnim( iAnim );
}