library Triangle
function getDistance takes real x1, real y1, real x2, real y2 returns real
local real dx = x1 - x2
local real dy = y1 - y2
return SquareRoot(dx * dx + dy * dy)
endfunction
function getAngle takes real x1, real y1, real x2, real y2 returns real
return bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
endfunction
struct triangle
real x1
real x2
real x3
real y1
real y2
real y3
real angle_one
real angle_two
real angle_three
real dist_one
real dist_two
real dist_three
integer model_path
integer owner
method createUnits takes real distance returns nothing
local unit u = CreateUnit(Player(this.owner), this.model_path, this.x1, this.x2, 0)
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real x_dist = distance * Cos(this.angle_one)
local real y_dist = distance * Sin(this.angle_one)
loop
set x = x + x_dist
set y = y + y_dist
set u = CreateUnit(Player(this.owner), this.model_path, x, y, 0)
exitwhen getDistance(GetUnitX(u), GetUnitY(u), this.x2, this.y2) <= distance
endloop
set x = this.x2
set y = this.y2
set x_dist = distance * Cos(this.angle_two)
set y_dist = distance * Sin(this.angle_two)
loop
set x = x + x_dist
set y = y + y_dist
set u = CreateUnit(Player(this.owner), this.model_path, x, y, 0)
exitwhen getDistance(GetUnitX(u), GetUnitY(u), this.x3, this.y3) <= distance
endloop
set x = this.x3
set y = this.y3
set x_dist = distance * Cos(this.angle_three)
set y_dist = distance * Sin(this.angle_three)
loop
set x = x + x_dist
set y = y + y_dist
set u = CreateUnit(Player(this.owner), this.model_path, x, y, 0)
exitwhen getDistance(GetUnitX(u), GetUnitY(u), this.x1, this.y1) <= distance
endloop
set u = null
endmethod
method setCoordinates takes real x, real y returns nothing
set this.x1 = x
set this.y1 = y
set this.x2 = x + this.dist_one * Cos(this.angle_one)
set this.y2 = y + this.dist_one * Sin(this.angle_one)
set this.x3 = this.x2 + this.dist_two * Cos(this.angle_two)
set this.x3 = this.x2 + this.dist_two * Sin(this.angle_two)
set this.dist_three = getDistance(this.x1, this.y1, this.x3, this.y3)
set this.angle_three = getAngle(this.x1, this.y1, this.x3, this.y3) * bj_DEGTORAD
endmethod
method init takes real x_coordinate, real y_coordinate, real angle_one, real angle_two, real length_one, real length_two, real distance_between_units, integer player_number, integer model_path returns nothing
set this.angle_one = angle_one * bj_DEGTORAD
set this.angle_two = angle_two * bj_DEGTORAD
set this.dist_one = length_one
set this.dist_two = length_two
set this.owner = player_number
set this.model_path = model_path
call this.setCoordinates(x_coordinate, y_coordinate)
call this.createUnits(distance_between_units)
endmethod
endstruct
endlibrary