Пример #1
0
ViceVehicle::ViceVehicle(SCRIPT_MISSION* pMission, DWORD dwModel, VCPosition_t position, bool bKeepOnDestroy)
{
	m_pMission = pMission;
	m_bKeepOnDestroy = bKeepOnDestroy;
	ViceModel::LoadOne(pMission, dwModel);
	$(&create_car, dwModel, position.x, position.y, position.z, &m_dwVehicle);
	ZAngle(position.a);
}
Пример #2
0
// Changes the heading of the missile to head toward the target.
void CHSMissile::ChangeHeading()
{
    HS_BOOL8 bChange;           // Indicates if any turning has occurred;

    if (!m_pData)
    {
        return;
    }

    // Calculate X, Y, and Z difference vector
    static double tX = 0.0, tY = 0.0, tZ = 0.0;

    if(NULL != m_target && HST_SHIP == m_target->GetType())
    {

        // get value from 0.0 - 1.0 where 1.0 is 100% visible
        float cloak_effect =
            static_cast<CHSShip* >(m_target)->CloakingEffect() * 100;

        // If the random value is less than the cloaking effect,
        // the missile still sees the ship and can update its
        // coordinates, otherwise, leave them at the previous
        // location
        if(hsInterface.GetRandom(100) <= (HS_UINT32) cloak_effect)
        {
            tX = m_target->GetX();
            tY = m_target->GetY();
            tZ = m_target->GetZ();
        }
    }
    else
    {
        tX = m_target->GetX();
        tY = m_target->GetY();
        tZ = m_target->GetZ();
    }

    HS_INT32 xyang = XYAngle(m_x, m_y, tX, tY);
    HS_INT32 zang = ZAngle(m_x, m_y, m_z, tX, tY, tZ);

    // Get the turn rate
    HS_INT32 iTurnRate = m_turnrate;

    bChange = false;

    // Check for change in zheading
    if (zang != m_zheading)
    {
        if (zang > m_zheading)
        {
            if ((zang - m_zheading) > iTurnRate)
                m_zheading += iTurnRate;
            else
                m_zheading = zang;
        }
        else
        {
            if ((m_zheading - zang) > iTurnRate)
                m_zheading -= iTurnRate;
            else
                m_zheading = zang;
        }
        bChange = true;
    }

    // Now handle any changes in the XY plane.
    HS_INT32 iDiff;
    if (xyang != m_xyheading)
    {
        if (abs(m_xyheading - xyang) < 180)
        {
            if (abs(m_xyheading - xyang) < iTurnRate)
                m_xyheading = xyang;
            else if (m_xyheading > xyang)
            {
                m_xyheading -= iTurnRate;

                if (m_xyheading < 0)
                    m_xyheading += 360;
            }
            else
            {
                m_xyheading += iTurnRate;

                if (m_xyheading > 359)
                    m_xyheading -= 360;
            }
        }
        else if (((360 - xyang) + m_xyheading) < 180)
        {
            iDiff = (360 - xyang) + m_xyheading;
            if (iDiff < iTurnRate)
            {
                m_xyheading = xyang;
            }
            else
            {
                m_xyheading -= iTurnRate;

                if (m_xyheading < 0)
                    m_xyheading += 360;
            }
        }
        else if (((360 - m_xyheading) + xyang) < 180)
        {
            iDiff = (360 - m_xyheading) + xyang;
            if (iDiff < iTurnRate)
            {
                m_xyheading = xyang;
            }
            else
            {
                m_xyheading += iTurnRate;

                if (m_xyheading > 359)
                    m_xyheading -= 360;
            }
        }
        else                    // This should never be true, but just in case.
        {
            m_xyheading += iTurnRate;

            if (m_xyheading > 359)
                m_xyheading -= 360;
        }
        bChange = true;
    }

    // Check to see if we need to recompute trajectory.
    if (bChange)
    {
        zang = m_zheading;
        if (zang < 0)
            zang += 360;

        CHSVector tvec(d2sin_table[m_xyheading] * d2cos_table[zang],
                       d2cos_table[m_xyheading] * d2cos_table[zang],
                       d2sin_table[zang]);
        m_motion_vector = tvec;
    }
}