Ejemplo n.º 1
0
ALERROR CSingleParticleEffectCreator::OnEffectCreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, const CString &sUNID)

//	OnEffectCreateFromXML
//
//	Initializes from XML

	{
	ALERROR error;

	CString sStyle = pDesc->GetAttribute(STYLE_ATTRIB);
	if (sStyle.IsBlank() || strEquals(sStyle, STYLE_PLAIN))
		m_iStyle = paintPlain;
	else if (strEquals(sStyle, STYLE_FLAME))
		m_iStyle = paintFlame;
	else if (strEquals(sStyle, STYLE_SMOKE))
		m_iStyle = paintSmoke;
	else if (strEquals(sStyle, STYLE_LINE))
		m_iStyle = paintLine;
	else
		{
		Ctx.sError = CONSTLIT("Invalid SingleParticle style");
		return ERR_FAIL;
		}

	CString sRange;
	if (pDesc->FindAttribute(MAX_WIDTH_ATTRIB, &sRange))
		{
		if (error = m_MaxWidth.LoadFromXML(sRange))
			return error;
		}
	else
		m_MaxWidth = DiceRange(0, 0, DEFAULT_MAX_WIDTH);

	if (pDesc->FindAttribute(MIN_WIDTH_ATTRIB, &sRange))
		{
		if (error = m_MinWidth.LoadFromXML(sRange))
			return error;
		}
	else
		m_MinWidth = DiceRange(0, 0, DEFAULT_MIN_WIDTH);

	//	Colors

	m_wPrimaryColor = ::LoadRGBColor(pDesc->GetAttribute(PRIMARY_COLOR_ATTRIB));
	m_wSecondaryColor = ::LoadRGBColor(pDesc->GetAttribute(SECONDARY_COLOR_ATTRIB));

	return NOERROR;
	}
Ejemplo n.º 2
0
bool CArmorClass::GetReferenceDamageAdj (const CItem *pItem, CSpaceObject *pInstalled, int *retiHP, int *retArray)

//	GetReferenceDamageAdj
//
//	Returns armor HP after adjustment for damage type

	{
	int i;

	CItemCtx ItemCtx(pItem, pInstalled);
	int iHP = GetMaxHP(ItemCtx);

	if (retiHP)
		*retiHP = iHP;

	for (i = 0; i < damageCount; i++)
		{
		DamageDesc Damage((DamageTypes)i, DiceRange(0, 0, 0));
		int iAdj = GetDamageAdj(ItemCtx.GetMods(), Damage);

		if (retArray)
			retArray[i] = CalcHPDamageAdj(iHP, iAdj);
		}

	return true;
	}
Ejemplo n.º 3
0
bool CShieldClass::GetReferenceDamageAdj (const CItem *pItem, CSpaceObject *pInstalled, int *retiHP, int *retArray) const

//	GetReferenceDamageAdj
//
//	Returns an array of damage adj values

	{
	CItemCtx Ctx(pItem, pInstalled);
	int i;

	const CItemEnhancement &Mods = Ctx.GetMods();

	int iMinHP, iMaxHP;
	CalcMinMaxHP(Ctx, m_iMaxCharges, 0, 0, &iMinHP, &iMaxHP);

	if (retiHP)
		*retiHP = iMaxHP;

	if (retArray)
		{
		for (i = 0; i < damageCount; i++)
			{
			DamageDesc Damage((DamageTypes)i, DiceRange(0, 0, 0));
			int iAdj = GetDamageAdj(Mods, Damage);
			if (iAdj == 0)
				retArray[i] = -1;
			else
				retArray[i] = (int)((iMaxHP * 100.0 / iAdj) + 0.5);
			}
		}

	return true;
	}
void CItemEnhancementStack::CalcCache (void) const

//	CalcCache
//
//	Computes accumulated values

	{
	int i;

	m_iBonus = 0;
	m_Damage = DamageDesc(damageGeneric, DiceRange());

	for (i = 0; i < m_Stack.GetCount(); i++)
		{
		m_iBonus += m_Stack[i].GetHPBonus();

		int iLevel;
		SpecialDamageTypes iSpecial;
		if ((iSpecial = m_Stack[i].GetSpecialDamage(&iLevel)) != specialNone)
			m_Damage.SetSpecialDamage(iSpecial, iLevel);
		}

	//	Done

	m_bCacheValid = true;
	}
Ejemplo n.º 5
0
ALERROR CGroupOfGenerators::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc)

//	LoadFromXML
//
//	Load from XML

	{
	int i;
	ALERROR error;

	//	Load content elements

	m_Table.InsertEmpty(pDesc->GetContentElementCount());
	for (i = 0; i < m_Table.GetCount(); i++)
		{
		CXMLElement *pEntry = pDesc->GetContentElement(i);
			
		m_Table[i].iChance = pEntry->GetAttributeInteger(CHANCE_ATTRIB);
		if (m_Table[i].iChance == 0)
			m_Table[i].iChance = 100;

		CString sCount = pEntry->GetAttribute(COUNT_ATTRIB);
		if (sCount.IsBlank())
			m_Table[i].Count = DiceRange(0, 0, 1);
		else
			m_Table[i].Count.LoadFromXML(sCount);

		if (error = IItemGenerator::CreateFromXML(Ctx, pEntry, &m_Table[i].pItem))
			return error;
		}

	//	See if we force an average value

	CString sAttrib;
	if (pDesc->FindAttribute(LEVEL_VALUE_ATTRIB, &sAttrib))
		{
		TArray<int> Values;
		ParseIntegerList(sAttrib, 0, &Values);

		m_AverageValue.InsertEmpty(MAX_ITEM_LEVEL + 1);
		m_AverageValue[0] = 0;
		for (i = 0; i < Values.GetCount(); i++)
			m_AverageValue[i + 1] = Values[i];

		for (i = Values.GetCount() + 1; i <= MAX_ITEM_LEVEL; i++)
			m_AverageValue[i] = 0;
		}
	else if (pDesc->FindAttribute(VALUE_ATTRIB, &sAttrib))
		{
		int iValue = strToInt(sAttrib, 0);

		m_AverageValue.InsertEmpty(MAX_ITEM_LEVEL + 1);
		m_AverageValue[0] = 0;
		for (i = 1; i <= MAX_ITEM_LEVEL; i++)
			m_AverageValue[i] = iValue;
		}

	return NOERROR;
	}
