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/parts/040-functions/053-generator-basics.sql
Emmanuel BENOîT e50775ec76 Database definition & tests organisation
* The main loader script has been updated to generate the list of files
it needs to load automatically. As a consequence, files that contained
manually-maintained lists of scripts have been removed, and definition
directories have been renamed accordingly.

* PostgreSQL extension loading and configuration has been moved to a
separate script to be loaded automatically in the main transaction.

* Data and function definition scripts that had the -data or -functions
suffix have been renamed (the suffix is unnecessary).

* Unit tests have been reorganised to follow the definition's structure.

* Documentation has been improved
2012-01-06 11:19:19 +01:00

51 lines
No EOL
1.4 KiB
SQL

-- LegacyWorlds Beta 6
-- PostgreSQL database scripts
--
-- A few types and internal functions used in most parts
-- of the universe generator.
--
-- Copyright(C) 2004-2012, DeepClone Development
-- --------------------------------------------------------
/* The coordinates of the area being generated. */
DROP TYPE IF EXISTS verse.generator_area_type CASCADE;
CREATE TYPE verse.generator_area_type AS (
x0 INT , y0 INT ,
x1 INT , y1 INT
);
/*
* List some quantity of random planets from an area of the universe
*
* This function returns a set of planet identifiers chosen at random from the
* specified area of the universe.
*
* Parameters:
* _area The area to select planets from
* _count The maximal amount of planets to return
*/
DROP FUNCTION IF EXISTS verse.list_random_planets_in( verse.generator_area_type , INT );
CREATE FUNCTION verse.list_random_planets_in( _area verse.generator_area_type , _count INT )
RETURNS SETOF INT
STRICT VOLATILE
SECURITY INVOKER
AS $list_random_planets_in$
SELECT _planets.name_id
FROM verse.planets _planets
INNER JOIN verse.systems _systems
ON _planets.system_id = _systems.id
WHERE _systems.x BETWEEN $1.x0 AND $1.x1
AND _systems.y BETWEEN $1.y0 AND $1.y1
ORDER BY RANDOM( )
LIMIT $2;
$list_random_planets_in$ LANGUAGE SQL;
REVOKE EXECUTE
ON FUNCTION verse.list_random_planets_in( verse.generator_area_type ,
INT )
FROM PUBLIC;