void CTilegenRange_ClosedExits::Initialize( CFreeVariableMap *pContext ) { m_Exits.RemoveAll(); const CRoomCandidate *pRoomCandidate = m_pRoomCandidateExpression->Evaluate( pContext ); if ( pRoomCandidate != NULL ) { CUtlVector< CRoomTemplateExit * > matchingExits; ( ( const CMapLayout * )pContext->GetFreeVariableDisallowNULL( "MapLayout" ) )->CheckExits( pRoomCandidate->m_pRoomTemplate, pRoomCandidate->m_iXPos, pRoomCandidate->m_iYPos, &matchingExits ); for ( int i = 0; i < matchingExits.Count(); ++ i ) { m_Exits.AddToTail( CExit( matchingExits[i]->m_iXPos + pRoomCandidate->m_iXPos, pRoomCandidate->m_pRoomTemplate->GetTilesY() - 1 - matchingExits[i]->m_iYPos + pRoomCandidate->m_iYPos, matchingExits[i]->m_ExitDirection, matchingExits[i]->m_szExitTag, NULL, false ) ); } } m_nCurrentExit = m_Exits.Count(); }
void BuildOpenExitList( const CRoomCandidate &roomCandidate, const CMapLayout *pMapLayout, CUtlVector< CExit > *pNewExitList ) { Assert( pMapLayout ); const CRoomTemplate *pTemplate = roomCandidate.m_pRoomTemplate; for ( int i = 0; i < pTemplate->m_Exits.Count(); ++ i ) { int nExitX, nExitY; if ( GetExitPosition( pTemplate, roomCandidate.m_iXPos, roomCandidate.m_iYPos, i, &nExitX, &nExitY ) ) { if ( !pMapLayout->GetRoom( nExitX, nExitY ) ) { pNewExitList->AddToTail( CExit( nExitX, nExitY, pTemplate->m_Exits[i]->m_ExitDirection, pTemplate->m_Exits[i]->m_szExitTag, NULL, false ) ); } } } }
void CLayoutSystem::AddOpenExit( CRoom *pSourceRoom, int nX, int nY, ExitDirection_t exitDirection, const char *pExitTag, bool bChokepointGrowSource ) { // Check to make sure exit isn't already in the list. for ( int i = 0; i < m_OpenExits.Count(); ++ i ) { const CExit *pExit = &m_OpenExits[i]; if ( pExit->X == nX && pExit->Y == nY && pExit->ExitDirection == exitDirection ) { // Exit already exists. Assert( pExit->pSourceRoom == pSourceRoom && Q_stricmp( pExitTag, pExit->m_szExitTag ) == 0 ); return; } } m_OpenExits.AddToTail( CExit( nX, nY, exitDirection, pExitTag, pSourceRoom, bChokepointGrowSource ) ); }
void CTilegenAction_AddConnectorRoomCandidates::Execute( CLayoutSystem *pLayoutSystem ) { CUtlVector< const CRoomTemplate * > roomTemplateList; if ( m_pTargetRoomTemplate != NULL ) { Assert( m_pTargetRoomTemplateFilter == NULL && m_pTargetThemeNameExpression == NULL ); roomTemplateList.AddToTail( m_pTargetRoomTemplate ); } else { Assert( m_pTargetRoomTemplateFilter != NULL && m_pTargetThemeNameExpression != NULL ); if ( m_pLevelTheme == NULL ) { const char *pThemeName = m_pTargetThemeNameExpression->Evaluate( pLayoutSystem->GetFreeVariables() ); m_pLevelTheme = CLevelTheme::FindTheme( pThemeName ); if ( m_pLevelTheme == NULL ) { Log_Warning( LOG_TilegenLayoutSystem, "Theme %s not found.\n", pThemeName ); pLayoutSystem->OnError(); return; } } BuildRoomTemplateList( pLayoutSystem, m_pLevelTheme, m_pTargetRoomTemplateFilter, true, &roomTemplateList ); } // Build a list of exit types we're looking for CUtlVector< CExit > desiredMatchingExits; for ( int i = 0; i < roomTemplateList.Count(); ++ i ) { const CRoomTemplate *pTemplate = roomTemplateList[i]; for ( int j = 0; j < pTemplate->m_Exits.Count(); ++ j ) { desiredMatchingExits.AddToTail( CExit( 0, 0, CRoomTemplateExit::GetOppositeDirection( pTemplate->m_Exits[j]->m_ExitDirection ), pTemplate->m_Exits[j]->m_szExitTag, NULL, false ) ); } } // Build up a room of connector candidates pLayoutSystem->ExecuteAction( m_pAddConnectorCandidates, NULL ); // Filter the set down by eliminating candidates which don't connect to the desired direction. CUtlVector< CRoomCandidate > *pRoomCandidateList = pLayoutSystem->GetRoomCandidateList(); CUtlVector< CExit > newOpenExits; for ( int i = pRoomCandidateList->Count() - 1; i >= 0; -- i ) { bool bMatch = false; newOpenExits.RemoveAll(); // Figure out which new exits would be open as a result of placing this room candidate. BuildOpenExitList( pRoomCandidateList->Element( i ), pLayoutSystem->GetMapLayout(), &newOpenExits ); // For every new open exit potentially created by this candidate, // see if one of them could connect to one of our desired exits. for ( int j = 0; j < newOpenExits.Count(); ++ j ) { const CExit *pNewOpenExit = &newOpenExits[j]; for ( int k = 0; k < desiredMatchingExits.Count(); ++ k ) { const CExit *pDesiredMatchingExit = &desiredMatchingExits[k]; if ( pNewOpenExit->ExitDirection == pDesiredMatchingExit->ExitDirection && Q_stricmp( pNewOpenExit->m_szExitTag, pDesiredMatchingExit->m_szExitTag ) == 0 ) { // Found a match! bMatch = true; break; } } if ( bMatch ) break; } if ( !bMatch ) { pRoomCandidateList->FastRemove( i ); } } }
DEFDIR(exit, _Noreturn) { while (*x_cur && !isgraph(*x_cur)) ++x_cur; CExit(LNE, COL, x_cur); }