Error CAutoResearch::StartAction(int param) { if ( m_phase != ALP_WAIT ) { return ERR_UNKNOWN; } m_research = static_cast<ResearchType>(param); if ( m_main->IsResearchDone(m_research, m_object->GetTeam()) ) { return ERR_RESEARCH_ALREADY; } if (m_object->GetPower() == nullptr || !m_object->GetPower()->Implements(ObjectInterfaceType::PowerContainer)) { return ERR_RESEARCH_POWER; } CPowerContainerObject* power = dynamic_cast<CPowerContainerObject*>(m_object->GetPower()); if ( power->GetCapacity() > 1.0f ) { return ERR_RESEARCH_TYPE; } if ( power->GetEnergy() < 1.0f ) { return ERR_RESEARCH_ENERGY; } float time = SEARCH_TIME; if ( m_research == RESEARCH_TANK ) time *= 0.3f; if ( m_research == RESEARCH_FLY ) time *= 0.3f; if ( m_research == RESEARCH_ATOMIC ) time *= 2.0f; SetBusy(true); InitProgressTotal(time); UpdateInterface(); m_channelSound = m_sound->Play(SOUND_RESEARCH, m_object->GetPosition(), 0.0f, 1.0f, true); m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, 2.0f, SOPER_CONTINUE); m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, time-4.0f, SOPER_CONTINUE); m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 2.0f, SOPER_STOP); m_phase = ALP_SEARCH; m_progress = 0.0f; m_speed = 1.0f/time; return ERR_OK; }
Error CAutoFactory::StartAction(int param) { CObject* cargo; ObjectType type = static_cast<ObjectType>(param); if ( type != OBJECT_NULL ) { if ( m_phase != AFP_WAIT ) { return ERR_OK; } m_type = type; cargo = SearchCargo(); // transform metal? if ( cargo == nullptr ) { return ERR_FACTORY_NULL; } if ( NearestVehicle() ) { return ERR_FACTORY_NEAR; } m_program = ""; SetBusy(true); InitProgressTotal(3.0f+2.0f+15.0f+2.0f+3.0f); UpdateInterface(); cargo->SetLock(true); // usable metal SoundManip(3.0f, 1.0f, 0.5f); m_phase = AFP_CLOSE_S; m_progress = 0.0f; m_speed = 1.0f/3.0f; return ERR_OK; } return ERR_UNKNOWN; }
bool CAutoConvert::EventProcess(const Event &event) { CObject* cargo; Math::Vector pos, speed; Math::Point dim, c, p; float angle; CAuto::EventProcess(event); if ( m_engine->GetPause() ) return true; if ( event.type != EVENT_FRAME ) return true; m_progress += event.rTime*m_speed; m_timeVirus -= event.rTime; if ( m_object->GetVirusMode() ) // contaminated by a virus? { if ( m_timeVirus <= 0.0f ) { m_timeVirus = 0.1f+Math::Rand()*0.3f; angle = (Math::Rand()-0.5f)*0.3f; m_object->SetPartRotationY(1, angle); m_object->SetPartRotationY(2, angle); m_object->SetPartRotationY(3, angle+Math::PI); m_object->SetPartRotationX(2, -Math::PI*0.35f*(0.8f+Math::Rand()*0.2f)); m_object->SetPartRotationX(3, -Math::PI*0.35f*(0.8f+Math::Rand()*0.2f)); } return true; } EventProgress(event.rTime); if ( m_phase == ACP_STOP ) return true; if ( m_phase == ACP_WAIT ) { if ( m_progress >= 1.0f ) { cargo = SearchStone(OBJECT_STONE); // Has stone transformed? if ( cargo == nullptr || SearchVehicle() ) { m_phase = ACP_WAIT; // still waiting ... m_progress = 0.0f; m_speed = 1.0f/2.0f; } else { cargo->SetLock(true); // stone usable SetBusy(true); InitProgressTotal(3.0f+10.0f+1.5f); UpdateInterface(); m_sound->Play(SOUND_OPEN, m_object->GetPosition(), 1.0f, 1.0f); m_bSoundClose = false; m_phase = ACP_CLOSE; m_progress = 0.0f; m_speed = 1.0f/3.0f; } } } if ( m_phase == ACP_CLOSE ) { if ( m_progress < 1.0f ) { if ( m_progress >= 0.8f && !m_bSoundClose ) { m_bSoundClose = true; m_sound->Play(SOUND_CLOSE, m_object->GetPosition(), 1.0f, 0.8f); } angle = -Math::PI*0.35f*(1.0f-Math::Bounce(m_progress, 0.85f, 0.05f)); m_object->SetPartRotationX(2, angle); m_object->SetPartRotationX(3, angle); } else { m_object->SetPartRotationX(2, 0.0f); m_object->SetPartRotationX(3, 0.0f); m_soundChannel = m_sound->Play(SOUND_CONVERT, m_object->GetPosition(), 0.0f, 0.25f, true); m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.25f, 0.5f, SOPER_CONTINUE); m_sound->AddEnvelope(m_soundChannel, 1.0f, 1.00f, 4.5f, SOPER_CONTINUE); m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.25f, 4.5f, SOPER_CONTINUE); m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.25f, 0.5f, SOPER_STOP); m_phase = ACP_ROTATE; m_progress = 0.0f; m_speed = 1.0f/10.0f; } } if ( m_phase == ACP_ROTATE ) { if ( m_progress < 1.0f ) { if ( m_progress < 0.5f ) { angle = powf((m_progress*2.0f)*5.0f, 2.0f); // accelerates } else { angle = -powf((2.0f-m_progress*2.0f)*5.0f, 2.0f); // slows } m_object->SetPartRotationY(1, angle); m_object->SetPartRotationY(2, angle); m_object->SetPartRotationY(3, angle+Math::PI); if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time ) { m_lastParticle = m_time; pos = m_object->GetPosition(); c.x = pos.x; c.y = pos.z; p.x = c.x; p.y = c.y+6.0f; p = Math::RotatePoint(c, Math::Rand()*Math::PI*2.0f, p); pos.x = p.x; pos.z = p.y; pos.y += 1.0f; speed = Math::Vector(0.0f, 0.0f, 0.0f); dim.x = Math::Rand()*2.0f+1.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 1.0f, 0.0f, 0.0f); } } else { m_object->SetPartRotationY(1, 0.0f); m_object->SetPartRotationY(2, 0.0f); m_object->SetPartRotationY(3, Math::PI); cargo = SearchStone(OBJECT_STONE); if ( cargo != nullptr ) { CObjectManager::GetInstancePointer()->DeleteObject(cargo); } CreateMetal(); // Create the metal m_sound->Play(SOUND_OPEN, m_object->GetPosition(), 1.0f, 1.5f); m_phase = ACP_OPEN; m_progress = 0.0f; m_speed = 1.0f/1.5f; } } if ( m_phase == ACP_OPEN ) { if ( m_progress < 1.0f ) { angle = -Math::PI*0.35f*Math::Bounce(m_progress, 0.7f, 0.2f); m_object->SetPartRotationX(2, angle); m_object->SetPartRotationX(3, angle); if ( m_progress < 0.9f && m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time ) { m_lastParticle = m_time; pos = m_object->GetPosition(); pos.x += (Math::Rand()-0.5f)*6.0f; pos.z += (Math::Rand()-0.5f)*6.0f; pos.y += Math::Rand()*4.0f; speed = Math::Vector(0.0f, 0.0f, 0.0f); dim.x = Math::Rand()*4.0f+3.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLUE, 1.0f, 0.0f, 0.0f); } } else { m_soundChannel = -1; m_object->SetPartRotationX(2, -Math::PI*0.35f); m_object->SetPartRotationX(3, -Math::PI*0.35f); SetBusy(false); UpdateInterface(); m_phase = ACP_WAIT; m_progress = 0.0f; m_speed = 1.0f/2.0f; } } return true; }
bool CAutoNuclear::EventProcess(const Event &event) { CObject* fret; Math::Matrix* mat; Math::Vector pos, goal, speed; Math::Point dim, rot; float angle; int i, max; CAuto::EventProcess(event); if ( m_engine->GetPause() ) return true; if ( event.type != EVENT_FRAME ) return true; m_progress += event.rTime*m_speed; m_timeVirus -= event.rTime; if ( m_object->GetVirusMode() ) // contaminated by a virus? { if ( m_timeVirus <= 0.0f ) { m_timeVirus = 0.1f+Math::Rand()*0.3f; } return true; } EventProgress(event.rTime); if ( m_phase == ANUP_WAIT ) { if ( m_progress >= 1.0f ) { fret = SearchUranium(); // transform uranium? if ( fret == 0 || SearchVehicle() ) { m_phase = ANUP_WAIT; // still waiting ... m_progress = 0.0f; m_speed = 1.0f/2.0f; } else { fret->SetLock(true); // usable uranium SetBusy(true); InitProgressTotal(1.5f+NUCLEAR_DELAY+1.5f); UpdateInterface(); m_sound->Play(SOUND_OPEN, m_object->GetPosition(0), 1.0f, 1.4f); m_phase = ANUP_CLOSE; m_progress = 0.0f; m_speed = 1.0f/1.5f; } } } if ( m_phase == ANUP_CLOSE ) { if ( m_progress < 1.0f ) { angle = (1.0f-m_progress)*(135.0f*Math::PI/180.0f); m_object->SetAngleZ(1, angle); } else { m_object->SetAngleZ(1, 0.0f); mat = m_object->GetWorldMatrix(0); max = static_cast< int >(10.0f*m_engine->GetParticleDensity()); for ( i=0 ; i<max ; i++ ) { pos.x = 27.0f; pos.y = 0.0f; pos.z = (Math::Rand()-0.5f)*8.0f; pos = Transform(*mat, pos); speed.y = 0.0f; speed.x = 0.0f; speed.z = 0.0f; dim.x = Math::Rand()*1.0f+1.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH); } m_sound->Play(SOUND_CLOSE, m_object->GetPosition(0), 1.0f, 1.0f); m_channelSound = m_sound->Play(SOUND_NUCLEAR, m_object->GetPosition(0), 1.0f, 0.1f, true); m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, NUCLEAR_DELAY-1.0f, SOPER_CONTINUE); m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 2.0f, SOPER_STOP); m_phase = ANUP_GENERATE; m_progress = 0.0f; m_speed = 1.0f/NUCLEAR_DELAY; } } if ( m_phase == ANUP_GENERATE ) { if ( m_progress < 1.0f ) { if ( m_lastParticle+m_engine->ParticleAdapt(0.10f) <= m_time ) { m_lastParticle = m_time; pos = m_object->GetPosition(0); pos.y += 30.0f; pos.x += (Math::Rand()-0.5f)*6.0f; pos.z += (Math::Rand()-0.5f)*6.0f; speed.y = Math::Rand()*15.0f+15.0f; speed.x = 0.0f; speed.z = 0.0f; dim.x = Math::Rand()*8.0f+8.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH); pos = m_pos; speed.x = (Math::Rand()-0.5f)*20.0f; speed.y = (Math::Rand()-0.5f)*20.0f; speed.z = (Math::Rand()-0.5f)*20.0f; dim.x = 2.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ, 1.0f, 0.0f, 0.0f); } } else { fret = SearchUranium(); if ( fret != 0 ) { fret->DeleteObject(); // destroyed uranium delete fret; m_object->SetPower(0); } CreatePower(); // creates the atomic cell max = static_cast< int >(20.0f*m_engine->GetParticleDensity()); for ( i=0 ; i<max ; i++ ) { pos = m_pos; pos.x += (Math::Rand()-0.5f)*3.0f; pos.y += (Math::Rand()-0.5f)*3.0f; pos.z += (Math::Rand()-0.5f)*3.0f; speed.y = 0.0f; speed.x = 0.0f; speed.z = 0.0f; dim.x = Math::Rand()*2.0f+2.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLUE, Math::Rand()*5.0f+5.0f, 0.0f, 0.0f); } m_sound->Play(SOUND_OPEN, m_object->GetPosition(0), 1.0f, 1.4f); m_phase = ANUP_OPEN; m_progress = 0.0f; m_speed = 1.0f/1.5f; } } if ( m_phase == ANUP_OPEN ) { if ( m_progress < 1.0f ) { angle = m_progress*(135.0f*Math::PI/180.0f); m_object->SetAngleZ(1, angle); } else { m_object->SetAngleZ(1, 135.0f*Math::PI/180.0f); SetBusy(false); UpdateInterface(); m_main->DisplayError(INFO_NUCLEAR, m_object); m_phase = ANUP_WAIT; m_progress = 0.0f; m_speed = 1.0f/2.0f; } } return true; }