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


C++ Coord::isInternalMap方法代码示例

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


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

示例1: moveTo

void cUObject::moveTo( const Coord& newpos )
{
	if ( pos_ == newpos )
	{
		return; // Nothing changed
	}

	// See if the map is valid
	if ( !newpos.isInternalMap() && !Maps::instance()->hasMap( newpos.map ) )
	{
		return;
	}

	// We're moved to the internal map although we're not on the internal map
	if ( newpos.isInternalMap() && !pos_.isInternalMap() )
	{
		MapObjects::instance()->remove( this ); // Remove from the sectors
		if ( multi_ )
		{
			multi_->removeObject( this );
			multi_ = 0;
		}
	}
	else if ( pos_.isInternalMap() && !newpos.isInternalMap() )
	{
		pos_ = newpos; // Add uses this coordinate internally
		MapObjects::instance()->add( this ); // Add to the sectors
	}
	else if ( !newpos.isInternalMap() )
	{
		MapObjects::instance()->update( this, newpos );
	}

	pos_ = newpos;
	changed_ = true;

	// We're not on an internal map
	if ( !pos_.isInternalMap() )
	{
		// Position Changed
		cMulti* multi = cMulti::find( newpos );
		// Don't put multis into themselves
		if ( multi != this && multi_ != multi )
		{
			if ( multi_ )
			{
				multi_->removeObject( this );
			}

			if ( multi )
			{
				multi->addObject( this );
			}

			multi_ = multi;
		}
	}
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:58,代码来源:uobject.cpp

示例2: sizeof

QList<unsigned char> cPathfinding::find(P_CHAR pChar, const Coord &from, const Coord &to)
{
	QList<unsigned char> result;
	int i;

	// We can only calculate a path on the normal maps and if the destination is not out of range
	if (from.isInternalMap() || from.distance(to) > (unsigned int)areaSize) {
		return result;
	}

	memset(touched, 0, sizeof(bool) * nodeCount); // Clear the touched nodes
	this->goal = to; // Save the goal

	// Actually th�s should be the x/y offset of our area
	xoffset = (from.x + to.x - areaSize) / 2;
	yoffset = (from.y + to.y - areaSize) / 2;

	int fromNode = getNodeIndex(from.x, from.y, from.z);
	int toNode = getNodeIndex(to.x, to.y, to.z);
	openlist = fromNode; // Where are we

	// Initialize the node
	nodes[fromNode].cost = 0;
	nodes[fromNode].total = heuristic(from.x - xoffset, from.y - yoffset, from.z);
	nodes[fromNode].parent = -1;
	nodes[fromNode].next = -1;
	nodes[fromNode].prev = -1;
	nodes[fromNode].z = from.z;

	// We touched this node
	onopen[fromNode] = true;
	touched[fromNode] = true;

	int depth = 0;
	int newTotal, newCost;

	// This is controlled by the npc moving. Some npcs can fly (move over impassables)
	// others can open doors
	ignoreDoors = false;
	ignoreMovableImpassables = false;
	int successors[8]; // List of successor nodes used in subsequent iterations. Never more than 8
	int successorCount; // Number of successors found

	while (openlist != -1) {
		if (++depth > maxDepth)
			break; // Break if we would exceed the maximum iteration count

		int bestnode = findBest(openlist);

		// Get adjacent nodes that we can walk to
		successorCount = getSuccessors(bestnode, pChar, successors);

		if (successorCount == 0) {
			break; // We've run into a situation where we'll never find a suitable successor
		}

		// Follow every possible successor
		for (i = 0; i < successorCount; ++i) {
			int successor = successors[i];

			if (touched[successor]) {
				continue; // If we worked on the node already, skip this part
			}

			// calculate the cost of the successor based on the currents node cost
			newCost = nodes[bestnode].cost + 1;
			newTotal = newCost + heuristic(successor % areaSize, (successor / areaSize) % areaSize, nodes[successor].z);

			// Always execute, !wasTouched was always true here
			// if ( !wasTouched || m_Nodes[newNode].total > newTotal )
			nodes[successor].parent = bestnode;
			nodes[successor].cost = newCost;
			nodes[successor].total = newTotal;
			addToChain(successor);

			// We found our target
			if (successor == toNode) {
				int pathCount = 0; // Stack allocation speed isn't a concern here anymore
				int parent = nodes[successor].parent;

				// Record the path in reverse order
				while (parent != -1) {
					path[pathCount++] = getDirection(parent % areaSize, (parent / areaSize) % areaSize, successor % areaSize, (successor / areaSize) % areaSize);
					successor = parent; // Track back
					parent = nodes[successor].parent;

					if (successor == fromNode) {
						break;
					}
				}

				int backtrack = 0;
				while (pathCount != 0) {
					result.append( path[--pathCount] );
				}
				return result; // Immediately return
			}
		}
	}

//.........这里部分代码省略.........
开发者ID:Mutilador,项目名称:Wolfpack,代码行数:101,代码来源:pathfinding.cpp


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