本文整理汇总了C++中CItemCtx::GetSource方法的典型用法代码示例。如果您正苦于以下问题:C++ CItemCtx::GetSource方法的具体用法?C++ CItemCtx::GetSource怎么用?C++ CItemCtx::GetSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CItemCtx
的用法示例。
在下文中一共展示了CItemCtx::GetSource方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FireGetMaxHP
int CArmorClass::FireGetMaxHP (CItemCtx &ItemCtx, int iMaxHP) const
// FireGetMaxHP
//
// Fire GetMaxHP event
{
SEventHandlerDesc Event;
if (FindEventHandlerArmorClass(evtGetMaxHP, &Event))
{
// Setup arguments
CCodeChainCtx Ctx;
Ctx.SaveAndDefineSourceVar(ItemCtx.GetSource());
Ctx.SaveAndDefineItemVar(ItemCtx);
Ctx.DefineInteger(CONSTLIT("aMaxHP"), iMaxHP);
ICCItem *pResult = Ctx.Run(Event);
if (pResult->IsError())
ItemCtx.GetSource()->ReportEventError(GET_MAX_HP_EVENT, pResult);
else if (!pResult->IsNil())
iMaxHP = Max(0, pResult->GetIntegerValue());
Ctx.Discard(pResult);
}
return iMaxHP;
}
示例2: AccumulateEnhancements
bool CDeviceClass::AccumulateEnhancements (CItemCtx &Device, CInstalledDevice *pTarget, TArray<CString> &EnhancementIDs, CItemEnhancementStack *pEnhancements)
// AccumulateEnhancements
//
// If this device can enhance pTarget, then we add to the list of enhancements.
{
int i;
bool bEnhanced = false;
CInstalledDevice *pDevice = Device.GetDevice();
CSpaceObject *pSource = Device.GetSource();
// See if we can enhance the target device
if (pDevice == NULL
|| (pDevice->IsEnabled() && !pDevice->IsDamaged()))
{
for (i = 0; i < m_Enhancements.GetCount(); i++)
{
// If this type of enhancement has already been applied, skip it
if (!m_Enhancements[i].sType.IsBlank()
&& EnhancementIDs.Find(m_Enhancements[i].sType))
continue;
// If we don't match the criteria, skip it.
if (pSource
&& pTarget
&& !pSource->GetItemForDevice(pTarget).MatchesCriteria(m_Enhancements[i].Criteria))
continue;
// Add the enhancement
pEnhancements->Insert(m_Enhancements[i].Enhancement);
bEnhanced = true;
// Remember that we added this enhancement class
if (!m_Enhancements[i].sType.IsBlank())
EnhancementIDs.Insert(m_Enhancements[i].sType);
}
}
// Let sub-classes add their own
if (OnAccumulateEnhancements(Device, pTarget, EnhancementIDs, pEnhancements))
bEnhanced = true;
// Done
return bEnhanced;
}
示例3: FireOnArmorDamage
void CArmorClass::FireOnArmorDamage (CItemCtx &ItemCtx, SDamageCtx &Ctx)
// FireOnArmorDamage
//
// Fires OnArmorDamage event
{
SEventHandlerDesc Event;
if (FindEventHandlerArmorClass(evtOnArmorDamage, &Event))
{
// Setup arguments
CCodeChainCtx CCCtx;
CCCtx.SaveAndDefineSourceVar(ItemCtx.GetSource());
CCCtx.SaveAndDefineItemVar(ItemCtx);
CCCtx.DefineInteger(CONSTLIT("aArmorHP"), Ctx.iHPLeft);
CCCtx.DefineInteger(CONSTLIT("aArmorSeg"), Ctx.iSectHit);
CCCtx.DefineSpaceObject(CONSTLIT("aAttacker"), Ctx.Attacker.GetObj());
CCCtx.DefineSpaceObject(CONSTLIT("aCause"), Ctx.pCause);
CCCtx.DefineDamageEffects(CONSTLIT("aDamageEffects"), Ctx);
CCCtx.DefineInteger(CONSTLIT("aDamageHP"), Ctx.iDamage);
CCCtx.DefineString(CONSTLIT("aDamageType"), GetDamageShortName(Ctx.Damage.GetDamageType()));
CCCtx.DefineInteger(CONSTLIT("aHitDir"), Ctx.iDirection);
CCCtx.DefineVector(CONSTLIT("aHitPos"), Ctx.vHitPos);
CCCtx.DefineSpaceObject(CONSTLIT("aOrderGiver"), (Ctx.Attacker.GetObj() ? Ctx.Attacker.GetObj()->GetOrderGiver(Ctx.Attacker.GetCause()) : NULL));
CCCtx.DefineItemType(CONSTLIT("aWeaponType"), Ctx.pDesc->GetWeaponType());
ICCItem *pResult = CCCtx.Run(Event);
// If we return Nil, then nothing
if (pResult->IsNil())
NULL;
// If we return an integer, then this is the damage that armor should take
else if (pResult->IsInteger())
Ctx.iDamage = pResult->GetIntegerValue();
// If we return a list, then we it to be a DamageEffects list (modifications to
// aDamageEffects)
else if (pResult->IsList())
LoadDamageEffectsFromItem(pResult, Ctx);
CCCtx.Discard(pResult);
}
}
示例4: CalcActivateDelay
int CItemEnhancementStack::CalcActivateDelay (CItemCtx &DeviceCtx) const
// CalcActivateDelay
//
// Calculates the activation delay (in ticks) for the given device if we apply
// this enhancement stack.
{
int i;
CInstalledDevice *pDevice = DeviceCtx.GetDevice();
if (pDevice == NULL)
return 0;
Metric rDelay = -1.0;
for (i = 0; i < m_Stack.GetCount(); i++)
{
int iMin, iMax;
int iAdj = m_Stack[i].GetActivateRateAdj(&iMin, &iMax);
if (iAdj != 100)
{
if (rDelay < 0.0)
{
pDevice->SetActivateDelayAdj(100);
rDelay = pDevice->GetActivateDelay(DeviceCtx.GetSource());
}
rDelay = iAdj * rDelay / 100.0;
if (rDelay < (Metric)iMin)
rDelay = (Metric)iMin;
else if (iMax > 0 && rDelay > (Metric)iMax)
rDelay = (Metric)iMax;
}
}
return (rDelay < 0.0 ? 100 : (int)(rDelay + 0.5));
}
示例5: CalcActivateDelay
int CItemEnhancementStack::CalcActivateDelay (CItemCtx &DeviceCtx) const
// CalcActivateDelay
//
// Calculates the activation delay (in ticks) for the given device if we apply
// this enhancement stack.
{
int i;
CInstalledDevice *pDevice = DeviceCtx.GetDevice();
if (pDevice == NULL)
return 0;
// Get the raw activation delay. NOTE: This DOES NOT include
// any enhancements on the item.
Metric rDelay = pDevice->GetClass()->GetActivateDelay(pDevice, DeviceCtx.GetSource());
// Apply enhancements (including on the item itself)
for (i = 0; i < m_Stack.GetCount(); i++)
{
int iMin, iMax;
int iAdj = m_Stack[i].GetActivateRateAdj(&iMin, &iMax);
if (iAdj != 100)
{
rDelay = iAdj * rDelay / 100.0;
if (rDelay < (Metric)iMin)
rDelay = (Metric)iMin;
else if (iMax > 0 && rDelay > (Metric)iMax)
rDelay = (Metric)iMax;
}
}
return (int)(rDelay + 0.5);
}
示例6: CalcDamageEffects
void CArmorClass::CalcDamageEffects (CItemCtx &ItemCtx, SDamageCtx &Ctx)
// CalcDamageEffects
//
// Initialize the damage effects based on the damage and on this armor type.
{
CSpaceObject *pSource = ItemCtx.GetSource();
CInstalledArmor *pArmor = ItemCtx.GetArmor();
// Compute all the effects (if we don't have installed armor, then the
// caller is responsible for setting this).
if (pArmor)
Ctx.iHPLeft = pArmor->GetHitPoints();
// Reflect
Ctx.bReflect = (IsReflective(ItemCtx, Ctx.Damage) && Ctx.iDamage > 0);
// Disintegration
int iDisintegration = Ctx.Damage.GetDisintegrationDamage();
Ctx.bDisintegrate = (iDisintegration > 0 && !IsDisintegrationImmune(ItemCtx));
// Shatter
int iShatter = Ctx.Damage.GetShatterDamage();
if (iShatter)
{
// Compute the threshold mass. Below this size, we shatter the object
int iMassLimit = 10 * mathPower(5, iShatter);
Ctx.bShatter = (pSource && pSource->GetMass() < iMassLimit);
}
else
Ctx.bShatter = false;
// Blinding
int iBlinding = Ctx.Damage.GetBlindingDamage();
if (iBlinding && !IsBlindingDamageImmune(ItemCtx))
{
// The chance of being blinded is dependent
// on the rating.
int iChance = 4 * iBlinding * iBlinding * GetBlindingDamageAdj() / 100;
Ctx.bBlind = (mathRandom(1, 100) <= iChance);
Ctx.iBlindTime = Ctx.iDamage * g_TicksPerSecond / 2;
}
else
Ctx.bBlind = false;
// EMP
int iEMP = Ctx.Damage.GetEMPDamage();
if (iEMP && !IsEMPDamageImmune(ItemCtx))
{
// The chance of being paralyzed is dependent
// on the EMP rating.
int iChance = 4 * iEMP * iEMP * GetEMPDamageAdj() / 100;
Ctx.bParalyze = (mathRandom(1, 100) <= iChance);
Ctx.iParalyzeTime = Ctx.iDamage * g_TicksPerSecond / 2;
}
else
Ctx.bParalyze = false;
// Device disrupt
int iDeviceDisrupt = Ctx.Damage.GetDeviceDisruptDamage();
if (iDeviceDisrupt && !IsDeviceDamageImmune(ItemCtx))
{
// The chance of damaging a device depends on the rating.
int iChance = 4 * iDeviceDisrupt * iDeviceDisrupt * GetDeviceDamageAdj() / 100;
Ctx.bDeviceDisrupt = (mathRandom(1, 100) <= iChance);
Ctx.iDisruptTime = 2 * Ctx.iDamage * g_TicksPerSecond;
}
else
Ctx.bDeviceDisrupt = false;
// Device damage
int iDeviceDamage = Ctx.Damage.GetDeviceDamage();
if (iDeviceDamage && !IsDeviceDamageImmune(ItemCtx))
{
// The chance of damaging a device depends on the rating.
int iChance = 4 * iDeviceDamage * iDeviceDamage * GetDeviceDamageAdj() / 100;
Ctx.bDeviceDamage = (mathRandom(1, 100) <= iChance);
}
else
Ctx.bDeviceDamage = false;
// Radiation
int iRadioactive = Ctx.Damage.GetRadiationDamage();
Ctx.bRadioactive = (iRadioactive > 0 && !IsRadiationImmune(ItemCtx));
//.........这里部分代码省略.........
示例7: AbsorbDamage
EDamageResults CArmorClass::AbsorbDamage (CItemCtx &ItemCtx, SDamageCtx &Ctx)
// AbsorbDamage
//
// Handles getting hit by damage.
//
// Returns damageNoDamage if all the damage was absorbed and no further processing is necessary
// Returns damageDestroyed if the source was destroyed
// Returns damageArmorHit if source was damage and further processing (destroy check) is needed
//
// Sets Ctx.iDamage to the amount of hit points left after damage absorption.
{
CSpaceObject *pSource = ItemCtx.GetSource();
CInstalledArmor *pArmor = ItemCtx.GetArmor();
if (pSource == NULL || pArmor == NULL)
return damageNoDamage;
// Compute all the effects (this initializes elements in Ctx).
CalcDamageEffects(ItemCtx, Ctx);
// First give custom weapons a chance
bool bCustomDamage = Ctx.pDesc->FireOnDamageArmor(Ctx);
if (pSource->IsDestroyed())
return damageDestroyed;
// Damage adjustment
CalcAdjustedDamage(ItemCtx, Ctx);
// If the armor has custom code to deal with damage, handle it here.
FireOnArmorDamage(ItemCtx, Ctx);
if (pSource->IsDestroyed())
return damageDestroyed;
// If this armor section reflects this kind of damage then
// send the damage on
if (Ctx.bReflect)
{
if (Ctx.pCause)
Ctx.pCause->CreateReflection(Ctx.vHitPos, (Ctx.iDirection + 120 + mathRandom(0, 120)) % 360);
return damageNoDamage;
}
// If this is a disintegration attack, then disintegrate the ship
if (Ctx.bDisintegrate)
{
if (!pSource->OnDestroyCheck(killedByDisintegration, Ctx.Attacker))
return damageNoDamage;
pSource->Destroy(killedByDisintegration, Ctx.Attacker);
return damageDestroyed;
}
// If this is a shatter attack, see if the ship is destroyed
if (Ctx.bShatter)
{
if (!pSource->OnDestroyCheck(killedByShatter, Ctx.Attacker))
return damageNoDamage;
pSource->Destroy(killedByShatter, Ctx.Attacker);
return damageDestroyed;
}
// If this is a paralysis attack and we've gotten past the shields
// then freeze the ship.
if (Ctx.bParalyze)
pSource->MakeParalyzed(Ctx.iParalyzeTime);
// If this is blinding damage then our sensors are disabled
if (Ctx.bBlind)
pSource->MakeBlind(Ctx.iBlindTime);
// If this attack is radioactive, then contaminate the ship
if (Ctx.bRadioactive)
pSource->OnHitByRadioactiveDamage(Ctx);
// If this is device damage, then see if any device is damaged
if (Ctx.bDeviceDamage)
pSource->OnHitByDeviceDamage();
if (Ctx.bDeviceDisrupt)
pSource->OnHitByDeviceDisruptDamage(Ctx.iDisruptTime);
// Create a hit effect. (Many weapons show an effect even if no damage was
// done.)
Ctx.pDesc->CreateHitEffect(pSource->GetSystem(), Ctx);
// If no damage has reached us, then we're done
//.........这里部分代码省略.........