Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_UnitAI.js
Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | AddMock(unit, IID_Position, { | ||||
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": () => {}, | ||||
"GetPassabilityClassName": () => "default" | "GetPassabilityClassName": () => "default", | ||||
"FaceTowardsPoint": () => true, | |||||
}); | }); | ||||
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, "elevationBonus": 0 }; }, | ||||
GetFullAttackRange: function() { return { "max": 40, "min": 0}; }, | GetFullAttackRange: function() { return { "max": 40, "min": 0, "elevationBonus": 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.SetupRangeQuery(1); | unitAI.SetupRangeQuery(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_UnitAI, { | AddMock(enemy, IID_UnitAI, { | ||||
IsAnimal: function() { return false; } | IsAnimal: function() { return false; } | ||||
}); | }); | ||||
AddMock(enemy, IID_Position, { | |||||
GetTurretParent: function() { return INVALID_ENTITY; }, | |||||
GetPosition: function() { return new Vector3D(); }, | |||||
GetPosition2D: function() { return new Vector2D(); }, | |||||
IsInWorld: function() { return true; }, | |||||
}); | |||||
} | } | ||||
else if (mode == 2) | else if (mode == 2) | ||||
AddMock(enemy, IID_Health, { | AddMock(enemy, IID_Health, { | ||||
GetHitpoints: function() { return 0; }, | GetHitpoints: function() { return 0; }, | ||||
}); | }); | ||||
var controllerFormation = ConstructComponent(controller, "Formation", {"FormationName": "Line Closed", "FormationShape": "square", "ShiftRows": "false", "SortingClasses": "", "WidthDepthRatio": 1, "UnitSeparationWidthMultiplier": 1, "UnitSeparationDepthMultiplier": 1, "SpeedMultiplier": 1, "Sloppyness": 0}); | var controllerFormation = ConstructComponent(controller, "Formation", {"FormationName": "Line Closed", "FormationShape": "square", "ShiftRows": "false", "SortingClasses": "", "WidthDepthRatio": 1, "UnitSeparationWidthMultiplier": 1, "UnitSeparationDepthMultiplier": 1, "SpeedMultiplier": 1, "Sloppyness": 0}); | ||||
var controllerAI = ConstructComponent(controller, "UnitAI", { "FormationController": "true", "DefaultStance": "aggressive" }); | var controllerAI = ConstructComponent(controller, "UnitAI", { "FormationController": "true", "DefaultStance": "aggressive" }); | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | AddMock(unit + i, IID_Position, { | ||||
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": () => {}, | ||||
"GetPassabilityClassName": () => "default" | "GetPassabilityClassName": () => "default", | ||||
"FaceTowardsPoint": () => true, | |||||
}); | }); | ||||
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, "elevationBonus": 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.SetupRangeQuery(1); | unitAI.SetupRangeQuery(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, { | |||||
GetTurretParent: function() { return INVALID_ENTITY; }, | |||||
GetPosition: function() { return new Vector3D(); }, | |||||
GetPosition2D: function() { return new Vector2D(); }, | |||||
IsInWorld: function() { return true; }, | |||||
}); | |||||
var controllerFormation = ConstructComponent(controller, "Formation", {"FormationName": "Line Closed", "FormationShape": "square", "ShiftRows": "false", "SortingClasses": "", "WidthDepthRatio": 1, "UnitSeparationWidthMultiplier": 1, "UnitSeparationDepthMultiplier": 1, "SpeedMultiplier": 1, "Sloppyness": 0}); | var controllerFormation = ConstructComponent(controller, "Formation", {"FormationName": "Line Closed", "FormationShape": "square", "ShiftRows": "false", "SortingClasses": "", "WidthDepthRatio": 1, "UnitSeparationWidthMultiplier": 1, "UnitSeparationDepthMultiplier": 1, "SpeedMultiplier": 1, "Sloppyness": 0}); | ||||
var controllerAI = ConstructComponent(controller, "UnitAI", { "FormationController": "true", "DefaultStance": "aggressive" }); | var controllerAI = ConstructComponent(controller, "UnitAI", { "FormationController": "true", "DefaultStance": "aggressive" }); | ||||
AddMock(controller, IID_Position, { | AddMock(controller, IID_Position, { | ||||
GetTurretParent: function() { return INVALID_ENTITY; }, | GetTurretParent: function() { return INVALID_ENTITY; }, | ||||
JumpTo: function(x, z) { this.x = x; this.z = z; }, | JumpTo: function(x, z) { this.x = x; this.z = z; }, | ||||
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; }, | ||||
}); | }); | ||||
AddMock(controller, IID_UnitMotion, { | AddMock(controller, IID_UnitMotion, { | ||||
"GetWalkSpeed": () => 1, | "GetWalkSpeed": () => 1, | ||||
"SetSpeedMultiplier": (speed) => {}, | "SetSpeedMultiplier": (speed) => {}, | ||||
"MoveToPointRange": (x, z, minRange, maxRange) => {}, | "MoveToPointRange": (x, z, minRange, maxRange) => {}, | ||||
"StopMoving": () => {}, | "StopMoving": () => {}, | ||||
"GetPassabilityClassName": () => "default" | "GetPassabilityClassName": () => "default", | ||||
"FaceTowardsPoint": () => true, | |||||
}); | }); | ||||
AddMock(controller, IID_Attack, { | AddMock(controller, IID_Attack, { | ||||
GetRange: function() { return {"max":10, "min": 0}; }, | GetRange: function() { return { "max":10, "min": 0, "elevationBonus": 0 }; }, | ||||
Stan: Missing spaces? | |||||
CanAttackAsFormation: function() { return false; }, | CanAttackAsFormation: function() { return false; }, | ||||
}); | }); | ||||
controllerAI.OnCreate(); | controllerAI.OnCreate(); | ||||
controllerFormation.SetMembers(units); | controllerFormation.SetMembers(units); | ||||
controllerAI.Attack(enemy, []); | controllerAI.Attack(enemy, []); | ||||
Show All 21 Lines |
Wildfire Games · Phabricator
Missing spaces?