Ejemplo n.º 1
0
int Weave::CalculatePositivePower(const ROOM_INDEX_DATA & room)
{
    // Check the room
    if (room.fount_positive_power != 0)
        return room.fount_positive_power;

   // Determine bias; this is where things like seasonal modifiers go
   int bias(room.area->fount_positive_bias);
   return CalculatePower(bias);
}
// Calculate power of matrix
ComplexMatrix CalculatePower(const ComplexMatrix &A, int n)
{
    assert(n >= 0);

    ComplexMatrix B(A.mNumRows, A.mNumCols);

    if (n == 0)
    {
        for (int i = 0; i < A.mNumRows; i++)
        {
            for (int j = 0; j < A.mNumCols; j++)
            {
                B.mMemory[i][j] = A.mMemory[i][j].CalculatePower(0);
            }
        }

        return B;
    }

    else if (n == 1)
    {
        return A;
    }

    else if (n % 2 == 0)
        // is even
    {
        return CalculatePower(A * A, n / 2);
    }

    else if (n % 2 != 0)
        // is odd
    {
        return A * CalculatePower(A * A, (n - 1) / 2);
    }
}