Planet resources and resource providers in XML dumps
* Dump version bumped up to 2 * Added SQL view that shows resource delta and provider information for all empire-owned planets * Added new storage classes for resource providers and resource deltas * Added row mapper which extracts all planet resources information (providers and deltas) * Modified dump generator to include planet resources / resource providers
This commit is contained in:
parent
95e6019c12
commit
ce6d86d344
17 changed files with 1607 additions and 50 deletions
legacyworlds-server-data/db-structure
parts/040-functions
tests
admin/040-functions/200-bugs
user/040-functions/200-bugs
|
@ -1220,6 +1220,54 @@ CREATE VIEW bugs.dump_planets_view
|
|||
GRANT SELECT ON bugs.dump_planets_view TO :dbuser;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Planet resources view for XML dumps
|
||||
* ------------------------------------
|
||||
*
|
||||
* This view combines both planet resources and resource providers for all
|
||||
* empire-owned planets. It is meant to be used in the XML dump generator.
|
||||
*
|
||||
*
|
||||
* Columns:
|
||||
* empire_id The empire's identifier
|
||||
* planet_id The planet's identifier
|
||||
* resource_name The string identifying the resource
|
||||
* pres_income The planet's income for that resource type
|
||||
* pres_upkeep The planet's upkeep for that resource type
|
||||
* resprov_quantity_max The resource provider's capacity, or NULL
|
||||
* if there is no resource provider of that
|
||||
* type on the planet
|
||||
* resprov_quantity The resource provider's current quantity, or
|
||||
* NULL if there is no resource provider of
|
||||
* that type on the planet
|
||||
* resprov_difficulty The resource provider's extraction difficulty,
|
||||
* or NULL if there is no resource provider
|
||||
* of that type on the planet
|
||||
* resprov_recovery The resource provider's recovery rate, or NULL
|
||||
* if there is no resource provider of that
|
||||
* type on the planet
|
||||
*/
|
||||
CREATE VIEW bugs.dump_planet_resources_view
|
||||
AS SELECT empire_id , planet_id ,
|
||||
name AS resource_name ,
|
||||
pres_income , pres_upkeep ,
|
||||
resprov_quantity_max , resprov_quantity ,
|
||||
resprov_difficulty , resprov_recovery
|
||||
FROM emp.planets
|
||||
INNER JOIN verse.planet_resources
|
||||
USING ( planet_id )
|
||||
INNER JOIN defs.strings
|
||||
ON resource_name_id = id
|
||||
LEFT OUTER JOIN verse.resource_providers
|
||||
USING ( planet_id , resource_name_id )
|
||||
ORDER BY name;
|
||||
|
||||
GRANT SELECT
|
||||
ON bugs.dump_planet_resources_view
|
||||
TO :dbuser;
|
||||
|
||||
|
||||
CREATE VIEW bugs.dump_queues_view
|
||||
AS SELECT ep.empire_id , ep.planet_id , FALSE AS military , q.queue_order ,
|
||||
q.building_id AS item_id , qin.name AS item_name ,
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Tests for bugs.dump_planet_resources_view
|
||||
*/
|
||||
BEGIN;
|
||||
/*
|
||||
* We need a couple of resources (one natural, one basic), three planets
|
||||
* with valid planet resource records (two of the planets will have a
|
||||
* resource provider), two empires (owning a planet with and without
|
||||
* resource providers, respectively).
|
||||
*/
|
||||
\i utils/strings.sql
|
||||
\i utils/resources.sql
|
||||
\i utils/accounts.sql
|
||||
\i utils/naming.sql
|
||||
\i utils/universe.sql
|
||||
SELECT _create_natural_resources( 1 , 'natRes' );
|
||||
SELECT _create_resources( 1 , 'basicRes' );
|
||||
SELECT _create_raw_planets( 3 , 'planet' );
|
||||
INSERT INTO verse.planet_resources(
|
||||
planet_id , resource_name_id , pres_income , pres_upkeep
|
||||
) VALUES (
|
||||
_get_map_name( 'planet1' ) , _get_string( 'basicRes1' ) , 1 , 2
|
||||
) , (
|
||||
_get_map_name( 'planet1' ) , _get_string( 'natRes1' ) , 3 , 4
|
||||
) , (
|
||||
_get_map_name( 'planet2' ) , _get_string( 'basicRes1' ) , 5 , 6
|
||||
) , (
|
||||
_get_map_name( 'planet2' ) , _get_string( 'natRes1' ) , 7 , 8
|
||||
) , (
|
||||
_get_map_name( 'planet3' ) , _get_string( 'basicRes1' ) , 9 , 10
|
||||
) , (
|
||||
_get_map_name( 'planet3' ) , _get_string( 'natRes1' ) , 11 , 12
|
||||
);
|
||||
SELECT _create_resource_provider( 'planet1' , 'natRes1' );
|
||||
SELECT _create_resource_provider( 'planet3' , 'natRes1' );
|
||||
|
||||
SELECT _create_emp_names( 2 , 'empire' );
|
||||
SELECT emp.create_empire( _get_emp_name( 'empire1' ) ,
|
||||
_get_map_name( 'planet1' ) ,
|
||||
200.0 );
|
||||
SELECT emp.create_empire( _get_emp_name( 'empire2' ) ,
|
||||
_get_map_name( 'planet2' ) ,
|
||||
200.0 );
|
||||
|
||||
|
||||
|
||||
/***** TESTS BEGIN HERE *****/
|
||||
SELECT plan( 2 );
|
||||
|
||||
SELECT diag_test_name( 'bugs.dump_planet_resources_view - Records without resource providers' );
|
||||
SELECT set_eq( $$
|
||||
SELECT empire_id , planet_id , resource_name , pres_income , pres_upkeep
|
||||
FROM bugs.dump_planet_resources_view
|
||||
WHERE resprov_quantity IS NULL
|
||||
$$ , $$ VALUES (
|
||||
_get_emp_name( 'empire1' ) , _get_map_name( 'planet1' ) , 'basicRes1' , 1 , 2
|
||||
) , (
|
||||
_get_emp_name( 'empire2' ) , _get_map_name( 'planet2' ) , 'basicRes1' , 5 , 6
|
||||
) , (
|
||||
_get_emp_name( 'empire2' ) , _get_map_name( 'planet2' ) , 'natRes1' , 7 , 8
|
||||
) $$ );
|
||||
|
||||
SELECT diag_test_name( 'bugs.dump_planet_resources_view - Records with resource providers' );
|
||||
SELECT set_eq( $$
|
||||
SELECT empire_id , planet_id , resource_name , pres_income , pres_upkeep
|
||||
FROM bugs.dump_planet_resources_view
|
||||
WHERE resprov_quantity IS NOT NULL
|
||||
$$ , $$ VALUES (
|
||||
_get_emp_name( 'empire1' ) , _get_map_name( 'planet1' ) , 'natRes1' , 3 , 4
|
||||
) $$ );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* Test privileges on bugs.dump_planet_resources_view
|
||||
*/
|
||||
BEGIN;
|
||||
SELECT plan( 1 );
|
||||
|
||||
SELECT diag_test_name( 'bugs.dump_planet_resources_view - Privileges' );
|
||||
SELECT lives_ok( 'SELECT * FROM bugs.dump_planet_resources_view' );
|
||||
|
||||
SELECT * FROM finish( );
|
||||
ROLLBACK;
|
Reference in a new issue