Permalink
Browse files

qtscript: Add some missing pieces for tutorial.

Adds the following:
clearConsole()
hackPlayIngameAudio()
hackStopIngameAudio()
eventDeliveryPointMoving()
eventDeliveryPointMoved()
  • Loading branch information...
perim committed Dec 2, 2017
1 parent 5b73dc0 commit e26b9516d3e065527e41fe5006f9f94983653882
Showing with 44 additions and 1 deletion.
  1. +4 −1 src/display.cpp
  2. +10 −0 src/qtscript.cpp
  3. +2 −0 src/qtscript.h
  4. +28 −0 src/qtscriptfuncs.cpp
View
@@ -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)
{
@@ -1353,6 +1355,7 @@ void finishDeliveryPosition()
psFlagPos->selected = false;
}
}
triggerEvent(TRIGGER_DELIVERY_POINT_MOVED, psStruct);
flagReposFinished = true;
}
View
@@ -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)}
@@ -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;
View
@@ -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,
View
@@ -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"
@@ -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
@@ -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)
@@ -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));

0 comments on commit e26b951

Please sign in to comment.