Page MenuHomeWildfire Games

petra: Fix all ESLint and JSHint warnings
ClosedPublic

Authored by Krinkle on Jun 16 2019, 10:51 PM.

Details

Reviewers
elexis
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Restricted Owners Package(Owns No Changed Paths)
Commits
rP22835: Fix some Petra whitespace; with rP22803/D2103 fixes all ESLint issues in petra/…
Trac Tickets
#5524
#2322
Summary

I ran ESLint v6.3.0 locally, and ran eslint --fix on the ai/petra/ directory to automatically fix all violations of the ESLint rules in our eslintrc.json file that could be automatically fixed.

There were also a number of warnings that could not be fixed automatically, which were factored out in D2070 and D2103 and merged first.

This means there should now be 0 ESLint violations in the ai/petra directory.

In addition to the automatic fixes, this commit also two lines of commented out code that were oddly auto-formatted due to being commented out inline instead of as whole statements. Rather than fixing the indentation to adhere to ESLInt, I removed it in AttackPlan#checkTargetObstruction. It had been commented out from its first commit (r18257), and didn't seem to have an obvious purpose.

Test Plan

We'll see the Coala bears' judgement.

Or, to verify locally:

  • In the top directory, run fresh-node (or another safe environment in which to download and run arbitrary code from the internet with your user privileges).
  • Run npm install eslint@6.3.0 eslint-plugin-brace-rules@0.1.6
  • Run ./node_modules/.bin/eslint -f tap -c ./build/jenkins/lint-config/eslintrc.json binaries/data/mods/public/simulation/ai/petra/
  • All OK and exit code 0 (no errors).

Diff Detail

Repository
rP 0 A.D. Public Repository
Branch
/ps/trunk
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 7984
Build 12997: Vulcan BuildJenkins
Build 12995: arc lint + arc unit

Event Timeline

Krinkle created this revision.Jun 16 2019, 10:51 PM
Owners added a subscriber: Restricted Owners Package.Jun 16 2019, 10:51 PM

The full list of warnings that existed here before this commit:

eslint ./ai/petra (rules curly:off)
/0ad/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
   142:35  warning  Multiple spaces found before '='                     no-multi-spaces
   144:35  warning  Multiple spaces found before '='                     no-multi-spaces
   148:37  warning  Multiple spaces found before '='                     no-multi-spaces
   150:35  warning  Multiple spaces found before '='                     no-multi-spaces
   152:35  warning  Multiple spaces found before '='                     no-multi-spaces
   154:37  warning  Multiple spaces found before '='                     no-multi-spaces
   156:37  warning  Multiple spaces found before '='                     no-multi-spaces
   158:37  warning  Multiple spaces found before '='                     no-multi-spaces
   158:85  warning  Extra space before value for key 'targetSize'        key-spacing
   167:32  warning  Multiple spaces found before '='                     no-multi-spaces
  1146:1   warning  Expected indentation of 2 tabs but found 0           indent
  1148:1   warning  Expected indentation of 2 tabs but found 3           indent
  1149:1   warning  Expected indentation of 2 tabs but found 3           indent
  1150:1   warning  Expected indentation of 2 tabs but found 0           indent
  1544:4   warning  Assignment can be replaced with operator assignment  operator-assignment

/0ad/binaries/data/mods/public/simulation/ai/petra/baseManager.js
  198:1  warning  Expected indentation of 2 tabs but found 0  indent

/0ad/binaries/data/mods/public/simulation/ai/petra/config.js
  49:69  warning  Trailing spaces not allowed  no-trailing-spaces

/0ad/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
  172:1  warning  Expected indentation of 1 tab but found 0  indent

/0ad/binaries/data/mods/public/simulation/ai/petra/headquarters.js
  1095:72  warning  Trailing spaces not allowed                 no-trailing-spaces
  2686:1   warning  Expected indentation of 1 tab but found 0   indent
  2761:1   warning  Expected indentation of 2 tabs but found 0  indent

/0ad/binaries/data/mods/public/simulation/ai/petra/mapModule.js
  196:1  warning  Expected indentation of 1 tab but found 0  indent

/0ad/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
  747:29  warning  A space is required after ','  comma-spacing
  747:44  warning  A space is required after ','  comma-spacing
  747:58  warning  A space is required after ','  comma-spacing
  747:72  warning  A space is required after ','  comma-spacing
  747:87  warning  A space is required after ','  comma-spacing

/0ad/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
  427:16  warning  Multiple spaces found before '='  no-multi-spaces

/0ad/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
  243:58  warning  Trailing spaces not allowed  no-trailing-spaces

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/ai/petra/tradeManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
| 462| 462| 			if (m1.foundationProgress() === undefined && m2.foundationProgress() === undefined)
| 463| 463| 			{
| 464| 464| 				if (accessIndex)
| 465|    |-				{
|    | 465|+				
| 466| 466| 					if (gameState.ai.accessibility.regionType[accessIndex] == "water" && sea == accessIndex)
| 467| 467| 					{
| 468| 468| 						if (gain < bestIndex.gain)
| 481| 481| 							continue;
| 482| 482| 						bestLand = { "source": m1, "target": m2, "gain": gain, "land": land, "sea": sea };
| 483| 483| 					}
| 484|    |-				}
|    | 484|+				
| 485| 485| 				if (gain < candidate.gain)
| 486| 486| 					continue;
| 487| 487| 				candidate = { "source": m1, "target": m2, "gain": gain, "land": land, "sea": sea };
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
| 601| 601| 		return;	// position found, but not enough gain compared to our present route
| 602| 602| 
| 603| 603| 	if (this.Config.debug > 1)
| 604|    |-	{
|    | 604|+	
| 605| 605| 		if (this.potentialTradeRoute)
| 606| 606| 			API3.warn("turn " + gameState.ai.playedTurn + "we could have a new route with gain " +
| 607| 607| 				marketPos[3] + " instead of the present " + this.potentialTradeRoute.gain);
| 608| 608| 		else
| 609| 609| 			API3.warn("turn " + gameState.ai.playedTurn + "we could have a first route with gain " +
| 610| 610| 				marketPos[3]);
| 611|    |-	}
|    | 611|+	
| 612| 612| 
| 613| 613| 	if (!this.tradeRoute)
| 614| 614| 		gameState.ai.queueManager.changePriority("economicBuilding", 2*this.Config.priorities.economicBuilding);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
| 664| 664| 
| 665| 665| 	let ret = {};
| 666| 666| 	for (let key in route)
| 667|    |-	{
|    | 667|+	
| 668| 668| 		if (key == "source" || key == "target")
| 669| 669| 		{
| 670| 670| 			if (!route[key])
| 673| 673| 		}
| 674| 674| 		else
| 675| 675| 			ret[key] = route[key];
| 676|    |-	}
|    | 676|+	
| 677| 677| 	return ret;
| 678| 678| };
| 679| 679| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
| 684| 684| 
| 685| 685| 	let ret = {};
| 686| 686| 	for (let key in route)
| 687|    |-	{
|    | 687|+	
| 688| 688| 		if (key == "source" || key == "target")
| 689| 689| 		{
| 690| 690| 			ret[key] = gameState.getEntityById(route[key]);
| 693| 693| 		}
| 694| 694| 		else
| 695| 695| 			ret[key] = route[key];
| 696|    |-	}
|    | 696|+	
| 697| 697| 	return ret;
| 698| 698| };
| 699| 699| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
| 711| 711| m.TradeManager.prototype.Deserialize = function(gameState, data)
| 712| 712| {
| 713| 713| 	for (let key in data)
| 714|    |-	{
|    | 714|+	
| 715| 715| 		if (key == "tradeRoute" || key == "potentialTradeRoute")
| 716| 716| 			this[key] = this.routeIdToEnt(gameState, data[key]);
| 717| 717| 		else
| 718| 718| 			this[key] = data[key];
| 719|    |-	}
|    | 719|+	
| 720| 720| };
| 721| 721| 
| 722| 722| return m;

binaries/data/mods/public/simulation/ai/petra/tradeManager.js
| 723| }(PETRA);
|    | [MAJOR] ESLintBear (no-use-before-define):
|    | 'PETRA' was used before it was defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|  97|  97| 	else if (pos.xx === undefined || pos.x == pos.xx && pos.z == pos.zz)
|  98|  98| 		builder.construct(this.type, pos.x, pos.z, pos.angle, this.metadata);
|  99|  99| 	else // try with the lowest, move towards us unless we're same
| 100|    |-	{
|    | 100|+	
| 101| 101| 		for (let step = 0; step <= 1; step += 0.2)
| 102| 102| 			builder.construct(this.type, step*pos.x + (1-step)*pos.xx, step*pos.z + (1-step)*pos.zz,
| 103| 103| 				pos.angle, this.metadata);
| 104|    |-	}
|    | 104|+	
| 105| 105| 	this.onStart(gameState);
| 106| 106| 	Engine.ProfileStop();
| 107| 107| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 131| 131| 	}
| 132| 132| 
| 133| 133| 	if (!this.position)
| 134|    |-	{
|    | 134|+	
| 135| 135| 		if (template.hasClass("CivCentre"))
| 136| 136| 		{
| 137| 137| 			let pos;
| 177| 177| 			else if (!pos)
| 178| 178| 				return false;
| 179| 179| 		}
| 180|    |-	}
|    | 180|+	
| 181| 181| 
| 182| 182| 	// Compute each tile's closeness to friendly structures:
| 183| 183| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 204| 204| 					placement.set(j, 45);
| 205| 205| 		}
| 206| 206| 		else
| 207|    |-		{
|    | 207|+		
| 208| 208| 			for (let j = 0; j < placement.map.length; ++j)
| 209| 209| 				if (HQ.basesMap.map[j] != 0)
| 210| 210| 					placement.set(j, 45);
| 211|    |-		}
|    | 211|+		
| 212| 212| 
| 213| 213| 		if (!HQ.requireHouses || !template.hasClass("House"))
| 214| 214| 		{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 211| 211| 		}
| 212| 212| 
| 213| 213| 		if (!HQ.requireHouses || !template.hasClass("House"))
| 214|    |-		{
|    | 214|+		
| 215| 215| 			gameState.getOwnStructures().forEach(function(ent) {
| 216| 216| 				let pos = ent.position();
| 217| 217| 				let x = Math.round(pos[0] / cellSize);
| 245| 245| 				else if (template.genericName() == "Rotary Mill" && ent.hasClass("Field"))
| 246| 246| 					placement.addInfluence(x, z, 60/cellSize, 40);
| 247| 247| 			});
| 248|    |-		}
|    | 248|+		
| 249| 249| 		if (template.hasClass("Farmstead"))
| 250| 250| 		{
| 251| 251| 			for (let j = 0; j < placement.map.length; ++j)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 219| 219| 
| 220| 220| 				let struct = m.getBuiltEntity(gameState, ent);
| 221| 221| 				if (struct.resourceDropsiteTypes() && struct.resourceDropsiteTypes().indexOf("food") != -1)
| 222|    |-				{
|    | 222|+				
| 223| 223| 					if (template.hasClass("Field") || template.hasClass("Corral"))
| 224| 224| 						placement.addInfluence(x, z, 80/cellSize, 50);
| 225| 225| 					else // If this is not a field add a negative influence because we want to leave this area for fields
| 226| 226| 						placement.addInfluence(x, z, 80/cellSize, -20);
| 227|    |-				}
|    | 227|+				
| 228| 228| 				else if (template.hasClass("House"))
| 229| 229| 				{
| 230| 230| 					if (ent.hasClass("House"))
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 247| 247| 			});
| 248| 248| 		}
| 249| 249| 		if (template.hasClass("Farmstead"))
| 250|    |-		{
|    | 250|+		
| 251| 251| 			for (let j = 0; j < placement.map.length; ++j)
| 252| 252| 			{
| 253| 253| 				let value = placement.map[j] - gameState.sharedScript.resourceMaps.wood.map[j]/3;
| 255| 255| 					value /= 2;	// we need space around farmstead, so disfavor map border
| 256| 256| 				placement.set(j, value);
| 257| 257| 			}
| 258|    |-		}
|    | 258|+		
| 259| 259| 	}
| 260| 260| 
| 261| 261| 	// Requires to be inside our territory, and inside our base territory if required
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 268| 268| 	{
| 269| 269| 		let base = this.metadata.base;
| 270| 270| 		for (let j = 0; j < placement.map.length; ++j)
| 271|    |-		{
|    | 271|+		
| 272| 272| 			if (HQ.basesMap.map[j] != base)
| 273| 273| 				placement.map[j] = 0;
| 274| 274| 			else if (placement.map[j] > 0)
| 283| 283| 				if (HQ.isNearInvadingArmy([x, z]))
| 284| 284| 					placement.map[j] = 0;
| 285| 285| 			}
| 286|    |-		}
|    | 286|+		
| 287| 287| 	}
| 288| 288| 	else
| 289| 289| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 286| 286| 		}
| 287| 287| 	}
| 288| 288| 	else
| 289|    |-	{
|    | 289|+	
| 290| 290| 		for (let j = 0; j < placement.map.length; ++j)
| 291| 291| 		{
| 292| 292| 			if (HQ.basesMap.map[j] == 0)
| 306| 306| 					placement.set(j, placement.map[j] + 100);
| 307| 307| 			}
| 308| 308| 		}
| 309|    |-	}
|    | 309|+	
| 310| 310| 
| 311| 311| 	// Find the best non-obstructed:
| 312| 312| 	// Find target building's approximate obstruction radius, and expand by a bit to make sure we're not too close,
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 288| 288| 	else
| 289| 289| 	{
| 290| 290| 		for (let j = 0; j < placement.map.length; ++j)
| 291|    |-		{
|    | 291|+		
| 292| 292| 			if (HQ.basesMap.map[j] == 0)
| 293| 293| 				placement.map[j] = 0;
| 294| 294| 			else if (placement.map[j] > 0)
| 305| 305| 				else if (favoredBase && HQ.basesMap.map[j] == favoredBase)
| 306| 306| 					placement.set(j, placement.map[j] + 100);
| 307| 307| 			}
| 308|    |-		}
|    | 308|+		
| 309| 309| 	}
| 310| 310| 
| 311| 311| 	// Find the best non-obstructed:
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 650| 650| 		{
| 651| 651| 			let count = 0;
| 652| 652| 			for (let j = 0; j < length-1; ++j)
| 653|    |-			{
|    | 653|+			
| 654| 654| 				if ((waterPoints[(i + j) % length]+1) % numPoints == waterPoints[(i + j + 1) % length])
| 655| 655| 					++count;
| 656| 656| 				else
| 657| 657| 					break;
| 658|    |-			}
|    | 658|+			
| 659| 659| 			consec[i] = count;
| 660| 660| 		}
| 661| 661| 		let start = 0;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 661| 661| 		let start = 0;
| 662| 662| 		let count = 0;
| 663| 663| 		for (let c in consec)
| 664|    |-		{
|    | 664|+		
| 665| 665| 			if (consec[c] > count)
| 666| 666| 			{
| 667| 667| 				start = c;
| 668| 668| 				count = consec[c];
| 669| 669| 			}
| 670|    |-		}
|    | 670|+		
| 671| 671| 
| 672| 672| 		// If we've found a shoreline, stop searching
| 673| 673| 		if (count != numPoints-1)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 857| 857| 			let dxmax = size - dy;
| 858| 858| 			let ky = iy + dy;
| 859| 859| 			if (ky >= 0 && ky < w)
| 860|    |-			{
|    | 860|+			
| 861| 861| 				for (let dx = -dxmax; dx <= dxmax; ++dx)
| 862| 862| 				{
| 863| 863| 					let kx = ix + dx;
| 868| 868| 					total += weight * resourceMaps[k].map[kx + w * ky];
| 869| 869| 					nbcell += weight;
| 870| 870| 				}
| 871|    |-			}
|    | 871|+			
| 872| 872| 			if (dy == 0)
| 873| 873| 				continue;
| 874| 874| 			ky = iy - dy;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 873| 873| 				continue;
| 874| 874| 			ky = iy - dy;
| 875| 875| 			if (ky >= 0 && ky < w)
| 876|    |-			{
|    | 876|+			
| 877| 877| 				for (let dx = -dxmax; dx <= dxmax; ++dx)
| 878| 878| 				{
| 879| 879| 					let kx = ix + dx;
| 884| 884| 					total += weight * resourceMaps[k].map[kx + w * ky];
| 885| 885| 					nbcell += weight;
| 886| 886| 				}
| 887|    |-			}
|    | 887|+			
| 888| 888| 		}
| 889| 889| 	}
| 890| 890| 	return nbcell ? total / nbcell : 0;

binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 951| }(PETRA);
|    | [MAJOR] ESLintBear (no-use-before-define):
|    | 'PETRA' was used before it was defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|  69|  69| 	this.rallyPoint = rallyPoint;
|  70|  70| 	this.overseas = 0;
|  71|  71| 	if (gameState.ai.HQ.navalMap)
|  72|    |-	{
|    |  72|+	
|  73|  73| 		for (let structure of gameState.getEnemyStructures().values())
|  74|  74| 		{
|  75|  75| 			if (this.target && structure.id() != this.target.id())
| 101| 101| 				gameState.ai.HQ.navalManager.setMinimalTransportShips(gameState, sea, 1);
| 102| 102| 			}
| 103| 103| 		}
| 104|    |-	}
|    | 104|+	
| 105| 105| 	this.paused = false;
| 106| 106| 	this.maxCompletingTime = 0;
| 107| 107| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 399| 399| 	// the completing step is used to return resources and regroup the units
| 400| 400| 	// so we check that we have no more forced order before starting the attack
| 401| 401| 	if (this.state == "completing")
| 402|    |-	{
|    | 402|+	
| 403| 403| 		// if our target was destroyed, go back to "unexecuted" state
| 404| 404| 		if (this.targetPlayer === undefined || !this.target || !gameState.getEntityById(this.target.id()))
| 405| 405| 		{
| 416| 416| 				return 1;
| 417| 417| 			return 2;
| 418| 418| 		}
| 419|    |-	}
|    | 419|+	
| 420| 420| 
| 421| 421| 	if (this.Config.debug > 3 && gameState.ai.playedTurn % 50 === 0)
| 422| 422| 		this.debugAttack();
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 525| 525| 
| 526| 526| 	// Remove those units which were in a temporary bombing attack
| 527| 527| 	for (let unitIds of gameState.ai.HQ.attackManager.bombingAttacks.values())
| 528|    |-	{
|    | 528|+	
| 529| 529| 		for (let entId of unitIds.values())
| 530| 530| 		{
| 531| 531| 			let ent = gameState.getEntityById(entId);
| 534| 534| 			unitIds.delete(entId);
| 535| 535| 			ent.stopMoving();
| 536| 536| 		}
| 537|    |-	}
|    | 537|+	
| 538| 538| 
| 539| 539| 	let rallyPoint = this.rallyPoint;
| 540| 540| 	let rallyIndex = gameState.ai.accessibility.getAccessValue(rallyPoint);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 872| 872| 			targets.addEnt(ent);
| 873| 873| 	}
| 874| 874| 	else
| 875|    |-	{
|    | 875|+	
| 876| 876| 		if (this.type == "Raid")
| 877| 877| 			targets = this.raidTargetFinder(gameState);
| 878| 878| 		else if (this.type == "Rush" || this.type == "Attack")
| 883| 883| 		}
| 884| 884| 		else
| 885| 885| 			targets = this.defaultTargetFinder(gameState, this.targetPlayer);
| 886|    |-	}
|    | 886|+	
| 887| 887| 	if (!targets.hasEntities())
| 888| 888| 		return undefined;
| 889| 889| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1341|1341| 				}
|1342|1342| 			}
|1343|1343| 			else
|1344|    |-			{
|    |1344|+			
|1345|1345| 				if (this.isBlocked && !ourUnit.hasClass("Ranged") && attacker.hasClass("Ranged"))
|1346|1346| 				{
|1347|1347| 					// do not react if our melee units are attacked by ranged one and we are blocked by walls
|1394|1394| 					ourUnit.attack(attacker.id(), m.allowCapture(gameState, ourUnit, attacker));
|1395|1395| 					ourUnit.setMetadata(PlayerID, "lastAttackPlanUpdateTime", time);
|1396|1396| 				}
|1397|    |-			}
|    |1397|+			
|1398|1398| 		}
|1399|1399| 
|1400|1400| 		let enemyUnits = gameState.getEnemyUnits(this.targetPlayer);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1343|1343| 			else
|1344|1344| 			{
|1345|1345| 				if (this.isBlocked && !ourUnit.hasClass("Ranged") && attacker.hasClass("Ranged"))
|1346|    |-				{
|    |1346|+				
|1347|1347| 					// do not react if our melee units are attacked by ranged one and we are blocked by walls
|1348|1348| 					// TODO check that the attacker is from behind the wall
|1349|1349| 					continue;
|1350|    |-				}
|    |1350|+				
|1351|1351| 				else if (m.isSiegeUnit(attacker))
|1352|1352| 				{	// if our unit is attacked by a siege unit, we'll send some melee units to help it.
|1353|1353| 					let collec = this.unitCollection.filter(API3.Filters.byClass("Melee")).filterNearest(ourUnit.position(), 5);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1386|1386| 							continue;
|1387|1387| 						let target = gameState.getEntityById(orderData[0].target);
|1388|1388| 						if (target && !target.hasClass("Structure") && !target.hasClass("Support"))
|1389|    |-						{
|    |1389|+						
|1390|1390| 							if (!target.hasClass("Ranged") || !attacker.hasClass("Melee"))
|1391|1391| 								continue;
|1392|    |-						}
|    |1392|+						
|1393|1393| 					}
|1394|1394| 					ourUnit.attack(attacker.id(), m.allowCapture(gameState, ourUnit, attacker));
|1395|1395| 					ourUnit.setMetadata(PlayerID, "lastAttackPlanUpdateTime", time);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1414|1414| 			if (!target || target.hasClass("Structure"))
|1415|1415| 				continue;
|1416|1416| 			if (!(targetId in unitTargets))
|1417|    |-			{
|    |1417|+			
|1418|1418| 				if (m.isSiegeUnit(target) || target.hasClass("Hero"))
|1419|1419| 					unitTargets[targetId] = -8;
|1420|1420| 				else if (target.hasClass("Champion") || target.hasClass("Ship"))
|1421|1421| 					unitTargets[targetId] = -5;
|1422|1422| 				else
|1423|1423| 					unitTargets[targetId] = -3;
|1424|    |-			}
|    |1424|+			
|1425|1425| 			++unitTargets[targetId];
|1426|1426| 		}
|1427|1427| 		let veto = {};
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1434|1434| 		if (this.type == "Rush")
|1435|1435| 			targetClassesUnit = { "attack": ["Unit", "Structure"], "avoid": ["Palisade", "StoneWall", "Tower", "Fortress"], "vetoEntities": veto };
|1436|1436| 		else
|1437|    |-		{
|    |1437|+		
|1438|1438| 			if (this.target.hasClass("Fortress"))
|1439|1439| 				targetClassesUnit = { "attack": ["Unit", "Structure"], "avoid": ["Palisade", "StoneWall"], "vetoEntities": veto };
|1440|1440| 			else if (this.target.hasClass("Palisade") || this.target.hasClass("StoneWall"))
|1441|1441| 				targetClassesUnit = { "attack": ["Unit", "Structure"], "avoid": ["Fortress"], "vetoEntities": veto };
|1442|1442| 			else
|1443|1443| 				targetClassesUnit = { "attack": ["Unit", "Structure"], "avoid": ["Palisade", "StoneWall", "Fortress"], "vetoEntities": veto };
|1444|    |-		}
|    |1444|+		
|1445|1445| 		if (this.target.hasClass("Structure"))
|1446|1446| 			targetClassesSiege = { "attack": ["Structure"], "avoid": [], "vetoEntities": veto };
|1447|1447| 		else
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1525|1525| 			let range = 60;
|1526|1526| 			let attackTypes = ent.attackTypes();
|1527|1527| 			if (this.isBlocked)
|1528|    |-			{
|    |1528|+			
|1529|1529| 				if (attackTypes && attackTypes.indexOf("Ranged") !== -1)
|1530|1530| 					range = ent.attackRange("Ranged").max;
|1531|1531| 				else if (attackTypes && attackTypes.indexOf("Melee") !== -1)
|1532|1532| 					range = ent.attackRange("Melee").max;
|1533|1533| 				else
|1534|1534| 					range = 10;
|1535|    |-			}
|    |1535|+			
|1536|1536| 			else if (attackTypes && attackTypes.indexOf("Ranged") !== -1)
|1537|1537| 				range = 30 + ent.attackRange("Ranged").max;
|1538|1538| 			else if (ent.hasClass("Cavalry"))
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1581|1581| 					}
|1582|1582| 				}
|1583|1583| 				else
|1584|    |-				{
|    |1584|+				
|1585|1585| 					if (!ent.hasClass("Ranged"))
|1586|1586| 					{
|1587|1587| 						let targetClasses = { "attack": targetClassesSiege.attack, "avoid": targetClassesSiege.avoid.concat("Ship"), "vetoEntities": veto };
|1589|1589| 					}
|1590|1590| 					else
|1591|1591| 						ent.attackMove(this.targetPos[0], this.targetPos[1], targetClassesSiege);
|1592|    |-				}
|    |1592|+				
|1593|1593| 			}
|1594|1594| 			else
|1595|1595| 			{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1643|1643| 				{
|1644|1644| 					let targetClasses = targetClassesUnit;
|1645|1645| 					if (maybeUpdate && ent.unitAIState() === "INDIVIDUAL.COMBAT.APPROACHING")	// we may be blocked by walls, attack everything
|1646|    |-					{
|    |1646|+					
|1647|1647| 						if (!ent.hasClass("Ranged") && !ent.hasClass("Ship"))
|1648|1648| 							targetClasses = { "attack": ["Unit", "Structure"], "avoid": ["Ship"], "vetoEntities": veto };
|1649|1649| 						else
|1650|1650| 							targetClasses = { "attack": ["Unit", "Structure"], "vetoEntities": veto };
|1651|    |-					}
|    |1651|+					
|1652|1652| 					else if (!ent.hasClass("Ranged") && !ent.hasClass("Ship"))
|1653|1653| 						targetClasses = { "attack": targetClassesUnit.attack, "avoid": targetClassesUnit.avoid.concat("Ship"), "vetoEntities": veto };
|1654|1654| 					ent.attackMove(this.targetPos[0], this.targetPos[1], targetClasses);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1789|1789| 	}
|1790|1790| 	// Are we arrived at destination ?
|1791|1791| 	if (attackedNB > 1 && (attackedUnitNB || this.hasSiegeUnits()))
|1792|    |-	{
|    |1792|+	
|1793|1793| 		if (gameState.ai.HQ.territoryMap.getOwner(this.position) === this.targetPlayer || attackedNB > 3)
|1794|1794| 		{
|1795|1795| 			this.state = "arrived";
|1796|1796| 			return true;
|1797|1797| 		}
|1798|    |-	}
|    |1798|+	
|1799|1799| 
|1800|1800| 	// basically haven't moved an inch: very likely stuck)
|1801|1801| 	if (API3.SquareVectorDistance(this.position, this.position5TurnsAgo) < 10 && this.path.length > 0 && gameState.ai.playedTurn % 5 === 0)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1915|1915| 			// Check if we could help any current attack
|1916|1916| 			let attackManager = gameState.ai.HQ.attackManager;
|1917|1917| 			for (let attackType in attackManager.startedAttacks)
|1918|    |-			{
|    |1918|+			
|1919|1919| 				for (let attack of attackManager.startedAttacks[attackType])
|1920|1920| 				{
|1921|1921| 					if (attack.name == this.name)
|1934|1934| 					this.targetPos = this.target.position();
|1935|1935| 					return true;
|1936|1936| 				}
|1937|    |-			}
|    |1937|+			
|1938|1938| 
|1939|1939| 			// If not, let's look for another enemy
|1940|1940| 			if (!this.target)

binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|2167| }(PETRA);
|    | [MAJOR] ESLintBear (no-use-before-define):
|    | 'PETRA' was used before it was defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 209| 209| 	}
| 210| 210| 
| 211| 211| 	for (let evt of events.Destroy)
| 212|    |-	{
|    | 212|+	
| 213| 213| 		// Let's check we haven't lost an important building here.
| 214| 214| 		if (evt && !evt.SuccessfulFoundation && evt.entityObj && evt.metadata && evt.metadata[PlayerID] &&
| 215| 215| 			evt.metadata[PlayerID].base)
| 226| 226| 			if (evt.metadata[PlayerID].baseAnchor && evt.metadata[PlayerID].baseAnchor === true)
| 227| 227| 				base.anchorLost(gameState, ent);
| 228| 228| 		}
| 229|    |-	}
|    | 229|+	
| 230| 230| 
| 231| 231| 	for (let evt of events.EntityRenamed)
| 232| 232| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 255| 255| 			// Let's get a few units from other bases there to build this.
| 256| 256| 			let builders = this.bulkPickWorkers(gameState, newbase, 10);
| 257| 257| 			if (builders !== false)
| 258|    |-			{
|    | 258|+			
| 259| 259| 				builders.forEach(worker => {
| 260| 260| 					worker.setMetadata(PlayerID, "base", newbase.ID);
| 261| 261| 					worker.setMetadata(PlayerID, "subrole", "builder");
| 262| 262| 					worker.setMetadata(PlayerID, "target-foundation", ent.id());
| 263| 263| 				});
| 264|    |-			}
|    | 264|+			
| 265| 265| 		}
| 266| 266| 		else if (ent.getMetadata(PlayerID, "base") == -2)	// anchorless base around a dock
| 267| 267| 		{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 269| 269| 			// Let's get a few units from other bases there to build this.
| 270| 270| 			let builders = this.bulkPickWorkers(gameState, newbase, 4);
| 271| 271| 			if (builders != false)
| 272|    |-			{
|    | 272|+			
| 273| 273| 				builders.forEach(worker => {
| 274| 274| 					worker.setMetadata(PlayerID, "base", newbase.ID);
| 275| 275| 					worker.setMetadata(PlayerID, "subrole", "builder");
| 276| 276| 					worker.setMetadata(PlayerID, "target-foundation", ent.id());
| 277| 277| 				});
| 278|    |-			}
|    | 278|+			
| 279| 279| 		}
| 280| 280| 	}
| 281| 281| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 395| 395| 	}
| 396| 396| 
| 397| 397| 	for (let evt of events.TrainingFinished)
| 398|    |-	{
|    | 398|+	
| 399| 399| 		for (let entId of evt.entities)
| 400| 400| 		{
| 401| 401| 			let ent = gameState.getEntityById(entId);
| 463| 463| 					ent.moveToRange(goal[0], goal[1]);
| 464| 464| 			}
| 465| 465| 		}
| 466|    |-	}
|    | 466|+	
| 467| 467| 
| 468| 468| 	for (let evt of events.TerritoryDecayChanged)
| 469| 469| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 411| 411| 					this.garrisonManager.registerHolder(gameState, holder);
| 412| 412| 			}
| 413| 413| 			else if (ent.getMetadata(PlayerID, "garrisonType"))
| 414|    |-			{
|    | 414|+			
| 415| 415| 				// we were supposed to be autogarrisoned, but this has failed (may-be full)
| 416| 416| 				ent.setMetadata(PlayerID, "garrisonType", undefined);
| 417|    |-			}
|    | 417|+			
| 418| 418| 
| 419| 419| 			// Check if this unit is no more needed in its attack plan
| 420| 420| 			// (happen when the training ends after the attack is started or aborted)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 482| 482| 	}
| 483| 483| 
| 484| 484| 	if (addBase)
| 485|    |-	{
|    | 485|+	
| 486| 486| 		if (!this.firstBaseConfig)
| 487| 487| 		{
| 488| 488| 			// This is our first base, let us configure our starting resources
| 495| 495| 			this.saveSpace = undefined;
| 496| 496| 			this.maxFields = false;
| 497| 497| 		}
| 498|    |-	}
|    | 498|+	
| 499| 499| 
| 500| 500| 	// Then deals with decaying structures: destroy them if being lost to enemy (except in easier difficulties)
| 501| 501| 	if (this.Config.difficulty < 2)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 484| 484| 	if (addBase)
| 485| 485| 	{
| 486| 486| 		if (!this.firstBaseConfig)
| 487|    |-		{
|    | 487|+		
| 488| 488| 			// This is our first base, let us configure our starting resources
| 489| 489| 			this.configFirstBase(gameState);
| 490|    |-		}
|    | 490|+		
| 491| 491| 		else
| 492| 492| 		{
| 493| 493| 			// Let us hope this new base will fix our possible resource shortage
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 773| 773| 		let aValue = 0.1;
| 774| 774| 		let bValue = 0.1;
| 775| 775| 		for (let param of parameters)
| 776|    |-		{
|    | 776|+		
| 777| 777| 			if (param[0] == "strength")
| 778| 778| 			{
| 779| 779| 				aValue += m.getMaxStrength(a[1]) * param[1];
| 807| 807| 			}
| 808| 808| 			else
| 809| 809| 				API3.warn(" trainMoreUnits avec non prevu " + uneval(param));
| 810|    |-		}
|    | 810|+		
| 811| 811| 		return -aValue/aCost + bValue/bCost;
| 812| 812| 	});
| 813| 813| 	return units[0][0];
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1051|1051| 				continue;
|1052|1052| 
|1053|1053| 			if (minDist > maxAccessDisfavored)     // Disfavor if quite far from any allied cc
|1054|    |-			{
|    |1054|+			
|1055|1055| 				if (!accessible)
|1056|1056| 				{
|1057|1057| 					if (minDist > maxNoAccessDisfavored)
|1061|1061| 				}
|1062|1062| 				else
|1063|1063| 					norm *= 0.5;
|1064|    |-			}
|    |1064|+			
|1065|1065| 
|1066|1066| 			// Not near any of our dropsite, except for oversea docks
|1067|1067| 			oversea = !accessible && dpList.some(dp => m.getLandAccess(gameState, dp.ent) == index);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1053|1053| 			if (minDist > maxAccessDisfavored)     // Disfavor if quite far from any allied cc
|1054|1054| 			{
|1055|1055| 				if (!accessible)
|1056|    |-				{
|    |1056|+				
|1057|1057| 					if (minDist > maxNoAccessDisfavored)
|1058|1058| 						norm *= 0.5;
|1059|1059| 					else
|1060|1060| 						norm *= 0.8;
|1061|    |-				}
|    |1061|+				
|1062|1062| 				else
|1063|1063| 					norm *= 0.5;
|1064|1064| 			}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1066|1066| 			// Not near any of our dropsite, except for oversea docks
|1067|1067| 			oversea = !accessible && dpList.some(dp => m.getLandAccess(gameState, dp.ent) == index);
|1068|1068| 			if (!oversea)
|1069|    |-			{
|    |1069|+			
|1070|1070| 				for (let dp of dpList)
|1071|1071| 				{
|1072|1072| 					let dist = API3.SquareVectorDistance(dp.pos, pos);
|1078|1078| 					else if (dist < 6400)
|1079|1079| 						norm *= 0.5;
|1080|1080| 				}
|1081|    |-			}
|    |1081|+			
|1082|1082| 			if (norm == 0)
|1083|1083| 				continue;
|1084|1084| 		}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1378|1378| 	// do not keep it if gain is too small, except if this is our first BarterMarket
|1379|1379| 	let idx;
|1380|1380| 	if (expectedGain < this.tradeManager.minimalGain)
|1381|    |-	{
|    |1381|+	
|1382|1382| 		if (template.hasClass("BarterMarket") &&
|1383|1383| 		    !gameState.getOwnEntitiesByClass("BarterMarket", true).hasEntities())
|1384|1384| 			idx = -1;	// needed by queueplanBuilding manager to keep that market
|1385|1385| 		else
|1386|1386| 			return false;
|1387|    |-	}
|    |1387|+	
|1388|1388| 	else
|1389|1389| 		idx = this.basesMap.map[bestJdx];
|1390|1390| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1565|1565| 			let cost = queues.economicBuilding.plans[0].getCost();
|1566|1566| 			queueManager.setAccounts(gameState, cost, "economicBuilding");
|1567|1567| 			if (!queueManager.canAfford("economicBuilding", cost))
|1568|    |-			{
|    |1568|+			
|1569|1569| 				for (let q in queueManager.queues)
|1570|1570| 				{
|1571|1571| 					if (q == "economicBuilding")
|1574|1574| 					if (queueManager.canAfford("economicBuilding", cost))
|1575|1575| 						break;
|1576|1576| 				}
|1577|    |-			}
|    |1577|+			
|1578|1578| 		}
|1579|1579| 		return;
|1580|1580| 	}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1624|1624| 		let highLevel = 0;
|1625|1625| 		let lowLevel = 0;
|1626|1626| 		for (let res in cost)
|1627|    |-		{
|    |1627|+		
|1628|1628| 			if (resources[res] && resources[res] > 0.7 * cost[res])
|1629|1629| 				++highLevel;
|1630|1630| 			else if (!resources[res] || resources[res] < 0.3 * cost[res])
|1631|1631| 				++lowLevel;
|1632|    |-		}
|    |1632|+		
|1633|1633| 		if (highLevel == 0 || lowLevel > 1)
|1634|1634| 			return;
|1635|1635| 	}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1750|1750| 	let freeSlots = gameState.getPopulationLimit() + HouseNb*popBonus - this.getAccountedPopulation(gameState);
|1751|1751| 	let priority;
|1752|1752| 	if (freeSlots < 5)
|1753|    |-	{
|    |1753|+	
|1754|1754| 		if (this.buildManager.isUnbuildable(gameState, house))
|1755|1755| 		{
|1756|1756| 			if (this.Config.debug > 1)
|1759|1759| 		}
|1760|1760| 		else
|1761|1761| 			priority = 2*this.Config.priorities.house;
|1762|    |-	}
|    |1762|+	
|1763|1763| 	else
|1764|1764| 		priority = this.Config.priorities.house;
|1765|1765| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1841|1841| 		return;
|1842|1842| 
|1843|1843| 	if (!this.saveResources && (this.currentPhase > 2 || gameState.isResearching(gameState.getPhaseName(3))))
|1844|    |-	{
|    |1844|+	
|1845|1845| 		// try to build fortresses
|1846|1846| 		if (this.canBuild(gameState, "structures/{civ}_fortress"))
|1847|1847| 		{
|1860|1860| 				return;
|1861|1861| 			}
|1862|1862| 		}
|1863|    |-	}
|    |1863|+	
|1864|1864| 
|1865|1865| 	if (this.Config.Military.numSentryTowers && this.currentPhase < 2 && this.canBuild(gameState, "structures/{civ}_sentry_tower"))
|1866|1866| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2004|2004| 		nAdvanced += gameState.countEntitiesAndQueuedByType(advanced, true);
|2005|2005| 
|2006|2006| 	if (!nAdvanced || nAdvanced < this.bAdvanced.length && this.getAccountedPopulation(gameState) > 110)
|2007|    |-	{
|    |2007|+	
|2008|2008| 		for (let advanced of this.bAdvanced)
|2009|2009| 		{
|2010|2010| 			if (gameState.countEntitiesAndQueuedByType(advanced, true) > 0 || !this.canBuild(gameState, advanced))
|2019|2019| 				queues.militaryBuilding.addPlan(new m.ConstructionPlan(gameState, advanced));
|2020|2020| 			return;
|2021|2021| 		}
|2022|    |-	}
|    |2022|+	
|2023|2023| };
|2024|2024| 
|2025|2025| /**
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2107|2107| 	// in which case we prefer melee units
|2108|2108| 	let numGarrisoned = this.garrisonManager.numberOfGarrisonedUnits(nearestAnchor);
|2109|2109| 	if (nearestAnchor._entity.trainingQueue)
|2110|    |-	{
|    |2110|+	
|2111|2111| 		for (let item of nearestAnchor._entity.trainingQueue)
|2112|2112| 		{
|2113|2113| 			if (item.metadata && item.metadata.garrisonType)
|2115|2115| 			else if (!item.progress && (!item.metadata || !item.metadata.trainer))
|2116|2116| 				nearestAnchor.stopProduction(item.id);
|2117|2117| 		}
|2118|    |-	}
|    |2118|+	
|2119|2119| 	let autogarrison = numGarrisoned < nearestAnchor.garrisonMax() &&
|2120|2120| 	                   nearestAnchor.hitpoints() > nearestAnchor.garrisonEjectHealth() * nearestAnchor.maxHitpoints();
|2121|2121| 	let rangedWanted = randBool() && autogarrison;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2109|2109| 	if (nearestAnchor._entity.trainingQueue)
|2110|2110| 	{
|2111|2111| 		for (let item of nearestAnchor._entity.trainingQueue)
|2112|    |-		{
|    |2112|+		
|2113|2113| 			if (item.metadata && item.metadata.garrisonType)
|2114|2114| 				numGarrisoned += item.count;
|2115|2115| 			else if (!item.progress && (!item.metadata || !item.metadata.trainer))
|2116|2116| 				nearestAnchor.stopProduction(item.id);
|2117|    |-		}
|    |2117|+		
|2118|2118| 	}
|2119|2119| 	let autogarrison = numGarrisoned < nearestAnchor.garrisonMax() &&
|2120|2120| 	                   nearestAnchor.hitpoints() > nearestAnchor.garrisonEjectHealth() * nearestAnchor.maxHitpoints();
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2149|2149| 	let cost = new API3.Resources(templateFound[1].cost());
|2150|2150| 	queueManager.setAccounts(gameState, cost, "emergency");
|2151|2151| 	if (!queueManager.canAfford("emergency", cost))
|2152|    |-	{
|    |2152|+	
|2153|2153| 		for (let q in queueManager.queues)
|2154|2154| 		{
|2155|2155| 			if (q == "emergency")
|2158|2158| 			if (queueManager.canAfford("emergency", cost))
|2159|2159| 				break;
|2160|2160| 		}
|2161|    |-	}
|    |2161|+	
|2162|2162| 	let metadata = { "role": "worker", "base": nearestAnchor.getMetadata(PlayerID, "base"), "plan": -1, "trainer": nearestAnchor.id() };
|2163|2163| 	if (autogarrison)
|2164|2164| 		metadata.garrisonType = "protection";
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2439|2439| m.HQ.prototype.assignGatherers = function()
|2440|2440| {
|2441|2441| 	for (let base of this.baseManagers)
|2442|    |-	{
|    |2442|+	
|2443|2443| 		for (let worker of base.workers.values())
|2444|2444| 		{
|2445|2445| 			if (worker.unitAIState().split(".")[1] != "RETURNRESOURCE")
|2449|2449| 				continue;
|2450|2450| 			this.AddTCGatherer(orders[1].target);
|2451|2451| 		}
|2452|    |-	}
|    |2452|+	
|2453|2453| };
|2454|2454| 
|2455|2455| m.HQ.prototype.isDangerousLocation = function(gameState, pos, radius)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2621|2621| 	{
|2622|2622| 		let pop = gameState.getPopulation();
|2623|2623| 		for (let ent of gameState.getOwnTrainingFacilities().values())
|2624|    |-		{
|    |2624|+		
|2625|2625| 			for (let item of ent.trainingQueue())
|2626|2626| 			{
|2627|2627| 				if (!item.unitTemplate)
|2630|2630| 				if (unitPop)
|2631|2631| 					pop += item.count * unitPop;
|2632|2632| 			}
|2633|    |-		}
|    |2633|+		
|2634|2634| 		this.turnCache.accountedPopulation = pop;
|2635|2635| 	}
|2636|2636| 	return this.turnCache.accountedPopulation;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2645|2645| 	{
|2646|2646| 		let workers = gameState.getOwnEntitiesByRole("worker", true).length;
|2647|2647| 		for (let ent of gameState.getOwnTrainingFacilities().values())
|2648|    |-		{
|    |2648|+		
|2649|2649| 			for (let item of ent.trainingQueue())
|2650|2650| 			{
|2651|2651| 				if (!item.metadata || !item.metadata.role || item.metadata.role != "worker")
|2652|2652| 					continue;
|2653|2653| 				workers += item.count;
|2654|2654| 			}
|2655|    |-		}
|    |2655|+		
|2656|2656| 		this.turnCache.accountedWorkers = workers;
|2657|2657| 	}
|2658|2658| 	return this.turnCache.accountedWorkers;

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2898| }(PETRA);
|    | [MAJOR] ESLintBear (no-use-before-define):
|    | 'PETRA' was used before it was defined.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 524| »   »   »   let·ratioMax·=·0.70·+·randFloat(0.,·0.1);
|    | [NORMAL] JSHintBear:
|    | A trailing decimal point can be confused with a dot: '0.'.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 529| »   »   »   »   ratioMax·=·0.85·+·randFloat(0.,·0.1);
|    | [NORMAL] JSHintBear:
|    | A trailing decimal point can be confused with a dot: '0.'.

binaries/data/mods/public/simulation/ai/petra/config.js
| 257| }(PETRA);
|    | [MAJOR] ESLintBear (no-use-before-define):
|    | 'PETRA' was used before it was defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/mapModule.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/mapModule.js
|  62|  62| 				continue;
|  63|  63| 		}
|  64|  64| 		else
|  65|    |-		{
|    |  65|+		
|  66|  66| 			if (!buildEnemy)
|  67|  67| 				continue;
|  68|    |-		}
|    |  68|+		
|  69|  69| 
|  70|  70| 		let x = ratio * (k % territoryMap.width);
|  71|  71| 		let y = ratio * Math.floor(k / territoryMap.width);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/mapModule.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/mapModule.js
|  70|  70| 		let x = ratio * (k % territoryMap.width);
|  71|  71| 		let y = ratio * Math.floor(k / territoryMap.width);
|  72|  72| 		for (let ix = 0; ix < ratio; ++ix)
|  73|    |-		{
|    |  73|+		
|  74|  74| 			for (let iy = 0; iy < ratio; ++iy)
|  75|  75| 			{
|  76|  76| 				let i = x + ix + (y + iy)*passabilityMap.width;
|  79|  79| 				if (!(passabilityMap.data[i] & obstructionMask))
|  80|  80| 					obstructionTiles[i] = 255;
|  81|  81| 			}
|  82|    |-		}
|    |  82|+		
|  83|  83| 	}
|  84|  84| 
|  85|  85| 	let map = new API3.Map(gameState.sharedScript, "passability", obstructionTiles);

binaries/data/mods/public/simulation/ai/petra/mapModule.js
| 221| }(PETRA);
|    | [MAJOR] ESLintBear (no-use-before-define):
|    | 'PETRA' was used before it was defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
| 385| 385| {
| 386| 386| 	// copy over all parameters.
| 387| 387| 	for (let i in otherArmy.assignedAgainst)
| 388|    |-	{
|    | 388|+	
| 389| 389| 		if (this.assignedAgainst[i] === undefined)
| 390| 390| 			this.assignedAgainst[i] = otherArmy.assignedAgainst[i];
| 391| 391| 		else
| 392| 392| 			this.assignedAgainst[i] = this.assignedAgainst[i].concat(otherArmy.assignedAgainst[i]);
| 393|    |-	}
|    | 393|+	
| 394| 394| 	for (let i in otherArmy.assignedTo)
| 395| 395| 		this.assignedTo[i] = otherArmy.assignedTo[i];
| 396| 396| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
| 481| 481| 
| 482| 482| 	let entStrength;
| 483| 483| 	if (ent.hasClass("Structure"))
| 484|    |-	{
|    | 484|+	
| 485| 485| 		if (ent.owner() !== PlayerID)
| 486| 486| 			entStrength = ent.getDefaultArrow() ? 6*ent.getDefaultArrow() : 4;
| 487| 487| 		else	// small strength used only when we try to recover capture points
| 488| 488| 			entStrength = 2;
| 489|    |-	}
|    | 489|+	
| 490| 490| 	else
| 491| 491| 		entStrength = m.getMaxStrength(ent);
| 492| 492| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
| 510| 510| 	// otherwise it would remove the old entity from this army list
| 511| 511| 	// TODO we should may-be reevaluate the strength
| 512| 512| 	for (let evt of events.EntityRenamed)	// take care of promoted and packed units
| 513|    |-	{
|    | 513|+	
| 514| 514| 		if (this.foeEntities.indexOf(evt.entity) !== -1)
| 515| 515| 		{
| 516| 516| 			let ent = gameState.getEntityById(evt.newentity);
| 538| 538| 					this.assignedAgainst[against][this.assignedAgainst[against].indexOf(evt.entity)] = evt.newentity;
| 539| 539| 			}
| 540| 540| 		}
| 541|    |-	}
|    | 541|+	
| 542| 542| 
| 543| 543| 	for (let evt of events.Garrison)
| 544| 544| 		this.removeFoe(gameState, evt.entity);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
| 544| 544| 		this.removeFoe(gameState, evt.entity);
| 545| 545| 
| 546| 546| 	for (let evt of events.OwnershipChanged)	// captured
| 547|    |-	{
|    | 547|+	
| 548| 548| 		if (!gameState.isPlayerEnemy(evt.to))
| 549| 549| 			this.removeFoe(gameState, evt.entity);
| 550| 550| 		else if (evt.from === PlayerID)
| 551| 551| 			this.removeOwn(gameState, evt.entity);
| 552|    |-	}
|    | 552|+	
| 553| 553| 
| 554| 554| 	for (let evt of events.Destroy)
| 555| 555| 	{

binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
| 651| }(PETRA);
|    | [MAJOR] ESLintBear (no-use-before-define):
|    | 'PETRA' was used before it was defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/baseManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/baseManager.js
| 181| 181| 
| 182| 182| 			let dist = API3.SquareVectorDistance(supply.position(), dropsitePos);
| 183| 183| 			if (dist < maxDistResourceSquare)
| 184|    |-			{
|    | 184|+			
| 185| 185| 				if (dist < maxDistResourceSquare/16)        // distmax/4
| 186| 186| 					nearby.push({ "dropsite": dropsiteId, "id": supply.id(), "ent": supply, "dist": dist });
| 187| 187| 				else if (dist < maxDistResourceSquare/4)    // distmax/2
| 188| 188| 					medium.push({ "dropsite": dropsiteId, "id": supply.id(), "ent": supply, "dist": dist });
| 189| 189| 				else
| 190| 190| 					faraway.push({ "dropsite": dropsiteId, "id": supply.id(), "ent": supply, "dist": dist });
| 191|    |-			}
|    | 191|+			
| 192| 192| 		});
| 193| 193| 
| 194| 194| 		nearby.sort((r1, r2) => r1.dist - r2.dist);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/baseManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/baseManager.js
| 229| 229| 
| 230| 230| 	let removeSupply = function(entId, supply){
| 231| 231| 		for (let i = 0; i < supply.length; ++i)
| 232|    |-		{
|    | 232|+		
| 233| 233| 			// exhausted resource, remove it from this list
| 234| 234| 			if (!supply[i].ent || !gameState.getEntityById(supply[i].id))
| 235| 235| 				supply.splice(i--, 1);
| 236| 236| 			// resource assigned to the removed dropsite, remove it
| 237| 237| 			else if (supply[i].dropsite == entId)
| 238| 238| 				supply.splice(i--, 1);
| 239|    |-		}
|    | 239|+		
| 240| 240| 	};
| 241| 241| 
| 242| 242| 	for (let type in this.dropsiteSupplies)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/baseManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/baseManager.js
| 432| 432| 		if (gameState.ai.playedTurn < this.gatherers[type].nextCheck)
| 433| 433| 			continue;
| 434| 434| 		for (let ent of this.gatherersByType(gameState, type).values())
| 435|    |-		{
|    | 435|+		
| 436| 436| 			if (ent.unitAIState() == "INDIVIDUAL.GATHER.GATHERING")
| 437| 437| 				++this.gatherers[type].used;
| 438| 438| 			else if (ent.unitAIState() == "INDIVIDUAL.RETURNRESOURCE.APPROACHING")
| 439| 439| 				++this.gatherers[type].lost;
| 440|    |-		}
|    | 440|+		
| 441| 441| 		// TODO  add also a test on remaining resources.
| 442| 442| 		let total = this.gatherers[type].used + this.gatherers[type].lost;
| 443| 443| 		if (total > 150 || total > 60 && type != "wood")
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/baseManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/baseManager.js
| 449| 449| 				if (newDP.quality > 50 && gameState.ai.HQ.canBuild(gameState, "structures/{civ}_storehouse"))
| 450| 450| 					queues.dropsites.addPlan(new m.ConstructionPlan(gameState, "structures/{civ}_storehouse", { "base": this.ID, "type": type }, newDP.pos));
| 451| 451| 				else if (!gameState.getOwnFoundations().filter(API3.Filters.byClass("CivCentre")).hasEntities() && !queues.civilCentre.hasQueuedUnits())
| 452|    |-				{
|    | 452|+				
| 453| 453| 					// No good dropsite, try to build a new base if no base already planned,
| 454| 454| 					// and if not possible, be less strict on dropsite quality.
| 455| 455| 					if ((!gameState.ai.HQ.canExpand || !gameState.ai.HQ.buildNewBase(gameState, queues, type)) &&
| 456| 456| 					    newDP.quality > Math.min(25, 50*0.15/ratio) &&
| 457| 457| 					    gameState.ai.HQ.canBuild(gameState, "structures/{civ}_storehouse"))
| 458| 458| 						queues.dropsites.addPlan(new m.ConstructionPlan(gameState, "structures/{civ}_storehouse", { "base": this.ID, "type": type }, newDP.pos));
| 459|    |-				}
|    | 459|+				
| 460| 460| 			}
| 461| 461| 			this.gatherers[type].nextCheck = gameState.ai.playedTurn + 20;
| 462| 462| 			this.gatherers[type].used = 0;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/baseManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/baseManager.js
| 512| 512| 		roleless = this.units.filter(API3.Filters.not(API3.Filters.byHasMetadata(PlayerID, "role"))).values();
| 513| 513| 
| 514| 514| 	for (let ent of roleless)
| 515|    |-	{
|    | 515|+	
| 516| 516| 		if (ent.hasClass("Worker") || ent.hasClass("CitizenSoldier") || ent.hasClass("FishingBoat"))
| 517| 517| 			ent.setMetadata(PlayerID, "role", "worker");
| 518| 518| 		else if (ent.hasClass("Support") && ent.hasClass("Elephant"))
| 519| 519| 			ent.setMetadata(PlayerID, "role", "worker");
| 520|    |-	}
|    | 520|+	
| 521| 521| };
| 522| 522| 
| 523| 523| /**
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/baseManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/baseManager.js
| 768| 768| 	let availableResources = gameState.ai.queueManager.getAvailableResources(gameState);
| 769| 769| 	let builderRatio = 1;
| 770| 770| 	for (let res of Resources.GetCodes())
| 771|    |-	{
|    | 771|+	
| 772| 772| 		if (availableResources[res] < 200)
| 773| 773| 		{
| 774| 774| 			builderRatio = 0.2;
| 776| 776| 		}
| 777| 777| 		else if (availableResources[res] < 1000)
| 778| 778| 			builderRatio = Math.min(builderRatio, availableResources[res] / 1000);
| 779|    |-	}
|    | 779|+	
| 780| 780| 
| 781| 781| 	for (let target of foundations.values())
| 782| 782| 	{

binaries/data/mods/public/simulation/ai/petra/baseManager.js
|1113| }(PETRA);
|    | [MAJOR] ESLintBear (no-use-before-define):
|    | 'PETRA' was used before it was defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
| 119| 119| 			continue;
| 120| 120| 		ent.setMetadata(PlayerID, "onBoard", ship.id());
| 121| 121| 		if (this.debug > 1)
| 122|    |-		{
|    | 122|+		
| 123| 123| 			if (ent.getMetadata(PlayerID, "role") == "attack")
| 124| 124| 				Engine.PostCommand(PlayerID, { "type": "set-shading-color", "entities": [ent.id()], "rgb": [2, 0, 0] });
| 125| 125| 			else
| 126| 126| 				Engine.PostCommand(PlayerID, { "type": "set-shading-color", "entities": [ent.id()], "rgb": [0, 2, 0] });
| 127|    |-		}
|    | 127|+		
| 128| 128| 		return;
| 129| 129| 	}
| 130| 130| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
| 299| 299| 	let shipTested = {};
| 300| 300| 
| 301| 301| 	for (let ent of this.units.values())
| 302|    |-	{
|    | 302|+	
| 303| 303| 		if (!ent.getMetadata(PlayerID, "onBoard"))
| 304| 304| 		{
| 305| 305| 			ready = false;
| 408| 408| 				ent.setMetadata(PlayerID, "posGarrison", ent.position());
| 409| 409| 			}
| 410| 410| 		}
| 411|    |-	}
|    | 411|+	
| 412| 412| 
| 413| 413| 	if (this.needSplit)
| 414| 414| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
| 557| 557| 		{
| 558| 558| 			let ship = gameState.getEntityById(ent.getMetadata(PlayerID, "onBoard"));
| 559| 559| 			if (ship)
| 560|    |-			{
|    | 560|+			
| 561| 561| 				if (ship.garrisoned().indexOf(entId) != -1)
| 562| 562| 					ent.setMetadata(PlayerID, "onBoard", "onBoard");
| 563| 563| 				else
| 566| 566| 					this.resetUnit(gameState, ent);
| 567| 567| 					ent.destroy();
| 568| 568| 				}
| 569|    |-			}
|    | 569|+			
| 570| 570| 			else
| 571| 571| 			{
| 572| 572| 				API3.warn("Petra transportPlan problem: unit on ship, but no ship ???");

binaries/data/mods/public/simulation/ai/petra/transportPlan.js
| 729| }(PETRA);
|    | [MAJOR] ESLintBear (no-use-before-define):
|    | 'PETRA' was used before it was defined.
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/differential/1756/display/redirect

Krinkle added a reviewer: Restricted Owners Package.Jun 19 2019, 6:03 PM

Hoping to see this land relatively soon to avoid merge conflicts, after that I'll move on to the next area to lint :)

Stan added a subscriber: Stan.Jun 19 2019, 6:20 PM

Hoping to see this land relatively soon to avoid merge conflicts, after that I'll move on to the next area to lint :)

Those are famous last words :)

Before this get committed you might as well want to fix the warnings that appeared in the Vulkan console.

Polakrity added inline comments.
binaries/data/mods/public/simulation/ai/petra/attackPlan.js
1144

can be merged

Krinkle marked an inline comment as done.Jun 19 2019, 8:55 PM
Krinkle added inline comments.
binaries/data/mods/public/simulation/ai/petra/attackPlan.js
1144

I prefer not to do refactoring in the same commit as lint clean up, which is going to be hundreds of files that should be trivial to review and that ESLint can statically confirm for you does not change the execution of the code in any way (thus zero risk, except for bugs in SpiderMonkey parsing code in non-standard way which is not impossible but unlikely).

I'm definitely interested in looking at Petra code more after this is done though, and a bunch of clean ups like this. I enjoy doing that :) But that also takes more time to analyse to make sure it really is redundant and I don't know the code well enough yet for that.

Krinkle marked an inline comment as done.EditedJun 19 2019, 8:57 PM
In D1993#83293, @Stan wrote:

Before this get committed you might as well want to fix the warnings that appeared in the Vulkan console.

The only remaining one should be for curly. Due to there being almost 50/50 adherence to that, I wasn't sure whether it is a style we still want to follow consistently or whether it might be something we want to disable and allow developer to choose on case-by-case basis whether curly braces are useful.

Personally, I think the added value of avoiding accidental extension of a conditional block (e.g. adding a second line below it) without curly braces is worth it. But, I don't want to push my own style :)


PS: I see there is ESLintBear (no-use-before-define): as well. This warns about the strange structure all petra JS files use - var PETRA = function(m){…}(PETRA);.

Changing that is something I would like to do because the pattern seems unusual in the JS world, and something that seems to actually be non-standard.

It is broken in isolation:

var XYZ = function (m) { console.log('my m', m); }(XYZ);
// Actual  > my m, undefined
// Expected> my m, Function

The reason it works is because somewhere before the first one of these files is executed, there is something that defines PETRA in a way that is not broken.

And, thanks to JavaScript, tolerating "redundant" var statements, the later assignments are mostly ignored. They are not passing the new PETRA, but the previous one.

Currently
var XYZ = 42;

// ------- ai/petra/*.js

var XYZ = function (m) { console.log('my m', m); }(XYZ);
// Actual  > my m, 42
// Expected> my m, Function

We can keep this pattern by removing the redundant var PETRA = part of it, and adding PETRA to an ESLint whitelist of known global variables. If that is an acceptable change to the structure of many files, I could do that as its own change. But, that is no longer a style-only change, though.

Proposed
var XYZ = 42;

// ------- eslintrc

/*global PETRA */

