Skip to content

Commit

Permalink
Qtscript: Add eventStructureDemolish.
Browse files Browse the repository at this point in the history
An event that triggers only when a completely built structures starts to
be demolished.

Refs ticket 4790.
  • Loading branch information
KJeff01 committed Aug 27, 2018
1 parent d02157d commit 349e73f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/qtscript.cpp
Expand Up @@ -1338,6 +1338,32 @@ bool triggerEventStructBuilt(STRUCTURE *psStruct, DROID *psDroid)
return true;
}

//__ ## eventStructureDemolish(structure[, droid])
//__
//__ An event that is run every time a structure begins to be demolished. This does
//__ not trigger again if the structure is partially demolished.
//__
bool triggerEventStructDemolish(STRUCTURE *psStruct, DROID *psDroid)
{
ASSERT(scriptsReady, "Scripts not initialized yet");
for (auto *engine : scripts)
{
int player = engine->globalObject().property("me").toInt32();
bool receiveAll = engine->globalObject().property("isReceivingAllEvents").toBool();
if (player == psStruct->player || receiveAll)
{
QScriptValueList args;
args += convStructure(psStruct, engine);
if (psDroid)
{
args += convDroid(psDroid, engine);
}
callFunction(engine, "eventStructureDemolish", args);
}
}
return true;
}

//__ ## eventStructureReady(structure)
//__
//__ An event that is run every time a structure is ready to perform some
Expand Down Expand Up @@ -1893,4 +1919,3 @@ void to_json(nlohmann::json& j, const QVariant& value) {
}
}
}

1 change: 1 addition & 0 deletions src/qtscript.h
Expand Up @@ -121,6 +121,7 @@ bool triggerEventDroidBuilt(DROID *psDroid, STRUCTURE *psFactory);
bool triggerEventAttacked(BASE_OBJECT *psVictim, BASE_OBJECT *psAttacker, int lastHit);
bool triggerEventResearched(RESEARCH *psResearch, STRUCTURE *psStruct, int player);
bool triggerEventStructBuilt(STRUCTURE *psStruct, DROID *psDroid);
bool triggerEventStructDemolish(STRUCTURE *psStruct, DROID *psDroid);
bool triggerEventDroidIdle(DROID *psDroid);
bool triggerEventDestroyed(BASE_OBJECT *psVictim);
bool triggerEventStructureReady(STRUCTURE *psStruct);
Expand Down
8 changes: 8 additions & 0 deletions src/structure.cpp
Expand Up @@ -842,6 +842,14 @@ void structureBuild(STRUCTURE *psStruct, DROID *psDroid, int buildPoints, int bu
if (prevStatus == SS_BUILT)
{
// Starting to demolish.
if (psDroid)
{
triggerEventStructDemolish(psStruct, psDroid);
}
else
{
triggerEventStructDemolish(psStruct, nullptr);
}
switch (psStruct->pStructureType->type)
{
case REF_POWER_GEN:
Expand Down

0 comments on commit 349e73f

Please sign in to comment.