/*! 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; }