bool CLightning::EventFrame(const Event &event) { if (m_terrain == nullptr) m_terrain = CRobotMain::GetInstancePointer()->GetTerrain(); if (m_camera == nullptr) m_camera = CRobotMain::GetInstancePointer()->GetCamera(); if (m_sound == nullptr) m_sound = CApplication::GetInstancePointer()->GetSound(); if (m_engine->GetPause()) return true; if (CRobotMain::GetInstancePointer()->GetMovieLock()) return true; m_progress += event.rTime*m_speed; if (m_phase == LightningPhase::Wait && m_lightningExists) { if (m_progress >= 1.0f) { m_pos.x = (Math::Rand()-0.5f)*(3200.0f-200.0f); m_pos.z = (Math::Rand()-0.5f)*(3200.0f-200.0f); m_pos.y = 0.0f; CObject* obj = SearchObject(m_pos); if (obj == nullptr) { m_terrain->AdjustToFloor(m_pos, true); } else { m_pos = obj->GetPosition(); m_terrain->AdjustToFloor(m_pos, true); // TODO: CLightningConductorObject ObjectType type = obj->GetType(); if (type == OBJECT_BASE) { m_pos.y += 120.0f; // top of the rocket } else if (type == OBJECT_PARA) { CAutoPowerCaptor* automat = static_cast<CAutoPowerCaptor*>(obj->GetAuto()); if (automat != nullptr) automat->StartLightning(); m_pos.y += 67.0f; // top of lightning rod } else { assert(obj->Implements(ObjectInterfaceType::Destroyable)); dynamic_cast<CDestroyableObject*>(obj)->DamageObject(DamageType::Lightning); } } StrikeAtPos(m_pos); } } if (m_phase == LightningPhase::Flash) { if (m_progress < 1.0f) { float max = 5.0f; for (std::size_t i = 0; i < m_segments.size(); i++) { max += 0.4f; m_segments[i].shift.x += (Math::Rand()-0.5f)*max*2.0f; if ( m_segments[i].shift.x < -max ) m_segments[i].shift.x = -max; if ( m_segments[i].shift.x > max ) m_segments[i].shift.x = max; m_segments[i].shift.y += (Math::Rand()-0.5f)*max*2.0f; if ( m_segments[i].shift.y < -max ) m_segments[i].shift.y = -max; if ( m_segments[i].shift.y > max ) m_segments[i].shift.y = max; m_segments[i].width += (Math::Rand()-0.5f)*2.0f; if ( m_segments[i].width < 1.0f ) m_segments[i].width = 1.0f; if ( m_segments[i].width > 6.0f ) m_segments[i].width = 6.0f; } m_segments[0].shift.x = 0.0f; m_segments[0].shift.y = 0.0f; m_segments[0].width = 0.0f; } else { m_phase = LightningPhase::Wait; m_progress = 0.0f; m_speed = 1.0f / (1.0f+Math::Rand()*m_delay); } } return true; }
bool CLightning::EventFrame(const Event &event) { if (m_engine->GetPause()) return true; if (CRobotMain::GetInstancePointer()->GetMovieLock()) return true; m_progress += event.rTime*m_speed; if (m_phase == LightningPhase::Wait) { if (m_progress >= 1.0f) { m_pos.x = (Math::Rand()-0.5f)*(3200.0f-200.0f); m_pos.z = (Math::Rand()-0.5f)*(3200.0f-200.0f); m_pos.y = 0.0f; CObject* obj = SearchObject(m_pos); if (obj == nullptr) { m_terrain->AdjustToFloor(m_pos, true); } else { m_pos = obj->GetPosition(); m_terrain->AdjustToFloor(m_pos, true); // TODO: CLightningConductorObject ObjectType type = obj->GetType(); if (type == OBJECT_BASE) { m_pos.y += 120.0f; // top of the rocket } else if (type == OBJECT_PARA) { CAutoPowerCaptor* automat = static_cast<CAutoPowerCaptor*>(obj->GetAuto()); if (automat != nullptr) automat->StartLightning(); m_pos.y += 67.0f; // top of lightning rod } else { assert(obj->Implements(ObjectInterfaceType::Destroyable)); dynamic_cast<CDestroyableObject*>(obj)->DamageObject(DamageType::Lightning); } } Math::Vector eye = m_engine->GetEyePt(); float dist = Math::Distance(m_pos, eye); float deep = m_engine->GetDeepView(); if (dist < deep) { Math::Vector pos = eye+((m_pos-eye)*0.2f); // like so close! m_sound->Play(SOUND_BLITZ, pos); m_camera->StartOver(CAM_OVER_EFFECT_LIGHTNING, m_pos, 1.0f); m_phase = LightningPhase::Flash; m_progress = 0.0f; m_speed = 1.0f; } } } if (m_phase == LightningPhase::Flash) { if (m_progress < 1.0f) { float max = 5.0f; for (std::size_t i = 0; i < m_segments.size(); i++) { max += 0.4f; m_segments[i].shift.x += (Math::Rand()-0.5f)*max*2.0f; if ( m_segments[i].shift.x < -max ) m_segments[i].shift.x = -max; if ( m_segments[i].shift.x > max ) m_segments[i].shift.x = max; m_segments[i].shift.y += (Math::Rand()-0.5f)*max*2.0f; if ( m_segments[i].shift.y < -max ) m_segments[i].shift.y = -max; if ( m_segments[i].shift.y > max ) m_segments[i].shift.y = max; m_segments[i].width += (Math::Rand()-0.5f)*2.0f; if ( m_segments[i].width < 1.0f ) m_segments[i].width = 1.0f; if ( m_segments[i].width > 6.0f ) m_segments[i].width = 6.0f; } m_segments[0].shift.x = 0.0f; m_segments[0].shift.y = 0.0f; m_segments[0].width = 0.0f; } else { m_phase = LightningPhase::Wait; m_progress = 0.0f; m_speed = 1.0f / (1.0f+Math::Rand()*m_delay); } } return true; }