Page MenuHomeWildfire Games

Let mods prevent resources from being bartered, traded and/or tributed.
Needs ReviewPublic

Authored by Freagarach on Apr 24 2019, 3:31 PM.

Details

Reviewers
None
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Trac Tickets
#4370
Summary

Adds code so that mods can prevent resources from being bartered, traded and/or tributed. Nothing specified means that all can be done.
Also adds a currency option, which allows resources to only be sold into the currency, but currency can be sold into all other resources. (Petra-AI Complies.)

Test Plan

Set "tradable", "barterable" and/or "tributable" to false and see how it works. Also add isCurrency to resources with at most one as true. If all resources' isCurrency are set to false it should give normal behaviour.

Diff Detail

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

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
Stan added inline comments.Apr 24 2019, 4:04 PM
binaries/data/mods/public/globalscripts/Resources.js
40

I think it could be replaced by if (!data.canExchange || data.canExchange == true) same for the below statements.

You can also probably find a way to inline the else with that.

Freagarach added inline comments.Apr 24 2019, 5:15 PM
binaries/data/mods/public/globalscripts/Resources.js
40

I've tried that, but since data.canExchange is a bool, it will return true if "canExchange":false. That took me a looong while to circumvent. Any tips on how to make this cleaner is welcome ;)

138

Yep I forgot it again ;)

178

I guess not? It is even worse: I use the other function nowhere.
But would this.GetTributable().filter(res => res).keys() return all resources in that object?

I still fail to grasp how the => thing works,,,

Thank you for this patch. Wouldn't it be better to set these attributes explicitly for all resources? E.g. simulation/data/resources/food.json:

{
	"code": "food",
	"name": "Food",
	"description": "Harvest from animals, berry bushes, fish, or fields.",
	"order": 1,
	"subtypes": {
		"fish": "Fish",
		"fruit": "Fruit",
		"grain": "Grain",
		"meat": "Meat"
	},
	"truePrice": 100,

	"barterable": true,
	"exchangable": true,
	"tradable": true,
	"tributable": true,
	"aiAnalysisInfluenceGroup": "ignore"
}

Could you also post screenshots to show what happens if one or more of these new resource attributes is false?

Also, if you try to befriend an AI, it occassionally demands 1000 of a resource; does the AI know it shouldn't ask for non-tributable resources?

Stan added inline comments.Apr 24 2019, 5:39 PM
binaries/data/mods/public/globalscripts/Resources.js
40

@Nescio is right, it's better to specify in the resource.json if the resource is tradeable, barterable, and tributable. This way if you forget you will get a nice error like you did on the forums.

Then assume the value exists. Also can exchange is useless cause it's basically the combination of the three others.

this.resourceTradable[data.code] = data.canTrade;
if (data.canTrade == true)
{
    this.resourceTradables.push(data.code);
}

this.resourceBarterable[data.code] = data.canBarter;
if (data.canBarter == true)
{
    this.canBarter.push(data.code);
}

this.resourceTributable[data.code] = data.canTribute;
if (data.canTribute == true)
{
    this.resourceTributables.push(data.code);
}
178

(res => res)

is equals to this

/**
 * @param {bool} a 
 */
let f = function (a)
{
    return a;
}

So in case of filter for each object of the array/object if the value is true, the object will be added in a new collection.

Then keys will only get the food, wood metal strings.

Yes, it would indeed be better, but if it is like this one can just add a new resource exactly the same way as before. I don't mind to copy extra code when making a new resource, but I reckoned this is less prone to error?
The screenshots I cannot add, but the icon is just not shown in the trade/diplomacy window. Except the small barter window when selecting the market, I couldn't find what to change to make sure that is not shown there.
I haven't changed the AI, so that will still ask for the resources and barter them also I guess, I didn't check actually. I can try and look for the code in Petra to fix it, but that will take some time.

Stan added a comment.Apr 24 2019, 6:04 PM

Yeah, we have to make sure Petra is gonna deal with it. It probably will but it's best to make sure.

There is a bit of balance between forcing the modders to be rigorous, and trying to prevent edge case. The more is set in stone without restricting them the better.

smiley added a subscriber: smiley.Apr 24 2019, 9:20 PM

Angen also have a patch doing this. See the mythology mod.

Stan added a subscriber: Angen.Apr 25 2019, 9:47 AM

@Angen I know you have little time but do you have some suggestions ? :)

I'm already checking out the code there, it is quite similar but has a few things I didn't think of.

elexis added a subscriber: elexis.Apr 25 2019, 11:23 AM

Might want to link the other code for comparison.

binaries/data/mods/public/globalscripts/Resources.js
15

Confusing naming. resourceTributable, resourceTributableCodes

40

I've tried that, but since data.canExchange is a bool, it will return true if "canExchange":false. That took me a looong while to circumvent. Any tips on how to make this cleaner is welcome ;)

Sounds like missing parenthesis https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence

if (typeof(data.canExchange) == "undefined" ? true : data.canExchange == true)
->
if (data.canExchange)
https://developer.mozilla.org/en-US/docs/Glossary/Falsy

If the property was not defined for some resources, then one can use if (!!data.canExchange) to circumvent the undefined warning.
But the property should also always be defined in the resource.

69

{ and } on a separate line

if (x)
y= true
else
y= false

is the same as
y = x

as Stan pointed out

87

Should be possible to remove the duplication

178

I still fail to grasp how the => thing works,,,

Arrow functions is just a different syntax for functions as Stan mentioned.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

collection

