Skip to content

Commit

Permalink
qtscript: Add some missing pieces for tutorial.
Browse files Browse the repository at this point in the history
Adds the following:
clearConsole()
hackPlayIngameAudio()
hackStopIngameAudio()
eventDeliveryPointMoving()
eventDeliveryPointMoved()
  • Loading branch information
perim committed Dec 2, 2017
1 parent 5b73dc0 commit e26b951
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/display.cpp
Expand Up @@ -1325,17 +1325,19 @@ void startDeliveryPosition(FLAG_POSITION *psFlag)
{
eventFireCallbackTrigger((TRIGGER_TYPE)CALL_DELIVPOINTMOVED);
}
triggerEvent(TRIGGER_DELIVERY_POINT_MOVING, psStruct);
}

// Finished repositioning a delivery point.
//
void finishDeliveryPosition()
{
STRUCTURE *psStruct = nullptr;
FLAG_POSITION *psFlagPos;
if (flagStructId)
{
flagReposVarsValid = false;
STRUCTURE *psStruct = IdToStruct(flagStructId, selectedPlayer);
psStruct = IdToStruct(flagStructId, selectedPlayer);
if (StructIsFactory(psStruct) && psStruct->pFunctionality
&& psStruct->pFunctionality->factory.psAssemblyPoint)
{
Expand All @@ -1353,6 +1355,7 @@ void finishDeliveryPosition()
psFlagPos->selected = false;
}
}
triggerEvent(TRIGGER_DELIVERY_POINT_MOVED, psStruct);
flagReposFinished = true;
}

Expand Down
10 changes: 10 additions & 0 deletions src/qtscript.cpp
Expand Up @@ -969,6 +969,10 @@ void jsShowDebug()
//__ An event that is run before game is saved. There is usually no need to use this event.
//__ \subsection{eventGameSaved()}
//__ An event that is run after game is saved. There is usually no need to use this event.
//__ \subsection{eventDeliveryPointMoving()}
//__ An event that is run when the current player starts to move a delivery point.
//__ \subsection{eventDeliveryPointMoved()}
//__ An event that is run after the current player has moved a delivery point.
//__ \subsection{eventTransporterLaunch(transport)}
//__ An event that is run when the mission transporter has been ordered to fly off.
//__ \subsection{eventTransporterArrived(transport)}
Expand Down Expand Up @@ -1015,6 +1019,12 @@ bool triggerEvent(SCRIPT_TRIGGER_TYPE trigger, BASE_OBJECT *psObj)
callFunction(engine, "eventReinforcementsArrived", QScriptValueList()); // deprecated!
callFunction(engine, "eventTransporterArrived", args);
break;
case TRIGGER_DELIVERY_POINT_MOVING:
callFunction(engine, "eventDeliveryPointMoving", args);
break;
case TRIGGER_DELIVERY_POINT_MOVED:
callFunction(engine, "eventDeliveryPointMoved", args);
break;
case TRIGGER_OBJECT_RECYCLED:
callFunction(engine, "eventObjectRecycled", args);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/qtscript.h
Expand Up @@ -39,6 +39,8 @@ enum SCRIPT_TRIGGER_TYPE
TRIGGER_TRANSPORTER_LAUNCH,
TRIGGER_TRANSPORTER_EXIT,
TRIGGER_TRANSPORTER_DONE,
TRIGGER_DELIVERY_POINT_MOVING,
TRIGGER_DELIVERY_POINT_MOVED,
TRIGGER_VIDEO_QUIT,
TRIGGER_MISSION_TIMEOUT,
TRIGGER_GAME_LOADED,
Expand Down
28 changes: 28 additions & 0 deletions src/qtscriptfuncs.cpp
Expand Up @@ -26,6 +26,7 @@
#include "lib/framework/wzconfig.h"
#include "lib/framework/fixedpoint.h"
#include "lib/sound/audio.h"
#include "lib/sound/cdaudio.h"
#include "lib/netplay/netplay.h"
#include "qtscriptfuncs.h"
#include "lib/ivis_opengl/tex.h"
Expand Down Expand Up @@ -2385,6 +2386,14 @@ static QScriptValue js_removeObject(QScriptContext *context, QScriptEngine *)
return QScriptValue(retval);
}

//-- \subsection{clearConsole()}
//-- Clear the console. (3.2.4+ only)
static QScriptValue js_clearConsole(QScriptContext *context, QScriptEngine *engine)
{
flushConsoleMessages();
return QScriptValue();
}

//-- \subsection{console(strings...)}
//-- Print text to the player console.
// TODO, should cover scrShowConsoleText, scrAddConsoleText, scrTagConsoleText and scrConsole
Expand Down Expand Up @@ -2776,6 +2785,22 @@ static QScriptValue js_centreView(QScriptContext *context, QScriptEngine *)
return QScriptValue();
}

//-- \subsection{hackPlayIngameAudio()} (3.2.4+ only)
static QScriptValue js_hackPlayIngameAudio(QScriptContext *context, QScriptEngine *)
{
debug(LOG_SOUND, "Script wanted music to start");
cdAudio_PlayTrack(SONG_INGAME);
return QScriptValue();
}

//-- \subsection{hackStopIngameAudio()} (3.2.4+ only)
static QScriptValue js_hackStopIngameAudio(QScriptContext *context, QScriptEngine *)
{
debug(LOG_SOUND, "Script wanted music to start");
cdAudio_Stop();
return QScriptValue();
}

//-- \subsection{playSound(sound[, x, y, z])}
//-- Play a sound, optionally at a location.
static QScriptValue js_playSound(QScriptContext *context, QScriptEngine *engine)
Expand Down Expand Up @@ -5468,10 +5493,13 @@ bool registerFunctions(QScriptEngine *engine, const QString& scriptName)
engine->globalObject().setProperty("hackMarkTiles", engine->newFunction(js_hackMarkTiles));
engine->globalObject().setProperty("receiveAllEvents", engine->newFunction(js_receiveAllEvents));
engine->globalObject().setProperty("hackDoNotSave", engine->newFunction(js_hackDoNotSave));
engine->globalObject().setProperty("hackPlayIngameAudio", engine->newFunction(js_hackPlayIngameAudio));
engine->globalObject().setProperty("hackStopIngameAudio", engine->newFunction(js_hackStopIngameAudio));

// General functions -- geared for use in AI scripts
engine->globalObject().setProperty("debug", engine->newFunction(js_debug));
engine->globalObject().setProperty("console", engine->newFunction(js_console));
engine->globalObject().setProperty("clearConsole", engine->newFunction(js_clearConsole));
engine->globalObject().setProperty("structureIdle", engine->newFunction(js_structureIdle));
engine->globalObject().setProperty("enumStruct", engine->newFunction(js_enumStruct));
engine->globalObject().setProperty("enumStructOffWorld", engine->newFunction(js_enumStructOffWorld));
Expand Down

0 comments on commit e26b951

Please sign in to comment.