Page MenuHomeWildfire Games

Decay/regenerate option for resources when not being gathered from
AbandonedPublic

Authored by smiley on Sun, Dec 30, 9:17 AM.

Details

Reviewers
None
Summary

Salvaged from an old diff. Which was probably made after seeing a post on the forum requesting this feature for mods.
Also included is a use case for huntable animals which would rot away or be scavenged.

Test Plan

Agree this could be a nice addition.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Lint Skipped
Unit
Unit Tests Skipped
Build Status
Buildable 6594
Build 10880: Vulcan BuildJenkins

Event Timeline

smiley created this revision.Sun, Dec 30, 9:17 AM
Vulcan added a subscriber: Vulcan.Sun, Dec 30, 10:19 AM

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

Linter detected issues:
Executing section Default...
Executing section Source...
Executing section JS...
|    | [NORMAL] ESLintBear (no-trailing-spaces):
|    | Trailing spaces not allowed.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/ResourceSupply.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/ResourceSupply.js
|  47|  47| {
|  48|  48| 	// Current resource amount (non-negative)
|  49|  49| 	this.amount = this.GetMaxAmount();
|  50|    |-	
|    |  50|+
|  51|  51| 	this.regenRate = null;
|  52|  52| 	this.regenInterval = null;
|  53|  53| 	this.regenerate = null; // timer
|    | [NORMAL] ESLintBear (semi):
|    | Missing semicolon.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/ResourceSupply.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/ResourceSupply.js
|  63|  63| 
|  64|  64| 	// List of IDs for each player
|  65|  65| 	this.gatherers = [];
|  66|    |-	let numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers()
|    |  66|+	let numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers();
|  67|  67| 	for (let i = 0; i < numPlayers; ++i)
|  68|  68| 		this.gatherers.push([]);
|  69|  69| 
|    | [NORMAL] ESLintBear (curly):
|    | Unnecessary { after 'if' condition.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/ResourceSupply.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/ResourceSupply.js
| 178| 178| {
| 179| 179| 	// this can happen if the unit is dead
| 180| 180| 	if (player == undefined || player == INVALID_PLAYER)
| 181|    |-	{
|    | 181|+	
| 182| 182| 		for (var i = 0; i < this.gatherers.length; ++i)
| 183| 183| 			this.RemoveGatherer(gathererID, i);
| 184|    |-	}
|    | 184|+	
| 185| 185| 	else
| 186| 186| 	{
| 187| 187| 		var index = this.gatherers[player].indexOf(gathererID);
|    | [NORMAL] ESLintBear (comma-spacing):
|    | A space is required after ','.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/ResourceSupply.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/ResourceSupply.js
| 187| 187| 		var index = this.gatherers[player].indexOf(gathererID);
| 188| 188| 		if (index !== -1)
| 189| 189| 		{
| 190|    |-			this.gatherers[player].splice(index,1);
|    | 190|+			this.gatherers[player].splice(index, 1);
| 191| 191| 			// broadcast message, mainly useful for the AIs.
| 192| 192| 			Engine.PostMessage(this.entity, MT_ResourceSupplyNumGatherersChanged, { "to": this.GetNumGatherers() });
| 193| 193| 			return;
|    | [NORMAL] ESLintBear (no-trailing-spaces):
|    | Trailing spaces not allowed.
|----|    | /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/ResourceSupply.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/differential/binaries/data/mods/public/simulation/components/ResourceSupply.js
| 193| 193| 			return;
| 194| 194| 		}
| 195| 195| 	}
| 196|    |-	
|    | 196|+
| 197| 197| 	if (!this.gatherers.every((player) => player.length))
| 198| 198| 		this.regenerate = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).SetInterval(this.entity, IID_ResourceSupply, "RegenerateSupply", this.regenInterval, this.regenInterval, undefined);
| 199| 199| };

binaries/data/mods/public/simulation/components/ResourceSupply.js
| 197| »   if·(!this.gatherers.every((player)·=>·player.length))
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'player' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/ResourceSupply.js
|  66| »   let·numPlayers·=·Engine.QueryInterface(SYSTEM_ENTITY,·IID_PlayerManager).GetNumPlayers()
|    | [NORMAL] JSHintBear:
|    | Missing semicolon.

binaries/data/mods/public/simulation/components/ResourceSupply.js
| 116| »   »   »   »   return·diminishingReturns·==·1·?·1·:·(1.·-·Math.pow(diminishingReturns,·numGatherers))·/·(1.·-·diminishingReturns)·/·numGatherers;
|    | [NORMAL] JSHintBear:
|    | A trailing decimal point can be confused with a dot: '1.'.

binaries/data/mods/public/simulation/components/ResourceSupply.js
| 116| »   »   »   »   return·diminishingReturns·==·1·?·1·:·(1.·-·Math.pow(diminishingReturns,·numGatherers))·/·(1.·-·diminishingReturns)·/·numGatherers;
|    | [NORMAL] JSHintBear:
|    | A trailing decimal point can be confused with a dot: '1.'.

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

elexis added a subscriber: elexis.Sun, Dec 30, 2:28 PM

Flesh doesn't stop rotting and flora/fungi don't stop growing while gathering from them?

(Aura/Tech effects could apply to it. Then the two new member variables would actually be written to more than once on init. Otherwise they can be inlined I suppose)
(Also I should be more patient with posting comments)

binaries/data/mods/public/simulation/components/ResourceSupply.js
53

this.regenerateTimer

55

this.template.Regeneration

In D1718#68039, @elexis wrote:

Flesh doesn't stop rotting and flora/fungi don't stop growing while gathering from them?

Abstractions. Although, being abandoned would accelerate just things. Ghost towns become reclaimed by nature. Carcasses would attract more insects and whatnot.
Which played a lesser role than actually writing something new.

smiley added inline comments.Sun, Dec 30, 2:41 PM
binaries/data/mods/public/simulation/components/ResourceSupply.js
55

I thought that would error out without !!

smiley abandoned this revision.Tue, Jan 15, 8:41 AM

Doesn’t seem like the current gameplay design needs this.
Regarding the patch itself if a modder is interested.
It’s missing a max check.

Stan added a subscriber: Stan.Tue, Jan 15, 9:24 AM

I would have loved this for fauna. Also like in AOM where cows gained food overtime'

(The patch is still here and can be commited if you want)

Stan added a comment.Tue, Jan 15, 1:28 PM

Sure. But first I need to fix the comments and get another review from a team programmer.

Might also be nice to add some tests.