(JS doesn't have collections afaik, only arrays and objects)

{ "food", "metal", ... }

That's not legal JS, braces indicate an object, but content indicates an array, so [ "val1", "val2", ...]

Is the performance so bad that you need to cache them instead of returning

When the resource-agnostic patch was done by s0600204 and me, we went for caching because there are only a handful of resources, so very few memory allocation and many references to resourceData, resourceDataObj, resourceCodes, resourceNames in GUI and simulation.

Here it's only GUI, and only upon trade/barter dialog resizing only, and upon player Commands. Still not a problem, and code consistency isn't so bad.
We also have to remember that globalscripts are loaded from scratch everytime a new GUI page is opened, each message box.

One must look at the actual callers to see if the caching makes any sense. (Actually doesn't look like it's really adding benefit, because the callers do tons of other stuff looping over resources already, but I can't go through these lines each now)

binaries/data/mods/public/gui/session/menu.js
885–887

newline after => {, missing semicolon (and another newline) after the barterUpdateCommon statement

binaries/data/mods/public/simulation/components/Player.js
423

!x

425

Most of the errors don't uneval any arguments and just print the identifier (rP14417 and rP18964 introduced the one below).

Actually it sounds wrong to throw an error when processing invalid player commands, since the error would occur in the GUI of one client, not in the simulation of every client processing that command. But it should be consistent, and we have many places checking for illegal commands (most notably Commands.js).

Perhaps it can be demoted to a warn() at least (the error should happen in the GUI if it's possible to trigger it, or better making it impossible to trigger it.)

Why not just loop over GetTradable(s)?

(A certain other project also has this feature implemented. Mostly irrelevant, but if this is not committed before the first release, it might be of some interest)

Stan added a comment.Apr 25 2019, 11:32 AM
binaries/data/mods/public/globalscripts/Resources.js
87

Yep could definitely be made in a function.

Freagarach marked 2 inline comments as done.Apr 25 2019, 12:17 PM
Freagarach added inline comments.
binaries/data/mods/public/globalscripts/Resources.js
178

Here it's only GUI, (...)

Doesn't the AI call these functions also?

binaries/data/mods/public/simulation/components/Player.js
425

Why not just loop over GetTradable(s)?

Well, in a way it loops over GetTradables, since this.tradingGoods is defined using GetTradables, so I guess this check is unnecessary then.

Freagarach updated this revision to Diff 7846.Apr 25 2019, 2:07 PM

Some fixes and Petra-AI should now follow the constraints, which is difficult to test fully.

Owners added a subscriber: Restricted Owners Package.Apr 25 2019, 2:07 PM

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

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/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  38|  38| 		// Specify whether resources can be exchanged
|  39|  39| 		this.resourceTradable[data.code] = data.tradable;
|  40|  40| 		if (data.tradable == true)
|  41|    |-		{
|    |  41|+		
|  42|  42| 			this.resourceTradables.push(data.code);
|  43|    |-		}
|    |  43|+		
|  44|  44| 
|  45|  45| 		this.resourceBarterable[data.code] = data.barterable;
|  46|  46| 		if (data.barterable == true)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  44|  44| 
|  45|  45| 		this.resourceBarterable[data.code] = data.barterable;
|  46|  46| 		if (data.barterable == true)
|  47|    |-		{
|    |  47|+		
|  48|  48| 			this.resourceBarterables.push(data.code);
|  49|    |-		}
|    |  49|+		
|  50|  50| 
|  51|  51| 		this.resourceTributable[data.code] = data.tributable;
|  52|  52| 		if (data.tributable == true)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  50|  50| 
|  51|  51| 		this.resourceTributable[data.code] = data.tributable;
|  52|  52| 		if (data.tributable == true)
|  53|    |-		{
|    |  53|+		
|  54|  54| 		    this.resourceTributables.push(data.code);
|  55|    |-		}
|    |  55|+		
|  56|  56| 
|  57|  57| 		for (let subres in data.subtypes)
|  58|  58| 			this.resourceNames[subres] = data.subtypes[subres];
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 3 tabs but found 2.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  61|  61| 	// Sort arrays by specified order
|  62|  62| 	let resSort = (a, b) =>
|  63|  63| 		a.order < b.order ? -1 :
|  64|    |-		a.order > b.order ? +1 : 0;
|    |  64|+			a.order > b.order ? +1 : 0;
|  65|  65| 
|  66|  66| 	this.resourceData.sort(resSort);
|  67|  67| 	this.resourceCodes.sort((a, b) => resSort(
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["sell"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|  95|  95| 	amountsToSubtract[resourceToSell] = amount;
|  96|  96| 	if (cmpPlayer.TrySubtractResources(amountsToSubtract))
|  97|  97| 	{
|  98|    |-		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
|    |  98|+		var amountToAdd = Math.round(prices.sell[resourceToSell] / prices["buy"][resourceToBuy] * amount);
|  99|  99| 		cmpPlayer.AddResource(resourceToBuy, amountToAdd);
| 100| 100| 
| 101| 101| 		// Display chat message to observers
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["buy"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|  95|  95| 	amountsToSubtract[resourceToSell] = amount;
|  96|  96| 	if (cmpPlayer.TrySubtractResources(amountsToSubtract))
|  97|  97| 	{
|  98|    |-		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
|    |  98|+		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices.buy[resourceToBuy] * amount);
|  99|  99| 		cmpPlayer.AddResource(resourceToBuy, amountToAdd);
| 100| 100| 
| 101| 101| 		// Display chat message to observers

binaries/data/mods/public/simulation/components/Barter.js
|  98| »   »   var·amountToAdd·=·Math.round(prices["sell"][resourceToSell]·/·prices["buy"][resourceToBuy]·*·amount);
|    | [NORMAL] JSHintBear:
|    | ['sell'] is better written in dot notation.

binaries/data/mods/public/simulation/components/Barter.js
|  98| »   »   var·amountToAdd·=·Math.round(prices["sell"][resourceToSell]·/·prices["buy"][resourceToBuy]·*·amount);
|    | [NORMAL] JSHintBear:
|    | ['buy'] is better written in dot notation.

binaries/data/mods/public/simulation/components/Player.js
| 385| »   for·(var·type·in·amounts)
|    | [NORMAL] JSHintBear:
|    | 'type' is already defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 452| 452| 				continue;
| 453| 453| 
| 454| 454| 			if (state.pack.progress == 0)
| 455|    |-			{
|    | 455|+			
| 456| 456| 				if (state.pack.packed)
| 457| 457| 					checks.unpackButton = true;
| 458| 458| 				else
| 459| 459| 					checks.packButton = true;
| 460|    |-			}
|    | 460|+			
| 461| 461| 			else if (state.pack.packed)
| 462| 462| 				checks.unpackCancelButton = true;
| 463| 463| 			else
|    | [NORMAL] ESLintBear (space-before-function-paren):
|    | Unexpected space before function parentheses.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 763| 763| 				addResearchToQueue(data.item.researchFacilityId, t);
| 764| 764| 			})(tech);
| 765| 765| 
| 766|    |-			button.onPressRight = (t => function () {
|    | 766|+			button.onPressRight = (t => function() {
| 767| 767| 				showTemplateDetails(
| 768| 768| 					t,
| 769| 769| 					GetTemplateData(data.unitEntStates.find(state => state.id == data.item.researchFacilityId).template).nativeCiv);
|    | [NORMAL] ESLintBear (semi):
|    | Missing semicolon.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 941| 941| 			"player": data.player
| 942| 942| 		});
| 943| 943| 
| 944|    |-		let unitIds = data.unitEntStates.map(status => status.id)
|    | 944|+		let unitIds = data.unitEntStates.map(status => status.id);
| 945| 945| 		let [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch] =
| 946| 946| 			getTrainingStatus(unitIds, data.item, data.playerState);
| 947| 947| 

binaries/data/mods/public/gui/session/selection_panels.js
|  48| »   »   »   switch·(data.item)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
|  59| »   »   switch·(data.item)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
| 731| »   »   »   »   »   »   switch·(entity.check)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
| 944| »   »   let·unitIds·=·data.unitEntStates.map(status·=>·status.id)
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /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
| 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.
|----|    | /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;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 102| 102| 				if (!mostNeeded)
| 103| 103| 					mostNeeded = gameState.ai.HQ.pickMostNeededResources(gameState);
| 104| 104| 				for (let k = 0; k < 2; ++k)
| 105|    |-				{
|    | 105|+				
| 106| 106| 					if (mostNeeded[k].type == res && mostNeeded[k].wanted > 0)
| 107| 107| 					{
| 108| 108| 						this.nextTributeRequest.set("all", gameState.ai.elapsedTime + 90);
| 112| 112| 							API3.warn("Tribute on " + res + " requested to player " + i);
| 113| 113| 						break;
| 114| 114| 					}
| 115|    |-				}
|    | 115|+				
| 116| 116| 			}
| 117| 117| 		}
| 118| 118| 		if (!toSend)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 159| 159| 			continue;
| 160| 160| 		let tributes = 0;
| 161| 161| 		for (let key in evt.amounts)
| 162|    |-		{
|    | 162|+		
| 163| 163| 			if (key === "food")
| 164| 164| 				tributes += evt.amounts[key];
| 165| 165| 			else
| 166| 166| 				tributes += 2*evt.amounts[key];
| 167|    |-		}
|    | 167|+		
| 168| 168| 		this.Config.personality.cooperative = Math.min(1, this.Config.personality.cooperative + 0.0001 * tributes);
| 169| 169| 	}
| 170| 170| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 238| 238| 
| 239| 239| 		// Our diplomacy will have changed already if the response was "accept"
| 240| 240| 		if (request.status === "waitingForTribute")
| 241|    |-		{
|    | 241|+		
| 242| 242| 			Engine.PostCommand(PlayerID, {
| 243| 243| 				"type": "tribute-request",
| 244| 244| 				"source": PlayerID,
| 246| 246| 				"resourceWanted": request.wanted,
| 247| 247| 				"resourceType": request.type
| 248| 248| 			});
| 249|    |-		}
|    | 249|+		
| 250| 250| 	}
| 251| 251| 
| 252| 252| 	// An AI player we sent a diplomacy request to demanded we send them a tribute
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 445| 445| {
| 446| 446| 	for (let [player, data] of this.receivedDiplomacyRequests)
| 447| 447| 		if (data.status === "waitingForTribute" && gameState.ai.elapsedTime > data.warnTime)
| 448|    |-		{
|    | 448|+		
| 449| 449| 			if (data.sentWarning)
| 450| 450| 			{
| 451| 451| 				this.receivedDiplomacyRequests.delete(player);
| 460| 460| 					"type": data.type
| 461| 461| 				});
| 462| 462| 			}
| 463|    |-		}
|    | 463|+		
| 464| 464| };
| 465| 465| 
| 466| 466| /**

binaries/data/mods/public/gui/session/menu.js
| 482| »   »   button.onPress·=·(function(player,·stance)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'stance' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'resCode' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'button' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 557| »   button.onPress·=·(function(i)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 623| »   button.onPress·=·(function(i,·button)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 623| »   button.onPress·=·(function(i,·button)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'button' is already declared in the upper scope.
Executing section cli...

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

Freagarach marked 3 inline comments as done and an inline comment as not done.Apr 25 2019, 2:12 PM
Stan added inline comments.Apr 25 2019, 2:27 PM
binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
411

Why not

for (let i = 0; Resource.GetCodes().length; ++i)
{
 ...
}

Also this function should request tributes anyways. You just need to pick the most wanted tributable resource. The check should probably done in gameState.ai.HQ.pickMostNeededResources(gameState)[i]

Freagarach updated this revision to Diff 7847.Apr 25 2019, 2:46 PM

Fixed tests.

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/components/tests/test_Player.js
|  16| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  28| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  40| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  16| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  28| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  40| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Barter.js
|  50| let·cmpBarter·=·ConstructComponent(SYSTEM_ENTITY,·"Barter");
|    | [NORMAL] JSHintBear:
|    | 'cmpBarter' was used before it was defined.

binaries/data/mods/public/simulation/components/Player.js
| 385| »   for·(var·type·in·amounts)
|    | [NORMAL] JSHintBear:
|    | 'type' is already defined.
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /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
| 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.
|----|    | /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;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 102| 102| 				if (!mostNeeded)
| 103| 103| 					mostNeeded = gameState.ai.HQ.pickMostNeededResources(gameState);
| 104| 104| 				for (let k = 0; k < 2; ++k)
| 105|    |-				{
|    | 105|+				
| 106| 106| 					if (mostNeeded[k].type == res && mostNeeded[k].wanted > 0)
| 107| 107| 					{
| 108| 108| 						this.nextTributeRequest.set("all", gameState.ai.elapsedTime + 90);
| 112| 112| 							API3.warn("Tribute on " + res + " requested to player " + i);
| 113| 113| 						break;
| 114| 114| 					}
| 115|    |-				}
|    | 115|+				
| 116| 116| 			}
| 117| 117| 		}
| 118| 118| 		if (!toSend)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 159| 159| 			continue;
| 160| 160| 		let tributes = 0;
| 161| 161| 		for (let key in evt.amounts)
| 162|    |-		{
|    | 162|+		
| 163| 163| 			if (key === "food")
| 164| 164| 				tributes += evt.amounts[key];
| 165| 165| 			else
| 166| 166| 				tributes += 2*evt.amounts[key];
| 167|    |-		}
|    | 167|+		
| 168| 168| 		this.Config.personality.cooperative = Math.min(1, this.Config.personality.cooperative + 0.0001 * tributes);
| 169| 169| 	}
| 170| 170| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 238| 238| 
| 239| 239| 		// Our diplomacy will have changed already if the response was "accept"
| 240| 240| 		if (request.status === "waitingForTribute")
| 241|    |-		{
|    | 241|+		
| 242| 242| 			Engine.PostCommand(PlayerID, {
| 243| 243| 				"type": "tribute-request",
| 244| 244| 				"source": PlayerID,
| 246| 246| 				"resourceWanted": request.wanted,
| 247| 247| 				"resourceType": request.type
| 248| 248| 			});
| 249|    |-		}
|    | 249|+		
| 250| 250| 	}
| 251| 251| 
| 252| 252| 	// An AI player we sent a diplomacy request to demanded we send them a tribute
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 445| 445| {
| 446| 446| 	for (let [player, data] of this.receivedDiplomacyRequests)
| 447| 447| 		if (data.status === "waitingForTribute" && gameState.ai.elapsedTime > data.warnTime)
| 448|    |-		{
|    | 448|+		
| 449| 449| 			if (data.sentWarning)
| 450| 450| 			{
| 451| 451| 				this.receivedDiplomacyRequests.delete(player);
| 460| 460| 					"type": data.type
| 461| 461| 				});
| 462| 462| 			}
| 463|    |-		}
|    | 463|+		
| 464| 464| };
| 465| 465| 
| 466| 466| /**
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  38|  38| 		// Specify whether resources can be exchanged
|  39|  39| 		this.resourceTradable[data.code] = data.tradable;
|  40|  40| 		if (data.tradable == true)
|  41|    |-		{
|    |  41|+		
|  42|  42| 			this.resourceTradables.push(data.code);
|  43|    |-		}
|    |  43|+		
|  44|  44| 
|  45|  45| 		this.resourceBarterable[data.code] = data.barterable;
|  46|  46| 		if (data.barterable == true)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  44|  44| 
|  45|  45| 		this.resourceBarterable[data.code] = data.barterable;
|  46|  46| 		if (data.barterable == true)
|  47|    |-		{
|    |  47|+		
|  48|  48| 			this.resourceBarterables.push(data.code);
|  49|    |-		}
|    |  49|+		
|  50|  50| 
|  51|  51| 		this.resourceTributable[data.code] = data.tributable;
|  52|  52| 		if (data.tributable == true)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  50|  50| 
|  51|  51| 		this.resourceTributable[data.code] = data.tributable;
|  52|  52| 		if (data.tributable == true)
|  53|    |-		{
|    |  53|+		
|  54|  54| 		    this.resourceTributables.push(data.code);
|  55|    |-		}
|    |  55|+		
|  56|  56| 
|  57|  57| 		for (let subres in data.subtypes)
|  58|  58| 			this.resourceNames[subres] = data.subtypes[subres];
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 3 tabs but found 2.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  61|  61| 	// Sort arrays by specified order
|  62|  62| 	let resSort = (a, b) =>
|  63|  63| 		a.order < b.order ? -1 :
|  64|    |-		a.order > b.order ? +1 : 0;
|    |  64|+			a.order > b.order ? +1 : 0;
|  65|  65| 
|  66|  66| 	this.resourceData.sort(resSort);
|  67|  67| 	this.resourceCodes.sort((a, b) => resSort(

binaries/data/mods/public/gui/session/menu.js
| 482| »   »   button.onPress·=·(function(player,·stance)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'stance' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'resCode' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'button' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 557| »   button.onPress·=·(function(i)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 623| »   button.onPress·=·(function(i,·button)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 623| »   button.onPress·=·(function(i,·button)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'button' is already declared in the upper scope.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 452| 452| 				continue;
| 453| 453| 
| 454| 454| 			if (state.pack.progress == 0)
| 455|    |-			{
|    | 455|+			
| 456| 456| 				if (state.pack.packed)
| 457| 457| 					checks.unpackButton = true;
| 458| 458| 				else
| 459| 459| 					checks.packButton = true;
| 460|    |-			}
|    | 460|+			
| 461| 461| 			else if (state.pack.packed)
| 462| 462| 				checks.unpackCancelButton = true;
| 463| 463| 			else
|    | [NORMAL] ESLintBear (space-before-function-paren):
|    | Unexpected space before function parentheses.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 763| 763| 				addResearchToQueue(data.item.researchFacilityId, t);
| 764| 764| 			})(tech);
| 765| 765| 
| 766|    |-			button.onPressRight = (t => function () {
|    | 766|+			button.onPressRight = (t => function() {
| 767| 767| 				showTemplateDetails(
| 768| 768| 					t,
| 769| 769| 					GetTemplateData(data.unitEntStates.find(state => state.id == data.item.researchFacilityId).template).nativeCiv);
|    | [NORMAL] ESLintBear (semi):
|    | Missing semicolon.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 941| 941| 			"player": data.player
| 942| 942| 		});
| 943| 943| 
| 944|    |-		let unitIds = data.unitEntStates.map(status => status.id)
|    | 944|+		let unitIds = data.unitEntStates.map(status => status.id);
| 945| 945| 		let [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch] =
| 946| 946| 			getTrainingStatus(unitIds, data.item, data.playerState);
| 947| 947| 

binaries/data/mods/public/gui/session/selection_panels.js
|  48| »   »   »   switch·(data.item)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
|  59| »   »   switch·(data.item)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
| 731| »   »   »   »   »   »   switch·(entity.check)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
| 944| »   »   let·unitIds·=·data.unitEntStates.map(status·=>·status.id)
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["sell"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|  95|  95| 	amountsToSubtract[resourceToSell] = amount;
|  96|  96| 	if (cmpPlayer.TrySubtractResources(amountsToSubtract))
|  97|  97| 	{
|  98|    |-		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
|    |  98|+		var amountToAdd = Math.round(prices.sell[resourceToSell] / prices["buy"][resourceToBuy] * amount);
|  99|  99| 		cmpPlayer.AddResource(resourceToBuy, amountToAdd);
| 100| 100| 
| 101| 101| 		// Display chat message to observers
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["buy"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|  95|  95| 	amountsToSubtract[resourceToSell] = amount;
|  96|  96| 	if (cmpPlayer.TrySubtractResources(amountsToSubtract))
|  97|  97| 	{
|  98|    |-		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
|    |  98|+		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices.buy[resourceToBuy] * amount);
|  99|  99| 		cmpPlayer.AddResource(resourceToBuy, amountToAdd);
| 100| 100| 
| 101| 101| 		// Display chat message to observers

binaries/data/mods/public/simulation/components/Barter.js
|  98| »   »   var·amountToAdd·=·Math.round(prices["sell"][resourceToSell]·/·prices["buy"][resourceToBuy]·*·amount);
|    | [NORMAL] JSHintBear:
|    | ['sell'] is better written in dot notation.

binaries/data/mods/public/simulation/components/Barter.js
|  98| »   »   var·amountToAdd·=·Math.round(prices["sell"][resourceToSell]·/·prices["buy"][resourceToBuy]·*·amount);
|    | [NORMAL] JSHintBear:
|    | ['buy'] is better written in dot notation.
Executing section cli...

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

Stan added inline comments.Apr 25 2019, 2:53 PM
binaries/data/mods/public/globalscripts/Resources.js
157

[array] → {string[]} see http://usejsdoc.org/tags-param.html

binaries/data/mods/public/simulation/components/tests/test_Player.js
1

add var here while at it.

6

Could probably be put in a function to avoid duplication

Freagarach added inline comments.Apr 25 2019, 2:54 PM
binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
411

Ah, thats what I wanted! I couldn't come up with that.

Also this function should request tributes anyways. You just need to pick the most wanted tributable resource.

But this is what it does right? At least that is what I meant ;) It loops over all resources and when the most needed resource is untributable, try the next one. If the the resource is tributable it should break the loop and use the requiredTribute as set lastly. Or am I thinking wrong now?

Stan added inline comments.Apr 25 2019, 3:15 PM
binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
411

Then one can do

// Returns the first element matching the condition IsResourceTributable
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
let requiredTribute = gameState.ai.HQ.pickMostNeededResources(gameState).find(res => Resources.GetTributable[requiredTribute]);

// Do not request tributes if no resources can be tributed.
if(!requiredTribute)
  return;

@Nescio This:

If you want this (that all resources can only be bartered into coin and vice versa, that is wat you want right?) you need to change (...)

cannot be achieved with this patch. If a resource is set unbarterable with this code it is not shown in the barter menu at all.
I think that what you want can be achieved by introducing a currency-parameter, but I also think it is outside the scope of this patch, but I'm not sure. Feedback/Thoughts on this are appreciated.

binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
411

I can't seem to get this working. I've tried:

let requiredTribute = gameState.ai.HQ.pickMostNeededResources(gameState).find(res => Resources.GetTributable[res]);

for I think that is what you meant, but it keeps giving me a

WARNING: JavaScript warning: simulation/ai/petra/diplomacyManager.js line 408
reference to undefined property Resources.GetTributable[res]

:(

Freagarach marked an inline comment as not done.Apr 25 2019, 8:59 PM
Freagarach updated this revision to Diff 7859.Apr 25 2019, 9:32 PM

Some minor fixes.

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

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/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  38|  38| 		// Specify whether resources can be exchanged
|  39|  39| 		this.resourceTradable[data.code] = data.tradable;
|  40|  40| 		if (data.tradable == true)
|  41|    |-		{
|    |  41|+		
|  42|  42| 			this.resourceTradables.push(data.code);
|  43|    |-		}
|    |  43|+		
|  44|  44| 
|  45|  45| 		this.resourceBarterable[data.code] = data.barterable;
|  46|  46| 		if (data.barterable == true)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  44|  44| 
|  45|  45| 		this.resourceBarterable[data.code] = data.barterable;
|  46|  46| 		if (data.barterable == true)
|  47|    |-		{
|    |  47|+		
|  48|  48| 			this.resourceBarterables.push(data.code);
|  49|    |-		}
|    |  49|+		
|  50|  50| 
|  51|  51| 		this.resourceTributable[data.code] = data.tributable;
|  52|  52| 		if (data.tributable == true)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  50|  50| 
|  51|  51| 		this.resourceTributable[data.code] = data.tributable;
|  52|  52| 		if (data.tributable == true)
|  53|    |-		{
|    |  53|+		
|  54|  54| 		    this.resourceTributables.push(data.code);
|  55|    |-		}
|    |  55|+		
|  56|  56| 
|  57|  57| 		for (let subres in data.subtypes)
|  58|  58| 			this.resourceNames[subres] = data.subtypes[subres];
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 3 tabs but found 2.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  61|  61| 	// Sort arrays by specified order
|  62|  62| 	let resSort = (a, b) =>
|  63|  63| 		a.order < b.order ? -1 :
|  64|    |-		a.order > b.order ? +1 : 0;
|    |  64|+			a.order > b.order ? +1 : 0;
|  65|  65| 
|  66|  66| 	this.resourceData.sort(resSort);
|  67|  67| 	this.resourceCodes.sort((a, b) => resSort(
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /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
| 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.
|----|    | /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;
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 452| 452| 				continue;
| 453| 453| 
| 454| 454| 			if (state.pack.progress == 0)
| 455|    |-			{
|    | 455|+			
| 456| 456| 				if (state.pack.packed)
| 457| 457| 					checks.unpackButton = true;
| 458| 458| 				else
| 459| 459| 					checks.packButton = true;
| 460|    |-			}
|    | 460|+			
| 461| 461| 			else if (state.pack.packed)
| 462| 462| 				checks.unpackCancelButton = true;
| 463| 463| 			else
|    | [NORMAL] ESLintBear (space-before-function-paren):
|    | Unexpected space before function parentheses.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 763| 763| 				addResearchToQueue(data.item.researchFacilityId, t);
| 764| 764| 			})(tech);
| 765| 765| 
| 766|    |-			button.onPressRight = (t => function () {
|    | 766|+			button.onPressRight = (t => function() {
| 767| 767| 				showTemplateDetails(
| 768| 768| 					t,
| 769| 769| 					GetTemplateData(data.unitEntStates.find(state => state.id == data.item.researchFacilityId).template).nativeCiv);
|    | [NORMAL] ESLintBear (semi):
|    | Missing semicolon.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 941| 941| 			"player": data.player
| 942| 942| 		});
| 943| 943| 
| 944|    |-		let unitIds = data.unitEntStates.map(status => status.id)
|    | 944|+		let unitIds = data.unitEntStates.map(status => status.id);
| 945| 945| 		let [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch] =
| 946| 946| 			getTrainingStatus(unitIds, data.item, data.playerState);
| 947| 947| 

binaries/data/mods/public/gui/session/selection_panels.js
|  48| »   »   »   switch·(data.item)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
|  59| »   »   switch·(data.item)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
| 731| »   »   »   »   »   »   switch·(entity.check)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
| 944| »   »   let·unitIds·=·data.unitEntStates.map(status·=>·status.id)
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.

binaries/data/mods/public/gui/session/menu.js
| 482| »   »   button.onPress·=·(function(player,·stance)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'stance' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'resCode' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'button' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 557| »   button.onPress·=·(function(i)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 623| »   button.onPress·=·(function(i,·button)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 623| »   button.onPress·=·(function(i,·button)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'button' is already declared in the upper scope.
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["sell"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|  95|  95| 	amountsToSubtract[resourceToSell] = amount;
|  96|  96| 	if (cmpPlayer.TrySubtractResources(amountsToSubtract))
|  97|  97| 	{
|  98|    |-		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
|    |  98|+		var amountToAdd = Math.round(prices.sell[resourceToSell] / prices["buy"][resourceToBuy] * amount);
|  99|  99| 		cmpPlayer.AddResource(resourceToBuy, amountToAdd);
| 100| 100| 
| 101| 101| 		// Display chat message to observers
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["buy"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|  95|  95| 	amountsToSubtract[resourceToSell] = amount;
|  96|  96| 	if (cmpPlayer.TrySubtractResources(amountsToSubtract))
|  97|  97| 	{
|  98|    |-		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
|    |  98|+		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices.buy[resourceToBuy] * amount);
|  99|  99| 		cmpPlayer.AddResource(resourceToBuy, amountToAdd);
| 100| 100| 
| 101| 101| 		// Display chat message to observers

binaries/data/mods/public/simulation/components/Barter.js
|  98| »   »   var·amountToAdd·=·Math.round(prices["sell"][resourceToSell]·/·prices["buy"][resourceToBuy]·*·amount);
|    | [NORMAL] JSHintBear:
|    | ['sell'] is better written in dot notation.

binaries/data/mods/public/simulation/components/Barter.js
|  98| »   »   var·amountToAdd·=·Math.round(prices["sell"][resourceToSell]·/·prices["buy"][resourceToBuy]·*·amount);
|    | [NORMAL] JSHintBear:
|    | ['buy'] is better written in dot notation.

binaries/data/mods/public/simulation/components/tests/test_Barter.js
|  50| let·cmpBarter·=·ConstructComponent(SYSTEM_ENTITY,·"Barter");
|    | [NORMAL] JSHintBear:
|    | 'cmpBarter' was used before it was defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 102| 102| 				if (!mostNeeded)
| 103| 103| 					mostNeeded = gameState.ai.HQ.pickMostNeededResources(gameState);
| 104| 104| 				for (let k = 0; k < 2; ++k)
| 105|    |-				{
|    | 105|+				
| 106| 106| 					if (mostNeeded[k].type == res && mostNeeded[k].wanted > 0)
| 107| 107| 					{
| 108| 108| 						this.nextTributeRequest.set("all", gameState.ai.elapsedTime + 90);
| 112| 112| 							API3.warn("Tribute on " + res + " requested to player " + i);
| 113| 113| 						break;
| 114| 114| 					}
| 115|    |-				}
|    | 115|+				
| 116| 116| 			}
| 117| 117| 		}
| 118| 118| 		if (!toSend)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 159| 159| 			continue;
| 160| 160| 		let tributes = 0;
| 161| 161| 		for (let key in evt.amounts)
| 162|    |-		{
|    | 162|+		
| 163| 163| 			if (key === "food")
| 164| 164| 				tributes += evt.amounts[key];
| 165| 165| 			else
| 166| 166| 				tributes += 2*evt.amounts[key];
| 167|    |-		}
|    | 167|+		
| 168| 168| 		this.Config.personality.cooperative = Math.min(1, this.Config.personality.cooperative + 0.0001 * tributes);
| 169| 169| 	}
| 170| 170| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 238| 238| 
| 239| 239| 		// Our diplomacy will have changed already if the response was "accept"
| 240| 240| 		if (request.status === "waitingForTribute")
| 241|    |-		{
|    | 241|+		
| 242| 242| 			Engine.PostCommand(PlayerID, {
| 243| 243| 				"type": "tribute-request",
| 244| 244| 				"source": PlayerID,
| 246| 246| 				"resourceWanted": request.wanted,
| 247| 247| 				"resourceType": request.type
| 248| 248| 			});
| 249|    |-		}
|    | 249|+		
| 250| 250| 	}
| 251| 251| 
| 252| 252| 	// An AI player we sent a diplomacy request to demanded we send them a tribute
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 445| 445| {
| 446| 446| 	for (let [player, data] of this.receivedDiplomacyRequests)
| 447| 447| 		if (data.status === "waitingForTribute" && gameState.ai.elapsedTime > data.warnTime)
| 448|    |-		{
|    | 448|+		
| 449| 449| 			if (data.sentWarning)
| 450| 450| 			{
| 451| 451| 				this.receivedDiplomacyRequests.delete(player);
| 460| 460| 					"type": data.type
| 461| 461| 				});
| 462| 462| 			}
| 463|    |-		}
|    | 463|+		
| 464| 464| };
| 465| 465| 
| 466| 466| /**

binaries/data/mods/public/simulation/components/Player.js
| 385| »   for·(var·type·in·amounts)
|    | [NORMAL] JSHintBear:
|    | 'type' is already defined.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  16| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  28| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  40| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  16| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  28| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  40| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.
Executing section cli...

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

Stan added inline comments.Apr 25 2019, 9:53 PM
binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
411

try with !== undefined ?

Angen added inline comments.Apr 25 2019, 10:17 PM
binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
409

well, decline then, else requiredTribute will be last resource in list.

411
let requiredTribute = gameState.ai.HQ.pickMostNeededResources(gameState).find(res => Resources.GetTributable[res]);

I think you could with something like this (not sure):

let requiredTribute = gameState.ai.HQ.pickMostNeededResources(gameState).find(res => !!Resources.GetTributable[res] && Resources.GetTributable[res]);
413

not needed repeated calling, call this

gameState.ai.HQ.pickMostNeededResources(gameState)

before looping and then go with [i] over object

414

what brings me to this check, actually it is not correct.
If your resource is not tributable, you break, but requiredTribute is allready assigned to that resource

Angen added inline comments.Apr 25 2019, 10:32 PM
binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
414

ok, sorry its too late here :D (you find first tributable and break, got it now) but, it does not look correct anyway. You have to handle when no resource is tributable somewhere :)

Freagarach added inline comments.Apr 25 2019, 10:41 PM
binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
411

Sadly not, neither of your suggestions work. There is no warning given, but requiredTribute is still not defined. uneval gives "(void 0)".

414

I understand, it looks ugly ;)
Perhaps an "if i == Resources.GetCodes().length" after the i++? This would not be necessary if Stan's suggestion can be incorporated.

Angen added inline comments.Apr 25 2019, 10:59 PM
binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
414

you can and should do check if at least one tributable resource globally exists before even calling mostneeded resources and deal with it there.

Freagarach marked 4 inline comments as done.Apr 26 2019, 8:34 AM
Freagarach updated this revision to Diff 7866.Apr 26 2019, 8:36 AM
Freagarach edited the test plan for this revision. (Show Details)

Fixed confusing names, AI tribute requests and removed unnecessary test in code.

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/components/tests/test_Player.js
|  16| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  28| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  40| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  16| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  28| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  40| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /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
| 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.
|----|    | /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/components/Player.js
| 385| »   for·(var·type·in·amounts)
|    | [NORMAL] JSHintBear:
|    | 'type' is already defined.

binaries/data/mods/public/gui/session/menu.js
| 482| »   »   button.onPress·=·(function(player,·stance)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'stance' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'resCode' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'button' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 557| »   button.onPress·=·(function(i)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 623| »   button.onPress·=·(function(i,·button)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 623| »   button.onPress·=·(function(i,·button)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'button' is already declared in the upper scope.
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["sell"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|  95|  95| 	amountsToSubtract[resourceToSell] = amount;
|  96|  96| 	if (cmpPlayer.TrySubtractResources(amountsToSubtract))
|  97|  97| 	{
|  98|    |-		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
|    |  98|+		var amountToAdd = Math.round(prices.sell[resourceToSell] / prices["buy"][resourceToBuy] * amount);
|  99|  99| 		cmpPlayer.AddResource(resourceToBuy, amountToAdd);
| 100| 100| 
| 101| 101| 		// Display chat message to observers
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["buy"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|  95|  95| 	amountsToSubtract[resourceToSell] = amount;
|  96|  96| 	if (cmpPlayer.TrySubtractResources(amountsToSubtract))
|  97|  97| 	{
|  98|    |-		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
|    |  98|+		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices.buy[resourceToBuy] * amount);
|  99|  99| 		cmpPlayer.AddResource(resourceToBuy, amountToAdd);
| 100| 100| 
| 101| 101| 		// Display chat message to observers

binaries/data/mods/public/simulation/components/Barter.js
|  98| »   »   var·amountToAdd·=·Math.round(prices["sell"][resourceToSell]·/·prices["buy"][resourceToBuy]·*·amount);
|    | [NORMAL] JSHintBear:
|    | ['sell'] is better written in dot notation.

binaries/data/mods/public/simulation/components/Barter.js
|  98| »   »   var·amountToAdd·=·Math.round(prices["sell"][resourceToSell]·/·prices["buy"][resourceToBuy]·*·amount);
|    | [NORMAL] JSHintBear:
|    | ['buy'] is better written in dot notation.

binaries/data/mods/public/simulation/components/tests/test_Barter.js
|  50| let·cmpBarter·=·ConstructComponent(SYSTEM_ENTITY,·"Barter");
|    | [NORMAL] JSHintBear:
|    | 'cmpBarter' was used before it was defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 102| 102| 				if (!mostNeeded)
| 103| 103| 					mostNeeded = gameState.ai.HQ.pickMostNeededResources(gameState);
| 104| 104| 				for (let k = 0; k < 2; ++k)
| 105|    |-				{
|    | 105|+				
| 106| 106| 					if (mostNeeded[k].type == res && mostNeeded[k].wanted > 0)
| 107| 107| 					{
| 108| 108| 						this.nextTributeRequest.set("all", gameState.ai.elapsedTime + 90);
| 112| 112| 							API3.warn("Tribute on " + res + " requested to player " + i);
| 113| 113| 						break;
| 114| 114| 					}
| 115|    |-				}
|    | 115|+				
| 116| 116| 			}
| 117| 117| 		}
| 118| 118| 		if (!toSend)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 159| 159| 			continue;
| 160| 160| 		let tributes = 0;
| 161| 161| 		for (let key in evt.amounts)
| 162|    |-		{
|    | 162|+		
| 163| 163| 			if (key === "food")
| 164| 164| 				tributes += evt.amounts[key];
| 165| 165| 			else
| 166| 166| 				tributes += 2*evt.amounts[key];
| 167|    |-		}
|    | 167|+		
| 168| 168| 		this.Config.personality.cooperative = Math.min(1, this.Config.personality.cooperative + 0.0001 * tributes);
| 169| 169| 	}
| 170| 170| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 238| 238| 
| 239| 239| 		// Our diplomacy will have changed already if the response was "accept"
| 240| 240| 		if (request.status === "waitingForTribute")
| 241|    |-		{
|    | 241|+		
| 242| 242| 			Engine.PostCommand(PlayerID, {
| 243| 243| 				"type": "tribute-request",
| 244| 244| 				"source": PlayerID,
| 246| 246| 				"resourceWanted": request.wanted,
| 247| 247| 				"resourceType": request.type
| 248| 248| 			});
| 249|    |-		}
|    | 249|+		
| 250| 250| 	}
| 251| 251| 
| 252| 252| 	// An AI player we sent a diplomacy request to demanded we send them a tribute
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 446| 446| {
| 447| 447| 	for (let [player, data] of this.receivedDiplomacyRequests)
| 448| 448| 		if (data.status === "waitingForTribute" && gameState.ai.elapsedTime > data.warnTime)
| 449|    |-		{
|    | 449|+		
| 450| 450| 			if (data.sentWarning)
| 451| 451| 			{
| 452| 452| 				this.receivedDiplomacyRequests.delete(player);
| 461| 461| 					"type": data.type
| 462| 462| 				});
| 463| 463| 			}
| 464|    |-		}
|    | 464|+		
| 465| 465| };
| 466| 466| 
| 467| 467| /**
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 452| 452| 				continue;
| 453| 453| 
| 454| 454| 			if (state.pack.progress == 0)
| 455|    |-			{
|    | 455|+			
| 456| 456| 				if (state.pack.packed)
| 457| 457| 					checks.unpackButton = true;
| 458| 458| 				else
| 459| 459| 					checks.packButton = true;
| 460|    |-			}
|    | 460|+			
| 461| 461| 			else if (state.pack.packed)
| 462| 462| 				checks.unpackCancelButton = true;
| 463| 463| 			else
|    | [NORMAL] ESLintBear (space-before-function-paren):
|    | Unexpected space before function parentheses.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 763| 763| 				addResearchToQueue(data.item.researchFacilityId, t);
| 764| 764| 			})(tech);
| 765| 765| 
| 766|    |-			button.onPressRight = (t => function () {
|    | 766|+			button.onPressRight = (t => function() {
| 767| 767| 				showTemplateDetails(
| 768| 768| 					t,
| 769| 769| 					GetTemplateData(data.unitEntStates.find(state => state.id == data.item.researchFacilityId).template).nativeCiv);
|    | [NORMAL] ESLintBear (semi):
|    | Missing semicolon.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 941| 941| 			"player": data.player
| 942| 942| 		});
| 943| 943| 
| 944|    |-		let unitIds = data.unitEntStates.map(status => status.id)
|    | 944|+		let unitIds = data.unitEntStates.map(status => status.id);
| 945| 945| 		let [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch] =
| 946| 946| 			getTrainingStatus(unitIds, data.item, data.playerState);
| 947| 947| 

binaries/data/mods/public/gui/session/selection_panels.js
|  48| »   »   »   switch·(data.item)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
|  59| »   »   switch·(data.item)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
| 731| »   »   »   »   »   »   switch·(entity.check)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
| 944| »   »   let·unitIds·=·data.unitEntStates.map(status·=>·status.id)
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  38|  38| 		// Specify whether resources can be exchanged
|  39|  39| 		this.resourceTradable[data.code] = data.tradable;
|  40|  40| 		if (data.tradable == true)
|  41|    |-		{
|    |  41|+		
|  42|  42| 			this.resourceTradableCodes.push(data.code);
|  43|    |-		}
|    |  43|+		
|  44|  44| 
|  45|  45| 		this.resourceBarterable[data.code] = data.barterable;
|  46|  46| 		if (data.barterable == true)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  44|  44| 
|  45|  45| 		this.resourceBarterable[data.code] = data.barterable;
|  46|  46| 		if (data.barterable == true)
|  47|    |-		{
|    |  47|+		
|  48|  48| 			this.resourceBarterableCodes.push(data.code);
|  49|    |-		}
|    |  49|+		
|  50|  50| 
|  51|  51| 		this.resourceTributable[data.code] = data.tributable;
|  52|  52| 		if (data.tributable == true)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  50|  50| 
|  51|  51| 		this.resourceTributable[data.code] = data.tributable;
|  52|  52| 		if (data.tributable == true)
|  53|    |-		{
|    |  53|+		
|  54|  54| 		    this.resourceTributableCodes.push(data.code);
|  55|    |-		}
|    |  55|+		
|  56|  56| 
|  57|  57| 		for (let subres in data.subtypes)
|  58|  58| 			this.resourceNames[subres] = data.subtypes[subres];
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 3 tabs but found 2.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  61|  61| 	// Sort arrays by specified order
|  62|  62| 	let resSort = (a, b) =>
|  63|  63| 		a.order < b.order ? -1 :
|  64|    |-		a.order > b.order ? +1 : 0;
|    |  64|+			a.order > b.order ? +1 : 0;
|  65|  65| 
|  66|  66| 	this.resourceData.sort(resSort);
|  67|  67| 	this.resourceCodes.sort((a, b) => resSort(
Executing section cli...

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

Freagarach marked an inline comment as done.Apr 26 2019, 8:48 AM
Freagarach marked 2 inline comments as done.Apr 26 2019, 12:15 PM

Okay, from what I see it is almost done?
Things to discuss:

  • resourceTradable/resourceBarterable/resourceTributable Objects are not used by me and can be removed I guess? Unless someone sees any useful application for it?
  • Connected: If the above is done, the question about the caching is not relevant anymore, right?
  • Duplication in the Resources.js and in the test_Player.js can be reduced. (I'm sorry, but I do not consider myself up to that task.)
  • Should I add a currency parameter in this patch so that @wowgetoffyourcellphone and @Nescio are happy? ;) (see this thread)
  • Are there any other things that ought to be done?

And a question, there are no reviewers, should I invite them or do they pick differentials themselve?

binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
411

I've fixed it :) Thanks for the help!

binaries/data/mods/public/simulation/components/tests/test_Player.js
1

I'm sorry, add 'var' where exactly? I thought you meant before "Resources = {" but that gives a build error.

Stan added inline comments.Apr 26 2019, 1:38 PM
binaries/data/mods/public/globalscripts/Resources.js
86

Still triplicated.

binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
411

I think requiredTribute = gameState.ai.HQ.pickMostNeededResources(gameState).find(res => Resources.GetTributableCodes().some(res2 => res2 == res)); would be better.

Freagarach updated this revision to Diff 7867.Apr 26 2019, 1:43 PM
Freagarach edited the summary of this revision. (Show Details)
Freagarach edited the test plan for this revision. (Show Details)

Sorry, didn't wait for reaction about the currency, I implemented it during lunch.

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

Linter detected issues:
Executing section Source...
Executing section JS...
|    | [NORMAL] ESLintBear (semi):
|    | Missing semicolon.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  52|  52| 		if (data.isCurrency == true)
|  53|  53| 		{
|  54|  54| 			if (this.resourceCurrency)
|  55|    |-				warn("There is more than one currency defined, taking the last one.")
|    |  55|+				warn("There is more than one currency defined, taking the last one.");
|  56|  56| 			this.resourceCurrency = data.code;
|  57|  57| 		}
|  58|  58| 
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 3 tabs but found 2.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  63|  63| 	// Sort arrays by specified order
|  64|  64| 	let resSort = (a, b) =>
|  65|  65| 		a.order < b.order ? -1 :
|  66|    |-		a.order > b.order ? +1 : 0;
|    |  66|+			a.order > b.order ? +1 : 0;
|  67|  67| 
|  68|  68| 	this.resourceData.sort(resSort);
|  69|  69| 	this.resourceCodes.sort((a, b) => resSort(

binaries/data/mods/public/globalscripts/Resources.js
|  55| »   »   »   »   warn("There·is·more·than·one·currency·defined,·taking·the·last·one.")
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /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
| 429| 429| 	let candidate = { "gain": 0 };
| 430| 430| 	let potential = { "gain": 0 };
| 431| 431| 	let bestIndex = { "gain": 0 };
| 432|    |-	let bestLand  = { "gain": 0 };
|    | 432|+	let bestLand = { "gain": 0 };
| 433| 433| 
| 434| 434| 	let mapSize = gameState.sharedScript.mapSize;
| 435| 435| 	let traderTemplatesGains = gameState.getTraderTemplatesGains();
|    | [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
| 467| 467| 			if (m1.foundationProgress() === undefined && m2.foundationProgress() === undefined)
| 468| 468| 			{
| 469| 469| 				if (accessIndex)
| 470|    |-				{
|    | 470|+				
| 471| 471| 					if (gameState.ai.accessibility.regionType[accessIndex] == "water" && sea == accessIndex)
| 472| 472| 					{
| 473| 473| 						if (gain < bestIndex.gain)
| 486| 486| 							continue;
| 487| 487| 						bestLand = { "source": m1, "target": m2, "gain": gain, "land": land, "sea": sea };
| 488| 488| 					}
| 489|    |-				}
|    | 489|+				
| 490| 490| 				if (gain < candidate.gain)
| 491| 491| 					continue;
| 492| 492| 				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
| 606| 606| 		return;	// position found, but not enough gain compared to our present route
| 607| 607| 
| 608| 608| 	if (this.Config.debug > 1)
| 609|    |-	{
|    | 609|+	
| 610| 610| 		if (this.potentialTradeRoute)
| 611| 611| 			API3.warn("turn " + gameState.ai.playedTurn + "we could have a new route with gain " +
| 612| 612| 				marketPos[3] + " instead of the present " + this.potentialTradeRoute.gain);
| 613| 613| 		else
| 614| 614| 			API3.warn("turn " + gameState.ai.playedTurn + "we could have a first route with gain " +
| 615| 615| 				marketPos[3]);
| 616|    |-	}
|    | 616|+	
| 617| 617| 
| 618| 618| 	if (!this.tradeRoute)
| 619| 619| 		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
| 669| 669| 
| 670| 670| 	let ret = {};
| 671| 671| 	for (let key in route)
| 672|    |-	{
|    | 672|+	
| 673| 673| 		if (key == "source" || key == "target")
| 674| 674| 		{
| 675| 675| 			if (!route[key])
| 678| 678| 		}
| 679| 679| 		else
| 680| 680| 			ret[key] = route[key];
| 681|    |-	}
|    | 681|+	
| 682| 682| 	return ret;
| 683| 683| };
| 684| 684| 
|    | [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
| 689| 689| 
| 690| 690| 	let ret = {};
| 691| 691| 	for (let key in route)
| 692|    |-	{
|    | 692|+	
| 693| 693| 		if (key == "source" || key == "target")
| 694| 694| 		{
| 695| 695| 			ret[key] = gameState.getEntityById(route[key]);
| 698| 698| 		}
| 699| 699| 		else
| 700| 700| 			ret[key] = route[key];
| 701|    |-	}
|    | 701|+	
| 702| 702| 	return ret;
| 703| 703| };
| 704| 704| 
|    | [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
| 716| 716| m.TradeManager.prototype.Deserialize = function(gameState, data)
| 717| 717| {
| 718| 718| 	for (let key in data)
| 719|    |-	{
|    | 719|+	
| 720| 720| 		if (key == "tradeRoute" || key == "potentialTradeRoute")
| 721| 721| 			this[key] = this.routeIdToEnt(gameState, data[key]);
| 722| 722| 		else
| 723| 723| 			this[key] = data[key];
| 724|    |-	}
|    | 724|+	
| 725| 725| };
| 726| 726| 
| 727| 727| return m;

binaries/data/mods/public/simulation/components/Player.js
| 385| »   for·(var·type·in·amounts)
|    | [NORMAL] JSHintBear:
|    | 'type' is already defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/menu.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/menu.js
| 860| 860| 		});
| 861| 861| 	};
| 862| 862| 
| 863|    |-	if (g_BarterSell == g_ResourceData.GetCurrency() || !g_ResourceData.GetCurrency()){
| 864|    |-		barterButton.Buy.hidden = isSelected;}
|    | 863|+	if (g_BarterSell == g_ResourceData.GetCurrency() || !g_ResourceData.GetCurrency())
|    | 864|+		barterButton.Buy.hidden = isSelected;
| 865| 865| 	else
| 866| 866| 		barterButton.Buy.hidden = resourceCode != g_ResourceData.GetCurrency();
| 867| 867| 

binaries/data/mods/public/gui/session/menu.js
| 482| »   »   button.onPress·=·(function(player,·stance)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'stance' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'resCode' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'button' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 557| »   button.onPress·=·(function(i)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 623| »   button.onPress·=·(function(i,·button)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 623| »   button.onPress·=·(function(i,·button)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'button' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 863| »   if·(g_BarterSell·==·g_ResourceData.GetCurrency()·||·!g_ResourceData.GetCurrency()){
|    | [NORMAL] ESLintBear (brace-rules/brace-on-same-line):
|    | Opening curly brace appears on the same line as controlling statement.

binaries/data/mods/public/gui/session/menu.js
| 864| »   »   barterButton.Buy.hidden·=·isSelected;}
|    | [NORMAL] ESLintBear (brace-rules/brace-on-same-line):
|    | Closing curly brace should be on the same line as opening curly brace or on the line after the previous block.
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["sell"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|  95|  95| 	amountsToSubtract[resourceToSell] = amount;
|  96|  96| 	if (cmpPlayer.TrySubtractResources(amountsToSubtract))
|  97|  97| 	{
|  98|    |-		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
|    |  98|+		var amountToAdd = Math.round(prices.sell[resourceToSell] / prices["buy"][resourceToBuy] * amount);
|  99|  99| 		cmpPlayer.AddResource(resourceToBuy, amountToAdd);
| 100| 100| 
| 101| 101| 		// Display chat message to observers
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["buy"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|  95|  95| 	amountsToSubtract[resourceToSell] = amount;
|  96|  96| 	if (cmpPlayer.TrySubtractResources(amountsToSubtract))
|  97|  97| 	{
|  98|    |-		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
|    |  98|+		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices.buy[resourceToBuy] * amount);
|  99|  99| 		cmpPlayer.AddResource(resourceToBuy, amountToAdd);
| 100| 100| 
| 101| 101| 		// Display chat message to observers

binaries/data/mods/public/simulation/components/Barter.js
|  98| »   »   var·amountToAdd·=·Math.round(prices["sell"][resourceToSell]·/·prices["buy"][resourceToBuy]·*·amount);
|    | [NORMAL] JSHintBear:
|    | ['sell'] is better written in dot notation.

binaries/data/mods/public/simulation/components/Barter.js
|  98| »   »   var·amountToAdd·=·Math.round(prices["sell"][resourceToSell]·/·prices["buy"][resourceToBuy]·*·amount);
|    | [NORMAL] JSHintBear:
|    | ['buy'] is better written in dot notation.

binaries/data/mods/public/simulation/components/tests/test_Barter.js
|  50| let·cmpBarter·=·ConstructComponent(SYSTEM_ENTITY,·"Barter");
|    | [NORMAL] JSHintBear:
|    | 'cmpBarter' was used before it was defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 102| 102| 				if (!mostNeeded)
| 103| 103| 					mostNeeded = gameState.ai.HQ.pickMostNeededResources(gameState);
| 104| 104| 				for (let k = 0; k < 2; ++k)
| 105|    |-				{
|    | 105|+				
| 106| 106| 					if (mostNeeded[k].type == res && mostNeeded[k].wanted > 0)
| 107| 107| 					{
| 108| 108| 						this.nextTributeRequest.set("all", gameState.ai.elapsedTime + 90);
| 112| 112| 							API3.warn("Tribute on " + res + " requested to player " + i);
| 113| 113| 						break;
| 114| 114| 					}
| 115|    |-				}
|    | 115|+				
| 116| 116| 			}
| 117| 117| 		}
| 118| 118| 		if (!toSend)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 159| 159| 			continue;
| 160| 160| 		let tributes = 0;
| 161| 161| 		for (let key in evt.amounts)
| 162|    |-		{
|    | 162|+		
| 163| 163| 			if (key === "food")
| 164| 164| 				tributes += evt.amounts[key];
| 165| 165| 			else
| 166| 166| 				tributes += 2*evt.amounts[key];
| 167|    |-		}
|    | 167|+		
| 168| 168| 		this.Config.personality.cooperative = Math.min(1, this.Config.personality.cooperative + 0.0001 * tributes);
| 169| 169| 	}
| 170| 170| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 238| 238| 
| 239| 239| 		// Our diplomacy will have changed already if the response was "accept"
| 240| 240| 		if (request.status === "waitingForTribute")
| 241|    |-		{
|    | 241|+		
| 242| 242| 			Engine.PostCommand(PlayerID, {
| 243| 243| 				"type": "tribute-request",
| 244| 244| 				"source": PlayerID,
| 246| 246| 				"resourceWanted": request.wanted,
| 247| 247| 				"resourceType": request.type
| 248| 248| 			});
| 249|    |-		}
|    | 249|+		
| 250| 250| 	}
| 251| 251| 
| 252| 252| 	// An AI player we sent a diplomacy request to demanded we send them a tribute
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 446| 446| {
| 447| 447| 	for (let [player, data] of this.receivedDiplomacyRequests)
| 448| 448| 		if (data.status === "waitingForTribute" && gameState.ai.elapsedTime > data.warnTime)
| 449|    |-		{
|    | 449|+		
| 450| 450| 			if (data.sentWarning)
| 451| 451| 			{
| 452| 452| 				this.receivedDiplomacyRequests.delete(player);
| 461| 461| 					"type": data.type
| 462| 462| 				});
| 463| 463| 			}
| 464|    |-		}
|    | 464|+		
| 465| 465| };
| 466| 466| 
| 467| 467| /**
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 452| 452| 				continue;
| 453| 453| 
| 454| 454| 			if (state.pack.progress == 0)
| 455|    |-			{
|    | 455|+			
| 456| 456| 				if (state.pack.packed)
| 457| 457| 					checks.unpackButton = true;
| 458| 458| 				else
| 459| 459| 					checks.packButton = true;
| 460|    |-			}
|    | 460|+			
| 461| 461| 			else if (state.pack.packed)
| 462| 462| 				checks.unpackCancelButton = true;
| 463| 463| 			else
|    | [NORMAL] ESLintBear (space-before-function-paren):
|    | Unexpected space before function parentheses.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 763| 763| 				addResearchToQueue(data.item.researchFacilityId, t);
| 764| 764| 			})(tech);
| 765| 765| 
| 766|    |-			button.onPressRight = (t => function () {
|    | 766|+			button.onPressRight = (t => function() {
| 767| 767| 				showTemplateDetails(
| 768| 768| 					t,
| 769| 769| 					GetTemplateData(data.unitEntStates.find(state => state.id == data.item.researchFacilityId).template).nativeCiv);
|    | [NORMAL] ESLintBear (semi):
|    | Missing semicolon.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 941| 941| 			"player": data.player
| 942| 942| 		});
| 943| 943| 
| 944|    |-		let unitIds = data.unitEntStates.map(status => status.id)
|    | 944|+		let unitIds = data.unitEntStates.map(status => status.id);
| 945| 945| 		let [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch] =
| 946| 946| 			getTrainingStatus(unitIds, data.item, data.playerState);
| 947| 947| 

binaries/data/mods/public/gui/session/selection_panels.js
|  48| »   »   »   switch·(data.item)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
|  59| »   »   switch·(data.item)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
| 731| »   »   »   »   »   »   switch·(entity.check)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
| 944| »   »   let·unitIds·=·data.unitEntStates.map(status·=>·status.id)
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  16| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  28| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  40| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  16| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  28| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  40| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.
Executing section cli...

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

Stan added a comment.Apr 26 2019, 1:46 PM

It's okay ;)

Freagarach added a comment.EditedApr 26 2019, 1:50 PM

It's okay ;)

:)
Do I need to make sure that Jenkins has nothing to complain about? Because quite a few things it says is not due to code I changed but was already there.

binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
411

In terms of performance? Or is there a different reason?

Freagarach added inline comments.Apr 26 2019, 1:54 PM
binaries/data/mods/public/gui/session/menu.js
864

MTM: Remove curly braces.

Stan added inline comments.Apr 26 2019, 2:11 PM
binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
411

Forgot type

gameState.ai.HQ.pickMostNeededResources(gameState).find(res => Resources.GetTributableCodes().some(res2 => res2 == res.type));

I think it's more readable saying "I want the first resource in the most needed resource that's in Resources.GetTributableCode()"

Than "I want the first resource in the most needed resource that's in where the first Resources.GetTributableCodes() that is not false is equal to res.type"

Freagarach added inline comments.Apr 26 2019, 4:45 PM
binaries/data/mods/public/globalscripts/Resources.js
99

Could not be deepfreezed (because it is no object nor an array?), it would be fun if the currency could be changed in game, so I don't mind ;)

binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
411

I thought this

Resources.GetTributableCodes().find(res2 => res2)

would just kind of loop over the tributable resource codes in that array? So returning that value.
But I agree and will change it.

Stan added inline comments.Apr 26 2019, 5:26 PM
binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
411

Well this returns the first element that it finds :)

let array = [12,41,42,31,26];
let result = array.find(a => a); // → result = 12
Freagarach updated this revision to Diff 7876.Sat, Apr 27, 5:31 PM
Freagarach marked 2 inline comments as done.

Some minor fixes.

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/components/tests/test_Player.js
|  16| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  28| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  40| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] ESLintBear (no-dupe-keys):
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  16| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  28| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.

binaries/data/mods/public/simulation/components/tests/test_Player.js
|  40| »   "BuildSchema":·(type)·=>·{
|    | [NORMAL] JSHintBear:
|    | Duplicate key 'BuildSchema'.
|    | [NORMAL] ESLintBear (semi):
|    | Missing semicolon.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  52|  52| 		if (data.isCurrency == true)
|  53|  53| 		{
|  54|  54| 			if (this.resourceCurrency)
|  55|    |-				warn("There is more than one currency defined, taking the last one.")
|    |  55|+				warn("There is more than one currency defined, taking the last one.");
|  56|  56| 			this.resourceCurrency = data.code;
|  57|  57| 		}
|  58|  58| 
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 3 tabs but found 2.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/globalscripts/Resources.js
|  63|  63| 	// Sort arrays by specified order
|  64|  64| 	let resSort = (a, b) =>
|  65|  65| 		a.order < b.order ? -1 :
|  66|    |-		a.order > b.order ? +1 : 0;
|    |  66|+			a.order > b.order ? +1 : 0;
|  67|  67| 
|  68|  68| 	this.resourceData.sort(resSort);
|  69|  69| 	this.resourceCodes.sort((a, b) => resSort(

binaries/data/mods/public/globalscripts/Resources.js
|  55| »   »   »   »   warn("There·is·more·than·one·currency·defined,·taking·the·last·one.")
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.

binaries/data/mods/public/simulation/components/tests/test_Barter.js
|  50| let·cmpBarter·=·ConstructComponent(SYSTEM_ENTITY,·"Barter");
|    | [NORMAL] JSHintBear:
|    | 'cmpBarter' was used before it was defined.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 102| 102| 				if (!mostNeeded)
| 103| 103| 					mostNeeded = gameState.ai.HQ.pickMostNeededResources(gameState);
| 104| 104| 				for (let k = 0; k < 2; ++k)
| 105|    |-				{
|    | 105|+				
| 106| 106| 					if (mostNeeded[k].type == res && mostNeeded[k].wanted > 0)
| 107| 107| 					{
| 108| 108| 						this.nextTributeRequest.set("all", gameState.ai.elapsedTime + 90);
| 112| 112| 							API3.warn("Tribute on " + res + " requested to player " + i);
| 113| 113| 						break;
| 114| 114| 					}
| 115|    |-				}
|    | 115|+				
| 116| 116| 			}
| 117| 117| 		}
| 118| 118| 		if (!toSend)
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'for-in'.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 159| 159| 			continue;
| 160| 160| 		let tributes = 0;
| 161| 161| 		for (let key in evt.amounts)
| 162|    |-		{
|    | 162|+		
| 163| 163| 			if (key === "food")
| 164| 164| 				tributes += evt.amounts[key];
| 165| 165| 			else
| 166| 166| 				tributes += 2*evt.amounts[key];
| 167|    |-		}
|    | 167|+		
| 168| 168| 		this.Config.personality.cooperative = Math.min(1, this.Config.personality.cooperative + 0.0001 * tributes);
| 169| 169| 	}
| 170| 170| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 238| 238| 
| 239| 239| 		// Our diplomacy will have changed already if the response was "accept"
| 240| 240| 		if (request.status === "waitingForTribute")
| 241|    |-		{
|    | 241|+		
| 242| 242| 			Engine.PostCommand(PlayerID, {
| 243| 243| 				"type": "tribute-request",
| 244| 244| 				"source": PlayerID,
| 246| 246| 				"resourceWanted": request.wanted,
| 247| 247| 				"resourceType": request.type
| 248| 248| 			});
| 249|    |-		}
|    | 249|+		
| 250| 250| 	}
| 251| 251| 
| 252| 252| 	// An AI player we sent a diplomacy request to demanded we send them a tribute
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/ai/petra/diplomacyManager.js
| 446| 446| {
| 447| 447| 	for (let [player, data] of this.receivedDiplomacyRequests)
| 448| 448| 		if (data.status === "waitingForTribute" && gameState.ai.elapsedTime > data.warnTime)
| 449|    |-		{
|    | 449|+		
| 450| 450| 			if (data.sentWarning)
| 451| 451| 			{
| 452| 452| 				this.receivedDiplomacyRequests.delete(player);
| 461| 461| 					"type": data.type
| 462| 462| 				});
| 463| 463| 			}
| 464|    |-		}
|    | 464|+		
| 465| 465| };
| 466| 466| 
| 467| 467| /**
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["sell"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|  95|  95| 	amountsToSubtract[resourceToSell] = amount;
|  96|  96| 	if (cmpPlayer.TrySubtractResources(amountsToSubtract))
|  97|  97| 	{
|  98|    |-		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
|    |  98|+		var amountToAdd = Math.round(prices.sell[resourceToSell] / prices["buy"][resourceToBuy] * amount);
|  99|  99| 		cmpPlayer.AddResource(resourceToBuy, amountToAdd);
| 100| 100| 
| 101| 101| 		// Display chat message to observers
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["buy"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/Barter.js
|  95|  95| 	amountsToSubtract[resourceToSell] = amount;
|  96|  96| 	if (cmpPlayer.TrySubtractResources(amountsToSubtract))
|  97|  97| 	{
|  98|    |-		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount);
|    |  98|+		var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices.buy[resourceToBuy] * amount);
|  99|  99| 		cmpPlayer.AddResource(resourceToBuy, amountToAdd);
| 100| 100| 
| 101| 101| 		// Display chat message to observers

binaries/data/mods/public/simulation/components/Barter.js
|  98| »   »   var·amountToAdd·=·Math.round(prices["sell"][resourceToSell]·/·prices["buy"][resourceToBuy]·*·amount);
|    | [NORMAL] JSHintBear:
|    | ['sell'] is better written in dot notation.

binaries/data/mods/public/simulation/components/Barter.js
|  98| »   »   var·amountToAdd·=·Math.round(prices["sell"][resourceToSell]·/·prices["buy"][resourceToBuy]·*·amount);
|    | [NORMAL] JSHintBear:
|    | ['buy'] is better written in dot notation.
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before '='.
|----|    | /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
| 429| 429| 	let candidate = { "gain": 0 };
| 430| 430| 	let potential = { "gain": 0 };
| 431| 431| 	let bestIndex = { "gain": 0 };
| 432|    |-	let bestLand  = { "gain": 0 };
|    | 432|+	let bestLand = { "gain": 0 };
| 433| 433| 
| 434| 434| 	let mapSize = gameState.sharedScript.mapSize;
| 435| 435| 	let traderTemplatesGains = gameState.getTraderTemplatesGains();
|    | [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
| 467| 467| 			if (m1.foundationProgress() === undefined && m2.foundationProgress() === undefined)
| 468| 468| 			{
| 469| 469| 				if (accessIndex)
| 470|    |-				{
|    | 470|+				
| 471| 471| 					if (gameState.ai.accessibility.regionType[accessIndex] == "water" && sea == accessIndex)
| 472| 472| 					{
| 473| 473| 						if (gain < bestIndex.gain)
| 486| 486| 							continue;
| 487| 487| 						bestLand = { "source": m1, "target": m2, "gain": gain, "land": land, "sea": sea };
| 488| 488| 					}
| 489|    |-				}
|    | 489|+				
| 490| 490| 				if (gain < candidate.gain)
| 491| 491| 					continue;
| 492| 492| 				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
| 606| 606| 		return;	// position found, but not enough gain compared to our present route
| 607| 607| 
| 608| 608| 	if (this.Config.debug > 1)
| 609|    |-	{
|    | 609|+	
| 610| 610| 		if (this.potentialTradeRoute)
| 611| 611| 			API3.warn("turn " + gameState.ai.playedTurn + "we could have a new route with gain " +
| 612| 612| 				marketPos[3] + " instead of the present " + this.potentialTradeRoute.gain);
| 613| 613| 		else
| 614| 614| 			API3.warn("turn " + gameState.ai.playedTurn + "we could have a first route with gain " +
| 615| 615| 				marketPos[3]);
| 616|    |-	}
|    | 616|+	
| 617| 617| 
| 618| 618| 	if (!this.tradeRoute)
| 619| 619| 		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
| 669| 669| 
| 670| 670| 	let ret = {};
| 671| 671| 	for (let key in route)
| 672|    |-	{
|    | 672|+	
| 673| 673| 		if (key == "source" || key == "target")
| 674| 674| 		{
| 675| 675| 			if (!route[key])
| 678| 678| 		}
| 679| 679| 		else
| 680| 680| 			ret[key] = route[key];
| 681|    |-	}
|    | 681|+	
| 682| 682| 	return ret;
| 683| 683| };
| 684| 684| 
|    | [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
| 689| 689| 
| 690| 690| 	let ret = {};
| 691| 691| 	for (let key in route)
| 692|    |-	{
|    | 692|+	
| 693| 693| 		if (key == "source" || key == "target")
| 694| 694| 		{
| 695| 695| 			ret[key] = gameState.getEntityById(route[key]);
| 698| 698| 		}
| 699| 699| 		else
| 700| 700| 			ret[key] = route[key];
| 701|    |-	}
|    | 701|+	
| 702| 702| 	return ret;
| 703| 703| };
| 704| 704| 
|    | [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
| 716| 716| m.TradeManager.prototype.Deserialize = function(gameState, data)
| 717| 717| {
| 718| 718| 	for (let key in data)
| 719|    |-	{
|    | 719|+	
| 720| 720| 		if (key == "tradeRoute" || key == "potentialTradeRoute")
| 721| 721| 			this[key] = this.routeIdToEnt(gameState, data[key]);
| 722| 722| 		else
| 723| 723| 			this[key] = data[key];
| 724|    |-	}
|    | 724|+	
| 725| 725| };
| 726| 726| 
| 727| 727| return m;

binaries/data/mods/public/gui/session/menu.js
| 482| »   »   button.onPress·=·(function(player,·stance)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'stance' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'resCode' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 514| »   »   button.onPress·=·(function(i,·resCode,·button)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'button' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 557| »   button.onPress·=·(function(i)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 623| »   button.onPress·=·(function(i,·button)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'i' is already declared in the upper scope.

binaries/data/mods/public/gui/session/menu.js
| 623| »   button.onPress·=·(function(i,·button)·{·return·function()·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'button' is already declared in the upper scope.
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 452| 452| 				continue;
| 453| 453| 
| 454| 454| 			if (state.pack.progress == 0)
| 455|    |-			{
|    | 455|+			
| 456| 456| 				if (state.pack.packed)
| 457| 457| 					checks.unpackButton = true;
| 458| 458| 				else
| 459| 459| 					checks.packButton = true;
| 460|    |-			}
|    | 460|+			
| 461| 461| 			else if (state.pack.packed)
| 462| 462| 				checks.unpackCancelButton = true;
| 463| 463| 			else
|    | [NORMAL] ESLintBear (space-before-function-paren):
|    | Unexpected space before function parentheses.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 763| 763| 				addResearchToQueue(data.item.researchFacilityId, t);
| 764| 764| 			})(tech);
| 765| 765| 
| 766|    |-			button.onPressRight = (t => function () {
|    | 766|+			button.onPressRight = (t => function() {
| 767| 767| 				showTemplateDetails(
| 768| 768| 					t,
| 769| 769| 					GetTemplateData(data.unitEntStates.find(state => state.id == data.item.researchFacilityId).template).nativeCiv);
|    | [NORMAL] ESLintBear (semi):
|    | Missing semicolon.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/gui/session/selection_panels.js
| 941| 941| 			"player": data.player
| 942| 942| 		});
| 943| 943| 
| 944|    |-		let unitIds = data.unitEntStates.map(status => status.id)
|    | 944|+		let unitIds = data.unitEntStates.map(status => status.id);
| 945| 945| 		let [buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch] =
| 946| 946| 			getTrainingStatus(unitIds, data.item, data.playerState);
| 947| 947| 

binaries/data/mods/public/gui/session/selection_panels.js
|  48| »   »   »   switch·(data.item)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
|  59| »   »   switch·(data.item)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
| 731| »   »   »   »   »   »   switch·(entity.check)
|    | [NORMAL] ESLintBear (default-case):
|    | Expected a default case.

binaries/data/mods/public/gui/session/selection_panels.js
| 944| »   »   let·unitIds·=·data.unitEntStates.map(status·=>·status.id)
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.

binaries/data/mods/public/simulation/components/Player.js
| 385| »   for·(var·type·in·amounts)
|    | [NORMAL] JSHintBear:
|    | 'type' is already defined.
Executing section cli...

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

Freagarach marked 8 inline comments as done.Mon, Apr 29, 7:44 PM

Two questions:

  • Can anyone help me how to make a function of the sorting (in Resources.js)? (And in test_Player.js.)
  • Which of the two functions I introduced in Resources.js would be most efficient? Currently GetTributableCodes/GetBarterableCodes/GetTradableCodes is used, which is just an array of the respective codes. Should I just remove the other functions since they are not used?