Ejemplo n.º 1
0
void EscortDisplay::MergeStacks() const
{
	if(icons.empty())
		return;
	
	set<const Sprite *> unstackable;
	while(true)
	{
		Icon *cheapest = nullptr;
		
		for(Icon &icon : icons)
		{
			if(unstackable.find(icon.sprite) == unstackable.end() && (!cheapest || *cheapest < icon))
				cheapest = &icon;
		}
		
		if(icons.size() <= iconsPerColumn * columns || !cheapest)
			break;
		
		// Merge all other instances of this ship's sprite with this icon.
		list<Icon>::iterator it = icons.begin();
		while(it != icons.end())
		{
			if(&*it == cheapest || it->sprite != cheapest->sprite || it->isHere != cheapest->isHere)
			{
				++it;
				continue;
			}
			
			cheapest->Merge(*it);
			it = icons.erase(it);	
		}
		unstackable.insert(cheapest->sprite);
	}
}
Ejemplo n.º 2
0
void EscortDisplay::MergeStacks() const
{
	if(icons.empty())
		return;
	
	int maxHeight = Screen::Height() - 450;
	set<const Sprite *> unstackable;
	while(true)
	{
		Icon *cheapest = nullptr;
		
		int height = 0;
		for(Icon &icon : icons)
		{
			if(unstackable.find(icon.sprite) == unstackable.end() && (!cheapest || *cheapest < icon))
				cheapest = &icon;
			
			height += icon.Height();
		}
		
		if(height < maxHeight || !cheapest)
			break;
		
		// Merge all other instances of this ship's sprite with this icon.
		vector<Icon>::iterator it = icons.begin();
		while(it != icons.end())
		{
			if(&*it == cheapest || it->sprite != cheapest->sprite || it->isHere != cheapest->isHere)
			{
				++it;
				continue;
			}
			
			cheapest->Merge(*it);
			it = icons.erase(it);	
		}
		unstackable.insert(cheapest->sprite);
	}
}