Skip to content
Open

1.9.6 #391

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Alchemy/Include/KernelExceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ class CException
// Just manually look it up on this page:
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55
//
// If the code doesnt exist there, it may be customer defined.
// If the code doesnt exist there, it may be customer defined. (Customer = non-microsoft code, usually drivers)
// We can output some basic metadata about the code too based on the code structure.
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/87fba13e-bf06-450e-83b1-9241dc81e781
//
// (Note that this doesnt care about endianness, it is always in this exact bit order
// Field masks:
// 0b 1100 0000 0000 0000 0000 0000 0000 0000 - severity 00 = success, 01 = info, 10 = warning, 11 = error
// 0b 0010 0000 0000 0000 0000 0000 0000 0000 - 0 = microsoft 1 = customer
// 0b 0010 0000 0000 0000 0000 0000 0000 0000 - 0 = microsoft 1 = customer (3rd party, usually drivers)
// 0b 0001 0000 0000 0000 0000 0000 0000 0000 - reserved (should always be 0!)
// 0b 0000 1111 1111 1111 0000 0000 0000 0000 - facility - indicates numbering space for the code field
// 0b 0000 0000 0000 0000 1111 1111 1111 1111 - code
Expand All @@ -209,7 +209,7 @@ class CException
else if (i == 2)
{
BYTE bySeverity = dwInfo >> 30 & 0x03;
BYTE byCustomer = dwInfo >> 29 & 0x01;
BYTE byCustomer = dwInfo >> 29 & 0x01; // False if microsoft code, True if 3rd party code (ex, drivers)
BYTE byReserved = dwInfo >> 28 & 0x01; // we check this bit in case of invalid customer-set codes or memory corruption
WORD wFacility = dwInfo >> 16 & 0x0FFF;
WORD wCode = dwInfo & 0x0000FFFF;
Expand All @@ -219,30 +219,30 @@ class CException
{
case (0b00):
{
CONSTLIT("SUCCESS");
sSeverity = CONSTLIT("SUCCESS");
break;
}
case (0b01):
{
CONSTLIT("INFO");
sSeverity = CONSTLIT("INFO");
break;
}
case (0b10):
{
CONSTLIT("WARNING");
sSeverity = CONSTLIT("WARNING");
break;
}
case (0b11):
{
CONSTLIT("ERROR");
sSeverity = CONSTLIT("ERROR");
break;
}
default:
CONSTLIT("INVALID");
sSeverity = CONSTLIT("INVALID");
}
CString sCustomer = byCustomer ? CONSTLIT("Customer") : CONSTLIT("Microsoft");
CString sSource = byCustomer ? CONSTLIT("3rd-Party") : CONSTLIT("Microsoft");
CString sBad = byReserved ? CONSTLIT("Invalid") : CONSTLIT("");
m_sMsg = strCat(m_sMsg, strPatternSubst(CONSTLIT(" - NTSTATUS: %x %s (Code by: %s Severity: %s Facility: %x Code: %x)"), dwInfo));
m_sMsg = strCat(m_sMsg, strPatternSubst(CONSTLIT(" - NTSTATUS: %x (Code by: %s Severity: %s Facility: %x Code: %x)"), dwInfo, sSource, sSeverity, wFacility, wCode));
}

// everything after this if in the array is junk
Expand Down
66 changes: 49 additions & 17 deletions Alchemy/Kernel/CString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2856,40 +2856,72 @@ CString Kernel::strRomanNumeral (int i)
}
}

double Kernel::strToDouble (const CString &sString, double rFailResult, bool *retbFailed)

// strToDouble
//
// Converts a string to a double
// Handles Hexadecimal ints as well
//
// Special cases:
// Invalid conversion:
// returns: rFailResult
// retbFailed: true
// Overflow: (ex, 1e500)
// returns: R_INF or R_NINF
// retbFailed: true
// Underflow: (ex, 1e-500)
// returns: 0
// retbFailed: true
// Explicity infinity: (Ex, "-infinity")
// returns: R_INF or R_NINF
// retbFailed: false
// Explicit NaN: (Ex, "nan" or "nan(\"SpecificNaN\")")
// returns: R_NAN
// retbFailed: false
//
// See strtod for more information
//
double Kernel::strToDouble (const CString &sString, double rFailResult, bool *retbFailed)

{
// Check to see if this is a hex integer
// strtod handles hexadecimal natively as well

char *pPos = sString.GetASCIIZPointer();
if (sString.GetLength() > 2
&& pPos[0] == '0'
&& (pPos[1] == 'x' || pPos[1] == 'X'))

char *pStop = NULL;
errno = 0;

double rResult = ::strtod(pPos, &pStop);

// Handle fail case: invalid conversion

if (pPos == pStop || *pStop != '\0')
{
bool bFailed;
DWORD dwValue = strToInt(sString, 0, &bFailed);
if (retbFailed) *retbFailed = bFailed;
return (bFailed ? rFailResult : (double)dwValue);
if (retbFailed)
*retbFailed = true;
return rFailResult;
}

// Assume a float
// It correctly handles underflows by returning INFINITIES or 0
// We return these but set retbFailed because it was NOT an explicit
// infinity or 0

double rResult = ::atof(sString.GetASCIIZPointer());
if (_isnan(rResult))
else if (errno == ERANGE)
{
if (retbFailed)
*retbFailed = true;
return rFailResult;
return rResult;
}

if (retbFailed)
*retbFailed = false;
// Otherwise we succeeded. If we get a nan or infinity
// its because someone explicitly set that in the string.

else
{
if (retbFailed)
*retbFailed = false;

return rResult;
return rResult;
}
}

CString Kernel::strToFilename (const CString &sString)
Expand Down
3 changes: 2 additions & 1 deletion Mammoth/Include/TSE.h
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ class CSpaceObject
virtual CString GetObjClassName (void) const { return CONSTLIT("unknown"); }
virtual Metric GetParallaxDist (void) { return 0.0; }
virtual EDamageResults GetPassthroughDefault (void) { return damageNoDamage; }
virtual int GetPlanetarySize (void) const { return 0; }
virtual int GetPlanetarySize (void) const { return 0; }
virtual ScaleTypes GetScale (void) const { return scaleFlotsam; }
virtual CSovereign *GetSovereign (void) const { return NULL; }
virtual Metric GetStellarMass (void) const { return 0.0; }
Expand Down Expand Up @@ -1307,6 +1307,7 @@ class CSpaceObject
virtual int GetMaxLightDistance (void) const { return 0; }
virtual Metric GetMaxWeaponRange (void) const { return 0.0; }
virtual int GetPerception (void) const { return perceptNormal; }
virtual int GetRelativeHealth () const { return INT_MAX; }
virtual int GetScore (void) { return 0; }
virtual CG32bitPixel GetSpaceColor (void) { return 0; }
virtual int GetStealth (void) const { return stealthNormal; }
Expand Down
2 changes: 2 additions & 0 deletions Mammoth/Include/TSEItemEnhancements.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class CItemEnhancement
DWORD GetModCode (void) const { return m_dwMods; }
int GetPerceptionAdj () const;
int GetPowerAdj (void) const;
int GetActivePowerAdj (void) const;
int GetReflectChance (DamageTypes iDamage) const;
Metric GetRegen180 (CItemCtx &Ctx, int iTicksPerUpdate) const;
int GetResistEnergyAdj (void) const { return (GetType() == etResistEnergy ? Level2DamageAdj(GetLevel(), IsDisadvantage()) : 100); }
Expand Down Expand Up @@ -273,6 +274,7 @@ class CItemEnhancementStack
int GetManeuverRate (void) const;
int GetPerceptionAdj () const;
int GetPowerAdj (void) const;
int GetActivePowerAdj (void) const;
int GetResistDamageAdj (DamageTypes iDamage) const;
int GetResistEnergyAdj (void) const;
int GetResistMatterAdj (void) const;
Expand Down
2 changes: 1 addition & 1 deletion Mammoth/Include/TSEPhysics.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CPhysicsForceResolver
struct SForceDesc
{
CSpaceObject *pObj = NULL;
CVector vForce; // Absolute acceleration
CVector vForce; // Force to apply
CVector vLimitedForce; // Accelerate only if below max speed.
Metric rDragFactor = 1.0; // Final velocity gets multiplied by this.
};
Expand Down
2 changes: 2 additions & 0 deletions Mammoth/Include/TSEPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,15 @@ class IPlayerController
virtual ICCItem *CreateGlobalRef (CCodeChain &CC) { return CC.CreateInteger((int)this); }
virtual CPlayerGameStats *GetGameStats (void) const { return NULL; }
virtual GenomeTypes GetGenome (void) const { return genomeUnknown; }
virtual DWORD GetLastWarningTick () const { return 0; }
virtual CString GetName (void) const { return NULL_STR; }
virtual bool GetPropertyInteger (const CString &sProperty, int *retiValue) { return false; }
virtual bool GetPropertyItemList (const CString &sProperty, CItemList *retItemList) { return false; }
virtual bool GetPropertyString (const CString &sProperty, CString *retsValue) { return false; }
virtual CSovereign *GetSovereign (void) const;
virtual EUIMode GetUIMode (void) const { return uimodeUnknown; }
virtual void OnMessageFromObj (const CSpaceObject *pSender, const CString &sMessage) { }
virtual void SetLastWarningTick (DWORD dwTick) { }
virtual bool SetPropertyInteger (const CString &sProperty, int iValue) { return false; }
virtual bool SetPropertyItemList (const CString &sProperty, const CItemList &ItemList) { return false; }
virtual bool SetPropertyString (const CString &sProperty, const CString &sValue) { return false; }
Expand Down
6 changes: 6 additions & 0 deletions Mammoth/Include/TSEShipAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,5 +527,11 @@ class COrderDesc
class CShipAIHelper
{
public:
// When adjusting formation positions, we cheat by this factor if we're
// really close.

static constexpr Metric CHEAT_FORMATION_FACTOR = 0.2;

static void ApplyFormationAccel (CShip& Ship, const CVector& vVel, Metric rCheatThrustFactor = CHEAT_FORMATION_FACTOR);
static bool CalcFormationParams (CShip *pShip, const CVector &vDestPos, const CVector &vDestVel, CVector *retvRecommendedVel, Metric *retrDeltaPos2 = NULL, Metric *retrDeltaVel2 = NULL);
};
24 changes: 14 additions & 10 deletions Mammoth/Include/TSEShipSystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,21 +514,25 @@ class CIntegralRotationDesc

