Resource database structures
* Added structures for resource definitions, natural resources definitions, resource providers, empire resources and empire mining settings (both empire-wide and planet-specific). * Added a few common utility functions to the SQL test suite. These functions allow test initialisation to be a little shorter. * Added "MINE" production type and an associated building definition. The production will not be added to the XML dump or to the output of the planets summary page, as this is extremely temporary.
This commit is contained in:
parent
631f49fb86
commit
4e1bb91780
20 changed files with 2223 additions and 2 deletions
legacyworlds-server-data/db-structure/tests/utils
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Utility functions used by unit tests
|
||||
*
|
||||
* Universe
|
||||
*/
|
||||
|
||||
/*
|
||||
* Create a new system at some coordinates and return its identifier
|
||||
*/
|
||||
CREATE FUNCTION _create_system( INT , INT ) RETURNS INT AS $$
|
||||
INSERT INTO verse.systems ( x , y )
|
||||
VALUES ( $1 , $2 )
|
||||
RETURNING id;
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
|
||||
/*
|
||||
* Create "raw" planets
|
||||
*/
|
||||
CREATE FUNCTION _create_raw_planets( _quantity INT , _prefix TEXT )
|
||||
RETURNS VOID
|
||||
AS $$
|
||||
DECLARE
|
||||
_system INT;
|
||||
_orbit INT;
|
||||
i INT;
|
||||
BEGIN
|
||||
PERFORM _create_map_names( _quantity , _prefix );
|
||||
|
||||
i := 0;
|
||||
WHILE i < _quantity
|
||||
LOOP
|
||||
i := i + 1;
|
||||
|
||||
IF _system IS NULL
|
||||
THEN
|
||||
_system := _create_system( i , i );
|
||||
_orbit := 1;
|
||||
END IF;
|
||||
|
||||
INSERT INTO verse.planets(
|
||||
name_id , system_id , orbit , picture , population
|
||||
) VALUES (
|
||||
_get_map_name( _prefix || i::TEXT ) , _system , _orbit , 1 , 1
|
||||
);
|
||||
|
||||
IF _orbit = 5
|
||||
THEN
|
||||
_system := NULL;
|
||||
ELSE
|
||||
_orbit := _orbit + 1;
|
||||
END IF;
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE PLPGSQL;
|
||||
|
||||
|
||||
/*
|
||||
* Create a resource provider
|
||||
*/
|
||||
CREATE FUNCTION _create_resource_provider( TEXT , TEXT ) RETURNS VOID AS $$
|
||||
INSERT INTO verse.resource_providers(
|
||||
planet_id , resource_name_id ,
|
||||
resprov_quantity_max , resprov_quantity ,
|
||||
resprov_difficulty , resprov_recovery
|
||||
) VALUES (
|
||||
_get_map_name( $1 ) , _get_string( $2 ) ,
|
||||
100 , 50 ,
|
||||
0.5 , 0.5
|
||||
);
|
||||
$$ LANGUAGE SQL;
|
Reference in a new issue