// -------  ai/petra/*.js

function (m) { console.log('my m', m); }(XYZ);
// Actual> my m, 42
Stan added a subscriber: wraitii.Jun 19 2019, 9:38 PM
In D1993#83293, @Stan wrote:

Before this get committed you might as well want to fix the warnings that appeared in the Vulkan console.

The only remaining one should be for curly. Due to there being almost 50/50 adherence to that, I wasn't sure whether it is a style we still want to follow consistently or whether it might be something we want to disable and allow developer to choose on case-by-case basis whether curly braces are useful.

The CC should state that, if they don't they should be updated.

if (condition)
    DoStuff();

if (condition)
{
    DoStuff();
    DoOtherStuff();
}

for (looping condition)
{
    if (condition)
    {
        DoStuff();
        DoOtherStuff();
    }
}

for (looping condition)
    if (condition)
        DoStuff();

for (looping condition)
{
    if (condition)
        DoStuff();
    DoOtherStuff();
}

Personally, I think the added value of avoiding accidental extension of a conditional block (e.g. adding a second line below it) without curly braces is worth it. But, I don't want to push my own style :)

PS: I see there is ESLintBear (no-use-before-define): as well. This warns about the strange structure all petra JS files use - var PETRA = function(m){…}(PETRA);.
Changing that is something I would like to do because the pattern seems unusual in the JS world, and something that seems to actually be non-standard.
It is broken in isolation:

var XYZ = function (m) { console.log('my m', m); }(XYZ);
// Actual > my m, undefined
// Expected> my m, Function

The reason it works is because somewhere before the first one of these files is executed, there is something that defines PETRA in a way that is not broken.
And, thanks to JavaScript, tolerating "redundant" var statements, the later assignments are mostly ignored. They are not passing the new PETRA, but the previous one.
We can keep this pattern by removing the redundant var PETRA = part of it, and adding PETRA to an ESLint whitelist of known global variables. If that is an acceptable change to the structure of many files, I could do that as its own change. But, that is no longer a style-only change, though.

I agree that it would be nice to have standard OOP prototypes, but @wraitii knows more about why it's done that way than I.

binaries/data/mods/public/simulation/ai/petra/attackPlan.js
1144

Also I don't think it can be merged.

Krinkle updated this revision to Diff 8564.Jun 19 2019, 11:06 PM
Krinkle edited the summary of this revision. (Show Details)
Krinkle edited the test plan for this revision. (Show Details)
  • Used eslint --fix to automatically fix the curly warnings as well per the 0AD coding conventions.
  • Implemented the proposal for making the PETRA module files to use a slightly simpler structure. The previous structure had some extra indirection with variable overrides that didn't actually work (as ESLint correctly flagged), and turned out to be redundant anyhow.

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

Linter detected issues:
Executing section Source...
Executing section JS...

binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 524| »   »   »   let·ratioMax·=·0.70·+·randFloat(0.,·0.1);
|    | [NORMAL] JSHintBear:
|    | A trailing decimal point can be confused with a dot: '0.'.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 529| »   »   »   »   ratioMax·=·0.85·+·randFloat(0.,·0.1);
|    | [NORMAL] JSHintBear:
|    | A trailing decimal point can be confused with a dot: '0.'.
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/differential/1786/display/redirect

Stan added a comment.Jun 19 2019, 11:18 PM

The auto fix failed I guess.

