Ejemplo n.º 1
0
void CHSDamCon::UnassignCrew(HS_DBREF player, int iCrew)
{
    // Be certain this is a valid crew ID.
    if ((iCrew < 1) || (iCrew > (int) GetNumCrews()))
    {
        return;
    }
    
    // Grab this crew's structure from the vector.
    THSDamageCrew & rtCrew = m_vecCrews[iCrew];
    // Only one crew can be assigned to a system at any one time.
    HS_INT32 iNumCrews = GetNumCrews();

    for (int idx = 0; idx < iNumCrews; idx++)
    {
        // If this crew is the one we're assigning, ignore it.
        if (idx == iCrew)
        {
            rtCrew.pAssignedTo = NULL;
            rtCrew.iSecondsLeft = 0;
            if (GetOwnerObject()->GetType() == HST_SHIP)
            {
                CHSShip *pOwnerShip = static_cast <CHSShip * >
                    (GetOwnerObject());

                pOwnerShip->NotifyConsoles(hsInterface.
                        HSPrintf(
                            "%s%s-%s Damage Control crew %i now available.",
                            ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, iCrew), 
                        MSG_ENGINEERING);
            }
        }
    }
}
Ejemplo n.º 2
0
void CHSJumpDrive::DoCycle()
{
    float rate;

    // Do base stuff first
    CHSEngSystem::DoCycle();

    // Charge jumpers?
    if ((GetCurrentPower() > 0) && (m_fChargeLevel < 100))
    {
        rate = GetChargeRate(true);

        if (rate > 0)
        {
            m_fChargeLevel += rate;

            // Make sure we don't overcharge
            if (m_fChargeLevel > 100)
            {
                m_fChargeLevel = 100;
            }

            if (m_fChargeLevel == 100)
            {
                if (GetOwnerObject()
                    && GetOwnerObject()->GetType() == HST_SHIP)
                {
                    CHSShip *cShip;
                    cShip = (CHSShip *) GetOwnerObject();
                    if (cShip)
                    {
                        cShip->NotifyConsoles(hsInterface.
                                              HSPrintf
                                              ("%s%s-%s Jump Drive charged.",
                                               ANSI_HILITE, ANSI_GREEN,
                                               ANSI_NORMAL), MSG_ENGINEERING);
                    }
                }
            }

        }
    }

    // If engaged, consume fuel.
    if (m_bEngaged)
    {
        ConsumeFuelBySpeed(m_uiSublightSpeed * m_iJumpSpeedMultiplier);
    }
}
Ejemplo n.º 3
0
void CHSDamCon::AssignCrew(HS_DBREF player, int iCrew, CHSEngSystem * pSystem)
{
    // Be certain this is a valid crew ID.
    if ((iCrew < 1) || (iCrew > (int) GetNumCrews()))
    {
        return;
    }

    // Grab this crew's structure from the vector.
    THSDamageCrew & rtCrew = m_vecCrews[iCrew];

    // If we're assigning to a valid system, try that.  
    // Otherwise, unassign this crew.
    if (pSystem)
    {
        // Only one crew can be assigned to a system at any one time.
        HS_INT32 iNumCrews = GetNumCrews();

        for (int idx = 0; idx < iNumCrews; idx++)
        {
            // If this crew is the one we're assigning, ignore it.
            if (idx == iCrew)
            {
                continue;
            }

            THSDamageCrew & rtAssignedCrew = m_vecCrews[idx];

            // Is this crew assigned to the system we want?
            if (rtAssignedCrew.pAssignedTo == pSystem)
            {
                hsStdError(player,
                           "A repair crew is already working on that system.");
                return;
            }
        }

        // This crew is now assigned.
        rtCrew.pAssignedTo = pSystem;
        rtCrew.iSecondsLeft = HSCONF.damage_repair_time;

        if (0 == rtCrew.iSecondsLeft)
        {
            rtCrew.iSecondsLeft = 1;
        }

        if (GetOwnerObject()->GetType() == HST_SHIP)
        {
            CHSShip *pOwnerShip = static_cast < CHSShip * >(GetOwnerObject());

            pOwnerShip->NotifyConsoles(hsInterface.
                                       HSPrintf
                                       ("%s%s-%s Damage Control crew %i assigned to %s.",
                                        ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL,
                                        iCrew, pSystem->GetName()),
                                       MSG_ENGINEERING);
        }
    }
    else
    {
        // This crew is unassigned.
        rtCrew.pAssignedTo = NULL;
        rtCrew.iSecondsLeft = 0;

        if (GetOwnerObject()->GetType() == HST_SHIP)
        {
            CHSShip *pOwnerShip = static_cast < CHSShip * >(GetOwnerObject());

            pOwnerShip->NotifyConsoles(hsInterface.
                                       HSPrintf
                                       ("%s%s-%s Damage Control crew %i now idle.",
                                        ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL,
                                        iCrew), MSG_ENGINEERING);
        }
    }
}
Ejemplo n.º 4
0
void CHSDamCon::DoCycle()
{
    // First we do the basic cycle, stress and such.
    CHSEngSystem::DoCycle();

    // Now we'll just go through our damage crews.
    HS_INT32 iEfficiency;
    HS_INT32 iRandNum;

    // Calculate percentage of power allocated to damage control.
    if (GetCurrentPower() != 0 && GetOptimalPower(false) != 0)
    {
        iEfficiency = (int) (100 * ((GetCurrentPower() * 1.00) /
                                    (GetOptimalPower(false) * 1.00)));
    }
    else
    {
        iEfficiency = 0;
    }

    iRandNum = hsInterface.GetRandom(99) + 1;

    // If we roll a random number greater than the power allocated to damage
    // control, then this round of damage control goes into the toilet.
    if (iRandNum > iEfficiency)
    {
        return;
    }

    // Insure that our number of crews matches the vector size.
    m_vecCrews.resize(GetNumCrews() + 1);

    // Run through all of our damage crews.
    // Those that are assigned get their time remaining reduced.
    unsigned int idx;
    for (idx = 1; idx <= GetNumCrews(); idx++)
    {
        THSDamageCrew & rtCrew = m_vecCrews[idx];

        // Is this crew working on anything?
        if (!rtCrew.pAssignedTo)
        {
            continue;
        }

        // This crew's time decreases.
        if (rtCrew.iSecondsLeft > 0)
        {
            rtCrew.iSecondsLeft--;
        }

        // If the crew is done working, reduce the damage on the system.
        if (rtCrew.iSecondsLeft <= 0)
        {
            rtCrew.pAssignedTo->ReduceDamage();

            // If this system is fully repaired, notify everyone, and pull this
            // crew off duty.
            if (rtCrew.pAssignedTo->GetDamageLevel() == DMG_NONE)
            {
                // If this system is part of a ship,
                // notify all consoles that repairs are complete.
                if (GetOwnerObject()->GetType() == HST_SHIP)
                {
                    CHSShip *pOwnerShip =
                        static_cast < CHSShip * >(GetOwnerObject());

                    pOwnerShip->NotifyConsoles(hsInterface.
                                               HSPrintf
                                               ("%s%s-%s %s repairs complete.",
                                                ANSI_HILITE, ANSI_GREEN,
                                                ANSI_NORMAL,
                                                rtCrew.pAssignedTo->
                                                GetName()), MSG_ENGINEERING);
                }

                // This crew is no longer assigned.
                rtCrew.pAssignedTo = NULL;
            }
            else
            {
                // This system is not repaired.  Reassign the crew to another
                // round of repairs.
                rtCrew.iSecondsLeft = HSCONF.damage_repair_time;

                if (0 == rtCrew.iSecondsLeft)
                {
                    rtCrew.iSecondsLeft = 1;
                }

                if (GetOwnerObject()->GetType() == HST_SHIP)
                {
                    CHSShip *pOwnerShip =
                        static_cast < CHSShip * >(GetOwnerObject());

                    pOwnerShip->NotifyConsoles(hsInterface.
                                               HSPrintf
                                               ("%s%s-%s %s repairs incomplete, continuing repairs.",
                                                ANSI_HILITE, ANSI_GREEN,
                                                ANSI_NORMAL,
                                                rtCrew.pAssignedTo->
                                                GetName()), MSG_ENGINEERING);
                }
            }
        }
    }
}