Resource provider regeneration

Implemented resource regeneration computation in the
verse.compute_provider_regeneration() function.

Created the PLANET_RES_REGEN update type, and added the corresponding
implementation.

Added resource regeneration constants registration.
This commit is contained in:
Emmanuel BENOîT 2012-01-02 15:10:04 +01:00
parent d768766214
commit 66c72ef718
8 changed files with 443 additions and 1 deletions
legacyworlds-server-data/db-structure/parts/functions

View file

@ -0,0 +1,61 @@
-- LegacyWorlds Beta 6
-- PostgreSQL database scripts
--
-- Resource providers functions
--
-- Copyright(C) 2004-2012, DeepClone Development
-- --------------------------------------------------------
/*
* Compute resource provider regeneration
*
* This function computes the quantity in a resource provider after it has
* been regenerated.
*
* Parameters:
* _quantity The current quantity of resources in the provider
* _max The maximal amount of resources supported by the
* provider
* _recovery_rate The provider's recovery rate
*
* Returns:
* ? The new quantity of resources.
*/
CREATE OR REPLACE FUNCTION verse.compute_provider_regeneration(
_quantity DOUBLE PRECISION ,
_max DOUBLE PRECISION ,
_recovery_rate DOUBLE PRECISION )
RETURNS DOUBLE PRECISION
STRICT IMMUTABLE
SECURITY INVOKER
AS $compute_provider_regeneration$
DECLARE
_uc_recovery DOUBLE PRECISION;
_uc_dampening DOUBLE PRECISION;
_uc_ticks DOUBLE PRECISION;
_result DOUBLE PRECISION;
BEGIN
_uc_recovery := sys.get_constant( 'game.resources.recovery' );
_uc_dampening := sys.get_constant( 'game.resources.recoveryDampening' );
_uc_ticks := 1440; -- FIXME: this should be a constant
_result := ( 1 - _quantity / _max ) ^ _uc_dampening;
_result := _quantity + _result * _recovery_rate * _uc_recovery / _uc_ticks;
IF _result > _max THEN
_result := _max;
END IF;
RETURN _result;
END;
$compute_provider_regeneration$ LANGUAGE PLPGSQL;
REVOKE EXECUTE
ON FUNCTION verse.compute_provider_regeneration(
DOUBLE PRECISION , DOUBLE PRECISION ,
DOUBLE PRECISION )
FROM PUBLIC;