binaries/data/mods/public/simulation/ai/petra/_petrabot.js
37 ↗(On Diff #8564)

Mmm that failed here, it should have braces, (cause the ones below do)

binaries/data/mods/public/simulation/ai/petra/attackManager.js
65 ↗(On Diff #8564)

Here as well.

Krinkle added inline comments.Jun 19 2019, 11:28 PM
binaries/data/mods/public/simulation/ai/petra/_petrabot.js
37 ↗(On Diff #8564)

That isn't how JavaScript works. It works fine without the brace, and ESLint would warn if I add it back, because the eslintrc file in the repository says that curly brace should be omitted when they are redundant according to the JavaScript syntax. And they are redundant here (they are redundant whenever they contain only a single statement or block).

But, do you mean that our preferred style is to include redundant branches if there is at least one block being wrapped that has braces? I wasn't able to infer that from your examples, and it do not see it mentioned at Code conventions.

ESLint also does not support such a writing style (see eslint options). Which means we would have to turn the rule off and do it by hand always.

Stan added a comment.Jun 20 2019, 12:06 AM

Maybe you can fix the last two warning (trailing dots)

binaries/data/mods/public/simulation/ai/petra/_petrabot.js
37 ↗(On Diff #8564)

But, do you mean that our preferred style is to include redundant branches if there is at least one block being wrapped that has braces? I wasn't able to infer that from your examples, and it do not see it mentioned at Code conventions.

Yes that's what I meant, and that is indeed an issue if it isn't supported. Maybe @wraitii will have more input than me on this.

In D1993#83352, @Stan wrote:

Maybe you can fix the last two warning (trailing dots)

Sure thing. Didn't see them locally as they're from the older JSHint config still. I'll see if I can migrate those to an ESLint rule in a separate commit, but will fix for now. Thanks!

Krinkle updated this revision to Diff 8566.Jun 20 2019, 12:58 AM
Krinkle edited the summary of this revision. (Show Details)

Fixed the two remaining JSHint warnings as well.

Krinkle retitled this revision from petra: Fix up most eslint warnings to petra: Fix all ESLint and JSHint warnings.Jun 20 2019, 1:14 AM
Krinkle planned changes to this revision.Jul 15 2019, 4:46 AM

I'll redo this diff on top of D2070 locally. In particular, it'll mean it won't try to "improve" around curly braces.

Krinkle edited the summary of this revision. (Show Details)Jul 15 2019, 6:30 PM
Krinkle edited the test plan for this revision. (Show Details)
Krinkle updated this revision to Diff 8912.Jul 15 2019, 6:38 PM
Krinkle edited the summary of this revision. (Show Details)

Now depends on D2070.

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 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/researchManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/researchManager.js
|  99|  99| 				continue;
| 100| 100| 		}
| 101| 101| 		for (let i in template.modifications)
| 102|    |-		{
|    | 102|+		
| 103| 103| 			if (gameState.ai.HQ.navalMap && template.modifications[i].value === "ResourceGatherer/Rates/food.fish")
| 104| 104| 				return { "name": tech[0], "increasePriority": this.CostSum(template.cost) < 400 };
| 105| 105| 			else if (template.modifications[i].value === "ResourceGatherer/Rates/food.fruit")
| 112| 112| 				return { "name": tech[0], "increasePriority": false };
| 113| 113| 			else if (template.modifications[i].value === "Attack/Ranged/MaxRange")
| 114| 114| 				return { "name": tech[0], "increasePriority": false };
| 115|    |-		}
|    | 115|+		
| 116| 116| 	}
| 117| 117| 	return null;
| 118| 118| };
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/researchManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/researchManager.js
| 138| 138| 				continue;
| 139| 139| 		}
| 140| 140| 		for (let i in template.modifications)
| 141|    |-		{
|    | 141|+		
| 142| 142| 			if (template.modifications[i].value === "ResourceGatherer/Rates/stone.rock")
| 143| 143| 				return { "name": tech[0], "increasePriority": this.CostSum(template.cost) < 400 };
| 144| 144| 			else if (template.modifications[i].value === "ResourceGatherer/Rates/metal.ore")
| 149| 149| 				return { "name": tech[0], "increasePriority": false };
| 150| 150| 			else if (template.modifications[i].value === "Health/IdleRegenRate")
| 151| 151| 				return { "name": tech[0], "increasePriority": false };
| 152|    |-		}
|    | 152|+		
| 153| 153| 	}
| 154| 154| 	return null;
| 155| 155| };
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/entityExtend.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/entityExtend.js
| 325| 325| m.getHolder = function(gameState, ent)
| 326| 326| {
| 327| 327| 	for (let holder of gameState.getEntities().values())
| 328|    |-	{
|    | 328|+	
| 329| 329| 		if (holder.isGarrisonHolder() && holder.garrisoned().indexOf(ent.id()) !== -1)
| 330| 330| 			return holder;
| 331|    |-	}
|    | 331|+	
| 332| 332| 	return undefined;
| 333| 333| };
| 334| 334| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|  62|  62| 		targetPlayer = evt.player;
|  63|  63| 		let available = 0;
|  64|  64| 		for (let attackType in this.upcomingAttacks)
|  65|    |-		{
|    |  65|+		
|  66|  66| 			for (let attack of this.upcomingAttacks[attackType])
|  67|  67| 			{
|  68|  68| 				if (attack.state === "completing")
|  79|  79| 				if (attack.unitCollection.length > 2)
|  80|  80| 					available += attack.unitCollection.length;
|  81|  81| 			}
|  82|    |-		}
|    |  82|+		
|  83|  83| 
|  84|  84| 		if (available > 12)	// launch the attack immediately
|  85|  85| 		{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|  84|  84| 		if (available > 12)	// launch the attack immediately
|  85|  85| 		{
|  86|  86| 			for (let attackType in this.upcomingAttacks)
|  87|    |-			{
|    |  87|+			
|  88|  88| 				for (let attack of this.upcomingAttacks[attackType])
|  89|  89| 				{
|  90|  90| 					if (attack.state === "completing" ||
|  94|  94| 					attack.forceStart();
|  95|  95| 					attack.requested = true;
|  96|  96| 				}
|  97|    |-			}
|    |  97|+			
|  98|  98| 			answer = "join";
|  99|  99| 		}
| 100| 100| 		else if (other !== undefined)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
| 105| 105| 		m.chatAnswerRequestAttack(gameState, targetPlayer, answer, other);
| 106| 106| 
| 107| 107| 	for (let evt of events.EntityRenamed)	// take care of packing units in bombing attacks
| 108|    |-	{
|    | 108|+	
| 109| 109| 		for (let [targetId, unitIds] of this.bombingAttacks)
| 110| 110| 		{
| 111| 111| 			if (targetId == evt.entity)
| 119| 119| 				unitIds.delete(evt.entity);
| 120| 120| 			}
| 121| 121| 		}
| 122|    |-	}
|    | 122|+	
| 123| 123| };
| 124| 124| 
| 125| 125| /**
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
| 107| 107| 	for (let evt of events.EntityRenamed)	// take care of packing units in bombing attacks
| 108| 108| 	{
| 109| 109| 		for (let [targetId, unitIds] of this.bombingAttacks)
| 110|    |-		{
|    | 110|+		
| 111| 111| 			if (targetId == evt.entity)
| 112| 112| 			{
| 113| 113| 				this.bombingAttacks.set(evt.newentity, unitIds);
| 118| 118| 				unitIds.add(evt.newentity);
| 119| 119| 				unitIds.delete(evt.entity);
| 120| 120| 			}
| 121|    |-		}
|    | 121|+		
| 122| 122| 	}
| 123| 123| };
| 124| 124| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
| 186| 186| 			let x;
| 187| 187| 			let z;
| 188| 188| 			if (struct.hasClass("Field"))
| 189|    |-			{
|    | 189|+			
| 190| 190| 				if (!struct.resourceSupplyNumGatherers() ||
| 191| 191| 				    !gameState.isPlayerEnemy(gameState.ai.HQ.territoryMap.getOwner(structPos)))
| 192| 192| 					continue;
| 193|    |-			}
|    | 193|+			
| 194| 194| 			let dist = API3.VectorDistance(entPos, structPos);
| 195| 195| 			if (dist > range)
| 196| 196| 			{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
| 254| 254| 
| 255| 255| 	let unexecutedAttacks = { "Rush": 0, "Raid": 0, "Attack": 0, "HugeAttack": 0 };
| 256| 256| 	for (let attackType in this.upcomingAttacks)
| 257|    |-	{
|    | 257|+	
| 258| 258| 		for (let i = 0; i < this.upcomingAttacks[attackType].length; ++i)
| 259| 259| 		{
| 260| 260| 			let attack = this.upcomingAttacks[attackType][i];
| 293| 293| 				this.upcomingAttacks[attackType].splice(i--, 1);
| 294| 294| 			}
| 295| 295| 		}
| 296|    |-	}
|    | 296|+	
| 297| 297| 
| 298| 298| 	for (let attackType in this.startedAttacks)
| 299| 299| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
| 296| 296| 	}
| 297| 297| 
| 298| 298| 	for (let attackType in this.startedAttacks)
| 299|    |-	{
|    | 299|+	
| 300| 300| 		for (let i = 0; i < this.startedAttacks[attackType].length; ++i)
| 301| 301| 		{
| 302| 302| 			let attack = this.startedAttacks[attackType][i];
| 313| 313| 				this.startedAttacks[attackType].splice(i--, 1);
| 314| 314| 			}
| 315| 315| 		}
| 316|    |-	}
|    | 316|+	
| 317| 317| 
| 318| 318| 	// creating plans after updating because an aborted plan might be reused in that case.
| 319| 319| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
| 339| 339| 	else if (unexecutedAttacks.Attack == 0 && unexecutedAttacks.HugeAttack == 0 &&
| 340| 340| 		this.startedAttacks.Attack.length + this.startedAttacks.HugeAttack.length < Math.min(2, 1 + Math.round(gameState.getPopulationMax()/100)) &&
| 341| 341| 		(this.startedAttacks.Attack.length + this.startedAttacks.HugeAttack.length == 0 || gameState.getPopulationMax() - gameState.getPopulation() > 12))
| 342|    |-	{
|    | 342|+	
| 343| 343| 		if (barracksNb >= 1 && (gameState.currentPhase() > 1 || gameState.isResearching(gameState.getPhaseName(2))) ||
| 344| 344| 			!gameState.ai.HQ.baseManagers[1])	// if we have no base ... nothing else to do than attack
| 345| 345| 		{
| 357| 357| 			}
| 358| 358| 			this.attackNumber++;
| 359| 359| 		}
| 360|    |-	}
|    | 360|+	
| 361| 361| 
| 362| 362| 	if (unexecutedAttacks.Raid === 0 && gameState.ai.HQ.defenseManager.targetList.length)
| 363| 363| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
| 383| 383| m.AttackManager.prototype.getPlan = function(planName)
| 384| 384| {
| 385| 385| 	for (let attackType in this.upcomingAttacks)
| 386|    |-	{
|    | 386|+	
| 387| 387| 		for (let attack of this.upcomingAttacks[attackType])
| 388| 388| 			if (attack.getName() == planName)
| 389| 389| 				return attack;
| 390|    |-	}
|    | 390|+	
| 391| 391| 	for (let attackType in this.startedAttacks)
| 392| 392| 	{
| 393| 393| 		for (let attack of this.startedAttacks[attackType])
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
| 389| 389| 				return attack;
| 390| 390| 	}
| 391| 391| 	for (let attackType in this.startedAttacks)
| 392|    |-	{
|    | 392|+	
| 393| 393| 		for (let attack of this.startedAttacks[attackType])
| 394| 394| 			if (attack.getName() == planName)
| 395| 395| 				return attack;
| 396|    |-	}
|    | 396|+	
| 397| 397| 	return undefined;
| 398| 398| };
| 399| 399| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackManager.js
| 465| 465| 		veto[i] = true;
| 466| 466| 	// No rush if enemy too well defended (i.e. iberians)
| 467| 467| 	if (attack.type == "Rush")
| 468|    |-	{
|    | 468|+	
| 469| 469| 		for (let i = 1; i < gameState.sharedScript.playersData.length; ++i)
| 470| 470| 		{
| 471| 471| 			if (!gameState.isPlayerEnemy(i) || veto[i])
| 479| 479| 			if (enemyDefense > 6)
| 480| 480| 				veto[i] = true;
| 481| 481| 		}
| 482|    |-	}
|    | 482|+	
| 483| 483| 
| 484| 484| 	// then if not a huge attack, continue attacking our previous target as long as it has some entities,
| 485| 485| 	// otherwise target the most accessible one
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|  79|  79| 		let tribute = {};
|  80|  80| 		let toSend = false;
|  81|  81| 		for (let res in allyResources)
|  82|    |-		{
|    |  82|+		
|  83|  83| 			if (donor && availableResources[res] > 200 && allyResources[res] < 0.2 * availableResources[res])
|  84|  84| 			{
|  85|  85| 				tribute[res] = Math.floor(0.3*availableResources[res] - allyResources[res]);
| 111| 111| 					}
| 112| 112| 				}
| 113| 113| 			}
| 114|    |-		}
|    | 114|+		
| 115| 115| 		if (!toSend)
| 116| 116| 			continue;
| 117| 117| 		if (this.Config.debug > 1)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|  99|  99| 				if (!mostNeeded)
| 100| 100| 					mostNeeded = gameState.ai.HQ.pickMostNeededResources(gameState);
| 101| 101| 				for (let k = 0; k < 2; ++k)
| 102|    |-				{
|    | 102|+				
| 103| 103| 					if (mostNeeded[k].type == res && mostNeeded[k].wanted > 0)
| 104| 104| 					{
| 105| 105| 						this.nextTributeRequest.set("all", gameState.ai.elapsedTime + 90);
| 109| 109| 							API3.warn("Tribute on " + res + " requested to player " + i);
| 110| 110| 						break;
| 111| 111| 					}
| 112|    |-				}
|    | 112|+				
| 113| 113| 			}
| 114| 114| 		}
| 115| 115| 		if (!toSend)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 156| 156| 			continue;
| 157| 157| 		let tributes = 0;
| 158| 158| 		for (let key in evt.amounts)
| 159|    |-		{
|    | 159|+		
| 160| 160| 			if (key === "food")
| 161| 161| 				tributes += evt.amounts[key];
| 162| 162| 			else
| 163| 163| 				tributes += 2*evt.amounts[key];
| 164|    |-		}
|    | 164|+		
| 165| 165| 		this.Config.personality.cooperative = Math.min(1, this.Config.personality.cooperative + 0.0001 * tributes);
| 166| 166| 	}
| 167| 167| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 235| 235| 
| 236| 236| 		// Our diplomacy will have changed already if the response was "accept"
| 237| 237| 		if (request.status === "waitingForTribute")
| 238|    |-		{
|    | 238|+		
| 239| 239| 			Engine.PostCommand(PlayerID, {
| 240| 240| 				"type": "tribute-request",
| 241| 241| 				"source": PlayerID,
| 243| 243| 				"resourceWanted": request.wanted,
| 244| 244| 				"resourceType": request.type
| 245| 245| 			});
| 246|    |-		}
|    | 246|+		
| 247| 247| 	}
| 248| 248| 
| 249| 249| 	// An AI player we sent a diplomacy request to demanded we send them a tribute
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 432| 432| {
| 433| 433| 	for (let [player, data] of this.receivedDiplomacyRequests)
| 434| 434| 		if (data.status === "waitingForTribute" && gameState.ai.elapsedTime > data.warnTime)
| 435|    |-		{
|    | 435|+		
| 436| 436| 			if (data.sentWarning)
| 437| 437| 			{
| 438| 438| 				this.receivedDiplomacyRequests.delete(player);
| 447| 447| 					"type": data.type
| 448| 448| 				});
| 449| 449| 			}
| 450|    |-		}
|    | 450|+		
| 451| 451| };
| 452| 452| 
| 453| 453| /**
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
| 385| 385| {
| 386| 386| 	// copy over all parameters.
| 387| 387| 	for (let i in otherArmy.assignedAgainst)
| 388|    |-	{
|    | 388|+	
| 389| 389| 		if (this.assignedAgainst[i] === undefined)
| 390| 390| 			this.assignedAgainst[i] = otherArmy.assignedAgainst[i];
| 391| 391| 		else
| 392| 392| 			this.assignedAgainst[i] = this.assignedAgainst[i].concat(otherArmy.assignedAgainst[i]);
| 393|    |-	}
|    | 393|+	
| 394| 394| 	for (let i in otherArmy.assignedTo)
| 395| 395| 		this.assignedTo[i] = otherArmy.assignedTo[i];
| 396| 396| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
| 481| 481| 
| 482| 482| 	let entStrength;
| 483| 483| 	if (ent.hasClass("Structure"))
| 484|    |-	{
|    | 484|+	
| 485| 485| 		if (ent.owner() !== PlayerID)
| 486| 486| 			entStrength = ent.getDefaultArrow() ? 6*ent.getDefaultArrow() : 4;
| 487| 487| 		else	// small strength used only when we try to recover capture points
| 488| 488| 			entStrength = 2;
| 489|    |-	}
|    | 489|+	
| 490| 490| 	else
| 491| 491| 		entStrength = m.getMaxStrength(ent);
| 492| 492| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
| 510| 510| 	// otherwise it would remove the old entity from this army list
| 511| 511| 	// TODO we should may-be reevaluate the strength
| 512| 512| 	for (let evt of events.EntityRenamed)	// take care of promoted and packed units
| 513|    |-	{
|    | 513|+	
| 514| 514| 		if (this.foeEntities.indexOf(evt.entity) !== -1)
| 515| 515| 		{
| 516| 516| 			let ent = gameState.getEntityById(evt.newentity);
| 538| 538| 					this.assignedAgainst[against][this.assignedAgainst[against].indexOf(evt.entity)] = evt.newentity;
| 539| 539| 			}
| 540| 540| 		}
| 541|    |-	}
|    | 541|+	
| 542| 542| 
| 543| 543| 	for (let evt of events.Garrison)
| 544| 544| 		this.removeFoe(gameState, evt.entity);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseArmy.js
| 544| 544| 		this.removeFoe(gameState, evt.entity);
| 545| 545| 
| 546| 546| 	for (let evt of events.OwnershipChanged)	// captured
| 547|    |-	{
|    | 547|+	
| 548| 548| 		if (!gameState.isPlayerEnemy(evt.to))
| 549| 549| 			this.removeFoe(gameState, evt.entity);
| 550| 550| 		else if (evt.from === PlayerID)
| 551| 551| 			this.removeOwn(gameState, evt.entity);
| 552|    |-	}
|    | 552|+	
| 553| 553| 
| 554| 554| 	for (let evt of events.Destroy)
| 555| 555| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/mapModule.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/mapModule.js
|  62|  62| 				continue;
|  63|  63| 		}
|  64|  64| 		else
|  65|    |-		{
|    |  65|+		
|  66|  66| 			if (!buildEnemy)
|  67|  67| 				continue;
|  68|    |-		}
|    |  68|+		
|  69|  69| 
|  70|  70| 		let x = ratio * (k % territoryMap.width);
|  71|  71| 		let y = ratio * Math.floor(k / territoryMap.width);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/mapModule.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/mapModule.js
|  70|  70| 		let x = ratio * (k % territoryMap.width);
|  71|  71| 		let y = ratio * Math.floor(k / territoryMap.width);
|  72|  72| 		for (let ix = 0; ix < ratio; ++ix)
|  73|    |-		{
|    |  73|+		
|  74|  74| 			for (let iy = 0; iy < ratio; ++iy)
|  75|  75| 			{
|  76|  76| 				let i = x + ix + (y + iy)*passabilityMap.width;
|  79|  79| 				if (!(passabilityMap.data[i] & obstructionMask))
|  80|  80| 					obstructionTiles[i] = 255;
|  81|  81| 			}
|  82|    |-		}
|    |  82|+		
|  83|  83| 	}
|  84|  84| 
|  85|  85| 	let map = new API3.Map(gameState.sharedScript, "passability", obstructionTiles);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
| 119| 119| 			continue;
| 120| 120| 		ent.setMetadata(PlayerID, "onBoard", ship.id());
| 121| 121| 		if (this.debug > 1)
| 122|    |-		{
|    | 122|+		
| 123| 123| 			if (ent.getMetadata(PlayerID, "role") == "attack")
| 124| 124| 				Engine.PostCommand(PlayerID, { "type": "set-shading-color", "entities": [ent.id()], "rgb": [2, 0, 0] });
| 125| 125| 			else
| 126| 126| 				Engine.PostCommand(PlayerID, { "type": "set-shading-color", "entities": [ent.id()], "rgb": [0, 2, 0] });
| 127|    |-		}
|    | 127|+		
| 128| 128| 		return;
| 129| 129| 	}
| 130| 130| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
| 299| 299| 	let shipTested = {};
| 300| 300| 
| 301| 301| 	for (let ent of this.units.values())
| 302|    |-	{
|    | 302|+	
| 303| 303| 		if (!ent.getMetadata(PlayerID, "onBoard"))
| 304| 304| 		{
| 305| 305| 			ready = false;
| 408| 408| 				ent.setMetadata(PlayerID, "posGarrison", ent.position());
| 409| 409| 			}
| 410| 410| 		}
| 411|    |-	}
|    | 411|+	
| 412| 412| 
| 413| 413| 	if (this.needSplit)
| 414| 414| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/transportPlan.js
| 557| 557| 		{
| 558| 558| 			let ship = gameState.getEntityById(ent.getMetadata(PlayerID, "onBoard"));
| 559| 559| 			if (ship)
| 560|    |-			{
|    | 560|+			
| 561| 561| 				if (ship.garrisoned().indexOf(entId) != -1)
| 562| 562| 					ent.setMetadata(PlayerID, "onBoard", "onBoard");
| 563| 563| 				else
| 566| 566| 					this.resetUnit(gameState, ent);
| 567| 567| 					ent.destroy();
| 568| 568| 				}
| 569|    |-			}
|    | 569|+			
| 570| 570| 			else
| 571| 571| 			{
| 572| 572| 				API3.warn("Petra transportPlan problem: unit on ship, but no ship ???");
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queue.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queue.js
|  22|  22| 	if (!newPlan)
|  23|  23| 		return;
|  24|  24| 	for (let plan of this.plans)
|  25|    |-	{
|    |  25|+	
|  26|  26| 		if (newPlan.category === "unit" && plan.type == newPlan.type && plan.number + newPlan.number <= plan.maxMerge)
|  27|  27| 		{
|  28|  28| 			plan.addItem(newPlan.number);
|  30|  30| 		}
|  31|  31| 		else if (newPlan.category === "technology" && plan.type === newPlan.type)
|  32|  32| 			return;
|  33|    |-	}
|    |  33|+	
|  34|  34| 	this.plans.push(newPlan);
|  35|  35| };
|  36|  36| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/buildManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/buildManager.js
|  27|  27| m.BuildManager.prototype.incrementBuilderCounters = function(civ, ent, increment)
|  28|  28| {
|  29|  29| 	for (let buildable of ent.buildableEntities(civ))
|  30|    |-	{
|    |  30|+	
|  31|  31| 		if (this.builderCounters.has(buildable))
|  32|  32| 		{
|  33|  33| 			let count = this.builderCounters.get(buildable) + increment;
|  42|  42| 			this.builderCounters.set(buildable, increment);
|  43|  43| 		else
|  44|  44| 			API3.warn(" Petra error in incrementBuilderCounters for " + buildable + " not yet set");
|  45|    |-	}
|    |  45|+	
|  46|  46| };
|  47|  47| 
|  48|  48| /** Update the builders counters */
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
|  52|  52| 		}
|  53|  53| 	}
|  54|  54| 	for (let enemy in attackingArmies)
|  55|    |-	{
|    |  55|+	
|  56|  56| 		for (let ally in attackingArmies[enemy])
|  57|  57| 		{
|  58|  58| 			if (this.attackedAllies[ally] === undefined)
|  59|  59| 				this.attackedAllies[ally] = 0;
|  60|  60| 			this.attackedAllies[ally] += 1;
|  61|  61| 		}
|  62|    |-	}
|    |  62|+	
|  63|  63| 	this.checkEnemyArmies(gameState);
|  64|  64| 	this.checkEnemyUnits(gameState);
|  65|  65| 	this.assignDefenders(gameState);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
|  70|  70| m.DefenseManager.prototype.makeIntoArmy = function(gameState, entityID, type = "default")
|  71|  71| {
|  72|  72| 	if (type == "default")
|  73|    |-	{
|    |  73|+	
|  74|  74| 		// Try to add it to an existing army.
|  75|  75| 		for (let army of this.armies)
|  76|  76| 			if (army.getType() == type && army.addFoe(gameState, entityID))
|  77|  77| 				return;	// over
|  78|    |-	}
|    |  78|+	
|  79|  79| 
|  80|  80| 	// Create a new army for it.
|  81|  81| 	let army = new m.DefenseArmy(gameState, [entityID], type);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
| 179| 179| 		if (territoryOwner != PlayerID && this.attackedAllies[territoryOwner] &&
| 180| 180| 		                                  this.attackedAllies[territoryOwner] > 1 &&
| 181| 181| 		                                  this.GetCooperationLevel(territoryOwner) > 0.7)
| 182|    |-		{
|    | 182|+		
| 183| 183| 			for (let building of gameState.getAllyStructures(territoryOwner).values())
| 184| 184| 			{
| 185| 185| 				if (building.foundationProgress() == 0 ||
| 188| 188| 				if (!this.territoryMap.isBlinking(building.position()))
| 189| 189| 					return true;
| 190| 190| 			}
| 191|    |-		}
|    | 191|+		
| 192| 192| 
| 193| 193| 		// Update the number of enemies attacking this ally
| 194| 194| 		let enemy = entity.owner();
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
| 211| 211| 	if (i == PlayerID)
| 212| 212| 	{
| 213| 213| 		if (!this.armies.length)
| 214|    |-		{
|    | 214|+		
| 215| 215| 			// check if we can recover capture points from any of our notdecaying structures
| 216| 216| 			for (let ent of gameState.getOwnStructures().values())
| 217| 217| 			{
| 229| 229| 				this.makeIntoArmy(gameState, ent.id(), "capturing");
| 230| 230| 				break;
| 231| 231| 			}
| 232|    |-		}
|    | 232|+		
| 233| 233| 		return;
| 234| 234| 	}
| 235| 235| 	else if (!gameState.isPlayerEnemy(i))
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
| 328| 328| 		if (!gameState.isPlayerEnemy(owner))
| 329| 329| 		{
| 330| 330| 			if (gameState.isPlayerMutualAlly(owner))
| 331|    |-			{
|    | 331|+			
| 332| 332| 				// update the number of enemies attacking this ally
| 333| 333| 				for (let id of army.foeEntities)
| 334| 334| 				{
| 343| 343| 					this.attackingArmies[enemy][owner] += 1;
| 344| 344| 					break;
| 345| 345| 				}
| 346|    |-			}
|    | 346|+			
| 347| 347| 			continue;
| 348| 348| 		}
| 349| 349| 		else if (owner != 0)   // enemy army back in its territory
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
| 530| 530| 		army.checkEvents(gameState, events);
| 531| 531| 
| 532| 532| 	for (let evt of events.OwnershipChanged)   // capture events
| 533|    |-	{
|    | 533|+	
| 534| 534| 		if (gameState.isPlayerMutualAlly(evt.from) && evt.to > 0)
| 535| 535| 		{
| 536| 536| 			let ent = gameState.getEntityById(evt.entity);
| 537| 537| 			if (ent && ent.hasClass("CivCentre")) // one of our cc has been captured
| 538| 538| 				gameState.ai.HQ.attackManager.switchDefenseToAttack(gameState, ent, { "range": 150 });
| 539| 539| 		}
| 540|    |-	}
|    | 540|+	
| 541| 541| 
| 542| 542| 	let allAttacked = {};
| 543| 543| 	for (let evt of events.Attacked)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
| 552| 552| 		let attacker = gameState.getEntityById(evt.attacker);
| 553| 553| 		if (attacker && gameState.isEntityOwn(attacker) && gameState.isEntityEnemy(target) && !attacker.hasClass("Ship") &&
| 554| 554| 		   (!target.hasClass("Structure") || target.attackRange("Ranged")))
| 555|    |-		{
|    | 555|+		
| 556| 556| 			// If enemies are in range of one of our defensive structures, garrison it for arrow multiplier
| 557| 557| 			// (enemy non-defensive structure are not considered to stay in sync with garrisonManager)
| 558| 558| 			if (attacker.position() && attacker.isGarrisonHolder() && attacker.getArrowMultiplier() &&
| 559| 559| 			    (target.owner() != 0 || !target.hasClass("Unit") ||
| 560| 560| 			     target.unitAIState() && target.unitAIState().split(".")[1] == "COMBAT"))
| 561| 561| 				this.garrisonUnitsInside(gameState, attacker, { "attacker": target });
| 562|    |-		}
|    | 562|+		
| 563| 563| 
| 564| 564| 		if (!gameState.isEntityOwn(target))
| 565| 565| 			continue;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/defenseManager.js
| 756| 756| 	let typeGarrison = data.type || "protection";
| 757| 757| 	let allowMelee = gameState.ai.HQ.garrisonManager.allowMelee(target);
| 758| 758| 	if (allowMelee === undefined)
| 759|    |-	{
|    | 759|+	
| 760| 760| 		// Should be kept in sync with garrisonManager to avoid garrisoning-ungarrisoning some units
| 761| 761| 		if (data.attacker)
| 762| 762| 			allowMelee = data.attacker.hasClass("Structure") ? data.attacker.attackRange("Ranged") : !m.isSiegeUnit(data.attacker);
| 763| 763| 		else
| 764| 764| 			allowMelee = true;
| 765|    |-	}
|    | 765|+	
| 766| 766| 	let units = gameState.getOwnUnits().filter(ent => {
| 767| 767| 		if (!ent.position())
| 768| 768| 			return false;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|  97|  97| 	else if (pos.xx === undefined || pos.x == pos.xx && pos.z == pos.zz)
|  98|  98| 		builder.construct(this.type, pos.x, pos.z, pos.angle, this.metadata);
|  99|  99| 	else // try with the lowest, move towards us unless we're same
| 100|    |-	{
|    | 100|+	
| 101| 101| 		for (let step = 0; step <= 1; step += 0.2)
| 102| 102| 			builder.construct(this.type, step*pos.x + (1-step)*pos.xx, step*pos.z + (1-step)*pos.zz,
| 103| 103| 				pos.angle, this.metadata);
| 104|    |-	}
|    | 104|+	
| 105| 105| 	this.onStart(gameState);
| 106| 106| 	Engine.ProfileStop();
| 107| 107| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 131| 131| 	}
| 132| 132| 
| 133| 133| 	if (!this.position)
| 134|    |-	{
|    | 134|+	
| 135| 135| 		if (template.hasClass("CivCentre"))
| 136| 136| 		{
| 137| 137| 			let pos;
| 177| 177| 			else if (!pos)
| 178| 178| 				return false;
| 179| 179| 		}
| 180|    |-	}
|    | 180|+	
| 181| 181| 
| 182| 182| 	// Compute each tile's closeness to friendly structures:
| 183| 183| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 204| 204| 					placement.set(j, 45);
| 205| 205| 		}
| 206| 206| 		else
| 207|    |-		{
|    | 207|+		
| 208| 208| 			for (let j = 0; j < placement.map.length; ++j)
| 209| 209| 				if (HQ.basesMap.map[j] != 0)
| 210| 210| 					placement.set(j, 45);
| 211|    |-		}
|    | 211|+		
| 212| 212| 
| 213| 213| 		if (!HQ.requireHouses || !template.hasClass("House"))
| 214| 214| 		{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 211| 211| 		}
| 212| 212| 
| 213| 213| 		if (!HQ.requireHouses || !template.hasClass("House"))
| 214|    |-		{
|    | 214|+		
| 215| 215| 			gameState.getOwnStructures().forEach(function(ent) {
| 216| 216| 				let pos = ent.position();
| 217| 217| 				let x = Math.round(pos[0] / cellSize);
| 245| 245| 				else if (template.genericName() == "Rotary Mill" && ent.hasClass("Field"))
| 246| 246| 					placement.addInfluence(x, z, 60/cellSize, 40);
| 247| 247| 			});
| 248|    |-		}
|    | 248|+		
| 249| 249| 		if (template.hasClass("Farmstead"))
| 250| 250| 		{
| 251| 251| 			for (let j = 0; j < placement.map.length; ++j)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 219| 219| 
| 220| 220| 				let struct = m.getBuiltEntity(gameState, ent);
| 221| 221| 				if (struct.resourceDropsiteTypes() && struct.resourceDropsiteTypes().indexOf("food") != -1)
| 222|    |-				{
|    | 222|+				
| 223| 223| 					if (template.hasClass("Field") || template.hasClass("Corral"))
| 224| 224| 						placement.addInfluence(x, z, 80/cellSize, 50);
| 225| 225| 					else // If this is not a field add a negative influence because we want to leave this area for fields
| 226| 226| 						placement.addInfluence(x, z, 80/cellSize, -20);
| 227|    |-				}
|    | 227|+				
| 228| 228| 				else if (template.hasClass("House"))
| 229| 229| 				{
| 230| 230| 					if (ent.hasClass("House"))
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 247| 247| 			});
| 248| 248| 		}
| 249| 249| 		if (template.hasClass("Farmstead"))
| 250|    |-		{
|    | 250|+		
| 251| 251| 			for (let j = 0; j < placement.map.length; ++j)
| 252| 252| 			{
| 253| 253| 				let value = placement.map[j] - gameState.sharedScript.resourceMaps.wood.map[j]/3;
| 255| 255| 					value /= 2;	// we need space around farmstead, so disfavor map border
| 256| 256| 				placement.set(j, value);
| 257| 257| 			}
| 258|    |-		}
|    | 258|+		
| 259| 259| 	}
| 260| 260| 
| 261| 261| 	// Requires to be inside our territory, and inside our base territory if required
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 268| 268| 	{
| 269| 269| 		let base = this.metadata.base;
| 270| 270| 		for (let j = 0; j < placement.map.length; ++j)
| 271|    |-		{
|    | 271|+		
| 272| 272| 			if (HQ.basesMap.map[j] != base)
| 273| 273| 				placement.map[j] = 0;
| 274| 274| 			else if (placement.map[j] > 0)
| 283| 283| 				if (HQ.isNearInvadingArmy([x, z]))
| 284| 284| 					placement.map[j] = 0;
| 285| 285| 			}
| 286|    |-		}
|    | 286|+		
| 287| 287| 	}
| 288| 288| 	else
| 289| 289| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 286| 286| 		}
| 287| 287| 	}
| 288| 288| 	else
| 289|    |-	{
|    | 289|+	
| 290| 290| 		for (let j = 0; j < placement.map.length; ++j)
| 291| 291| 		{
| 292| 292| 			if (HQ.basesMap.map[j] == 0)
| 306| 306| 					placement.set(j, placement.map[j] + 100);
| 307| 307| 			}
| 308| 308| 		}
| 309|    |-	}
|    | 309|+	
| 310| 310| 
| 311| 311| 	// Find the best non-obstructed:
| 312| 312| 	// Find target building's approximate obstruction radius, and expand by a bit to make sure we're not too close,
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 288| 288| 	else
| 289| 289| 	{
| 290| 290| 		for (let j = 0; j < placement.map.length; ++j)
| 291|    |-		{
|    | 291|+		
| 292| 292| 			if (HQ.basesMap.map[j] == 0)
| 293| 293| 				placement.map[j] = 0;
| 294| 294| 			else if (placement.map[j] > 0)
| 305| 305| 				else if (favoredBase && HQ.basesMap.map[j] == favoredBase)
| 306| 306| 					placement.set(j, placement.map[j] + 100);
| 307| 307| 			}
| 308|    |-		}
|    | 308|+		
| 309| 309| 	}
| 310| 310| 
| 311| 311| 	// Find the best non-obstructed:
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 650| 650| 		{
| 651| 651| 			let count = 0;
| 652| 652| 			for (let j = 0; j < length-1; ++j)
| 653|    |-			{
|    | 653|+			
| 654| 654| 				if ((waterPoints[(i + j) % length]+1) % numPoints == waterPoints[(i + j + 1) % length])
| 655| 655| 					++count;
| 656| 656| 				else
| 657| 657| 					break;
| 658|    |-			}
|    | 658|+			
| 659| 659| 			consec[i] = count;
| 660| 660| 		}
| 661| 661| 		let start = 0;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 661| 661| 		let start = 0;
| 662| 662| 		let count = 0;
| 663| 663| 		for (let c in consec)
| 664|    |-		{
|    | 664|+		
| 665| 665| 			if (consec[c] > count)
| 666| 666| 			{
| 667| 667| 				start = c;
| 668| 668| 				count = consec[c];
| 669| 669| 			}
| 670|    |-		}
|    | 670|+		
| 671| 671| 
| 672| 672| 		// If we've found a shoreline, stop searching
| 673| 673| 		if (count != numPoints-1)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 857| 857| 			let dxmax = size - dy;
| 858| 858| 			let ky = iy + dy;
| 859| 859| 			if (ky >= 0 && ky < w)
| 860|    |-			{
|    | 860|+			
| 861| 861| 				for (let dx = -dxmax; dx <= dxmax; ++dx)
| 862| 862| 				{
| 863| 863| 					let kx = ix + dx;
| 868| 868| 					total += weight * resourceMaps[k].map[kx + w * ky];
| 869| 869| 					nbcell += weight;
| 870| 870| 				}
| 871|    |-			}
|    | 871|+			
| 872| 872| 			if (dy == 0)
| 873| 873| 				continue;
| 874| 874| 			ky = iy - dy;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueplanBuilding.js
| 873| 873| 				continue;
| 874| 874| 			ky = iy - dy;
| 875| 875| 			if (ky >= 0 && ky < w)
| 876|    |-			{
|    | 876|+			
| 877| 877| 				for (let dx = -dxmax; dx <= dxmax; ++dx)
| 878| 878| 				{
| 879| 879| 					let kx = ix + dx;
| 884| 884| 					total += weight * resourceMaps[k].map[kx + w * ky];
| 885| 885| 					nbcell += weight;
| 886| 886| 				}
| 887|    |-			}
|    | 887|+			
| 888| 888| 		}
| 889| 889| 	}
| 890| 890| 	return nbcell ? total / nbcell : 0;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
| 182| 182| 	let minWaterSize = Math.floor(0.2*totalSize);
| 183| 183| 	let cellArea = passabilityMap.cellSize * passabilityMap.cellSize;
| 184| 184| 	for (let i = 0; i < accessibility.regionSize.length; ++i)
| 185|    |-	{
|    | 185|+	
| 186| 186| 		if (landIndex && i == landIndex)
| 187| 187| 			this.landRegions[i] = true;
| 188| 188| 		else if (accessibility.regionType[i] === "land" && cellArea*accessibility.regionSize[i] > 320)
| 215| 215| 		}
| 216| 216| 		else if (accessibility.regionType[i] === "water" && cellArea*accessibility.regionSize[i] > 3600)
| 217| 217| 			this.navalRegions[i] = true;
| 218|    |-	}
|    | 218|+	
| 219| 219| 
| 220| 220| 	if (this.Config.debug < 3)
| 221| 221| 		return true;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
| 186| 186| 		if (landIndex && i == landIndex)
| 187| 187| 			this.landRegions[i] = true;
| 188| 188| 		else if (accessibility.regionType[i] === "land" && cellArea*accessibility.regionSize[i] > 320)
| 189|    |-		{
|    | 189|+		
| 190| 190| 			if (landIndex)
| 191| 191| 			{
| 192| 192| 				let sea = this.getSeaBetweenIndices(gameState, landIndex, i);
| 207| 207| 					this.navalRegions[seaIndex] = true;
| 208| 208| 				}
| 209| 209| 			}
| 210|    |-		}
|    | 210|+		
| 211| 211| 		else if (accessibility.regionType[i] === "water" && accessibility.regionSize[i] > minWaterSize)
| 212| 212| 		{
| 213| 213| 			this.navalMap = true;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
| 443| 443| 	let startingSize = 0;
| 444| 444| 	let startingLand = [];
| 445| 445| 	for (let region in this.landRegions)
| 446|    |-	{
|    | 446|+	
| 447| 447| 		for (let base of this.baseManagers)
| 448| 448| 		{
| 449| 449| 			if (!base.anchor || base.accessIndex != +region)
| 452| 452| 			startingLand.push(base.accessIndex);
| 453| 453| 			break;
| 454| 454| 		}
| 455|    |-	}
|    | 455|+	
| 456| 456| 	let cell = gameState.getPassabilityMap().cellSize;
| 457| 457| 	startingSize = startingSize * cell * cell;
| 458| 458| 	if (this.Config.debug > 1)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
| 463| 463| 		this.Config.Economy.popForDock = Math.min(this.Config.Economy.popForDock, 16);
| 464| 464| 		let num = Math.max(this.Config.Economy.targetNumFishers, 2);
| 465| 465| 		for (let land of startingLand)
| 466|    |-		{
|    | 466|+		
| 467| 467| 			for (let sea of gameState.ai.accessibility.regionLinks[land])
| 468| 468| 				if (gameState.ai.HQ.navalRegions[sea])
| 469| 469| 					this.navalManager.updateFishingBoats(sea, num);
| 470|    |-		}
|    | 470|+		
| 471| 471| 		this.maxFields = 1;
| 472| 472| 		this.needCorral = true;
| 473| 473| 	}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
| 480| 480| 	let startingFood = gameState.getResources().food;
| 481| 481| 	let check = {};
| 482| 482| 	for (let proxim of ["nearby", "medium", "faraway"])
| 483|    |-	{
|    | 483|+	
| 484| 484| 		for (let base of this.baseManagers)
| 485| 485| 		{
| 486| 486| 			for (let supply of base.dropsiteSupplies.food[proxim])
| 491| 491| 				startingFood += supply.ent.resourceSupplyAmount();
| 492| 492| 			}
| 493| 493| 		}
| 494|    |-	}
|    | 494|+	
| 495| 495| 	if (startingFood < 800)
| 496| 496| 	{
| 497| 497| 		if (startingSize < 25000)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
| 482| 482| 	for (let proxim of ["nearby", "medium", "faraway"])
| 483| 483| 	{
| 484| 484| 		for (let base of this.baseManagers)
| 485|    |-		{
|    | 485|+		
| 486| 486| 			for (let supply of base.dropsiteSupplies.food[proxim])
| 487| 487| 			{
| 488| 488| 				if (check[supply.id])    // avoid double counting as same resource can appear several time
| 490| 490| 				check[supply.id] = true;
| 491| 491| 				startingFood += supply.ent.resourceSupplyAmount();
| 492| 492| 			}
| 493|    |-		}
|    | 493|+		
| 494| 494| 	}
| 495| 495| 	if (startingFood < 800)
| 496| 496| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
| 493| 493| 		}
| 494| 494| 	}
| 495| 495| 	if (startingFood < 800)
| 496|    |-	{
|    | 496|+	
| 497| 497| 		if (startingSize < 25000)
| 498| 498| 		{
| 499| 499| 			this.needFish = true;
| 501| 501| 		}
| 502| 502| 		else
| 503| 503| 			this.needFarm = true;
| 504|    |-	}
|    | 504|+	
| 505| 505| 	// - count the available wood resource, and allow rushes only if enough (we should otherwise favor expansion)
| 506| 506| 	let startingWood = gameState.getResources().wood;
| 507| 507| 	check = {};
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
| 506| 506| 	let startingWood = gameState.getResources().wood;
| 507| 507| 	check = {};
| 508| 508| 	for (let proxim of ["nearby", "medium", "faraway"])
| 509|    |-	{
|    | 509|+	
| 510| 510| 		for (let base of this.baseManagers)
| 511| 511| 		{
| 512| 512| 			for (let supply of base.dropsiteSupplies.wood[proxim])
| 517| 517| 				startingWood += supply.ent.resourceSupplyAmount();
| 518| 518| 			}
| 519| 519| 		}
| 520|    |-	}
|    | 520|+	
| 521| 521| 	if (this.Config.debug > 1)
| 522| 522| 		API3.warn("startingWood: " + startingWood + " (cut at 8500 for no rush and 6000 for saveResources)");
| 523| 523| 	if (startingWood < 6000)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
| 508| 508| 	for (let proxim of ["nearby", "medium", "faraway"])
| 509| 509| 	{
| 510| 510| 		for (let base of this.baseManagers)
| 511|    |-		{
|    | 511|+		
| 512| 512| 			for (let supply of base.dropsiteSupplies.wood[proxim])
| 513| 513| 			{
| 514| 514| 				if (check[supply.id])    // avoid double counting as same resource can appear several time
| 516| 516| 				check[supply.id] = true;
| 517| 517| 				startingWood += supply.ent.resourceSupplyAmount();
| 518| 518| 			}
| 519|    |-		}
|    | 519|+		
| 520| 520| 	}
| 521| 521| 	if (this.Config.debug > 1)
| 522| 522| 		API3.warn("startingWood: " + startingWood + " (cut at 8500 for no rush and 6000 for saveResources)");
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js
| 536| 536| 		let allowed = Math.ceil((startingWood - 8500) / 3000);
| 537| 537| 		// Not useful to prepare rushing if too long ceasefire
| 538| 538| 		if (gameState.isCeasefireActive())
| 539|    |-		{
|    | 539|+		
| 540| 540| 			if (gameState.ceasefireTimeRemaining > 900)
| 541| 541| 				allowed = 0;
| 542| 542| 			else if (gameState.ceasefireTimeRemaining > 600 && allowed > 1)
| 543| 543| 				allowed = 1;
| 544|    |-		}
|    | 544|+		
| 545| 545| 		this.attackManager.setRushes(allowed);
| 546| 546| 	}
| 547| 547| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueManager.js
| 116| 116| 				break;
| 117| 117| 			let cost = queue.plans[j].getCost();
| 118| 118| 			if (queue.plans[j].isGo(gameState))
| 119|    |-			{
|    | 119|+			
| 120| 120| 				if (j === 0)
| 121| 121| 					total = totalShort;
| 122| 122| 				else
| 123| 123| 					total = totalMedium;
| 124|    |-			}
|    | 124|+			
| 125| 125| 			else
| 126| 126| 				total = totalLong;
| 127| 127| 			for (let type in total)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueManager.js
| 303| 303| 			available -= toAdd;
| 304| 304| 		}
| 305| 305| 		if (missing && available > 0)   // distribute the rest (due to floor) in any queue
| 306|    |-		{
|    | 306|+		
| 307| 307| 			for (let j in tempPrio)
| 308| 308| 			{
| 309| 309| 				let toAdd = Math.min(maxNeed[j], available);
| 312| 312| 				if (available <= 0)
| 313| 313| 					break;
| 314| 314| 			}
| 315|    |-		}
|    | 315|+		
| 316| 316| 		if (available < 0)
| 317| 317| 			API3.warn("Petra: problem with remaining " + res + " in queueManager " + available);
| 318| 318| 	}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/queueManager.js
| 365| 365| 		{
| 366| 366| 			let item = queue.getNext();
| 367| 367| 			if (this.accounts[name].canAfford(item.getCost()) && item.canStart(gameState))
| 368|    |-			{
|    | 368|+			
| 369| 369| 				// canStart may update the cost because of the costMultiplier so we must check it again
| 370| 370| 				if (this.accounts[name].canAfford(item.getCost()))
| 371| 371| 				{
| 374| 374| 					queue.startNext(gameState);
| 375| 375| 					queue.switched = 0;
| 376| 376| 				}
| 377|    |-			}
|    | 377|+			
| 378| 378| 		}
| 379| 379| 		else if (!queue.hasQueuedUnits())
| 380| 380| 		{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/garrisonManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/garrisonManager.js
| 149| 149| 				if (ent.hasClass("Structure"))
| 150| 150| 					around.defenseStructure = true;
| 151| 151| 				else if (m.isSiegeUnit(ent))
| 152|    |-				{
|    | 152|+				
| 153| 153| 					if (ent.attackTypes().indexOf("Melee") !== -1)
| 154| 154| 						around.meleeSiege = true;
| 155| 155| 					else
| 156| 156| 						around.rangeSiege = true;
| 157|    |-				}
|    | 157|+				
| 158| 158| 				else
| 159| 159| 				{
| 160| 160| 					around.unit = true;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/victoryManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/victoryManager.js
|  27|  27| m.VictoryManager.prototype.init = function(gameState)
|  28|  28| {
|  29|  29| 	if (gameState.getVictoryConditions().has("wonder"))
|  30|    |-	{
|    |  30|+	
|  31|  31| 		for (let wonder of gameState.getOwnEntitiesByClass("Wonder", true).values())
|  32|  32| 			this.criticalEnts.set(wonder.id(), { "guardsAssigned": 0, "guards": new Map() });
|  33|    |-	}
|    |  33|+	
|  34|  34| 
|  35|  35| 	if (gameState.getVictoryConditions().has("regicide"))
|  36|  36| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/victoryManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/victoryManager.js
|  33|  33| 	}
|  34|  34| 
|  35|  35| 	if (gameState.getVictoryConditions().has("regicide"))
|  36|    |-	{
|    |  36|+	
|  37|  37| 		for (let hero of gameState.getOwnEntitiesByClass("Hero", true).values())
|  38|  38| 		{
|  39|  39| 			let defaultStance = hero.hasClass("Soldier") ? "aggressive" : "passive";
|  46|  46| 				"guards": new Map() // ids of ents who are currently guarding this hero
|  47|  47| 			});
|  48|  48| 		}
|  49|    |-	}
|    |  49|+	
|  50|  50| 
|  51|  51| 	if (gameState.getVictoryConditions().has("capture_the_relic"))
|  52|  52| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/victoryManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/victoryManager.js
|  49|  49| 	}
|  50|  50| 
|  51|  51| 	if (gameState.getVictoryConditions().has("capture_the_relic"))
|  52|    |-	{
|    |  52|+	
|  53|  53| 		for (let relic of gameState.updatingGlobalCollection("allRelics", API3.Filters.byClass("Relic")).values())
|  54|  54| 		{
|  55|  55| 			if (relic.owner() == PlayerID)
|  56|  56| 				this.criticalEnts.set(relic.id(), { "guardsAssigned": 0, "guards": new Map() });
|  57|  57| 		}
|  58|    |-	}
|    |  58|+	
|  59|  59| };
|  60|  60| 
|  61|  61| /**
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/victoryManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/victoryManager.js
|  51|  51| 	if (gameState.getVictoryConditions().has("capture_the_relic"))
|  52|  52| 	{
|  53|  53| 		for (let relic of gameState.updatingGlobalCollection("allRelics", API3.Filters.byClass("Relic")).values())
|  54|    |-		{
|    |  54|+		
|  55|  55| 			if (relic.owner() == PlayerID)
|  56|  56| 				this.criticalEnts.set(relic.id(), { "guardsAssigned": 0, "guards": new Map() });
|  57|    |-		}
|    |  57|+		
|  58|  58| 	}
|  59|  59| };
|  60|  60| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/victoryManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/victoryManager.js
| 359| 359| {
| 360| 360| 	let numWorkers = gameState.getOwnEntitiesByRole("worker", true).length;
| 361| 361| 	if (numWorkers < 20)
| 362|    |-	{
|    | 362|+	
| 363| 363| 		for (let data of this.criticalEnts.values())
| 364| 364| 		{
| 365| 365| 			for (let guardId of data.guards.keys())
| 384| 384| 			if (numWorkers >= 20)
| 385| 385| 				break;
| 386| 386| 		}
| 387|    |-	}
|    | 387|+	
| 388| 388| 
| 389| 389| 	let minWorkers = 25;
| 390| 390| 	let deltaWorkers = 3;
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
| 424| 424| 	let candidate = { "gain": 0 };
| 425| 425| 	let potential = { "gain": 0 };
| 426| 426| 	let bestIndex = { "gain": 0 };
| 427|    |-	let bestLand  = { "gain": 0 };
|    | 427|+	let bestLand = { "gain": 0 };
| 428| 428| 
| 429| 429| 	let mapSize = gameState.sharedScript.mapSize;
| 430| 430| 	let traderTemplatesGains = gameState.getTraderTemplatesGains();
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
| 462| 462| 			if (m1.foundationProgress() === undefined && m2.foundationProgress() === undefined)
| 463| 463| 			{
| 464| 464| 				if (accessIndex)
| 465|    |-				{
|    | 465|+				
| 466| 466| 					if (gameState.ai.accessibility.regionType[accessIndex] == "water" && sea == accessIndex)
| 467| 467| 					{
| 468| 468| 						if (gain < bestIndex.gain)
| 481| 481| 							continue;
| 482| 482| 						bestLand = { "source": m1, "target": m2, "gain": gain, "land": land, "sea": sea };
| 483| 483| 					}
| 484|    |-				}
|    | 484|+				
| 485| 485| 				if (gain < candidate.gain)
| 486| 486| 					continue;
| 487| 487| 				candidate = { "source": m1, "target": m2, "gain": gain, "land": land, "sea": sea };
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
| 601| 601| 		return;	// position found, but not enough gain compared to our present route
| 602| 602| 
| 603| 603| 	if (this.Config.debug > 1)
| 604|    |-	{
|    | 604|+	
| 605| 605| 		if (this.potentialTradeRoute)
| 606| 606| 			API3.warn("turn " + gameState.ai.playedTurn + "we could have a new route with gain " +
| 607| 607| 				marketPos[3] + " instead of the present " + this.potentialTradeRoute.gain);
| 608| 608| 		else
| 609| 609| 			API3.warn("turn " + gameState.ai.playedTurn + "we could have a first route with gain " +
| 610| 610| 				marketPos[3]);
| 611|    |-	}
|    | 611|+	
| 612| 612| 
| 613| 613| 	if (!this.tradeRoute)
| 614| 614| 		gameState.ai.queueManager.changePriority("economicBuilding", 2*this.Config.priorities.economicBuilding);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
| 664| 664| 
| 665| 665| 	let ret = {};
| 666| 666| 	for (let key in route)
| 667|    |-	{
|    | 667|+	
| 668| 668| 		if (key == "source" || key == "target")
| 669| 669| 		{
| 670| 670| 			if (!route[key])
| 673| 673| 		}
| 674| 674| 		else
| 675| 675| 			ret[key] = route[key];
| 676|    |-	}
|    | 676|+	
| 677| 677| 	return ret;
| 678| 678| };
| 679| 679| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
| 684| 684| 
| 685| 685| 	let ret = {};
| 686| 686| 	for (let key in route)
| 687|    |-	{
|    | 687|+	
| 688| 688| 		if (key == "source" || key == "target")
| 689| 689| 		{
| 690| 690| 			ret[key] = gameState.getEntityById(route[key]);
| 693| 693| 		}
| 694| 694| 		else
| 695| 695| 			ret[key] = route[key];
| 696|    |-	}
|    | 696|+	
| 697| 697| 	return ret;
| 698| 698| };
| 699| 699| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js
| 711| 711| m.TradeManager.prototype.Deserialize = function(gameState, data)
| 712| 712| {
| 713| 713| 	for (let key in data)
| 714|    |-	{
|    | 714|+	
| 715| 715| 		if (key == "tradeRoute" || key == "potentialTradeRoute")
| 716| 716| 			this[key] = this.routeIdToEnt(gameState, data[key]);
| 717| 717| 		else
| 718| 718| 			this[key] = data[key];
| 719|    |-	}
|    | 719|+	
| 720| 720| };
| 721| 721| 
| 722| 722| }(PETRA));
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 209| 209| 	}
| 210| 210| 
| 211| 211| 	for (let evt of events.Destroy)
| 212|    |-	{
|    | 212|+	
| 213| 213| 		// Let's check we haven't lost an important building here.
| 214| 214| 		if (evt && !evt.SuccessfulFoundation && evt.entityObj && evt.metadata && evt.metadata[PlayerID] &&
| 215| 215| 			evt.metadata[PlayerID].base)
| 226| 226| 			if (evt.metadata[PlayerID].baseAnchor && evt.metadata[PlayerID].baseAnchor === true)
| 227| 227| 				base.anchorLost(gameState, ent);
| 228| 228| 		}
| 229|    |-	}
|    | 229|+	
| 230| 230| 
| 231| 231| 	for (let evt of events.EntityRenamed)
| 232| 232| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 255| 255| 			// Let's get a few units from other bases there to build this.
| 256| 256| 			let builders = this.bulkPickWorkers(gameState, newbase, 10);
| 257| 257| 			if (builders !== false)
| 258|    |-			{
|    | 258|+			
| 259| 259| 				builders.forEach(worker => {
| 260| 260| 					worker.setMetadata(PlayerID, "base", newbase.ID);
| 261| 261| 					worker.setMetadata(PlayerID, "subrole", "builder");
| 262| 262| 					worker.setMetadata(PlayerID, "target-foundation", ent.id());
| 263| 263| 				});
| 264|    |-			}
|    | 264|+			
| 265| 265| 		}
| 266| 266| 		else if (ent.getMetadata(PlayerID, "base") == -2)	// anchorless base around a dock
| 267| 267| 		{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 269| 269| 			// Let's get a few units from other bases there to build this.
| 270| 270| 			let builders = this.bulkPickWorkers(gameState, newbase, 4);
| 271| 271| 			if (builders != false)
| 272|    |-			{
|    | 272|+			
| 273| 273| 				builders.forEach(worker => {
| 274| 274| 					worker.setMetadata(PlayerID, "base", newbase.ID);
| 275| 275| 					worker.setMetadata(PlayerID, "subrole", "builder");
| 276| 276| 					worker.setMetadata(PlayerID, "target-foundation", ent.id());
| 277| 277| 				});
| 278|    |-			}
|    | 278|+			
| 279| 279| 		}
| 280| 280| 	}
| 281| 281| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 395| 395| 	}
| 396| 396| 
| 397| 397| 	for (let evt of events.TrainingFinished)
| 398|    |-	{
|    | 398|+	
| 399| 399| 		for (let entId of evt.entities)
| 400| 400| 		{
| 401| 401| 			let ent = gameState.getEntityById(entId);
| 463| 463| 					ent.moveToRange(goal[0], goal[1]);
| 464| 464| 			}
| 465| 465| 		}
| 466|    |-	}
|    | 466|+	
| 467| 467| 
| 468| 468| 	for (let evt of events.TerritoryDecayChanged)
| 469| 469| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 411| 411| 					this.garrisonManager.registerHolder(gameState, holder);
| 412| 412| 			}
| 413| 413| 			else if (ent.getMetadata(PlayerID, "garrisonType"))
| 414|    |-			{
|    | 414|+			
| 415| 415| 				// we were supposed to be autogarrisoned, but this has failed (may-be full)
| 416| 416| 				ent.setMetadata(PlayerID, "garrisonType", undefined);
| 417|    |-			}
|    | 417|+			
| 418| 418| 
| 419| 419| 			// Check if this unit is no more needed in its attack plan
| 420| 420| 			// (happen when the training ends after the attack is started or aborted)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 482| 482| 	}
| 483| 483| 
| 484| 484| 	if (addBase)
| 485|    |-	{
|    | 485|+	
| 486| 486| 		if (!this.firstBaseConfig)
| 487| 487| 		{
| 488| 488| 			// This is our first base, let us configure our starting resources
| 495| 495| 			this.saveSpace = undefined;
| 496| 496| 			this.maxFields = false;
| 497| 497| 		}
| 498|    |-	}
|    | 498|+	
| 499| 499| 
| 500| 500| 	// Then deals with decaying structures: destroy them if being lost to enemy (except in easier difficulties)
| 501| 501| 	if (this.Config.difficulty < 2)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 484| 484| 	if (addBase)
| 485| 485| 	{
| 486| 486| 		if (!this.firstBaseConfig)
| 487|    |-		{
|    | 487|+		
| 488| 488| 			// This is our first base, let us configure our starting resources
| 489| 489| 			this.configFirstBase(gameState);
| 490|    |-		}
|    | 490|+		
| 491| 491| 		else
| 492| 492| 		{
| 493| 493| 			// Let us hope this new base will fix our possible resource shortage
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 773| 773| 		let aValue = 0.1;
| 774| 774| 		let bValue = 0.1;
| 775| 775| 		for (let param of parameters)
| 776|    |-		{
|    | 776|+		
| 777| 777| 			if (param[0] == "strength")
| 778| 778| 			{
| 779| 779| 				aValue += m.getMaxStrength(a[1]) * param[1];
| 807| 807| 			}
| 808| 808| 			else
| 809| 809| 				API3.warn(" trainMoreUnits avec non prevu " + uneval(param));
| 810|    |-		}
|    | 810|+		
| 811| 811| 		return -aValue/aCost + bValue/bCost;
| 812| 812| 	});
| 813| 813| 	return units[0][0];
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1051|1051| 				continue;
|1052|1052| 
|1053|1053| 			if (minDist > maxAccessDisfavored)     // Disfavor if quite far from any allied cc
|1054|    |-			{
|    |1054|+			
|1055|1055| 				if (!accessible)
|1056|1056| 				{
|1057|1057| 					if (minDist > maxNoAccessDisfavored)
|1061|1061| 				}
|1062|1062| 				else
|1063|1063| 					norm *= 0.5;
|1064|    |-			}
|    |1064|+			
|1065|1065| 
|1066|1066| 			// Not near any of our dropsite, except for oversea docks
|1067|1067| 			oversea = !accessible && dpList.some(dp => m.getLandAccess(gameState, dp.ent) == index);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1053|1053| 			if (minDist > maxAccessDisfavored)     // Disfavor if quite far from any allied cc
|1054|1054| 			{
|1055|1055| 				if (!accessible)
|1056|    |-				{
|    |1056|+				
|1057|1057| 					if (minDist > maxNoAccessDisfavored)
|1058|1058| 						norm *= 0.5;
|1059|1059| 					else
|1060|1060| 						norm *= 0.8;
|1061|    |-				}
|    |1061|+				
|1062|1062| 				else
|1063|1063| 					norm *= 0.5;
|1064|1064| 			}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1066|1066| 			// Not near any of our dropsite, except for oversea docks
|1067|1067| 			oversea = !accessible && dpList.some(dp => m.getLandAccess(gameState, dp.ent) == index);
|1068|1068| 			if (!oversea)
|1069|    |-			{
|    |1069|+			
|1070|1070| 				for (let dp of dpList)
|1071|1071| 				{
|1072|1072| 					let dist = API3.SquareVectorDistance(dp.pos, pos);
|1078|1078| 					else if (dist < 6400)
|1079|1079| 						norm *= 0.5;
|1080|1080| 				}
|1081|    |-			}
|    |1081|+			
|1082|1082| 			if (norm == 0)
|1083|1083| 				continue;
|1084|1084| 		}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1378|1378| 	// do not keep it if gain is too small, except if this is our first BarterMarket
|1379|1379| 	let idx;
|1380|1380| 	if (expectedGain < this.tradeManager.minimalGain)
|1381|    |-	{
|    |1381|+	
|1382|1382| 		if (template.hasClass("BarterMarket") &&
|1383|1383| 		    !gameState.getOwnEntitiesByClass("BarterMarket", true).hasEntities())
|1384|1384| 			idx = -1;	// needed by queueplanBuilding manager to keep that market
|1385|1385| 		else
|1386|1386| 			return false;
|1387|    |-	}
|    |1387|+	
|1388|1388| 	else
|1389|1389| 		idx = this.basesMap.map[bestJdx];
|1390|1390| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1565|1565| 			let cost = queues.economicBuilding.plans[0].getCost();
|1566|1566| 			queueManager.setAccounts(gameState, cost, "economicBuilding");
|1567|1567| 			if (!queueManager.canAfford("economicBuilding", cost))
|1568|    |-			{
|    |1568|+			
|1569|1569| 				for (let q in queueManager.queues)
|1570|1570| 				{
|1571|1571| 					if (q == "economicBuilding")
|1574|1574| 					if (queueManager.canAfford("economicBuilding", cost))
|1575|1575| 						break;
|1576|1576| 				}
|1577|    |-			}
|    |1577|+			
|1578|1578| 		}
|1579|1579| 		return;
|1580|1580| 	}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1624|1624| 		let highLevel = 0;
|1625|1625| 		let lowLevel = 0;
|1626|1626| 		for (let res in cost)
|1627|    |-		{
|    |1627|+		
|1628|1628| 			if (resources[res] && resources[res] > 0.7 * cost[res])
|1629|1629| 				++highLevel;
|1630|1630| 			else if (!resources[res] || resources[res] < 0.3 * cost[res])
|1631|1631| 				++lowLevel;
|1632|    |-		}
|    |1632|+		
|1633|1633| 		if (highLevel == 0 || lowLevel > 1)
|1634|1634| 			return;
|1635|1635| 	}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1750|1750| 	let freeSlots = gameState.getPopulationLimit() + HouseNb*popBonus - this.getAccountedPopulation(gameState);
|1751|1751| 	let priority;
|1752|1752| 	if (freeSlots < 5)
|1753|    |-	{
|    |1753|+	
|1754|1754| 		if (this.buildManager.isUnbuildable(gameState, house))
|1755|1755| 		{
|1756|1756| 			if (this.Config.debug > 1)
|1759|1759| 		}
|1760|1760| 		else
|1761|1761| 			priority = 2*this.Config.priorities.house;
|1762|    |-	}
|    |1762|+	
|1763|1763| 	else
|1764|1764| 		priority = this.Config.priorities.house;
|1765|1765| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1841|1841| 		return;
|1842|1842| 
|1843|1843| 	if (!this.saveResources && (this.currentPhase > 2 || gameState.isResearching(gameState.getPhaseName(3))))
|1844|    |-	{
|    |1844|+	
|1845|1845| 		// try to build fortresses
|1846|1846| 		if (this.canBuild(gameState, "structures/{civ}_fortress"))
|1847|1847| 		{
|1860|1860| 				return;
|1861|1861| 			}
|1862|1862| 		}
|1863|    |-	}
|    |1863|+	
|1864|1864| 
|1865|1865| 	if (this.Config.Military.numSentryTowers && this.currentPhase < 2 && this.canBuild(gameState, "structures/{civ}_sentry_tower"))
|1866|1866| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2004|2004| 		nAdvanced += gameState.countEntitiesAndQueuedByType(advanced, true);
|2005|2005| 
|2006|2006| 	if (!nAdvanced || nAdvanced < this.bAdvanced.length && this.getAccountedPopulation(gameState) > 110)
|2007|    |-	{
|    |2007|+	
|2008|2008| 		for (let advanced of this.bAdvanced)
|2009|2009| 		{
|2010|2010| 			if (gameState.countEntitiesAndQueuedByType(advanced, true) > 0 || !this.canBuild(gameState, advanced))
|2019|2019| 				queues.militaryBuilding.addPlan(new m.ConstructionPlan(gameState, advanced));
|2020|2020| 			return;
|2021|2021| 		}
|2022|    |-	}
|    |2022|+	
|2023|2023| };
|2024|2024| 
|2025|2025| /**
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2107|2107| 	// in which case we prefer melee units
|2108|2108| 	let numGarrisoned = this.garrisonManager.numberOfGarrisonedUnits(nearestAnchor);
|2109|2109| 	if (nearestAnchor._entity.trainingQueue)
|2110|    |-	{
|    |2110|+	
|2111|2111| 		for (let item of nearestAnchor._entity.trainingQueue)
|2112|2112| 		{
|2113|2113| 			if (item.metadata && item.metadata.garrisonType)
|2115|2115| 			else if (!item.progress && (!item.metadata || !item.metadata.trainer))
|2116|2116| 				nearestAnchor.stopProduction(item.id);
|2117|2117| 		}
|2118|    |-	}
|    |2118|+	
|2119|2119| 	let autogarrison = numGarrisoned < nearestAnchor.garrisonMax() &&
|2120|2120| 	                   nearestAnchor.hitpoints() > nearestAnchor.garrisonEjectHealth() * nearestAnchor.maxHitpoints();
|2121|2121| 	let rangedWanted = randBool() && autogarrison;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2109|2109| 	if (nearestAnchor._entity.trainingQueue)
|2110|2110| 	{
|2111|2111| 		for (let item of nearestAnchor._entity.trainingQueue)
|2112|    |-		{
|    |2112|+		
|2113|2113| 			if (item.metadata && item.metadata.garrisonType)
|2114|2114| 				numGarrisoned += item.count;
|2115|2115| 			else if (!item.progress && (!item.metadata || !item.metadata.trainer))
|2116|2116| 				nearestAnchor.stopProduction(item.id);
|2117|    |-		}
|    |2117|+		
|2118|2118| 	}
|2119|2119| 	let autogarrison = numGarrisoned < nearestAnchor.garrisonMax() &&
|2120|2120| 	                   nearestAnchor.hitpoints() > nearestAnchor.garrisonEjectHealth() * nearestAnchor.maxHitpoints();
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2149|2149| 	let cost = new API3.Resources(templateFound[1].cost());
|2150|2150| 	queueManager.setAccounts(gameState, cost, "emergency");
|2151|2151| 	if (!queueManager.canAfford("emergency", cost))
|2152|    |-	{
|    |2152|+	
|2153|2153| 		for (let q in queueManager.queues)
|2154|2154| 		{
|2155|2155| 			if (q == "emergency")
|2158|2158| 			if (queueManager.canAfford("emergency", cost))
|2159|2159| 				break;
|2160|2160| 		}
|2161|    |-	}
|    |2161|+	
|2162|2162| 	let metadata = { "role": "worker", "base": nearestAnchor.getMetadata(PlayerID, "base"), "plan": -1, "trainer": nearestAnchor.id() };
|2163|2163| 	if (autogarrison)
|2164|2164| 		metadata.garrisonType = "protection";
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2439|2439| m.HQ.prototype.assignGatherers = function()
|2440|2440| {
|2441|2441| 	for (let base of this.baseManagers)
|2442|    |-	{
|    |2442|+	
|2443|2443| 		for (let worker of base.workers.values())
|2444|2444| 		{
|2445|2445| 			if (worker.unitAIState().split(".")[1] != "RETURNRESOURCE")
|2449|2449| 				continue;
|2450|2450| 			this.AddTCGatherer(orders[1].target);
|2451|2451| 		}
|2452|    |-	}
|    |2452|+	
|2453|2453| };
|2454|2454| 
|2455|2455| m.HQ.prototype.isDangerousLocation = function(gameState, pos, radius)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2621|2621| 	{
|2622|2622| 		let pop = gameState.getPopulation();
|2623|2623| 		for (let ent of gameState.getOwnTrainingFacilities().values())
|2624|    |-		{
|    |2624|+		
|2625|2625| 			for (let item of ent.trainingQueue())
|2626|2626| 			{
|2627|2627| 				if (!item.unitTemplate)
|2630|2630| 				if (unitPop)
|2631|2631| 					pop += item.count * unitPop;
|2632|2632| 			}
|2633|    |-		}
|    |2633|+		
|2634|2634| 		this.turnCache.accountedPopulation = pop;
|2635|2635| 	}
|2636|2636| 	return this.turnCache.accountedPopulation;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
|2645|2645| 	{
|2646|2646| 		let workers = gameState.getOwnEntitiesByRole("worker", true).length;
|2647|2647| 		for (let ent of gameState.getOwnTrainingFacilities().values())
|2648|    |-		{
|    |2648|+		
|2649|2649| 			for (let item of ent.trainingQueue())
|2650|2650| 			{
|2651|2651| 				if (!item.metadata || !item.metadata.role || item.metadata.role != "worker")
|2652|2652| 					continue;
|2653|2653| 				workers += item.count;
|2654|2654| 			}
|2655|    |-		}
|    |2655|+		
|2656|2656| 		this.turnCache.accountedWorkers = workers;
|2657|2657| 	}
|2658|2658| 	return this.turnCache.accountedWorkers;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js
| 181| 181| 
| 182| 182| 			let dist = API3.SquareVectorDistance(supply.position(), dropsitePos);
| 183| 183| 			if (dist < maxDistResourceSquare)
| 184|    |-			{
|    | 184|+			
| 185| 185| 				if (dist < maxDistResourceSquare/16)        // distmax/4
| 186| 186| 					nearby.push({ "dropsite": dropsiteId, "id": supply.id(), "ent": supply, "dist": dist });
| 187| 187| 				else if (dist < maxDistResourceSquare/4)    // distmax/2
| 188| 188| 					medium.push({ "dropsite": dropsiteId, "id": supply.id(), "ent": supply, "dist": dist });
| 189| 189| 				else
| 190| 190| 					faraway.push({ "dropsite": dropsiteId, "id": supply.id(), "ent": supply, "dist": dist });
| 191|    |-			}
|    | 191|+			
| 192| 192| 		});
| 193| 193| 
| 194| 194| 		nearby.sort((r1, r2) => r1.dist - r2.dist);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js
| 229| 229| 
| 230| 230| 	let removeSupply = function(entId, supply){
| 231| 231| 		for (let i = 0; i < supply.length; ++i)
| 232|    |-		{
|    | 232|+		
| 233| 233| 			// exhausted resource, remove it from this list
| 234| 234| 			if (!supply[i].ent || !gameState.getEntityById(supply[i].id))
| 235| 235| 				supply.splice(i--, 1);
| 236| 236| 			// resource assigned to the removed dropsite, remove it
| 237| 237| 			else if (supply[i].dropsite == entId)
| 238| 238| 				supply.splice(i--, 1);
| 239|    |-		}
|    | 239|+		
| 240| 240| 	};
| 241| 241| 
| 242| 242| 	for (let type in this.dropsiteSupplies)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js
| 432| 432| 		if (gameState.ai.playedTurn < this.gatherers[type].nextCheck)
| 433| 433| 			continue;
| 434| 434| 		for (let ent of this.gatherersByType(gameState, type).values())
| 435|    |-		{
|    | 435|+		
| 436| 436| 			if (ent.unitAIState() == "INDIVIDUAL.GATHER.GATHERING")
| 437| 437| 				++this.gatherers[type].used;
| 438| 438| 			else if (ent.unitAIState() == "INDIVIDUAL.RETURNRESOURCE.APPROACHING")
| 439| 439| 				++this.gatherers[type].lost;
| 440|    |-		}
|    | 440|+		
| 441| 441| 		// TODO  add also a test on remaining resources.
| 442| 442| 		let total = this.gatherers[type].used + this.gatherers[type].lost;
| 443| 443| 		if (total > 150 || total > 60 && type != "wood")
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js
| 449| 449| 				if (newDP.quality > 50 && gameState.ai.HQ.canBuild(gameState, "structures/{civ}_storehouse"))
| 450| 450| 					queues.dropsites.addPlan(new m.ConstructionPlan(gameState, "structures/{civ}_storehouse", { "base": this.ID, "type": type }, newDP.pos));
| 451| 451| 				else if (!gameState.getOwnFoundations().filter(API3.Filters.byClass("CivCentre")).hasEntities() && !queues.civilCentre.hasQueuedUnits())
| 452|    |-				{
|    | 452|+				
| 453| 453| 					// No good dropsite, try to build a new base if no base already planned,
| 454| 454| 					// and if not possible, be less strict on dropsite quality.
| 455| 455| 					if ((!gameState.ai.HQ.canExpand || !gameState.ai.HQ.buildNewBase(gameState, queues, type)) &&
| 456| 456| 					    newDP.quality > Math.min(25, 50*0.15/ratio) &&
| 457| 457| 					    gameState.ai.HQ.canBuild(gameState, "structures/{civ}_storehouse"))
| 458| 458| 						queues.dropsites.addPlan(new m.ConstructionPlan(gameState, "structures/{civ}_storehouse", { "base": this.ID, "type": type }, newDP.pos));
| 459|    |-				}
|    | 459|+				
| 460| 460| 			}
| 461| 461| 			this.gatherers[type].nextCheck = gameState.ai.playedTurn + 20;
| 462| 462| 			this.gatherers[type].used = 0;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js
| 512| 512| 		roleless = this.units.filter(API3.Filters.not(API3.Filters.byHasMetadata(PlayerID, "role"))).values();
| 513| 513| 
| 514| 514| 	for (let ent of roleless)
| 515|    |-	{
|    | 515|+	
| 516| 516| 		if (ent.hasClass("Worker") || ent.hasClass("CitizenSoldier") || ent.hasClass("FishingBoat"))
| 517| 517| 			ent.setMetadata(PlayerID, "role", "worker");
| 518| 518| 		else if (ent.hasClass("Support") && ent.hasClass("Elephant"))
| 519| 519| 			ent.setMetadata(PlayerID, "role", "worker");
| 520|    |-	}
|    | 520|+	
| 521| 521| };
| 522| 522| 
| 523| 523| /**
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js
| 768| 768| 	let availableResources = gameState.ai.queueManager.getAvailableResources(gameState);
| 769| 769| 	let builderRatio = 1;
| 770| 770| 	for (let res of Resources.GetCodes())
| 771|    |-	{
|    | 771|+	
| 772| 772| 		if (availableResources[res] < 200)
| 773| 773| 		{
| 774| 774| 			builderRatio = 0.2;
| 776| 776| 		}
| 777| 777| 		else if (availableResources[res] < 1000)
| 778| 778| 			builderRatio = Math.min(builderRatio, availableResources[res] / 1000);
| 779|    |-	}
|    | 779|+	
| 780| 780| 
| 781| 781| 	for (let target of foundations.values())
| 782| 782| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|  69|  69| 	this.rallyPoint = rallyPoint;
|  70|  70| 	this.overseas = 0;
|  71|  71| 	if (gameState.ai.HQ.navalMap)
|  72|    |-	{
|    |  72|+	
|  73|  73| 		for (let structure of gameState.getEnemyStructures().values())
|  74|  74| 		{
|  75|  75| 			if (this.target && structure.id() != this.target.id())
| 101| 101| 				gameState.ai.HQ.navalManager.setMinimalTransportShips(gameState, sea, 1);
| 102| 102| 			}
| 103| 103| 		}
| 104|    |-	}
|    | 104|+	
| 105| 105| 	this.paused = false;
| 106| 106| 	this.maxCompletingTime = 0;
| 107| 107| 
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 139| 139| 	{
| 140| 140| 		priority = 90;
| 141| 141| 		// basically we want a mix of citizen soldiers so our barracks have a purpose, and champion units.
| 142|    |-		this.unitStat.RangedInfantry    = { "priority": 0.7, "minSize": 5, "targetSize": 20, "batchSize": 5, "classes": ["Infantry", "Ranged", "CitizenSoldier"],
|    | 142|+		this.unitStat.RangedInfantry = { "priority": 0.7, "minSize": 5, "targetSize": 20, "batchSize": 5, "classes": ["Infantry", "Ranged", "CitizenSoldier"],
| 143| 143| 			"interests": [["strength", 3]] };
| 144| 144| 		this.unitStat.MeleeInfantry     = { "priority": 0.7, "minSize": 5, "targetSize": 20, "batchSize": 5, "classes": ["Infantry", "Melee", "CitizenSoldier"],
| 145| 145| 			"interests": [["strength", 3]] };
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 141| 141| 		// basically we want a mix of citizen soldiers so our barracks have a purpose, and champion units.
| 142| 142| 		this.unitStat.RangedInfantry    = { "priority": 0.7, "minSize": 5, "targetSize": 20, "batchSize": 5, "classes": ["Infantry", "Ranged", "CitizenSoldier"],
| 143| 143| 			"interests": [["strength", 3]] };
| 144|    |-		this.unitStat.MeleeInfantry     = { "priority": 0.7, "minSize": 5, "targetSize": 20, "batchSize": 5, "classes": ["Infantry", "Melee", "CitizenSoldier"],
|    | 144|+		this.unitStat.MeleeInfantry = { "priority": 0.7, "minSize": 5, "targetSize": 20, "batchSize": 5, "classes": ["Infantry", "Melee", "CitizenSoldier"],
| 145| 145| 			"interests": [["strength", 3]] };
| 146| 146| 		this.unitStat.ChampRangedInfantry = { "priority": 1, "minSize": 3, "targetSize": 18, "batchSize": 3, "classes": ["Infantry", "Ranged", "Champion"],
| 147| 147| 			"interests": [["strength", 3]] };
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 145| 145| 			"interests": [["strength", 3]] };
| 146| 146| 		this.unitStat.ChampRangedInfantry = { "priority": 1, "minSize": 3, "targetSize": 18, "batchSize": 3, "classes": ["Infantry", "Ranged", "Champion"],
| 147| 147| 			"interests": [["strength", 3]] };
| 148|    |-		this.unitStat.ChampMeleeInfantry  = { "priority": 1, "minSize": 3, "targetSize": 18, "batchSize": 3, "classes": ["Infantry", "Melee", "Champion"],
|    | 148|+		this.unitStat.ChampMeleeInfantry = { "priority": 1, "minSize": 3, "targetSize": 18, "batchSize": 3, "classes": ["Infantry", "Melee", "Champion"],
| 149| 149| 			"interests": [["strength", 3]] };
| 150| 150| 		this.unitStat.RangedCavalry     = { "priority": 0.7, "minSize": 4, "targetSize": 20, "batchSize": 4, "classes": ["Cavalry", "Ranged", "CitizenSoldier"],
| 151| 151| 			"interests": [["strength", 2]] };
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 147| 147| 			"interests": [["strength", 3]] };
| 148| 148| 		this.unitStat.ChampMeleeInfantry  = { "priority": 1, "minSize": 3, "targetSize": 18, "batchSize": 3, "classes": ["Infantry", "Melee", "Champion"],
| 149| 149| 			"interests": [["strength", 3]] };
| 150|    |-		this.unitStat.RangedCavalry     = { "priority": 0.7, "minSize": 4, "targetSize": 20, "batchSize": 4, "classes": ["Cavalry", "Ranged", "CitizenSoldier"],
|    | 150|+		this.unitStat.RangedCavalry = { "priority": 0.7, "minSize": 4, "targetSize": 20, "batchSize": 4, "classes": ["Cavalry", "Ranged", "CitizenSoldier"],
| 151| 151| 			"interests": [["strength", 2]] };
| 152| 152| 		this.unitStat.MeleeCavalry      = { "priority": 0.7, "minSize": 4, "targetSize": 20, "batchSize": 4, "classes": ["Cavalry", "Melee", "CitizenSoldier"],
| 153| 153| 			"interests": [["strength", 2]] };
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 149| 149| 			"interests": [["strength", 3]] };
| 150| 150| 		this.unitStat.RangedCavalry     = { "priority": 0.7, "minSize": 4, "targetSize": 20, "batchSize": 4, "classes": ["Cavalry", "Ranged", "CitizenSoldier"],
| 151| 151| 			"interests": [["strength", 2]] };
| 152|    |-		this.unitStat.MeleeCavalry      = { "priority": 0.7, "minSize": 4, "targetSize": 20, "batchSize": 4, "classes": ["Cavalry", "Melee", "CitizenSoldier"],
|    | 152|+		this.unitStat.MeleeCavalry = { "priority": 0.7, "minSize": 4, "targetSize": 20, "batchSize": 4, "classes": ["Cavalry", "Melee", "CitizenSoldier"],
| 153| 153| 			"interests": [["strength", 2]] };
| 154| 154| 		this.unitStat.ChampRangedCavalry  = { "priority": 1, "minSize": 3, "targetSize": 15, "batchSize": 3, "classes": ["Cavalry", "Ranged", "Champion"],
| 155| 155| 			"interests": [["strength", 3]] };
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 151| 151| 			"interests": [["strength", 2]] };
| 152| 152| 		this.unitStat.MeleeCavalry      = { "priority": 0.7, "minSize": 4, "targetSize": 20, "batchSize": 4, "classes": ["Cavalry", "Melee", "CitizenSoldier"],
| 153| 153| 			"interests": [["strength", 2]] };
| 154|    |-		this.unitStat.ChampRangedCavalry  = { "priority": 1, "minSize": 3, "targetSize": 15, "batchSize": 3, "classes": ["Cavalry", "Ranged", "Champion"],
|    | 154|+		this.unitStat.ChampRangedCavalry = { "priority": 1, "minSize": 3, "targetSize": 15, "batchSize": 3, "classes": ["Cavalry", "Ranged", "Champion"],
| 155| 155| 			"interests": [["strength", 3]] };
| 156| 156| 		this.unitStat.ChampMeleeCavalry   = { "priority": 1, "minSize": 3, "targetSize": 15, "batchSize": 3, "classes": ["Cavalry", "Melee", "Champion"],
| 157| 157| 			"interests": [["strength", 2]] };
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 153| 153| 			"interests": [["strength", 2]] };
| 154| 154| 		this.unitStat.ChampRangedCavalry  = { "priority": 1, "minSize": 3, "targetSize": 15, "batchSize": 3, "classes": ["Cavalry", "Ranged", "Champion"],
| 155| 155| 			"interests": [["strength", 3]] };
| 156|    |-		this.unitStat.ChampMeleeCavalry   = { "priority": 1, "minSize": 3, "targetSize": 15, "batchSize": 3, "classes": ["Cavalry", "Melee", "Champion"],
|    | 156|+		this.unitStat.ChampMeleeCavalry = { "priority": 1, "minSize": 3, "targetSize": 15, "batchSize": 3, "classes": ["Cavalry", "Melee", "Champion"],
| 157| 157| 			"interests": [["strength", 2]] };
| 158| 158| 		this.unitStat.Hero                = { "priority": 1, "minSize": 0, "targetSize": 1, "batchSize": 1, "classes": ["Hero"],
| 159| 159| 			"interests": [["strength", 2]] };
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 155| 155| 			"interests": [["strength", 3]] };
| 156| 156| 		this.unitStat.ChampMeleeCavalry   = { "priority": 1, "minSize": 3, "targetSize": 15, "batchSize": 3, "classes": ["Cavalry", "Melee", "Champion"],
| 157| 157| 			"interests": [["strength", 2]] };
| 158|    |-		this.unitStat.Hero                = { "priority": 1, "minSize": 0, "targetSize": 1, "batchSize": 1, "classes": ["Hero"],
|    | 158|+		this.unitStat.Hero = { "priority": 1, "minSize": 0, "targetSize": 1, "batchSize": 1, "classes": ["Hero"],
| 159| 159| 			"interests": [["strength", 2]] };
| 160| 160| 		this.neededShips = 5;
| 161| 161| 	}
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 164| 164| 		priority = 70;
| 165| 165| 		this.unitStat.RangedInfantry = { "priority": 1, "minSize": 6, "targetSize": 16, "batchSize": 3, "classes": ["Infantry", "Ranged"],
| 166| 166| 			"interests": [["canGather", 1], ["strength", 1.6], ["costsResource", 0.3, "stone"], ["costsResource", 0.3, "metal"]] };
| 167|    |-		this.unitStat.MeleeInfantry  = { "priority": 1, "minSize": 6, "targetSize": 16, "batchSize": 3, "classes": ["Infantry", "Melee"],
|    | 167|+		this.unitStat.MeleeInfantry = { "priority": 1, "minSize": 6, "targetSize": 16, "batchSize": 3, "classes": ["Infantry", "Melee"],
| 168| 168| 			"interests": [["canGather", 1], ["strength", 1.6], ["costsResource", 0.3, "stone"], ["costsResource", 0.3, "metal"]] };
| 169| 169| 		this.unitStat.Cavalry = { "priority": 1, "minSize": 2, "targetSize": 6, "batchSize": 2, "classes": ["Cavalry", "CitizenSoldier"],
| 170| 170| 			"interests": [["strength", 1]] };
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 399| 399| 	// the completing step is used to return resources and regroup the units
| 400| 400| 	// so we check that we have no more forced order before starting the attack
| 401| 401| 	if (this.state == "completing")
| 402|    |-	{
|    | 402|+	
| 403| 403| 		// if our target was destroyed, go back to "unexecuted" state
| 404| 404| 		if (this.targetPlayer === undefined || !this.target || !gameState.getEntityById(this.target.id()))
| 405| 405| 		{
| 416| 416| 				return 1;
| 417| 417| 			return 2;
| 418| 418| 		}
| 419|    |-	}
|    | 419|+	
| 420| 420| 
| 421| 421| 	if (this.Config.debug > 3 && gameState.ai.playedTurn % 50 === 0)
| 422| 422| 		this.debugAttack();
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 525| 525| 
| 526| 526| 	// Remove those units which were in a temporary bombing attack
| 527| 527| 	for (let unitIds of gameState.ai.HQ.attackManager.bombingAttacks.values())
| 528|    |-	{
|    | 528|+	
| 529| 529| 		for (let entId of unitIds.values())
| 530| 530| 		{
| 531| 531| 			let ent = gameState.getEntityById(entId);
| 534| 534| 			unitIds.delete(entId);
| 535| 535| 			ent.stopMoving();
| 536| 536| 		}
| 537|    |-	}
|    | 537|+	
| 538| 538| 
| 539| 539| 	let rallyPoint = this.rallyPoint;
| 540| 540| 	let rallyIndex = gameState.ai.accessibility.getAccessValue(rallyPoint);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
| 872| 872| 			targets.addEnt(ent);
| 873| 873| 	}
| 874| 874| 	else
| 875|    |-	{
|    | 875|+	
| 876| 876| 		if (this.type == "Raid")
| 877| 877| 			targets = this.raidTargetFinder(gameState);
| 878| 878| 		else if (this.type == "Rush" || this.type == "Attack")
| 883| 883| 		}
| 884| 884| 		else
| 885| 885| 			targets = this.defaultTargetFinder(gameState, this.targetPlayer);
| 886|    |-	}
|    | 886|+	
| 887| 887| 	if (!targets.hasEntities())
| 888| 888| 		return undefined;
| 889| 889| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1341|1341| 				}
|1342|1342| 			}
|1343|1343| 			else
|1344|    |-			{
|    |1344|+			
|1345|1345| 				if (this.isBlocked && !ourUnit.hasClass("Ranged") && attacker.hasClass("Ranged"))
|1346|1346| 				{
|1347|1347| 					// do not react if our melee units are attacked by ranged one and we are blocked by walls
|1394|1394| 					ourUnit.attack(attacker.id(), m.allowCapture(gameState, ourUnit, attacker));
|1395|1395| 					ourUnit.setMetadata(PlayerID, "lastAttackPlanUpdateTime", time);
|1396|1396| 				}
|1397|    |-			}
|    |1397|+			
|1398|1398| 		}
|1399|1399| 
|1400|1400| 		let enemyUnits = gameState.getEnemyUnits(this.targetPlayer);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1343|1343| 			else
|1344|1344| 			{
|1345|1345| 				if (this.isBlocked && !ourUnit.hasClass("Ranged") && attacker.hasClass("Ranged"))
|1346|    |-				{
|    |1346|+				
|1347|1347| 					// do not react if our melee units are attacked by ranged one and we are blocked by walls
|1348|1348| 					// TODO check that the attacker is from behind the wall
|1349|1349| 					continue;
|1350|    |-				}
|    |1350|+				
|1351|1351| 				else if (m.isSiegeUnit(attacker))
|1352|1352| 				{	// if our unit is attacked by a siege unit, we'll send some melee units to help it.
|1353|1353| 					let collec = this.unitCollection.filter(API3.Filters.byClass("Melee")).filterNearest(ourUnit.position(), 5);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1386|1386| 							continue;
|1387|1387| 						let target = gameState.getEntityById(orderData[0].target);
|1388|1388| 						if (target && !target.hasClass("Structure") && !target.hasClass("Support"))
|1389|    |-						{
|    |1389|+						
|1390|1390| 							if (!target.hasClass("Ranged") || !attacker.hasClass("Melee"))
|1391|1391| 								continue;
|1392|    |-						}
|    |1392|+						
|1393|1393| 					}
|1394|1394| 					ourUnit.attack(attacker.id(), m.allowCapture(gameState, ourUnit, attacker));
|1395|1395| 					ourUnit.setMetadata(PlayerID, "lastAttackPlanUpdateTime", time);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1414|1414| 			if (!target || target.hasClass("Structure"))
|1415|1415| 				continue;
|1416|1416| 			if (!(targetId in unitTargets))
|1417|    |-			{
|    |1417|+			
|1418|1418| 				if (m.isSiegeUnit(target) || target.hasClass("Hero"))
|1419|1419| 					unitTargets[targetId] = -8;
|1420|1420| 				else if (target.hasClass("Champion") || target.hasClass("Ship"))
|1421|1421| 					unitTargets[targetId] = -5;
|1422|1422| 				else
|1423|1423| 					unitTargets[targetId] = -3;
|1424|    |-			}
|    |1424|+			
|1425|1425| 			++unitTargets[targetId];
|1426|1426| 		}
|1427|1427| 		let veto = {};
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1434|1434| 		if (this.type == "Rush")
|1435|1435| 			targetClassesUnit = { "attack": ["Unit", "Structure"], "avoid": ["Palisade", "StoneWall", "Tower", "Fortress"], "vetoEntities": veto };
|1436|1436| 		else
|1437|    |-		{
|    |1437|+		
|1438|1438| 			if (this.target.hasClass("Fortress"))
|1439|1439| 				targetClassesUnit = { "attack": ["Unit", "Structure"], "avoid": ["Palisade", "StoneWall"], "vetoEntities": veto };
|1440|1440| 			else if (this.target.hasClass("Palisade") || this.target.hasClass("StoneWall"))
|1441|1441| 				targetClassesUnit = { "attack": ["Unit", "Structure"], "avoid": ["Fortress"], "vetoEntities": veto };
|1442|1442| 			else
|1443|1443| 				targetClassesUnit = { "attack": ["Unit", "Structure"], "avoid": ["Palisade", "StoneWall", "Fortress"], "vetoEntities": veto };
|1444|    |-		}
|    |1444|+		
|1445|1445| 		if (this.target.hasClass("Structure"))
|1446|1446| 			targetClassesSiege = { "attack": ["Structure"], "avoid": [], "vetoEntities": veto };
|1447|1447| 		else
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1525|1525| 			let range = 60;
|1526|1526| 			let attackTypes = ent.attackTypes();
|1527|1527| 			if (this.isBlocked)
|1528|    |-			{
|    |1528|+			
|1529|1529| 				if (attackTypes && attackTypes.indexOf("Ranged") !== -1)
|1530|1530| 					range = ent.attackRange("Ranged").max;
|1531|1531| 				else if (attackTypes && attackTypes.indexOf("Melee") !== -1)
|1532|1532| 					range = ent.attackRange("Melee").max;
|1533|1533| 				else
|1534|1534| 					range = 10;
|1535|    |-			}
|    |1535|+			
|1536|1536| 			else if (attackTypes && attackTypes.indexOf("Ranged") !== -1)
|1537|1537| 				range = 30 + ent.attackRange("Ranged").max;
|1538|1538| 			else if (ent.hasClass("Cavalry"))
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1581|1581| 					}
|1582|1582| 				}
|1583|1583| 				else
|1584|    |-				{
|    |1584|+				
|1585|1585| 					if (!ent.hasClass("Ranged"))
|1586|1586| 					{
|1587|1587| 						let targetClasses = { "attack": targetClassesSiege.attack, "avoid": targetClassesSiege.avoid.concat("Ship"), "vetoEntities": veto };
|1589|1589| 					}
|1590|1590| 					else
|1591|1591| 						ent.attackMove(this.targetPos[0], this.targetPos[1], targetClassesSiege);
|1592|    |-				}
|    |1592|+				
|1593|1593| 			}
|1594|1594| 			else
|1595|1595| 			{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1643|1643| 				{
|1644|1644| 					let targetClasses = targetClassesUnit;
|1645|1645| 					if (maybeUpdate && ent.unitAIState() === "INDIVIDUAL.COMBAT.APPROACHING")	// we may be blocked by walls, attack everything
|1646|    |-					{
|    |1646|+					
|1647|1647| 						if (!ent.hasClass("Ranged") && !ent.hasClass("Ship"))
|1648|1648| 							targetClasses = { "attack": ["Unit", "Structure"], "avoid": ["Ship"], "vetoEntities": veto };
|1649|1649| 						else
|1650|1650| 							targetClasses = { "attack": ["Unit", "Structure"], "vetoEntities": veto };
|1651|    |-					}
|    |1651|+					
|1652|1652| 					else if (!ent.hasClass("Ranged") && !ent.hasClass("Ship"))
|1653|1653| 						targetClasses = { "attack": targetClassesUnit.attack, "avoid": targetClassesUnit.avoid.concat("Ship"), "vetoEntities": veto };
|1654|1654| 					ent.attackMove(this.targetPos[0], this.targetPos[1], targetClasses);
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1789|1789| 	}
|1790|1790| 	// Are we arrived at destination ?
|1791|1791| 	if (attackedNB > 1 && (attackedUnitNB || this.hasSiegeUnits()))
|1792|    |-	{
|    |1792|+	
|1793|1793| 		if (gameState.ai.HQ.territoryMap.getOwner(this.position) === this.targetPlayer || attackedNB > 3)
|1794|1794| 		{
|1795|1795| 			this.state = "arrived";
|1796|1796| 			return true;
|1797|1797| 		}
|1798|    |-	}
|    |1798|+	
|1799|1799| 
|1800|1800| 	// basically haven't moved an inch: very likely stuck)
|1801|1801| 	if (API3.SquareVectorDistance(this.position, this.position5TurnsAgo) < 10 && this.path.length > 0 && gameState.ai.playedTurn % 5 === 0)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/attackPlan.js
|1915|1915| 			// Check if we could help any current attack
|1916|1916| 			let attackManager = gameState.ai.HQ.attackManager;
|1917|1917| 			for (let attackType in attackManager.startedAttacks)
|1918|    |-			{
|    |1918|+			
|1919|1919| 				for (let attack of attackManager.startedAttacks[attackType])
|1920|1920| 				{
|1921|1921| 					if (attack.name == this.name)
|1934|1934| 					this.targetPos = this.target.position();
|1935|1935| 					return true;
|1936|1936| 				}
|1937|    |-			}
|    |1937|+			
|1938|1938| 
|1939|1939| 			// If not, let's look for another enemy
|1940|1940| 			if (!this.target)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js
|  64|  64| 	}
|  65|  65| 
|  66|  66| 	for (let i = 0; i < gameState.ai.accessibility.regionSize.length; ++i)
|  67|    |-	{
|    |  67|+	
|  68|  68| 		if (!gameState.ai.HQ.navalRegions[i])
|  69|  69| 		{
|  70|  70| 			// push dummies
| 101| 101| 			this.neededTransportShips.push(0);
| 102| 102| 			this.neededWarShips.push(0);
| 103| 103| 		}
| 104|    |-	}
|    | 104|+	
| 105| 105| 
| 106| 106| 	if (deserializing)
| 107| 107| 		return;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js
| 125| 125| 	}
| 126| 126| 	// and keep only thoses with enough room around when possible
| 127| 127| 	for (let land in this.landingZones)
| 128|    |-	{
|    | 128|+	
| 129| 129| 		for (let sea in this.landingZones[land])
| 130| 130| 		{
| 131| 131| 			let landing = this.landingZones[land][sea];
| 152| 152| 					landing.delete(i);
| 153| 153| 			}
| 154| 154| 		}
| 155|    |-	}
|    | 155|+	
| 156| 156| 
| 157| 157| 	// Assign our initial docks and ships
| 158| 158| 	for (let ship of this.ships.values())
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-of'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js
| 147| 147| 			}
| 148| 148| 			nbcut = Math.min(2, nbcut);
| 149| 149| 			for (let i of landing)
| 150|    |-			{
|    | 150|+			
| 151| 151| 				if (nbaround[i] < nbcut)
| 152| 152| 					landing.delete(i);
| 153|    |-			}
|    | 153|+			
| 154| 154| 		}
| 155| 155| 	}
| 156| 156| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js
| 716| 716| 		return;
| 717| 717| 
| 718| 718| 	if (gameState.ai.HQ.getAccountedPopulation(gameState) > this.Config.Economy.popForDock)
| 719|    |-	{
|    | 719|+	
| 720| 720| 		if (queues.dock.countQueuedUnitsWithClass("NavalMarket") === 0 &&
| 721| 721| 			!gameState.getOwnStructures().filter(API3.Filters.and(API3.Filters.byClass("NavalMarket"), API3.Filters.isFoundation())).hasEntities() &&
| 722| 722| 			gameState.ai.HQ.canBuild(gameState, "structures/{civ}_dock"))
| 741| 741| 				}
| 742| 742| 			}
| 743| 743| 		}
| 744|    |-	}
|    | 744|+	
| 745| 745| 
| 746| 746| 	if (gameState.currentPhase() < 2 || gameState.ai.HQ.getAccountedPopulation(gameState) < this.Config.Economy.popPhase2 + 15 ||
| 747| 747| 	    queues.militaryBuilding.hasQueuedUnits())
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
|  49|  49| 					break;
|  50|  50| 				}
|  51|  51| 				if (!hasDropsite)
|  52|    |-				{
|    |  52|+				
|  53|  53| 					for (let unit of gameState.getOwnUnits().filter(API3.Filters.byClass("Support")).values())
|  54|  54| 					{
|  55|  55| 						if (!unit.position() || m.getLandAccess(gameState, unit) != plan.endIndex)
|  60|  60| 						hasDropsite = true;
|  61|  61| 						break;
|  62|  62| 					}
|  63|    |-				}
|    |  63|+				
|  64|  64| 				if (!hasDropsite)
|  65|  65| 					plan.removeUnit(gameState, ent);
|  66|  66| 			}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
| 206| 206| 			// TODO if we already carry the max we can ->  returnresources
| 207| 207| 			if (!ent.resourceCarrying() || !ent.resourceCarrying().length ||
| 208| 208| 				ent.resourceCarrying()[0].type == ent.getMetadata(PlayerID, "gather-type"))
| 209|    |-			{
|    | 209|+			
| 210| 210| 				this.startGathering(gameState);
| 211|    |-			}
|    | 211|+			
| 212| 212| 			else if (!m.returnResources(gameState, ent))     // try to deposit resources
| 213| 213| 			{
| 214| 214| 				// no dropsite, abandon old resources and start gathering new ones
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
| 210| 210| 				this.startGathering(gameState);
| 211| 211| 			}
| 212| 212| 			else if (!m.returnResources(gameState, ent))     // try to deposit resources
| 213|    |-			{
|    | 213|+			
| 214| 214| 				// no dropsite, abandon old resources and start gathering new ones
| 215| 215| 				this.startGathering(gameState);
| 216|    |-			}
|    | 216|+			
| 217| 217| 		}
| 218| 218| 		else if (unitAIStateOrder == "GATHER")
| 219| 219| 		{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
| 281| 281| 				{
| 282| 282| 					let nearby = this.base.dropsiteSupplies[gatherType].nearby;
| 283| 283| 					if (!nearby.some(sup => sup.id == supplyId))
| 284|    |-					{
|    | 284|+					
| 285| 285| 						if (nearby.length)
| 286| 286| 							ent.setMetadata(PlayerID, "supply", undefined);
| 287| 287| 						else
| 290| 290| 							if (!medium.some(sup => sup.id == supplyId) && medium.length)
| 291| 291| 								ent.setMetadata(PlayerID, "supply", undefined);
| 292| 292| 						}
| 293|    |-					}
|    | 293|+					
| 294| 294| 				}
| 295| 295| 			}
| 296| 296| 		}
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'else'.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
| 386| 386| 			}
| 387| 387| 		}
| 388| 388| 		else	// Perform some sanity checks
| 389|    |-		{
|    | 389|+		
| 390| 390| 			if (unitAIStateOrder == "GATHER" || unitAIStateOrder == "RETURNRESOURCE")
| 391| 391| 			{
| 392| 392| 				// we may have drifted towards ennemy territory during the hunt, if yes go home
| 401| 401| 						m.returnResources(gameState, ent);
| 402| 402| 				}
| 403| 403| 			}
| 404|    |-		}
|    | 404|+		
| 405| 405| 	}
| 406| 406| 	else if (subrole == "fisher")
| 407| 407| 	{
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
| 404| 404| 		}
| 405| 405| 	}
| 406| 406| 	else if (subrole == "fisher")
| 407|    |-	{
|    | 407|+	
| 408| 408| 		if (ent.isIdle())
| 409| 409| 			this.startFishing(gameState);
| 410| 410| 		else	// if we have drifted towards ennemy territory during the fishing, go home
| 413| 413| 			if (territoryOwner != 0 && !gameState.isPlayerAlly(territoryOwner))  // player is its own ally
| 414| 414| 				this.startFishing(gameState);
| 415| 415| 		}
| 416|    |-	}
|    | 416|+	
| 417| 417| };
| 418| 418| 
| 419| 419| m.Worker.prototype.retryWorking = function(gameState, subrole)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
| 544| 544| 		}
| 545| 545| 	}
| 546| 546| 	if (resource == "food")	// --> for food, try to gather from fields if any, otherwise build one if any
| 547|    |-	{
|    | 547|+	
| 548| 548| 		for (let base of gameState.ai.HQ.baseManagers)
| 549| 549| 		{
| 550| 550| 			if (base.ID == this.baseID)
| 566| 566| 				return true;
| 567| 567| 			}
| 568| 568| 		}
| 569|    |-	}
|    | 569|+	
| 570| 570| 	for (let base of gameState.ai.HQ.baseManagers)
| 571| 571| 	{
| 572| 572| 		if (base.ID == this.baseID)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js
| 617| 617| 		}
| 618| 618| 	}
| 619| 619| 	if (resource == "food")	// --> for food, try to gather from fields if any, otherwise build one if any
| 620|    |-	{
|    | 620|+	
| 621| 621| 		for (let base of gameState.ai.HQ.baseManagers)
| 622| 622| 		{
| 623| 623| 			if (base.accessIndex == this.entAccess)
| 637| 637| 				return true;
| 638| 638| 			}
| 639| 639| 		}
| 640|    |-	}
|    | 640|+	
| 641| 641| 	for (let base of gameState.ai.HQ.baseManagers)
| 642| 642| 	{
| 643| 643| 		if (base.accessIndex == this.entAccess)
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/87/display/redirect

Krinkle marked an inline comment as done.Jul 15 2019, 6:46 PM

It seems the Jenkins build did not apply the parent patch from the stack, hence there are violations found (naturally) for the rules we proposed to disable (curly, and no-multi-spaces).

Krinkle edited the summary of this revision. (Show Details)Jul 15 2019, 6:50 PM
Krinkle updated the Trac tickets for this revision.Jul 20 2019, 9:32 PM
Krinkle updated this revision to Diff 9023.Jul 20 2019, 10:20 PM
Krinkle edited the summary of this revision. (Show Details)

Build failure - The Moirai have given mortals hearts that can endure.

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/156/display/redirect

elexis updated the Trac tickets for this revision.Aug 29 2019, 5:46 PM
elexis requested changes to this revision.Aug 29 2019, 6:21 PM
elexis added a subscriber: elexis.

Taking this out of the review queue until D2103 is addressed, then this needs a rebase where most of the code is dropped.

This revision now requires changes to proceed.Aug 29 2019, 6:21 PM
Krinkle updated this revision to Diff 9547.Aug 31 2019, 4:57 PM
Krinkle edited the summary of this revision. (Show Details)
Krinkle edited the test plan for this revision. (Show Details)

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

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/521/display/redirect

Krinkle edited the test plan for this revision. (Show Details)Aug 31 2019, 5:08 PM

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

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/12/display/redirect

elexis accepted this revision.Sep 2 2019, 11:13 PM

Thanks for having cleaned all Petra ESLint issues, I think its the first "finished" folder sinec we introduced it in 2016!

This revision is now accepted and ready to land.Sep 2 2019, 11:13 PM