本文整理汇总了C++中CCodeChainCtx类的典型用法代码示例。如果您正苦于以下问题:C++ CCodeChainCtx类的具体用法?C++ CCodeChainCtx怎么用?C++ CCodeChainCtx使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCodeChainCtx类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
ICCItem *CMission::FireOnReward (ICCItem *pData)
// FireOnReward
//
// Fire <OnReward>
//
// Callers are responsible for discarding the result, if not NULL.
{
SEventHandlerDesc Event;
if (FindEventHandler(EVENT_ON_REWARD, &Event))
{
CCodeChainCtx Ctx;
Ctx.SaveAndDefineSourceVar(this);
Ctx.SaveAndDefineDataVar(pData);
ICCItem *pResult = Ctx.Run(Event);
if (pResult->IsError())
{
ReportEventError(EVENT_ON_REWARD, pResult);
Ctx.Discard(pResult);
return NULL;
}
return pResult;
}
return NULL;
}
示例2: Translate
bool CLanguageDataBlock::Translate (CSpaceObject *pObj, const CString &sID, ICCItem **retpResult) const
// Translate
//
// Translates to an item. The caller is responsible for discarding.
{
// If we can't find this ID then we can't translate
SEntry *pEntry = m_Data.GetAt(sID);
if (pEntry == NULL)
return false;
// If we don't need to run code then we just return the string.
if (pEntry->pCode == NULL)
{
*retpResult = g_pUniverse->GetCC().CreateString(pEntry->sText);
return true;
}
// Otherwise we have to run some code
CCodeChainCtx Ctx;
Ctx.SaveAndDefineSourceVar(pObj);
Ctx.DefineString(CONSTLIT("aTextID"), sID);
*retpResult = Ctx.Run(pEntry->pCode); // LATER:Event
return true;
}
示例3: if
COverlayType *CDeviceClass::FireGetOverlayType (CItemCtx &ItemCtx) const
// FireGetOverlayType
//
// Fire GetOverlayType event
{
SEventHandlerDesc Event;
if (FindEventHandlerDeviceClass(evtGetOverlayType, &Event))
{
// Setup arguments
CCodeChainCtx Ctx;
Ctx.SaveAndDefineSourceVar(ItemCtx.GetSource());
Ctx.SaveAndDefineItemVar(ItemCtx);
ICCItem *pResult = Ctx.Run(Event);
DWORD dwUNID = 0;
if (pResult->IsError())
ItemCtx.GetSource()->ReportEventError(GET_OVERLAY_TYPE_EVENT, pResult);
else if (!pResult->IsNil())
dwUNID = pResult->GetIntegerValue();
Ctx.Discard(pResult);
// Done
return COverlayType::AsType(g_pUniverse->FindDesignType(dwUNID));
}
else
return GetOverlayType();
}
示例4: LoadGlobalsElement
ALERROR CExtension::LoadGlobalsElement (SDesignLoadCtx &Ctx, CXMLElement *pDesc)
// LoadGlobalsElement
//
// Loads <Globals>
{
CCodeChainCtx CCCtx;
// Parse the code and keep it
ICCItem *pCode = CCCtx.Link(pDesc->GetContentText(0), 0, NULL);
if (pCode->IsError())
{
Ctx.sError = strPatternSubst(CONSTLIT("%s globals: %s"), Ctx.sErrorFilespec, pCode->GetStringValue());
return ERR_FAIL;
}
SGlobalsEntry *pEntry = m_Globals.Insert();
pEntry->pCode = pCode;
pEntry->sFilespec = Ctx.sErrorFilespec;
#ifdef DEBUG_GLOBALS
::kernelDebugLogMessage("Loading globals in %s", Ctx.sErrorFilespec);
#endif
return NOERROR;
}
示例5: InitPainterParameters
void CEffectCreator::InitPainterParameters (CCreatePainterCtx &Ctx, IEffectPainter *pPainter)
// InitPainterParameters
//
// Initialize painter parameters
{
SEventHandlerDesc Event;
if (FindEventHandlerEffectType(evtGetParameters, &Event))
{
CCodeChainCtx CCCtx;
CCCtx.SaveAndDefineDataVar(Ctx.GetData());
ICCItem *pResult = CCCtx.Run(Event);
if (pResult->IsError())
::kernelDebugLogMessage(CONSTLIT("EffectType %x GetParameters: %s"), GetUNID(), (LPSTR)pResult->GetStringValue());
else if (pResult->IsSymbolTable())
{
int i;
CCSymbolTable *pTable = (CCSymbolTable *)pResult;
for (i = 0; i < pTable->GetCount(); i++)
{
CString sParam = pTable->GetKey(i);
ICCItem *pValue = pTable->GetElement(i);
CEffectParamDesc Value;
if (pValue->IsNil())
Value.InitNull();
else if (pValue->IsInteger())
Value.InitInteger(pValue->GetIntegerValue());
else if (pValue->IsIdentifier())
{
CString sValue = pValue->GetStringValue();
char *pPos = sValue.GetASCIIZPointer();
// If this is a color, parse it
if (*pPos == '#')
Value.InitColor(::LoadRGBColor(sValue));
// Otherwise, a string
else
Value.InitString(sValue);
}
pPainter->SetParam(Ctx, sParam, Value);
}
}
else
::kernelDebugLogMessage(CONSTLIT("EffectType %x GetParameters: Expected struct result."), GetUNID());
CCCtx.Discard(pResult);
}
}
示例6: EvalBool
bool IDockScreenDisplay::EvalBool (const CString &sCode, bool *retbResult, CString *retsError)
// EvalBool
//
// Evaluates the given string
{
CCodeChainCtx Ctx;
Ctx.SetScreen(m_pDockScreen);
Ctx.SaveAndDefineSourceVar(m_pLocation);
Ctx.SaveAndDefineDataVar(m_pData);
char *pPos = sCode.GetPointer();
ICCItem *pExp = Ctx.Link(sCode, 1, NULL);
ICCItem *pResult = Ctx.Run(pExp); // LATER:Event
Ctx.Discard(pExp);
if (pResult->IsError())
{
*retsError = pResult->GetStringValue();
Ctx.Discard(pResult);
return false;
}
*retbResult = !pResult->IsNil();
Ctx.Discard(pResult);
return true;
}
示例7: CreateTemplateTypes
ALERROR CDesignCollection::CreateTemplateTypes (SDesignLoadCtx &Ctx)
// CreateTemplateTypes
//
// This is called inside of BindDesign to create all template types
{
ALERROR error;
int i;
// Create an appropriate context for running code
CCodeChainCtx CCCtx;
// Loop over all active types looking for templates.
// NOTE: We cannot use the type-specific arrays because they have not been
// set up yet (remember that we are inside of BindDesign).
for (i = 0; i < m_AllTypes.GetCount(); i++)
{
CDesignType *pTemplate = m_AllTypes.GetEntry(i);
if (pTemplate->GetType() != designTemplateType)
continue;
// Get the function to generate the type source
CString sSource;
SEventHandlerDesc Event;
if (pTemplate->FindEventHandler(GET_TYPE_SOURCE_EVENT, &Event))
{
ICCItem *pResult = CCCtx.Run(Event);
if (pResult->IsError())
{
Ctx.sError = strPatternSubst(CONSTLIT("GetTypeSource (%x): %s"), pTemplate->GetUNID(), pResult->GetStringValue());
return ERR_FAIL;
}
else if (pResult->IsNil())
sSource = NULL_STR;
else
sSource = pResult->GetStringValue();
CCCtx.Discard(pResult);
}
// Define the type
if (!sSource.IsBlank())
{
if (error = AddDynamicType(pTemplate->GetExtension(), pTemplate->GetUNID(), sSource, true, &Ctx.sError))
return error;
}
}
return NOERROR;
}
示例8: if
CSpaceObject *IDockScreenDisplay::EvalListSource (const CString &sString, CString *retsError)
// EvalListSource
//
// Returns the object from which we should display items
{
char *pPos = sString.GetPointer();
// See if we need to evaluate
if (*pPos == '=')
{
CCodeChainCtx Ctx;
Ctx.SetScreen(this);
Ctx.SaveAndDefineSourceVar(m_pLocation);
Ctx.SaveAndDefineDataVar(m_pData);
ICCItem *pExp = Ctx.Link(sString, 1, NULL);
ICCItem *pResult = Ctx.Run(pExp); // LATER:Event
Ctx.Discard(pExp);
if (pResult->IsError())
{
*retsError = pResult->GetStringValue();
Ctx.Discard(pResult);
return NULL;
}
// Convert to an object pointer
CSpaceObject *pSource;
if (strEquals(pResult->GetStringValue(), DATA_FROM_PLAYER))
pSource = m_pPlayer->GetShip();
else if (strEquals(pResult->GetStringValue(), DATA_FROM_STATION)
|| strEquals(pResult->GetStringValue(), DATA_FROM_SOURCE))
pSource = m_pLocation;
else
pSource = Ctx.AsSpaceObject(pResult);
Ctx.Discard(pResult);
return pSource;
}
// Otherwise, compare to constants
else if (strEquals(sString, DATA_FROM_PLAYER))
return m_pPlayer->GetShip();
else
return m_pLocation;
}
示例9: ASSERT
int CShieldClass::FireGetMaxHP (CInstalledDevice *pDevice, CSpaceObject *pSource, int iMaxHP) const
// FireGetMaxHP
//
// Fire GetMaxHP event
{
SEventHandlerDesc Event;
if (FindEventHandlerShieldClass(evtGetMaxHP, &Event))
{
ASSERT(pSource);
ASSERT(pDevice);
CCodeChainCtx Ctx;
Ctx.SaveAndDefineSourceVar(pSource);
Ctx.SaveItemVar();
Ctx.DefineItem(pSource->GetItemForDevice(pDevice));
Ctx.DefineInteger(CONSTLIT("aMaxHP"), iMaxHP);
ICCItem *pResult = Ctx.Run(Event);
if (pResult->IsError())
pSource->ReportEventError(GET_MAX_HP_EVENT, pResult);
else if (!pResult->IsNil())
iMaxHP = Max(0, pResult->GetIntegerValue());
Ctx.Discard(pResult);
}
return iMaxHP;
}
示例10: FireOnStart
void CMission::FireOnStart (void)
// FireOnStart
//
// Fire <OnStarted>
{
SEventHandlerDesc Event;
if (FindEventHandler(EVENT_ON_STARTED, &Event))
{
CCodeChainCtx Ctx;
Ctx.SaveAndDefineSourceVar(this);
ICCItem *pResult = Ctx.Run(Event);
if (pResult->IsError())
ReportEventError(EVENT_ON_STARTED, pResult);
Ctx.Discard(pResult);
}
}
示例11: FireOnGameStart
void CAdventureDesc::FireOnGameStart (void)
// FireOnGameStart
//
// Fire OnGameStart event
{
SEventHandlerDesc Event;
if (FindEventHandler(ON_GAME_START_EVENT, &Event))
{
CCodeChainCtx Ctx;
// Run code
ICCItem *pResult = Ctx.Run(Event);
if (pResult->IsError())
kernelDebugLogMessage("OnGameStart error: %s", pResult->GetStringValue());
Ctx.Discard(pResult);
}
}
示例12: 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;
}
示例13: FireCustomEvent
void CMission::FireCustomEvent (const CString &sEvent)
// FireCustomEvent
//
// Fires a custom timed event
{
SEventHandlerDesc Event;
if (FindEventHandler(sEvent, &Event))
{
CCodeChainCtx Ctx;
Ctx.SetEvent(eventDoEvent);
Ctx.SaveAndDefineSourceVar(this);
ICCItem *pResult = Ctx.Run(Event);
if (pResult->IsError())
ReportEventError(sEvent, pResult);
Ctx.Discard(pResult);
}
}
示例14: FireOnSetPlayerTarget
void CMission::FireOnSetPlayerTarget (const CString &sReason)
// FireOnSetPlayerTarget
//
// Fire <OnSetPlayerTarget>
{
SEventHandlerDesc Event;
if (FindEventHandler(EVENT_ON_SET_PLAYER_TARGET, &Event))
{
CCodeChainCtx Ctx;
Ctx.SaveAndDefineSourceVar(this);
Ctx.DefineString(STR_A_REASON, sReason);
ICCItem *pResult = Ctx.Run(Event);
if (pResult->IsError())
ReportEventError(EVENT_ON_SET_PLAYER_TARGET, pResult);
Ctx.Discard(pResult);
}
}
示例15: FireOnReward
void CMission::FireOnReward (ICCItem *pData)
// FireOnReward
//
// Fire <OnReward>
{
SEventHandlerDesc Event;
if (FindEventHandler(EVENT_ON_REWARD, &Event))
{
CCodeChainCtx Ctx;
Ctx.SaveAndDefineSourceVar(this);
Ctx.SaveAndDefineDataVar(pData);
ICCItem *pResult = Ctx.Run(Event);
if (pResult->IsError())
ReportEventError(EVENT_ON_REWARD, pResult);
Ctx.Discard(pResult);
}
}