This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server-data/db-structure/tests/utils/common-setup/setup-gu-pmc-get-data-test.sql
Emmanuel BENOîT bf6bea5a79 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
2012-02-09 10:54:00 +01:00

157 lines
5.6 KiB
PL/PgSQL

/*
* We need rows in quite a few tables to make sure locking works as
* advertised.
*
* - First we will need a planet with no resource providers. This one
* shouldn't be selected at all.
*
* - We need a planet with resource providers, but no owning empire. The
* planet will be selected, but all fields that are obtained from the
* empire's data will be NULL.
*
* - We need a planet owned by an empire for which empire-wide settings
* will be used.
*
* - We need a planet owned by an empire but that uses planet-specific
* settings.
*
* - We need a planet with no resource providers owned by an empire. This
* one shouldn't be selected.
*
* - Finally, we need a planet that matches the criterias but isn't
* scheduled for an update at the time.
*
* FIXME: cannot test where the happiness column comes from until values
* all use DOUBLE PRECISION.
*/
DELETE FROM sys.update_types
WHERE updtype_name <> 'PlanetMining';
\i utils/strings.sql
\i utils/resources.sql
\i utils/accounts.sql
\i utils/naming.sql
\i utils/universe.sql
SELECT sys.uoc_constant( 'game.resources.weightBase' , '(test)' , 'Resources' , 10.0 );
SELECT _create_natural_resources( 2 , 'resource' );
SELECT _create_raw_planets( 6 , 'planet' );
SELECT _create_emp_names( 5 , 'empire' );
INSERT INTO emp.empires ( name_id , cash )
SELECT id , 0 FROM naming.empire_names;
/* Planet #2 */
INSERT INTO verse.resource_providers (
planet_id , resource_name_id , resprov_quantity_max ,
resprov_quantity , resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'planet2' ) , _get_string( 'resource1' ) , 100 ,
100 , 0.2 , 0.5
) , (
_get_map_name( 'planet2' ) , _get_string( 'resource2' ) , 100 ,
100 , 0.2 , 0.5
);
/* Planet #3 */
INSERT INTO verse.resource_providers (
planet_id , resource_name_id , resprov_quantity_max ,
resprov_quantity , resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'planet3' ) , _get_string( 'resource1' ) , 100 ,
100 , 0.3 , 0.5
) , (
_get_map_name( 'planet3' ) , _get_string( 'resource2' ) , 100 ,
100 , 0.3 , 0.5
);
INSERT INTO verse.planet_happiness ( planet_id , current , target )
VALUES ( _get_map_name( 'planet3' ) , 0.3 , 0.3 );
INSERT INTO emp.planets ( empire_id , planet_id )
VALUES ( _get_emp_name( 'empire1' ) , _get_map_name( 'planet3' ) );
INSERT INTO emp.mining_settings( empire_id , resource_name_id , empmset_weight )
VALUES (
_get_emp_name( 'empire1' ) , _get_string( 'resource1' ) , 2
) , (
_get_emp_name( 'empire1' ) , _get_string( 'resource2' ) , 2
);
/* Planet #4 */
INSERT INTO verse.resource_providers (
planet_id , resource_name_id , resprov_quantity_max ,
resprov_quantity , resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'planet4' ) , _get_string( 'resource1' ) , 100 ,
100 , 0.4 , 0.5
) , (
_get_map_name( 'planet4' ) , _get_string( 'resource2' ) , 100 ,
100 , 0.4 , 0.5
);
INSERT INTO verse.planet_happiness ( planet_id , current , target )
VALUES ( _get_map_name( 'planet4' ) , 0.4 , 0.4 );
INSERT INTO emp.planets ( empire_id , planet_id )
VALUES ( _get_emp_name( 'empire2' ) , _get_map_name( 'planet4' ) );
INSERT INTO emp.mining_settings( empire_id , resource_name_id , empmset_weight )
VALUES (
_get_emp_name( 'empire2' ) , _get_string( 'resource1' ) , 2
) , (
_get_emp_name( 'empire2' ) , _get_string( 'resource2' ) , 2
);
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id , resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'empire2' ) , _get_map_name( 'planet4' ) , _get_string( 'resource1' ) , 1
) , (
_get_emp_name( 'empire2' ) , _get_map_name( 'planet4' ) , _get_string( 'resource2' ) , 3
);
/* Planet #5 */
INSERT INTO verse.planet_happiness ( planet_id , current , target )
VALUES ( _get_map_name( 'planet5' ) , 0.5 , 0.5 );
INSERT INTO emp.planets ( empire_id , planet_id )
VALUES ( _get_emp_name( 'empire3' ) , _get_map_name( 'planet5' ) );
INSERT INTO emp.mining_settings( empire_id , resource_name_id , empmset_weight )
VALUES (
_get_emp_name( 'empire3' ) , _get_string( 'resource1' ) , 2
) , (
_get_emp_name( 'empire3' ) , _get_string( 'resource2' ) , 2
);
/* Planet #6 */
INSERT INTO verse.resource_providers (
planet_id , resource_name_id , resprov_quantity_max ,
resprov_quantity , resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'planet6' ) , _get_string( 'resource1' ) , 100 ,
100 , 0.6 , 0.5
) , (
_get_map_name( 'planet6' ) , _get_string( 'resource2' ) , 100 ,
100 , 0.6 , 0.5
);
INSERT INTO verse.planet_happiness ( planet_id , current , target )
VALUES ( _get_map_name( 'planet6' ) , 0.6 , 0.6 );
INSERT INTO emp.planets ( empire_id , planet_id )
VALUES ( _get_emp_name( 'empire4' ) , _get_map_name( 'planet6' ) );
INSERT INTO emp.mining_settings( empire_id , resource_name_id , empmset_weight )
VALUES (
_get_emp_name( 'empire4' ) , _get_string( 'resource1' ) , 2
) , (
_get_emp_name( 'empire4' ) , _get_string( 'resource2' ) , 2
);
/* Insert planet resource records */
INSERT INTO verse.planet_resources ( planet_id , resource_name_id , pres_income , pres_upkeep )
SELECT p.name_id , r.resource_name_id , 42 , 0
FROM verse.planets p CROSS JOIN defs.resources r;
/* Modify update records for the planets. Planet 6 is not to be processed.
*/
UPDATE sys.updates su
SET update_state = 'PROCESSING' , update_last = 0
FROM verse.planets_updates vu
WHERE vu.update_id = su.update_id
AND vu.name_id <> _get_map_name( 'planet6' );
UPDATE sys.updates su
SET update_state = 'PROCESSED' , update_last = 0
FROM verse.planets_updates vu
WHERE vu.update_id = su.update_id
AND vu.name_id = _get_map_name( 'planet6' );