bool CTaskManip::Abort() { int i; if ( m_object->GetFret() == 0 ) // not carrying anything? { m_hand = TMH_OPEN; // open clamp m_arm = TMA_NEUTRAL; } else { m_hand = TMH_CLOSE; // closed clamp m_arm = TMA_STOCK; } InitAngle(); if ( !m_bSubm ) { for ( i=0 ; i<5 ; i++ ) { m_object->SetAngleZ(i+1, m_finalAngle[i]); } } m_camera->StopCentering(m_object, 2.0f); m_physics->SetFreeze(false); // is moving again return true; }
bool CTaskSearch::Abort() { m_hand = TSH_UP; InitAngle(); for (int i = 0; i < 3; i++) { m_object->SetAngleZ(i+1, m_finalAngle[i]); } m_camera->StopCentering(m_object, 2.0f); m_physics->SetFreeze(false); // is moving again return true; }
Error CTaskSearch::IsEnded() { int i; 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 == TSP_DOWN || m_phase == TSP_UP ) { for ( i=0 ; i<3 ; i++ ) { m_object->SetAngleZ(i+1, m_finalAngle[i]); } } if ( m_phase == TSP_DOWN ) { m_sound->Play(SOUND_REPAIR, m_object->GetPosition(0)); m_phase = TSP_SEARCH; m_speed = 1.0f/4.0f; return ERR_CONTINUE; } if ( m_phase == TSP_SEARCH ) { CreateMark(); m_hand = TSH_UP; InitAngle(); i = m_sound->Play(SOUND_MANIP, m_object->GetPosition(0), 0.0f, 0.3f, true); m_sound->AddEnvelope(i, 0.5f, 1.0f, 0.1f, SOPER_CONTINUE); m_sound->AddEnvelope(i, 0.5f, 1.0f, 0.9f, SOPER_CONTINUE); m_sound->AddEnvelope(i, 0.0f, 0.3f, 0.1f, SOPER_STOP); m_phase = TSP_UP; m_speed = 1.0f/1.0f; return ERR_CONTINUE; } Abort(); return ERR_STOP; }
Error CTaskSearch::Start() { ObjectType type; Math::Vector speed; int i; m_bError = true; if ( !m_physics->GetLand() ) return ERR_SEARCH_FLY; speed = m_physics->GetMotorSpeed(); if ( speed.x != 0.0f || speed.z != 0.0f ) return ERR_SEARCH_MOTOR; type = m_object->GetType(); if ( type != OBJECT_MOBILEfs && type != OBJECT_MOBILEts && type != OBJECT_MOBILEws && type != OBJECT_MOBILEis ) return ERR_SEARCH_VEH; m_hand = TSH_DOWN; m_phase = TSP_DOWN; m_progress = 0.0f; m_speed = 1.0f/1.0f; m_time = 0.0f; m_lastParticle = 0.0f; InitAngle(); m_bError = false; // ok m_camera->StartCentering(m_object, Math::PI*0.50f, 99.9f, 0.0f, 1.0f); i = m_sound->Play(SOUND_MANIP, m_object->GetPosition(0), 0.0f, 0.3f, true); m_sound->AddEnvelope(i, 0.5f, 1.0f, 0.1f, SOPER_CONTINUE); m_sound->AddEnvelope(i, 0.5f, 1.0f, 0.9f, SOPER_CONTINUE); m_sound->AddEnvelope(i, 0.0f, 0.3f, 0.1f, SOPER_STOP); m_physics->SetFreeze(true); // it does not move return ERR_OK; }
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; }