-
Notifications
You must be signed in to change notification settings - Fork 0
/
05.harbors.sql
35 lines (35 loc) · 897 Bytes
/
05.harbors.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
WITH RECURSIVE
resources AS
(
SELECT '////####^^^' || CHR(34) || CHR(34) || CHR(34) || CHR(34) || '... '::TEXT tile_resources,
'/#^' || CHR(34) || '.????'::TEXT harbor_resources
),
harbors (rn, x, y, pier1, pier2) AS
(
VALUES
(1, -1, -1, 0, 1),
(2, 1, -1, 1, 2),
(3, 3, 0, 1, 2),
(4, 5, 2, 2, 3),
(5, 5, 4, 3, 4),
(6, 4, 5, 3, 4),
(7, 2, 5, 4, 5),
(8, 0, 3, 5, 0),
(9, -1, 1, 5, 0)
),
harbor_resources AS
(
SELECT '/#>".????'::TEXT harbor_resources
)
SELECT resource, rn, x, y, pier1, pier2
FROM harbors
CROSS JOIN
resources
JOIN LATERAL
(
SELECT resource, ROW_NUMBER() OVER (ORDER BY RANDOM()) rn
FROM REGEXP_SPLIT_TO_TABLE(harbor_resources, '') q (resource)
) q
USING (rn)
ORDER BY
RANDOM()