From e0a4101c795ca8eea41d1cb764f02936978c1327 Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Sat, 9 May 2020 17:17:51 -0500 Subject: [PATCH] Fix cache issue. Sometimes results from calling two or more cached functions from the same function could swap the returned data. --- multiplay/skirmish/cobra_includes/adaption.js | 6 +-- multiplay/skirmish/cobra_includes/build.js | 4 +- .../skirmish/cobra_includes/mapDynamics.js | 12 +++--- .../skirmish/cobra_includes/miscFunctions.js | 37 +++++++------------ multiplay/skirmish/cobra_includes/tactics.js | 6 +-- 5 files changed, 28 insertions(+), 37 deletions(-) diff --git a/multiplay/skirmish/cobra_includes/adaption.js b/multiplay/skirmish/cobra_includes/adaption.js index f67a069..9bdacd8 100644 --- a/multiplay/skirmish/cobra_includes/adaption.js +++ b/multiplay/skirmish/cobra_includes/adaption.js @@ -36,7 +36,7 @@ function playerCyborgRatio(player) return enumDroid(player, DROID_CYBORG).length / (enumDroid(player).length + 1); } - return cacheThis(uncached, [player], undefined, 8000); + return cacheThis(uncached, [player], "playerCyborgRatio" + player, 8000); } //Count how many Enemy VTOL units are on the map. @@ -63,7 +63,7 @@ function countEnemyVTOL(player) return enemyVtolCount; } - return cacheThis(uncached, [player], undefined, 9000); + return cacheThis(uncached, [player], "countEnemyVTOL" + player, 9000); } function playerVtolRatio(player) @@ -78,7 +78,7 @@ function playerVtolRatio(player) return countEnemyVTOL(player) / (enumDroid(player).length + 1); } - return cacheThis(uncached, [player], undefined, 6000); + return cacheThis(uncached, [player], "playerVtolRatio" + player, 6000); } diff --git a/multiplay/skirmish/cobra_includes/build.js b/multiplay/skirmish/cobra_includes/build.js index 7240af4..b5b36f3 100644 --- a/multiplay/skirmish/cobra_includes/build.js +++ b/multiplay/skirmish/cobra_includes/build.js @@ -7,7 +7,7 @@ function needPowerGenerator() return ((countStruct(structures.derricks) - (countStruct(structures.gens) * 4)) > 0); } - return cacheThis(uncached, [], undefined, 8000); + return cacheThis(uncached, [], "needPowerGenerator1", 8000); } function minTruckCount() @@ -17,7 +17,7 @@ function minTruckCount() return (highOilMap() ? 3 : 2) * MIN_TRUCKS_PER_GROUP; } - return cacheThis(uncached, [], undefined, Infinity); + return cacheThis(uncached, [], "minTruckCount1", Infinity); } //Determine if this is a constructor droid. Specify and optional second paramter diff --git a/multiplay/skirmish/cobra_includes/mapDynamics.js b/multiplay/skirmish/cobra_includes/mapDynamics.js index 0ea6922..be382f4 100644 --- a/multiplay/skirmish/cobra_includes/mapDynamics.js +++ b/multiplay/skirmish/cobra_includes/mapDynamics.js @@ -59,7 +59,7 @@ function checkIfSeaMap() return hoverMap; } - return cacheThis(uncached, [], undefined, Infinity); + return cacheThis(uncached, [], "checkIfSeaMap1", Infinity); } //All derricks and all oil resources to find the map total. @@ -81,7 +81,7 @@ function countAllResources() return amount; } - return cacheThis(uncached, [], undefined, Infinity); + return cacheThis(uncached, [], "countAllResources1", Infinity); } // The amount of oil each player should hold. @@ -100,7 +100,7 @@ function averageOilPerPlayer() return Math.floor(countAllResources() / players); } - return cacheThis(uncached, [], undefined, Infinity); + return cacheThis(uncached, [], "averageOilPerPlayer1", Infinity); } //Is the map a low/medium/high power level. Returns a string of LOW/MEDIUM/HIGH. @@ -130,7 +130,7 @@ function mapOilLevel() return str; } - return cacheThis(uncached, [], undefined, Infinity); + return cacheThis(uncached, [], "mapOilLevel1", Infinity); } function highOilMap() @@ -147,7 +147,7 @@ function highOilMap() return false; } - return cacheThis(uncached, [], undefined, Infinity); + return cacheThis(uncached, [], "highOilMap1", Infinity); } //Determine the base area that Cobra claims. @@ -225,5 +225,5 @@ function cobraBaseArea() return area; } - return cacheThis(uncached, [], undefined, 20000); + return cacheThis(uncached, [], "cobraBaseArea1", 20000); } diff --git a/multiplay/skirmish/cobra_includes/miscFunctions.js b/multiplay/skirmish/cobra_includes/miscFunctions.js index 9000b28..79713da 100644 --- a/multiplay/skirmish/cobra_includes/miscFunctions.js +++ b/multiplay/skirmish/cobra_includes/miscFunctions.js @@ -103,7 +103,7 @@ function rangeStep(player) return undefined; } - return cacheThis(uncached, [player]); + return cacheThis(uncached, [player], "rangeStep" + player, 10000); } //passing true finds allies and passing false finds enemies. @@ -114,31 +114,22 @@ function playerAlliance(ally) ally = false; } - function uncached(ally) + var players = []; + + for (var i = 0; i < maxPlayers; ++i) { - var players = []; - for (var i = 0; i < maxPlayers; ++i) + if (i === me) { - if (!ally) - { - if (!allianceExistsBetween(i, me) && (i !== me)) - { - players.push(i); - } - } - else - { - if (allianceExistsBetween(i, me) && (i !== me)) - { - players.push(i); - } - } + continue; } - return players; + if ((!ally && !allianceExistsBetween(i, me)) || (ally && allianceExistsBetween(i, me))) + { + players.push(i); + } } - return cacheThis(uncached, [ally], undefined, 5000); + return players; } //return real power levels. @@ -185,7 +176,7 @@ function findLivingEnemies() return alive; } - return cacheThis(uncached, [], undefined, 8000); + return cacheThis(uncached, [], "findLivingEnemies1", 8000); } //The enemy of which Cobra is focusing on. @@ -230,7 +221,7 @@ function getMostHarmfulPlayer() return mostHarmful; } - return cacheThis(uncached, [], undefined, 5000); + return cacheThis(uncached, [], "getMostHarmfulPlayer1", 5000); } //Set the initial grudge counter to target a random enemy. @@ -402,5 +393,5 @@ function randomOffsetLocation(location) return {x: newValueX, y: newValueY}; } - return cacheThis(uncached, [location], undefined, 2000); + return cacheThis(uncached, [location], "randomOffsetLocation1", 2000); } diff --git a/multiplay/skirmish/cobra_includes/tactics.js b/multiplay/skirmish/cobra_includes/tactics.js index 51ed4eb..20c6883 100644 --- a/multiplay/skirmish/cobra_includes/tactics.js +++ b/multiplay/skirmish/cobra_includes/tactics.js @@ -54,7 +54,7 @@ function returnClosestEnemyFactory(enemyNumber) return undefined; } - return cacheThis(uncached, [enemyNumber]); + return cacheThis(uncached, [enemyNumber], "returnClosestEnemyFactory" + enemyNumber, 8000); } //Should the vtol attack when ammo is high enough? @@ -179,7 +179,7 @@ function findNearestEnemyDroid(enemy) return undefined; } - return cacheThis(uncached, [enemy], enemy, 5000); + return cacheThis(uncached, [enemy], "findNearestEnemyDroid" + enemy, 5000); } //Return information about the closest structure of an enemy. Returns undefined otherwise. @@ -207,7 +207,7 @@ function findNearestEnemyStructure(enemy) return undefined; } - return cacheThis(uncached, [enemy], enemy, 5000); + return cacheThis(uncached, [enemy], "findNearestEnemyStructure" + enemy, 5000); } //Sensors know all your secrets. They will observe what is closest to Cobra base.