bool CAutoFactory::EventProcess(const Event &event) { ObjectType type; CObject* fret; CObject* vehicle; Math::Matrix* mat; CPhysics* physics; Math::Vector pos, speed; Math::Point dim; float zoom, angle, prog; int i; CAuto::EventProcess(event); if ( m_engine->GetPause() ) return true; if ( m_object->GetSelect() ) // factory selected? { if ( event.type == EVENT_UPDINTERFACE ) { CreateInterface(true); } type = OBJECT_NULL; if ( event.type == EVENT_OBJECT_FACTORYwa ) type = OBJECT_MOBILEwa; if ( event.type == EVENT_OBJECT_FACTORYta ) type = OBJECT_MOBILEta; if ( event.type == EVENT_OBJECT_FACTORYfa ) type = OBJECT_MOBILEfa; if ( event.type == EVENT_OBJECT_FACTORYia ) type = OBJECT_MOBILEia; if ( event.type == EVENT_OBJECT_FACTORYws ) type = OBJECT_MOBILEws; if ( event.type == EVENT_OBJECT_FACTORYts ) type = OBJECT_MOBILEts; if ( event.type == EVENT_OBJECT_FACTORYfs ) type = OBJECT_MOBILEfs; if ( event.type == EVENT_OBJECT_FACTORYis ) type = OBJECT_MOBILEis; if ( event.type == EVENT_OBJECT_FACTORYwc ) type = OBJECT_MOBILEwc; if ( event.type == EVENT_OBJECT_FACTORYtc ) type = OBJECT_MOBILEtc; if ( event.type == EVENT_OBJECT_FACTORYfc ) type = OBJECT_MOBILEfc; if ( event.type == EVENT_OBJECT_FACTORYic ) type = OBJECT_MOBILEic; if ( event.type == EVENT_OBJECT_FACTORYwi ) type = OBJECT_MOBILEwi; if ( event.type == EVENT_OBJECT_FACTORYti ) type = OBJECT_MOBILEti; if ( event.type == EVENT_OBJECT_FACTORYfi ) type = OBJECT_MOBILEfi; if ( event.type == EVENT_OBJECT_FACTORYii ) type = OBJECT_MOBILEii; if ( event.type == EVENT_OBJECT_FACTORYrt ) type = OBJECT_MOBILErt; if ( event.type == EVENT_OBJECT_FACTORYrc ) type = OBJECT_MOBILErc; if ( event.type == EVENT_OBJECT_FACTORYrr ) type = OBJECT_MOBILErr; if ( event.type == EVENT_OBJECT_FACTORYrs ) type = OBJECT_MOBILErs; if ( event.type == EVENT_OBJECT_FACTORYsa ) type = OBJECT_MOBILEsa; Error err = StartAction(type); if( err != ERR_OK && err != ERR_GENERIC ) m_displayText->DisplayError(err, m_object); if( err != ERR_GENERIC ) return false; } if ( event.type != EVENT_FRAME ) return true; m_progress += event.rTime*m_speed; EventProgress(event.rTime); if ( m_phase == AFP_WAIT ) { if ( m_progress >= 1.0f ) { m_phase = AFP_WAIT; // still waiting ... m_progress = 0.0f; m_speed = 1.0f/2.0f; } } if ( m_phase == AFP_CLOSE_S ) { if ( m_progress < 1.0f ) { for ( i=0 ; i<9 ; i++ ) { zoom = 0.30f+(m_progress-0.5f+i/16.0f)*2.0f*0.70f; if ( zoom < 0.30f ) zoom = 0.30f; if ( zoom > 1.00f ) zoom = 1.00f; m_object->SetZoomZ( 1+i, zoom); m_object->SetZoomZ(10+i, zoom); } } else { for ( i=0 ; i<9 ; i++ ) { m_object->SetZoomZ( 1+i, 1.0f); m_object->SetZoomZ(10+i, 1.0f); } SoundManip(2.0f, 1.0f, 1.2f); m_phase = AFP_CLOSE_T; m_progress = 0.0f; m_speed = 1.0f/2.0f; } } if ( m_phase == AFP_CLOSE_T ) { if ( m_progress < 1.0f ) { for ( i=0 ; i<9 ; i++ ) { angle = -m_progress*(Math::PI/2.0f)+Math::PI/2.0f; m_object->SetAngleZ( 1+i, angle); m_object->SetAngleZ(10+i, -angle); } } else { for ( i=0 ; i<9 ; i++ ) { m_object->SetAngleZ( 1+i, 0.0f); m_object->SetAngleZ(10+i, 0.0f); } m_channelSound = m_sound->Play(SOUND_FACTORY, m_object->GetPosition(0), 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, 11.0f, SOPER_CONTINUE); m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 2.0f, SOPER_STOP); m_phase = AFP_BUILD; m_progress = 0.0f; m_speed = 1.0f/15.0f; } } if ( m_phase == AFP_BUILD ) { if ( m_progress == 0.0f ) { if ( !CreateVehicle() ) { fret = SearchFret(); // transform metal? if ( fret != 0 ) { fret->SetLock(false); // metal usable again } if ( m_channelSound != -1 ) { m_sound->FlushEnvelope(m_channelSound); m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 1.0f, SOPER_STOP); m_channelSound = -1; } m_phase = AFP_OPEN_T; m_progress = 0.0f; m_speed = 1.0f/2.0f; return true; } } if ( m_progress < 1.0f ) { if ( m_type == OBJECT_MOBILErt || m_type == OBJECT_MOBILErc || m_type == OBJECT_MOBILErr || m_type == OBJECT_MOBILErs ) { prog = 1.0f-m_progress*1.5f; if ( prog < 0.0f ) prog = 0.0f; } else { prog = 1.0f-m_progress; } angle = powf(prog*10.0f, 2.0f)+m_object->GetAngleY(0); vehicle = SearchVehicle(); if ( vehicle != 0 ) { vehicle->SetAngleY(0, angle+Math::PI); vehicle->SetZoom(0, m_progress); } fret = SearchFret(); // transform metal? if ( fret != 0 ) { fret->SetZoom(0, 1.0f-m_progress); } if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time ) { m_lastParticle = m_time; #if 0 pos = m_fretPos; pos.x += (Math::Rand()-0.5f)*20.0f; pos.z += (Math::Rand()-0.5f)*20.0f; pos.y += 1.0f; speed.x = (Math::Rand()-0.5f)*12.0f; speed.z = (Math::Rand()-0.5f)*12.0f; speed.y = Math::Rand()*12.0f; dim.x = Math::Rand()*12.0f+10.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, PARTIBLUE, 1.0f, 0.0f, 0.0f); #else mat = m_object->GetWorldMatrix(0); pos = Math::Vector(-12.0f, 20.0f, -4.0f); // position of chimney pos = Math::Transform(*mat, pos); pos.y += 2.0f; pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f; speed.x = 0.0f; speed.z = 0.0f; speed.y = 6.0f+Math::Rand()*6.0f; dim.x = Math::Rand()*1.5f+1.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISMOKE3, 4.0f); #endif } } else { m_displayText->DisplayError(INFO_FACTORY, m_object); SoundManip(2.0f, 1.0f, 1.2f); fret = SearchFret(); // transform metal? if ( fret != 0 ) { fret->DeleteObject(); // removes the metal delete fret; } m_vehicle = vehicle = SearchVehicle(); if ( vehicle != 0 ) { physics = vehicle->GetPhysics(); if ( physics != 0 ) { physics->SetFreeze(false); // can move } vehicle->SetLock(false); // vehicle useable //? vehicle->GetPhysics()->GetBrain()->StartTaskAdvance(16.0f); vehicle->SetAngleY(0, m_object->GetAngleY(0)+Math::PI); vehicle->SetZoom(0, 1.0f); } m_main->CreateShortcuts(); m_phase = AFP_OPEN_T; m_progress = 0.0f; m_speed = 1.0f/2.0f; } } if ( m_phase == AFP_OPEN_T ) { if ( m_progress < 1.0f ) { for ( i=0 ; i<9 ; i++ ) { angle = -(1.0f-m_progress)*(Math::PI/2.0f)+Math::PI/2.0f; m_object->SetAngleZ( 1+i, angle); m_object->SetAngleZ(10+i, -angle); } if ( m_lastParticle+m_engine->ParticleAdapt(0.1f) <= m_time ) { m_lastParticle = m_time; pos = m_fretPos; pos.x += (Math::Rand()-0.5f)*10.0f; pos.z += (Math::Rand()-0.5f)*10.0f; pos.y += Math::Rand()*10.0f; speed = Math::Vector(0.0f, 0.0f, 0.0f); dim.x = 2.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 2.0f, 0.0f, 0.0f); } } else { for ( i=0 ; i<9 ; i++ ) { m_object->SetAngleZ( 1+i, Math::PI/2.0f); m_object->SetAngleZ(10+i, -Math::PI/2.0f); } SoundManip(3.0f, 1.0f, 0.5f); m_phase = AFP_OPEN_S; m_progress = 0.0f; m_speed = 1.0f/3.0f; } } if ( m_phase == AFP_OPEN_S ) { if ( m_progress < 1.0f ) { for ( i=0 ; i<9 ; i++ ) { zoom = 0.30f+((1.0f-m_progress)-0.5f+i/16.0f)*2.0f*0.70f; if ( zoom < 0.30f ) zoom = 0.30f; if ( zoom > 1.00f ) zoom = 1.00f; m_object->SetZoomZ( 1+i, zoom); m_object->SetZoomZ(10+i, zoom); } if ( m_lastParticle+m_engine->ParticleAdapt(0.1f) <= m_time ) { m_lastParticle = m_time; pos = m_fretPos; pos.x += (Math::Rand()-0.5f)*10.0f; pos.z += (Math::Rand()-0.5f)*10.0f; pos.y += Math::Rand()*10.0f; speed = Math::Vector(0.0f, 0.0f, 0.0f); dim.x = 2.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 2.0f, 0.0f, 0.0f); } } else { for ( i=0 ; i<9 ; i++ ) { m_object->SetZoomZ( 1+i, 0.30f); m_object->SetZoomZ(10+i, 0.30f); } if ( m_program != nullptr ) { CBrain* brain = m_vehicle->GetBrain(); if ( brain != nullptr ) { brain->SendProgram(0, const_cast<const char*>(m_program)); brain->SetScriptRun(0); brain->RunProgram(0); } } SetBusy(false); UpdateInterface(); m_phase = AFP_WAIT; m_progress = 0.0f; m_speed = 1.0f/2.0f; } } return true; }
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 CAutoResearch::EventProcess(const Event &event) { CPowerContainerObject* power; Math::Vector pos, speed; Error message; Math::Point dim; float angle; CAuto::EventProcess(event); if ( m_engine->GetPause() ) return true; if ( event.type == EVENT_UPDINTERFACE ) { if ( m_object->GetSelect() ) CreateInterface(true); } if ( m_object->GetSelect() ) // center selected? { Error err = ERR_UNKNOWN; if ( event.type == EVENT_OBJECT_RTANK ) err = StartAction(RESEARCH_TANK); if ( event.type == EVENT_OBJECT_RFLY ) err = StartAction(RESEARCH_FLY); if ( event.type == EVENT_OBJECT_RTHUMP ) err = StartAction(RESEARCH_THUMP); if ( event.type == EVENT_OBJECT_RCANON ) err = StartAction(RESEARCH_CANON); if ( event.type == EVENT_OBJECT_RTOWER ) err = StartAction(RESEARCH_TOWER); if ( event.type == EVENT_OBJECT_RPHAZER ) err = StartAction(RESEARCH_PHAZER); if ( event.type == EVENT_OBJECT_RSHIELD ) err = StartAction(RESEARCH_SHIELD); if ( event.type == EVENT_OBJECT_RATOMIC ) err = StartAction(RESEARCH_ATOMIC); if( err != ERR_OK && err != ERR_UNKNOWN ) m_main->DisplayError(err, m_object); if( err != ERR_UNKNOWN ) return false; } 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; } UpdateInterface(event.rTime); EventProgress(event.rTime); angle = m_time*0.1f; m_object->SetPartRotationY(1, angle); // rotates the antenna angle = (30.0f+sinf(m_time*0.3f)*20.0f)*Math::PI/180.0f; m_object->SetPartRotationZ(2, angle); // directs the antenna if ( m_phase == ALP_WAIT ) { FireStopUpdate(m_progress, false); // extinguished return true; } if ( m_phase == ALP_SEARCH ) { FireStopUpdate(m_progress, true); // flashes if ( m_progress < 1.0f ) { if ( m_object->GetPower() == nullptr || !m_object->GetPower()->Implements(ObjectInterfaceType::PowerContainer) ) // more battery? { SetBusy(false); UpdateInterface(); m_phase = ALP_WAIT; m_progress = 0.0f; m_speed = 1.0f/1.0f; return true; } power = dynamic_cast<CPowerContainerObject*>(m_object->GetPower()); power->SetEnergyLevel(1.0f-m_progress); if ( 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 += 11.0f; speed.x = (Math::Rand()-0.5f)*2.0f; speed.z = (Math::Rand()-0.5f)*2.0f; speed.y = Math::Rand()*20.0f; dim.x = Math::Rand()*1.0f+1.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIVAPOR); } } else { m_main->MarkResearchDone(m_research, m_object->GetTeam()); // research done m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE)); UpdateInterface(); m_main->DisplayError(INFO_RESEARCH, m_object); message = ERR_OK; if ( m_research == RESEARCH_TANK ) message = INFO_RESEARCHTANK; if ( m_research == RESEARCH_FLY ) message = INFO_RESEARCHFLY; if ( m_research == RESEARCH_THUMP ) message = INFO_RESEARCHTHUMP; if ( m_research == RESEARCH_CANON ) message = INFO_RESEARCHCANON; if ( m_research == RESEARCH_TOWER ) message = INFO_RESEARCHTOWER; if ( m_research == RESEARCH_PHAZER ) message = INFO_RESEARCHPHAZER; if ( m_research == RESEARCH_SHIELD ) message = INFO_RESEARCHSHIELD; if ( m_research == RESEARCH_ATOMIC ) message = INFO_RESEARCHATOMIC; if ( message != ERR_OK ) { m_main->DisplayError(message, m_object); } SetBusy(false); UpdateInterface(); m_phase = ALP_WAIT; m_progress = 0.0f; m_speed = 1.0f/1.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; }
bool CAutoFactory::EventProcess(const Event &event) { ObjectType type; CObject* cargo; CObject* vehicle; Math::Matrix* mat; CPhysics* physics; Math::Vector pos, speed; Math::Point dim; float zoom, angle, prog; int i; CAuto::EventProcess(event); if ( m_engine->GetPause() ) return true; if ( m_object->GetSelect() ) // factory selected? { if ( event.type == EVENT_UPDINTERFACE ) { CreateInterface(true); } type = ObjectTypeFromFactoryButton(event.type); Error err = StartAction(type); if( err != ERR_OK && err != ERR_UNKNOWN ) m_main->DisplayError(err, m_object); if( err != ERR_UNKNOWN ) return false; } if ( event.type != EVENT_FRAME ) return true; m_progress += event.rTime*m_speed; EventProgress(event.rTime); if ( m_phase == AFP_WAIT ) { if ( m_progress >= 1.0f ) { m_phase = AFP_WAIT; // still waiting ... m_progress = 0.0f; m_speed = 1.0f/2.0f; } } if ( m_phase == AFP_CLOSE_S ) { if ( m_progress < 1.0f ) { for ( i=0 ; i<9 ; i++ ) { zoom = 0.30f+(m_progress-0.5f+i/16.0f)*2.0f*0.70f; if ( zoom < 0.30f ) zoom = 0.30f; if ( zoom > 1.00f ) zoom = 1.00f; m_object->SetPartScaleZ( 1+i, zoom); m_object->SetPartScaleZ(10+i, zoom); } } else { for ( i=0 ; i<9 ; i++ ) { m_object->SetPartScaleZ( 1+i, 1.0f); m_object->SetPartScaleZ(10+i, 1.0f); } SoundManip(2.0f, 1.0f, 1.2f); m_phase = AFP_CLOSE_T; m_progress = 0.0f; m_speed = 1.0f/2.0f; } } if ( m_phase == AFP_CLOSE_T ) { if ( m_progress < 1.0f ) { for ( i=0 ; i<9 ; i++ ) { angle = -m_progress*(Math::PI/2.0f)+Math::PI/2.0f; m_object->SetPartRotationZ( 1+i, angle); m_object->SetPartRotationZ(10+i, -angle); } } else { for ( i=0 ; i<9 ; i++ ) { m_object->SetPartRotationZ( 1+i, 0.0f); m_object->SetPartRotationZ(10+i, 0.0f); } m_channelSound = m_sound->Play(SOUND_FACTORY, 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, 11.0f, SOPER_CONTINUE); m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 2.0f, SOPER_STOP); m_phase = AFP_BUILD; m_progress = 0.0f; m_speed = 1.0f/15.0f; } } if ( m_phase == AFP_BUILD ) { if ( m_progress == 0.0f ) { if ( !CreateVehicle() ) { cargo = SearchCargo(); // transform metal? if ( cargo != nullptr ) { cargo->SetLock(false); // metal usable again } if ( m_channelSound != -1 ) { m_sound->FlushEnvelope(m_channelSound); m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 1.0f, SOPER_STOP); m_channelSound = -1; } m_phase = AFP_OPEN_T; m_progress = 0.0f; m_speed = 1.0f/2.0f; return true; } } if ( m_progress < 1.0f ) { if ( m_type == OBJECT_MOBILErt || m_type == OBJECT_MOBILErc || m_type == OBJECT_MOBILErr || m_type == OBJECT_MOBILErs ) { prog = 1.0f-m_progress*1.5f; if ( prog < 0.0f ) prog = 0.0f; } else { prog = 1.0f-m_progress; } angle = powf(prog*10.0f, 2.0f)+m_object->GetRotationY(); vehicle = SearchVehicle(); if ( vehicle != nullptr ) { vehicle->SetRotationY(angle+Math::PI); vehicle->SetScale(m_progress); } cargo = SearchCargo(); // transform metal? if ( cargo != nullptr ) { cargo->SetScale(1.0f-m_progress); } if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time ) { m_lastParticle = m_time; mat = m_object->GetWorldMatrix(0); pos = Math::Vector(-12.0f, 20.0f, -4.0f); // position of chimney pos = Math::Transform(*mat, pos); pos.y += 2.0f; pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f; speed.x = 0.0f; speed.z = 0.0f; speed.y = 6.0f+Math::Rand()*6.0f; dim.x = Math::Rand()*1.5f+1.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISMOKE3, 4.0f); } } else { m_main->DisplayError(INFO_FACTORY, m_object); SoundManip(2.0f, 1.0f, 1.2f); cargo = SearchCargo(); // transform metal? if ( cargo != nullptr ) { CObjectManager::GetInstancePointer()->DeleteObject(cargo); } vehicle = SearchVehicle(); if ( vehicle != nullptr ) { assert(vehicle->Implements(ObjectInterfaceType::Movable)); physics = dynamic_cast<CMovableObject*>(vehicle)->GetPhysics(); physics->SetFreeze(false); // can move vehicle->SetLock(false); // vehicle useable vehicle->SetRotationY(m_object->GetRotationY()+Math::PI); vehicle->SetScale(1.0f); if ( !m_program.empty() ) { if (vehicle->Implements(ObjectInterfaceType::Programmable) && vehicle->Implements(ObjectInterfaceType::ProgramStorage)) { Program* program = dynamic_cast<CProgramStorageObject*>(vehicle)->AddProgram(); if (boost::regex_search(m_program, boost::regex("^[A-Za-z0-9_]+$"))) // Public function name? { std::string code = "extern void object::Start_"+m_program+"()\n{\n\t\n\t//Automatically generated by object.factory()\n\t"+m_program+"();\n\t\n}\n"; program->script->SendScript(code.c_str()); } else if (boost::regex_search(m_program, boost::regex("\\.txt$"))) // File name (with .txt extension)? { program->script->ReadScript(m_program.c_str()); } else // Program code? { program->script->SendScript(m_program.c_str()); } dynamic_cast<CProgrammableObject*>(vehicle)->RunProgram(program); } } } m_main->CreateShortcuts(); m_phase = AFP_OPEN_T; m_progress = 0.0f; m_speed = 1.0f/2.0f; } } if ( m_phase == AFP_OPEN_T ) { if ( m_progress < 1.0f ) { for ( i=0 ; i<9 ; i++ ) { angle = -(1.0f-m_progress)*(Math::PI/2.0f)+Math::PI/2.0f; m_object->SetPartRotationZ( 1+i, angle); m_object->SetPartRotationZ(10+i, -angle); } if ( m_lastParticle+m_engine->ParticleAdapt(0.1f) <= m_time ) { m_lastParticle = m_time; pos = m_cargoPos; pos.x += (Math::Rand()-0.5f)*10.0f; pos.z += (Math::Rand()-0.5f)*10.0f; pos.y += Math::Rand()*10.0f; speed = Math::Vector(0.0f, 0.0f, 0.0f); dim.x = 2.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 2.0f, 0.0f, 0.0f); } } else { for ( i=0 ; i<9 ; i++ ) { m_object->SetPartRotationZ( 1+i, Math::PI/2.0f); m_object->SetPartRotationZ(10+i, -Math::PI/2.0f); } SoundManip(3.0f, 1.0f, 0.5f); m_phase = AFP_OPEN_S; m_progress = 0.0f; m_speed = 1.0f/3.0f; } } if ( m_phase == AFP_OPEN_S ) { if ( m_progress < 1.0f ) { for ( i=0 ; i<9 ; i++ ) { zoom = 0.30f+((1.0f-m_progress)-0.5f+i/16.0f)*2.0f*0.70f; if ( zoom < 0.30f ) zoom = 0.30f; if ( zoom > 1.00f ) zoom = 1.00f; m_object->SetPartScaleZ( 1+i, zoom); m_object->SetPartScaleZ(10+i, zoom); } if ( m_lastParticle+m_engine->ParticleAdapt(0.1f) <= m_time ) { m_lastParticle = m_time; pos = m_cargoPos; pos.x += (Math::Rand()-0.5f)*10.0f; pos.z += (Math::Rand()-0.5f)*10.0f; pos.y += Math::Rand()*10.0f; speed = Math::Vector(0.0f, 0.0f, 0.0f); dim.x = 2.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 2.0f, 0.0f, 0.0f); } } else { for ( i=0 ; i<9 ; i++ ) { m_object->SetPartScaleZ( 1+i, 0.30f); m_object->SetPartScaleZ(10+i, 0.30f); } SetBusy(false); UpdateInterface(); m_phase = AFP_WAIT; m_progress = 0.0f; m_speed = 1.0f/2.0f; } } return true; }
bool CAutoPowerCaptor::EventProcess(const Event &event) { Math::Vector pos, speed; Math::Point dim; int i; 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 == APAP_LIGHTNING ) { if ( m_progress < 1.0f ) { if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time ) { m_lastParticle = m_time; for ( i=0 ; i<10 ; i++ ) { pos = m_object->GetPosition(); pos.x += (Math::Rand()-0.5f)*m_progress*40.0f; pos.z += (Math::Rand()-0.5f)*m_progress*40.0f; pos.y += 50.0f-m_progress*50.0f; speed.x = (Math::Rand()-0.5f)*20.0f; speed.z = (Math::Rand()-0.5f)*20.0f; speed.y = 5.0f+Math::Rand()*5.0f; dim.x = 2.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ, 1.0f, 20.0f, 0.5f); } } } else { m_phase = APAP_CHARGE; m_progress = 0.0f; m_speed = 1.0f/2.0f; } } if ( m_phase == APAP_CHARGE ) { if ( m_progress < 1.0f ) { if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time ) { m_lastParticle = m_time; for ( i=0 ; i<2 ; i++ ) { pos = m_object->GetPosition(); pos.y += 16.0f; speed.x = (Math::Rand()-0.5f)*10.0f; speed.z = (Math::Rand()-0.5f)*10.0f; speed.y = -Math::Rand()*30.0f; dim.x = 1.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ, 1.0f, 0.0f, 0.0f); } } ChargeObject(event.rTime); } else { m_phase = APAP_WAIT; m_progress = 0.0f; m_speed = 1.0f/1.0f; } } return true; }