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:
Emmanuel BENOîT 2011-12-19 11:57:08 +01:00
parent 631f49fb86
commit 4e1bb91780
20 changed files with 2223 additions and 2 deletions
legacyworlds-server-data/db-structure/tests/utils

View file

@ -0,0 +1,63 @@
/*
* Utility functions used by unit tests
*
* Resources and natural resources
*/
/*
* Function that creates some quantity of resources
* All resources are created using the specified prefix for the strings
*/
CREATE FUNCTION _create_resources( _quantity INT , _prefix TEXT )
RETURNS VOID
AS $$
DECLARE
i INT;
BEGIN
PERFORM _create_test_strings( _quantity , _prefix );
PERFORM _create_test_strings( _quantity , _prefix || 'Description' );
i := 0;
WHILE i < _quantity
LOOP
i := i + 1;
INSERT INTO defs.resources (
resource_name_id , resource_description_id , resource_weight
) VALUES (
_get_string( _prefix || i::TEXT ) ,
_get_string( _prefix || 'Description' || i::TEXT ) ,
i
);
END LOOP;
END;
$$ LANGUAGE PLPGSQL;
/*
* Function that creates some quantity of /natural/ resources
* All resources are created using the specified prefix for the strings
*/
CREATE FUNCTION _create_natural_resources( _quantity INT , _prefix TEXT )
RETURNS VOID
AS $$
DECLARE
i INT;
BEGIN
PERFORM _create_resources( _quantity , _prefix );
i := 0;
WHILE i < _quantity
LOOP
i := i + 1;
INSERT INTO defs.natural_resources(
resource_name_id , natres_p_presence , natres_quantity_avg ,
natres_quantity_dev , natres_difficulty_avg ,
natres_difficulty_dev , natres_recovery_avg ,
natres_recovery_dev
) VALUES (
_get_string( _prefix || i::TEXT ) , 0.5 , 100 , 1 , 0.5 , 0.05 , 0.5 , 0.05
);
END LOOP;
END;
$$ LANGUAGE PLPGSQL;