Skip to content

Commit

Permalink
Fix cache issue.
Browse files Browse the repository at this point in the history
Sometimes results from calling two or more cached functions from the same function could swap the returned data.
  • Loading branch information
KJeff01 committed May 9, 2020
1 parent 561cd93 commit e0a4101
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 37 deletions.
6 changes: 3 additions & 3 deletions multiplay/skirmish/cobra_includes/adaption.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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);
}


Expand Down
4 changes: 2 additions & 2 deletions multiplay/skirmish/cobra_includes/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions multiplay/skirmish/cobra_includes/mapDynamics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -130,7 +130,7 @@ function mapOilLevel()
return str;
}

return cacheThis(uncached, [], undefined, Infinity);
return cacheThis(uncached, [], "mapOilLevel1", Infinity);
}

function highOilMap()
Expand All @@ -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.
Expand Down Expand Up @@ -225,5 +225,5 @@ function cobraBaseArea()
return area;
}

return cacheThis(uncached, [], undefined, 20000);
return cacheThis(uncached, [], "cobraBaseArea1", 20000);
}
37 changes: 14 additions & 23 deletions multiplay/skirmish/cobra_includes/miscFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -402,5 +393,5 @@ function randomOffsetLocation(location)
return {x: newValueX, y: newValueY};
}

return cacheThis(uncached, [location], undefined, 2000);
return cacheThis(uncached, [location], "randomOffsetLocation1", 2000);
}
6 changes: 3 additions & 3 deletions multiplay/skirmish/cobra_includes/tactics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e0a4101

Please sign in to comment.