Skip to content

Commit

Permalink
convert var to let in "for" loops (general)
Browse files Browse the repository at this point in the history
  • Loading branch information
ximex committed Apr 11, 2021
1 parent 178c0c7 commit 11710b4
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion data/base/script/fastplay/fastdemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function grantStartTech()
];

camCompleteRequiredResearch(TECH, CAM_HUMAN_PLAYER);
for (var i = 0, l = STRUCTS.length; i < l; ++i)
for (let i = 0, l = STRUCTS.length; i < l; ++i)
{
enableStructure(STRUCTS[i], CAM_HUMAN_PLAYER);
}
Expand Down
22 changes: 11 additions & 11 deletions data/base/script/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ function reticuleManufactureCheck()
var structureComplete = false;
var facs = [FACTORY, CYBORG_FACTORY, VTOL_FACTORY,];

for (var i = 0, len = facs.length; i < len; ++i)
for (let i = 0, len = facs.length; i < len; ++i)
{
var facType = facs[i];
var offWorldFacs = enumStructOffWorld(selectedPlayer, facType);
var onMapFacs = enumStruct(selectedPlayer, facType);

if (offWorldFacs !== null)
{
for (var j = 0, len2 = offWorldFacs.length; j < len2; ++j)
for (let j = 0, len2 = offWorldFacs.length; j < len2; ++j)
{
if (offWorldFacs[j].status === BUILT)
{
Expand All @@ -34,7 +34,7 @@ function reticuleManufactureCheck()
}
if (!structureComplete)
{
for (var j = 0, len2 = onMapFacs.length; j < len2; ++j)
for (let j = 0, len2 = onMapFacs.length; j < len2; ++j)
{
if (onMapFacs[j].status === BUILT)
{
Expand Down Expand Up @@ -65,15 +65,15 @@ function reticuleResearchCheck()
var structureComplete = false;
var labs = [RESEARCH_LAB,];

for (var i = 0, len = labs.length; i < len; ++i)
for (let i = 0, len = labs.length; i < len; ++i)
{
var resType = labs[i];
var offWorldLabs = enumStructOffWorld(selectedPlayer, resType);
var onMapLabs = enumStruct(selectedPlayer, resType);

if (offWorldLabs !== null)
{
for (var j = 0, len2 = offWorldLabs.length; j < len2; ++j)
for (let j = 0, len2 = offWorldLabs.length; j < len2; ++j)
{
if (offWorldLabs[j].status === BUILT)
{
Expand All @@ -84,7 +84,7 @@ function reticuleResearchCheck()
}
if (!structureComplete)
{
for (var j = 0, len2 = onMapLabs.length; j < len2; ++j)
for (let j = 0, len2 = onMapLabs.length; j < len2; ++j)
{
if (onMapLabs[j].status === BUILT)
{
Expand Down Expand Up @@ -127,15 +127,15 @@ function reticuleDesignCheck()
var structureComplete = false;
var hqs = [HQ,];

for (var i = 0, len = hqs.length; i < len; ++i)
for (let i = 0, len = hqs.length; i < len; ++i)
{
var hqType = hqs[i];
var offWorldHq = enumStructOffWorld(selectedPlayer, hqType);
var onMapHq = enumStruct(selectedPlayer, hqType);

if (offWorldHq !== null)
{
for (var j = 0, len2 = offWorldHq.length; j < len2; ++j)
for (let j = 0, len2 = offWorldHq.length; j < len2; ++j)
{
if (offWorldHq[j].status === BUILT)
{
Expand All @@ -146,7 +146,7 @@ function reticuleDesignCheck()
}
if (!structureComplete)
{
for (var j = 0, len2 = onMapHq.length; j < len2; ++j)
for (let j = 0, len2 = onMapHq.length; j < len2; ++j)
{
if (onMapHq[j].status === BUILT)
{
Expand Down Expand Up @@ -287,7 +287,7 @@ function setLimits()
setDroidLimit(selectedPlayer, 10, DROID_COMMAND);
setDroidLimit(selectedPlayer, 15, DROID_CONSTRUCT);

for (var i = 0; i < maxPlayers; ++i)
for (let i = 0; i < maxPlayers; ++i)
{
setStructureLimits("A0PowerGenerator", 5, i);
setStructureLimits("A0ResourceExtractor", 200, i);
Expand Down Expand Up @@ -414,7 +414,7 @@ function eventResearched(research, structure, player)
{
//debug("RESEARCH : " + research.fullname + "(" + research.name + ") for " + player);
// iterate over all results
for (var i = 0; i < research.results.length; i++)
for (let i = 0; i < research.results.length; i++)
{
var v = research.results[i];
//debug(" RESULT : class=" + v['class'] + " parameter=" + v['parameter'] + " value=" + v['value'] + " filter=" + v['filterParameter'] + " filterparam=" + v['filterParameter']);
Expand Down
6 changes: 3 additions & 3 deletions data/base/script/tutorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ function checkForPowGen()

//Get the truck that is building the generator and store its ID.
var trucks = enumDroid(CAM_HUMAN_PLAYER, DROID_CONSTRUCT);
for (var i = 0, len = trucks.length; i < len; ++i)
for (let i = 0, len = trucks.length; i < len; ++i)
{
var truck = trucks[i];
if (truck.order === DORDER_BUILD)
Expand Down Expand Up @@ -322,7 +322,7 @@ function checkHelpBuild()
if (tutState === 6)
{
var objects = enumDroid(CAM_HUMAN_PLAYER);
for (var i = 0, l = objects.length; i < l; ++i)
for (let i = 0, l = objects.length; i < l; ++i)
{
var obj = objects[i];
if (obj.type === DROID &&
Expand Down Expand Up @@ -410,7 +410,7 @@ function eventSelectionChanged(objects)
if (tut0 || tut5)
{
//Check if they selected a truck.
for (var i = 0, l = objects.length; i < l; ++i)
for (let i = 0, l = objects.length; i < l; ++i)
{
var obj = objects[i];
if (obj.type === DROID && obj.droidType === DROID_CONSTRUCT)
Expand Down
4 changes: 2 additions & 2 deletions data/mp/multiplay/script/rules/endconditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function checkEndConditions()
/* If teams enabled check if all team members have lost */
if (alliancesType == ALLIANCES_TEAMS || alliancesType == ALLIANCES_UNSHARED)
{
for (var playnum = 0; playnum < maxPlayers; playnum++)
for (let playnum = 0; playnum < maxPlayers; playnum++)
{
if (playnum != selectedPlayer && allianceExistsBetween(selectedPlayer, playnum))
{
Expand All @@ -40,7 +40,7 @@ function checkEndConditions()
var gamewon = true;

// check if all enemies defeated
for (var playnum = 0; playnum < maxPlayers; playnum++)
for (let playnum = 0; playnum < maxPlayers; playnum++)
{
if (playnum != selectedPlayer && !allianceExistsBetween(selectedPlayer, playnum)) // checking enemy player
{
Expand Down
18 changes: 9 additions & 9 deletions data/mp/multiplay/script/rules/events/gameinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ function eventGameInit()
{
//From script/rules/setupgame.js
setupGame();

//From script/rules/printsettings.js
printGameSettings();

//From script/rules/oildrum.js
oilDrumInit();

Expand All @@ -15,29 +15,29 @@ function eventGameInit()
//From script/setup/setupscavenger.js
setupScavenger();

for (var playnum = 0; playnum < maxPlayers; playnum++)
for (let playnum = 0; playnum < maxPlayers; playnum++)
{
//From script/setup/powermodifier.js
setupPowerModifier(playnum);

//From script/setup/droidlimit.js
droidLimit(playnum);

//From script/setup/setupstructure.js
setupStructure(playnum);

//From script/setup/setupstructurelimit.js
setupStructureLimit(playnum);

//From script/setup/setupresearch.js
setupResearch(playnum);

//From script/setup/setupcomponents.js
setupComponents(playnum);

//From script/setup/setupbase.js
setupBase(playnum);

//From script/setup/setuptechlevels.js
seupTechLevel(playnum);

Expand Down
4 changes: 2 additions & 2 deletions data/mp/multiplay/script/rules/events/research.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function eventResearched(research, structure, player)
{
//if (research.name == "") debug("RESEARCH : " + research.fullname + "(" + research.name + ") for " + player);
// iterate over all results
for (var i = 0; i < research.results.length; i++)
for (let i = 0; i < research.results.length; i++)
{
var v = research.results[i];
//if (research.name == "") debug(" RESULT : class=" + v['class'] + " parameter=" + v['parameter'] + " value=" + v['value'] + " filter=" + v['filterParameter'] + " filterval=" + v['filterValue']);
Expand All @@ -19,7 +19,7 @@ function eventResearched(research, structure, player)
if (Stats[ctype][cname][parameter] instanceof Array)
{
var dst = Upgrades[player][ctype][cname][parameter].slice();
for (var x = 0; x < dst.length; x++)
for (let x = 0; x < dst.length; x++)
{
dst[x] += Math.ceil(Stats[ctype][cname][parameter][x] * v['value'] / 100);
}
Expand Down
8 changes: 4 additions & 4 deletions data/mp/multiplay/script/rules/oildrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function placeOilDrum()
var nearbyTruck = false;
const SCAN_RANGE_TRUCKS = 6;
var nearbyObjects = enumRange(x, y, SCAN_RANGE_TRUCKS, ALL_PLAYERS, false);
for (var i = 0, len = nearbyObjects.length; i < len; ++i)
for (let i = 0, len = nearbyObjects.length; i < len; ++i)
{
var object = nearbyObjects[i];
if (object.type === DROID && object.droidType === DROID_CONSTRUCT)
Expand All @@ -31,7 +31,7 @@ function placeOilDrum()
// see if the random position is valid
var occupied = (enumRange(x, y, SCAN_RANGE_OCCUPIED, ALL_PLAYERS, false).length > 0);
var unreachable = true;
for (var i = 0; i < maxPlayers; ++i)
for (let i = 0; i < maxPlayers; ++i)
{
if (propulsionCanReach("hover01", x, y, startPositions[i].x, startPositions[i].y))
{
Expand Down Expand Up @@ -61,7 +61,7 @@ function eventPickup(feature, droid)
{
if (feature.stattype == OIL_DRUM)
{
var delay;
let delay;
// generate Geom(1/6) distribution for oil drum respawn delay
for (delay = 0; ; ++delay)
{
Expand All @@ -84,7 +84,7 @@ function oilDrumInit()
{
// always at least one oil drum, and one more for every 64x64 tiles of map area
oilDrumData.maxOilDrums = (mapWidth * mapHeight) >> 12; // replace float division with shift for sync-safety
for (var i = 0; i < oilDrumData.maxOilDrums; ++i)
for (let i = 0; i < oilDrumData.maxOilDrums; ++i)
{
queue("placeOilDrum", 10000 * i);
}
Expand Down
12 changes: 6 additions & 6 deletions data/mp/multiplay/script/rules/reticule.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ function reticuleManufactureCheck()
var structureComplete = false;
var facs = [FACTORY, CYBORG_FACTORY, VTOL_FACTORY,];

for (var i = 0, len = facs.length; i < len; ++i)
for (let i = 0, len = facs.length; i < len; ++i)
{
var onMapFacs = enumStruct(selectedPlayer, facs[i]);
for (var j = 0, len2 = onMapFacs.length; j < len2; ++j)
for (let j = 0, len2 = onMapFacs.length; j < len2; ++j)
{
if (onMapFacs[j].status === BUILT)
{
Expand All @@ -31,10 +31,10 @@ function reticuleResearchCheck()
var structureComplete = false;
var labs = [RESEARCH_LAB,];

for (var i = 0, len = labs.length; i < len; ++i)
for (let i = 0, len = labs.length; i < len; ++i)
{
var onMapResLabs = enumStruct(selectedPlayer, labs[i]);
for (var j = 0, len2 = onMapResLabs.length; j < len2; ++j)
for (let j = 0, len2 = onMapResLabs.length; j < len2; ++j)
{
if (onMapResLabs[j].status === BUILT)
{
Expand Down Expand Up @@ -70,10 +70,10 @@ function reticuleDesignCheck()
var structureComplete = false;
var HQS = [HQ,];

for (var i = 0, len = HQS.length; i < len; ++i)
for (let i = 0, len = HQS.length; i < len; ++i)
{
var onMapHQ = enumStruct(selectedPlayer, HQS[i]);
for (var j = 0, len2 = onMapHQ.length; j < len2; ++j)
for (let j = 0, len2 = onMapHQ.length; j < len2; ++j)
{
if (onMapHQ[j].status === BUILT)
{
Expand Down
4 changes: 2 additions & 2 deletions data/mp/multiplay/script/rules/setup/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function setupBase(player) // inside hackNetOff()
completeResearchOnTime(cleanTech, player);
// Keep only some structures for insane AI
var structs = enumStruct(player);
for (var i = 0; i < structs.length; i++)
for (let i = 0; i < structs.length; i++)
{
var s = structs[i];
if (playerData[player].difficulty != INSANE
Expand All @@ -23,7 +23,7 @@ function setupBase(player) // inside hackNetOff()
completeResearchOnTime(timeBaseTech, player);
// Keep only some structures
var structs = enumStruct(player);
for (var i = 0; i < structs.length; i++)
for (let i = 0; i < structs.length; i++)
{
var s = structs[i];
if ((playerData[player].difficulty != INSANE && (s.stattype == WALL || s.stattype == DEFENSE))
Expand Down
8 changes: 4 additions & 4 deletions data/mp/multiplay/script/scavengers/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function produceDroid(fac1) {
case 4: buildDroid(fac1, "Firebus", "FireBody", "BaBaProp", null, null, "BabaFlame"); break;
default: buildDroid(fac1, "Bloke", "B1BaBaPerson01", "BaBaLegs", null, null, "BaBaMG"); break;
}
}
}
}

// Regularly check back on our scavs
Expand All @@ -46,7 +46,7 @@ function scavtick()
{
// another way of dealing with lists is to iterate over them
// note, you must NOT use the for (... in ...) construct to iterate over an array of objects with properties!
for (var i = 0; i < droidlist.length; i++)
for (let i = 0; i < droidlist.length; i++)
{
var droid = droidlist[i];
var current = 0;
Expand All @@ -55,7 +55,7 @@ function scavtick()

// Find closest factory; notice that we still have the factory list from earlier, which
// saves us a few expensive scripting calls
for (var j = 0; j < factorylist.length; j++)
for (let j = 0; j < factorylist.length; j++)
{
var fact = factorylist[j];
current = distBetweenTwoPoints(fact.x, fact.y, droid.x, droid.y);
Expand Down Expand Up @@ -104,7 +104,7 @@ function eventAttacked(victim, attacker)
{
lastAttack = gameTime;
var droidlist = enumGroup(attackGroup);
for (var i = 0; i < droidlist.length; i++)
for (let i = 0; i < droidlist.length; i++)
{
var droid = droidlist[i];
if (distBetweenTwoPoints(victim.x, victim.y, attacker.x, attacker.y) < 24)
Expand Down

0 comments on commit 11710b4

Please sign in to comment.