REPLACE INTO Maps(UserID, X, Y, TerrainID)
SELECT Units.UserID, Maps.X, Maps.Y, Maps.TerrainID
FROM Maps, Units
WHERE ((Maps.X = Units.X – 1 AND Maps.Y = Units.Y) OR
(Maps.X = Units.X – 1 AND Maps.Y = Units.Y + 1) OR
(Maps.X = Units.X AND Maps.Y = Units.Y – 1) OR
(Maps.X = Units.X AND Maps.Y = Units.Y) OR
(Maps.X = Units.X AND Maps.Y = Units.Y + 1) OR
(Maps.X = Units.X + 1 AND Maps.Y = Units.Y) OR
(Maps.X = Units.X + 1 AND Maps.Y = Units.Y + 1)) AND Maps.UserID = 0;

I’m particularly pleased with the above MySQL query – assuming we’re storing the ‘real’ map info with UserID 0 this’ll copy the real info into each player’s map for the 7 hex squares around each of their units. I just like how non-difficult it wound up being. Sleep now.

Advertisements