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


C++ P_PLAYER::maxWeight方法代码示例

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


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

示例1: consumeStamina

/*!
  Calculates the amount of Stamina needed for a move of the
  passed character.
*/
bool cMovement::consumeStamina( P_PLAYER pChar, bool running )
{
	// Dead people and gms don't care about weight
	if ( pChar->isDead() || pChar->isGMorCounselor() )
	{
		return true;
	}

	// Calculate the stones we weight too much
	int overWeight = ( int ) ( pChar->weight() - pChar->maxWeight() );
	bool mounted = pChar->atLayer( cBaseChar::Mount ) != 0;
	bool update = false;

	// We carry too much
	if ( overWeight > 0 )
	{
		// How much stamina we loose
		int amount = 5 + ( overWeight / 25 );

		// Only one third loss if mounted
		if ( mounted )
		{
			amount = amount / 3;
		}

		// Double loss if running
		if ( running )
		{
			amount = amount * 2;
		}

		// Set the new stamina
		pChar->setStamina( wpMax<Q_INT16>( 0, pChar->stamina() - amount ), false );
		update = true;

		// We are overloaded
		if ( pChar->stamina() == 0 )
		{
			pChar->socket()->updateStamina();
			pChar->socket()->clilocMessage( 500109 );
			return false;
		}
	}

	// If we have less than 10% stamina left, we loose
	// stamina more quickly
	if ( ( pChar->stamina() * 100 ) / wpMax<ushort>( 1, pChar->maxStamina() ) < 10 )
	{
		pChar->setStamina( wpMax<Q_INT16>( 0, pChar->stamina() - 1 ), false );
		update = true;
	}

	// We can't move anymore because we are exhausted
	if ( pChar->stamina() == 0 )
	{
		pChar->socket()->updateStamina();
		pChar->socket()->clilocMessage( 500110 );
		return false;
	}

	// Normally reduce stamina every few steps
	if ( pChar->stepsTaken() % ( mounted ? 48 : 16 ) == 0 )
	{
		pChar->setStamina( wpMax<Q_INT16>( 0, pChar->stamina() - 1 ) );
		update = true;
	}

	if ( update )
	{
		pChar->socket()->updateStamina();
	}

	return true;
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:78,代码来源:walking.cpp


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