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; }
Error CTaskTake::Start() { m_height = 0.0f; m_step = 0; m_progress = 0.0f; float iAngle = m_object->GetRotationY(); iAngle = Math::NormAngle(iAngle); // 0..2*Math::PI float oAngle = iAngle; m_bError = true; // operation impossible if ( !m_physics->GetLand() ) { Math::Vector pos = m_object->GetPosition(); float h = m_water->GetLevel(m_object); if ( pos.y < h ) return ERR_MANIP_WATER; // impossible under water return ERR_MANIP_FLY; } ObjectType type = m_object->GetType(); if ( type != OBJECT_HUMAN && type != OBJECT_TECH ) return ERR_WRONG_BOT; m_physics->SetMotorSpeed(Math::Vector(0.0f, 0.0f, 0.0f)); if (m_object->IsCarryingCargo()) m_order = TTO_DEPOSE; else m_order = TTO_TAKE; if ( m_order == TTO_TAKE ) { Math::Vector pos = m_object->GetPosition(); float h = m_water->GetLevel(m_object); if ( pos.y < h ) return ERR_MANIP_WATER; // impossible under water CObject* other = SearchFriendObject(oAngle, 1.5f, Math::PI*0.50f); if (other != nullptr) assert(other->Implements(ObjectInterfaceType::Powered)); if (other != nullptr && dynamic_cast<CPoweredObject*>(other)->GetPower() != nullptr) { CObject* power = dynamic_cast<CPoweredObject*>(other)->GetPower(); type = power->GetType(); if ( type == OBJECT_URANIUM ) return ERR_MANIP_RADIO; assert(power->Implements(ObjectInterfaceType::Transportable)); //? m_camera->StartCentering(m_object, Math::PI*0.3f, -Math::PI*0.1f, 0.0f, 0.8f); m_arm = TTA_FRIEND; } else { other = SearchTakeObject(oAngle, 1.5f, Math::PI*0.45f); if ( other == nullptr ) return ERR_MANIP_NIL; type = other->GetType(); if ( type == OBJECT_URANIUM ) return ERR_MANIP_RADIO; //? m_camera->StartCentering(m_object, Math::PI*0.3f, 99.9f, 0.0f, 0.8f); m_arm = TTA_FFRONT; m_main->HideDropZone(other); // hides buildable area } } if ( m_order == TTO_DEPOSE ) { //? speed = m_physics->GetMotorSpeed(); //? if ( speed.x != 0.0f || //? speed.z != 0.0f ) return ERR_MANIP_MOTOR; CObject* other = SearchFriendObject(oAngle, 1.5f, Math::PI*0.50f); if (other != nullptr) assert(other->Implements(ObjectInterfaceType::Powered)); if (other != nullptr && dynamic_cast<CPoweredObject*>(other)->GetPower() == nullptr ) { //? m_camera->StartCentering(m_object, Math::PI*0.3f, -Math::PI*0.1f, 0.0f, 0.8f); m_arm = TTA_FRIEND; } else { if ( !IsFreeDeposeObject(Math::Vector(2.5f, 0.0f, 0.0f)) ) return ERR_MANIP_OCC; //? m_camera->StartCentering(m_object, Math::PI*0.3f, 99.9f, 0.0f, 0.8f); m_arm = TTA_FFRONT; } } m_bTurn = true; // preliminary rotation necessary m_angle = oAngle; // angle was reached m_physics->SetFreeze(true); // it does not move m_bError = false; // ok return ERR_OK; }