fix: coordinates were still generated in wrong descension

This commit is contained in:
Martin Ambrus
2017-10-28 11:08:35 +02:00
parent 2cfb84ebe2
commit 6226412825
+13 -12
View File
@@ -62,10 +62,10 @@ INSERT INTO %PREFIX%wdata
IF (@otype = 0, CONCAT("t", (FLOOR(0 + RAND() * 9)) ), CONCAT("o", @otype) ) as image
FROM
-- the following select will generate a number from -%WORLDSIZE% to +%WORLDSIZE% as an Y coordinate
-- the following select will generate a number from -%WORLDSIZE% to +%WORLDSIZE% as an X coordinate
-- (courtesy of Unreason, https://stackoverflow.com/a/2652051/467164)
-- this first line will keep incrementing @row until we run out of all the data provided by the "t" subselects below
(SELECT @row := @row - 1 as y FROM
(SELECT @row := @row + 1 as x FROM
-- t and t2 each contain 10 rows of dummy data,
-- cartesian product of these is 10^4, i.e. 10000 rows of dummy data
@@ -79,21 +79,22 @@ INSERT INTO %PREFIX%wdata
-- here we tell MySQL where to start, so if we have a world 100x100, this will set @row to -101
-- (not -100 because the first select already increments the @row by 1, so we'd start at -99 instead)
(SELECT @row := (%WORLDSIZE% + 1)) as beginning
(SELECT @row := (-%WORLDSIZE% - 1)) as beginning
) as x,
-- since we maxed out the potential of world generation to number 400, we need to use a WHERE here
-- as to only get the number of rows we need for the current map size
WHERE @row >= -(%WORLDSIZE% - 1)) as y,
-- this query is the same as previous query for Y coordinate but will generate numbers
-- for the X coordinate - both of these joined together this way will generate data such as:
-- this query is the same as previous query for X coordinate but will generate numbers
-- for the Y coordinate - both of these joined together this way will generate data such as:
-- -100, 100; -99, 100; -98, 100 ...
(SELECT @row2 := @row2 + 1 as x FROM
(SELECT @row2 := @row2 - 1 as y FROM
(select 0 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t,
(select 0 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
(select 0 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8) t3,
(SELECT @row2 := (-%WORLDSIZE% - 1)) as beginning
WHERE @row2 <= (%WORLDSIZE% - 1)) as x
(SELECT @row2 := (%WORLDSIZE% + 1)) as beginning
) as y
WHERE
x BETWEEN -%WORLDSIZE% AND %WORLDSIZE%
AND
y BETWEEN -%WORLDSIZE% AND %WORLDSIZE%
) as generator;