Emmanuel BENOîT
4e1bb91780
* 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.
71 lines
No EOL
1.3 KiB
PL/PgSQL
71 lines
No EOL
1.3 KiB
PL/PgSQL
/*
|
|
* 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; |