Skip to content

Commit

Permalink
qtscript: Add new function setExperienceMultiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
epilef committed Nov 28, 2012
1 parent 09fa278 commit dafff61
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions data/base/script/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function eventStartLevel()
setDroidLimit(0, 100);
setCommanderLimit(0, 10);
setConstructorLimit(0, 15);
setExperienceMultiplier(1);

var structlist = enumStruct(me, HQ);
for (var i = 0; i < structlist.length; i++)
Expand Down
1 change: 1 addition & 0 deletions data/mp/multiplay/skirmish/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var lastHitTime = 0;
function eventGameInit()
{
hackNetOff();
setExperienceMultiplier(1);
for (var playnum = 0; playnum < maxPlayers; playnum++)
{
setDroidLimit(playnum, 150);
Expand Down
9 changes: 8 additions & 1 deletion src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,13 @@ static const struct rankMap arrRank[] =
{512, 1024, N_("Hero")}
};

static int experienceMultiplier;

void setExpMult(int value)
{
experienceMultiplier = value;
}

unsigned int getDroidLevel(const DROID* psDroid)
{
bool isCommander = (psDroid->droidType == DROID_COMMAND ||
Expand All @@ -2403,7 +2410,7 @@ unsigned int getDroidLevel(const DROID* psDroid)
{
const unsigned int requiredKills = isCommander ? arrRank[i].commanderKills : arrRank[i].kills;

if (numKills < requiredKills)
if (numKills*experienceMultiplier < requiredKills)
{
return i - 1;
}
Expand Down
1 change: 1 addition & 0 deletions src/droid.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ bool calcDroidMuzzleBaseLocation(DROID *psDroid, Vector3i *muzzle, int weapon_sl
extern bool selectDroidByID(UDWORD id, UDWORD player);

/* Droid experience stuff */
void setExpMult(int value);
extern unsigned int getDroidLevel(const DROID* psDroid);
extern UDWORD getDroidEffectiveLevel(DROID *psDroid);
extern const char *getDroidLevelName(DROID *psDroid);
Expand Down
10 changes: 10 additions & 0 deletions src/qtscriptfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2933,6 +2933,15 @@ static QScriptValue js_setConstructorLimit(QScriptContext *context, QScriptEngin
return QScriptValue();
}

//-- \subsection{setExperienceMultiplier(value)}
//-- Set the multiplier to be applyed to experience to get ranks.
static QScriptValue js_setExperienceMultiplier(QScriptContext *context, QScriptEngine *)
{
int value = context->argument(0).toInt32();
setExpMult(value);
return QScriptValue();
}

//-- \subsection{hackAddMessage(message, type, player, immediate)}
//-- See wzscript docs for info, to the extent any exist.
static QScriptValue js_hackAddMessage(QScriptContext *context, QScriptEngine *)
Expand Down Expand Up @@ -3202,6 +3211,7 @@ bool registerFunctions(QScriptEngine *engine, QString scriptName)
engine->globalObject().setProperty("setDroidLimit", engine->newFunction(js_setDroidLimit));
engine->globalObject().setProperty("setCommanderLimit", engine->newFunction(js_setCommanderLimit));
engine->globalObject().setProperty("setConstructorLimit", engine->newFunction(js_setConstructorLimit));
engine->globalObject().setProperty("setExperienceMultiplier", engine->newFunction(js_setExperienceMultiplier));

// Functions that operate on the current player only
engine->globalObject().setProperty("centreView", engine->newFunction(js_centreView));
Expand Down

0 comments on commit dafff61

Please sign in to comment.