Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Include/TSE.h
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ class CSpaceObject : public CObject
int FireOnDamage (SDamageCtx &Ctx, int iDamage);
void FireOnDeselected (void);
void FireOnDestroy (const SDestroyCtx &Ctx);
void FireOnDestroyObj (const SDestroyCtx &Ctx);
bool FireOnDockObjAdj (CSpaceObject **retpObj);
void FireOnEnteredGate (CTopologyNode *pDestNode, const CString &sDestEntryPoint, CSpaceObject *pGate);
void FireOnEnteredSystem (CSpaceObject *pGate);
Expand Down
4 changes: 4 additions & 0 deletions Include/TSETransLisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class CCodeChainCtx
CCodeChainCtx (void);
~CCodeChainCtx (void);

void DefineContainingType (CDesignType *pType);
void DefineContainingType (const CItem &Item);
void DefineContainingType (const COverlay *pOverlay);
void DefineContainingType (CSpaceObject *pObj);
inline ICCItem *CreateNil (void) { return m_CC.CreateNil(); }
inline void DefineBool (const CString &sVar, bool bValue) { m_CC.DefineGlobal(sVar, (bValue ? m_CC.CreateTrue() : m_CC.CreateNil())); }
void DefineDamageCtx (const SDamageCtx &Ctx, int iDamage = -1);
Expand Down
41 changes: 41 additions & 0 deletions TSE/CCodeChainCtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define STR_G_DATA CONSTLIT("gData")
#define STR_G_ITEM CONSTLIT("gItem")
#define STR_G_SOURCE CONSTLIT("gSource")
#define STR_G_TYPE CONSTLIT("gType")

TArray<CCodeChainCtx::SInvokeFrame> CCodeChainCtx::g_Invocations;

Expand Down Expand Up @@ -247,6 +248,46 @@ void CCodeChainCtx::DefineDamageEffects (const CString &sVar, SDamageCtx &Ctx)
pItem->Discard(&m_CC);
}

void CCodeChainCtx::DefineContainingType (CDesignType *pType)

// DefineContainingType
//
// Defines an containing type

{
DefineInteger(CONSTLIT(STR_G_TYPE), pType->GetUNID());
}

void CCodeChainCtx::DefineContainingType (const CItem &Item)

// DefineContainingType
//
// Defines an containing type

{
DefineInteger(CONSTLIT(STR_G_TYPE), Item.GetType()->GetUNID());
}

void CCodeChainCtx::DefineContainingType (const COverlay *pOverlay)

// DefineContainingType
//
// Defines an containing type

{
DefineInteger(CONSTLIT(STR_G_TYPE), pOverlay->GetType()->GetUNID());
}

void CCodeChainCtx::DefineContainingType (CSpaceObject *pObj)

// DefineContainingType
//
// Defines an containing type

{
DefineContainingType(pObj->GetType());
}

void CCodeChainCtx::DefineItem (const CString &sVar, CItemCtx &ItemCtx)

