Mining computation update

* Added various views and helper functions used by the mining
computation but which may be re-used in other parts.

* Added mining computation update type and associated update function

* New constants: game.resources.weightBase (the value used to compute
weights from mining settings) and game.resources.extraction (the
quantity extracted in a day from a full provider at difficulty 0)
This commit is contained in:
Emmanuel BENOîT 2012-01-16 12:35:20 +01:00
parent 038bba896a
commit 74b6f2ab09
20 changed files with 1139 additions and 2 deletions
legacyworlds-server-data/db-structure/parts/040-functions

View file

@ -98,4 +98,44 @@ CREATE VIEW emp.mining_settings_view
GRANT SELECT
ON emp.mining_settings_view
TO :dbuser;
TO :dbuser;
/*
* Compute a resource provider's extraction factor
*
* This function computes the extraction factor - a multiplier which makes
* mining more costly if the difficulty is high or if a provider is almost
* empty - based on a provider's fill ratio and difficulty.
*
* The complete formula can be read on the Wiki:
* https://wiki.legacyworlds.com/wiki/Mining#Resource_provider_extraction
*
* Parameters:
* _fill_ratio The ratio between the provider's current and maximal
* quantities
* _difficulty The provider's extraction difficulty.
*
* Returns:
* ? The provider's extraction factor
*/
DROP FUNCTION IF EXISTS verse.get_extraction_factor(
DOUBLE PRECISION , DOUBLE PRECISION );
CREATE FUNCTION verse.get_extraction_factor(
_fill_ratio DOUBLE PRECISION ,
_difficulty DOUBLE PRECISION )
RETURNS DOUBLE PRECISION
STRICT IMMUTABLE
SECURITY INVOKER
AS $get_extraction_factor$
SELECT ( 1 - $2 * 0.5 ) * POW( $1 , 1.5 + 2 * $2 );
$get_extraction_factor$ LANGUAGE SQL;
REVOKE EXECUTE
ON FUNCTION verse.get_extraction_factor(
DOUBLE PRECISION , DOUBLE PRECISION )
FROM PUBLIC;