当前位置: 首页>>代码示例>>C++>>正文


C++ Town::Build方法代码示例

本文整理汇总了C++中Town::Build方法的典型用法代码示例。如果您正苦于以下问题:C++ Town::Build方法的具体用法?C++ Town::Build怎么用?C++ Town::Build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Town的用法示例。


在下文中一共展示了Town::Build方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

void
TownGenerator::Generate ()
{
	// STODO: have two options for building symmetry: symmetrical section placement and centered section placement.
	uint32 worldSize = WorldGeneratorAPI ()->GetWorldSize ();	
	uint32 numTownsLeft = 3; //(worldSize / (SECTOR_BLENGTH * 2)) + 1; // STODO: change this in future for larger maps
	uint32 numDungeonsLeft = 1;
	townSupportingAreas_ = WorldGeneratorAPI ()->GetTownSupportingAreas ();
	for( uint32 i = 0; i < townSupportingAreas_->GetCount(); ++i )
	{
		isSmoothedTownSupportingAreas_.InsertBack(false); // this ensures terrain is smoothed in a zone only once
	}

	// STODO: use this to shift the bounds of a town/dungeon away from sector borders
	townSupportingAreasSparseArray_ = WorldGeneratorAPI ()->GetTownSupportingAreasSparseArray (); 

	uint32 unsuccessfulAddCount = 0;
	while (numTownsLeft > 0 || numDungeonsLeft > 0)
	{
		if (townSupportingAreas_->GetCount () == 0)
			break;

		uint32 randIndex = rand () % townSupportingAreas_->GetCount ();

		// check if town is to be placed
		uint32 xMin = (townSupportingAreas_->GetElement (randIndex) % (worldSize / SECTOR_BLENGTH)) * SECTOR_BLENGTH;
		uint32 yMin = (townSupportingAreas_->GetElement (randIndex) / (worldSize / SECTOR_BLENGTH)) * SECTOR_BLENGTH;
		bool doLevelTerrain = !isSmoothedTownSupportingAreas_[randIndex];

		if (rand () % 2 == 0 && numDungeonsLeft > 0)
		{
			Dungeon* dungeon = new Dungeon (xMin, yMin, doLevelTerrain);
			isSmoothedTownSupportingAreas_[randIndex] = true;
			if (dungeon->PlaceBuildings ())
			{
				dungeon->Build ();
				dungeons_.InsertBack (dungeon);
				townSupportingAreas_->Remove (randIndex);
				isSmoothedTownSupportingAreas_.Remove( randIndex );
				--numDungeonsLeft;
			}
			else
			{
				delete dungeon;
				++unsuccessfulAddCount;
			}
		}
		else if (numTownsLeft > 0)
		{
			Town* town = new Town (xMin, yMin, doLevelTerrain);
			isSmoothedTownSupportingAreas_[randIndex] = true;
			if (town->PlaceBuildings ())
			{
				town->Build ();
				towns_.InsertBack (town);
				townSupportingAreas_->Remove (randIndex);
				isSmoothedTownSupportingAreas_.Remove( randIndex );
				--numTownsLeft;
			}
			else
			{
				delete town;
				++unsuccessfulAddCount;
			}
		}

		if (unsuccessfulAddCount > 25)
			break;
	}

	// STODO: this is preliminary code:
	// connect roads between town
	GetWorld()->BeginModify();
	RoadGenerator rGen;
	Vector<BaseArea*> areas;
	for( uint32 i = 0; i < towns_.GetCount(); ++i )
	{
		areas.InsertBack( towns_[i] );
	}
	for( uint32 i = 0; i < dungeons_.GetCount(); ++i )
	{
		areas.InsertBack( dungeons_[i] );
	}
	if( towns_.GetCount() >= 2 )
	{
		rGen.ConnectZones(ROAD_PRIMARY, towns_[0], towns_[1], 1.0f, &areas); // STODO: add avoidance points for all zones as well
		if( towns_.GetCount() >= 3 )
		{
			rGen.ConnectZones(ROAD_PRIMARY, towns_[0], towns_[2], 1.0f, &areas);
			rGen.ConnectZones(ROAD_PRIMARY, towns_[1], towns_[2], 1.0f, &areas);
		}
	}
	GetWorld()->EndModify();

	// DEBUG_TOWNGENERATOR:
	/*
	GetWorld()->BeginModify();
	AStar3D search;
	search.AllocMem( 150, 150, 120 );
	
//.........这里部分代码省略.........
开发者ID:smcbeth,项目名称:Example,代码行数:101,代码来源:towngenerator.cpp


注:本文中的Town::Build方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。