Page MenuHomeWildfire Games

Fix UnitAI infinite loop following rP22023
ClosedPublic

Authored by wraitii on Jan 13 2019, 3:11 PM.

Details

Reviewers
None
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Commits
rP22059: Fix UnitAI infinite loop following rP22023
Summary

As reported by Angen and Gurken Khan on the forums, there is a crash following rP22023 caused by an infinite loop in UnitAI.

The loop as described by Angen in rP22023:

... -> enter IDLE -> Find Targets -> Order.Attack -> Order.Attack fails (movement fails but it could be anything else) -> finishorder -> setNextState(IDLE) -> leave and enter IDLE -> ...

I believe we switch to IDLE so that our default "no order" state is IDLE.

I don't think we can fix the Order.Attack behaviour by itself - D13 would make the moment _likely_ return true but not always.
Finding new targets right away in IDLE.enter also seems reasonable, not waiting a turn is better.

So >> It does seem like we don't want to leave-re-enter IDLE from finishOrder. So my fix is to explicitly check for that.

Test Plan

See commands.txt in rP22023, this fixes the crash.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

wraitii created this revision.Jan 13 2019, 3:11 PM
Vulcan added a subscriber: Vulcan.Jan 13 2019, 3:13 PM

Successful build - Chance fights ever on the side of the prudent.

