void CAutoFactory::DeleteObject(bool all) { if ( !all ) { CObject* cargo = SearchCargo(); // transform metal? if ( cargo != nullptr ) { CObjectManager::GetInstancePointer()->DeleteObject(cargo); } CObject* vehicle = SearchVehicle(); if ( vehicle != nullptr ) { CObjectManager::GetInstancePointer()->DeleteObject(vehicle); } } 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; } CAuto::DeleteObject(all); }
bool CAutoNest::EventProcess(const Event &event) { CObject* cargo; CAuto::EventProcess(event); if ( m_engine->GetPause() ) return true; if ( event.type != EVENT_FRAME ) return true; m_progress += event.rTime*m_speed; if ( m_phase == ANP_WAIT ) { if ( m_progress >= 1.0f ) { if ( !SearchFree(m_cargoPos) ) { m_phase = ANP_WAIT; m_progress = 0.0f; m_speed = 1.0f/4.0f; } else { CreateCargo(m_cargoPos, 0.0f, OBJECT_BULLET); m_phase = ANP_BIRTH; m_progress = 0.0f; m_speed = 1.0f/5.0f; } } } if ( m_phase == ANP_BIRTH ) { cargo = SearchCargo(); if ( m_progress < 1.0f ) { if ( cargo != nullptr ) { cargo->SetScale(m_progress); } } else { if ( cargo != nullptr ) { cargo->SetScale(1.0f); cargo->SetLock(false); } m_phase = ANP_WAIT; m_progress = 0.0f; m_speed = 1.0f/5.0f; } } return true; }
void CAutoNest::DeleteObject(bool all) { if ( !all ) { CObject* cargo = SearchCargo(); if ( cargo != nullptr ) { CObjectManager::GetInstancePointer()->DeleteObject(cargo); } } CAuto::DeleteObject(all); }
void CAutoDerrick::DeleteObject(bool all) { if ( !all ) { CObject* cargo = SearchCargo(); if ( cargo != nullptr && cargo->GetLock() ) { CObjectManager::GetInstancePointer()->DeleteObject(cargo); } } if ( m_soundChannel != -1 ) { m_sound->FlushEnvelope(m_soundChannel); m_sound->AddEnvelope(m_soundChannel, 0.0f, 1.0f, 1.0f, SOPER_STOP); m_soundChannel = -1; } CAuto::DeleteObject(all); }
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 CAutoDerrick::EventProcess(const Event &event) { CObject* cargo; Math::Vector pos, speed; Math::Point dim; float angle, duration, factor; CAuto::EventProcess(event); if ( m_engine->GetPause() ) return true; if ( event.type != EVENT_FRAME ) return true; if ( m_phase == ADP_WAIT ) 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; pos.x = 0.0f; pos.z = 0.0f; pos.y = -2.0f*Math::Rand(); m_object->SetPartPosition(1, pos); // up / down the drill m_object->SetPartRotationY(1, Math::Rand()*0.5f); // rotates the drill } return true; } if ( m_phase == ADP_EXCAVATE ) { if ( m_soundChannel == -1 ) { if ( m_type == OBJECT_URANIUM ) { factor = DERRICK_DELAYu/DERRICK_DELAY; } else { factor = 1.0f; } m_soundChannel = m_sound->Play(SOUND_DERRICK, m_object->GetPosition(), 1.0f, 0.5f, true); m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.5f, 4.0f*factor, SOPER_CONTINUE); m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.3f, 6.0f*factor, SOPER_CONTINUE); m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.5f, 1.0f, SOPER_CONTINUE); m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.5f, 4.0f, SOPER_STOP); } if ( m_progress >= 6.0f/16.0f && // penetrates into the ground? m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time ) { m_lastParticle = m_time; pos = m_object->GetPosition(); speed.x = (Math::Rand()-0.5f)*10.0f; speed.z = (Math::Rand()-0.5f)*10.0f; speed.y = Math::Rand()*5.0f; dim.x = Math::Rand()*3.0f+2.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, 2.0f); } if ( m_progress >= 6.0f/16.0f && // penetrates into the ground? m_lastTrack+m_engine->ParticleAdapt(0.5f) <= m_time ) { m_lastTrack = m_time; pos = m_object->GetPosition(); speed.x = (Math::Rand()-0.5f)*12.0f; speed.z = (Math::Rand()-0.5f)*12.0f; speed.y = Math::Rand()*10.0f+10.0f; dim.x = 0.6f; dim.y = dim.x; pos.y += dim.y; duration = Math::Rand()*2.0f+2.0f; m_particle->CreateTrack(pos, speed, dim, Gfx::PARTITRACK5, duration, Math::Rand()*10.0f+15.0f, duration*0.2f, 1.0f); } if ( m_progress < 1.0f ) { pos.x = 0.0f; pos.z = 0.0f; pos.y = -m_progress*16.0f; m_object->SetPartPosition(1, pos); // down the drill angle = m_object->GetPartRotationY(1); angle += event.rTime*8.0f; m_object->SetPartRotationY(1, angle); // rotates the drill } else { m_phase = ADP_ASCEND; m_progress = 0.0f; m_speed = 1.0f/5.0f; } } if ( m_phase == ADP_ASCEND ) { if ( m_progress <= 7.0f/16.0f && m_lastParticle+m_engine->ParticleAdapt(0.1f) <= m_time ) { m_lastParticle = m_time; pos = m_object->GetPosition(); speed.x = (Math::Rand()-0.5f)*10.0f; speed.z = (Math::Rand()-0.5f)*10.0f; speed.y = Math::Rand()*5.0f; dim.x = Math::Rand()*3.0f+2.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, 2.0f); } if ( m_progress <= 4.0f/16.0f && m_lastTrack+m_engine->ParticleAdapt(1.0f) <= m_time ) { m_lastTrack = m_time; pos = m_object->GetPosition(); speed.x = (Math::Rand()-0.5f)*12.0f; speed.z = (Math::Rand()-0.5f)*12.0f; speed.y = Math::Rand()*10.0f+10.0f; dim.x = 0.6f; dim.y = dim.x; pos.y += dim.y; duration = Math::Rand()*2.0f+2.0f; m_particle->CreateTrack(pos, speed, dim, Gfx::PARTITRACK5, duration, Math::Rand()*10.0f+15.0f, duration*0.2f, 1.0f); } if ( m_progress < 1.0f ) { pos.x = 0.0f; pos.z = 0.0f; pos.y = -(1.0f-m_progress)*16.0f; m_object->SetPartPosition(1, pos); // back the drill angle = m_object->GetPartRotationY(1); angle -= event.rTime*2.0f; m_object->SetPartRotationY(1, angle); // rotates the drill } else { m_soundChannel = -1; m_bSoundFall = false; m_phase = ADP_EXPORT; m_progress = 0.0f; m_speed = 1.0f/5.0f; } } if ( m_phase == ADP_ISFREE ) { if ( m_progress >= 1.0f ) { m_bSoundFall = false; m_phase = ADP_EXPORT; m_progress = 0.0f; m_speed = 1.0f/5.0f; } } if ( m_phase == ADP_EXPORT ) { if ( m_progress == 0.0f ) { Math::Vector cargoPos = GetCargoPos(); if ( SearchFree(cargoPos) ) { angle = m_object->GetRotationY(); CreateCargo(cargoPos, angle, m_type, 16.0f); } else { m_phase = ADP_ISFREE; m_progress = 0.0f; m_speed = 1.0f/2.0f; return true; } } cargo = SearchCargo(); if ( cargo != nullptr && m_progress <= 0.5f && m_lastParticle+m_engine->ParticleAdapt(0.1f) <= m_time ) { m_lastParticle = m_time; if ( m_progress < 0.3f ) { pos = cargo->GetPosition(); pos.x += (Math::Rand()-0.5f)*5.0f; pos.z += (Math::Rand()-0.5f)*5.0f; pos.y += (Math::Rand()-0.5f)*5.0f; speed = Math::Vector(0.0f, 0.0f, 0.0f); dim.x = 3.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFIRE, 1.0f, 0.0f, 0.0f); } else { pos = cargo->GetPosition(); pos.x += (Math::Rand()-0.5f)*5.0f; pos.z += (Math::Rand()-0.5f)*5.0f; pos.y += Math::Rand()*2.5f; speed = Math::Vector(0.0f, 0.0f, 0.0f); dim.x = 1.0f; dim.y = dim.x; m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 2.0f, 0.0f, 0.0f); } } if ( m_progress < 1.0f ) { if ( cargo != nullptr ) { Math::Vector cargoPos = GetCargoPos(); pos = cargo->GetPosition(); pos.y -= event.rTime*20.0f; // grave if ( !m_bSoundFall && pos.y < cargoPos.y ) { m_sound->Play(SOUND_BOUM, cargoPos); m_bSoundFall = true; } if ( pos.y < cargoPos.y ) { pos.y = cargoPos.y; cargo->SetLock(false); // object usable } cargo->SetPosition(pos); } } else { if ( ExistKey() ) // key already exists? { m_phase = ADP_WAIT; m_progress = 0.0f; m_speed = 1.0f/10.0f; } else { m_phase = ADP_EXCAVATE; m_progress = 0.0f; m_speed = 1.0f/(m_type==OBJECT_URANIUM?DERRICK_DELAYu:DERRICK_DELAY); } } } 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; }