From 1cc610802b5da0fa763fd335f3ef6e2fc7a183b5 Mon Sep 17 00:00:00 2001 From: Martin Ambrus Date: Fri, 27 Oct 2017 22:44:32 +0200 Subject: [PATCH] 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. --- var/db/datagen-world-data.sql | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/var/db/datagen-world-data.sql b/var/db/datagen-world-data.sql index 6c067c62..2d9a3bb2 100644 --- a/var/db/datagen-world-data.sql +++ b/var/db/datagen-world-data.sql @@ -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;