Fix missing parentheses in formation turning angle calculation
The function that is calculating the difference between the two angles is missing some parentheses. Didn't notice it sooner as it works in 95% of all cases without them, but sometimes you can see the formation doing a wrong turn. reviewed by : @Freagarach Differential revision: https://code.wildfiregames.com/D4626 This was SVN commit r26874.
This commit is contained in:
parent
ed4e07e594
commit
dec727ce8e
@ -892,7 +892,7 @@ Formation.prototype.GetRealOffsetPositions = function(offsets)
|
||||
|
||||
Formation.prototype.AreAnglesSimilar = function(a1, a2)
|
||||
{
|
||||
const d = Math.abs(a1 - a2) % 2 * Math.PI;
|
||||
const d = Math.abs(a1 - a2) % (2 * Math.PI);
|
||||
return d < this.maxTurningAngle || d > 2 * Math.PI - this.maxTurningAngle;
|
||||
};
|
||||
|
||||
|
@ -0,0 +1,40 @@
|
||||
Engine.LoadComponentScript("interfaces/Timer.js");
|
||||
Engine.LoadComponentScript("interfaces/Formation.js");
|
||||
Engine.LoadComponentScript("Formation.js");
|
||||
|
||||
const entity_id = 5;
|
||||
|
||||
AddMock(SYSTEM_ENTITY, IID_Timer, {
|
||||
"SetInterval": () => {},
|
||||
"SetTimeout": () => {},
|
||||
});
|
||||
|
||||
const formationTemplate = {
|
||||
"RequiredMemberCount": 2,
|
||||
"DisabledTooltip": "",
|
||||
"SpeedMultiplier": 1,
|
||||
"FormationShape": "square",
|
||||
"MaxTurningAngle": 0,
|
||||
"SortingClasses": "Hero Champion Cavalry Melee Ranged",
|
||||
"SortingOrder": "fillToTheCenter",
|
||||
"ShiftRows": false,
|
||||
"UnitSeparationWidthMultiplier": 1,
|
||||
"UnitSeparationDepthMultiplier": 1,
|
||||
"WidthDepthRatio": 1,
|
||||
"Sloppiness": 0
|
||||
};
|
||||
|
||||
const cmpFormation = ConstructComponent(entity_id, "Formation", formationTemplate);
|
||||
|
||||
const testingAngles = [];
|
||||
|
||||
for (let i = 0; i < 179; i++)
|
||||
testingAngles.push(i * Math.PI / 180);
|
||||
|
||||
TS_ASSERT(testingAngles.every(x => !cmpFormation.AreAnglesSimilar(0, x)));
|
||||
TS_ASSERT(testingAngles.every(x => !cmpFormation.AreAnglesSimilar(0, -x)));
|
||||
|
||||
cmpFormation.maxTurningAngle = Math.PI;
|
||||
|
||||
TS_ASSERT(testingAngles.every(x => cmpFormation.AreAnglesSimilar(0, x)));
|
||||
TS_ASSERT(testingAngles.every(x => cmpFormation.AreAnglesSimilar(0, -x)));
|
Loading…
Reference in New Issue
Block a user