Beispiel #1
0
void Section::operator=(Section const& section)
{
	delete myComponent;
	delete room;

	myComponent = new Component;
	room = new Rect;
	*myComponent = section.GetComponent();
	*room = section.GetRoom();
	roomConnected = section.GetConnectedRooms();
	groupId = section.groupId;
	hasRoom = section.hasRoom;
	hasPath = section.hasPath;
}
void MysteryDungeonMaker::MakePath()
{
	//ステップ1(部屋のあるセクションの上下左右をチェック)
	int sectionRowNum=dungeonSize->DungeonRowNum();
	int sectionColumnNum=dungeonSize->DungeonColumnNum();
	for (int i = 0; i < sectionRowNum; i++)
	{
		for (int j = 0; j < sectionColumnNum; j++)
		{
			if (sections[i][j].HasRoom())
			{
				for (int k = 0; k < 4; ++k)
				{
					int i_rota=i+up_down[k];
					int j_rota=j+right_left[k];
					if ((0 <= i_rota && i_rota < sectionRowNum) && (0 <= j_rota && j_rota < sectionColumnNum))
					{
						if (sections[i_rota][j_rota].HasRoom())
						{
							ConnectAdjacentRoom(&sections[i][j], &sections[i_rota][j_rota]);
						}
					}
				}
			}
		}
	}

	//ステップ2(部屋のないセクションの上下左右をチェック)
	for (int i = 0; i < sectionRowNum; i++)
	{
		for (int j = 0; j < sectionColumnNum; j++)
		{
			if ( ! sections[i][j].HasRoom())
			{
				std::vector<Section*> aroundSections;
				for (int k = 0; k < 4; ++k)
				{
					int i_rota = i + up_down[k];
					int j_rota = j + right_left[k];
					if ((0 <= i_rota && i_rota < sectionRowNum) && (0 <= j_rota && j_rota < sectionColumnNum))
					{
						if (sections[i_rota][j_rota].HasRoom())
							aroundSections.push_back(&sections[i_rota][j_rota]);
					}
				}

				if (aroundSections.size() == 2)
				{
					if( ! aroundSections[0]->isConnectedTo(*aroundSections[1]))
					{
						MakeRoom(Component(i, j), 1, 1);
						ConnectAdjacentRoom(&sections[i][j], aroundSections[0]);
						ConnectAdjacentRoom(&sections[i][j], aroundSections[1]);
						RemoveRoom(sections[i][j].GetRoom());
						sections[i][j].SetHasPath(true);
					}
				}
			}
		}
	}

	//ステップ3
	std::vector<std::vector<Section*>> groups = ClassifyGroups();
	std::vector<Component>route;
	while (groups.size() > 1)
	{
		DungeonMakerHelper::SortByGroupSize(&groups);
		for (size_t i = 0; i < groups[0].size(); i++)
		{
			route = SearchShortestRoute(*groups[0][i]);
			if ( ! route.empty())
				break;
		}
		
		if (!route.empty())
		{
			Component goal = route[route.size() - 1];
			for (size_t i = 0; i < route.size() - 1; i++)
			{
				if (route[i+1] != goal)
					MakeRoom(route[i + 1], 1, 1);

				Section* sectionMadeRoom = &sections[route[i + 1].i][route[i + 1].j];
				ConnectAdjacentRoom(&sections[route[i].i][route[i].j], sectionMadeRoom);
			}

			for (size_t i = 1; i < route.size() - 1; i++)
			{
				Section* roomRemoved = &sections[route[i].i][route[i].j];
				RemoveRoom(roomRemoved->GetRoom());
				roomRemoved->SetHasPath(true);
			}
		}

		ResetGroupId();
		groups = ClassifyGroups();
	}
}