fix: data generation starts and continues in a different way

It goes from -100, 100 through -99, 100 all the way up to 100, -100.
Anything else breaks the map coordinates.
This commit is contained in:
Martin Ambrus
2017-10-27 22:44:32 +02:00
parent 5a967055f4
commit 1cc610802b
+10 -10
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 X coordinate
-- the following select will generate a number from -%WORLDSIZE% to +%WORLDSIZE% as an Y 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 x FROM
(SELECT @row := @row - 1 as y 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,21 @@ 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 final
(SELECT @row := (%WORLDSIZE% + 1)) as beginning
-- 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 x,
WHERE @row >= -(%WORLDSIZE% - 1)) as y,
-- 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; -100, -99; -100, -98 ...
(SELECT @row2 := @row2 + 1 as y FROM
-- 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:
-- -100, 100; -99, 100; -98, 100 ...
(SELECT @row2 := @row2 + 1 as x 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) t3,
(SELECT @row2 := -(%WORLDSIZE% + 1)) as final
WHERE @row2 <= (%WORLDSIZE% - 1)) as y
(SELECT @row2 := (-%WORLDSIZE% - 1)) as beginning
WHERE @row2 <= (%WORLDSIZE% - 1)) as x
) as generator;