Example #1
0
void CDamageSource::SetObj (CSpaceObject *pSource)

//	SetObj
//
//	Sets the damage source
	
	{
	//	If this is the player, remember it in case we lose the
	//	source later.

	if (pSource)
		{
		CSpaceObject *pOrderGiver;

		if (pSource->IsPlayer())
			{
			m_dwFlags |= FLAG_IS_PLAYER;
			m_dwFlags |= FLAG_IS_PLAYER_CAUSED;
			}
		else if ((pOrderGiver = pSource->GetOrderGiver()) && pOrderGiver->IsPlayer())
			{
			m_dwFlags |= FLAG_IS_PLAYER_SUBORDINATE;
			m_dwFlags |= FLAG_IS_PLAYER_CAUSED;
			}
		}
	else
		m_dwFlags &= ~(FLAG_IS_PLAYER | FLAG_IS_PLAYER_SUBORDINATE | FLAG_IS_PLAYER_CAUSED);

	//	If the source is already destroyed, then don't store it--just get the
	//	name of the source.

	if (pSource && pSource->IsDestroyed())
		{
		m_sSourceName = pSource->GetName(&m_dwSourceNameFlags);
		m_pSource = NULL;
		}

	//	Otherwise, remember the source

	else
		m_pSource = pSource;
	}
Example #2
0
CSpaceObject *CDamageSource::GetObj (void) const

//	GetObj
//
//	Returns the source object

	{
	CSpaceObject *pOrderGiver;

	//	If the source is the player then always return the player
	//	object (regardless of m_pSource). We do this in case
	//	the player changes ships.

	if (m_dwFlags & FLAG_IS_PLAYER)
		{
		CSystem *pSystem = g_pUniverse->GetCurrentSystem();
		return (pSystem ? pSystem->GetPlayer() : NULL);
		}

	//	Otherwise, if we're a subordinate and our order giver
	//	has changed, switch back to the player.

	else if ((m_dwFlags & FLAG_IS_PLAYER_SUBORDINATE)
			&& (m_pSource == NULL
				|| (pOrderGiver = m_pSource->GetOrderGiver()) == NULL
				|| !pOrderGiver->IsPlayer()))
		{
		CSystem *pSystem = g_pUniverse->GetCurrentSystem();
		return (pSystem ? pSystem->GetPlayer() : NULL);
		}

	//	Otherwise, return the source (even if NULL)

	else
		return m_pSource;
	}