示例#1
0
void ViewSelectSpawn::updateSpawnList()
{
	GameDocument * pDoc = (GameDocument *)document();
	ASSERT( pDoc );
	UniverseContext * pContext = pDoc->context();
	ASSERT( pContext );

	int myFaction = pDoc->factionId();
	int highlighted = m_pListSpawn->highlighted();
	int selected = m_pListSpawn->selected();

	// reset the update time
	m_UpdateSpawnList = 1.0f;
	// remove all items from the list
	m_pListSpawn->removeAllItems();
	// release our spawn list
	m_Spawn.release();

	// make a list of all spawn positions in alpha order
	for(int i=0;i<pContext->zoneCount();i++)
	{
		NodeZone * pZone = pContext->zone( i );
		for(int j=0;j<pZone->childCount();j++)
		{
			Noun * pSpawn = NULL;

			BaseNode * pChild = pZone->child(j);
			if ( dynamic_cast<NounPlanet *>( pChild ) )
			{
				NounPlanet * pPlanet = (NounPlanet *)pChild;
				if ( pPlanet->factionId() == myFaction && (pPlanet->flags() & NounPlanet::FLAG_HAS_SHIPYARD) != 0 )
					pSpawn = pPlanet;
			}
			else if ( dynamic_cast<NounJumpGate *>( pChild ) )
			{
				NounJumpGate * pGate = (NounJumpGate *)pChild;
				if ( pGate->factionId() == myFaction )
					pSpawn = pGate;
			}

			if ( pSpawn != NULL )
			{
				// add item to list
				m_pListSpawn->addItem( pSpawn->name() );
				// add to internal list
				m_Spawn.push( pSpawn );
			}
		}
	}

	// restore the currently highlighted item
	m_pListSpawn->setHighlighted( highlighted );
	m_pListSpawn->setSelected( selected );
}