bool CItemMulti::Ship_MoveDelta( CPointBase pdelta ) { // Move the ship one space in some direction. ASSERT( m_pRegion->m_iLinkedSectors ); int znew = GetTopZ() + pdelta.m_z; if ( pdelta.m_z > 0 ) { if ( znew >= (UO_SIZE_Z - PLAYER_HEIGHT )-1 ) return( false ); } else if ( pdelta.m_z < 0 ) { if ( znew <= (UO_SIZE_MIN_Z + 3 )) return( false ); } // Move the ship and everything on the deck CObjBase * ppObjs[MAX_MULTI_LIST_OBJS+1]; int iCount = Ship_ListObjs( ppObjs ); for ( int i=0; i <iCount; i++ ) { CObjBase * pObj = ppObjs[i]; ASSERT(pObj); CPointMap pt = pObj->GetTopPoint(); pt += pdelta; if ( ! pt.IsValidPoint()) // boat goes out of bounds ! { DEBUG_ERR(( "Ship uid=0%x out of bounds\n", (DWORD) GetUID())); continue; } pObj->MoveTo( pt ); if ( pObj->IsChar()) { ASSERT( m_pRegion->m_iLinkedSectors ); pObj->RemoveFromView(); // Get rid of the blink/walk pObj->Update(); } } return( true ); }
bool CItemMulti::Ship_Face( DIR_TYPE dir ) { // Change the direction of the ship. ASSERT( IsTopLevel()); DEBUG_CHECK( m_pRegion ); if ( m_pRegion == NULL ) { return false; } int i=0; for ( ; true; i++ ) { if ( i >= COUNTOF(sm_Ship_FaceDir)) return( false ); if ( dir == sm_Ship_FaceDir[i] ) break; } int iFaceOffset = Ship_GetFaceOffset(); ITEMID_TYPE idnew = (ITEMID_TYPE) ( GetID() - iFaceOffset + i ); const CItemBaseMulti * pMultiNew = Multi_GetDef( idnew ); if ( pMultiNew == NULL ) { return false; } const CItemBaseMulti * pMultiDef = Multi_GetDef(); ASSERT( pMultiDef); int iTurn = dir - sm_Ship_FaceDir[ iFaceOffset ]; // ?? Are there blocking items in the way of the turn ? // CRectMap // Reorient everything on the deck CObjBase * ppObjs[MAX_MULTI_LIST_OBJS+1]; int iCount = Ship_ListObjs( ppObjs ); int i2 = 0; for ( i=0; i<iCount; i++ ) { CObjBase * pObj = ppObjs[i]; CPointMap pt = pObj->GetTopPoint(); if ( pObj->IsItem()) { CItem * pItem = STATIC_CAST <CItem*> (pObj); ASSERT( pItem ); if ( pItem == this ) { m_pRegion->UnRealizeRegion(); pItem->SetID(idnew); // Adjust the region to be the new shape/area. MultiRealizeRegion(); pItem->Update(); continue; } // Is this a ship component ? transform it. //int i = Multi_IsComponentOf( pItem ); if ( Multi_IsPartOf( pItem ) ) //i>=0 ) { pItem->SetDispID( pMultiNew->m_Components[i2].m_id ); pt = GetTopPoint(); pt.m_x += pMultiNew->m_Components[i2].m_dx; pt.m_y += pMultiNew->m_Components[i2].m_dy; pt.m_z += pMultiNew->m_Components[i2].m_dz; pItem->MoveTo( pt ); i2++; continue; } } // -2,6 = left. // +2,-6 = right. // +-4 = flip around int iTmp; int xdiff = GetTopPoint().m_x - pt.m_x; int ydiff = GetTopPoint().m_y - pt.m_y; switch ( iTurn ) { case 2: // right case (2-DIR_QTY): iTmp = xdiff; xdiff = ydiff; ydiff = -iTmp; break; case -2: // left. case (DIR_QTY-2): iTmp = xdiff; xdiff = -ydiff; ydiff = iTmp; break; default: // u turn. xdiff = -xdiff; ydiff = -ydiff; break; } pt.m_x = GetTopPoint().m_x + xdiff; pt.m_y = GetTopPoint().m_y + ydiff; pObj->MoveTo( pt ); if ( pObj->IsChar()) { // Turn creatures as well. CChar * pChar = STATIC_CAST <CChar*> (pObj); ASSERT(pChar); pChar->m_dirFace = GetDirTurn( pChar->m_dirFace, iTurn ); pChar->RemoveFromView(); pChar->Update(); } } m_itShip.m_DirFace = dir; return( true ); }