Index: ps/trunk/binaries/data/mods/public/gui/session/selection_panels.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/selection_panels.js +++ ps/trunk/binaries/data/mods/public/gui/session/selection_panels.js @@ -916,7 +916,7 @@ if (unitEntStates.some(state => !state.unitAI || !hasClass(state, "Unit") || hasClass(state, "Animal"))) return []; - return unitEntStates[0].unitAI.possibleStances; + return unitEntStates[0].unitAI.selectableStances; }, "setupButton": function(data) { Index: ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js +++ ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -286,7 +286,7 @@ var cmpUpgrade = Engine.QueryInterface(ent, IID_Upgrade); if (cmpUpgrade) ret.upgrade = { - "upgrades" : cmpUpgrade.GetUpgrades(), + "upgrades": cmpUpgrade.GetUpgrades(), "progress": cmpUpgrade.GetProgress(), "template": cmpUpgrade.GetUpgradingTo() }; @@ -349,8 +349,8 @@ "canGuard": cmpUnitAI.CanGuard(), "isGuarding": cmpUnitAI.IsGuardOf(), "canPatrol": cmpUnitAI.CanPatrol(), - "possibleStances": cmpUnitAI.GetPossibleStances(), - "isIdle":cmpUnitAI.IsIdle(), + "selectableStances": cmpUnitAI.GetSelectableStances(), + "isIdle": cmpUnitAI.IsIdle(), }; let cmpGuard = Engine.QueryInterface(ent, IID_Guard); @@ -816,7 +816,7 @@ let color = playerColors[owner]; if (!color) { - color = { "r":1, "g":1, "b":1 }; + color = { "r": 1, "g": 1, "b": 1 }; let cmpPlayer = QueryPlayerIDInterface(owner); if (cmpPlayer) color = cmpPlayer.GetDisplayedColor(); @@ -895,7 +895,7 @@ GuiInterface.prototype.GetNonGaiaEntities = function() { - return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetNonGaiaEntities(); + return Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetNonGaiaEntities(); }; /** Index: ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js +++ ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js @@ -70,50 +70,66 @@ // do worry around armies slaughtering the guy standing next to you), etc. var g_Stances = { "violent": { - targetVisibleEnemies: true, - targetAttackersAlways: true, - respondFlee: false, - respondChase: true, - respondChaseBeyondVision: true, - respondStandGround: false, - respondHoldGround: false, + "targetVisibleEnemies": true, + "targetAttackersAlways": true, + "respondFlee": false, + "respondChase": true, + "respondChaseBeyondVision": true, + "respondStandGround": false, + "respondHoldGround": false, + "selectable": true }, "aggressive": { - targetVisibleEnemies: true, - targetAttackersAlways: false, - respondFlee: false, - respondChase: true, - respondChaseBeyondVision: false, - respondStandGround: false, - respondHoldGround: false, + "targetVisibleEnemies": true, + "targetAttackersAlways": false, + "respondFlee": false, + "respondChase": true, + "respondChaseBeyondVision": false, + "respondStandGround": false, + "respondHoldGround": false, + "selectable": true }, "defensive": { - targetVisibleEnemies: true, - targetAttackersAlways: false, - respondFlee: false, - respondChase: false, - respondChaseBeyondVision: false, - respondStandGround: false, - respondHoldGround: true, + "targetVisibleEnemies": true, + "targetAttackersAlways": false, + "respondFlee": false, + "respondChase": false, + "respondChaseBeyondVision": false, + "respondStandGround": false, + "respondHoldGround": true, + "selectable": true }, "passive": { - targetVisibleEnemies: false, - targetAttackersAlways: false, - respondFlee: true, - respondChase: false, - respondChaseBeyondVision: false, - respondStandGround: false, - respondHoldGround: false, + "targetVisibleEnemies": false, + "targetAttackersAlways": false, + "respondFlee": true, + "respondChase": false, + "respondChaseBeyondVision": false, + "respondStandGround": false, + "respondHoldGround": false, + "selectable": true }, "standground": { - targetVisibleEnemies: true, - targetAttackersAlways: false, - respondFlee: false, - respondChase: false, - respondChaseBeyondVision: false, - respondStandGround: true, - respondHoldGround: false, - }, + "targetVisibleEnemies": true, + "targetAttackersAlways": false, + "respondFlee": false, + "respondChase": false, + "respondChaseBeyondVision": false, + "respondStandGround": true, + "respondHoldGround": false, + "selectable": true + }, + "none": { + // Only to be used by AI or trigger scripts + "targetVisibleEnemies": false, + "targetAttackersAlways": false, + "respondFlee": false, + "respondChase": false, + "respondChaseBeyondVision": false, + "respondStandGround": false, + "respondHoldGround": false, + "selectable": false + } }; // See ../helpers/FSM.js for some documentation of this FSM specification syntax @@ -1366,7 +1382,7 @@ }, "WALKING": { - "enter": function () { + "enter": function() { var cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); var cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); if (cmpFormation && cmpVisual) @@ -1577,7 +1593,7 @@ }, "WALKING": { - "enter": function () { + "enter": function() { this.SelectAnimation("move"); }, @@ -1587,7 +1603,7 @@ }, "WALKINGANDFIGHTING": { - "enter": function () { + "enter": function() { // Show weapons rather than carried resources. this.SetAnimationVariant("combat"); @@ -1610,7 +1626,7 @@ }, "PATROL": { - "enter": function () { + "enter": function() { // Memorize the origin position in case that we want to go back let cmpPosition = Engine.QueryInterface(this.entity, IID_Position); if (!cmpPosition || !cmpPosition.IsInWorld()) @@ -1656,7 +1672,7 @@ }, "ESCORTING": { - "enter": function () { + "enter": function() { // Show weapons rather than carried resources. this.SetAnimationVariant("combat"); @@ -1706,7 +1722,7 @@ }, "GUARDING": { - "enter": function () { + "enter": function() { this.StartTimer(1000, 1000); this.SetHeldPositionOnEntity(this.entity); this.SetAnimationVariant("combat"); @@ -1793,7 +1809,7 @@ }, "APPROACHING": { - "enter": function () { + "enter": function() { // Show weapons rather than carried resources. this.SetAnimationVariant("combat"); @@ -2031,7 +2047,7 @@ }, "CHASING": { - "enter": function () { + "enter": function() { // Show weapons rather than carried resources. this.SetAnimationVariant("combat"); @@ -2106,7 +2122,7 @@ // Try to find another nearby target of the same specific type // Also don't switch to a different type of huntable animal - var nearby = this.FindNearbyResource(function (ent, type, template) { + var nearby = this.FindNearbyResource(function(ent, type, template) { return ( ent != oldTarget && ((type.generic == "treasure" && oldType.generic == "treasure") @@ -2171,7 +2187,7 @@ // Try to find another nearby target of the same specific type // Also don't switch to a different type of huntable animal - var nearby = this.FindNearbyResource(function (ent, type, template) { + var nearby = this.FindNearbyResource(function(ent, type, template) { return ( ent != oldTarget && ((type.generic == "treasure" && oldType.generic == "treasure") @@ -2218,7 +2234,7 @@ // Try to find another nearby target of the same specific type // Also don't switch to a different type of huntable animal - var nearby = this.FindNearbyResource(function (ent, type, template) { + var nearby = this.FindNearbyResource(function(ent, type, template) { return ( (type.generic == "treasure" && resourceType.generic == "treasure") || (type.specific == resourceType.specific @@ -2427,7 +2443,7 @@ // Try to find a new resource of the same specific type near our current position: // Also don't switch to a different type of huntable animal - var nearby = this.FindNearbyResource(function (ent, type, template) { + var nearby = this.FindNearbyResource(function(ent, type, template) { return ( (type.generic == "treasure" && resourceType.generic == "treasure") || (type.specific == resourceType.specific @@ -2471,7 +2487,7 @@ }, "APPROACHING": { - "enter": function () { + "enter": function() { this.SelectAnimation("move"); this.StartTimer(1000, 1000); }, @@ -2572,12 +2588,12 @@ }, }, "CHASING": { - "enter": function () { + "enter": function() { this.SelectAnimation("move"); this.StartTimer(1000, 1000); }, - "leave": function () { + "leave": function() { this.StopTimer(); }, "Timer": function(msg) { @@ -2591,7 +2607,7 @@ this.WalkToHeldPosition(); } }, - "MoveCompleted": function () { + "MoveCompleted": function() { this.SetNextState("HEALING"); }, }, @@ -2600,7 +2616,7 @@ // Returning to dropsite "RETURNRESOURCE": { "APPROACHING": { - "enter": function () { + "enter": function() { this.SelectAnimation("move"); }, @@ -2658,7 +2674,7 @@ }, "APPROACHINGMARKET": { - "enter": function () { + "enter": function() { this.SelectAnimation("move"); }, @@ -2686,7 +2702,7 @@ "REPAIR": { "APPROACHING": { - "enter": function () { + "enter": function() { this.SelectAnimation("move"); }, @@ -2834,7 +2850,7 @@ var types = cmpResourceDropsite.GetTypes(); // TODO: Slightly undefined behavior here, we don't know what type of resource will be collected, // may cause problems for AIs (especially hunting fast animals), but avoid ugly hacks to fix that! - var nearby = this.FindNearbyResource(function (ent, type, template) { + var nearby = this.FindNearbyResource(function(ent, type, template) { return (types.indexOf(type.generic) != -1); }, msg.data.newentity); if (nearby) @@ -4527,7 +4543,7 @@ var pos = cmpPosition.GetPosition(); var heldPosition = this.heldPosition; if (heldPosition === undefined) - heldPosition = {"x": pos.x, "z": pos.z}; + heldPosition = { "x": pos.x, "z": pos.z }; return Math.euclidDistance2D(pos.x, pos.z, heldPosition.x, heldPosition.z) < halfvision + range.max; }; @@ -5526,8 +5542,8 @@ var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); var entities = cmpRangeManager.ResetActiveQuery(this.losRangeQuery); - var targets = entities.filter(function (v) { return cmpAttack.CanAttack(v) && attackfilter(v); }) - .sort(function (a, b) { return cmpAttack.CompareEntitiesByPreference(a, b); }); + var targets = entities.filter(function(v) { return cmpAttack.CanAttack(v) && attackfilter(v); }) + .sort(function(a, b) { return cmpAttack.CompareEntitiesByPreference(a, b); }); return targets; }; @@ -5595,11 +5611,11 @@ return g_Stances[this.stance]; }; -UnitAI.prototype.GetPossibleStances = function() +UnitAI.prototype.GetSelectableStances = function() { if (this.IsTurret()) return []; - return Object.keys(g_Stances); + return Object.keys(g_Stances).filter(key => g_Stances[key].selectable); }; UnitAI.prototype.GetStanceName = function()