Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_UnitAI.js
Engine.LoadHelperScript("FSM.js"); | Engine.LoadHelperScript("FSM.js"); | ||||
Engine.LoadHelperScript("Entity.js"); | Engine.LoadHelperScript("Entity.js"); | ||||
Engine.LoadHelperScript("Player.js"); | Engine.LoadHelperScript("Player.js"); | ||||
Engine.LoadHelperScript("Sound.js"); | |||||
Engine.LoadComponentScript("interfaces/Attack.js"); | Engine.LoadComponentScript("interfaces/Attack.js"); | ||||
Engine.LoadComponentScript("interfaces/Auras.js"); | Engine.LoadComponentScript("interfaces/Auras.js"); | ||||
Engine.LoadComponentScript("interfaces/Builder.js"); | |||||
Engine.LoadComponentScript("interfaces/BuildingAI.js"); | Engine.LoadComponentScript("interfaces/BuildingAI.js"); | ||||
Engine.LoadComponentScript("interfaces/Capturable.js"); | Engine.LoadComponentScript("interfaces/Capturable.js"); | ||||
Engine.LoadComponentScript("interfaces/Resistance.js"); | Engine.LoadComponentScript("interfaces/Resistance.js"); | ||||
Engine.LoadComponentScript("interfaces/Formation.js"); | Engine.LoadComponentScript("interfaces/Formation.js"); | ||||
Engine.LoadComponentScript("interfaces/Heal.js"); | Engine.LoadComponentScript("interfaces/Heal.js"); | ||||
Engine.LoadComponentScript("interfaces/Health.js"); | Engine.LoadComponentScript("interfaces/Health.js"); | ||||
Engine.LoadComponentScript("interfaces/Pack.js"); | Engine.LoadComponentScript("interfaces/Pack.js"); | ||||
Engine.LoadComponentScript("interfaces/ResourceSupply.js"); | Engine.LoadComponentScript("interfaces/ResourceSupply.js"); | ||||
Engine.LoadComponentScript("interfaces/ResourceGatherer.js"); | Engine.LoadComponentScript("interfaces/ResourceGatherer.js"); | ||||
Engine.LoadComponentScript("interfaces/Timer.js"); | Engine.LoadComponentScript("interfaces/Timer.js"); | ||||
Engine.LoadComponentScript("interfaces/UnitAI.js"); | Engine.LoadComponentScript("interfaces/UnitAI.js"); | ||||
Engine.LoadComponentScript("Formation.js"); | Engine.LoadComponentScript("Formation.js"); | ||||
Engine.LoadComponentScript("UnitAI.js"); | Engine.LoadComponentScript("UnitAI.js"); | ||||
/** | |||||
* Fairly straightforward test that entity renaming is handled | |||||
* by unitAI states. These ought to be augmented with integration tests, ideally. | |||||
*/ | |||||
function TestTargetEntityRenaming(init_state, post_state, setup) | |||||
{ | |||||
ResetState(); | |||||
const player_ent = 5; | |||||
const target_ent = 6; | |||||
AddMock(SYSTEM_ENTITY, IID_Timer, { | |||||
"SetInterval": () => {}, | |||||
"SetTimeout": () => {}, | |||||
bb: trailing `,`, more below | |||||
}); | |||||
AddMock(SYSTEM_ENTITY, IID_ObstructionManager, { | |||||
"IsInTargetRange": () => false, | |||||
}); | |||||
let unitAI = ConstructComponent(player_ent, "UnitAI", { | |||||
"FormationController": "false", | |||||
"DefaultStance": "aggressive", | |||||
"FleeDistance": 10, | |||||
}); | |||||
unitAI.OnCreate(); | |||||
setup(unitAI, player_ent, target_ent); | |||||
TS_ASSERT_EQUALS(unitAI.GetCurrentState(), init_state); | |||||
unitAI.OnGlobalEntityRenamed({ | |||||
"entity": target_ent, | |||||
"newentity": target_ent + 1, | |||||
}); | |||||
TS_ASSERT_EQUALS(unitAI.GetCurrentState(), post_state); | |||||
} | |||||
TestTargetEntityRenaming( | |||||
"INDIVIDUAL.GARRISON.APPROACHING", "INDIVIDUAL.IDLE", | |||||
(unitAI, player_ent, target_ent) => { | |||||
unitAI.CanGarrison = (target) => target == target_ent; | |||||
unitAI.MoveToGarrisonRange = (target) => target == target_ent; | |||||
AddMock(target_ent, IID_GarrisonHolder, { | |||||
"CanPickup": () => false, | |||||
}); | |||||
unitAI.Garrison(target_ent, false); | |||||
} | |||||
); | |||||
TestTargetEntityRenaming( | |||||
"INDIVIDUAL.REPAIR.REPAIRING", "INDIVIDUAL.IDLE", | |||||
(unitAI, player_ent, target_ent) => { | |||||
QueryBuilderListInterface = () => {}; | |||||
unitAI.CheckTargetRange = () => true; | |||||
unitAI.CanRepair = (target) => target == target_ent; | |||||
unitAI.Repair(target_ent, false, false); | |||||
} | |||||
); | |||||
TestTargetEntityRenaming( | |||||
"INDIVIDUAL.FLEEING", "INDIVIDUAL.FLEEING", | |||||
(unitAI, player_ent, target_ent) => { | |||||
DistanceBetweenEntities = () => 10; | |||||
unitAI.CheckTargetRangeExplicit = () => false; | |||||
AddMock(player_ent, IID_UnitMotion, { | |||||
"MoveToTargetRange": () => true, | |||||
"GetRunMultiplier": () => 1.0, | |||||
bbUnsubmitted Not Done Inline Actionstrailing .0 bb: trailing `.0` | |||||
"SetSpeedMultiplier": () => {}, | |||||
"StopMoving": () => {}, | |||||
}); | |||||
unitAI.Flee(target_ent, false); | |||||
} | |||||
); | |||||
/* Regression test. | /* Regression test. | ||||
* Tests the FSM behaviour of a unit when walking as part of a formation, | * Tests the FSM behaviour of a unit when walking as part of a formation, | ||||
* then exiting the formation. | * then exiting the formation. | ||||
* mode == 0: There is no enemy unit nearby. | * mode == 0: There is no enemy unit nearby. | ||||
* mode == 1: There is a live enemy unit nearby. | * mode == 1: There is a live enemy unit nearby. | ||||
* mode == 2: There is a dead enemy unit nearby. | * mode == 2: There is a dead enemy unit nearby. | ||||
*/ | */ | ||||
function TestFormationExiting(mode) | function TestFormationExiting(mode) | ||||
▲ Show 20 Lines • Show All 306 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
trailing ,, more below