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; }
Error CTaskPen::IsEnded() { if ( m_engine->GetPause() ) return ERR_CONTINUE; if ( m_bError ) return ERR_STOP; if ( m_progress < 1.0f ) return ERR_CONTINUE; m_progress = 0.0f; if ( m_phase == TPP_UP ) { m_phase = TPP_TURN; m_progress = 0.0f; m_delay = fabs(m_oldAngle-m_newAngle)/Math::PI; m_time = 0.0f; m_lastParticle = 0.0f; if ( m_delay > 0.0f ) { SoundManip(m_delay, 1.0f, 1.0f); } return ERR_CONTINUE; } if ( m_phase == TPP_TURN ) { m_sound->Play(SOUND_PSHHH2, m_supportPos, 1.0f, 1.4f); m_phase = TPP_DOWN; m_progress = 0.0f; m_delay = m_timeDown; m_time = 0.0f; m_lastParticle = 0.0f; return ERR_CONTINUE; } Abort(); return ERR_STOP; }
Error CTaskManip::IsEnded() { CObject* fret; Math::Vector pos; float angle, dist; int i; if ( m_engine->GetPause() ) return ERR_CONTINUE; if ( m_bError ) return ERR_STOP; if ( m_bBee ) // bee? { return ERR_STOP; } if ( m_bTurn ) // preliminary rotation? { angle = m_object->GetAngleY(0); angle = Math::NormAngle(angle); // 0..2*Math::PI if ( Math::TestAngle(angle, m_angle-Math::PI*0.01f, m_angle+Math::PI*0.01f) ) { m_bTurn = false; // rotation ended m_physics->SetMotorSpeedZ(0.0f); if ( m_move == 0.0f ) { SoundManip(1.0f/m_speed); } } return ERR_CONTINUE; } if ( m_move != 0.0f ) // preliminary advance? { if ( m_timeLimit <= 0.0f ) { //OK 1.9 dist = Math::Distance(m_object->GetPosition(0), m_targetPos); if ( dist <= m_advanceLength + 2.0f ) { m_move = 0.0f; // advance ended m_physics->SetMotorSpeedX(0.0f); SoundManip(1.0f/m_speed); return ERR_CONTINUE; } else { //EOK 1.9 m_move = 0.0f; // advance ended m_physics->SetMotorSpeedX(0.0f); // stops Abort(); return ERR_STOP; } } dist = Math::Distance(m_object->GetPosition(0), m_targetPos); if ( dist <= m_advanceLength ) { m_move = 0.0f; // advance ended m_physics->SetMotorSpeedX(0.0f); SoundManip(1.0f/m_speed); } return ERR_CONTINUE; } if ( m_progress < 1.0f ) return ERR_CONTINUE; m_progress = 0.0f; if ( !m_bSubm ) { for ( i=0 ; i<5 ; i++ ) { m_object->SetAngleZ(i+1, m_finalAngle[i]); } } m_step ++; if ( m_order == TMO_GRAB ) { if ( m_step == 1 ) { if ( m_bSubm ) m_speed = 1.0f/0.7f; m_hand = TMH_CLOSE; // closes the clamp to take InitAngle(); SoundManip(1.0f/m_speed, 0.8f, 1.5f); return ERR_CONTINUE; } if ( m_step == 2 ) { if ( m_bSubm ) m_speed = 1.0f/1.5f; if ( !TruckTakeObject() && m_object->GetFret() == 0 ) { m_hand = TMH_OPEN; // reopens the clamp m_arm = TMA_NEUTRAL; InitAngle(); SoundManip(1.0f/m_speed, 0.8f, 1.5f); } else { if ( (m_arm == TMA_OTHER || m_arm == TMA_POWER ) && (m_fretType == OBJECT_POWER || m_fretType == OBJECT_ATOMIC ) ) { m_sound->Play(SOUND_POWEROFF, m_object->GetPosition(0)); } m_arm = TMA_STOCK; InitAngle(); SoundManip(1.0f/m_speed); } return ERR_CONTINUE; } } if ( m_order == TMO_DROP ) { if ( m_step == 1 ) { if ( m_bSubm ) m_speed = 1.0f/0.7f; fret = m_object->GetFret(); if ( TruckDeposeObject() ) { if ( (m_arm == TMA_OTHER || m_arm == TMA_POWER ) && (m_fretType == OBJECT_POWER || m_fretType == OBJECT_ATOMIC ) ) { m_sound->Play(SOUND_POWERON, m_object->GetPosition(0)); } if ( fret != 0 && m_fretType == OBJECT_METAL && m_arm == TMA_FFRONT ) { m_main->ShowDropZone(fret, m_object); // shows buildable area } m_hand = TMH_OPEN; // opens the clamp to deposit SoundManip(1.0f/m_speed, 0.8f, 1.5f); } InitAngle(); return ERR_CONTINUE; } if ( m_step == 2 ) { if ( m_bSubm ) m_speed = 1.0f/1.5f; m_arm = TMA_NEUTRAL; InitAngle(); SoundManip(1.0f/m_speed); return ERR_CONTINUE; } } Abort(); return ERR_STOP; }
Error CTaskManip::Start(TaskManipOrder order, TaskManipArm arm) { ObjectType type; CObject *front, *other, *power; Gfx::CPyro *pyro; float iAngle, dist, len; float fDist, fAngle, oDist, oAngle, oHeight; Math::Vector pos, fPos, oPos; m_arm = arm; m_height = 0.0f; m_step = 0; m_progress = 0.0f; m_speed = 1.0f/1.5f; iAngle = m_object->GetAngleY(0); iAngle = Math::NormAngle(iAngle); // 0..2*Math::PI oAngle = iAngle; m_bError = true; // operation impossible if ( m_arm != TMA_FFRONT && m_arm != TMA_FBACK && m_arm != TMA_POWER && m_arm != TMA_GRAB ) return ERR_MANIP_VEH; m_physics->SetMotorSpeed(Math::Vector(0.0f, 0.0f, 0.0f)); type = m_object->GetType(); if ( type == OBJECT_BEE ) // bee? { if ( m_object->GetFret() == 0 ) { if ( !m_physics->GetLand() ) return ERR_MANIP_FLY; other = SearchTakeUnderObject(m_targetPos, MARGIN_BEE); if ( other == 0 ) return ERR_MANIP_NIL; m_object->SetFret(other); // takes the ball other->SetTruck(m_object); other->SetTruckPart(0); // taken with the base other->SetPosition(0, Math::Vector(0.0f, -3.0f, 0.0f)); } else { other = m_object->GetFret(); // other = ball m_object->SetFret(0); // lick the ball other->SetTruck(0); pos = m_object->GetPosition(0); pos.y -= 3.0f; other->SetPosition(0, pos); pos = m_object->GetPosition(0); pos.y += 2.0f; m_object->SetPosition(0, pos); // against the top of jump pyro = new Gfx::CPyro(); pyro->Create(Gfx::PT_FALL, other); // the ball falls } m_bBee = true; m_bError = false; // ok return ERR_OK; } m_bBee = false; m_bSubm = ( type == OBJECT_MOBILEsa ); // submarine? if ( m_arm == TMA_GRAB ) // takes immediately? { TruckTakeObject(); Abort(); return ERR_OK; } m_energy = 0.0f; power = m_object->GetPower(); if ( power != 0 ) { m_energy = power->GetEnergy(); } if ( !m_physics->GetLand() ) return ERR_MANIP_FLY; if ( type != OBJECT_MOBILEfa && type != OBJECT_MOBILEta && type != OBJECT_MOBILEwa && type != OBJECT_MOBILEia && type != OBJECT_MOBILEsa ) return ERR_MANIP_VEH; if ( m_bSubm ) // submarine? { m_arm = TMA_FFRONT; // only possible in front! } m_move = 0.0f; // advance not necessary m_angle = iAngle; if ( order == TMO_AUTO ) { if ( m_object->GetFret() == 0 ) { m_order = TMO_GRAB; } else { m_order = TMO_DROP; } } else { m_order = order; } if ( m_order == TMO_GRAB && m_object->GetFret() != 0 ) { return ERR_MANIP_BUSY; } if ( m_order == TMO_DROP && m_object->GetFret() == 0 ) { return ERR_MANIP_EMPTY; } //? speed = m_physics->GetMotorSpeed(); //? if ( speed.x != 0.0f || //? speed.z != 0.0f ) return ERR_MANIP_MOTOR; if ( m_order == TMO_GRAB ) { if ( m_arm == TMA_FFRONT ) { front = SearchTakeFrontObject(true, fPos, fDist, fAngle); other = SearchOtherObject(true, oPos, oDist, oAngle, oHeight); if ( front != 0 && fDist < oDist ) { m_targetPos = fPos; m_angle = fAngle; m_move = 1.0f; // advance required } else if ( other != 0 && oDist < fDist ) { if ( other->GetPower() == 0 ) return ERR_MANIP_NIL; m_targetPos = oPos; m_angle = oAngle; m_height = oHeight; m_move = 1.0f; // advance required m_arm = TMA_OTHER; } else { return ERR_MANIP_NIL; } m_main->HideDropZone(front); // hides buildable area } if ( m_arm == TMA_FBACK ) { if ( SearchTakeBackObject(true, m_targetPos, fDist, m_angle) == 0 ) { return ERR_MANIP_NIL; } m_angle += Math::PI; m_move = -1.0f; // back necessary } if ( m_arm == TMA_POWER ) { if ( m_object->GetPower() == 0 ) return ERR_MANIP_NIL; } } if ( m_order == TMO_DROP ) { if ( m_arm == TMA_FFRONT ) { other = SearchOtherObject(true, oPos, oDist, oAngle, oHeight); if ( other != 0 && other->GetPower() == 0 ) { m_targetPos = oPos; m_angle = oAngle; m_height = oHeight; m_move = 1.0f; // advance required m_arm = TMA_OTHER; } else { if ( !IsFreeDeposeObject(Math::Vector(TAKE_DIST, 0.0f, 0.0f)) ) return ERR_MANIP_OCC; } } if ( m_arm == TMA_FBACK ) { if ( !IsFreeDeposeObject(Math::Vector(-TAKE_DIST, 0.0f, 0.0f)) ) return ERR_MANIP_OCC; } if ( m_arm == TMA_POWER ) { if ( m_object->GetPower() != 0 ) return ERR_MANIP_OCC; } } dist = Math::Distance(m_object->GetPosition(0), m_targetPos); len = dist-TAKE_DIST; if ( m_arm == TMA_OTHER ) len -= TAKE_DIST_OTHER; if ( len < 0.0f ) len = 0.0f; if ( m_arm == TMA_FBACK ) len = -len; m_advanceLength = dist-m_physics->GetLinLength(len); if ( dist <= m_advanceLength+0.2f ) m_move = 0.0f; // not necessary to advance if ( m_energy == 0.0f ) m_move = 0.0f; if ( m_move != 0.0f ) // forward or backward? { m_timeLimit = m_physics->GetLinTimeLength(fabs(len))*1.5f; if ( m_timeLimit < 0.5f ) m_timeLimit = 0.5f; } if ( m_object->GetFret() == 0 ) // not carrying anything? { m_hand = TMH_OPEN; // open clamp } else { m_hand = TMH_CLOSE; // closed clamp } InitAngle(); if ( iAngle == m_angle || m_energy == 0.0f ) { m_bTurn = false; // preliminary rotation unnecessary SoundManip(1.0f/m_speed); } else { m_bTurn = true; // preliminary rotation necessary } if ( m_bSubm ) { m_camera->StartCentering(m_object, Math::PI*0.8f, 99.9f, 0.0f, 0.5f); } m_physics->SetFreeze(true); // it does not move m_bError = false; // ok return ERR_OK; }
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; }
Error CTaskPen::Start(bool bDown, TraceColor color) { Math::Vector pos; Math::Matrix* mat; ObjectType type; int i; if (color == TraceColor::Default) color = m_object->GetTraceColor(); m_object->SetTraceDown(bDown); m_object->SetTraceColor(color); m_physics->SetMotorSpeedX(0.0f); m_physics->SetMotorSpeedY(0.0f); m_physics->SetMotorSpeedZ(0.0f); m_bError = true; // operation impossible type = m_object->GetType(); if ( type != OBJECT_MOBILEdr ) return ERR_WRONG_BOT; m_bError = false; // ok m_oldAngle = m_object->GetPartRotationY(1); m_newAngle = ColorToAngle(color); i = AngleToRank(m_oldAngle); pos = m_object->GetPartPosition(10+i); if ( pos.y == 0.0f ) // pencil at the top? { m_timeUp = 0.0f; } else // pencil on the bottom? { m_timeUp = 1.0f; // must rise up } if ( bDown ) // must go down ? { m_timeDown = 0.7f; } else { m_timeDown = 0.0f; } mat = m_object->GetWorldMatrix(0); pos = Math::Vector(-3.0f, 7.0f, 0.0f); pos = Math::Transform(*mat, pos); // position of carousel m_supportPos = pos; m_phase = TPP_UP; m_progress = 0.0f; m_delay = m_timeUp; m_time = 0.0f; if ( m_timeUp > 0.0f ) { SoundManip(m_timeUp, 1.0f, 0.5f); } m_lastParticle = 0.0f; //? m_camera->StartCentering(m_object, Math::PI*0.60f, 99.9f, 5.0f, 0.5f); return ERR_OK; }
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; }