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/universe.sql

71 lines
1.3 KiB
MySQL
Raw Normal View History

/*
* 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;