Skip to content

Commit

Permalink
MAX_COMMAND_DROIDS and MAX_CONSTRUCTOR_DROIDS moved to rules.js
Browse files Browse the repository at this point in the history
  • Loading branch information
epilef authored and perim committed Nov 27, 2012
1 parent 208c665 commit 09fa278
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
2 changes: 2 additions & 0 deletions data/base/script/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ function eventStartLevel()
setMiniMap(false);
setDesign(false);
setDroidLimit(0, 100);
setCommanderLimit(0, 10);
setConstructorLimit(0, 15);

var structlist = enumStruct(me, HQ);
for (var i = 0; i < structlist.length; i++)
Expand Down
2 changes: 2 additions & 0 deletions data/mp/multiplay/skirmish/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ function eventGameInit()
for (var playnum = 0; playnum < maxPlayers; playnum++)
{
setDroidLimit(playnum, 150);
setCommanderLimit(playnum, 10);
setConstructorLimit(playnum, 15);

enableStructure("A0CommandCentre", playnum); // make structures available to build
enableStructure("A0LightFactory", playnum);
Expand Down
8 changes: 4 additions & 4 deletions src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3294,10 +3294,10 @@ DROID *giftSingleDroid(DROID *psD, UDWORD to)

// Check unit limits (multiplayer only)
if (bMultiPlayer
&& (getNumDroids(to) + 1 > getMaxDroids(to)
|| ((psD->droidType == DROID_CYBORG_CONSTRUCT || psD->droidType == DROID_CONSTRUCT)
&& getNumConstructorDroids(to) + 1 > MAX_CONSTRUCTOR_DROIDS)
|| (psD->droidType == DROID_COMMAND && getNumCommandDroids(to) + 1 > MAX_COMMAND_DROIDS)))
&& (getNumDroids(to) + 1 > getMaxDroids(to)
|| ((psD->droidType == DROID_CYBORG_CONSTRUCT || psD->droidType == DROID_CONSTRUCT)
&& getNumConstructorDroids(to) + 1 > getMaxConstructors(to))
|| (psD->droidType == DROID_COMMAND && getNumCommandDroids(to) + 1 > getMaxCommanders(to))))
{
if (to == selectedPlayer || psD->player == selectedPlayer)
{
Expand Down
4 changes: 0 additions & 4 deletions src/droid.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
//used to stop structures being built too near the edge and droids being placed down
#define TOO_NEAR_EDGE 3

/* Define max number of allowed droids per droid type */
#define MAX_COMMAND_DROIDS 10 // max number of commanders a player can have
#define MAX_CONSTRUCTOR_DROIDS 15 // max number of constructors a player can have

/* Experience modifies */
#define EXP_REDUCE_DAMAGE 6 // damage of a droid is reduced by this value per experience level, in %
#define EXP_ACCURACY_BONUS 5 // accuracy of a droid is increased by this value per experience level, in %
Expand Down
26 changes: 24 additions & 2 deletions src/qtscriptfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2888,11 +2888,11 @@ static QScriptValue js_getDroidLimit(QScriptContext *context, QScriptEngine *eng
DROID_TYPE type = (DROID_TYPE)context->argument(1).toInt32();
if (type == DROID_COMMAND)
{
return QScriptValue(MAX_COMMAND_DROIDS);
return QScriptValue(getMaxCommanders(context->argument(1).toInt32()));
}
else if (type == DROID_CONSTRUCT)
{
return QScriptValue(MAX_CONSTRUCTOR_DROIDS);
return QScriptValue(getMaxConstructors(context->argument(1).toInt32()));
}
// else return general unit limit
}
Expand All @@ -2913,6 +2913,26 @@ static QScriptValue js_setDroidLimit(QScriptContext *context, QScriptEngine *)
return QScriptValue();
}

//-- \subsection{setCommanderLimit(player, value)}
//-- Set the maximum number of commanders that this player can produce.
static QScriptValue js_setCommanderLimit(QScriptContext *context, QScriptEngine *)
{
int player = context->argument(0).toInt32();
int value = context->argument(1).toInt32();
setMaxCommanders(player, value);
return QScriptValue();
}

//-- \subsection{setConstructorLimit(player, value)}
//-- Set the maximum number of constructors that this player can produce.
static QScriptValue js_setConstructorLimit(QScriptContext *context, QScriptEngine *)
{
int player = context->argument(0).toInt32();
int value = context->argument(1).toInt32();
setMaxConstructors(player, 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 @@ -3180,6 +3200,8 @@ bool registerFunctions(QScriptEngine *engine, QString scriptName)
engine->globalObject().setProperty("getDroidProduction", engine->newFunction(js_getDroidProduction));
engine->globalObject().setProperty("getDroidLimit", engine->newFunction(js_getDroidLimit));
engine->globalObject().setProperty("setDroidLimit", engine->newFunction(js_setDroidLimit));
engine->globalObject().setProperty("setCommanderLimit", engine->newFunction(js_setCommanderLimit));
engine->globalObject().setProperty("setConstructorLimit", engine->newFunction(js_setConstructorLimit));

// Functions that operate on the current player only
engine->globalObject().setProperty("centreView", engine->newFunction(js_centreView));
Expand Down
32 changes: 29 additions & 3 deletions src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ static int structureTotalReturn(STRUCTURE *psStruct);
// last time the maximum units message was displayed
static UDWORD lastMaxUnitMessage;

/// max number of units
// max number of units
static int droidLimit[MAX_PLAYERS];
// max number of commanders
static int commanderLimit[MAX_PLAYERS];
// max number of constructors
static int constructorLimit[MAX_PLAYERS];

#define MAX_UNIT_MESSAGE_PAUSE 20000

Expand Down Expand Up @@ -290,6 +294,8 @@ void structureInitVars(void)
for (i = 0; i < MAX_PLAYERS; i++)
{
droidLimit[i] = INT16_MAX;
commanderLimit[i] = INT16_MAX;
constructorLimit[i] = INT16_MAX;
asStructLimits[i] = NULL;
for (j = 0; j < NUM_FLAG_TYPES; j++)
{
Expand Down Expand Up @@ -2548,11 +2554,31 @@ void setMaxDroids(int player, int value)
droidLimit[player] = value;
}

void setMaxCommanders(int player, int value)
{
commanderLimit[player] = value;
}

void setMaxConstructors(int player, int value)
{
constructorLimit[player] = value;
}

int getMaxDroids(int player)
{
return droidLimit[player];
}

int getMaxCommanders(int player)
{
return commanderLimit[player];
}

int getMaxConstructors(int player)
{
return constructorLimit[player];
}

bool IsPlayerDroidLimitReached(int player)
{
unsigned int numDroids = getNumDroids(player) + getNumMissionDroids(player) + getNumTransporterDroids(player);
Expand All @@ -2566,14 +2592,14 @@ static bool maxDroidsByTypeReached(STRUCTURE *psStructure)
CHECK_STRUCTURE(psStructure);

if (droidTemplateType((DROID_TEMPLATE *)psFact->psSubject) == DROID_COMMAND
&& getNumCommandDroids(psStructure->player) >= MAX_COMMAND_DROIDS)
&& getNumCommandDroids(psStructure->player) >= getMaxCommanders(psStructure->player))
{
return true;
}

if ((droidTemplateType((DROID_TEMPLATE *)psFact->psSubject) == DROID_CONSTRUCT
|| droidTemplateType((DROID_TEMPLATE *)psFact->psSubject) == DROID_CYBORG_CONSTRUCT)
&& getNumConstructorDroids(psStructure->player) >= MAX_CONSTRUCTOR_DROIDS)
&& getNumConstructorDroids(psStructure->player) >= getMaxConstructors(psStructure->player))
{
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ extern STRUCTSTRENGTH_MODIFIER asStructStrengthModifier[WE_NUMEFFECTS][
extern void handleAbandonedStructures(void);

int getMaxDroids(int player);
int getMaxCommanders(int player);
int getMaxConstructors(int player);
void setMaxDroids(int player, int value);
void setMaxCommanders(int player, int value);
void setMaxConstructors(int player, int value);

bool IsPlayerDroidLimitReached(int player);
bool CheckHaltOnMaxUnitsReached(STRUCTURE *psStructure);

Expand Down

0 comments on commit 09fa278

Please sign in to comment.