Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

qtscript: Change countDroid function to countDroid(droid type[, playe…

…r]. Type can

be one of DROID_ANY, DROID_CONSTRUCT or DROID_COMMAND. Make use of it in semperfi-js.
  • Loading branch information...
commit def9fb81c34a7c6d3c343c659507ed1b6f40f5ee 1 parent 13b07b7
@perim perim authored
Showing with 18 additions and 19 deletions.
  1. +2 −16 data/mp/multiplay/skirmish/semperfi.js
  2. +16 −3 src/qtscriptfuncs.cpp
View
18 data/mp/multiplay/skirmish/semperfi.js
@@ -129,9 +129,7 @@ function buildVTOL(struct)
// If negative, we have too many power generator (usually not a problem in itself).
function numUnusedDerricks()
{
- var derricklist = enumStruct(me, derrick);
- var powgenlist = enumStruct(me, powGen);
- return derricklist.length - powgenlist.length * 4;
+ return countStruct(derrick) - countStruct(powGen) * 4;
}
function conCanHelp(mydroid, bx, by)
@@ -462,8 +460,7 @@ function eventDroidBuilt(droid, struct)
{
if (struct.stattype == FACTORY)
{
- var trucklist = enumDroid(me, DROID_CONSTRUCT);
- if (trucklist.length < 6)
+ if (countDroid(DROID_CONSTRUCT) < 6)
{
buildTruck(struct);
}
@@ -594,17 +591,6 @@ function eventStartLevel()
// Maintenance calls - to fix quirks
setTimer("maintenance", 1000 * 60 * 2); // every 2 minutes, call it to check if anything left to do
-
- /*
- if (numFactories() > 1 && isStructureAvailable(defStructs[0], me) && playerData[me].difficulty > MEDIUM)
- {
- dbgPlr("TRUCK RUSH!");
- queue("truckRush");
- }
- else
- {
- queue("buildFundamentals");
- }*/
}
function eventDroidIdle(droid)
View
19 src/qtscriptfuncs.cpp
@@ -1997,13 +1997,15 @@ static QScriptValue js_countStruct(QScriptContext *context, QScriptEngine *engin
return QScriptValue(quantity);
}
-//-- \subsection{countDroid([player])}
-//-- Count the number of droids that a given player has.
+//-- \subsection{countDroid(droid type[, player])}
+//-- Count the number of droids that a given player has. Droid type must be either
+//-- DROID_ANY, DROID_COMMAND or DROID_CONSTRUCT.
//-- The player parameter can be a specific player, ALL_PLAYERS, ALLIES or ENEMIES.
static QScriptValue js_countDroid(QScriptContext *context, QScriptEngine *engine)
{
int player;
int quantity = 0;
+ int type = context->argument(0).toInt32();
if (context->argumentCount() > 1)
{
player = context->argument(1).toInt32();
@@ -2018,7 +2020,18 @@ static QScriptValue js_countDroid(QScriptContext *context, QScriptEngine *engine
|| (player == ALLIES && aiCheckAlliances(i, player))
|| (player == ENEMIES && !aiCheckAlliances(i, player)))
{
- quantity += getNumDroids(i);
+ if (type == DROID_ANY)
+ {
+ quantity += getNumDroids(i);
+ }
+ else if (type == DROID_CONSTRUCT)
+ {
+ quantity += getNumConstructorDroids(i);
+ }
+ else if (type == DROID_COMMAND)
+ {
+ quantity += getNumCommandDroids(i);
+ }
}
}
return QScriptValue(quantity);
Please sign in to comment.
Something went wrong with that request. Please try again.