Skip to content

Instantly share code, notes, and snippets.

@Drumsin
Drumsin / drawNumberOfTilesInRingRandom.lua
Last active June 11, 2022 20:37
AoE4 Generated Map Function: Draw number of tiles in a ring that are positioned randomly
--extends the GetAllSquaresOfTypeInRingAroundSquare() function in that you can choose the number of tiles to draw which are randomly placed in a ring
--rowCoord and colCoord is the square position for the ring centre
--numberOfTilesToDraw is the number of tiles you want to draw which are randomly positioned in the ring
--chosenTerrain is the terrain to draw
--ringRadius is the distance in squares from the center
--ringWidth is the thickness of the ring inwards towards the center
--terrainTypes is a list of terrain types that can be selcted in the ring. If a potential ring square does not match one of the types it won't be selected
--terrainLayoutResult is the coarse grid layout
function drawNumberOfTilesInRingRandom(rowCoord, colCoord, numberOfTilesToDraw, chosenTerrain, ringRadius, ringWidth, terrainTypes, terrainLayoutResult)
count = 0
@Drumsin
Drumsin / drawBox.lua
Last active June 11, 2022 03:35
AoE4 Generated Map Function: Draw Box
--draws a box starting from top left coordinates and expands down and to the right
--copy and paste code to preview at https://aoe4.app/
--rowCoord is the top left row of where your box draw begins
--colCoord is the top left col of where your box draw begins
--rowSize how far down do you want to draw your box
--colSize how far across do you want to draw your box
--pickedTerrain the terrainType e.g. tt_lake_shallow
function drawBox(rowCoord, colCoord, rowSize, colSize, pickedTerrain)
@Drumsin
Drumsin / closestEdgeFurthestEdge.lua
Last active June 11, 2022 03:35
AoE4 Generated Map Function: Closest or Furthest edge functions
--tells you what is the closest and furthest edge from a given coordinate
--copy and paste code to preview at https://aoe4.app/
--returns the closest edge of a given coordinate
--rowCoordinate (int) grid coordinate
--colCoordinate (int) grid coordinate
--edgesCompare (array) the edges to compare e.g. { 'left', 'right' } what is closest edge, left or right
--returns (string) 'top' 'right' 'bottom' 'left'
function closestEdge(rowCoordinate, colCoordinate, edgesCompare)
@Drumsin
Drumsin / circleFill.lua
Last active June 11, 2022 03:36
AoE4 Generated Map Function: Circle Fill
--draws a circle that is filled
--copy and paste code to preview at https://aoe4.app/
local function circleFill(centerCoord, tileCoord, radius)
dx = centerCoord.row - tileCoord.row
dy = centerCoord.col - tileCoord.col
distanceSquared = (dx*dx) + (dy*dy)
return distanceSquared <= radius*radius
end
centerCoord = { row = mapHalfSize, col = mapHalfSize }
@Drumsin
Drumsin / circleOutline.lua
Last active June 11, 2022 03:36
AoE4 Generated Map Function: Circle Outline
--draws a circle outline
--copy and paste code to preview at https://aoe4.app/
--radius (float) the radius of the circle
--centerCoord (table) x y coordinates of the circle center
--pickedTerrain (str/var) the terrainType name to draw
--implodeWidth (float) experimental and can produce interesting results when increasing
--iterations (int) the number of circle iterations to draw, used in conjunction with strokeSpacing
--strokeWidth (int) the circles outline width
--strokeSpacing (float) the amount of spacing between circles if there are multiple iterations set
@Drumsin
Drumsin / diagonalCross.lua
Last active June 11, 2022 03:37
AoE4 Generated Map Function: Diagonal Cross
--draws a diagonal cross
--copy and paste code to preview at https://aoe4.app/
for i = 1, gridSize do
terrainLayoutResult[i][i].terrainType = tt_lake_shallow
terrainLayoutResult[gridSize - i + 1][i].terrainType = tt_lake_shallow
end