Linter detected issues:
Executing section Source...
Executing section JS...
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 228| 228| 		// Move a tile outside the building
| 229| 229| 		let range = 4;
| 230| 230| 		if (this.MoveToTargetRangeExplicit(msg.data.target, range, range))
| 231|    |-		{
|    | 231|+		
| 232| 232| 			// We've started walking to the given point
| 233| 233| 			this.SetNextState("INDIVIDUAL.WALKING");
| 234|    |-		}
|    | 234|+		
| 235| 235| 		else
| 236| 236| 		{
| 237| 237| 			// We are already at the target, or can't move at all
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 233| 233| 			this.SetNextState("INDIVIDUAL.WALKING");
| 234| 234| 		}
| 235| 235| 		else
| 236|    |-		{
|    | 236|+		
| 237| 237| 			// We are already at the target, or can't move at all
| 238| 238| 			this.FinishOrder();
| 239|    |-		}
|    | 239|+		
| 240| 240| 	},
| 241| 241| 
| 242| 242| 	// Individual orders:
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 335| 335| 
| 336| 336| 		var ok = this.MoveToTarget(this.order.data.target);
| 337| 337| 		if (ok)
| 338|    |-		{
|    | 338|+		
| 339| 339| 			// We've started walking to the given point
| 340| 340| 			if (this.IsAnimal())
| 341| 341| 				this.SetNextState("ANIMAL.WALKING");
| 342| 342| 			else
| 343| 343| 				this.SetNextState("INDIVIDUAL.WALKING");
| 344|    |-		}
|    | 344|+		
| 345| 345| 		else
| 346| 346| 		{
| 347| 347| 			// We are already at the target, or can't move at all
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 363| 363| 		var cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
| 364| 364| 		if (this.lastShorelinePosition && cmpPosition && (this.lastShorelinePosition.x == cmpPosition.GetPosition().x)
| 365| 365| 		    && (this.lastShorelinePosition.z == cmpPosition.GetPosition().z))
| 366|    |-		{
|    | 366|+		
| 367| 367| 			// we were already on the shoreline, and have not moved since
| 368| 368| 			if (DistanceBetweenEntities(this.entity, this.order.data.target) < 50)
| 369| 369| 				needToMove = false;
| 370|    |-		}
|    | 370|+		
| 371| 371| 
| 372| 372| 		// TODO: what if the units are on a cliff ? the ship will go below the cliff
| 373| 373| 		// and the units won't be able to garrison. Should go to the nearest (accessible) shore
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 361| 361| 		// Check if we need to move     TODO implement a better way to know if we are on the shoreline
| 362| 362| 		var needToMove = true;
| 363| 363| 		var cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
| 364|    |-		if (this.lastShorelinePosition && cmpPosition && (this.lastShorelinePosition.x == cmpPosition.GetPosition().x)
| 365|    |-		    && (this.lastShorelinePosition.z == cmpPosition.GetPosition().z))
|    | 364|+		if (this.lastShorelinePosition && cmpPosition && (this.lastShorelinePosition.x == cmpPosition.GetPosition().x) &&
|    | 365|+		    (this.lastShorelinePosition.z == cmpPosition.GetPosition().z))
| 366| 366| 		{
| 367| 367| 			// we were already on the shoreline, and have not moved since
| 368| 368| 			if (DistanceBetweenEntities(this.entity, this.order.data.target) < 50)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 372| 372| 		// TODO: what if the units are on a cliff ? the ship will go below the cliff
| 373| 373| 		// and the units won't be able to garrison. Should go to the nearest (accessible) shore
| 374| 374| 		if (needToMove && this.MoveToTarget(this.order.data.target))
| 375|    |-		{
|    | 375|+		
| 376| 376| 			this.SetNextState("INDIVIDUAL.PICKUP.APPROACHING");
| 377|    |-		}
|    | 377|+		
| 378| 378| 		else
| 379| 379| 		{
| 380| 380| 			// We are already at the target, or can't move at all
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 401| 401| 		var distance = DistanceBetweenEntities(this.entity, this.order.data.target) + (+this.template.FleeDistance);
| 402| 402| 		var cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion);
| 403| 403| 		if (cmpUnitMotion.MoveToTargetRange(this.order.data.target, distance, -1))
| 404|    |-		{
|    | 404|+		
| 405| 405| 			// We've started fleeing from the given target
| 406| 406| 			if (this.IsAnimal())
| 407| 407| 				this.SetNextState("ANIMAL.FLEEING");
| 408| 408| 			else
| 409| 409| 				this.SetNextState("INDIVIDUAL.FLEEING");
| 410|    |-		}
|    | 410|+		
| 411| 411| 		else
| 412| 412| 		{
| 413| 413| 			// We are already at the target, or can't move at all
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 448| 448| 			}
| 449| 449| 
| 450| 450| 			if (this.order.data.attackType == this.oldAttackType)
| 451|    |-			{
|    | 451|+			
| 452| 452| 				if (this.IsAnimal())
| 453| 453| 					this.SetNextState("ANIMAL.COMBAT.ATTACKING");
| 454| 454| 				else
| 455| 455| 					this.SetNextState("INDIVIDUAL.COMBAT.ATTACKING");
| 456|    |-			}
|    | 456|+			
| 457| 457| 			else
| 458| 458| 			{
| 459| 459| 				if (this.IsAnimal())
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 455| 455| 					this.SetNextState("INDIVIDUAL.COMBAT.ATTACKING");
| 456| 456| 			}
| 457| 457| 			else
| 458|    |-			{
|    | 458|+			
| 459| 459| 				if (this.IsAnimal())
| 460| 460| 					this.SetNextState("ANIMAL.COMBAT.ATTACKING");
| 461| 461| 				else
| 462| 462| 					this.SetNextState("INDIVIDUAL.COMBAT.ATTACKING");
| 463|    |-			}
|    | 463|+			
| 464| 464| 			return;
| 465| 465| 		}
| 466| 466| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 580| 580| 					this.PushOrderFront("Walk", this.order.data.lastPos);
| 581| 581| 				}
| 582| 582| 				else
| 583|    |-				{
|    | 583|+				
| 584| 584| 					// We couldn't move there, or the target moved away
| 585| 585| 					this.FinishOrder();
| 586|    |-				}
|    | 586|+				
| 587| 587| 				return;
| 588| 588| 			}
| 589| 589| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 593| 593| 
| 594| 594| 		// Try to move within range
| 595| 595| 		if (this.MoveToTargetRange(this.order.data.target, IID_ResourceGatherer))
| 596|    |-		{
|    | 596|+		
| 597| 597| 			// We've started walking to the given point
| 598| 598| 			this.SetNextState("INDIVIDUAL.GATHER.APPROACHING");
| 599|    |-		}
|    | 599|+		
| 600| 600| 		else
| 601| 601| 		{
| 602| 602| 			// We are already at the target, or can't move at all,
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 670| 670| 	"Order.Repair": function(msg) {
| 671| 671| 		// Try to move within range
| 672| 672| 		if (this.MoveToTargetRange(this.order.data.target, IID_Builder))
| 673|    |-		{
|    | 673|+		
| 674| 674| 			// We've started walking to the given point
| 675| 675| 			this.SetNextState("INDIVIDUAL.REPAIR.APPROACHING");
| 676|    |-		}
|    | 676|+		
| 677| 677| 		else
| 678| 678| 		{
| 679| 679| 			// We are already at the target, or can't move at all,
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 706| 706| 		}
| 707| 707| 
| 708| 708| 		if (this.MoveToGarrisonRange(this.order.data.target))
| 709|    |-		{
|    | 709|+		
| 710| 710| 			this.SetNextState("INDIVIDUAL.GARRISON.APPROACHING");
| 711|    |-		}
|    | 711|+		
| 712| 712| 		else
| 713| 713| 		{
| 714| 714| 			// We do a range check before actually garrisoning
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 834| 834| 			if (!this.CheckTargetAttackRange(target, target))
| 835| 835| 			{
| 836| 836| 				if (this.TargetIsAlive(target) && this.CheckTargetVisible(target))
| 837|    |-				{
|    | 837|+				
| 838| 838| 					if (this.MoveToTargetAttackRange(target, target))
| 839| 839| 					{
| 840| 840| 						this.SetNextState("COMBAT.APPROACHING");
| 841| 841| 						return;
| 842| 842| 					}
| 843|    |-				}
|    | 843|+				
| 844| 844| 				this.FinishOrder();
| 845| 845| 				return;
| 846| 846| 			}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 859| 859| 			}
| 860| 860| 			// Check if we are already in range, otherwise walk there
| 861| 861| 			if (!this.CheckGarrisonRange(msg.data.target))
| 862|    |-			{
|    | 862|+			
| 863| 863| 				if (!this.CheckTargetVisible(msg.data.target))
| 864| 864| 				{
| 865| 865| 					this.FinishOrder();
| 874| 874| 						return;
| 875| 875| 					}
| 876| 876| 				}
| 877|    |-			}
|    | 877|+			
| 878| 878| 
| 879| 879| 			this.SetNextState("GARRISON.GARRISONING");
| 880| 880| 		},
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 866| 866| 					return;
| 867| 867| 				}
| 868| 868| 				else
| 869|    |-				{
|    | 869|+				
| 870| 870| 					// Out of range; move there in formation
| 871| 871| 					if (this.MoveToGarrisonRange(msg.data.target))
| 872| 872| 					{
| 873| 873| 						this.SetNextState("GARRISON.APPROACHING");
| 874| 874| 						return;
| 875| 875| 					}
| 876|    |-				}
|    | 876|+				
| 877| 877| 			}
| 878| 878| 
| 879| 879| 			this.SetNextState("GARRISON.GARRISONING");
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 865| 865| 					this.FinishOrder();
| 866| 866| 					return;
| 867| 867| 				}
| 868|    |-				else
| 869|    |-				{
|    | 868|+				
| 870| 869| 					// Out of range; move there in formation
| 871| 870| 					if (this.MoveToGarrisonRange(msg.data.target))
| 872| 871| 					{
| 873| 872| 						this.SetNextState("GARRISON.APPROACHING");
| 874| 873| 						return;
| 875| 874| 					}
| 876|    |-				}
|    | 875|+				
| 877| 876| 			}
| 878| 877| 
| 879| 878| 			this.SetNextState("GARRISON.GARRISONING");
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
| 892| 892| 						this.PushOrderFront("Walk", msg.data.lastPos);
| 893| 893| 					}
| 894| 894| 					else
| 895|    |-					{
|    | 895|+					
| 896| 896| 						// We couldn't move there, or the target moved away
| 897| 897| 						this.FinishOrder();
| 898|    |-					}
|    | 898|+					
| 899| 899| 					return;
| 900| 900| 				}
| 901| 901| 
|    | [NORMAL] ESLintBear (key-spacing):
|    | Missing space before value for key 'GARRISON'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1113|1113| 			},
|1114|1114| 		},
|1115|1115| 
|1116|    |-		"GARRISON":{
|    |1116|+		"GARRISON": {
|1117|1117| 			"enter": function() {
|1118|1118| 				// If the garrisonholder should pickup, warn it so it can take needed action
|1119|1119| 				var cmpGarrisonHolder = Engine.QueryInterface(this.order.data.target, IID_GarrisonHolder);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1297|1297| 			// If the controller handled an order but some members rejected it,
|1298|1298| 			// they will have no orders and be in the FORMATIONMEMBER.IDLE state.
|1299|1299| 			if (this.orderQueue.length)
|1300|    |-			{
|    |1300|+			
|1301|1301| 				// We're leaving the formation, so stop our FormationWalk order
|1302|1302| 				if (this.FinishOrder())
|1303|1303| 					return;
|1304|    |-			}
|    |1304|+			
|1305|1305| 
|1306|1306| 			// No orders left, we're an individual now
|1307|1307| 			if (this.IsAnimal())
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1325|1325| 			// Move a tile outside the building
|1326|1326| 			let range = 4;
|1327|1327| 			if (this.MoveToTargetRangeExplicit(msg.data.target, range, range))
|1328|    |-			{
|    |1328|+			
|1329|1329| 				// We've started walking to the given point
|1330|1330| 				this.SetNextState("WALKINGTOPOINT");
|1331|    |-			}
|    |1331|+			
|1332|1332| 			else
|1333|1333| 			{
|1334|1334| 				// We are already at the target, or can't move at all
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1330|1330| 				this.SetNextState("WALKINGTOPOINT");
|1331|1331| 			}
|1332|1332| 			else
|1333|    |-			{
|    |1333|+			
|1334|1334| 				// We are already at the target, or can't move at all
|1335|1335| 				this.FinishOrder();
|1336|    |-			}
|    |1336|+			
|1337|1337| 		},
|1338|1338| 
|1339|1339| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1531|1531| 
|1532|1532| 			"LosRangeUpdate": function(msg) {
|1533|1533| 				if (this.GetStance().targetVisibleEnemies)
|1534|    |-				{
|    |1534|+				
|1535|1535| 					// Start attacking one of the newly-seen enemy (if any)
|1536|1536| 					this.AttackEntitiesByPreference(msg.data.added);
|1537|    |-				}
|    |1537|+				
|1538|1538| 			},
|1539|1539| 
|1540|1540| 			"LosHealRangeUpdate": function(msg) {
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1717|1717| 						// if nothing better to do, check if the guarded needs to be healed or repaired
|1718|1718| 						var cmpHealth = Engine.QueryInterface(this.isGuardOf, IID_Health);
|1719|1719| 						if (cmpHealth && (cmpHealth.GetHitpoints() < cmpHealth.GetMaxHitpoints()))
|1720|    |-						{
|    |1720|+						
|1721|1721| 							if (this.CanHeal(this.isGuardOf))
|1722|1722| 								this.PushOrderFront("Heal", { "target": this.isGuardOf, "force": false });
|1723|1723| 							else if (this.CanRepair(this.isGuardOf))
|1724|1724| 								this.PushOrderFront("Repair", { "target": this.isGuardOf, "autocontinue": false, "force": false });
|1725|    |-						}
|    |1725|+						
|1726|1726| 					}
|1727|1727| 				},
|1728|1728| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1805|1805| 				"MoveCompleted": function() {
|1806|1806| 
|1807|1807| 					if (this.CheckTargetAttackRange(this.order.data.target, this.order.data.attackType))
|1808|    |-					{
|    |1808|+					
|1809|1809| 						// If the unit needs to unpack, do so
|1810|1810| 						if (this.CanUnpack())
|1811|1811| 						{
|1814|1814| 						}
|1815|1815| 						else
|1816|1816| 							this.SetNextState("ATTACKING");
|1817|    |-					}
|    |1817|+					
|1818|1818| 					else
|1819|1819| 					{
|1820|1820| 						if (this.MoveToTargetAttackRange(this.order.data.target, this.order.data.attackType))
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1812|1812| 							this.PushOrderFront("Unpack", { "force": true });
|1813|1813| 							return;
|1814|1814| 						}
|1815|    |-						else
|1816|    |-							this.SetNextState("ATTACKING");
|    |1815|+						this.SetNextState("ATTACKING");
|1817|1816| 					}
|1818|1817| 					else
|1819|1818| 					{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1816|1816| 							this.SetNextState("ATTACKING");
|1817|1817| 					}
|1818|1818| 					else
|1819|    |-					{
|    |1819|+					
|1820|1820| 						if (this.MoveToTargetAttackRange(this.order.data.target, this.order.data.attackType))
|1821|1821| 						{
|1822|1822| 							this.SetNextState("APPROACHING");
|1826|1826| 							// Give up
|1827|1827| 							this.FinishOrder();
|1828|1828| 						}
|1829|    |-					}
|    |1829|+					
|1830|1830| 				},
|1831|1831| 			},
|1832|1832| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1818|1818| 					else
|1819|1819| 					{
|1820|1820| 						if (this.MoveToTargetAttackRange(this.order.data.target, this.order.data.attackType))
|1821|    |-						{
|    |1821|+						
|1822|1822| 							this.SetNextState("APPROACHING");
|1823|    |-						}
|    |1823|+						
|1824|1824| 						else
|1825|1825| 						{
|1826|1826| 							// Give up
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1822|1822| 							this.SetNextState("APPROACHING");
|1823|1823| 						}
|1824|1824| 						else
|1825|    |-						{
|    |1825|+						
|1826|1826| 							// Give up
|1827|1827| 							this.FinishOrder();
|1828|    |-						}
|    |1828|+						
|1829|1829| 					}
|1830|1830| 				},
|1831|1831| 			},
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1843|1843| 					}
|1844|1844| 					// Check the target is still alive and attackable
|1845|1845| 					if (this.CanAttack(target) && !this.CheckTargetAttackRange(target, this.order.data.attackType))
|1846|    |-					{
|    |1846|+					
|1847|1847| 						// Can't reach it - try to chase after it
|1848|1848| 						if (this.ShouldChaseTargetedEntity(target, this.order.data.force))
|1849|1849| 						{
|1858|1858| 								return;
|1859|1859| 							}
|1860|1860| 						}
|1861|    |-					}
|    |1861|+					
|1862|1862| 
|1863|1863| 					var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);
|1864|1864| 					this.attackTimers = cmpAttack.GetTimers(this.order.data.attackType);
|    | [NORMAL] ESLintBear (no-unneeded-ternary):
|    | Unnecessary use of boolean literals in conditional expression.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|1889|1889| 					// TODO: we should probably only bother syncing projectile attacks, not melee
|1890|1890| 
|1891|1891| 					// If using a non-default prepare time, re-sync the animation when the timer runs.
|1892|    |-					this.resyncAnimation = (prepare != this.attackTimers.prepare) ? true : false;
|    |1892|+					this.resyncAnimation = (prepare != this.attackTimers.prepare);
|1893|1893| 
|1894|1894| 					this.FaceTowardsTarget(this.order.data.target);
|1895|1895| 
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2018|2018| 
|2019|2019| 				"Attacked": function(msg) {
|2020|2020| 					// If we are capturing and are attacked by something that we would not capture, attack that entity instead
|2021|    |-					if (this.order.data.attackType == "Capture" && (this.GetStance().targetAttackersAlways || !this.order.data.force)
|2022|    |-						&& this.order.data.target != msg.data.attacker && this.GetBestAttackAgainst(msg.data.attacker, true) != "Capture")
|    |2021|+					if (this.order.data.attackType == "Capture" && (this.GetStance().targetAttackersAlways || !this.order.data.force) &&
|    |2022|+						this.order.data.target != msg.data.attacker && this.GetBestAttackAgainst(msg.data.attacker, true) != "Capture")
|2023|2023| 						this.RespondToTargetedEntities([msg.data.attacker]);
|2024|2024| 				},
|2025|2025| 			},
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2102|2102| 						// Also don't switch to a different type of huntable animal
|2103|2103| 						var nearby = this.FindNearbyResource(function(ent, type, template) {
|2104|2104| 							return (
|2105|    |-								ent != oldTarget
|2106|    |-								 && ((type.generic == "treasure" && oldType.generic == "treasure")
|    |2105|+								ent != oldTarget &&
|    |2106|+								 ((type.generic == "treasure" && oldType.generic == "treasure")
|2107|2107| 								 || (type.specific == oldType.specific
|2108|2108| 								 && (type.specific != "meat" || oldTemplate == template)))
|2109|2109| 							);
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '||' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2103|2103| 						var nearby = this.FindNearbyResource(function(ent, type, template) {
|2104|2104| 							return (
|2105|2105| 								ent != oldTarget
|2106|    |-								 && ((type.generic == "treasure" && oldType.generic == "treasure")
|2107|    |-								 || (type.specific == oldType.specific
|    |2106|+								 && ((type.generic == "treasure" && oldType.generic == "treasure") ||
|    |2107|+								 (type.specific == oldType.specific
|2108|2108| 								 && (type.specific != "meat" || oldTemplate == template)))
|2109|2109| 							);
|2110|2110| 						}, oldTarget);
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2104|2104| 							return (
|2105|2105| 								ent != oldTarget
|2106|2106| 								 && ((type.generic == "treasure" && oldType.generic == "treasure")
|2107|    |-								 || (type.specific == oldType.specific
|2108|    |-								 && (type.specific != "meat" || oldTemplate == template)))
|    |2107|+								 || (type.specific == oldType.specific &&
|    |2108|+								 (type.specific != "meat" || oldTemplate == template)))
|2109|2109| 							);
|2110|2110| 						}, oldTarget);
|2111|2111| 						if (nearby)
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2113|2113| 							this.PerformGather(nearby, false, false);
|2114|2114| 							return true;
|2115|2115| 						}
|2116|    |-						else
|2117|    |-						{
|    |2116|+						
|2118|2117| 							// It's probably better in this case, to avoid units getting stuck around a dropsite
|2119|2118| 							// in a "Target is far away, full, nearby are no good resources, return to dropsite" loop
|2120|2119| 							// to order it to GatherNear the resource position.
|2135|2134| 									return true;
|2136|2135| 								}
|2137|2136| 							}
|2138|    |-						}
|    |2137|+						
|2139|2138| 						return true;
|2140|2139| 					}
|2141|2140| 					return false;
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2125|2125| 								this.GatherNearPosition(pos.x, pos.z, oldType, oldTemplate);
|2126|2126| 								return true;
|2127|2127| 							}
|2128|    |-							else
|2129|    |-							{
|    |2128|+							
|2130|2129| 								// we're kind of stuck here. Return resource.
|2131|2130| 								var nearby = this.FindNearestDropsite(oldType.generic);
|2132|2131| 								if (nearby)
|2134|2133| 									this.PushOrderFront("ReturnResource", { "target": nearby, "force": false });
|2135|2134| 									return true;
|2136|2135| 								}
|2137|    |-							}
|    |2136|+							
|2138|2137| 						}
|2139|2138| 						return true;
|2140|2139| 					}
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2167|2167| 						// Also don't switch to a different type of huntable animal
|2168|2168| 						var nearby = this.FindNearbyResource(function(ent, type, template) {
|2169|2169| 							return (
|2170|    |-								ent != oldTarget
|2171|    |-								&& ((type.generic == "treasure" && oldType.generic == "treasure")
|    |2170|+								ent != oldTarget &&
|    |2171|+								((type.generic == "treasure" && oldType.generic == "treasure")
|2172|2172| 								|| (type.specific == oldType.specific
|2173|2173| 								&& (type.specific != "meat" || oldTemplate == template)))
|2174|2174| 							);
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '||' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2168|2168| 						var nearby = this.FindNearbyResource(function(ent, type, template) {
|2169|2169| 							return (
|2170|2170| 								ent != oldTarget
|2171|    |-								&& ((type.generic == "treasure" && oldType.generic == "treasure")
|2172|    |-								|| (type.specific == oldType.specific
|    |2171|+								&& ((type.generic == "treasure" && oldType.generic == "treasure") ||
|    |2172|+								(type.specific == oldType.specific
|2173|2173| 								&& (type.specific != "meat" || oldTemplate == template)))
|2174|2174| 							);
|2175|2175| 						});
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2169|2169| 							return (
|2170|2170| 								ent != oldTarget
|2171|2171| 								&& ((type.generic == "treasure" && oldType.generic == "treasure")
|2172|    |-								|| (type.specific == oldType.specific
|2173|    |-								&& (type.specific != "meat" || oldTemplate == template)))
|    |2172|+								|| (type.specific == oldType.specific &&
|    |2173|+								(type.specific != "meat" || oldTemplate == template)))
|2174|2174| 							);
|2175|2175| 						});
|2176|2176| 						if (nearby)
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '||' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2214|2214| 					// Also don't switch to a different type of huntable animal
|2215|2215| 					var nearby = this.FindNearbyResource(function(ent, type, template) {
|2216|2216| 						return (
|2217|    |-							(type.generic == "treasure" && resourceType.generic == "treasure")
|2218|    |-							|| (type.specific == resourceType.specific
|    |2217|+							(type.generic == "treasure" && resourceType.generic == "treasure") ||
|    |2218|+							(type.specific == resourceType.specific
|2219|2219| 							&& (type.specific != "meat" || resourceTemplate == template))
|2220|2220| 						);
|2221|2221| 					});
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2215|2215| 					var nearby = this.FindNearbyResource(function(ent, type, template) {
|2216|2216| 						return (
|2217|2217| 							(type.generic == "treasure" && resourceType.generic == "treasure")
|2218|    |-							|| (type.specific == resourceType.specific
|2219|    |-							&& (type.specific != "meat" || resourceTemplate == template))
|    |2218|+							|| (type.specific == resourceType.specific &&
|    |2219|+							(type.specific != "meat" || resourceTemplate == template))
|2220|2220| 						);
|2221|2221| 					});
|2222|2222| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2331|2331| 
|2332|2332| 					var cmpSupply = Engine.QueryInterface(this.gatheringTarget, IID_ResourceSupply);
|2333|2333| 					if (cmpSupply && cmpSupply.IsAvailable(cmpOwnership.GetOwner(), this.entity))
|2334|    |-					{
|    |2334|+					
|2335|2335| 						// Check we can still reach and gather from the target
|2336|2336| 						if (this.CheckTargetRange(this.gatheringTarget, IID_ResourceGatherer) && this.CanGather(this.gatheringTarget))
|2337|2337| 						{
|2397|2397| 								return;
|2398|2398| 							}
|2399|2399| 						}
|2400|    |-					}
|    |2400|+					
|2401|2401| 
|2402|2402| 					// We're already in range, can't get anywhere near it or the target is exhausted.
|2403|2403| 
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '||' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2423|2423| 					// Also don't switch to a different type of huntable animal
|2424|2424| 					var nearby = this.FindNearbyResource(function(ent, type, template) {
|2425|2425| 						return (
|2426|    |-							(type.generic == "treasure" && resourceType.generic == "treasure")
|2427|    |-							|| (type.specific == resourceType.specific
|    |2426|+							(type.generic == "treasure" && resourceType.generic == "treasure") ||
|    |2427|+							(type.specific == resourceType.specific
|2428|2428| 							&& (type.specific != "meat" || resourceTemplate == template))
|2429|2429| 						);
|2430|2430| 					});
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2424|2424| 					var nearby = this.FindNearbyResource(function(ent, type, template) {
|2425|2425| 						return (
|2426|2426| 							(type.generic == "treasure" && resourceType.generic == "treasure")
|2427|    |-							|| (type.specific == resourceType.specific
|2428|    |-							&& (type.specific != "meat" || resourceTemplate == template))
|    |2427|+							|| (type.specific == resourceType.specific &&
|    |2428|+							(type.specific != "meat" || resourceTemplate == template))
|2429|2429| 						);
|2430|2430| 					});
|2431|2431| 					if (nearby)
|    | [NORMAL] ESLintBear (no-unneeded-ternary):
|    | Unnecessary use of boolean literals in conditional expression.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2511|2511| 					this.StartTimer(prepare, this.healTimers.repeat);
|2512|2512| 
|2513|2513| 					// If using a non-default prepare time, re-sync the animation when the timer runs.
|2514|    |-					this.resyncAnimation = (prepare != this.healTimers.prepare) ? true : false;
|    |2514|+					this.resyncAnimation = (prepare != this.healTimers.prepare);
|2515|2515| 
|2516|2516| 					this.FaceTowardsTarget(this.order.data.target);
|2517|2517| 				},
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2726|2726| 					{
|2727|2727| 						// The building was already finished/fully repaired before we arrived;
|2728|2728| 						// let the ConstructionFinished handler handle this.
|2729|    |-						this.OnGlobalConstructionFinished({"entity": this.repairTarget, "newentity": this.repairTarget});
|    |2729|+						this.OnGlobalConstructionFinished({ "entity": this.repairTarget, "newentity": this.repairTarget});
|2730|2730| 						return true;
|2731|2731| 					}
|2732|2732| 
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2726|2726| 					{
|2727|2727| 						// The building was already finished/fully repaired before we arrived;
|2728|2728| 						// let the ConstructionFinished handler handle this.
|2729|    |-						this.OnGlobalConstructionFinished({"entity": this.repairTarget, "newentity": this.repairTarget});
|    |2729|+						this.OnGlobalConstructionFinished({"entity": this.repairTarget, "newentity": this.repairTarget });
|2730|2730| 						return true;
|2731|2731| 					}
|2732|2732| 
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2766|2766| 					if (this.MoveToTargetRange(this.repairTarget, IID_Builder))
|2767|2767| 						this.SetNextState("APPROACHING");
|2768|2768| 					else if (!this.CheckTargetRange(this.repairTarget, IID_Builder))
|2769|    |-						this.FinishOrder(); //can't approach and isn't in reach
|    |2769|+						this.FinishOrder(); // can't approach and isn't in reach
|2770|2770| 				},
|2771|2771| 			},
|2772|2772| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2853|2853| 
|2854|2854| 				// Unit was approaching and there's nothing to do now, so switch to walking
|2855|2855| 				if (oldState === "INDIVIDUAL.REPAIR.APPROACHING")
|2856|    |-				{
|    |2856|+				
|2857|2857| 					// We're already walking to the given point, so add this as a order.
|2858|2858| 					this.WalkToTarget(msg.data.newentity, true);
|2859|    |-				}
|    |2859|+				
|2860|2860| 			},
|2861|2861| 		},
|2862|2862| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|2906|2906| 
|2907|2907| 					// Check that we can garrison here
|2908|2908| 					if (this.CanGarrison(target))
|2909|    |-					{
|    |2909|+					
|2910|2910| 						// Check that we're in range of the garrison target
|2911|2911| 						if (this.CheckGarrisonRange(target))
|2912|2912| 						{
|2982|2982| 								return false;
|2983|2983| 							}
|2984|2984| 						}
|2985|    |-					}
|    |2985|+					
|2986|2986| 					// Garrisoning failed for some reason, so finish the order
|2987|2987| 					this.FinishOrder();
|2988|2988| 					return true;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3089|3089| 		"Attacked": function(msg) {
|3090|3090| 			if (this.template.NaturalBehaviour == "skittish" ||
|3091|3091| 			    this.template.NaturalBehaviour == "passive")
|3092|    |-			{
|    |3092|+			
|3093|3093| 				this.Flee(msg.data.attacker, false);
|3094|    |-			}
|    |3094|+			
|3095|3095| 			else if (this.IsDangerousAnimal() || this.template.NaturalBehaviour == "defensive")
|3096|3096| 			{
|3097|3097| 				if (this.CanAttack(msg.data.attacker))
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3098|3098| 					this.Attack(msg.data.attacker, false);
|3099|3099| 			}
|3100|3100| 			else if (this.template.NaturalBehaviour == "domestic")
|3101|    |-			{
|    |3101|+			
|3102|3102| 				// Never flee, stop what we were doing
|3103|3103| 				this.SetNextState("IDLE");
|3104|    |-			}
|    |3104|+			
|3105|3105| 		},
|3106|3106| 
|3107|3107| 		"Order.LeaveFoundation": function(msg) {
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3108|3108| 			// Move a tile outside the building
|3109|3109| 			var range = 4;
|3110|3110| 			if (this.MoveToTargetRangeExplicit(msg.data.target, range, range))
|3111|    |-			{
|    |3111|+			
|3112|3112| 				// We've started walking to the given point
|3113|3113| 				this.SetNextState("WALKING");
|3114|    |-			}
|    |3114|+			
|3115|3115| 			else
|3116|3116| 			{
|3117|3117| 				// We are already at the target, or can't move at all
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3113|3113| 				this.SetNextState("WALKING");
|3114|3114| 			}
|3115|3115| 			else
|3116|    |-			{
|    |3116|+			
|3117|3117| 				// We are already at the target, or can't move at all
|3118|3118| 				this.FinishOrder();
|3119|    |-			}
|    |3119|+			
|3120|3120| 		},
|3121|3121| 
|3122|3122| 		"IDLE": {
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3155|3155| 				}
|3156|3156| 				// Start attacking one of the newly-seen enemy (if any)
|3157|3157| 				else if (this.IsDangerousAnimal())
|3158|    |-				{
|    |3158|+				
|3159|3159| 					this.AttackVisibleEntity(msg.data.added);
|3160|    |-				}
|    |3160|+				
|3161|3161| 
|3162|3162| 				// TODO: if two units enter our range together, we'll attack the
|3163|3163| 				// first and then the second won't trigger another LosRangeUpdate
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3198|3198| 				}
|3199|3199| 				// Start attacking one of the newly-seen enemy (if any)
|3200|3200| 				else if (this.template.NaturalBehaviour == "violent")
|3201|    |-				{
|    |3201|+				
|3202|3202| 					this.AttackVisibleEntity(msg.data.added);
|3203|    |-				}
|    |3203|+				
|3204|3204| 			},
|3205|3205| 
|3206|3206| 			"MoveCompleted": function() { },
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 2 tabs but found 7.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3215|3215| 		"COMBAT": "INDIVIDUAL.COMBAT", // reuse the same combat behaviour for animals
|3216|3216| 
|3217|3217| 		"WALKING": "INDIVIDUAL.WALKING",	// reuse the same walking behaviour for animals
|3218|    |-							// only used for domestic animals
|    |3218|+		// only used for domestic animals
|3219|3219| 	},
|3220|3220| };
|3221|3221| 
|    | [NORMAL] ESLintBear (no-unneeded-ternary):
|    | Unnecessary use of boolean literals in conditional expression.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3272|3272| 
|3273|3273| UnitAI.prototype.IsAnimal = function()
|3274|3274| {
|3275|    |-	return (this.template.NaturalBehaviour ? true : false);
|    |3275|+	return (!!this.template.NaturalBehaviour);
|3276|3276| };
|3277|3277| 
|3278|3278| UnitAI.prototype.IsDangerousAnimal = function()
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3310|3310| UnitAI.prototype.GetGarrisonHolder = function()
|3311|3311| {
|3312|3312| 	if (this.IsGarrisoned())
|3313|    |-	{
|    |3313|+	
|3314|3314| 		for (let order of this.orderQueue)
|3315|3315| 			if (order.type == "Garrison")
|3316|3316| 				return order.data.target;
|3317|    |-	}
|    |3317|+	
|3318|3318| 	return INVALID_ENTITY;
|3319|3319| };
|3320|3320| 
|    | [NORMAL] ESLintBear (comma-spacing):
|    | A space is required after ','.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3388|3388| 		{
|3389|3389| 			let index = this.GetCurrentState().indexOf(".");
|3390|3390| 			if (index != -1)
|3391|    |-				this.UnitFsm.SwitchToNextState(this, this.GetCurrentState().slice(0,index));
|    |3391|+				this.UnitFsm.SwitchToNextState(this, this.GetCurrentState().slice(0, index));
|3392|3392| 			this.Stop(false);
|3393|3393| 		}
|3394|3394| 
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3444|3444| 		if (this.orderQueue[i].type != "PickupUnit" || this.orderQueue[i].data.target != msg.entity)
|3445|3445| 			continue;
|3446|3446| 		if (i == 0)
|3447|    |-			this.UnitFsm.ProcessMessage(this, {"type": "PickupCanceled", "data": msg});
|    |3447|+			this.UnitFsm.ProcessMessage(this, { "type": "PickupCanceled", "data": msg});
|3448|3448| 		else
|3449|3449| 			this.orderQueue.splice(i, 1);
|3450|3450| 		Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() });
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3444|3444| 		if (this.orderQueue[i].type != "PickupUnit" || this.orderQueue[i].data.target != msg.entity)
|3445|3445| 			continue;
|3446|3446| 		if (i == 0)
|3447|    |-			this.UnitFsm.ProcessMessage(this, {"type": "PickupCanceled", "data": msg});
|    |3447|+			this.UnitFsm.ProcessMessage(this, {"type": "PickupCanceled", "data": msg });
|3448|3448| 		else
|3449|3449| 			this.orderQueue.splice(i, 1);
|3450|3450| 		Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() });
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3528|3528| };
|3529|3529| 
|3530|3530| 
|3531|    |-//// FSM linkage functions ////
|    |3531|+// // FSM linkage functions ////
|3532|3532| 
|3533|3533| // Setting the next state to the current state will leave/re-enter the top-most substate.
|3534|3534| UnitAI.prototype.SetNextState = function(state)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3697|3697| 				continue;
|3698|3698| 			if (this.orderQueue[i].type == type)
|3699|3699| 				continue;
|3700|    |-			this.orderQueue.splice(i, 0, {"type": type, "data": data});
|    |3700|+			this.orderQueue.splice(i, 0, { "type": type, "data": data});
|3701|3701| 			Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() });
|3702|3702| 			return;
|3703|3703| 		}
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3697|3697| 				continue;
|3698|3698| 			if (this.orderQueue[i].type == type)
|3699|3699| 				continue;
|3700|    |-			this.orderQueue.splice(i, 0, {"type": type, "data": data});
|    |3700|+			this.orderQueue.splice(i, 0, {"type": type, "data": data });
|3701|3701| 			Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() });
|3702|3702| 			return;
|3703|3703| 		}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3711|3711| {
|3712|3712| 	// Remember the previous work orders to be able to go back to them later if required
|3713|3713| 	if (data && data.force)
|3714|    |-	{
|    |3714|+	
|3715|3715| 		if (this.IsFormationController())
|3716|3716| 			this.CallMemberFunction("UpdateWorkOrders", [type]);
|3717|3717| 		else
|3718|3718| 			this.UpdateWorkOrders(type);
|3719|    |-	}
|    |3719|+	
|3720|3720| 
|3721|3721| 	let garrisonHolder = this.IsGarrisoned() && type != "Ungarrison" ? this.GetGarrisonHolder() : null;
|3722|3722| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3788|3788| 	{
|3789|3789| 		var cmpUnitAI = Engine.QueryInterface(this.formationController, IID_UnitAI);
|3790|3790| 		if (cmpUnitAI)
|3791|    |-		{
|    |3791|+		
|3792|3792| 			for (var i = 0; i < cmpUnitAI.orderQueue.length; ++i)
|3793|3793| 			{
|3794|3794| 				if (isWorkType(cmpUnitAI.orderQueue[i].type))
|3797|3797| 					return;
|3798|3798| 				}
|3799|3799| 			}
|3800|    |-		}
|    |3800|+		
|3801|3801| 	}
|3802|3802| 
|3803|3803| 	// If nothing found, take the unit orders
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3790|3790| 		if (cmpUnitAI)
|3791|3791| 		{
|3792|3792| 			for (var i = 0; i < cmpUnitAI.orderQueue.length; ++i)
|3793|    |-			{
|    |3793|+			
|3794|3794| 				if (isWorkType(cmpUnitAI.orderQueue[i].type))
|3795|3795| 				{
|3796|3796| 					this.workOrders = cmpUnitAI.orderQueue.slice(i);
|3797|3797| 					return;
|3798|3798| 				}
|3799|    |-			}
|    |3799|+			
|3800|3800| 		}
|3801|3801| 	}
|3802|3802| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3802|3802| 
|3803|3803| 	// If nothing found, take the unit orders
|3804|3804| 	for (var i = 0; i < this.orderQueue.length; ++i)
|3805|    |-	{
|    |3805|+	
|3806|3806| 		if (isWorkType(this.orderQueue[i].type))
|3807|3807| 		{
|3808|3808| 			this.workOrders = this.orderQueue.slice(i);
|3809|3809| 			return;
|3810|3810| 		}
|3811|    |-	}
|    |3811|+	
|3812|3812| };
|3813|3813| 
|3814|3814| UnitAI.prototype.BackToWork = function()
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3868|3868| 	if (data.timerRepeat === undefined)
|3869|3869| 		this.timer = undefined;
|3870|3870| 
|3871|    |-	this.UnitFsm.ProcessMessage(this, {"type": "Timer", "data": data, "lateness": lateness});
|    |3871|+	this.UnitFsm.ProcessMessage(this, { "type": "Timer", "data": data, "lateness": lateness});
|3872|3872| };
|3873|3873| 
|3874|3874| /**
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3868|3868| 	if (data.timerRepeat === undefined)
|3869|3869| 		this.timer = undefined;
|3870|3870| 
|3871|    |-	this.UnitFsm.ProcessMessage(this, {"type": "Timer", "data": data, "lateness": lateness});
|    |3871|+	this.UnitFsm.ProcessMessage(this, {"type": "Timer", "data": data, "lateness": lateness });
|3872|3872| };
|3873|3873| 
|3874|3874| /**
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3903|3903| 	this.timer = undefined;
|3904|3904| };
|3905|3905| 
|3906|    |-//// Message handlers /////
|    |3906|+// // Message handlers /////
|3907|3907| 
|3908|3908| UnitAI.prototype.OnMotionChanged = function(msg)
|3909|3909| {
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3908|3908| UnitAI.prototype.OnMotionChanged = function(msg)
|3909|3909| {
|3910|3910| 	if (msg.starting && !msg.error)
|3911|    |-		this.UnitFsm.ProcessMessage(this, {"type": "MoveStarted", "data": msg});
|    |3911|+		this.UnitFsm.ProcessMessage(this, { "type": "MoveStarted", "data": msg});
|3912|3912| 	else if (!msg.starting || msg.error)
|3913|3913| 		this.UnitFsm.ProcessMessage(this, {"type": "MoveCompleted", "data": msg});
|3914|3914| };
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3908|3908| UnitAI.prototype.OnMotionChanged = function(msg)
|3909|3909| {
|3910|3910| 	if (msg.starting && !msg.error)
|3911|    |-		this.UnitFsm.ProcessMessage(this, {"type": "MoveStarted", "data": msg});
|    |3911|+		this.UnitFsm.ProcessMessage(this, {"type": "MoveStarted", "data": msg });
|3912|3912| 	else if (!msg.starting || msg.error)
|3913|3913| 		this.UnitFsm.ProcessMessage(this, {"type": "MoveCompleted", "data": msg});
|3914|3914| };
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3910|3910| 	if (msg.starting && !msg.error)
|3911|3911| 		this.UnitFsm.ProcessMessage(this, {"type": "MoveStarted", "data": msg});
|3912|3912| 	else if (!msg.starting || msg.error)
|3913|    |-		this.UnitFsm.ProcessMessage(this, {"type": "MoveCompleted", "data": msg});
|    |3913|+		this.UnitFsm.ProcessMessage(this, { "type": "MoveCompleted", "data": msg});
|3914|3914| };
|3915|3915| 
|3916|3916| UnitAI.prototype.OnGlobalConstructionFinished = function(msg)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3910|3910| 	if (msg.starting && !msg.error)
|3911|3911| 		this.UnitFsm.ProcessMessage(this, {"type": "MoveStarted", "data": msg});
|3912|3912| 	else if (!msg.starting || msg.error)
|3913|    |-		this.UnitFsm.ProcessMessage(this, {"type": "MoveCompleted", "data": msg});
|    |3913|+		this.UnitFsm.ProcessMessage(this, {"type": "MoveCompleted", "data": msg });
|3914|3914| };
|3915|3915| 
|3916|3916| UnitAI.prototype.OnGlobalConstructionFinished = function(msg)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3918|3918| 	// TODO: This is a bit inefficient since every unit listens to every
|3919|3919| 	// construction message - ideally we could scope it to only the one we're building
|3920|3920| 
|3921|    |-	this.UnitFsm.ProcessMessage(this, {"type": "ConstructionFinished", "data": msg});
|    |3921|+	this.UnitFsm.ProcessMessage(this, { "type": "ConstructionFinished", "data": msg});
|3922|3922| };
|3923|3923| 
|3924|3924| UnitAI.prototype.OnGlobalEntityRenamed = function(msg)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3918|3918| 	// TODO: This is a bit inefficient since every unit listens to every
|3919|3919| 	// construction message - ideally we could scope it to only the one we're building
|3920|3920| 
|3921|    |-	this.UnitFsm.ProcessMessage(this, {"type": "ConstructionFinished", "data": msg});
|    |3921|+	this.UnitFsm.ProcessMessage(this, {"type": "ConstructionFinished", "data": msg });
|3922|3922| };
|3923|3923| 
|3924|3924| UnitAI.prototype.OnGlobalEntityRenamed = function(msg)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3943|3943| 
|3944|3944| UnitAI.prototype.OnAttacked = function(msg)
|3945|3945| {
|3946|    |-	this.UnitFsm.ProcessMessage(this, {"type": "Attacked", "data": msg});
|    |3946|+	this.UnitFsm.ProcessMessage(this, { "type": "Attacked", "data": msg});
|3947|3947| };
|3948|3948| 
|3949|3949| UnitAI.prototype.OnGuardedAttacked = function(msg)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3943|3943| 
|3944|3944| UnitAI.prototype.OnAttacked = function(msg)
|3945|3945| {
|3946|    |-	this.UnitFsm.ProcessMessage(this, {"type": "Attacked", "data": msg});
|    |3946|+	this.UnitFsm.ProcessMessage(this, {"type": "Attacked", "data": msg });
|3947|3947| };
|3948|3948| 
|3949|3949| UnitAI.prototype.OnGuardedAttacked = function(msg)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3948|3948| 
|3949|3949| UnitAI.prototype.OnGuardedAttacked = function(msg)
|3950|3950| {
|3951|    |-	this.UnitFsm.ProcessMessage(this, {"type": "GuardedAttacked", "data": msg.data});
|    |3951|+	this.UnitFsm.ProcessMessage(this, { "type": "GuardedAttacked", "data": msg.data});
|3952|3952| };
|3953|3953| 
|3954|3954| UnitAI.prototype.OnHealthChanged = function(msg)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3948|3948| 
|3949|3949| UnitAI.prototype.OnGuardedAttacked = function(msg)
|3950|3950| {
|3951|    |-	this.UnitFsm.ProcessMessage(this, {"type": "GuardedAttacked", "data": msg.data});
|    |3951|+	this.UnitFsm.ProcessMessage(this, {"type": "GuardedAttacked", "data": msg.data });
|3952|3952| };
|3953|3953| 
|3954|3954| UnitAI.prototype.OnHealthChanged = function(msg)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3953|3953| 
|3954|3954| UnitAI.prototype.OnHealthChanged = function(msg)
|3955|3955| {
|3956|    |-	this.UnitFsm.ProcessMessage(this, {"type": "HealthChanged", "from": msg.from, "to": msg.to});
|    |3956|+	this.UnitFsm.ProcessMessage(this, { "type": "HealthChanged", "from": msg.from, "to": msg.to});
|3957|3957| };
|3958|3958| 
|3959|3959| UnitAI.prototype.OnRangeUpdate = function(msg)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3953|3953| 
|3954|3954| UnitAI.prototype.OnHealthChanged = function(msg)
|3955|3955| {
|3956|    |-	this.UnitFsm.ProcessMessage(this, {"type": "HealthChanged", "from": msg.from, "to": msg.to});
|    |3956|+	this.UnitFsm.ProcessMessage(this, {"type": "HealthChanged", "from": msg.from, "to": msg.to });
|3957|3957| };
|3958|3958| 
|3959|3959| UnitAI.prototype.OnRangeUpdate = function(msg)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3959|3959| UnitAI.prototype.OnRangeUpdate = function(msg)
|3960|3960| {
|3961|3961| 	if (msg.tag == this.losRangeQuery)
|3962|    |-		this.UnitFsm.ProcessMessage(this, {"type": "LosRangeUpdate", "data": msg});
|    |3962|+		this.UnitFsm.ProcessMessage(this, { "type": "LosRangeUpdate", "data": msg});
|3963|3963| 	else if (msg.tag == this.losHealRangeQuery)
|3964|3964| 		this.UnitFsm.ProcessMessage(this, {"type": "LosHealRangeUpdate", "data": msg});
|3965|3965| };
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3959|3959| UnitAI.prototype.OnRangeUpdate = function(msg)
|3960|3960| {
|3961|3961| 	if (msg.tag == this.losRangeQuery)
|3962|    |-		this.UnitFsm.ProcessMessage(this, {"type": "LosRangeUpdate", "data": msg});
|    |3962|+		this.UnitFsm.ProcessMessage(this, {"type": "LosRangeUpdate", "data": msg });
|3963|3963| 	else if (msg.tag == this.losHealRangeQuery)
|3964|3964| 		this.UnitFsm.ProcessMessage(this, {"type": "LosHealRangeUpdate", "data": msg});
|3965|3965| };
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3961|3961| 	if (msg.tag == this.losRangeQuery)
|3962|3962| 		this.UnitFsm.ProcessMessage(this, {"type": "LosRangeUpdate", "data": msg});
|3963|3963| 	else if (msg.tag == this.losHealRangeQuery)
|3964|    |-		this.UnitFsm.ProcessMessage(this, {"type": "LosHealRangeUpdate", "data": msg});
|    |3964|+		this.UnitFsm.ProcessMessage(this, { "type": "LosHealRangeUpdate", "data": msg});
|3965|3965| };
|3966|3966| 
|3967|3967| UnitAI.prototype.OnPackFinished = function(msg)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3961|3961| 	if (msg.tag == this.losRangeQuery)
|3962|3962| 		this.UnitFsm.ProcessMessage(this, {"type": "LosRangeUpdate", "data": msg});
|3963|3963| 	else if (msg.tag == this.losHealRangeQuery)
|3964|    |-		this.UnitFsm.ProcessMessage(this, {"type": "LosHealRangeUpdate", "data": msg});
|    |3964|+		this.UnitFsm.ProcessMessage(this, {"type": "LosHealRangeUpdate", "data": msg });
|3965|3965| };
|3966|3966| 
|3967|3967| UnitAI.prototype.OnPackFinished = function(msg)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3966|3966| 
|3967|3967| UnitAI.prototype.OnPackFinished = function(msg)
|3968|3968| {
|3969|    |-	this.UnitFsm.ProcessMessage(this, {"type": "PackFinished", "packed": msg.packed});
|    |3969|+	this.UnitFsm.ProcessMessage(this, { "type": "PackFinished", "packed": msg.packed});
|3970|3970| };
|3971|3971| 
|3972|3972| //// Helper functions to be called by the FSM ////
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3966|3966| 
|3967|3967| UnitAI.prototype.OnPackFinished = function(msg)
|3968|3968| {
|3969|    |-	this.UnitFsm.ProcessMessage(this, {"type": "PackFinished", "packed": msg.packed});
|    |3969|+	this.UnitFsm.ProcessMessage(this, {"type": "PackFinished", "packed": msg.packed });
|3970|3970| };
|3971|3971| 
|3972|3972| //// Helper functions to be called by the FSM ////
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|3969|3969| 	this.UnitFsm.ProcessMessage(this, {"type": "PackFinished", "packed": msg.packed});
|3970|3970| };
|3971|3971| 
|3972|    |-//// Helper functions to be called by the FSM ////
|    |3972|+// // Helper functions to be called by the FSM ////
|3973|3973| 
|3974|3974| UnitAI.prototype.GetWalkSpeed = function()
|3975|3975| {
|    | [NORMAL] ESLintBear (semi):
|    | Missing semicolon.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4073|4073| 	if (!cmpOwnership || cmpOwnership.GetOwner() == INVALID_PLAYER)
|4074|4074| 		return undefined;
|4075|4075| 
|4076|    |-	let cmpPosition = Engine.QueryInterface(this.entity, IID_Position)
|    |4076|+	let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
|4077|4077| 	if (!cmpPosition || !cmpPosition.IsInWorld())
|4078|4078| 		return undefined;
|4079|4079| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4158|4158| 			PlaySound(name, member);
|4159|4159| 	}
|4160|4160| 	else
|4161|    |-	{
|    |4161|+	
|4162|4162| 		// Otherwise use our own sounds
|4163|4163| 		PlaySound(name, this.entity);
|4164|    |-	}
|    |4164|+	
|4165|4165| };
|4166|4166| 
|4167|4167| /*
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4327|4327| 	else
|4328|4328| 		// return false? Or hope you come close enough?
|4329|4329| 		var parabolicMaxRange = 0;
|4330|    |-		//return false;
|    |4330|+		// return false;
|4331|4331| 
|4332|4332| 	// the parabole changes while walking, take something in the middle
|4333|4333| 	var guessedMaxRange = (range.max + parabolicMaxRange)/2;
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4392|4392| 	if (this.IsFormationMember())
|4393|4393| 	{
|4394|4394| 		var cmpFormationUnitAI = Engine.QueryInterface(this.formationController, IID_UnitAI);
|4395|    |-		if (cmpFormationUnitAI && cmpFormationUnitAI.IsAttackingAsFormation()
|4396|    |-			&& cmpFormationUnitAI.order.data.target == target)
|    |4395|+		if (cmpFormationUnitAI && cmpFormationUnitAI.IsAttackingAsFormation() &&
|    |4396|+			cmpFormationUnitAI.order.data.target == target)
|4397|4397| 			return true;
|4398|4398| 	}
|4399|4399| 
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4560|4560| UnitAI.prototype.AttackEntityInZone = function(ents)
|4561|4561| {
|4562|4562| 	var target = ents.find(target =>
|4563|    |-		this.CanAttack(target)
|4564|    |-		&& this.CheckTargetDistanceFromHeldPosition(target, IID_Attack, this.GetBestAttackAgainst(target, true))
|    |4563|+		this.CanAttack(target) &&
|    |4564|+		this.CheckTargetDistanceFromHeldPosition(target, IID_Attack, this.GetBestAttackAgainst(target, true))
|4565|4565| 		&& (this.GetStance().respondChaseBeyondVision || this.CheckTargetIsInVisionRange(target))
|4566|4566| 	);
|4567|4567| 	if (!target)
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4561|4561| {
|4562|4562| 	var target = ents.find(target =>
|4563|4563| 		this.CanAttack(target)
|4564|    |-		&& this.CheckTargetDistanceFromHeldPosition(target, IID_Attack, this.GetBestAttackAgainst(target, true))
|4565|    |-		&& (this.GetStance().respondChaseBeyondVision || this.CheckTargetIsInVisionRange(target))
|    |4564|+		&& this.CheckTargetDistanceFromHeldPosition(target, IID_Attack, this.GetBestAttackAgainst(target, true)) &&
|    |4565|+		(this.GetStance().respondChaseBeyondVision || this.CheckTargetIsInVisionRange(target))
|4566|4566| 	);
|4567|4567| 	if (!target)
|4568|4568| 		return false;
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before 'Engine'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4625|4625| 	// If we are guarding/escorting, don't abandon as long as the guarded unit is in target range of the attacker
|4626|4626| 	if (this.isGuardOf)
|4627|4627| 	{
|4628|    |-		var cmpUnitAI =  Engine.QueryInterface(target, IID_UnitAI);
|    |4628|+		var cmpUnitAI = Engine.QueryInterface(target, IID_UnitAI);
|4629|4629| 		var cmpAttack = Engine.QueryInterface(target, IID_Attack);
|4630|4630| 		if (cmpUnitAI && cmpAttack &&
|4631|4631| 		    cmpAttack.GetAttackTypes().some(type => cmpUnitAI.CheckTargetAttackRange(this.isGuardOf, type)))
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 3 tabs but found 4.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4629|4629| 		var cmpAttack = Engine.QueryInterface(target, IID_Attack);
|4630|4630| 		if (cmpUnitAI && cmpAttack &&
|4631|4631| 		    cmpAttack.GetAttackTypes().some(type => cmpUnitAI.CheckTargetAttackRange(this.isGuardOf, type)))
|4632|    |-				return false;
|    |4632|+			return false;
|4633|4633| 	}
|4634|4634| 
|4635|4635| 	// Stop if we're in hold-ground mode and it's too far from the holding point
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4634|4634| 
|4635|4635| 	// Stop if we're in hold-ground mode and it's too far from the holding point
|4636|4636| 	if (this.GetStance().respondHoldGround)
|4637|    |-	{
|    |4637|+	
|4638|4638| 		if (!this.CheckTargetDistanceFromHeldPosition(target, iid, type))
|4639|4639| 			return true;
|4640|    |-	}
|    |4640|+	
|4641|4641| 
|4642|4642| 	// Stop if it's left our vision range, unless we're especially persistent
|4643|4643| 	if (!this.GetStance().respondChaseBeyondVision)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4641|4641| 
|4642|4642| 	// Stop if it's left our vision range, unless we're especially persistent
|4643|4643| 	if (!this.GetStance().respondChaseBeyondVision)
|4644|    |-	{
|    |4644|+	
|4645|4645| 		if (!this.CheckTargetIsInVisionRange(target))
|4646|4646| 			return true;
|4647|    |-	}
|    |4647|+	
|4648|4648| 
|4649|4649| 	// (Note that CCmpUnitMotion will detect if the target is lost in FoW,
|4650|4650| 	// and will continue moving to its last seen position and then stop)
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before 'Engine'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4667|4667| 	// If we are guarding/escorting, chase at least as long as the guarded unit is in target range of the attacker
|4668|4668| 	if (this.isGuardOf)
|4669|4669| 	{
|4670|    |-		let cmpUnitAI =  Engine.QueryInterface(target, IID_UnitAI);
|    |4670|+		let cmpUnitAI = Engine.QueryInterface(target, IID_UnitAI);
|4671|4671| 		let cmpAttack = Engine.QueryInterface(target, IID_Attack);
|4672|4672| 		if (cmpUnitAI && cmpAttack &&
|4673|4673| 		    cmpAttack.GetAttackTypes().some(type => cmpUnitAI.CheckTargetAttackRange(this.isGuardOf, type)))
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4680|4680| 	return false;
|4681|4681| };
|4682|4682| 
|4683|    |-//// External interface functions ////
|    |4683|+// // External interface functions ////
|4684|4684| 
|4685|4685| UnitAI.prototype.SetFormationController = function(ent)
|4686|4686| {
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4690|4690| 	// of our own formation (or ourself if not in formation)
|4691|4691| 	var cmpObstruction = Engine.QueryInterface(this.entity, IID_Obstruction);
|4692|4692| 	if (cmpObstruction)
|4693|    |-	{
|    |4693|+	
|4694|4694| 		if (ent == INVALID_ENTITY)
|4695|4695| 			cmpObstruction.SetControlGroup(this.entity);
|4696|4696| 		else
|4697|4697| 			cmpObstruction.SetControlGroup(ent);
|4698|    |-	}
|    |4698|+	
|4699|4699| 
|4700|4700| 	// If we were removed from a formation, let the FSM switch back to INDIVIDUAL
|4701|4701| 	if (ent == INVALID_ENTITY)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4833|4833| 	// if we already had an old guard order, do nothing if the target is the same
|4834|4834| 	// and the order is running, otherwise remove the previous order
|4835|4835| 	if (this.isGuardOf)
|4836|    |-	{
|    |4836|+	
|4837|4837| 		if (this.isGuardOf == target && this.order && this.order.type == "Guard")
|4838|4838| 			return;
|4839|4839| 		else
|4840|4840| 			this.RemoveGuard();
|4841|    |-	}
|    |4841|+	
|4842|4842| 
|4843|4843| 	this.AddOrder("Guard", { "target": target, "force": false }, queued);
|4844|4844| };
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|4836|4836| 	{
|4837|4837| 		if (this.isGuardOf == target && this.order && this.order.type == "Guard")
|4838|4838| 			return;
|4839|    |-		else
|4840|    |-			this.RemoveGuard();
|    |4839|+		this.RemoveGuard();
|4841|4840| 	}
|4842|4841| 
|4843|4842| 	this.AddOrder("Guard", { "target": target, "force": false }, queued);
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|5007|5007| 			this.WalkToTarget(target, queued);
|5008|5008| 		return;
|5009|5009| 	}
|5010|    |-	this.AddOrder("Attack", { "target": target, "force": true, "allowCapture": allowCapture}, queued);
|    |5010|+	this.AddOrder("Attack", { "target": target, "force": true, "allowCapture": allowCapture }, queued);
|5011|5011| };
|5012|5012| 
|5013|5013| /**
|    | [NORMAL] ESLintBear (no-trailing-spaces):
|    | Trailing spaces not allowed.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|5156|5156| 	    this.workOrders.length && this.workOrders[0].type == "Trade")
|5157|5157| 	{
|5158|5158| 		let cmpTrader = Engine.QueryInterface(this.entity, IID_Trader);
|5159|    |-		if (cmpTrader.HasBothMarkets() && 
|    |5159|+		if (cmpTrader.HasBothMarkets() &&
|5160|5160| 		   (cmpTrader.GetFirstMarket() == target && cmpTrader.GetSecondMarket() == source ||
|5161|5161| 		    cmpTrader.GetFirstMarket() == source && cmpTrader.GetSecondMarket() == target))
|5162|5162| 		{
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|5437|5437| 				{
|5438|5438| 					var cmpIdentity = Engine.QueryInterface(targ, IID_Identity);
|5439|5439| 					var targetClasses = this.order.data.targetClasses;
|5440|    |-					if (targetClasses.attack && cmpIdentity
|5441|    |-						&& !MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.attack))
|    |5440|+					if (targetClasses.attack && cmpIdentity &&
|    |5441|+						!MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.attack))
|5442|5442| 						continue;
|5443|5443| 					if (targetClasses.avoid && cmpIdentity
|5444|5444| 						&& MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid))
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|5440|5440| 					if (targetClasses.attack && cmpIdentity
|5441|5441| 						&& !MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.attack))
|5442|5442| 						continue;
|5443|    |-					if (targetClasses.avoid && cmpIdentity
|5444|    |-						&& MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid))
|    |5443|+					if (targetClasses.avoid && cmpIdentity &&
|    |5444|+						MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid))
|5445|5445| 						continue;
|5446|5446| 					// Only used by the AIs to prevent some choices of targets
|5447|5447| 					if (targetClasses.vetoEntities && targetClasses.vetoEntities[targ])
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|5463|5463| 		{
|5464|5464| 			var cmpIdentity = Engine.QueryInterface(targ, IID_Identity);
|5465|5465| 			var targetClasses = this.order.data.targetClasses;
|5466|    |-			if (cmpIdentity && targetClasses.attack
|5467|    |-				&& !MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.attack))
|    |5466|+			if (cmpIdentity && targetClasses.attack &&
|    |5467|+				!MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.attack))
|5468|5468| 				continue;
|5469|5469| 			if (cmpIdentity && targetClasses.avoid
|5470|5470| 				&& MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid))
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|5466|5466| 			if (cmpIdentity && targetClasses.attack
|5467|5467| 				&& !MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.attack))
|5468|5468| 				continue;
|5469|    |-			if (cmpIdentity && targetClasses.avoid
|5470|    |-				&& MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid))
|    |5469|+			if (cmpIdentity && targetClasses.avoid &&
|    |5470|+				MatchesClassList(cmpIdentity.GetClassesList(), targetClasses.avoid))
|5471|5471| 				continue;
|5472|5472| 			// Only used by the AIs to prevent some choices of targets
|5473|5473| 			if (targetClasses.vetoEntities && targetClasses.vetoEntities[targ])
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required after '{'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|5599|5599| 
|5600|5600| UnitAI.prototype.SetHeldPosition = function(x, z)
|5601|5601| {
|5602|    |-	this.heldPosition = {"x": x, "z": z};
|    |5602|+	this.heldPosition = { "x": x, "z": z};
|5603|5603| };
|5604|5604| 
|5605|5605| UnitAI.prototype.SetHeldPositionOnEntity = function(entity)
|    | [NORMAL] ESLintBear (object-curly-spacing):
|    | A space is required before '}'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|5599|5599| 
|5600|5600| UnitAI.prototype.SetHeldPosition = function(x, z)
|5601|5601| {
|5602|    |-	this.heldPosition = {"x": x, "z": z};
|    |5602|+	this.heldPosition = {"x": x, "z": z };
|5603|5603| };
|5604|5604| 
|5605|5605| UnitAI.prototype.SetHeldPositionOnEntity = function(entity)
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|5626|5626| 	return false;
|5627|5627| };
|5628|5628| 
|5629|    |-//// Helper functions ////
|    |5629|+// // Helper functions ////
|5630|5630| 
|5631|5631| UnitAI.prototype.CanAttack = function(target)
|5632|5632| {
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|5830|5830| 	return cmpPack && cmpPack.IsPacking();
|5831|5831| };
|5832|5832| 
|5833|    |-//// Formation specific functions ////
|    |5833|+// // Formation specific functions ////
|5834|5834| 
|5835|5835| UnitAI.prototype.IsAttackingAsFormation = function()
|5836|5836| {
|    | [NORMAL] ESLintBear (operator-linebreak):
|    | '&&' should be placed at the end of the line.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|5835|5835| UnitAI.prototype.IsAttackingAsFormation = function()
|5836|5836| {
|5837|5837| 	var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack);
|5838|    |-	return cmpAttack && cmpAttack.CanAttackAsFormation()
|5839|    |-		&& this.GetCurrentState() == "FORMATIONCONTROLLER.COMBAT.ATTACKING";
|    |5838|+	return cmpAttack && cmpAttack.CanAttackAsFormation() &&
|    |5839|+		this.GetCurrentState() == "FORMATIONCONTROLLER.COMBAT.ATTACKING";
|5840|5840| };
|5841|5841| 
|5842|5842| //// Animal specific functions ////
|    | [NORMAL] ESLintBear (spaced-comment):
|    | Expected space or tab after '//' in comment.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/UnitAI.js
|5839|5839| 		&& this.GetCurrentState() == "FORMATIONCONTROLLER.COMBAT.ATTACKING";
|5840|5840| };
|5841|5841| 
|5842|    |-//// Animal specific functions ////
|    |5842|+// // Animal specific functions ////
|5843|5843| 
|5844|5844| UnitAI.prototype.MoveRandomly = function(distance)
|5845|5845| {

binaries/data/mods/public/simulation/components/UnitAI.js
|2413| »   »   »   »   »   »   let·nearby·=·this.FindNearestDropsite(resourceType.generic);
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'nearby' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|3773| »   var·isWorkType·=·type·=>·type·==·"Gather"·||·type·==·"Trade"·||·type·==·"Repair"·||·type·==·"ReturnResource";
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'type' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4547| »   var·target·=·ents.find(target·=>·this.CanAttack(target));
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'target' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4562| »   var·target·=·ents.find(target·=>
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'target' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4608| »   var·ent·=·ents.find(ent·=>·this.CanHeal(ent));
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'ent' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4631| »   »   ····cmpAttack.GetAttackTypes().some(type·=>·cmpUnitAI.CheckTargetAttackRange(this.isGuardOf,·type)))
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'type' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|5087| »   var·lastPos·=·undefined;
|    | [NORMAL] ESLintBear (no-undef-init):
|    | It's not necessary to initialize 'lastPos' to undefined.

binaries/data/mods/public/simulation/components/UnitAI.js
| 365| »   »   ····&&·(this.lastShorelinePosition.z·==·cmpPosition.GetPosition().z))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|1881| »   »   »   »   »   »   var·cmpFormation·=·Engine.QueryInterface(this.formationController,·IID_Formation);
|    | [NORMAL] JSHintBear:
|    | 'cmpFormation' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2022| »   »   »   »   »   »   &&·this.order.data.target·!=·msg.data.attacker·&&·this.GetBestAttackAgainst(msg.data.attacker,·true)·!=·"Capture")
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2106| »   »   »   »   »   »   »   »   ·&&·((type.generic·==·"treasure"·&&·oldType.generic·==·"treasure")
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2107| »   »   »   »   »   »   »   »   ·||·(type.specific·==·oldType.specific
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '||'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2108| »   »   »   »   »   »   »   »   ·&&·(type.specific·!=·"meat"·||·oldTemplate·==·template)))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2131| »   »   »   »   »   »   »   »   var·nearby·=·this.FindNearestDropsite(oldType.generic);
|    | [NORMAL] JSHintBear:
|    | 'nearby' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2171| »   »   »   »   »   »   »   »   &&·((type.generic·==·"treasure"·&&·oldType.generic·==·"treasure")
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2172| »   »   »   »   »   »   »   »   ||·(type.specific·==·oldType.specific
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '||'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2173| »   »   »   »   »   »   »   »   &&·(type.specific·!=·"meat"·||·oldTemplate·==·template)))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2218| »   »   »   »   »   »   »   ||·(type.specific·==·resourceType.specific
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '||'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2219| »   »   »   »   »   »   »   &&·(type.specific·!=·"meat"·||·resourceTemplate·==·template))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2235| »   »   »   »   »   var·nearby·=·this.FindNearestDropsite(resourceType.generic);
|    | [NORMAL] JSHintBear:
|    | 'nearby' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2408| »   »   »   »   »   var·cmpResourceGatherer·=·Engine.QueryInterface(this.entity,·IID_ResourceGatherer);
|    | [NORMAL] JSHintBear:
|    | 'cmpResourceGatherer' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2424| »   »   »   »   »   var·nearby·=·this.FindNearbyResource(function(ent,·type,·template)·{
|    | [NORMAL] JSHintBear:
|    | 'nearby' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2427| »   »   »   »   »   »   »   ||·(type.specific·==·resourceType.specific
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '||'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2428| »   »   »   »   »   »   »   &&·(type.specific·!=·"meat"·||·resourceTemplate·==·template))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2448| »   »   »   »   »   var·nearby·=·this.FindNearestDropsite(resourceType.generic);
|    | [NORMAL] JSHintBear:
|    | 'nearby' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2637| »   »   »   »   »   var·cmpResourceGatherer·=·Engine.QueryInterface(this.entity,·IID_ResourceGatherer);
|    | [NORMAL] JSHintBear:
|    | 'cmpResourceGatherer' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2832| »   »   »   »   »   var·cmpResourceDropsite·=·Engine.QueryInterface(msg.data.newentity,·IID_ResourceDropsite);
|    | [NORMAL] JSHintBear:
|    | 'cmpResourceDropsite' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2908| »   »   »   »   »   if·(this.CanGarrison(target))
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|2911| »   »   »   »   »   »   if·(this.CheckGarrisonRange(target))
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|2913| »   »   »   »   »   »   »   var·cmpGarrisonHolder·=·Engine.QueryInterface(target,·IID_GarrisonHolder);
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|2935| »   »   »   »   »   »   »   »   var·cmpResourceDropsite·=·Engine.QueryInterface(target,·IID_ResourceDropsite);
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|2936| »   »   »   »   »   »   »   »   if·(cmpResourceDropsite·&&·this.CanReturnResource(target,·true))
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|2951| »   »   »   »   »   »   »   »   »   var·cmpHolderPosition·=·Engine.QueryInterface(target,·IID_Position);
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|2952| »   »   »   »   »   »   »   »   »   var·cmpHolderUnitAI·=·Engine.QueryInterface(target,·IID_UnitAI);
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|2979| »   »   »   »   »   »   »   if·(this.MoveToTarget(target))
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|3735| »   »   var·order·=·{·"type":·type,·"data":·data·};
|    | [NORMAL] JSHintBear:
|    | 'order' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|3804| »   for·(var·i·=·0;·i·<·this.orderQueue.length;·++i)
|    | [NORMAL] JSHintBear:
|    | 'i' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|4076| »   let·cmpPosition·=·Engine.QueryInterface(this.entity,·IID_Position)
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.

binaries/data/mods/public/simulation/components/UnitAI.js
|4329| »   »   var·parabolicMaxRange·=·0;
|    | [NORMAL] JSHintBear:
|    | 'parabolicMaxRange' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|4333| »   var·guessedMaxRange·=·(range.max·+·parabolicMaxRange)/2;
|    | [NORMAL] JSHintBear:
|    | 'parabolicMaxRange' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4340| »   return·cmpUnitMotion.MoveToTargetRange(target,·range.min,·Math.min(range.max,·parabolicMaxRange));
|    | [NORMAL] JSHintBear:
|    | 'parabolicMaxRange' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4396| »   »   »   &&·cmpFormationUnitAI.order.data.target·==·target)
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|4564| »   »   &&·this.CheckTargetDistanceFromHeldPosition(target,·IID_Attack,·this.GetBestAttackAgainst(target,·true))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|4565| »   »   &&·(this.GetStance().respondChaseBeyondVision·||·this.CheckTargetIsInVisionRange(target))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|5087| »   var·lastPos·=·undefined;
|    | [NORMAL] JSHintBear:
|    | It's not necessary to initialize 'lastPos' to 'undefined'.

binaries/data/mods/public/simulation/components/UnitAI.js
|5441| »   »   »   »   »   »   &&·!MatchesClassList(cmpIdentity.GetClassesList(),·targetClasses.attack))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|5444| »   »   »   »   »   »   &&·MatchesClassList(cmpIdentity.GetClassesList(),·targetClasses.avoid))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|5457| »   var·targets·=·this.GetTargetsFromUnit();
|    | [NORMAL] JSHintBear:
|    | 'targets' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|5458| »   for·(var·targ·of·targets)
|    | [NORMAL] JSHintBear:
|    | 'targ' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|5464| »   »   »   var·cmpIdentity·=·Engine.QueryInterface(targ,·IID_Identity);
|    | [NORMAL] JSHintBear:
|    | 'cmpIdentity' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|5465| »   »   »   var·targetClasses·=·this.order.data.targetClasses;
|    | [NORMAL] JSHintBear:
|    | 'targetClasses' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|5467| »   »   »   »   &&·!MatchesClassList(cmpIdentity.GetClassesList(),·targetClasses.attack))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|5470| »   »   »   »   &&·MatchesClassList(cmpIdentity.GetClassesList(),·targetClasses.avoid))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|5545| »   »   var·cmpVision·=·Engine.QueryInterface(this.entity,·IID_Vision);
|    | [NORMAL] JSHintBear:
|    | 'cmpVision' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|5548| »   »   var·range·=·cmpVision.GetRange();
|    | [NORMAL] JSHintBear:
|    | 'range' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|5553| »   »   var·cmpRanged·=·Engine.QueryInterface(this.entity,·iid);
|    | [NORMAL] JSHintBear:
|    | 'cmpRanged' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|5556| »   »   var·range·=·iid·!==·IID_Attack·?·cmpRanged.GetRange()·:·cmpRanged.GetFullAttackRange();
|    | [NORMAL] JSHintBear:
|    | 'range' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|5556| »   »   var·range·=·iid·!==·IID_Attack·?·cmpRanged.GetRange()·:·cmpRanged.GetFullAttackRange();
|    | [MAJOR] JSHintBear:
|    | Too many errors. (93% scanned).
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/differential/954/

Itms added a subscriber: Itms.Jan 13 2019, 8:24 PM

It would be nice to have something that detects such infinite loops and creates JS errors instead of engine crashes.

elexis added a subscriber: elexis.Jan 13 2019, 11:51 PM

something that detects such infinite loops

(Sounds a lot like solving the halting problem)

(The stack in this diff is the first of N unexplored behavior changes of rP22023. The general approach of that commit sounded reasonable, but not knowing which behavior changes one triggers might introduce unwanted behavior changes.)

Yeah I don't think we can really do this without adding a lot of JS overhead to the FSM, sadly. Maybe newer SM has better debugging support for this kind of issue?

I'll give a quick look to other instance changed by rP22023 to see if I can find something dangerous elsewhere, however this is probably crashing quite often on SVN so I'd like to commit it soon.

wraitii marked 6 inline comments as done.Jan 18 2019, 4:31 PM

General remarks:

  • an order is a change of action, so changing state should be able to trigger cleanup in our existing state without crashing. So we can discard any Order.XXX SetNextState as being conceptually OK.
  • This crash happens when an order sets us in a new state in which the Enter clause gives us the same order (hence the infinite loop)

Because of that, it is enough to look at all FSM states that can put us in a new Order/State in the "Enter" phase - since otherwise there's no chance of an infinite loop.

There's few of those:

  • one in Formation.Idle redirects us to Idle.Idle or Animal.Idle >> Fine
  • one in Combat.attacking, to Combat.Chasing, but then nothing else so we're good.
  • one in Repair.Repairing which goes to Approaching, but again after that we're fine
  • one in animal.Idle which puts us in Feeding but that also ought to be fine
  • one in Formation.Idle redirects us to Idle.Idle or Animal.Idle >> Fine

So we don't have other obvious crashes. I could have missed something on the above reasoning, but I don't believe so.
Ergo, this is complete imo.

Yeah I don't think we can really do this without adding a lot of JS overhead to the FSM, sadly.

Literally impossible to detect infinite loops in general, only specific ones like this one here. https://en.wikipedia.org/wiki/Halting_problem#Proof_concept
(I guess it's possible to write a program that can detect if a function appears more than 100k times in a stack, but not sure that is nice to have.)

it is enough to look at all FSM states that can put us in a new Order/State in the "Enter" phase - since otherwise there's no chance of an infinite loop.

I didn't check, but this sounds more like a verification than what I read before.
Notice there could also be undesired effects other than infinite loops as well, for example doing things that cost performance but are not necessary to perform.
Is that MT_UnitAIOrderDataChanged now sent redundantly sent for instance (I try to avoid reading this big file)?

wraitii added a comment.EditedJan 18 2019, 5:49 PM

(I guess it's possible to write a program that can detect if a function appears more than 100k times in a stack, but not sure that is nice to have.)

yes that's what I mean here.

Notice there could also be undesired effects other than infinite loops as well, for example doing things that cost performance but are not necessary to perform.
Is that MT_UnitAIOrderDataChanged now sent redundantly sent for instance (I try to avoid reading this big file)?

We only send this explicitly in 1 case in the FSM states, and it's in a case where we are actually skipping a redundant order explicitly. In other cases, it happens in the order-handling functions such as FinishOrder or PushOrder, and even if we push two orders with the same data, unless those are sent at the "exact" same time, they will be different orders. Gathering from the same tree at minute 5 and 9 is not the same order.

Overall I have reasonable doubt that there are other unintended negative side effects (as this has already fixed a reported bug for example, so that's a positive side effect). I did expect this to have some impact, since it changes behaviour in some cases, but I expected it to have a mostly neutral impact.

Note that I don't pretend to have a 100% understanding of the UnitAI code, and I don't believe I ever can get that level of understanding of such complex code, so me being 100% sure is impossible.

This revision was not accepted when it landed; it landed in state Needs Review.Jan 19 2019, 8:45 AM
This revision was automatically updated to reflect the committed changes.

Committed this as it fixes the issue, making svn playable again. There might be a better fix, but it sounds like it would require a more extensive unitAI rewrite.

did expect this to have some impact, since it changes behaviour in some cases, but I expected it to have a mostly neutral impact.

But these cases are limited and discoverable?

Well "discoverable", depends what you mean. Ultimately it's all in the code obviously.

My testing showed that this mostly affected Animal.IDle and Individual.Idle, so I doubt it's anything but "limited" beyond this problem.

endsWith is exceptional (first occasion where IDLE state is checked in unitAI this way), this.isIdle seems to be the variable used for that?
Judging by UnitAI.prototype.OnCreate that property is used for all three types.

In D1743#84321, @elexis wrote:

endsWith is exceptional (first occasion where IDLE state is checked in unitAI this way), this.isIdle seems to be the variable used for that?

As commented in IDLE.enter:

// The GUI and AI want to know when a unit is idle, but we don't
// want to send frequent spurious messages if the unit's only
// idle for an instant and will quickly go off and do something else.
// So we'll set a timer here and only report the idle event if we
// remain idle

Thus this.isIdle might actually be false in FinishOrder, and would therefore not correctly detect that the unit is in IDLE state.
Furthermore, what we want here is explicitly to check that the state isn't [INDIVIDUAL/ANIMAL].IDLE, not that we are in some kind of human-defined "idle" state.