Research update

* Implemented new research update. Old research system no longer
updates.

* Fixed a major bug in the constants registrar

* Added game.research.vacation constant (determines the rate of
research when players are in vacation mode)
This commit is contained in:
Emmanuel BENOîT 2012-04-02 13:29:43 +02:00
parent a14601df37
commit c7949e41cc
11 changed files with 414 additions and 85 deletions
legacyworlds-server-data/db-structure/parts/040-functions

View file

@ -21,7 +21,7 @@
* _empire The empire's identifier
* _technology The string identifier for the technology to implement
*/
DROP FUNCTION emp.technology_implement( INT , TEXT );
DROP FUNCTION IF EXISTS emp.technology_implement( INT , TEXT );
CREATE FUNCTION emp.technology_implement( _empire INT , _technology TEXT )
RETURNS BOOLEAN
LANGUAGE PLPGSQL
@ -291,6 +291,56 @@ GRANT EXECUTE
/*
* Compute an empire's total research points
* ------------------------------------------
*
* Obtain an empire's total research points by adding the happiness-adjusted
* value for each planet, then applying the global modifier for vacation mode
* if necessary.
*
* FIXME: time factor is hard-coded
*
* Parameters:
* _empire The empire's identifier
* _on_vacation TRUE if the player is on vacation, FALSE otherwise
*
* Returns:
* ? The amount of research points.
*/
DROP FUNCTION IF EXISTS emp.research_get_points( INT , BOOLEAN );
CREATE FUNCTION emp.research_get_points( _empire INT , _on_vacation BOOLEAN )
RETURNS DOUBLE PRECISION
LANGUAGE SQL
STRICT STABLE
SECURITY INVOKER
AS $research_get_points$
SELECT SUM( verse.adjust_production(
_planet.population * sys.get_constant( 'game.research.basePoints' ) ,
_happiness.current / _planet.population
) ) * ( CASE
WHEN $2 THEN
sys.get_constant( 'game.research.vacation' )
ELSE
1.0
END )::DOUBLE PRECISION
FROM emp.planets _emp_planet
INNER JOIN verse.planets _planet
ON _emp_planet.planet_id = _planet.name_id
INNER JOIN verse.planet_happiness _happiness
USING ( planet_id )
WHERE _emp_planet.empire_id = $1;
$research_get_points$;
REVOKE EXECUTE
ON FUNCTION emp.research_get_points( INT , BOOLEAN )
FROM PUBLIC;
/*
* Technology visibility view