Advertisement
Guest User

DetachChildLanded

a guest
Mar 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. / Detach a child from the specified slot and unload it in LANDED mode; i.e., place it on the ground.
  2. // slotNumber = payload slot number
  3. // Returns: true on success, false if the child refused to be detached or if no child is in the specified slot
  4. bool XRPayloadBay::DetachChildLanded(const int slotNumber)
  5. {
  6.     _ASSERTE(slotNumber > 0);
  7.  
  8.     bool retVal = false;
  9.  
  10.     // see if there is a child in the requested slot
  11.     VESSEL *pChild = GetChild(slotNumber);
  12.     if (pChild != nullptr)
  13.     {
  14.         // Must obtain "move-to" coordinates while the child is still attached!  The subclass needs the child's attachment point
  15.         // to compute the proper coordinates.
  16.         VECTOR3 deployToCoords = GetLandedDeployToCoords(slotNumber);   // get from the subclass; these are ship-local coordinates
  17.  
  18.         // Detach the child vessel.
  19.         DetachChild(slotNumber, 0.0);    // no delta-V
  20.  
  21.         // obtain the child's coordinates
  22.         VESSELSTATUS2 childVS;
  23.         VESSEL3_EXT::GetStatusSafe(*pChild, childVS, false);
  24.  
  25.         // move the child to the deployToCoordinates by converting them (as a delta) from parent-local to GLOBAL coordinates
  26.         VECTOR3 globalChildDeltaCoords;
  27.         GetParentVessel().GlobalRot(deployToCoords, globalChildDeltaCoords);
  28.  
  29.         // now take the parent's rpos, apply the delta, and store it in the child's VS
  30.         VESSELSTATUS2 parentVS;
  31.         VESSEL3_EXT::GetStatusSafe(GetParentVessel(), parentVS, false);
  32.         childVS.rpos = (parentVS.rpos + globalChildDeltaCoords);
  33.        
  34.         // WARNING: do not force status=1 (landed) here!  It will cause the "bounce bug" and crash Orbiter.
  35.         childVS.status = 0;                  // set to FREEFLIGHT
  36.         pChild->DefSetStateEx(&childVS);     // update the vessel's state with the new location
  37.  
  38.         retVal = true;
  39.     }
  40.  
  41.     return retVal;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement