Example #1
0
void CTextPainter::OnReadFromStream (SLoadCtx &Ctx)

//	OnReadFromStream
//
//	Reads from a stream
//
//	CString			m_sText

	{
	m_sText.ReadFromStream(Ctx.pStream);
	MeasureText();
	}
Example #2
0
ALERROR IEffectPainter::ValidateClass (SLoadCtx &Ctx, const CString &sOriginalClass)

//	ValidateClass
//
//	Reads the class string. If the class does not match the current painter,
//	we read the old data and return ERR_FAIL.

	{
	if (Ctx.dwVersion >= 40)
		{
		CString sClass;
		sClass.ReadFromStream(Ctx.pStream);

		//	If the original class doesn't match the current one, then it means
		//	that the design changed. In that case, we load the painter using the
		//	old class.

		if (!strEquals(sClass, sOriginalClass))
			{
			//	If sClass is blank, then it means that the original did not have
			//	an effect painter (but the current design does)

			if (!sClass.IsBlank())
				{
				//	Get the original creator

				CEffectCreator *pOriginalCreator;
				if (CEffectCreator::CreateFromTag(sClass, &pOriginalCreator) != NOERROR)
					{
					kernelDebugLogMessage("Unable to find original effect creator: %s", sClass.GetASCIIZPointer());
					return ERR_FAIL;
					}

				//	Load the original painter

				IEffectPainter *pOriginalPainter = pOriginalCreator->CreatePainter();
				pOriginalPainter->ReadFromStream(Ctx);

				//	Discard

				pOriginalPainter->Delete();
				delete pOriginalCreator;
				}

			//	Done

			return ERR_FAIL;
			}
		}

	return NOERROR;
	}
Example #3
0
void CBeam::OnReadFromStream (SLoadCtx &Ctx)

//	OnReadFromStream
//
//	Read object data from a stream
//
//	CString		CWeaponFireDesc UNID
//	DWORD		m_iBonus
//	DWORD		m_iCause
//	DWORD		m_iRotation
//	Vector		m_vPaintTo
//	DWORD		m_iTick
//	DWORD		m_iLifeLeft
//	DWORD		m_Source (CSpaceObject Ref)
//	DWORD		m_pSovereign (UNID)
//	DWORD		m_pHit (CSpaceObject Ref)
//	DWORD		m_iHitDir

{
    DWORD dwLoad;

#ifdef DEBUG_LOAD
    ::OutputDebugString("CBeam::OnReadFromStream\n");
#endif
    //	Load descriptor

    CString sDescUNID;
    sDescUNID.ReadFromStream(Ctx.pStream);
    m_pDesc = g_pUniverse->FindWeaponFireDesc(sDescUNID);

    Ctx.pStream->Read((char *)&m_iBonus, sizeof(DWORD));
    if (Ctx.dwVersion >= 18)
    {
        Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
        m_iCause = (DestructionTypes)dwLoad;
    }
    else
        m_iCause = killedByDamage;

    Ctx.pStream->Read((char *)&m_iRotation, sizeof(DWORD));
    Ctx.pStream->Read((char *)&m_vPaintTo, sizeof(CVector));
    Ctx.pStream->Read((char *)&m_iTick, sizeof(DWORD));
    Ctx.pStream->Read((char *)&m_iLifeLeft, sizeof(m_iLifeLeft));
    m_Source.ReadFromStream(Ctx);
    CSystem::ReadSovereignRefFromStream(Ctx, &m_pSovereign);
    CSystem::ReadObjRefFromStream(Ctx, &m_pHit);
    Ctx.pStream->Read((char *)&m_iHitDir, sizeof(DWORD));

    ComputeOffsets();
}
Example #4
0
CString IEffectPainter::ReadUNID (SLoadCtx &Ctx)

//	ReadUNID
//
//	Returns the UNID saved to a stream

	{
	CString sUNID;

	if (Ctx.dwVersion >= 15)
		sUNID.ReadFromStream(Ctx.pStream);
	else
		{
		DWORD dwUNID;
		Ctx.pStream->Read((char *)&dwUNID, sizeof(DWORD));
		sUNID = strFromInt(dwUNID, FALSE);
		}

	return sUNID;
	}
Example #5
0
void CCurrencyBlock::ReadFromStream (SLoadCtx &Ctx)

//	ReadFromStream
//
//	DWORD		Count of currencies
//	DWORD			CEconomyType UNID
//	LONGLONG		value

{
    int i;

    DWORD dwCount;
    Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));

    for (i = 0; i < (int)dwCount; i++)
    {
        DWORD dwUNID;
        if (Ctx.dwVersion >= 62)
        {
            Ctx.pStream->Read((char *)&dwUNID, sizeof(DWORD));
        }
        else
        {
            CString sCurrency;
            sCurrency.ReadFromStream(Ctx.pStream);

            //	Previous to 62 we never stored any currency
            //	other than credits

            dwUNID = DEFAULT_ECONOMY_UNID;
        }

        SEntry *pEntry = m_Block.Insert(dwUNID);
        Ctx.pStream->Read((char *)&pEntry->iValue, sizeof(CurrencyValue));
    }
}
Example #6
0
IEffectPainter *CEffectCreator::CreatePainterFromStream (SLoadCtx &Ctx, bool bNullCreator)

//	CreatePainterFromStream
//
//	Load a painter from a stream

	{
	CEffectCreator *pCreator;

	//	For previous versions, we only stored UNID if we had a creator

	if (Ctx.dwVersion < 43 && bNullCreator)
		return NULL;

	//	At version 15 we started saving versions as string UNIDs. We need to do this
	//	because sometimes the effect creator is inside a weapon fire desc
	//	structure (also identified by string UNIDs).

	if (Ctx.dwVersion >= 15)
		{
		CString sUNID;
		sUNID.ReadFromStream(Ctx.pStream);

		pCreator = (sUNID.IsBlank() ? NULL : CEffectCreator::FindEffectCreator(sUNID));

		//	Load the creator class that saved the painter

		if (IEffectPainter::ValidateClass(Ctx, (pCreator ? pCreator->GetTag() : NULL_STR)) != NOERROR)
			return NULL;

		//	Error

		if (pCreator == NULL)
			{
			if (!sUNID.IsBlank())
				kernelDebugLogMessage("Invalid painter creator: %s", sUNID.GetASCIIZPointer());
			return NULL;
			}
		}

	//	Old style uses DWORD UNIDs

	else
		{
		//	The first DWORD is the UNID of the creator

		DWORD dwUNID;
		Ctx.pStream->Read((char *)&dwUNID, sizeof(DWORD));
		if (dwUNID == 0)
			return NULL;

		pCreator = g_pUniverse->FindEffectType(dwUNID);

		//	Error

		if (pCreator == NULL)
			{
			kernelDebugLogMessage("Invalid painter creator: %x", dwUNID);
			return NULL;
			}
		}

	//	Let the creator create the object

	IEffectPainter *pPainter = pCreator->CreatePainter();

	//	Load it

	pPainter->ReadFromStream(Ctx);

	//	Done

	return pPainter;
	}
Example #7
0
void CMissile::OnReadFromStream (SLoadCtx &Ctx)

//	OnReadFromStream
//
//	Read object data from a stream
//
//	CString		CWeaponFireDesc UNID
//	DWORD		m_iBonus
//	DWORD		m_iCause
//	DWORD		m_iHitPoints
//	DWORD		m_iLifeLeft
//	DWORD		m_Source (CSpaceObject ref)
//	DWORD		m_pSovereign (CSovereign ref)
//	DWORD		m_pHit (CSpaceObject ref)
//	Vector		m_vHitPos
//	DWORD		m_iHitDir
//	DWORD		m_iRotation
//	DWORD		m_pTarget (CSpaceObject ref)
//	DWORD		m_iTick
//
//	IEffectPainter	m_pPainter
//
//	DWORD		Number of exhaust particles
//	Vector		exhaust: vPos
//	Vector		exhaust: vVel
//
//	-- version > 0 -----------------------
//	DWORD		flags
//	DWORD		Number of saved rotations
//	DWORD		rotation[]

{
    DWORD dwLoad;

#ifdef DEBUG_LOAD
    ::OutputDebugString("CMissile::OnReadFromStream\n");
#endif
    //	Load descriptor

    CString sDescUNID;
    sDescUNID.ReadFromStream(Ctx.pStream);
    m_pDesc = g_pUniverse->FindWeaponFireDesc(sDescUNID);

    //	Load other stuff

    Ctx.pStream->Read((char *)&m_iBonus, sizeof(m_iBonus));
    if (Ctx.dwVersion >= 18)
    {
        Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
        m_iCause = (DestructionTypes)dwLoad;
    }
    else
        m_iCause = killedByDamage;

    if (Ctx.dwVersion >= 28)
        Ctx.pStream->Read((char *)&m_iHitPoints, sizeof(DWORD));
    else
        m_iHitPoints = 0;

    Ctx.pStream->Read((char *)&m_iLifeLeft, sizeof(DWORD));
    m_Source.ReadFromStream(Ctx);
    Ctx.pSystem->ReadSovereignRefFromStream(Ctx, &m_pSovereign);
    Ctx.pSystem->ReadObjRefFromStream(Ctx, &m_pHit);
    Ctx.pStream->Read((char *)&m_vHitPos, sizeof(CVector));
    Ctx.pStream->Read((char *)&m_iHitDir, sizeof(DWORD));
    Ctx.pStream->Read((char *)&m_iRotation, sizeof(DWORD));
    Ctx.pSystem->ReadObjRefFromStream(Ctx, &m_pTarget);
    Ctx.pStream->Read((char *)&m_iTick, sizeof(DWORD));

    //	Load painter

    m_pPainter = CEffectCreator::CreatePainterFromStream(Ctx, (m_pDesc->GetEffect() == NULL));

    //	Load exhaust

    if (m_pDesc->m_iExhaustRate > 0)
    {
        int iCount = (m_pDesc->m_iExhaustLifetime / m_pDesc->m_iExhaustRate) + 1;
        m_pExhaust = new TQueue<SExhaustParticle>(iCount);
    }

    Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
    for (int i = 0; i < (int)dwLoad; i++)
    {
        CVector vPos;
        CVector vVel;
        Ctx.pStream->Read((char *)&vPos, sizeof(CVector));
        Ctx.pStream->Read((char *)&vVel, sizeof(CVector));

        if (m_pExhaust && i < m_pExhaust->GetMaxCount())
        {
            SExhaustParticle &Particle = m_pExhaust->GetAt(m_pExhaust->Queue());
            Particle.vPos = vPos;
            Particle.vVel = vVel;
        }
    }

    //	Load saved rotations

    if (Ctx.dwVersion >= 1)
    {
        Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
        m_fDestroyed =		((dwLoad & 0x00000001) ? true : false);
        m_fReflection =		((dwLoad & 0x00000002) ? true : false);
        m_fDetonate =		((dwLoad & 0x00000004) ? true : false);
        m_fPassthrough =	((dwLoad & 0x00000008) ? true : false);

        Ctx.pStream->Read((char *)&m_iSavedRotationsCount, sizeof(DWORD));
        if (m_iSavedRotationsCount > 0)
        {
            m_pSavedRotations = new int [m_pDesc->GetVaporTrailLength()];
            Ctx.pStream->Read((char *)m_pSavedRotations, sizeof(DWORD) * m_iSavedRotationsCount);
        }
        else
            m_iSavedRotationsCount = 0;
    }
}
Example #8
0
void CTopologyNode::CreateFromStream (SUniverseLoadCtx &Ctx, CTopologyNode **retpNode)

//	CreateFromStream
//
//	Creates a node from a stream
//
//	CString		m_sID
//	DWORD		m_SystemUNID
//	DWORD		m_pMap (UNID)
//	DWORD		m_xPos
//	DWORD		m_yPos
//	CString		m_sName
//	DWORD		m_iLevel
//	DWORD		m_dwID
//
//	DWORD		No of named gates
//	CString		gate: sName
//	CString		gate: sDestNode
//	CString		gate: sDestEntryPoint
//
//	DWORD		No of variant labels
//	CString		variant label
//
//	CAttributeDataBlock	m_Data
//	DWORD		flags
//
//	CString		m_sEpitaph
//	CString		m_sEndGameReason

	{
	int i;
	DWORD dwLoad;
	CTopologyNode *pNode;

	CString sID;
	sID.ReadFromStream(Ctx.pStream);

	DWORD dwSystemUNID;
	Ctx.pStream->Read((char *)&dwSystemUNID, sizeof(DWORD));

	CSystemMap *pMap;
	if (Ctx.dwVersion >= 6)
		{
		DWORD dwMapUNID;
		Ctx.pStream->Read((char *)&dwMapUNID, sizeof(DWORD));
		pMap = CSystemMap::AsType(g_pUniverse->FindDesignType(dwMapUNID));
		}
	else
		pMap = NULL;

	pNode = new CTopologyNode(sID, dwSystemUNID, pMap);

	if (Ctx.dwVersion >= 6)
		{
		Ctx.pStream->Read((char *)&pNode->m_xPos, sizeof(DWORD));
		Ctx.pStream->Read((char *)&pNode->m_yPos, sizeof(DWORD));
		}
	
	pNode->m_sName.ReadFromStream(Ctx.pStream);
	Ctx.pStream->Read((char *)&pNode->m_iLevel, sizeof(DWORD));
	Ctx.pStream->Read((char *)&pNode->m_dwID, sizeof(DWORD));

	DWORD dwCount;
	Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));
	for (i = 0; i < (int)dwCount; i++)
		{
		StarGateDesc *pDesc = new StarGateDesc;
		CString sName;
		sName.ReadFromStream(Ctx.pStream);
		pDesc->sDestNode.ReadFromStream(Ctx.pStream);
		pDesc->sDestEntryPoint.ReadFromStream(Ctx.pStream);
		pDesc->pDestNode = NULL;

		pNode->m_NamedGates.AddEntry(sName, (CObject *)pDesc);
		}

	Ctx.pStream->Read((char *)&dwCount, sizeof(DWORD));
	for (i = 0; i < (int)dwCount; i++)
		{
		CString sLabel;
		sLabel.ReadFromStream(Ctx.pStream);
		pNode->m_VariantLabels.Insert(sLabel);
		}

	if (Ctx.dwVersion >= 1)
		pNode->m_Data.ReadFromStream(Ctx.pStream);

	//	Flags

	if (Ctx.dwVersion >= 6)
		Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
	else
		dwLoad = 0;

	pNode->m_bKnown = (dwLoad & 0x00000001 ? true : false);
	pNode->m_bMarked = false;

	//	More

	if (Ctx.dwVersion >= 5)
		{
		pNode->m_sEpitaph.ReadFromStream(Ctx.pStream);
		pNode->m_sEndGameReason.ReadFromStream(Ctx.pStream);
		}
	else
		{
		//	For previous version, we forgot to save this, so do it now

		if (pNode->IsEndGame())
			{
			pNode->m_sEpitaph = CONSTLIT("left Human Space on a journey to the Galactic Core");
			pNode->m_sEndGameReason = CONSTLIT("leftHumanSpace");
			}
		}

	//	Done

	*retpNode = pNode;
	}