Skip to content

Commit

Permalink
qtscript: Add two new fun functions, cameraSlide(x, y) and cameraTrac…
Browse files Browse the repository at this point in the history
…k(droid),

to access the warcam camera tracking code from scripts.
  • Loading branch information
perim committed Nov 15, 2012
1 parent 6c1fc06 commit fdf2db1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/qtscriptfuncs.cpp
Expand Up @@ -59,6 +59,7 @@
#include "mapgrid.h"
#include "lighting.h"
#include "atmos.h"
#include "warcam.h"

#define FAKE_REF_LASSAT 999
#define ALL_PLAYERS -1
Expand Down Expand Up @@ -2348,6 +2349,7 @@ static QScriptValue js_countDroid(QScriptContext *context, QScriptEngine *engine
int player = me;
int quantity = 0;
int type = context->argument(0).toInt32();
SCRIPT_ASSERT(context, type <= DROID_ANY, "Bad droid type parameter");
if (context->argumentCount() > 1)
{
player = context->argument(1).toInt32();
Expand Down Expand Up @@ -2761,6 +2763,40 @@ static QScriptValue js_setSky(QScriptContext *context, QScriptEngine *)
return QScriptValue(found);
}

//-- \subsection{cameraSlide(x, y)}
//-- Slide the camera over to the given position on the map.
static QScriptValue js_cameraSlide(QScriptContext *context, QScriptEngine *)
{
int x = context->argument(0).toNumber();
int y = context->argument(1).toNumber();
requestRadarTrack(x, y);
return QScriptValue();
}

//-- \subsection{cameraTrack(droid)}
//-- Make the camera follow the given droid object around. Pass in a null object to stop.
static QScriptValue js_cameraTrack(QScriptContext *context, QScriptEngine *)
{
if (context->argument(0).isNull())
{
setWarCamActive(false);
}
else
{
QScriptValue droidVal = context->argument(0);
int id = droidVal.property("id").toInt32();
int player = droidVal.property("player").toInt32();
DROID *targetDroid = IdToDroid(id, player);
SCRIPT_ASSERT(context, targetDroid, "No such droid id %d belonging to player %d", id, player);
for (DROID *psDroid = apsDroidLists[selectedPlayer]; psDroid!=NULL; psDroid = psDroid->psNext)
{
psDroid->selected = (psDroid == targetDroid); // select only the target droid
}
setWarCamActive(true);
}
return QScriptValue();
}

// ----------------------------------------------------------------------------------------
// Register functions with scripting system

Expand All @@ -2778,6 +2814,8 @@ bool registerFunctions(QScriptEngine *engine)
engine->globalObject().setProperty("setSunIntensity", engine->newFunction(js_setSunIntensity));
engine->globalObject().setProperty("setWeather", engine->newFunction(js_setWeather));
engine->globalObject().setProperty("setSky", engine->newFunction(js_setSky));
engine->globalObject().setProperty("cameraSlide", engine->newFunction(js_cameraSlide));
engine->globalObject().setProperty("cameraTrack", engine->newFunction(js_cameraTrack));

// horrible hacks follow -- do not rely on these being present!
engine->globalObject().setProperty("hackNetOff", engine->newFunction(js_hackNetOff));
Expand Down

0 comments on commit fdf2db1

Please sign in to comment.