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

View file

@ -24,6 +24,7 @@
\i parts/functions/110-prefs-functions.sql
\i parts/functions/120-map-functions.sql
\i parts/functions/140-planets-functions.sql
\i parts/functions/145-resource-providers-functions.sql
\i parts/functions/150-battle-functions.sql
\i parts/functions/160-battle-views.sql
\i parts/functions/163-alliance-functions.sql

View file

@ -19,4 +19,5 @@
\i parts/updates/080-planet-construction.sql
\i parts/updates/090-planet-military.sql
\i parts/updates/100-planet-population.sql
\i parts/updates/105-planet-resource-regeneration.sql
\i parts/updates/110-planet-money.sql

View file

@ -28,20 +28,53 @@ CREATE TYPE log_type
-- Update types
CREATE TYPE update_type AS ENUM (
/* Empires' money is being updated using the previous update's results */
'EMPIRE_MONEY' ,
/* Empire research points are being attributed to technologies */
'EMPIRE_RESEARCH' ,
/* The effects of empires' debts are being computed */
'EMPIRE_DEBT' ,
/* Fleets which were 1 update away are arriving at their destination */
'PLANET_FLEET_ARRIVALS' ,
/* Other fleets are moving */
'PLANET_FLEET_MOVEMENTS' ,
/* Fleet states (e.g. "deploying", "unavailable", etc...) are being
* updated.
*/
'PLANET_FLEET_STATUS' ,
/* Start new battles where necessary */
'PLANET_BATTLE_START' ,
/* Process all in-progress battles */
'PLANET_BATTLE_MAIN' ,
/* Finalise battles that need to be ended */
'PLANET_BATTLE_END' ,
/* Abandon planets */
'PLANET_ABANDON' ,
/* Handle civilian build queues */
'PLANET_CONSTRUCTION' ,
/* Handle military build queues */
'PLANET_MILITARY' ,
/* Update planets' population */
'PLANET_POPULATION' ,
'PLANET_MONEY'
/* Regenerate resources in resource providers */
'PLANET_RES_REGEN' ,
/* Compute income and upkeep of planets */
'PLANET_MONEY'
);
-- Types of recapitulative e-mail messages

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;

View file

@ -0,0 +1,47 @@
-- LegacyWorlds Beta 6
-- PostgreSQL database scripts
--
-- Game updates - resource regeneration
--
-- Copyright(C) 2004-2012, DeepClone Development
-- --------------------------------------------------------
/*
* Resource provider regeneration update
*
* This function computes the regeneration of resource providers for the current batch
* of planets.
*
* Parameters:
* _tick The identifier of the game update
*/
CREATE OR REPLACE FUNCTION sys.process_planet_res_regen_updates( _tick BIGINT )
RETURNS VOID
STRICT VOLATILE
SECURITY INVOKER
AS $process_planet_res_regen_updates$
UPDATE verse.resource_providers _provider
SET resprov_quantity = verse.compute_provider_regeneration(
_provider.resprov_quantity ,
_provider.resprov_quantity_max ,
_provider.resprov_recovery
)
FROM sys.updates _upd_sys
INNER JOIN verse.updates _upd_verse
ON _upd_verse.update_id = _upd_sys.id
WHERE _upd_sys.last_tick = $1
AND _upd_sys.status = 'PROCESSING'
AND _upd_sys.gu_type = 'PLANET_RES_REGEN'
AND _provider.planet_id = _upd_verse.planet_id;
$process_planet_res_regen_updates$ LANGUAGE SQL;
REVOKE EXECUTE
ON FUNCTION sys.process_planet_res_regen_updates( BIGINT )
FROM PUBLIC;