// Handles cyclic stuff for engines void CHSSysEngines::DoCycle() { HS_INT32 iFuel; // Do base class stuff first CHSEngSystem::DoCycle(); // Do anything? if (!m_current_speed && !GetCurrentPower()) { return; } // Change our speed if needed ChangeSpeed(); // Consume fuel. Yummy. if (m_current_speed) { iFuel = (HS_INT32) m_current_speed; if (GetAfterburning()) { iFuel *= HSCONF.afterburn_fuel_ratio; } ConsumeFuelBySpeed((HS_INT32) m_current_speed); } }
/** * Update function */ void ABatteryCollectorCharacter::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); // Check if current power is 0 and if it is then set to game over if (GetCurrentPower() <= 0) { SetGameOverFlag(true); } }
HS_UINT32 CHSSysEngines::GetMaxVelocity(HS_BOOL8 bAdjusted) { HS_FLOAT64 dmgperc; CHSSysEngines *ptr; HS_UINT32 uVal; HS_INT32 iOptPower; // Use some logic here. if (!m_puiMaxVelocity) { // Go to the parent's setting? if (!GetParent()) { return 0; } else { // Yes, this system exists on a ship, so // find the default values on the parent. ptr = (CHSSysEngines *) GetParent(); uVal = ptr->GetMaxVelocity(false); } } else uVal = *m_puiMaxVelocity; // Make overloading and damage adjustments? if (bAdjusted) { // At this point, uVal is the maximum velocity assuming // 100% power level. We have to adjust for power level // now. The speed inrcreases proportional to overload // percentage. HS_FLOAT32 fVal; iOptPower = GetOptimalPower(true); fVal = (HS_FLOAT32) GetCurrentPower(); fVal /= (HS_FLOAT32) iOptPower; uVal = (HS_UINT32) (fVal * uVal); // Figure in damage. 1/4 reduction per level of damage dmgperc = 1 - (.25 * GetDamageLevel()); uVal = (HS_UINT32) (uVal * dmgperc); // Do we have a fuel system? if (GetFuelSource()) { if (GetFuelSource()->GetFuelRemaining() <= 0) return 0; } } return uVal; }
// Returns the acceleration rate for the engines. If the // bAdjusted variable is set to false, no damage or power level // adjustments are made. HS_UINT32 CHSSysEngines::GetAcceleration(HS_BOOL8 bAdjusted) { double dmgperc; CHSSysEngines *ptr; HS_UINT32 uVal; HS_INT32 iOptPower; // Use some logic here. if (!m_puiAcceleration) { // Go to the parent's setting? if (!GetParent()) { // No. We are the default values. return 0; } else { // Yes, this system exists on a ship, so // find the default values on the parent. ptr = (CHSSysEngines *) GetParent(); uVal = ptr->GetAcceleration(false); } } else { uVal = *m_puiAcceleration; } // Make overloading and damage adjustments? if (bAdjusted) { // If afterburning, acceleration is increased // like speed. if (GetAfterburning()) { uVal *= m_iAfterburnRatio; //HSCONF.afterburn_ratio; } float fVal; iOptPower = GetOptimalPower(false); fVal = (float) GetCurrentPower(); fVal /= (float) iOptPower; uVal = (HS_UINT32) (uVal * fVal); // Figure in damage. 1/4 reduction per level of damage dmgperc = 1 - (.25 * GetDamageLevel()); uVal = (HS_UINT32) (uVal * dmgperc); } return uVal; }
float CHSSysCloak::GetEfficiency(HS_BOOL8 bAdjusted) { float rval; // Do we have a local value? if (!m_efficiency) { // Do we have a parent? if (GetParent()) { CHSSysCloak *ptr; ptr = (CHSSysCloak *) GetParent(); rval = ptr->GetEfficiency(false); } else return 0; // default of 1000 (1k) } else { rval = *m_efficiency; } if (bAdjusted) { float fVal; int iOptPower; iOptPower = GetOptimalPower(false); fVal = (float) GetCurrentPower(); if (iOptPower) { fVal /= (float) iOptPower; } else { fVal = 1.00; } rval *= fVal; if (rval > 100) { rval = (float) 99.999999; } } return rval; }
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); } }
HS_INT8 *CHSJumpDrive::GetStatus() { static HS_INT8 tbuf[32]; if (m_fChargeLevel == 100) { return "Charged"; } else if (GetCurrentPower() <= 0) { return "Offline"; } else { sprintf(tbuf, "%.0f/100%%", m_fChargeLevel); return tbuf; } }
// Returns the turning rate for the thrusters system. If bAdjusted // is set to false, then the maximum raw turning rate is returned, // otherwise, it is adjusted for damage and power levels. HS_UINT32 CHSSysThrusters::GetRate(HS_BOOL8 bAdjusted) { double dmgperc; CHSSysThrusters *ptr; HS_UINT32 uVal; int iOptPower; // Use some logic here. if (!m_puiTurningRate) { // Go to the parent's setting? if (!GetParent()) { // No. We are the default values. return 0; } else { // Yes, this system exists on a ship, so // find the default values on the parent. ptr = (CHSSysThrusters *) GetParent(); uVal = ptr->GetRate(false); } } else uVal = *m_puiTurningRate; // Make overloading and damage adjustments? if (bAdjusted) { float fVal; iOptPower = GetOptimalPower(false); fVal = (float) GetCurrentPower(); fVal /= (float) iOptPower; uVal = (HS_UINT32) (uVal * fVal); // Figure in damage. 1/4 reduction per level of damage dmgperc = 1 - (.25 * GetDamageLevel()); uVal = (HS_UINT32) (uVal * dmgperc); } return uVal; }
// Returns the charge rate for the jump drives. If bAdjusted // is set to true, damage and power level adjustements are // made to the value before returning it. float CHSJumpDrive::GetChargeRate(HS_BOOL8 bAdjusted) { float rate; // Base rate of 1/2 percent per second rate = 0.5; // Adjust? if (bAdjusted) { // Damage adjustment rate *= 1 - ((float) .25 * GetDamageLevel()); // Power adjustment. Add .00001 just in case // optimal power is 0. float fPower; fPower = (float) (GetOptimalPower(false) + .00001); fPower = GetCurrentPower() / fPower; rate *= fPower; } return rate; }
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); } } } } }