Ejemplo n.º 6
0
ALERROR CTableOfGenerators::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc)

//	LoadFromXML
//
//	Load from XML

	{
	int i;
	ALERROR error;

	m_iTotalChance = 0;
	int iCount = pDesc->GetContentElementCount();
	if (iCount > 0)
		{
		m_Table.InsertEmpty(iCount);

		//	Pre-initialize to NULL in case we exit with an error

		for (i = 0; i < iCount; i++)
			m_Table[i].pItem = NULL;

		//	Load

		for (i = 0; i < iCount; i++)
			{
			CXMLElement *pEntry = pDesc->GetContentElement(i);
			
			m_Table[i].iChance = pEntry->GetAttributeInteger(CHANCE_ATTRIB);
			m_iTotalChance += m_Table[i].iChance;

			CString sCount = pEntry->GetAttribute(COUNT_ATTRIB);
			if (sCount.IsBlank())
				m_Table[i].Count = DiceRange(0, 0, 1);
			else
				m_Table[i].Count.LoadFromXML(sCount);

			if (error = IItemGenerator::CreateFromXML(Ctx, pEntry, &m_Table[i].pItem))
				return error;
			}
		}

	return NOERROR;
	}
Ejemplo n.º 7
0
ALERROR CGroupOfGenerators::LoadFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc)

//	LoadFromXML
//
//	Load from XML

	{
	int i;
	ALERROR error;

	m_iCount = pDesc->GetContentElementCount();
	if (m_iCount > 0)
		{
		m_Table = new SEntry [m_iCount];
		utlMemSet(m_Table, sizeof(SEntry) * m_iCount, 0);

		for (i = 0; i < m_iCount; i++)
			{
			CXMLElement *pEntry = pDesc->GetContentElement(i);
			
			m_Table[i].iChance = pEntry->GetAttributeInteger(CHANCE_ATTRIB);
			if (m_Table[i].iChance == 0)
				m_Table[i].iChance = 100;

			CString sCount = pEntry->GetAttribute(COUNT_ATTRIB);
			if (sCount.IsBlank())
				m_Table[i].Count = DiceRange(0, 0, 1);
			else
				m_Table[i].Count.LoadFromXML(sCount);

			if (error = IItemGenerator::CreateFromXML(Ctx, pEntry, &m_Table[i].pItem))
				return error;
			}
		}
	else
		m_Table = NULL;

	return NOERROR;
	}
Ejemplo n.º 8
0
ALERROR CSmokeTrailEffectCreator::OnEffectCreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, const CString &sUNID)

//	OnEffectCreateFromXML
//
//	Initializes from XML

	{
	ALERROR error;

	//	In previous versions there was a bug in emitSpeed. It was interpreted
	//	as half its actual value. If this is loading from a previous version,
	//	we divide by two.

	bool bEmitSpeedFix = (Ctx.GetAPIVersion() < 3);

	//	Load some stuff

	m_iEmitLifetime = pDesc->GetAttributeIntegerBounded(EMIT_LIFETIME_ATTRIB, 0, -1, 100);
	m_iLifetime = pDesc->GetAttributeIntegerBounded(LIFETIME_ATTRIB, 0, -1, -1);

	if (!pDesc->FindAttributeInteger(ROTATION_ATTRIB, &m_iRotation))
		m_iRotation = 180;

	if (error = m_Spread.LoadFromXML(pDesc->GetAttribute(SPREAD_ATTRIB)))
		return error;

	CString sRange;
	if (pDesc->FindAttribute(PARTICLE_LIFETIME_ATTRIB, &sRange))
		{
		if (error = m_ParticleLifetime.LoadFromXML(sRange))
			return error;
		}
	else
		m_ParticleLifetime = DiceRange(0, 0, DEFAULT_PARTICLE_LIFETIME);

	if (pDesc->FindAttribute(NEW_PARTICLES_ATTRIB, &sRange))
		{
		if (error = m_NewParticles.LoadFromXML(sRange))
			return error;
		}
	else
		m_NewParticles = DiceRange(0, 0, DEFAULT_NEW_PARTICLES_PER_TICK);

	if (pDesc->FindAttribute(EMIT_SPEED_ATTRIB, &sRange))
		{
		if (error = m_InitSpeed.LoadFromXML(sRange))
			return error;

		if (bEmitSpeedFix)
			m_InitSpeed.Scale(0.5);
		}
	else
		m_InitSpeed = DiceRange(0, 0, DEFAULT_EMIT_SPEED);

	//	Load the effect to use for particles

	CXMLElement *pEffect = pDesc->GetContentElementByTag(PARTICLE_EFFECT_TAG);
	if (pEffect)
		{
		if (error = CEffectCreator::CreateFromXML(Ctx, pEffect, NULL_STR, &m_pParticleEffect))
			return error;
		}
	else
		m_pParticleEffect = NULL;

	return NOERROR;
	}