Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3132 closed defect (fixed)

[PATCH] Return proportional amount of resources when deleting foundations

Reported by: elexis Owned by: mimo
Priority: Should Have Milestone: Alpha 19
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description (last modified by sanderd17)

Currently 100% of the resources are returned when a building foundation is deleted or destroyed.

The source code actually says that a proportional amount should be returned. Only because of a programming mistake or bug 100% are returned.

See function Foundation.prototype.OnDestroy in file trunk/binaries/data/mods/public/simulation/components/Foundation.js

Foundation.prototype.OnDestroy = function()
{
	// Refund a portion of the construction cost, proportional to the amount of build progress remaining
        // ...

	for (var r in this.costs)
	{
		var scaled = Math.floor(this.costs[r] * (1.0 - this.GetBuildProgress()));
                // ...
	}
};


/**
 * Returns the current build progress in a [0,1] range.
 */
Foundation.prototype.GetBuildProgress = function()
{
	var cmpHealth = Engine.QueryInterface(this.entity, IID_Health)
	var hitpoints = cmpHealth.GetHitpoints();
	var maxHitpoints = cmpHealth.GetMaxHitpoints();
	return (hitpoints / maxHitpoints);
};

http://svn.wildfiregames.com/public/ps/trunk/binaries/data/mods/public/simulation/components/Foundation.js

The GetBuildProgress() function always returns 0 because the hitpoint count in this function equates to 0.

Attachments (1)

t3132_refund_a_bit_more_resources.patch (892 bytes ) - added by elexis 9 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 by sanderd17, 9 years ago

Description: modified (diff)
Summary: Return proportional amount of resources when deleting buildingsReturn proportional amount of resources when deleting foundations

comment:2 by mimo, 9 years ago

Owner: set to mimo
Resolution: fixed
Status: newclosed

In 16470:

fix computation of foundation refund when destroyed, fixes #3132

comment:3 by mimo, 9 years ago

Component: Core engineUI & Simulation
Milestone: BacklogAlpha 19

comment:4 by elexis, 9 years ago

Resolution: fixed
Status: closedreopened

comment:5 by elexis, 9 years ago

With the patch above, it will refund 100% of the resources when a completely unbuilt building will be deleted. Currently it returns only 99%, which is a bit annoying when playing nomad and you misplaced your CC. In that case you will not be able to place it somewhere else without gathering 1 unit of each resource.

comment:6 by elexis, 9 years ago

Keywords: patch review added
Summary: Return proportional amount of resources when deleting foundations[PATCH] Return proportional amount of resources when deleting foundations

comment:7 by mimo, 9 years ago

Resolution: fixed
Status: reopenedclosed

In 16574:

fix rounding when returning resources from aborted foundation, patch by elexis, fixes #3132

comment:8 by mimo, 9 years ago

Keywords: review removed

thanks for the patch

comment:9 by elexis, 9 years ago

r16622 not only fixed a oos that was caused by the original patch - it also changes the behaviour of the refund. The original patch refunded resources just by the current build progress, while the new behaviour is to return resources according to the highest build progress.

This way another 'bug' is fixed. If you would build a CC 90% and then the enemy destroys it, you would get returned 100% of the resources. With the newer version you get only those 10% back. Thanks for that fix.

in reply to:  9 ; comment:10 by mimo, 9 years ago

Replying to elexis:

r16622 not only fixed a oos that was caused by the original patch - it also changes the behaviour of the refund. The original patch refunded resources just by the current build progress, while the new behaviour is to return resources according to the highest build progress.

hummm, did you read or used the original patch before posting this comment ? the highest build progress was there since the first patch.

in reply to:  10 comment:11 by elexis, 9 years ago

Replying to mimo:

hummm, did you read or used the original patch before posting this comment ? the highest build progress was there since the first patch.

Ah, true. Sorry for not crediting you.

Before mimos patch (r16470) it had the wrong behaviour (returning always 100% when a structure is destroyed by enemies).

http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/public/simulation/components/Foundation.js?rev=16469

Note: See TracTickets for help on using tickets.