1
0
forked from 0ad/0ad

Fix renaming fields losing the ability to be gathered.

Introduced in c888844b3a.
The problem was trying to set the amount to Infinity by substracting
Infinity from it.

Differential revision: https://code.wildfiregames.com/D4263
Tested by: @Langbart
Fixes: #6317

This was SVN commit r25912.
This commit is contained in:
Freagarach 2021-09-10 06:22:43 +00:00
parent e9f1b0799a
commit e56d46548b
2 changed files with 20 additions and 0 deletions

View File

@ -257,6 +257,9 @@ ResourceSupply.prototype.Change = function(change)
*/
ResourceSupply.prototype.SetAmount = function(newValue)
{
// We currently don't support changing to or fro Infinity.
if (this.IsInfinite() || newValue === Infinity)
return;
this.Change(newValue - this.amount);
};

View File

@ -91,6 +91,23 @@ TS_ASSERT(!cmpResourceSupply.IsAvailableTo(70));
cmpResourceSupply.RemoveGatherer(71);
TS_ASSERT_EQUALS(cmpResourceSupply.GetNumGatherers(), 0);
// #6317
const infiniteTemplate = {
"Max": "Infinity",
"Type": "food.grain",
"KillBeforeGather": "false",
"MaxGatherers": "1"
};
const cmpInfiniteResourceSupply = ConstructComponent(entity, "ResourceSupply", infiniteTemplate);
cmpResourceSupply.OnOwnershipChanged({ "to": 1 });
TS_ASSERT(cmpInfiniteResourceSupply.IsInfinite());
TS_ASSERT_UNEVAL_EQUALS(cmpInfiniteResourceSupply.TakeResources(300), { "amount": 300, "exhausted": false });
cmpInfiniteResourceSupply.OnEntityRenamed({ "newentity": entity });
TS_ASSERT(cmpInfiniteResourceSupply.IsAvailable());
// Test Changes.