Skip to content

Instantly share code, notes, and snippets.

@fryja
fryja / drawTriangle.lua
Created November 28, 2023 13:38
AoE4 Generated Map Function - Fill Triangle between 3 points
-- point1, point2 and point3 take a tile coordinate formatted in row, col. eg. {10,10}
function drawTriangle(point1, point2, point3, terrainToDraw)
local function sign(p1, p2, p3)
return (p1[2] - p3[2]) * (p2[1] - p3[1]) - (p2[2] - p3[2]) * (p1[1] - p3[1])
end
local function pointInTriangle(point, v1, v2, v3)
@fryja
fryja / getSquaresInTriangle.lua
Created November 28, 2023 13:37
AoE4 Generated map function - Get Tiles in a Triangle between 3 points
-- point1, point2 and point3 take a tile coordinate formatted in row, col. eg. {10,10}
function getSquaresInTriangle(point1, point2, point3)
tiles = {}
local function sign(p1, p2, p3)
return (p1[2] - p3[2]) * (p2[1] - p3[1]) - (p2[2] - p3[2]) * (p1[1] - p3[1])
end
@fryja
fryja / drawRect.lua
Created November 25, 2023 08:37
AoE4 Generated Map Function - Draw Filled Rectangle
-- draws a box of terrain from a start coordinate to an end coordinate
-- startRow, startCol (int) are the start row and col coordinates of the rectangle
-- endRow, endCol (int) are the start row and col coordinates of the rectangle
-- pickedTerrain is the terrain type you wish the rectangle to be filled with
function drawRect(startRow, startCol, endRow, endCol, pickedTerrain)
local function sign(number)
return number > 0 and 1 or (number == 0 and 0 or -1)
end