static constexpr int ROTATION_FRACTION = 1080;

CIntegralRotationDesc (void) { }
CIntegralRotationDesc () { }
explicit CIntegralRotationDesc (const CRotationDesc &Desc) { InitFromDesc(Desc); }

int AlignToRotationAngle (int iAngle) const { return GetRotationAngle(GetFrameIndex(iAngle)); }
int CalcFinalRotationFrame (int iRotationFrame, int iRotationSpeed) const;
int GetFrameAngle (void) const { return (m_iCount > 0 ? mathRound(360.0 / m_iCount) : 0); }
int GetFrameCount (void) const { return m_iCount; }
int GetFrameAngle () const { return (m_iCount > 0 ? mathRound(360.0 / m_iCount) : 0); }
int GetFrameCount () const { return m_iCount; }
int GetFrameIndex (int iAngle) const { return (m_iCount > 0 ? (m_FacingsData[m_iCount].AngleToFrameIndex[AngleMod(iAngle)]) : 0); }
int GetManeuverDelay (void) const;
Metric GetManeuverRatio (void) const { return (Metric)m_iMaxRotationRate / ROTATION_FRACTION; }
int GetMaxRotationSpeed (void) const { return m_iMaxRotationRate; }
Metric GetMaxRotationSpeedDegrees (void) const;
int GetMaxRotationTimeTicks (void) const { Metric rSpeed = GetMaxRotationSpeedDegrees(); return (rSpeed > 0.0 ? (int)(360.0 / rSpeed) : 0); }
int GetRotationAccel (void) const { return m_iRotationAccel; }
int GetRotationAccelStop (void) const { return m_iRotationAccelStop; }
int GetManeuverDelay () const;
Metric GetManeuverRatio () const { return (Metric)m_iMaxRotationRate / ROTATION_FRACTION; }
int GetMaxRotationSpeed () const { return m_iMaxRotationRate; }
Metric GetMaxRotationSpeedDegrees () const;
int GetMaxRotationTimeTicks () const { Metric rSpeed = GetMaxRotationSpeedDegrees(); return (rSpeed > 0.0 ? (int)(360.0 / rSpeed) : 0); }
int GetRotationAccel () const { return m_iRotationAccel; }
Metric GetRotationAccelDegrees () const;
int GetRotationAccelStop () const { return m_iRotationAccelStop; }
Metric GetRotationAccelStopDegrees () const;
int GetRotationResponsiveness () const { return min(m_iMaxRotationRate, min(m_iRotationAccel, m_iRotationAccelStop)); }
Metric GetRotationResponsivenessDegrees () const;
int GetRotationAngle (int iIndex) const { return (m_iCount > 0 ? m_FacingsData[m_iCount].FrameIndexToAngle[iIndex % m_iCount] : 0); }
int GetRotationAngleExact (int iRotationFrameExact) const { return (m_iCount > 0 ? GetRotationAngleExact(m_iCount, iRotationFrameExact) : 0); }
int GetRotationFrameExact (int iAngle) const { return (m_iCount > 0 ? GetRotationFrameExact(m_iCount, iAngle) : 0); }
Expand Down
7 changes: 7 additions & 0 deletions Mammoth/Include/TSESpaceObjectsImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CAreaDamage : public TSpaceObjectImpl<OBJID_CAREADAMAGE>
virtual CString GetNamePattern (DWORD dwNounPhraseFlags = 0, DWORD *retdwFlags = NULL) const override;
virtual CString GetObjClassName (void) const override { return CONSTLIT("CAreaDamage"); }
virtual CSystem::LayerEnum GetPaintLayer (void) const override { return CSystem::layerEffects; }
virtual int GetRelativeHealth () const override { return IsDestroyed() ? -1 : INT_MAX; }
virtual CSpaceObject *GetSecondarySource (void) const override { return m_Source.GetSecondaryObj(); }
virtual CSovereign *GetSovereign (void) const override { return m_pSovereign; }
virtual CDesignType *GetType (void) const override { return m_pDesc->GetWeaponType(); }
Expand Down Expand Up @@ -80,6 +81,7 @@ class CBeam : public TSpaceObjectImpl<OBJID_CBEAM>
virtual CString GetNamePattern (DWORD dwNounPhraseFlags = 0, DWORD *retdwFlags = NULL) const override;
virtual CString GetObjClassName (void) const override { return CONSTLIT("CBeam"); }
virtual CSystem::LayerEnum GetPaintLayer (void) const override { return CSystem::layerStations; }
virtual int GetRelativeHealth () const override { return IsDestroyed() ? -1 : 100; }
virtual CSpaceObject *GetSecondarySource (void) const override { return m_Source.GetSecondaryObj(); }
virtual CSovereign *GetSovereign (void) const override { return m_pSovereign; }
virtual const CWeaponFireDesc *GetWeaponFireDesc (void) const override { return m_pDesc; }
Expand Down Expand Up @@ -169,6 +171,7 @@ class CContinuousBeam : public TSpaceObjectImpl<OBJID_CCONTINUOUSBEAM>
virtual CString GetNamePattern (DWORD dwNounPhraseFlags = 0, DWORD *retdwFlags = NULL) const override;
virtual CString GetObjClassName (void) const override { return CONSTLIT("CContinuousBeam"); }
virtual CSystem::LayerEnum GetPaintLayer (void) const override { return CSystem::layerEffects; }
virtual int GetRelativeHealth () const override { return IsDestroyed() ? -1 : INT_MAX; }
virtual int GetRotation (void) const override { return m_iLastDirection; }
virtual CSpaceObject *GetSecondarySource (void) const override { return m_Source.GetSecondaryObj(); }
virtual CSovereign *GetSovereign (void) const override { return m_pSovereign; }
Expand Down Expand Up @@ -548,6 +551,7 @@ class CMissile : public TSpaceObjectImpl<OBJID_CMISSILE>
virtual COverlayList *GetOverlays (void) override { return &m_Overlays; }
virtual const COverlayList *GetOverlays (void) const override { return &m_Overlays; }
virtual CSystem::LayerEnum GetPaintLayer (void) const override { return (m_pDesc->GetPassthrough() > 0 ? CSystem::layerEffects : CSystem::layerStations); }
virtual int GetRelativeHealth () const override { return IsDestroyed() ? -1 : (m_pDesc->GetHitPoints() ? min(100, mathRound((Metric)m_iHitPoints / m_pDesc->GetHitPoints())) : 100); }
virtual int GetRotation (void) const override { return m_iRotation; }
virtual CSpaceObject *GetSecondarySource (void) const override { return m_Source.GetSecondaryObj(); }
virtual CSovereign *GetSovereign (void) const override { return m_pSovereign; }
Expand Down Expand Up @@ -651,6 +655,7 @@ class CParticleDamage : public TSpaceObjectImpl<OBJID_CPARTICLEDAMAGE>
virtual CString GetNamePattern (DWORD dwNounPhraseFlags = 0, DWORD *retdwFlags = NULL) const override;
virtual CString GetObjClassName (void) const override { return CONSTLIT("CParticleDamage"); }
virtual CSystem::LayerEnum GetPaintLayer (void) const override { return CSystem::layerEffects; }
virtual int GetRelativeHealth () const override { return IsDestroyed() ? -1 : INT_MAX; }
virtual CSpaceObject *GetSecondarySource (void) const override { return m_Source.GetSecondaryObj(); }
virtual CSovereign *GetSovereign (void) const override { return m_pSovereign; }
virtual CDesignType *GetType (void) const override { return m_pDesc->GetWeaponType(); }
Expand Down Expand Up @@ -934,6 +939,7 @@ class CRadiusDamage : public TSpaceObjectImpl<OBJID_CRADIUSDAMAGE>
virtual CString GetNamePattern (DWORD dwNounPhraseFlags = 0, DWORD *retdwFlags = NULL) const override;
virtual CString GetObjClassName (void) const override { return CONSTLIT("CRadiusDamage"); }
virtual CSystem::LayerEnum GetPaintLayer (void) const override { return CSystem::layerEffects; }
virtual int GetRelativeHealth () const override { return IsDestroyed() ? -1 : INT_MAX; }
virtual CSpaceObject *GetSecondarySource (void) const override { return m_Source.GetSecondaryObj(); }
virtual CSovereign *GetSovereign (void) const override { return m_pSovereign; }
virtual CDesignType *GetType (void) const override { return m_pDesc->GetWeaponType(); }
Expand Down Expand Up @@ -1206,6 +1212,7 @@ class CShip : public TSpaceObjectImpl<OBJID_CSHIP>
virtual CSystem::LayerEnum GetPaintLayer (void) const override { return (m_fShipCompartment ? CSystem::layerOverhang : CSystem::layerShips); }
virtual int GetPerception (void) const override;
virtual ICCItem *GetPropertyCompatible (CCodeChainCtx &Ctx, const CString &sName) const override;
virtual int GetRelativeHealth () const override;
virtual int GetRotation (void) const override { return m_Rotation.GetRotationAngle(m_Perf.GetIntegralRotationDesc()); }
virtual int GetRotationFrameIndex (void) const override { return m_Rotation.GetFrameIndex(); }
virtual ScaleTypes GetScale (void) const override { return scaleShip; }
Expand Down
1 change: 1 addition & 0 deletions Mammoth/Include/TSEStationImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class CStation : public TSpaceObjectImpl<OBJID_CSTATION>
virtual int GetPlanetarySize (void) const override { return (GetScale() == scaleWorld ? m_pType->GetSize() : 0); }
virtual ICCItem *GetPropertyCompatible (CCodeChainCtx &Ctx, const CString &sName) const override;
virtual IShipGenerator *GetRandomEncounterTable (int *retiFrequency = NULL) const override;
virtual int GetRelativeHealth () const override;
virtual int GetRotation (void) const override;
virtual ScaleTypes GetScale (void) const override { return m_Scale; }
virtual CXMLElement *GetScreen (const CString &sName) override { return m_pType->GetScreen(sName); }
Expand Down
Loading