//------------------------------------------------------------------------------ // Pow! //------------------------------------------------------------------------------ void CQUAGrenadeHelicopter::DoExplosion( const Vector &vecOrigin, const Vector &vecVelocity ) { ExplosionCreate( GetAbsOrigin(), GetAbsAngles(), this, 75.0, 275.0, (SF_ENVEXPLOSION_NOSPARKS|SF_ENVEXPLOSION_NODLIGHTS|SF_ENVEXPLOSION_NODECAL|SF_ENVEXPLOSION_NOFIREBALL|SF_ENVEXPLOSION_NOPARTICLES), 55000.0 ); if ( GetShakeAmplitude() ) { UTIL_ScreenShake( GetAbsOrigin(), GetShakeAmplitude(), 150.0, 1.0, GetShakeRadius(), SHAKE_START ); } CEffectData data; // If we're under water do a water explosion if ( GetWaterLevel() != 0 && (GetWaterType() & CONTENTS_WATER) ) { data.m_vOrigin = WorldSpaceCenter(); data.m_flMagnitude = 128; data.m_flScale = 128; data.m_fFlags = 0; DispatchEffect( "WaterSurfaceExplosion", data ); } else { // Otherwise do a normal explosion data.m_vOrigin = GetAbsOrigin(); DispatchEffect( "HelicopterMegaBomb", data ); } UTIL_Remove( this ); }
//----------------------------------------------------------------------------- // Purpose: Returns whether or not we are allowed to sprint now. //----------------------------------------------------------------------------- bool CSDKPlayer::CanSprint() { return ( //!IsWalking() && // Not if we're walking !( m_Local.m_bDucked && !m_Local.m_bDucking ) && // Nor if we're ducking (GetWaterLevel() != 3) ); // Certainly not underwater }
void CLeech::Killed( const CTakeDamageInfo& info, GibAction gibAction ) { Vector vecSplatDir; TraceResult tr; //ALERT(at_aiconsole, "Leech: killed\n"); // tell owner ( if any ) that we're dead.This is mostly for MonsterMaker functionality. CBaseEntity *pOwner = CBaseEntity::Instance(pev->owner); if (pOwner) pOwner->DeathNotice( this ); // When we hit the ground, play the "death_end" activity if ( GetWaterLevel() ) { pev->angles.z = 0; pev->angles.x = 0; pev->origin.z += 1; pev->avelocity = g_vecZero; if ( RANDOM_LONG( 0, 99 ) < 70 ) pev->avelocity.y = RANDOM_LONG( -720, 720 ); pev->gravity = 0.02; ClearBits(pev->flags, FL_ONGROUND); SetActivity( ACT_DIESIMPLE ); } else SetActivity( ACT_DIEFORWARD ); pev->movetype = MOVETYPE_TOSS; pev->takedamage = DAMAGE_NO; SetThink( &CLeech::DeadThink ); }
void CBaseGrenade ::TumbleThink( void ) { if (!IsInWorld()) { Remove( ); return; } StudioFrameAdvance( ); SetNextThink( gpGlobals->curtime + 0.1f ); // // Emit a danger sound one second before exploding. // if (m_flDetonateTime - 1 < gpGlobals->curtime) { #if !defined( CLIENT_DLL ) CSoundEnt::InsertSound ( SOUND_DANGER, GetAbsOrigin() + GetAbsVelocity() * (m_flDetonateTime - gpGlobals->curtime), 400, 0.1, this ); #endif } if (m_flDetonateTime <= gpGlobals->curtime) { SetThink( &CBaseGrenade::Detonate ); } if (GetWaterLevel() != 0) { SetAbsVelocity( GetAbsVelocity() * 0.5 ); m_flPlaybackRate = 0.2; } }
void CBaseGrenadeConcussion::FallThink(void) { if (!IsInWorld()) { Remove( ); return; } CSoundEnt::InsertSound ( SOUND_DANGER, GetAbsOrigin() + GetAbsVelocity() * 0.5, GetAbsVelocity().Length( ), 0.2 ); SetNextThink( gpGlobals->curtime + random->RandomFloat(0.05, 0.1) ); if (GetWaterLevel() != 0) { SetAbsVelocity( GetAbsVelocity() * 0.5 ); } Vector pos = GetAbsOrigin() + Vector(random->RandomFloat(-4, 4), random->RandomFloat(-4, 4), random->RandomFloat(-4, 4)); CPVSFilter filter( GetAbsOrigin() ); te->Sprite( filter, 0.0, &pos, m_nTrailSprite, random->RandomFloat(0.5, 0.8), 200 ); }
//----------------------------------------------------------------------------- // Purpose: // Input : *pEntity - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool CNPC_Ichthyosaur::FVisible( CBaseEntity *pEntity, int traceMask, CBaseEntity **ppBlocker ) { // don't look through water if ( GetWaterLevel() != pEntity->GetWaterLevel() ) return false; return BaseClass::FVisible( pEntity, traceMask, ppBlocker ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- bool CObjectSentrygun::ValidTargetPlayer( CTFPlayer *pPlayer, const Vector &vecStart, const Vector &vecEnd ) { // Keep shooting at spies that go invisible after we acquire them as a target. if ( pPlayer->m_Shared.GetPercentInvisible() > 0.5 ) return false; // Keep shooting at spies that disguise after we acquire them as at a target. if ( pPlayer->m_Shared.InCond( TF_COND_DISGUISED ) && pPlayer->m_Shared.GetDisguiseTeam() == GetTeamNumber() && pPlayer != m_hEnemy ) return false; // Not across water boundary. if ( ( GetWaterLevel() == 0 && pPlayer->GetWaterLevel() >= 3 ) || ( GetWaterLevel() == 3 && pPlayer->GetWaterLevel() <= 0 ) ) return false; // Ray trace!!! return FVisible( pPlayer, MASK_SHOT | CONTENTS_GRATE ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- bool CObjectSentrygun::ValidTargetObject( CBaseObject *pObject, const Vector &vecStart, const Vector &vecEnd ) { // Ignore objects being placed, they are not real objects yet. if ( pObject->IsPlacing() ) return false; // Ignore sappers. if ( pObject->MustBeBuiltOnAttachmentPoint() ) return false; // Not across water boundary. if ( ( GetWaterLevel() == 0 && pObject->GetWaterLevel() >= 3 ) || ( GetWaterLevel() == 3 && pObject->GetWaterLevel() <= 0 ) ) return false; // Ray trace. return FVisible( pObject, MASK_SHOT | CONTENTS_GRATE ); }
void CShockBeam::FlyThink() { if( GetWaterLevel() == WATERLEVEL_HEAD ) { SetThink( &CShockBeam::WaterExplodeThink ); } SetNextThink( gpGlobals->time + 0.01 ); }
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: //----------------------------------------------------------------------------- void CBasePlayer::UpdateUnderwaterState( void ) { if ( GetWaterLevel() == WL_Eyes ) { if ( IsPlayerUnderwater() == false ) { SetPlayerUnderwater( true ); } return; } if ( IsPlayerUnderwater() ) { SetPlayerUnderwater( false ); } if ( GetWaterLevel() == 0 ) { if ( GetFlags() & FL_INWATER ) { #ifndef CLIENT_DLL if ( m_iHealth > 0 && IsAlive() ) { EmitSound( "Player.Wade" ); } #endif RemoveFlag( FL_INWATER ); } } else if ( !(GetFlags() & FL_INWATER) ) { #ifndef CLIENT_DLL // player enter water sound if (GetWaterType() == CONTENTS_WATER) { EmitSound( "Player.Wade" ); } #endif AddFlag( FL_INWATER ); } }
void CFlowerBolt::BubbleThink( void ) { QAngle angNewAngles; VectorAngles( GetAbsVelocity(), angNewAngles ); SetAbsAngles( angNewAngles ); SetNextThink( gpGlobals->curtime + 0.1f ); if ( GetWaterLevel() == 0 ) return; UTIL_BubbleTrail( GetAbsOrigin() - GetAbsVelocity() * 0.1f, GetAbsOrigin(), 5 ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CFlare::FlareThink( void ) { float deltaTime = ( m_flTimeBurnOut - gpGlobals->curtime ); if ( !m_bInActiveList && ( ( deltaTime > FLARE_BLIND_TIME ) || ( m_flTimeBurnOut == -1.0f ) ) ) { AddToActiveFlares(); } if ( m_flTimeBurnOut != -1.0f ) { //Fading away if ( ( deltaTime <= FLARE_DECAY_TIME ) && ( m_bFading == false ) ) { m_bFading = true; CSoundEnvelopeController::GetController().SoundChangePitch( m_pBurnSound, 60, deltaTime ); CSoundEnvelopeController::GetController().SoundFadeOut( m_pBurnSound, deltaTime ); } // if flare is no longer bright, remove it from active flare list if ( m_bInActiveList && ( deltaTime <= FLARE_BLIND_TIME ) ) { RemoveFromActiveFlares(); } //Burned out if ( m_flTimeBurnOut < gpGlobals->curtime ) { UTIL_Remove( this ); return; } } //Act differently underwater if ( GetWaterLevel() > 1 ) { UTIL_Bubbles( GetAbsOrigin() + Vector( -2, -2, -2 ), GetAbsOrigin() + Vector( 2, 2, 2 ), 1 ); m_bSmoke = false; } else { //Shoot sparks if ( random->RandomInt( 0, 8 ) == 1 ) { g_pEffects->Sparks( GetAbsOrigin() ); } } //Next update SetNextThink( gpGlobals->curtime + 0.1f ); }
void CHL2MP_Player::ResetAnimation( void ) { if ( IsAlive() ) { SetSequence ( -1 ); SetActivity( ACT_INVALID ); if (!GetAbsVelocity().x && !GetAbsVelocity().y) SetAnimation( PLAYER_IDLE ); else if ((GetAbsVelocity().x || GetAbsVelocity().y) && ( GetFlags() & FL_ONGROUND )) SetAnimation( PLAYER_WALK ); else if (GetWaterLevel() > 1) SetAnimation( PLAYER_WALK ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CCrossbowBolt::BubbleThink() { QAngle angNewAngles; VectorAngles( GetAbsVelocity(), angNewAngles ); SetAbsAngles( angNewAngles ); SetNextThink( gpGlobals->curtime + 0.1f ); // Make danger sounds out in front of me, to scare snipers back into their hole CSoundEnt::InsertSound( SOUND_DANGER_SNIPERONLY, GetAbsOrigin() + GetAbsVelocity() * 0.2, 120.0f, 0.5f, this, SOUNDENT_CHANNEL_REPEATED_DANGER ); if ( GetWaterLevel() == 0 ) return; UTIL_BubbleTrail( GetAbsOrigin() - GetAbsVelocity() * 0.1f, GetAbsOrigin(), 5 ); }
void CBaseGrenade::DangerSoundThink( void ) { if (!IsInWorld()) { Remove( ); return; } #if !defined( CLIENT_DLL ) CSoundEnt::InsertSound ( SOUND_DANGER, GetAbsOrigin() + GetAbsVelocity() * 0.5, GetAbsVelocity().Length( ), 0.2, this ); #endif SetNextThink( gpGlobals->curtime + 0.2 ); if (GetWaterLevel() != 0) { SetAbsVelocity( GetAbsVelocity() * 0.5 ); } }
void CBaseGrenadeProjectile::DangerSoundThink( void ) { if (!IsInWorld()) { Remove( ); return; } if( gpGlobals->curtime > m_flDetonateTime ) { Detonate(); return; } CSoundEnt::InsertSound ( SOUND_DANGER, GetAbsOrigin() + GetAbsVelocity() * 0.5, GetAbsVelocity().Length( ), 0.2 ); SetNextThink( gpGlobals->curtime + 0.2 ); if (GetWaterLevel() != 0) { SetAbsVelocity( GetAbsVelocity() * 0.5 ); } }
//========================================================= //========================================================= void CAP_PlayerInfected::PostThink() { BaseClass::PostThink(); // Mientras estemos vivos if ( IsAlive() ) { // Estamos atacando // TODO: Creo que esto no es lo mejor if ( IsButtonPressed(IN_ATTACK) && gpGlobals->curtime >= m_iNextAttack ) { DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); m_iNextAttack = ATTACK_INTERVAL; } // ¡No sabemos nadar! // TODO: Animación de "ahogo" if ( GetWaterLevel() >= WL_Waist ) { SetBloodColor( DONT_BLEED ); TakeDamage( CTakeDamageInfo(this, this, GetMaxHealth(), DMG_GENERIC) ); } } }
//------------------------------------------------------------------------------ // If we hit water, then stop //------------------------------------------------------------------------------ void CQUAGrenadeHelicopter::PhysicsSimulate( void ) { Vector vecPrevPosition = GetAbsOrigin(); BaseClass::PhysicsSimulate(); if (!m_bActivated && (GetMoveType() != MOVETYPE_VPHYSICS)) { if ( GetWaterLevel() > 1 ) { SetAbsVelocity( vec3_origin ); SetMoveType( MOVETYPE_NONE ); BecomeActive(); } // Stuck condition, can happen pretty often if ( vecPrevPosition == GetAbsOrigin() ) { SetAbsVelocity( vec3_origin ); SetMoveType( MOVETYPE_NONE ); BecomeActive(); } } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CNPC_Ichthyosaur::PrescheduleThink( void ) { BaseClass::PrescheduleThink(); //Ambient sounds /* if ( random->RandomInt( 0, 20 ) == 10 ) { if ( random->RandomInt( 0, 1 ) ) { ENVELOPE_CONTROLLER.SoundChangeVolume( m_pSwimSound, random->RandomFloat( 0.0f, 0.5f ), 1.0f ); } else { ENVELOPE_CONTROLLER.SoundChangeVolume( m_pVoiceSound, random->RandomFloat( 0.0f, 0.5f ), 1.0f ); } } */ //Pings if ( m_flNextPingTime < gpGlobals->curtime ) { m_flNextPingTime = gpGlobals->curtime + random->RandomFloat( 3.0f, 8.0f ); } //Growls if ( ( m_NPCState == NPC_STATE_COMBAT || m_NPCState == NPC_STATE_ALERT ) && ( m_flNextGrowlTime < gpGlobals->curtime ) ) { m_flNextGrowlTime = gpGlobals->curtime + random->RandomFloat( 2.0f, 6.0f ); } //Randomly emit bubbles if ( random->RandomInt( 0, 10 ) == 0 ) { UTIL_Bubbles( GetAbsOrigin()+(GetHullMins()*0.5f), GetAbsOrigin()+(GetHullMaxs()*0.5f), 1 ); } //Check our water level if ( GetWaterLevel() != 3 ) { if ( GetWaterLevel() < 2 ) { DevMsg( 2, "Came out of water\n" ); if ( Beached() ) { SetSchedule( SCHED_ICH_THRASH ); Vector vecNewVelocity = GetAbsVelocity(); vecNewVelocity[2] = 8.0f; SetAbsVelocity( vecNewVelocity ); } } else { //TODO: Wake effects } } //If we have a victim, update them if ( m_pVictim != NULL ) { //See if it's time to release the victim if ( m_flHoldTime < gpGlobals->curtime ) { ReleaseVictim(); return; } Bite(); } }
void CSatchelCharge::SatchelThink( void ) { // If attached resize so player can pick up off wall if (m_bIsAttached) { UTIL_SetSize(this, Vector( -2, -2, -6), Vector(2, 2, 6)); } UpdateSlideSound(); // See if I can lose my owner (has dropper moved out of way?) // Want do this so owner can shoot the satchel charge if (GetOwnerEntity()) { trace_t tr; Vector vUpABit = GetAbsOrigin(); vUpABit.z += 5.0; CBaseEntity* saveOwner = GetOwnerEntity(); SetOwnerEntity( NULL ); UTIL_TraceEntity( this, GetAbsOrigin(), vUpABit, MASK_SOLID, &tr ); if ( tr.startsolid || tr.fraction != 1.0 ) { SetOwnerEntity( saveOwner ); } } // Bounce movement code gets this think stuck occasionally so check if I've // succeeded in moving, otherwise kill my motions. else if ((GetAbsOrigin() - m_vLastPosition).LengthSqr()<1) { SetAbsVelocity( vec3_origin ); QAngle angVel = GetLocalAngularVelocity(); angVel.y = 0; SetLocalAngularVelocity( angVel ); // Kill any remaining sound KillSlideSound(); // Clear think function SetThink(NULL); return; } m_vLastPosition= GetAbsOrigin(); StudioFrameAdvance( ); SetNextThink( gpGlobals->curtime + 0.1f ); if (!IsInWorld()) { // Kill any remaining sound KillSlideSound(); UTIL_Remove( this ); return; } // Is it attached to a wall? if (m_bIsAttached) { return; } Vector vecNewVel = GetAbsVelocity(); if (GetWaterLevel() == 3) { SetMoveType( MOVETYPE_FLY ); vecNewVel *= 0.8; vecNewVel.z += 8; SetLocalAngularVelocity( GetLocalAngularVelocity() * 0.9 ); } else if (GetWaterLevel() == 0) { SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); } else { vecNewVel.z -= 8; } SetAbsVelocity( vecNewVel ); }
void CHL1BaseGrenade::Explode( trace_t *pTrace, int bitsDamageType ) { float flRndSound;// sound randomizer SetModelName( NULL_STRING );//invisible AddSolidFlags( FSOLID_NOT_SOLID ); m_takedamage = DAMAGE_NO; // Pull out of the wall a bit if ( pTrace->fraction != 1.0 ) { SetLocalOrigin( pTrace->endpos + (pTrace->plane.normal * 0.6) ); } UTIL_Relink( this ); Vector vecAbsOrigin = GetAbsOrigin(); int contents = UTIL_PointContents ( vecAbsOrigin ); if ( pTrace->fraction != 1.0 ) { Vector vecNormal = pTrace->plane.normal; surfacedata_t *pdata = physprops->GetSurfaceData( pTrace->surface.surfaceProps ); CPASFilter filter( vecAbsOrigin ); te->Explosion( filter, 0.0, &vecAbsOrigin, !( contents & MASK_WATER ) ? g_sModelIndexFireball : g_sModelIndexWExplosion, m_DmgRadius * .03, 25, TE_EXPLFLAG_NONE, m_DmgRadius, m_flDamage, &vecNormal, (char) pdata->gameMaterial ); } else { CPASFilter filter( vecAbsOrigin ); te->Explosion( filter, 0.0, &vecAbsOrigin, !( contents & MASK_WATER ) ? g_sModelIndexFireball : g_sModelIndexWExplosion, m_DmgRadius * .03, 25, TE_EXPLFLAG_NONE, m_DmgRadius, m_flDamage ); } CSoundEnt::InsertSound ( SOUND_COMBAT, GetAbsOrigin(), BASEGRENADE_EXPLOSION_VOLUME, 3.0 ); // Use the owner's position as the reported position Vector vecReported = GetOwner() ? GetOwner()->GetAbsOrigin() : vec3_origin; CTakeDamageInfo info( this, GetOwner(), GetBlastForce(), GetAbsOrigin(), m_flDamage, bitsDamageType, 0, &vecReported ); RadiusDamage( info, GetAbsOrigin(), m_DmgRadius, CLASS_NONE ); UTIL_DecalTrace( pTrace, "Scorch" ); flRndSound = random->RandomFloat( 0 , 1 ); EmitSound( "BaseGrenade.Explode" ); SetTouch( NULL ); m_fEffects |= EF_NODRAW; SetAbsVelocity( vec3_origin ); SetThink( Smoke ); SetNextThink( gpGlobals->curtime + 0.3); if ( GetWaterLevel() == 0 ) { int sparkCount = random->RandomInt( 0,3 ); QAngle angles; VectorAngles( pTrace->plane.normal, angles ); for ( int i = 0; i < sparkCount; i++ ) Create( "spark_shower", GetAbsOrigin(), angles, NULL ); } }
//----------------------------------------------------------------------------- // Purpose: Returns whether or not we are allowed to sprint now. //----------------------------------------------------------------------------- bool C_HL2MP_Player::CanSprint( void ) { return ( (!m_Local.m_bDucked && !m_Local.m_bDucking) && (GetWaterLevel() != 3) ); }
int main(int argc, char *argv[]) { union SIGNAL *Msg; unsigned char Buf[sizeof(union SIGNAL)]; char TimeStamp[100], TimeStampStop[100], FilePath[40]; unsigned char UpdateInterval, Idx; enum ProcTypes_e ProcessorType; char ByteportText[100]; int fd_Own, fd_ToOwn, fd_Timo, fd_BytePRep, fd_Sens; // First thing to do! Register signal and signal handler for (error) signals from operating system signal(SIGINT, SignalCallbackHandler); // Ctrl -c catched signal(SIGSEGV, SignalCallbackHandler); // Segmentation fault catched signal(SIGILL, SignalCallbackHandler); // Illegal instruction catched signal(SIGBUS, SignalCallbackHandler); // Bus error catched signal(SIGSTKFLT, SignalCallbackHandler); // Stack fault catched signal(SIGXFSZ, SignalCallbackHandler); // File size exceeded ctached //DebugOn = TRUE; // Start in Debug mode //ProcState.ModeState = Water; // Set initial value, for test purpose. TBD later ProcState.ModeState = MainMode; // Set initial value, for test purpose. TBD later ProcState.ServMode = AnchStop; // Set initial value ProcState.MinOutTemp = SENS_DEF_VAL; ProcState.MaxOutTemp = SENS_DEF_VAL; ProcState.OutTemp = SENS_DEF_VAL; ProcState.MinSeaTemp = SENS_DEF_VAL; ProcState.MaxSeaTemp = SENS_DEF_VAL; ProcState.SeaTemp = SENS_DEF_VAL; ProcState.MinRefrigTemp = SENS_DEF_VAL; ProcState.MaxRefrigTemp = SENS_DEF_VAL; ProcState.RefrigTemp = SENS_DEF_VAL; ProcState.MinBoxTemp = SENS_DEF_VAL; ProcState.MaxBoxTemp = SENS_DEF_VAL; ProcState.BoxTemp = SENS_DEF_VAL; ProcState.MinWaterTemp = SENS_DEF_VAL; ProcState.MaxWaterTemp = SENS_DEF_VAL; ProcState.WaterTemp = SENS_DEF_VAL; ProcState.WaterLevel = SENS_DEF_VAL; ProcState.HWTemp = SENS_DEF_VAL; ProcState.DieselLevel = SENS_DEF_VAL; ProcState.BatVoltS = 13.5; //SENS_DEF_VAL; Start value, avoids div by 0! ProcState.BatVoltF = 13.5; //SENS_DEF_VAL; Start value, avoids div by 0! ProcState.BatAmpS = SENS_DEF_VAL; ProcState.BatAmpF = SENS_DEF_VAL; ProcState.LCD_Id = 0; ProcState.fd.lcd = 0; ProcState.fd.RD_MainPipe = 0; ProcState.fd.WR_MainPipe = 0; ProcState.fd.RD_TimoPipe = 0; ProcState.fd.WR_TimoPipe = 0; ProcState.fd.WR_OWPipe = 0; ProcState.fd.RD_OWPipe = 0; ProcState.fd.WR_kbdButPipe = 0; ProcState.fd.RD_kbdButPipe = 0; ProcState.fd.WR_kbdKnobPipe = 0; ProcState.fd.RD_kbdKnobPipe = 0; ProcState.fd.RD_BPRepPipe = 0; ProcState.fd.WR_BPRepPipe = 0; ProcState.fd.OutTemp = 0; ProcState.fd.BoxTemp = 0; ProcState.fd.DieselLevel = 0; ProcState.fd.WaterLevel = 0; ProcState.fd.RefrigTemp = 0; ProcState.DevLCDDefined = FALSE; ProcState.UpdateInterval = 12; // Timeout intervall for data & display update ProcState.LCDBlkOnTimer = LCDBlkOnTimerVal; // Time before turning backlight off // Check if 1wire master ID present, set name accordingly. For now use default sprintf(ProcState.DeviceName,"%s", "JosefinSim"); // Initiate filter queue for (Idx = 0; Idx < NO_OF_ELEM_IN_FILTERQUEU; Idx++) { FQueue[Idx].ADDiesel = SENS_DEF_VAL; FQueue[Idx].ADWater = SENS_DEF_VAL; FQueue[Idx].ADBatVoltF = SENS_DEF_VAL; } memset(LCDText, ' ', 100); // Clear display buffer InitProc(&ProcState); //LOG_MSG("All processes initiated\r\n");sleep(0); fd_ToOwn = ProcState.fd.WR_MainPipe; fd_Own = ProcState.fd.RD_MainPipe; fd_BytePRep = ProcState.fd.WR_BPRepPipe; fd_Timo = ProcState.fd.WR_TimoPipe; fd_Sens = ProcState.fd.WR_OWPipe; sprintf(&LCDText[0], " %s started Ver: %s Golding production ", ProcState.DeviceName, __DATE__ ); // Now we must wait for the LCD to be initiated... int idx = 0; while (!ProcState.DevLCDDefined) { usleep(200000); // LOG_MSG("."); idx++; if (idx >= 1000) { LOG_MSG("Err: Not able to start, no LCD found..exit! \r\n"); exit(0); } } if (ProcState.DevLCDDefined) { // If LCD attached LCD1W_WRITE(LCD1, 1, &LCDText[Line1]); LCD1W_WRITE(LCD1, 3, &LCDText[Line2]); LCD1W_WRITE(LCD1, 2, &LCDText[Line3]); LCD1W_WRITE(LCD1, 4, &LCDText[Line4]); } else { // report error sprintf(InfoText, "Err: LCD not initated fd = %d \n", ProcState.fd.lcd); LOG_MSG(InfoText); } REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitTOut", SIGInitMeasTempOut, 3 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitTBox", SIGInitMeasTempBox, 8 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitTRefrig", SIGInitMeasTempRefrig, 3 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitTWater", SIGInitMeasTempWater, 15 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitTHWater", SIGInitMeasTempHW, 15 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitTSea", SIGInitMeasTempSea, 20 Sec); // REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitADInt", SIGInitMeasADInt, 2 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitADExt", SIGInitMeasADExt, 10 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitBlkOn", SIGMinuteTick, 60 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainInitLCDBlink", SIGSecondTick, 1 Sec); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainSend BPReport", SIGInitByteportReport, 10 Sec); Msg = (void *) Buf; if (fd_BytePRep != 0) { Msg->SigNo = SIGByteportInit; sprintf(Msg->ByteportReport.Str, ProcState.DeviceName); SEND(fd_BytePRep, Msg, sizeof(union SIGNAL)); } else LOG_MSG ("Error: No Byteport handler defined \r\n"); sprintf(InfoText, "%s started Ver: %s\n", ProcState.DeviceName, __DATE__); LOG_MSG(InfoText); while (TRUE) { WAIT(fd_Own, Buf, sizeof(union SIGNAL)); //if (Msg->SigNo == 10) {DbgTest = 1;} fflush(stdout); // Flush stdout, used if we print to file Msg = (void *) Buf; if (DbgTest == 1) {printf("2: %d\r\n", Msg->SigNo);usleep(200000);} switch(Msg->SigNo) { case SIGSecondTick: LCDDisplayUpdate(&ProcState); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainLCDBlink", SIGSecondTick, 1 Sec); break; case SIGMinuteTick: // Wait until backlight should be turned off REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MinuteTick", SIGMinuteTick, 60 Sec); // printf("Tick: %d\r\n", ProcState.LCDBlkOnTimer); if (ProcState.fd.lcd >= 0) { // First check that we have a LCD attached if (ProcState.LCDBlkOnTimer <= 0) Set1WLCDBlkOff(LCD1); // Turn off backlight on display else ProcState.LCDBlkOnTimer--; } break; case SIGInitByteportReport: // Select below which values to report to Byteport, and how often! Msg->SigNo = SIGByteportReport; sprintf(Msg->ByteportReport.Str, "OutTemp=%-.1f;BoxTemp=%-.1f;RefrigTemp=%-.1f;WaterTemp=%-.1f;WaterLevel=%-.1f;DieselLevel=%-.1f;BatVoltF=%-.1f", ProcState.OutTemp, ProcState.BoxTemp,ProcState.RefrigTemp,ProcState.WaterLevel, ProcState.DieselLevel, ProcState.BatVoltF); //sprintf(Msg->ByteportReport.Str, "OutTemp=%-.1f;BoxTemp=%-.1f;RefrigTemp=%-.1f;WaterTemp=%-.1f;HWaterTemp=%-.1f;SeaTemp=%-.1f;WaterLevel=%-.1f;DieselLevel=%-.1f;BatVoltF=%-.1f", ProcState.OutTemp, ProcState.BoxTemp,ProcState.RefrigTemp, ProcState.WaterTemp, ProcState.HWaterTemp, ProcState.SeaTemp, ProcState.WaterLevel, ProcState.DieselLevel, ProcState.BatVoltF); if (DebugOn == 1) { printf(" %s \r\n", Msg->ByteportReport.Str); } SEND(fd_BytePRep, Msg, sizeof(union SIGNAL)); REQ_TIMEOUT(fd_Timo, fd_ToOwn, "MainSend BPReport", SIGInitByteportReport, 60 Sec); // Time between each report to Byteport break; case SIGInitMeasTempBox: // Initiate loop to read Temperature sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = BOX_TEMP; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasTempRefrig: // Initiate loop to read Temperature sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = REFRIG_TEMP; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasTempWater: // Initiate loop to read Temperature sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = WATER_TEMP; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasTempSea: // Initiate loop to read Temperature sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = SEA_TEMP; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasTempHW: // Initiate loop to read Temperature sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = HWATER_TEMP; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasTempOut: // Initiate loop to read Temperature sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = OUT_TEMP; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasADInt: // Initiate loop to read AD sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = ADINT; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGInitMeasADExt: // Initiate loop to read AD sensors Msg->SigNo = SIGReadSensorReq; Msg->SensorReq.Client_fd = fd_ToOwn; Msg->SensorReq.Sensor = ADEXT; SEND(fd_Sens, Msg, sizeof(union SIGNAL)); break; case SIGReadSensorResp: if (DbgTest == 1) { printf(" SenRsp %d: %10.5f sec V1: %f V2: %f Status: %s \r\n", Msg->SensorResp.Sensor, Msg->SensorResp.CmdTime, Msg->SensorResp.Val[0], Msg->SensorResp.Val[1], Msg->SensorResp.Status ? "OK" : "ERROR"); } switch (Msg->SensorResp.Sensor) { case OUT_TEMP: ProcState.OutTemp = Msg->SensorResp.Val[0]; if (Msg->SensorResp.Status) { // Valid data recieved if ((ProcState.MinOutTemp == SENS_DEF_VAL) || (ProcState.OutTemp < ProcState.MinOutTemp)) ProcState.MinOutTemp = Msg->SensorResp.Val[0]; if ((ProcState.MaxOutTemp == SENS_DEF_VAL) || (ProcState.OutTemp > ProcState.MaxOutTemp)) ProcState.MaxOutTemp = Msg->SensorResp.Val[0]; } // No valid data REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitTOut", SIGInitMeasTempOut, 30 Sec); LCDDisplayUpdate(&ProcState); break; case BOX_TEMP: ProcState.BoxTemp = Msg->SensorResp.Val[0]; if (Msg->SensorResp.Status) { // Valid data recieved if ((ProcState.MinBoxTemp == SENS_DEF_VAL) || (ProcState.BoxTemp < ProcState.MinBoxTemp)) ProcState.MinBoxTemp = Msg->SensorResp.Val[0]; if ((ProcState.MaxBoxTemp == SENS_DEF_VAL) || (ProcState.BoxTemp > ProcState.MaxBoxTemp)) ProcState.MaxBoxTemp = Msg->SensorResp.Val[0]; } REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitTBox", SIGInitMeasTempBox, 15 Sec); LCDDisplayUpdate(&ProcState); break; case REFRIG_TEMP: ProcState.RefrigTemp = Msg->SensorResp.Val[0]; if (Msg->SensorResp.Status) { // Valid data recieved if ((ProcState.MinRefrigTemp == SENS_DEF_VAL) || (ProcState.RefrigTemp < ProcState.MinRefrigTemp)) ProcState.MinRefrigTemp = Msg->SensorResp.Val[0]; if ((ProcState.MaxRefrigTemp == SENS_DEF_VAL) || (ProcState.RefrigTemp > ProcState.MaxRefrigTemp)) ProcState.MaxRefrigTemp = Msg->SensorResp.Val[0]; } REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitTRefrig", SIGInitMeasTempRefrig, 20 Sec); LCDDisplayUpdate(&ProcState); break; case WATER_TEMP: ProcState.WaterTemp = Msg->SensorResp.Val[0]; if (Msg->SensorResp.Status) { // Valid data recieved if ((ProcState.MinWaterTemp == SENS_DEF_VAL) || (ProcState.WaterTemp < ProcState.MinWaterTemp)) ProcState.MinWaterTemp = Msg->SensorResp.Val[0]; if ((ProcState.MaxWaterTemp == SENS_DEF_VAL) || (ProcState.WaterTemp > ProcState.MaxWaterTemp)) ProcState.MaxWaterTemp = Msg->SensorResp.Val[0]; } REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitTWater", SIGInitMeasTempWater, 20 Sec); LCDDisplayUpdate(&ProcState); break; case HWATER_TEMP: ProcState.HWTemp = Msg->SensorResp.Val[0]; if (Msg->SensorResp.Status) { // Valid data recieved if ((ProcState.MinHWTemp == SENS_DEF_VAL) || (ProcState.HWTemp < ProcState.MinHWTemp)) ProcState.MinHWTemp = Msg->SensorResp.Val[0]; if ((ProcState.MaxHWTemp == SENS_DEF_VAL) || (ProcState.HWTemp > ProcState.MaxHWTemp)) ProcState.MaxHWTemp = Msg->SensorResp.Val[0]; } REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitHW", SIGInitMeasTempHW, 20 Sec); LCDDisplayUpdate(&ProcState); break; case SEA_TEMP: ProcState.SeaTemp= Msg->SensorResp.Val[0]; if (Msg->SensorResp.Status) { // Valid data recieved if ((ProcState.MinSeaTemp == SENS_DEF_VAL) || (ProcState.SeaTemp < ProcState.MinSeaTemp)) ProcState.MinSeaTemp = Msg->SensorResp.Val[0]; if ((ProcState.MaxSeaTemp == SENS_DEF_VAL) || (ProcState.SeaTemp > ProcState.MaxSeaTemp)) ProcState.MaxSeaTemp = Msg->SensorResp.Val[0]; } REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitTSea", SIGInitMeasTempSea, 40 Sec); LCDDisplayUpdate(&ProcState); break; case ADINT: /* if (Msg->SensorResp.Status) { // Valid data recieved ProcState.BatVoltF = 11* (Msg->SensorResp.Val[0]) + 0.65; //Correction due to ... //sprintf(InfoText, "BatF %f AD %6.3f\n", ProcState.BatVoltF, Msg->SensorResp.Val[0]); //LOG_MSG(InfoText); } REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitADInt", SIGInitMeasADInt, 5 Sec); // TIMER_START(TM1AD); LCDDisplayUpdate(&ProcState); */ break; case ADEXT: if (Msg->SensorResp.Status) { // Valid data recieved // Filter data to get better readings with less variation if (FQueue[0].ADWater == SENS_DEF_VAL) { // Not initiated yet, do it! for (Idx = 0; Idx < NO_OF_ELEM_IN_FILTERQUEU; Idx++) { FQueue[Idx].ADDiesel = Msg->SensorResp.Val[0]; FQueue[Idx].ADWater = Msg->SensorResp.Val[1]; FQueue[Idx].ADBatVoltF = Msg->SensorResp.Val[2]; } // for } // if // Move all data up 1 position in queue for (Idx = (NO_OF_ELEM_IN_FILTERQUEU - 1); Idx > 0; Idx--) { // printf("Idx: %d\r\n", Idx); FQueue[Idx].ADDiesel = FQueue[Idx - 1].ADDiesel; FQueue[Idx].ADWater = FQueue[Idx - 1].ADWater; FQueue[Idx].ADBatVoltF = FQueue[Idx - 1].ADBatVoltF; } // for FQueue[0].ADDiesel = Msg->SensorResp.Val[0]; FQueue[0].ADWater = Msg->SensorResp.Val[1]; FQueue[0].ADBatVoltF = Msg->SensorResp.Val[2]; Msg->SensorResp.Val[0] = 0; Msg->SensorResp.Val[1] = 0; Msg->SensorResp.Val[2] = 0; // Calculate mean value of all elem in filter queue for (Idx = 0; Idx < NO_OF_ELEM_IN_FILTERQUEU; Idx++) { //printf("ADD %d: %4f ", Idx, FQueue[Idx].ADDiesel); Msg->SensorResp.Val[0] += FQueue[Idx].ADDiesel; Msg->SensorResp.Val[1] += FQueue[Idx].ADWater; Msg->SensorResp.Val[2] += FQueue[Idx].ADBatVoltF; } // for //printf("\r\n"); Msg->SensorResp.Val[0] = Msg->SensorResp.Val[0]/(NO_OF_ELEM_IN_FILTERQUEU); Msg->SensorResp.Val[1] = Msg->SensorResp.Val[1]/(NO_OF_ELEM_IN_FILTERQUEU); Msg->SensorResp.Val[2] = Msg->SensorResp.Val[2]/(NO_OF_ELEM_IN_FILTERQUEU); //printf("Wavg: %4f WLatest: %4f \r\n", Msg->SensorResp.Val[1], FQueue[0].ADWater); ProcState.BatVoltF = (Msg->SensorResp.Val[2] + 0.5); // Need to 0.5V due to measurement errors..? ProcState.ADWaterLevel = Msg->SensorResp.Val[1]; ProcState.ADDieselLevel = Msg->SensorResp.Val[0]; if ((ProcState.BatVoltF < 10) || (ProcState.BatVoltF > 15)) // Check if reasonable Voltage ProcState.BatVoltF = 13; // Set default value // Compensate for battery voltage ProcState.ADWaterLevel = ProcState.ADWaterLevel * 13 / ProcState.BatVoltF; ProcState.ADDieselLevel = ProcState.ADDieselLevel * 13 / ProcState.BatVoltF; if (DebugOn) // Print adjusted AD reading printf(">>>>Converted AD reading[BF %4.2f DL: %4.2f WL: %4.2f BS: %4.2f]\r\n", ProcState.BatVoltF, Msg->SensorResp.Val[0], Msg->SensorResp.Val[1], Msg->SensorResp.Val[2]); // Calculate water and diesel levels ProcState.WaterLevel = GetWaterLevel(ProcState.ADWaterLevel); ProcState.DieselLevel = GetDieselLevel(ProcState.ADDieselLevel); } if ((ProcState.ModeState == Water) || (ProcState.ModeState == Diesel) ) { // Fast update. Always send to Byteport at same pace! Msg->SigNo = SIGByteportReport; sprintf(Msg->ByteportReport.Str, "WaterLevel=%-.1f", ProcState.WaterLevel); if (DebugOn == 1) { LOG_MSG(Msg->ByteportReport.Str); } SEND(fd_BytePRep, Msg, sizeof(union SIGNAL)); REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitADExtFst", SIGInitMeasADExt, 1 Sec); // if (DebugOn) printf("Fast update M:%d \r\n",ProcState.ModeState); } else { // Slow update REQ_TIMEOUT(fd_Timo, ProcState.fd.WR_MainPipe, "MainInitADExtSlw", SIGInitMeasADExt, 12 Sec); // if (DebugOn) printf("Slow update M:%d \r\n",ProcState.ModeState ); } //sprintf(InfoText, "BatF %7.3f AD: %7.3f \n", ProcState.BatVoltS, Msg->SensorResp.Val[3]); //LOG_MSG(InfoText); // Write to file for Byteport reporting. create file if not opened yet //if (ProcState.fd.WaterLevel == 0) // No file descriptor defined LCDDisplayUpdate(&ProcState); break; // ADExt default: CHECK(FALSE, "Undefined sensor...\n"); break; } LCDDisplayUpdate(&ProcState); /* // Removed 20161227. Now we use Byteport cmd reporting by Axel! // Write to file for Byteport reporting. Create file if not opened yet if (DbgTest == 1) {printf("Enter send to Byteport\r\n");usleep(200000);} sprintf(FilePath, "/tmp/ByteportReports/BatVoltF"); // Set filename if((ProcState.fd.BatVoltF = fopen(FilePath, "w+")) == NULL) { // Check that file exists sprintf(InfoText, "ERROR: %s %d Can not open file %s \n", strerror(errno), errno, FilePath); CHECK(FALSE, InfoText); } else { sprintf(ByteportText, "%-.1f", ProcState.BatVoltF); fprintf(ProcState.fd.BatVoltF, ByteportText); fclose(ProcState.fd.BatVoltF); } if (DbgTest == 1) {printf("BatVoltF written\r\n");usleep(200000);} sprintf(FilePath, "/tmp/ByteportReports/DieselLevel"); // Set filename if((ProcState.fd.DieselLevel = fopen(FilePath, "w+")) == NULL) { // Check that file exists sprintf(InfoText, "ERROR: %s %d Can not open file %s \n", strerror(errno), errno, FilePath); CHECK(FALSE, InfoText); } else { sprintf(ByteportText, "%-.1f", ProcState.DieselLevel); fprintf(ProcState.fd.DieselLevel, ByteportText); fclose(ProcState.fd.DieselLevel); } if (DbgTest == 1) {printf("DieselLevel written\r\n");usleep(200000);} sprintf(FilePath, "/tmp/ByteportReports/WaterLevel"); // Set filename if((ProcState.fd.WaterLevel = fopen(FilePath, "w+")) == NULL) { // Check that file exists sprintf(InfoText, "ERROR: %s %d Can not open file %s \n", strerror(errno), errno, FilePath); CHECK(FALSE, InfoText); } else { sprintf(ByteportText, "%-.1f", ProcState.WaterLevel); fprintf(ProcState.fd.WaterLevel, ByteportText); fclose(ProcState.fd.WaterLevel); } if (DbgTest == 1) {printf("Leaving send to Byteport\r\n");usleep(200000);} if (Msg->SensorResp.Sensor == WATER_TEMP) {// Just to secure only 1 line when no display present LCDDisplayUpdate(&ProcState); } */ break; // Turn on backlight on Display when a button is pushed. case SIGOpButOn: if (DbgTest == 1) {printf("3: %d\r\n", Msg->SigNo);usleep(200000);} if (!ProcState.fd.lcd) { // First check that we have a LCD attached if (ProcState.LCDBlkOnTimer <= 0) { // If Display OFF, Set timer and turn on Display-nothing else ProcState.LCDBlkOnTimer = LCDBlkOnTimerVal; // Time before turning backlight off Set1WLCDBlkOn(LCD1); // Turn on backlight on display } else { // Execute button pressed OpButPressed(&ProcState); LCDDisplayUpdate(&ProcState); } } break; case SIGLftButOn: //printf("Left button presssed Msg: %s\n"); ProcState.LCDBlkOnTimer = LCDBlkOnTimerVal; // Time before turning backlight off Set1WLCDBlkOn(LCD1); // Turn on backlight on display RghtButPressed(&ProcState); // LftButPressed(&ProcState); // Due to problems reading Left/Right. Step always Right!!! LCDDisplayUpdate(&ProcState); break; case SIGRghtButOn: //printf("Right button presssed \n"); ProcState.LCDBlkOnTimer = LCDBlkOnTimerVal; // Time before turning backlight off Set1WLCDBlkOn(LCD1); // Turn on backlight on display RghtButPressed(&ProcState); LCDDisplayUpdate(&ProcState); break; case SIGServCmdReq: switch (Msg->ServCmdReq.Cmd) { case Dwn: printf("Main: Anchor Down \r\n"); break; case SlwUp: printf("Main: Anchor Slow Up \r\n"); break; case Up: printf("Main: Anchor Up \r\n"); break; case AnchStop: printf("Main: Anchor STOP \r\n"); break; case SetTime: printf("Main: Set Time \r\n"); break; default: sprintf(InfoText, "Illegal server cmd received: %d\n", Msg->ServCmdReq.Cmd); CHECK(FALSE, InfoText); break; } // End switch break; default: sprintf(InfoText, "Illegal signal received: %d MsgLen: %d Data: %x %x %x %x\n", Msg->SigNo, sizeof(Msg), Msg->Data[0], Msg->Data[1],Msg->Data[2],Msg->Data[3]); CHECK(FALSE, InfoText); break; } // Switch } // While }
void CSnark::HuntThink( void ) { if (!IsInWorld()) { SetTouch( NULL ); UTIL_Remove( this ); return; } StudioFrameAdvance( ); SetNextThink( gpGlobals->curtime + 0.1f ); // explode when ready if ( gpGlobals->curtime >= m_flDie ) { g_vecAttackDir = GetAbsVelocity(); VectorNormalize( g_vecAttackDir ); m_iHealth = -1; CTakeDamageInfo info( this, this, 1, DMG_GENERIC ); Event_Killed( info ); return; } // float if ( GetWaterLevel() != 0) { if ( GetMoveType() == MOVETYPE_FLYGRAVITY ) { SetMoveType( MOVETYPE_FLY, MOVECOLLIDE_FLY_BOUNCE ); } Vector vecVel = GetAbsVelocity(); vecVel *= 0.9; vecVel.z += 8.0; SetAbsVelocity( vecVel ); } else if ( GetMoveType() == MOVETYPE_FLY ) { SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); } // return if not time to hunt if ( m_flNextHunt > gpGlobals->curtime ) return; m_flNextHunt = gpGlobals->curtime + 2.0; Vector vecFlat = GetAbsVelocity(); vecFlat.z = 0; VectorNormalize( vecFlat ); if ( GetEnemy() == NULL || !GetEnemy()->IsAlive() ) { // find target, bounce a bit towards it. GetSenses()->Look( 512 ); SetEnemy( BestEnemy() ); } // squeek if it's about time blow up if ( (m_flDie - gpGlobals->curtime <= 0.5) && (m_flDie - gpGlobals->curtime >= 0.3) ) { CPASAttenuationFilter filter( this ); enginesound->EmitSound( filter, entindex(), CHAN_VOICE, "squeek/sqk_die1.wav", 1, ATTN_NORM, 0, 100 + random->RandomInt( 0, 0x3F ) ); CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), 256, 0.25 ); } // higher pitch as squeeker gets closer to detonation time float flpitch = 155.0 - 60.0 * ( (m_flDie - gpGlobals->curtime) / SQUEEK_DETONATE_DELAY ); if ( flpitch < 80 ) flpitch = 80; if ( GetEnemy() != NULL ) { if ( FVisible( GetEnemy() ) ) { m_vecTarget = GetEnemy()->EyePosition() - GetAbsOrigin(); VectorNormalize( m_vecTarget ); } float flVel = GetAbsVelocity().Length(); float flAdj = 50.0 / ( flVel + 10.0 ); if ( flAdj > 1.2 ) flAdj = 1.2; // ALERT( at_console, "think : enemy\n"); // ALERT( at_console, "%.0f %.2f %.2f %.2f\n", flVel, m_vecTarget.x, m_vecTarget.y, m_vecTarget.z ); SetAbsVelocity( GetAbsVelocity() * flAdj + (m_vecTarget * 300) ); } if ( GetFlags() & FL_ONGROUND ) { SetLocalAngularVelocity( QAngle( 0, 0, 0 ) ); } else { QAngle angVel = GetLocalAngularVelocity(); if ( angVel == QAngle( 0, 0, 0 ) ) { angVel.x = random->RandomFloat( -100, 100 ); angVel.z = random->RandomFloat( -100, 100 ); SetLocalAngularVelocity( angVel ); } } if ( ( GetAbsOrigin() - m_posPrev ).Length() < 1.0 ) { Vector vecVel = GetAbsVelocity(); vecVel.x = random->RandomFloat( -100, 100 ); vecVel.y = random->RandomFloat( -100, 100 ); SetAbsVelocity( vecVel ); } m_posPrev = GetAbsOrigin(); QAngle angles; VectorAngles( GetAbsVelocity(), angles ); angles.z = 0; angles.x = 0; SetAbsAngles( angles ); }
//----------------------------------------------------------------------------- // Purpose: // Input : *pOther - //----------------------------------------------------------------------------- void CFlare::FlareTouch( CBaseEntity *pOther ) { Assert( pOther ); if ( !pOther->IsSolid() ) return; if ( ( m_nBounces < 10 ) && ( GetWaterLevel() < 1 ) ) { // Throw some real chunks here g_pEffects->Sparks( GetAbsOrigin() ); } //If the flare hit a person or NPC, do damage here. if ( pOther && pOther->m_takedamage ) { /* The Flare is the iRifle round right now. No damage, just ignite. (sjb) //Damage is a function of how fast the flare is flying. int iDamage = GetAbsVelocity().Length() / 50.0f; if ( iDamage < 5 ) { //Clamp minimum damage iDamage = 5; } //Use m_pOwner, not GetOwnerEntity() pOther->TakeDamage( CTakeDamageInfo( this, m_pOwner, iDamage, (DMG_BULLET|DMG_BURN) ) ); m_flNextDamage = gpGlobals->curtime + 1.0f; */ CBaseAnimating *pAnim; pAnim = dynamic_cast<CBaseAnimating*>(pOther); if( pAnim ) { pAnim->Ignite( 30.0f ); } Vector vecNewVelocity = GetAbsVelocity(); vecNewVelocity *= 0.1f; SetAbsVelocity( vecNewVelocity ); SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); SetGravity(1.0f); Die( 0.5 ); return; } else { // hit the world, check the material type here, see if the flare should stick. trace_t tr; tr = CBaseEntity::GetTouchTrace(); //Only do this on the first bounce if ( m_nBounces == 0 ) { const surfacedata_t *pdata = physprops->GetSurfaceData( tr.surface.surfaceProps ); if ( pdata != NULL ) { //Only embed into concrete and wood (jdw: too obscure for players?) //if ( ( pdata->gameMaterial == 'C' ) || ( pdata->gameMaterial == 'W' ) ) { Vector impactDir = ( tr.endpos - tr.startpos ); VectorNormalize( impactDir ); float surfDot = tr.plane.normal.Dot( impactDir ); //Do not stick to ceilings or on shallow impacts if ( ( tr.plane.normal.z > -0.5f ) && ( surfDot < -0.9f ) ) { RemoveSolidFlags( FSOLID_NOT_SOLID ); AddSolidFlags( FSOLID_TRIGGER ); UTIL_SetOrigin( this, tr.endpos + ( tr.plane.normal * 2.0f ) ); SetAbsVelocity( vec3_origin ); SetMoveType( MOVETYPE_NONE ); SetTouch( &CFlare::FlareBurnTouch ); int index = decalsystem->GetDecalIndexForName( "SmallScorch" ); if ( index >= 0 ) { CBroadcastRecipientFilter filter; te->Decal( filter, 0.0, &tr.endpos, &tr.startpos, ENTINDEX( tr.m_pEnt ), tr.hitbox, index ); } CPASAttenuationFilter filter2( this, "Flare.Touch" ); EmitSound( filter2, entindex(), "Flare.Touch" ); return; } } } } //Scorch decal if ( GetAbsVelocity().LengthSqr() > (250*250) ) { int index = decalsystem->GetDecalIndexForName( "FadingScorch" ); if ( index >= 0 ) { CBroadcastRecipientFilter filter; te->Decal( filter, 0.0, &tr.endpos, &tr.startpos, ENTINDEX( tr.m_pEnt ), tr.hitbox, index ); } } // Change our flight characteristics SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); SetGravity( UTIL_ScaleForGravity( 640 ) ); m_nBounces++; //After the first bounce, smacking into whoever fired the flare is fair game SetOwnerEntity( this ); // Slow down Vector vecNewVelocity = GetAbsVelocity(); vecNewVelocity.x *= 0.8f; vecNewVelocity.y *= 0.8f; SetAbsVelocity( vecNewVelocity ); //Stopped? if ( GetAbsVelocity().Length() < 64.0f ) { SetAbsVelocity( vec3_origin ); SetMoveType( MOVETYPE_NONE ); RemoveSolidFlags( FSOLID_NOT_SOLID ); AddSolidFlags( FSOLID_TRIGGER ); SetTouch( &CFlare::FlareBurnTouch ); } } }
void CSqueakGrenade::HuntThink( void ) { // ALERT( at_console, "think\n" ); if( !IsInWorld() ) { SetTouch( NULL ); UTIL_Remove( this ); return; } StudioFrameAdvance(); pev->nextthink = gpGlobals->time + 0.1; // explode when ready if( gpGlobals->time >= m_flDie ) { g_vecAttackDir = pev->velocity.Normalize(); pev->health = -1; Killed( CTakeDamageInfo( this, 0, 0 ), GIB_NORMAL ); return; } // float if( GetWaterLevel() != WATERLEVEL_DRY ) { if( pev->movetype == MOVETYPE_BOUNCE ) { pev->movetype = MOVETYPE_FLY; } pev->velocity = pev->velocity * 0.9; pev->velocity.z += 8.0; } else if( pev->movetype == MOVETYPE_FLY ) { pev->movetype = MOVETYPE_BOUNCE; } // return if not time to hunt if( m_flNextHunt > gpGlobals->time ) return; m_flNextHunt = gpGlobals->time + 2.0; CBaseEntity *pOther = NULL; Vector vecDir; TraceResult tr; Vector vecFlat = pev->velocity; vecFlat.z = 0; vecFlat = vecFlat.Normalize(); UTIL_MakeVectors( pev->angles ); if( m_hEnemy == NULL || !m_hEnemy->IsAlive() ) { // find target, bounce a bit towards it. Look( 512 ); m_hEnemy = BestVisibleEnemy(); } // squeek if it's about time blow up if( ( m_flDie - gpGlobals->time <= 0.5 ) && ( m_flDie - gpGlobals->time >= 0.3 ) ) { EMIT_SOUND_DYN( this, CHAN_VOICE, "squeek/sqk_die1.wav", 1, ATTN_NORM, 0, 100 + RANDOM_LONG( 0, 0x3F ) ); CSoundEnt::InsertSound( bits_SOUND_COMBAT, GetAbsOrigin(), 256, 0.25 ); } // higher pitch as squeeker gets closer to detonation time float flpitch = 155.0 - 60.0 * ( ( m_flDie - gpGlobals->time ) / SQUEEK_DETONATE_DELAY ); if( flpitch < 80 ) flpitch = 80; if( m_hEnemy != NULL ) { if( FVisible( m_hEnemy ) ) { vecDir = m_hEnemy->EyePosition() - GetAbsOrigin(); m_vecTarget = vecDir.Normalize(); } float flVel = pev->velocity.Length(); float flAdj = 50.0 / ( flVel + 10.0 ); if( flAdj > 1.2 ) flAdj = 1.2; // ALERT( at_console, "think : enemy\n"); // ALERT( at_console, "%.0f %.2f %.2f %.2f\n", flVel, m_vecTarget.x, m_vecTarget.y, m_vecTarget.z ); pev->velocity = pev->velocity * flAdj + m_vecTarget * 300; } if( pev->flags & FL_ONGROUND ) { pev->avelocity = Vector( 0, 0, 0 ); } else { if( pev->avelocity == Vector( 0, 0, 0 ) ) { pev->avelocity.x = RANDOM_FLOAT( -100, 100 ); pev->avelocity.z = RANDOM_FLOAT( -100, 100 ); } } if( ( GetAbsOrigin() - m_posPrev ).Length() < 1.0 ) { pev->velocity.x = RANDOM_FLOAT( -100, 100 ); pev->velocity.y = RANDOM_FLOAT( -100, 100 ); } m_posPrev = GetAbsOrigin(); pev->angles = UTIL_VecToAngles( pev->velocity ); pev->angles.z = 0; pev->angles.x = 0; }
void CPlantedC4::C4Think() { if (!IsInWorld()) { UTIL_Remove( this ); return; } SetNextThink( gpGlobals->curtime + 0.12 ); if ( gpGlobals->curtime >= m_flNextFreq ) { m_flNextFreq = gpGlobals->curtime + m_flNextFreqInterval; m_flNextFreqInterval *= 0.9; m_iCurWave = clamp( m_iCurWave+1, 0, 5 ); } if ( gpGlobals->curtime >= m_flNextBeep ) { m_flNextBeep = gpGlobals->curtime + 1.4; // Play a beep sound. char soundName[64]; Q_snprintf( soundName, sizeof( soundName ), "c4.beep%d", m_iCurWave ); CPASAttenuationFilter filter( this ); EmitSound( filter, entindex(), soundName ); // let the bots hear the bomb beeping //g_pBotControl->OnEvent( EVENT_BOMB_BEEP, this ); } if(gpGlobals->curtime >= m_flNextBlink)//added by SupraFiend to improve Bomb visibility { m_flNextBlink = gpGlobals->curtime + BLINK_INTERVAL; Vector vPos = GetAbsOrigin(); vPos.z += 5; CPVSFilter filter( GetAbsOrigin() ); te->GlowSprite( filter, 0, &vPos, g_sModelIndexC4Glow, 1, 0.5, 255 ); } // IF the timer has expired ! blow this bomb up! if (m_flC4Blow <= gpGlobals->curtime) { // let the bots hear the bomb exploding //g_pBotControl->OnEvent( EVENT_BOMB_EXPLODED ); // Tell the bomb target brush to trigger its targets //MIKETODO: use entity IO? /* if ( m_pentCurBombTarget ) { CBaseEntity* pBombTarget = CBaseEntity::Instance( m_pentCurBombTarget ); if ( pBombTarget ) pBombTarget->Use( CBaseEntity::Instance( pev->owner ), this, USE_TOGGLE, 0 ); } */ // give the defuser credit for defusing the bomb CBasePlayer *pBombOwner = dynamic_cast< CBasePlayer* >( GetOwnerEntity() ); if ( pBombOwner ) { pBombOwner->IncrementFragCount( 3 ); } CSGameRules()->m_bBombDropped = false; if (GetWaterLevel() == 0) SetThink ( &CPlantedC4::Detonate2 ); else UTIL_Remove (this); // Get rid of this thing if it's underwater.. } //if the defusing process has started if ((m_bStartDefuse == true) && (m_pBombDefuser != NULL)) { //if the defusing process has not ended yet if ( m_flDefuseCountDown > gpGlobals->curtime) { int iOnGround = FBitSet( m_pBombDefuser->GetFlags(), FL_ONGROUND ); //if the bomb defuser has stopped defusing the bomb if( m_fNextDefuse < gpGlobals->curtime || !iOnGround ) { if ( !iOnGround ) ClientPrint( m_pBombDefuser, HUD_PRINTCENTER, "#C4_Defuse_Must_Be_On_Ground"); // release the player from being frozen m_pBombDefuser->ResetMaxSpeed(); m_pBombDefuser->m_bIsDefusing = false; //cancel the progress bar m_pBombDefuser->SetProgressBarTime( 0 ); m_pBombDefuser = NULL; m_bStartDefuse = false; m_flDefuseCountDown = 0; // tell the bots someone has aborted defusing //g_pBotControl->OnEvent( EVENT_BOMB_DEFUSE_ABORTED ); } return; } //if the defuse process has ended, kill the c4 else if ( !m_pBombDefuser->IsDead() ) { // tell the bots the bomb is defused //g_pBotControl->OnEvent( EVENT_BOMB_DEFUSED ); //MIKETODO: spectator /* // Broadcast to the entire server Broadcast( "BOMBDEF" ); // send director message, that something important happened here MESSAGE_BEGIN( MSG_SPEC, SVC_DIRECTOR ); WRITE_BYTE ( 9 ); WRITE_BYTE ( DRC_CMD_EVENT ); // bomb defuse WRITE_SHORT( ENTINDEX( m_pBombDefuser->edict() )); // index number of secondary entity WRITE_SHORT( 0 ); // index number of secondary entity WRITE_LONG( 15 | DRC_FLAG_DRAMATIC | DRC_FLAG_FINAL | DRC_FLAG_FACEPLAYER ); // eventflags (priority and flags) MESSAGE_END(); */ CPASAttenuationFilter filter( this ); EmitSound( filter, entindex(), "c4.disarmed" ); UTIL_Remove(this); // The bomb has just been disarmed.. Check to see if the round should end now m_bJustBlew = true; // release the player from being frozen m_pBombDefuser->ResetMaxSpeed(); m_pBombDefuser->m_bIsDefusing = false; CSGameRules()->m_bBombDefused = true; CSGameRules()->CheckWinConditions(); // give the defuser credit for defusing the bomb m_pBombDefuser->IncrementFragCount( 3 ); CSGameRules()->m_bBombDropped = false; // Clear their progress bar. m_pBombDefuser->SetProgressBarTime( 0 ); m_pBombDefuser = NULL; m_bStartDefuse = false; return; } //if it gets here then the previouse defuser has taken off or been killed // release the player from being frozen m_pBombDefuser->ResetMaxSpeed(); m_pBombDefuser->m_bIsDefusing = false; m_bStartDefuse = false; m_pBombDefuser = NULL; // tell the bots someone has aborted defusing //g_pBotControl->OnEvent( EVENT_BOMB_DEFUSE_ABORTED ); } }
void CLeech::UpdateMotion( void ) { float flapspeed = (pev->speed - m_flAccelerate) / LEECH_ACCELERATE; m_flAccelerate = m_flAccelerate * 0.8 + pev->speed * 0.2; if (flapspeed < 0) flapspeed = -flapspeed; flapspeed += 1.0; if (flapspeed < 0.5) flapspeed = 0.5; if (flapspeed > 1.9) flapspeed = 1.9; pev->framerate = flapspeed; if ( !m_fPathBlocked ) pev->avelocity.y = pev->ideal_yaw; else pev->avelocity.y = pev->ideal_yaw * m_obstacle; if ( pev->avelocity.y > 150 ) m_IdealActivity = ACT_TURN_LEFT; else if ( pev->avelocity.y < -150 ) m_IdealActivity = ACT_TURN_RIGHT; else m_IdealActivity = ACT_SWIM; // lean float targetPitch, delta; delta = m_height - GetAbsOrigin().z; if ( delta < -10 ) targetPitch = -30; else if ( delta > 10 ) targetPitch = 30; else targetPitch = 0; pev->angles.x = UTIL_Approach( targetPitch, pev->angles.x, 60 * LEECH_FRAMETIME ); // bank pev->avelocity.z = - (pev->angles.z + (pev->avelocity.y * 0.25)); if ( m_MonsterState == MONSTERSTATE_COMBAT && HasConditions( bits_COND_CAN_MELEE_ATTACK1 ) ) m_IdealActivity = ACT_MELEE_ATTACK1; // Out of water check if ( !GetWaterLevel() ) { pev->movetype = MOVETYPE_TOSS; m_IdealActivity = ACT_TWITCH; pev->velocity = g_vecZero; // Animation will intersect the floor if either of these is non-zero pev->angles.z = 0; pev->angles.x = 0; if ( pev->framerate < 1.0 ) pev->framerate = 1.0; } else if ( pev->movetype == MOVETYPE_TOSS ) { pev->movetype = MOVETYPE_FLY; pev->flags &= ~FL_ONGROUND; RecalculateWaterlevel(); m_waterTime = gpGlobals->time + 2; // Recalc again soon, water may be rising } if ( m_Activity != m_IdealActivity ) { SetActivity ( m_IdealActivity ); } float flInterval = StudioFrameAdvance(); DispatchAnimEvents ( flInterval ); #if DEBUG_BEAMS if ( !m_pb ) m_pb = CBeam::BeamCreate( "sprites/laserbeam.spr", 5 ); if ( !m_pt ) m_pt = CBeam::BeamCreate( "sprites/laserbeam.spr", 5 ); m_pb->PointsInit( GetAbsOrigin(), GetAbsOrigin() + gpGlobals->v_forward * LEECH_CHECK_DIST ); m_pt->PointsInit( GetAbsOrigin(), GetAbsOrigin() - gpGlobals->v_right * (pev->avelocity.y*0.25) ); if ( m_fPathBlocked ) { float color = m_obstacle * 30; if ( m_obstacle == 1.0 ) color = 0; if ( color > 255 ) color = 255; m_pb->SetColor( 255, (int)color, (int)color ); } else m_pb->SetColor( 255, 255, 0 ); m_pt->SetColor( 0, 0, 255 ); #endif }
void CBasePlayer::UpdateStepSound( surfacedata_t *psurface, const Vector &vecOrigin, const Vector &vecVelocity ) { bool bWalking; float fvol; Vector knee; Vector feet; float height; float speed; float velrun; float velwalk; int fLadder; if ( m_flStepSoundTime > 0 ) { m_flStepSoundTime -= 1000.0f * gpGlobals->frametime; if ( m_flStepSoundTime < 0 ) { m_flStepSoundTime = 0; } } if ( m_flStepSoundTime > 0 ) return; if ( GetFlags() & (FL_FROZEN|FL_ATCONTROLS)) return; if ( GetMoveType() == MOVETYPE_NOCLIP || GetMoveType() == MOVETYPE_OBSERVER ) return; if ( !sv_footsteps.GetFloat() ) return; speed = VectorLength( vecVelocity ); float groundspeed = Vector2DLength( vecVelocity.AsVector2D() ); // determine if we are on a ladder fLadder = ( GetMoveType() == MOVETYPE_LADDER ); GetStepSoundVelocities( &velwalk, &velrun ); bool onground = ( GetFlags() & FL_ONGROUND ); bool movingalongground = ( groundspeed > 0.0001f ); bool moving_fast_enough = ( speed >= velwalk ); #ifdef PORTAL // In Portal we MUST play footstep sounds even when the player is moving very slowly // This is used to count the number of footsteps they take in the challenge mode // -Jeep moving_fast_enough = true; #endif // To hear step sounds you must be either on a ladder or moving along the ground AND // You must be moving fast enough if ( !moving_fast_enough || !(fLadder || ( onground && movingalongground )) ) return; // MoveHelper()->PlayerSetAnimation( PLAYER_WALK ); bWalking = speed < velrun; VectorCopy( vecOrigin, knee ); VectorCopy( vecOrigin, feet ); height = GetPlayerMaxs()[ 2 ] - GetPlayerMins()[ 2 ]; knee[2] = vecOrigin[2] + 0.2 * height; // find out what we're stepping in or on... if ( fLadder ) { psurface = GetLadderSurface(vecOrigin); fvol = 0.5; SetStepSoundTime( STEPSOUNDTIME_ON_LADDER, bWalking ); } else if ( GetWaterLevel() == WL_Waist ) { static int iSkipStep = 0; if ( iSkipStep == 0 ) { iSkipStep++; return; } if ( iSkipStep++ == 3 ) { iSkipStep = 0; } psurface = physprops->GetSurfaceData( physprops->GetSurfaceIndex( "wade" ) ); fvol = 0.65; SetStepSoundTime( STEPSOUNDTIME_WATER_KNEE, bWalking ); } else if ( GetWaterLevel() == WL_Feet ) { psurface = physprops->GetSurfaceData( physprops->GetSurfaceIndex( "water" ) ); fvol = bWalking ? 0.2 : 0.5; SetStepSoundTime( STEPSOUNDTIME_WATER_FOOT, bWalking ); } else { if ( !psurface ) return; SetStepSoundTime( STEPSOUNDTIME_NORMAL, bWalking ); switch ( psurface->game.material ) { default: case CHAR_TEX_CONCRETE: fvol = bWalking ? 0.2 : 0.5; break; case CHAR_TEX_METAL: fvol = bWalking ? 0.2 : 0.5; break; case CHAR_TEX_DIRT: fvol = bWalking ? 0.25 : 0.55; break; case CHAR_TEX_VENT: fvol = bWalking ? 0.4 : 0.7; break; case CHAR_TEX_GRATE: fvol = bWalking ? 0.2 : 0.5; break; case CHAR_TEX_TILE: fvol = bWalking ? 0.2 : 0.5; break; case CHAR_TEX_SLOSH: fvol = bWalking ? 0.2 : 0.5; break; } } // play the sound // 65% volume if ducking if ( GetFlags() & FL_DUCKING ) { fvol *= 0.65; } PlayStepSound( feet, psurface, fvol, false ); }