void CIntegralRotationDesc::InitRotationCount (int iCount) // InitRotationCount // // Initialize count { int i; // If we're in backwards compatibility mode and if we've got a different // count, then we need to recompute our degrees per tick. if (m_iManeuverability && iCount != m_iCount && iCount > 0) { m_rDegreesPerTick = (STD_SECONDS_PER_UPDATE * 360.0) / (iCount * m_iManeuverability); m_rAccelPerTick = m_rDegreesPerTick; m_rAccelPerTickStop = m_rDegreesPerTick; } // Initialize count m_iCount = iCount; m_Rotations.DeleteAll(); if (m_iCount > 0) { m_iMaxRotationRate = Max(1, mathRound(ROTATION_FRACTION * m_rDegreesPerTick * m_iCount / 360.0)); m_iRotationAccel = Max(1, mathRound(ROTATION_FRACTION * m_rAccelPerTick * m_iCount / 360.0)); m_iRotationAccelStop = Max(1, mathRound(ROTATION_FRACTION * m_rAccelPerTickStop * m_iCount / 360.0)); Metric rFrameAngle = 360.0 / m_iCount; m_Rotations.InsertEmpty(m_iCount); for (i = 0; i < m_iCount; i++) m_Rotations[i].iRotation = AngleMod(mathRound(90.0 - i * rFrameAngle)); } else { m_iMaxRotationRate = 0; m_iRotationAccel = 0; } }
void CIntegralRotation::UpdateAccel (const CIntegralRotationDesc &Desc, Metric rHullMass, Metric rItemMass) // UpdateAccel // // Recalculates rotation acceleration based on the mass of the ship. { // If we have no mass, then we just take the default acceleration if (rHullMass == 0.0) { m_iRotationAccel = Desc.GetRotationAccel(); m_iRotationAccelStop = Desc.GetRotationAccelStop(); m_iMaxRotationRate = Desc.GetMaxRotationSpeed(); } // Otherwise we compute based on the mass else { Metric rExtraMass = (rItemMass - rHullMass) * MANEUVER_MASS_FACTOR; // If we don't have too much extra mass, then rotation is not affected. if (rExtraMass <= 0.0) { m_iRotationAccel = Desc.GetRotationAccel(); m_iRotationAccelStop = Desc.GetRotationAccelStop(); m_iMaxRotationRate = Desc.GetMaxRotationSpeed(); return; } // Otherwise, we slow down Metric rRatio = 1.0f / Min(MAX_INERTIA_RATIO, (1.0f + (rExtraMass / rHullMass))); m_iRotationAccel = Max(1, (int)mathRound(rRatio * Desc.GetRotationAccel())); m_iRotationAccelStop = Max(1, (int)mathRound(rRatio * Desc.GetRotationAccelStop())); m_iMaxRotationRate = Max(1, (int)mathRound(pow(rRatio, 0.3) * Desc.GetMaxRotationSpeed())); } }
/** * Adjust the number data to be with the correct NUMERIC * DIGITS setting. * * @param numPtr The pointer to the start of the current numeric data. * @param result Where this should be copied back to after adjustment. * @param resultLen The length of the result area. Data is copied relative * to the end of the data. * @param digits The digits setting for the adjustment. * * @return The new number ptr after the copy. */ char *NumberStringBase::adjustNumber(char *numPtr, char *result, wholenumber_t resultLen, wholenumber_t digits) { // remove all leading zeros that might have occurred after the operation. numPtr = stripLeadingZeros(numPtr); // after stripping, is the length of the number larger than the digits setting? if (digitsCount > digits) { // NOTE: the original version had a bug where it was attempting to adjust the // exponent, but because it updated the length first, the net adjustment was zero. // I "fixed" this and completely broke the power operation. I really don't understand // why the exponent does not need adjusting here, but it appears it doesn't. // adjust the length down to the digits value digitsCount = digits; // round the number. mathRound(numPtr); } // copy the data into the result area, aligned with the end of the // buffer. We return the pointer to the new start of the number return (char *)memcpy(((result + resultLen - 1) - digitsCount), numPtr, digitsCount); }