Extracted quantities update as soon as possible

* The quantities of resources extracted from mines will now be updated
as soon as they have a reason to. This includes planet assignment,
abandonment, ownership changes, and updates to mining priorities.

* The mining update will now remove the current resource income from the
providers, and only then re-compute all extracted quantities. This is
more logical and corresponds to the way the other game updates work.

* Fixed bug in extraction computation where the size of the planet's
happy population was used instead of the happy/total ratio when
adjusting the mining production for riots.

* The following SQL scripts must be re-executed to upgrade a database:
  -> 040-functions/040-empire.sql
  -> 040-functions/145-resource-providers.sql
  -> 040-functions/147-empire-mining.sql
  -> 050-updates/120-planet-mining.sql
This commit is contained in:
Emmanuel BENOîT 2012-02-09 10:54:00 +01:00
parent f3aa563758
commit bf6bea5a79
35 changed files with 863 additions and 372 deletions
legacyworlds-server-data/db-structure/tests/admin/040-functions/040-empire

View file

@ -3,7 +3,7 @@
*/
BEGIN;
/* We need a pair of natural resources, a basic resource, a planet
* and an empire name.
* and an empire name. We add a resource provider to the planet.
*/
\i utils/strings.sql
\i utils/resources.sql
@ -14,9 +14,42 @@ BEGIN;
SELECT _create_resources( 1 , 'basicRes' );
SELECT _create_raw_planets( 1 , 'testPlanet' );
SELECT _create_emp_names( 1 , 'testEmp' );
INSERT INTO verse.planet_resources( planet_id , resource_name_id )
SELECT name_id , resource_name_id
FROM verse.planets CROSS JOIN defs.resources;
INSERT INTO verse.resource_providers (
planet_id , resource_name_id , resprov_quantity_max ,
resprov_quantity , resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'natRes1' ) , 100 ,
100 , 0.2 , 0.5
);
/* We replace the emp.mining_get_input() and emp.mining_compute_extraction()
* functions with something we control fully.
*/
CREATE OR REPLACE FUNCTION emp.mining_get_input( _empire INT )
RETURNS SETOF emp.planet_mining_type
LANGUAGE SQL
AS $$
SELECT _get_map_name( 'testPlanet1' ) AS planet ,
_get_string( 'natRes1' ) AS resource ,
NULL::DOUBLE PRECISION AS quantity , NULL::DOUBLE PRECISION AS quantity_max ,
NULL::DOUBLE PRECISION AS difficulty , NULL::INT AS empire ,
NULL::REAL AS happiness , NULL::DOUBLE PRECISION AS weight ,
NULL::DOUBLE PRECISION AS total_weight;
$$;
CREATE OR REPLACE FUNCTION emp.mining_compute_extraction( _input emp.planet_mining_type )
RETURNS DOUBLE PRECISION LANGUAGE SQL
AS $$
SELECT 42::DOUBLE PRECISION;
$$;
/***** TESTS BEGIN HERE *****/
SELECT plan( 7 );
SELECT plan( 8 );
SELECT emp.create_empire( _get_emp_name( 'testEmp1' ) ,
_get_map_name( 'testPlanet1' ) ,
@ -25,10 +58,12 @@ BEGIN;
SELECT diag_test_name( 'emp.create_empire() - Empire exists' );
SELECT is( COUNT(*)::INT , 1 ) FROM emp.empires
WHERE name_id = _get_emp_name( 'testEmp1' );
SELECT diag_test_name( 'emp.create_empire() - Empire cash' );
SELECT diag_test_name( 'emp.create_empire() - Empire cash set' );
SELECT is( cash , 200.0::REAL ) FROM emp.empires
WHERE name_id = _get_emp_name( 'testEmp1' );
SELECT diag_test_name( 'emp.create_empire() - Empire debt' );
SELECT diag_test_name( 'emp.create_empire() - Empire debt set' );
SELECT is( debt , 0.0::REAL ) FROM emp.empires
WHERE name_id = _get_emp_name( 'testEmp1' );
@ -57,5 +92,11 @@ BEGIN;
FROM emp.resources
WHERE empire_id = _get_emp_name( 'testEmp1' );
SELECT diag_test_name( 'emp.create_empire() - Resource mining has been updated' );
SELECT is( pres_income::DOUBLE PRECISION , 42::DOUBLE PRECISION )
FROM verse.planet_resources
WHERE planet_id = _get_map_name( 'testPlanet1' )
AND resource_name_id = _get_string( 'natRes1' );
SELECT * FROM finish( );
ROLLBACK;