// DefineItem
Expand Down
36 changes: 29 additions & 7 deletions TSE/CDesignType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ void CDesignType::FireCustomEvent (const CString &sEvent, ECodeChainEvents iEven
if (FindEventHandler(sEvent, &Event))
{
Ctx.SetEvent(iEvent);
Ctx.DefineContainingType(this);
Ctx.SaveAndDefineDataVar(pData);

ICCItem *pResult = Ctx.Run(Event);
Expand Down Expand Up @@ -808,7 +809,7 @@ bool CDesignType::FireGetCreatePos (CSpaceObject *pBase, CSpaceObject *pTarget,
if (FindEventHandler(GET_CREATE_POS_EVENT, &Event))
{
CCodeChainCtx Ctx;

Ctx.DefineContainingType(this);
Ctx.DefineSpaceObject(CONSTLIT("aBaseObj"), pBase);
Ctx.DefineSpaceObject(CONSTLIT("aTargetObj"), pTarget);

Expand Down Expand Up @@ -854,9 +855,9 @@ void CDesignType::FireGetGlobalAchievements (CGameStats &Stats)
if (FindEventHandler(GET_GLOBAL_ACHIEVEMENTS_EVENT, &Event))
{
CCodeChainCtx Ctx;

Ctx.DefineContainingType(this);
// Run code

ICCItem *pResult = Ctx.Run(Event);
if (pResult->IsError())
ReportEventError(GET_GLOBAL_ACHIEVEMENTS_EVENT, pResult);
Expand Down Expand Up @@ -917,6 +918,7 @@ bool CDesignType::FireGetGlobalDockScreen (const SEventHandlerDesc &Event, CSpac
// Set up

CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);
Ctx.SaveAndDefineSourceVar(pObj);

// Run
Expand All @@ -939,7 +941,7 @@ bool CDesignType::FireGetGlobalPlayerPriceAdj (const SEventHandlerDesc &Event, S

{
CCodeChainCtx Ctx;

Ctx.DefineContainingType(this);
// Set up

Ctx.SetEvent(eventGetGlobalPlayerPriceAdj);
Expand Down Expand Up @@ -994,7 +996,7 @@ int CDesignType::FireGetGlobalResurrectPotential (void)
if (FindEventHandler(GET_GLOBAL_RESURRECT_POTENTIAL_EVENT, &Event))
{
CCodeChainCtx Ctx;

Ctx.DefineContainingType(this);
// Run code

ICCItem *pResult = Ctx.Run(Event);
Expand Down Expand Up @@ -1022,6 +1024,7 @@ void CDesignType::FireObjCustomEvent (const CString &sEvent, CSpaceObject *pObj,
if (FindEventHandler(sEvent, &Event))
{
Ctx.SaveAndDefineSourceVar(pObj);
Ctx.DefineContainingType(this);

ICCItem *pResult = Ctx.Run(Event);
if (pResult->IsError())
Expand Down Expand Up @@ -1049,7 +1052,7 @@ ALERROR CDesignType::FireOnGlobalDockPaneInit (const SEventHandlerDesc &Event, v

{
CCodeChainCtx Ctx;

Ctx.DefineContainingType(this);
// Set up

Ctx.SetScreen(pScreen);
Expand Down Expand Up @@ -1077,6 +1080,7 @@ void CDesignType::FireOnGlobalIntroCommand(const SEventHandlerDesc &Event, const

{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);
Ctx.DefineString(CONSTLIT("aCommand"), sCommand);

// Run code
Expand All @@ -1098,6 +1102,7 @@ void CDesignType::FireOnGlobalIntroStarted (const SEventHandlerDesc &Event)

{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);

// Run code

Expand All @@ -1118,6 +1123,7 @@ void CDesignType::FireOnGlobalPlayerBoughtItem (const SEventHandlerDesc &Event,

{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);

// Set up

Expand All @@ -1143,6 +1149,7 @@ void CDesignType::FireOnGlobalPlayerSoldItem (const SEventHandlerDesc &Event, CS

{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);

// Set up

Expand Down Expand Up @@ -1204,6 +1211,7 @@ void CDesignType::FireOnGlobalObjDestroyed (const SEventHandlerDesc &Event, SDes

{
CCodeChainCtx CCCtx;
CCCtx.DefineContainingType(this);

CCCtx.DefineSpaceObject(CONSTLIT("aObjDestroyed"), Ctx.pObj);
CCCtx.DefineSpaceObject(CONSTLIT("aDestroyer"), Ctx.Attacker.GetObj());
Expand Down Expand Up @@ -1232,6 +1240,7 @@ ALERROR CDesignType::FireOnGlobalPlayerChangedShips (CSpaceObject *pOldShip, CSt
if (FindEventHandler(ON_GLOBAL_PLAYER_CHANGED_SHIPS_EVENT, &Event))
{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);

Ctx.DefineSpaceObject(CONSTLIT("aOldPlayerShip"), pOldShip);

Expand Down Expand Up @@ -1259,6 +1268,7 @@ ALERROR CDesignType::FireOnGlobalPlayerEnteredSystem (CString *retsError)
if (FindEventHandler(ON_GLOBAL_PLAYER_ENTERED_SYSTEM_EVENT, &Event))
{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);

// Run code

Expand All @@ -1284,6 +1294,7 @@ ALERROR CDesignType::FireOnGlobalPlayerLeftSystem (CString *retsError)
if (FindEventHandler(ON_GLOBAL_PLAYER_LEFT_SYSTEM_EVENT, &Event))
{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);

// Run code

Expand All @@ -1309,6 +1320,7 @@ ALERROR CDesignType::FireOnGlobalResurrect (CString *retsError)
if (FindEventHandler(ON_GLOBAL_RESURRECT_EVENT, &Event))
{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);

// Run code

Expand Down Expand Up @@ -1370,6 +1382,7 @@ ALERROR CDesignType::FireOnGlobalSystemCreated (SSystemCreateCtx &SysCreateCtx,
if (FindEventHandler(ON_GLOBAL_SYSTEM_CREATED_EVENT, &Event))
{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);
Ctx.SetSystemCreateCtx(&SysCreateCtx);

// Run code
Expand All @@ -1392,6 +1405,7 @@ void CDesignType::FireOnGlobalSystemStarted (const SEventHandlerDesc &Event, DWO

{
CCodeChainCtx CCCtx;
CCCtx.DefineContainingType(this);
CCCtx.DefineInteger(CONSTLIT("aElapsedTime"), dwElapsedTime);

// Run code
Expand All @@ -1411,6 +1425,7 @@ void CDesignType::FireOnGlobalSystemStopped (const SEventHandlerDesc &Event)

{
CCodeChainCtx CCCtx;
CCCtx.DefineContainingType(this);

// Run code

Expand All @@ -1433,6 +1448,7 @@ ALERROR CDesignType::FireOnGlobalTopologyCreated (CString *retsError)
if (FindEventHandler(ON_GLOBAL_TOPOLOGY_CREATED_EVENT, &Event))
{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);

// Run code

Expand All @@ -1458,6 +1474,7 @@ ALERROR CDesignType::FireOnGlobalTypesInit (SDesignLoadCtx &Ctx)
if (FindEventHandler(evtOnGlobalTypesInit, &Event))
{
CCodeChainCtx CCCtx;
CCCtx.DefineContainingType(this);
CCCtx.SetEvent(eventOnGlobalTypesInit);

ICCItem *pResult = CCCtx.Run(Event);
Expand All @@ -1481,6 +1498,7 @@ ALERROR CDesignType::FireOnGlobalUniverseCreated (const SEventHandlerDesc &Event

{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);

// Run code

Expand All @@ -1502,6 +1520,8 @@ ALERROR CDesignType::FireOnGlobalUniverseLoad (const SEventHandlerDesc &Event)

{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);

if (g_pUniverse->InResurrectMode())
Ctx.DefineString(CONSTLIT("aReason"), CONSTLIT("resurrect"));
else
Expand All @@ -1527,6 +1547,7 @@ ALERROR CDesignType::FireOnGlobalUniverseSave (const SEventHandlerDesc &Event)

{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);

// Run code

Expand All @@ -1548,6 +1569,7 @@ void CDesignType::FireOnGlobalUpdate (const SEventHandlerDesc &Event)

{
CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);

// Run code

Expand All @@ -1572,7 +1594,7 @@ void CDesignType::FireOnRandomEncounter (CSpaceObject *pObj)
if (FindEventHandler(ON_RANDOM_ENCOUNTER_EVENT, &Event))
{
CCodeChainCtx Ctx;

Ctx.DefineContainingType(this);
Ctx.SaveAndDefineSourceVar(pObj);

ICCItem *pResult = Ctx.Run(Event);
Expand Down
14 changes: 11 additions & 3 deletions TSE/COverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ void COverlay::FireCustomEvent (CSpaceObject *pSource, const CString &sEvent, IC
if (m_pType->FindEventHandler(sEvent, &Event))
{
CCodeChainCtx Ctx;

// Setup

Ctx.DefineContainingType(this);
Ctx.SaveAndDefineSourceVar(pSource);
Ctx.SaveAndDefineDataVar(pData);
Ctx.SaveAndDefineOverlayID(m_dwID);
Expand Down Expand Up @@ -380,6 +381,7 @@ bool COverlay::FireGetDockScreen (CSpaceObject *pSource, CString *retsScreen, in
return false;

CCodeChainCtx Ctx;
Ctx.DefineContainingType(this);
Ctx.SaveAndDefineSourceVar(pSource);
Ctx.SaveAndDefineOverlayID(m_dwID);

Expand All @@ -404,10 +406,11 @@ void COverlay::FireOnCreate (CSpaceObject *pSource)
if (m_pType->FindEventHandler(ON_CREATE_EVENT, &Event))
{
CCodeChainCtx Ctx;

// Setup

Ctx.SetEvent(eventOverlayEvent);
Ctx.DefineContainingType(this);
Ctx.SaveAndDefineSourceVar(pSource);
Ctx.SaveAndDefineOverlayID(m_dwID);

Expand Down Expand Up @@ -435,10 +438,11 @@ bool COverlay::FireOnDamage (CSpaceObject *pSource, SDamageCtx &Ctx)
if (m_pType->FindEventHandler(ON_DAMAGE_EVENT, &Event))
{
CCodeChainCtx CCCtx;

// Setup

CCCtx.SetEvent(eventOverlayEvent);
CCCtx.DefineContainingType(this);
CCCtx.SaveAndDefineSourceVar(pSource);
CCCtx.DefineDamageCtx(Ctx);
CCCtx.SaveAndDefineOverlayID(m_dwID);
Expand Down Expand Up @@ -485,6 +489,7 @@ void COverlay::FireOnDestroy (CSpaceObject *pSource)
// Setup

Ctx.SetEvent(eventOverlayEvent);
Ctx.DefineContainingType(this);
Ctx.SaveAndDefineSourceVar(pSource);
Ctx.SaveAndDefineOverlayID(m_dwID);

Expand Down Expand Up @@ -516,6 +521,7 @@ void COverlay::FireOnObjDestroyed (CSpaceObject *pSource, const SDestroyCtx &Ctx
// Setup

CCCtx.SetEvent(eventOverlayEvent);
CCCtx.DefineContainingType(this);
CCCtx.SaveAndDefineSourceVar(pSource);
CCCtx.SaveAndDefineOverlayID(m_dwID);
CCCtx.DefineSpaceObject(CONSTLIT("aObjDestroyed"), Ctx.pObj);
Expand Down Expand Up @@ -550,6 +556,7 @@ void COverlay::FireOnObjDocked (CSpaceObject *pSource, CSpaceObject *pShip) cons
CCodeChainCtx Ctx;

Ctx.SetEvent(eventOverlayEvent);
Ctx.DefineContainingType(this);
Ctx.SaveAndDefineSourceVar(pSource);
Ctx.SaveAndDefineOverlayID(m_dwID);
Ctx.DefineSpaceObject(CONSTLIT("aObjDocked"), pShip);
Expand Down Expand Up @@ -577,6 +584,7 @@ void COverlay::FireOnUpdate (CSpaceObject *pSource)
// Setup

Ctx.SetEvent(eventOverlayEvent);
Ctx.DefineContainingType(this);
Ctx.SaveAndDefineSourceVar(pSource);
Ctx.SaveAndDefineOverlayID(m_dwID);

Expand Down
Loading