Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_UnitAI.js
Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | function TestFormationExiting(mode) | ||||
AddMock(SYSTEM_ENTITY, IID_RangeManager, { | AddMock(SYSTEM_ENTITY, IID_RangeManager, { | ||||
CreateActiveQuery: function(ent, minRange, maxRange, players, iid, flags) { | CreateActiveQuery: function(ent, minRange, maxRange, players, iid, flags) { | ||||
return 1; | return 1; | ||||
}, | }, | ||||
EnableActiveQuery: function(id) { }, | EnableActiveQuery: function(id) { }, | ||||
ResetActiveQuery: function(id) { if (mode == 0) return []; else return [enemy]; }, | ResetActiveQuery: function(id) { if (mode == 0) return []; else return [enemy]; }, | ||||
DisableActiveQuery: function(id) { }, | DisableActiveQuery: function(id) { }, | ||||
GetEntityFlagMask: function(identifier) { }, | GetEntityFlagMask: function(identifier) { }, | ||||
GetLosVisibility: function() { return "visible"; } | |||||
}); | }); | ||||
AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | ||||
GetCurrentTemplateName: function(ent) { return "special/formations/line_closed"; }, | GetCurrentTemplateName: function(ent) { return "special/formations/line_closed"; }, | ||||
}); | }); | ||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | ||||
GetPlayerByID: function(id) { return playerEntity; }, | GetPlayerByID: function(id) { return playerEntity; }, | ||||
Show All 18 Lines | function TestFormationExiting(mode) | ||||
}); | }); | ||||
AddMock(unit, IID_Ownership, { | AddMock(unit, IID_Ownership, { | ||||
GetOwner: function() { return 1; }, | GetOwner: function() { return 1; }, | ||||
}); | }); | ||||
AddMock(unit, IID_Position, { | AddMock(unit, IID_Position, { | ||||
GetTurretParent: function() { return INVALID_ENTITY; }, | GetTurretParent: function() { return INVALID_ENTITY; }, | ||||
GetHeightOffset: function() { return 0; }, | |||||
GetPosition: function() { return new Vector3D(); }, | GetPosition: function() { return new Vector3D(); }, | ||||
GetPosition2D: function() { return new Vector2D(); }, | GetPosition2D: function() { return new Vector2D(); }, | ||||
GetRotation: function() { return { "y": 0 }; }, | GetRotation: function() { return { "y": 0 }; }, | ||||
IsInWorld: function() { return true; }, | IsInWorld: function() { return true; }, | ||||
}); | }); | ||||
AddMock(unit, IID_UnitMotion, { | AddMock(unit, IID_UnitMotion, { | ||||
"GetWalkSpeed": () => 1, | "GetWalkSpeed": () => 1, | ||||
"MoveToFormationOffset": (target, x, z) => {}, | "MoveToFormationOffset": (target, x, z) => {}, | ||||
"MoveToTargetRange": (target, min, max) => true, | "MoveToTargetRange": (target, min, max) => true, | ||||
"StopMoving": () => {}, | "StopMoving": () => {}, | ||||
"SetFacePointAfterMove": () => {}, | "SetFacePointAfterMove": () => {}, | ||||
"GetFacePointAfterMove": () => true, | "GetFacePointAfterMove": () => true, | ||||
"FaceTowardsPoint": () => {}, | |||||
"GetPassabilityClassName": () => "default" | "GetPassabilityClassName": () => "default" | ||||
}); | }); | ||||
AddMock(unit, IID_Vision, { | AddMock(unit, IID_Vision, { | ||||
GetRange: function() { return 10; }, | GetRange: function() { return 10; }, | ||||
}); | }); | ||||
AddMock(unit, IID_Attack, { | AddMock(unit, IID_Attack, { | ||||
GetRange: function() { return { "max": 10, "min": 0}; }, | GetRange: function() { return { "max": 10, "min": 0}; }, | ||||
GetFullAttackRange: function() { return { "max": 40, "min": 0}; }, | GetFullAttackRange: function() { return { "max": 40, "min": 0}; }, | ||||
GetBestAttackAgainst: function(t) { return "melee"; }, | GetBestAttackAgainst: function(t) { return "Melee"; }, | ||||
GetPreference: function(t) { return 0; }, | GetPreference: function(t) { return 0; }, | ||||
GetTimers: function() { return { "prepare": 500, "repeat": 1000 }; }, | GetTimers: function() { return { "prepare": 500, "repeat": 1000 }; }, | ||||
CanAttack: function(v) { return true; }, | CanAttack: function(v) { return true; }, | ||||
CompareEntitiesByPreference: function(a, b) { return 0; }, | CompareEntitiesByPreference: function(a, b) { return 0; }, | ||||
}); | }); | ||||
unitAI.OnCreate(); | unitAI.OnCreate(); | ||||
unitAI.SetupAttackRangeQuery(1); | unitAI.SetupAttackRangeQuery(1); | ||||
if (mode == 1) | if (mode == 1) | ||||
{ | { | ||||
AddMock(enemy, IID_Health, { | AddMock(enemy, IID_Health, { | ||||
GetHitpoints: function() { return 10; }, | GetHitpoints: function() { return 10; }, | ||||
}); | }); | ||||
AddMock(enemy, IID_Position, { | |||||
GetHeightOffset: function() { return 0; }, | |||||
GetPosition: function() { return new Vector3D(); }, | |||||
GetPosition2D: function() { return new Vector2D(this.x, this.z); }, | |||||
IsInWorld: function() { return true; } | |||||
}); | |||||
AddMock(enemy, IID_UnitAI, { | AddMock(enemy, IID_UnitAI, { | ||||
IsAnimal: function() { return false; } | IsAnimal: function() { return false; } | ||||
}); | }); | ||||
} | } | ||||
else if (mode == 2) | else if (mode == 2) | ||||
AddMock(enemy, IID_Health, { | AddMock(enemy, IID_Health, { | ||||
GetHitpoints: function() { return 0; }, | GetHitpoints: function() { return 0; }, | ||||
}); | }); | ||||
Show All 12 Lines | function TestFormationExiting(mode) | ||||
let controllerAI = ConstructComponent(controller, "UnitAI", { | let controllerAI = ConstructComponent(controller, "UnitAI", { | ||||
"FormationController": "true", | "FormationController": "true", | ||||
"DefaultStance": "aggressive" | "DefaultStance": "aggressive" | ||||
}); | }); | ||||
AddMock(controller, IID_Position, { | AddMock(controller, IID_Position, { | ||||
JumpTo: function(x, z) { this.x = x; this.z = z; }, | JumpTo: function(x, z) { this.x = x; this.z = z; }, | ||||
GetTurretParent: function() { return INVALID_ENTITY; }, | GetTurretParent: function() { return INVALID_ENTITY; }, | ||||
GetHeightOffset: function() { return 0; }, | |||||
GetPosition: function() { return new Vector3D(this.x, 0, this.z); }, | GetPosition: function() { return new Vector3D(this.x, 0, this.z); }, | ||||
GetPosition2D: function() { return new Vector2D(this.x, this.z); }, | GetPosition2D: function() { return new Vector2D(this.x, this.z); }, | ||||
GetRotation: function() { return { "y": 0 }; }, | GetRotation: function() { return { "y": 0 }; }, | ||||
IsInWorld: function() { return true; }, | IsInWorld: function() { return true; }, | ||||
MoveOutOfWorld: () => {} | MoveOutOfWorld: () => {} | ||||
}); | }); | ||||
AddMock(controller, IID_UnitMotion, { | AddMock(controller, IID_UnitMotion, { | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | function TestMoveIntoFormationWhileAttacking() | ||||
AddMock(SYSTEM_ENTITY, IID_RangeManager, { | AddMock(SYSTEM_ENTITY, IID_RangeManager, { | ||||
CreateActiveQuery: function(ent, minRange, maxRange, players, iid, flags) { | CreateActiveQuery: function(ent, minRange, maxRange, players, iid, flags) { | ||||
return 1; | return 1; | ||||
}, | }, | ||||
EnableActiveQuery: function(id) { }, | EnableActiveQuery: function(id) { }, | ||||
ResetActiveQuery: function(id) { return [enemy]; }, | ResetActiveQuery: function(id) { return [enemy]; }, | ||||
DisableActiveQuery: function(id) { }, | DisableActiveQuery: function(id) { }, | ||||
GetEntityFlagMask: function(identifier) { }, | GetEntityFlagMask: function(identifier) { }, | ||||
GetLosVisibility: function() { return "visible"; } | |||||
}); | }); | ||||
AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | ||||
GetCurrentTemplateName: function(ent) { return "special/formations/line_closed"; }, | GetCurrentTemplateName: function(ent) { return "special/formations/line_closed"; }, | ||||
}); | }); | ||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | ||||
GetPlayerByID: function(id) { return playerEntity; }, | GetPlayerByID: function(id) { return playerEntity; }, | ||||
Show All 22 Lines | for (var i = 0; i < unitCount; i++) { | ||||
}); | }); | ||||
AddMock(unit + i, IID_Ownership, { | AddMock(unit + i, IID_Ownership, { | ||||
GetOwner: function() { return 1; }, | GetOwner: function() { return 1; }, | ||||
}); | }); | ||||
AddMock(unit + i, IID_Position, { | AddMock(unit + i, IID_Position, { | ||||
GetTurretParent: function() { return INVALID_ENTITY; }, | GetTurretParent: function() { return INVALID_ENTITY; }, | ||||
GetHeightOffset: function() { return 0; }, | |||||
GetPosition: function() { return new Vector3D(); }, | GetPosition: function() { return new Vector3D(); }, | ||||
GetPosition2D: function() { return new Vector2D(); }, | GetPosition2D: function() { return new Vector2D(); }, | ||||
TurnTo: function() {}, | |||||
GetRotation: function() { return { "y": 0 }; }, | GetRotation: function() { return { "y": 0 }; }, | ||||
IsInWorld: function() { return true; }, | IsInWorld: function() { return true; }, | ||||
}); | }); | ||||
AddMock(unit + i, IID_UnitMotion, { | AddMock(unit + i, IID_UnitMotion, { | ||||
"GetWalkSpeed": () => 1, | "GetWalkSpeed": () => 1, | ||||
"MoveToFormationOffset": (target, x, z) => {}, | "MoveToFormationOffset": (target, x, z) => {}, | ||||
"MoveToTargetRange": (target, min, max) => true, | "MoveToTargetRange": (target, min, max) => true, | ||||
"StopMoving": () => {}, | "StopMoving": () => {}, | ||||
"SetFacePointAfterMove": () => {}, | "SetFacePointAfterMove": () => {}, | ||||
"GetFacePointAfterMove": () => true, | "GetFacePointAfterMove": () => true, | ||||
"FaceTowardsPoint": () => {}, | |||||
"GetPassabilityClassName": () => "default" | "GetPassabilityClassName": () => "default" | ||||
}); | }); | ||||
AddMock(unit + i, IID_Vision, { | AddMock(unit + i, IID_Vision, { | ||||
GetRange: function() { return 10; }, | GetRange: function() { return 10; }, | ||||
}); | }); | ||||
AddMock(unit + i, IID_Attack, { | AddMock(unit + i, IID_Attack, { | ||||
GetRange: function() { return {"max":10, "min": 0}; }, | GetRange: function() { return {"max":10, "min": 0}; }, | ||||
GetFullAttackRange: function() { return { "max": 40, "min": 0}; }, | GetFullAttackRange: function() { return { "max": 40, "min": 0}; }, | ||||
GetBestAttackAgainst: function(t) { return "melee"; }, | GetBestAttackAgainst: function(t) { return "Melee"; }, | ||||
GetTimers: function() { return { "prepare": 500, "repeat": 1000 }; }, | GetTimers: function() { return { "prepare": 500, "repeat": 1000 }; }, | ||||
CanAttack: function(v) { return true; }, | CanAttack: function(v) { return true; }, | ||||
CompareEntitiesByPreference: function(a, b) { return 0; }, | CompareEntitiesByPreference: function(a, b) { return 0; }, | ||||
}); | }); | ||||
unitAI.OnCreate(); | unitAI.OnCreate(); | ||||
unitAI.SetupAttackRangeQuery(1); | unitAI.SetupAttackRangeQuery(1); | ||||
unitAIs.push(unitAI); | unitAIs.push(unitAI); | ||||
} | } | ||||
// create enemy | // create enemy | ||||
AddMock(enemy, IID_Health, { | AddMock(enemy, IID_Health, { | ||||
GetHitpoints: function() { return 40; }, | GetHitpoints: function() { return 40; }, | ||||
}); | }); | ||||
AddMock(enemy, IID_Position, { | |||||
GetHeightOffset: function() { return 0; }, | |||||
GetPosition: function() { return new Vector3D(); }, | |||||
GetPosition2D: function() { return new Vector2D(); }, | |||||
IsInWorld: function() { return true; } | |||||
}); | |||||
let controllerFormation = ConstructComponent(controller, "Formation", { | let controllerFormation = ConstructComponent(controller, "Formation", { | ||||
"FormationName": "Line Closed", | "FormationName": "Line Closed", | ||||
"FormationShape": "square", | "FormationShape": "square", | ||||
"ShiftRows": "false", | "ShiftRows": "false", | ||||
"SortingClasses": "", | "SortingClasses": "", | ||||
"WidthDepthRatio": 1, | "WidthDepthRatio": 1, | ||||
"UnitSeparationWidthMultiplier": 1, | "UnitSeparationWidthMultiplier": 1, | ||||
"UnitSeparationDepthMultiplier": 1, | "UnitSeparationDepthMultiplier": 1, | ||||
Show All 29 Lines | AddMock(controller, IID_Attack, { | ||||
GetRange: function() { return {"max":10, "min": 0}; }, | GetRange: function() { return {"max":10, "min": 0}; }, | ||||
CanAttackAsFormation: function() { return false; }, | CanAttackAsFormation: function() { return false; }, | ||||
}); | }); | ||||
controllerAI.OnCreate(); | controllerAI.OnCreate(); | ||||
controllerFormation.SetMembers(units); | controllerFormation.SetMembers(units); | ||||
controllerAI.Attack(enemy, []); | controllerAI.Attack(enemy); | ||||
for (let ent of unitAIs) | for (let ent of unitAIs) | ||||
TS_ASSERT_EQUALS(unitAI.fsmStateName, "INDIVIDUAL.COMBAT.ATTACKING"); | TS_ASSERT_EQUALS(unitAI.fsmStateName, "INDIVIDUAL.COMBAT.ATTACKING"); | ||||
controllerAI.MoveIntoFormation({"name": "Circle"}); | controllerAI.MoveIntoFormation({"name": "Circle"}); | ||||
// let all units be in position | // let all units be in position | ||||
for (let ent of unitAIs) | for (let ent of unitAIs) | ||||
Show All 13 Lines |
Wildfire Games · Phabricator