Skip to content

Commit

Permalink
qtscript: Add new events eventPlayerLeft(player index) for when a pla…
Browse files Browse the repository at this point in the history
…yer leaves

the game, and eventDesignCreated(template) for when a player creates a new design
in the design GUI.
  • Loading branch information
perim committed Jan 17, 2013
1 parent 20c7024 commit 391492d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/design.cpp
Expand Up @@ -80,6 +80,7 @@
#include "template.h"
#include "multiplay.h"
#include "multistat.h"
#include "qtscript.h"

#define FLASH_BUTTONS // Enable flashing body part buttons.

Expand Down Expand Up @@ -4237,6 +4238,7 @@ void intProcessDesign(UDWORD id)
if (saveTemplate())
{
eventFireCallbackTrigger((TRIGGER_TYPE)CALL_DROIDDESIGNED);
triggerEventDesignCreated(&sCurrDesign);
}

switch ( desCompMode )
Expand Down
2 changes: 2 additions & 0 deletions src/multijoin.cpp
Expand Up @@ -67,6 +67,7 @@
#include "multiint.h"
#include "multistat.h"
#include "multigifts.h"
#include "qtscript.h"
#include "scriptcb.h"

// ////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -302,6 +303,7 @@ bool MultiPlayerLeave(UDWORD playerIndex)
// fire script callback to reassign skirmish players.
CBPlayerLeft = playerIndex;
eventFireCallbackTrigger((TRIGGER_TYPE)CALL_PLAYERLEFT);
triggerEventPlayerLeft(playerIndex);

netPlayersUpdated = true;
return true;
Expand Down
28 changes: 28 additions & 0 deletions src/qtscript.cpp
Expand Up @@ -655,6 +655,20 @@ bool triggerEvent(SCRIPT_TRIGGER_TYPE trigger)
return true;
}

//__ \subsection{eventPlayerLeft(player index)}
//__ An event that is run after a player has left the game.
bool triggerEventPlayerLeft(int id)
{
for (int i = 0; i < scripts.size(); ++i)
{
QScriptEngine *engine = scripts.at(i);
QScriptValueList args;
args += id;
callFunction(engine, "eventPlayerLeft", args);
}
return true;
}

//__ \subsection{eventCheatMode(entered)} Game entered or left cheat/debug mode.
//__ The entered parameter is true if cheat mode entered, false otherwise.
bool triggerEventCheatMode(bool entered)
Expand Down Expand Up @@ -1008,3 +1022,17 @@ bool triggerEventArea(QString label, DROID *psDroid)
return true;
}

//__ \subsection{eventDesignCreated(template)}
//__ An event that is run whenever a new droid template is created. It is only
//__ run on the client of the player designing the template.
bool triggerEventDesignCreated(DROID_TEMPLATE *psTemplate)
{
for (int i = 0; i < scripts.size(); ++i)
{
QScriptEngine *engine = scripts.at(i);
QScriptValueList args;
args += convTemplate(psTemplate, engine);
callFunction(engine, "eventDesignCreated", args);
}
return true;
}
2 changes: 2 additions & 0 deletions src/qtscript.h
Expand Up @@ -100,5 +100,7 @@ bool triggerEventGroupLoss(BASE_OBJECT *psObj, int group, int size, QScriptEngin
bool triggerEventDroidMoved(DROID *psDroid, int oldx, int oldy);
bool triggerEventArea(QString label, DROID *psDroid);
bool triggerEventSelected();
bool triggerEventPlayerLeft(int id);
bool triggerEventDesignCreated(DROID_TEMPLATE *psTemplate);

#endif
1 change: 1 addition & 0 deletions src/qtscriptfuncs.h
Expand Up @@ -57,6 +57,7 @@ QScriptValue convStructure(STRUCTURE *psStruct, QScriptEngine *engine);
QScriptValue convObj(BASE_OBJECT *psObj, QScriptEngine *engine);
QScriptValue convFeature(FEATURE *psFeature, QScriptEngine *engine);
QScriptValue convMax(BASE_OBJECT *psObj, QScriptEngine *engine);
QScriptValue convTemplate(DROID_TEMPLATE *psTemplate, QScriptEngine *engine);
QScriptValue convResearch(RESEARCH *psResearch, QScriptEngine *engine, int player);
BASE_OBJECT *IdToObject(OBJECT_TYPE type, int id, int player);

Expand Down

0 comments on commit 391492d

Please sign in to comment.