Skip to content

Commit

Permalink
qtscript: Change eventGroupEmpty(group id) event into eventGroupLoss(…
Browse files Browse the repository at this point in the history
…object, group id, new size).
  • Loading branch information
perim committed Nov 23, 2012
1 parent 849c918 commit 4ce8d2d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
12 changes: 7 additions & 5 deletions src/qtscript.cpp
Expand Up @@ -218,7 +218,7 @@ static QScriptValue js_queue(QScriptContext *context, QScriptEngine *engine)
return QScriptValue();
}

void scriptRemoveObject(const BASE_OBJECT *psObj)
void scriptRemoveObject(BASE_OBJECT *psObj)
{
QHash<int, bindNode>::iterator i = bindings.find(psObj->id);
while (i != bindings.end() && i.key() == psObj->id)
Expand Down Expand Up @@ -906,14 +906,16 @@ bool triggerEventChat(int from, int to, const char *message)
return true;
}

//__ \subsection{eventGroupEmpty(id)}
//__ \subsection{eventGroupLoss(object, group id, new size)}
//__ An event that is run whenever a group becomes empty. Input parameter
//__ is the group's index.
//__ is the about to be killed object, the group's id, and the new group size.
// Since groups are entities local to one context, we do not iterate over them here.
bool triggerEventGroupEmpty(int group, QScriptEngine *engine)
bool triggerEventGroupLoss(BASE_OBJECT *psObj, int group, int size, QScriptEngine *engine)
{
QScriptValueList args;
args += convMax(psObj, engine);
args += QScriptValue(group);
callFunction(engine, "eventGroupEmpty", args);
args += QScriptValue(size);
callFunction(engine, "eventGroupLoss", args);
return true;
}
4 changes: 2 additions & 2 deletions src/qtscript.h
Expand Up @@ -70,7 +70,7 @@ bool loadLabels(const char *filename);
bool writeLabels(const char *filename);

/// Tell script system that an object has been removed.
void scriptRemoveObject(const BASE_OBJECT *psObj);
void scriptRemoveObject(BASE_OBJECT *psObj);

// ----------------------------------------------
// Event functions
Expand All @@ -91,6 +91,6 @@ bool triggerEventObjectTransfer(BASE_OBJECT *psObj, int from);
bool triggerEventChat(int from, int to, const char *message);
bool triggerEventPickup(FEATURE *psFeat, DROID *psDroid);
bool triggerEventCheatMode(bool entered);
bool triggerEventGroupEmpty(int group, QScriptEngine *engine);
bool triggerEventGroupLoss(BASE_OBJECT *psObj, int group, int size, QScriptEngine *engine);

#endif
7 changes: 2 additions & 5 deletions src/qtscriptfuncs.cpp
Expand Up @@ -80,7 +80,7 @@ static ENGINEMAP groups;
// ----------------------------------------------------------------------------------------
// Utility functions -- not called directly from scripts

void groupRemoveObject(const BASE_OBJECT *psObj)
void groupRemoveObject(BASE_OBJECT *psObj)
{
for (ENGINEMAP::iterator i = groups.begin(); i != groups.end(); ++i)
{
Expand All @@ -93,10 +93,7 @@ void groupRemoveObject(const BASE_OBJECT *psObj)
const int newValue = groupMembers.property(groupId).toInt32() - 1;
ASSERT(newValue >= 0, "Bad group count in group %d (was %d)", groupId, newValue + 1);
groupMembers.setProperty(groupId, newValue, QScriptValue::ReadOnly);
if (newValue == 0)
{
triggerEventGroupEmpty(groupId, engine);
}
triggerEventGroupLoss(psObj, groupId, newValue, engine);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/qtscriptfuncs.h
Expand Up @@ -39,7 +39,7 @@ enum SCRIPT_TYPES
// ----------------------------------------------
// Private to scripting module functions below

void groupRemoveObject(const BASE_OBJECT *psObj);
void groupRemoveObject(BASE_OBJECT *psObj);

/// Register functions to engine context
bool registerFunctions(QScriptEngine *engine, QString scriptName);
Expand Down

0 comments on commit 4ce8d2d

Please sign in to comment.