library Wolf
globals
planet array PLANET
comet array COMET
integer PCOUNT = 0
integer CCOUNT = 0
timer PTIMER = CreateTimer()
timer CTIMER = CreateTimer()
string array PNAME
string array CNAME
constant integer MAX_FOLLOW = 5
endglobals
struct planet
unit self
unit father
real distance
real rotationspeed
real circlingspeed
real angle
string name
endstruct
struct comet
unit self
unit array follow[MAX_FOLLOW]
integer countfollow
real speed
real angle
string name
endstruct
function CometDestroy takes comet c returns nothing
local integer i = 0
loop
exitwhen i > c.countfollow
call RemoveUnit(c.follow[i])
set i = i + 1
endloop
call RemoveUnit(c.self)
call c.destroy()
endfunction
function OutofMap takes real x, real y returns boolean
if x < GetCameraBoundMinX() or x > GetCameraBoundMaxX() or y < GetCameraBoundMinY() or y > GetCameraBoundMaxY() then
return true
endif
return false
endfunction
function MoveComets takes nothing returns nothing
local comet c
local integer i = 0
local integer int = 0
local unit u
local unit un
loop
exitwhen i > CCOUNT
set c = COMET[i]
set u = c.self
call SetUnitX(u, GetUnitX(u) + c.speed / 25 * Cos(c.angle * bj_DEGTORAD))
call SetUnitY(u, GetUnitY(u) + c.speed / 25 * Sin(c.angle * bj_DEGTORAD))
if OutofMap(GetUnitX(u), GetUnitY(u)) then
call CometDestroy(c)
endif
loop
exitwhen int > c.countfollow
set un = c.follow[int]
call SetUnitX(un, GetUnitX(un) + c.speed / 25 * Cos(c.angle * bj_DEGTORAD))
call SetUnitY(un, GetUnitY(un) + c.speed / 25 * Sin(c.angle * bj_DEGTORAD))
set int = int + 1
endloop
set u = null
set i = i + 1
endloop
if CCOUNT == 0 then
call PauseTimer(CTIMER)
endif
endfunction
function MovePlanets takes nothing returns nothing
local planet p
local integer i = 0
loop
exitwhen i > PCOUNT
set p = PLANET[i]
set p.angle = p.angle + p.circlingspeed
call SetUnitX(p.self, GetUnitX(p.father) + p.distance * Cos(p.angle * bj_DEGTORAD))
call SetUnitY(p.self, GetUnitY(p.father) + p.distance * Sin(p.angle * bj_DEGTORAD))
call SetUnitFacing(p.self, GetUnitFacing(p.self) + p.rotationspeed)
set i = i + 1
endloop
if PCOUNT == 0 then
call PauseTimer(PTIMER)
endif
endfunction
function MainCreate takes real x, real y, real angle, real rotationspeed, real size, integer model, integer pnum, string name returns nothing
local planet mainplanet = planet.create()
local unit u = CreateUnit(Player(pnum), model, x, y, angle)
call SetUnitScale(u, size, size, size)
set mainplanet.self = u
set mainplanet.rotationspeed = 14.4 / rotationspeed
set mainplanet.angle = angle
set mainplanet.name = name
set PCOUNT = PCOUNT + 1
set PLANET[PCOUNT - 1] = mainplanet
if PCOUNT - 1 == 0 then
call TimerStart(PTIMER, 0.04, true, function MovePlanets)
endif
set u = null
endfunction
function MoonCreate takes planet p, real distance, real angle, real rotationspeed, real circlingspeed, real size, integer model, integer pnum, string name returns nothing
local planet moon = planet.create()
local unit u = CreateUnit(Player(pnum), model, GetUnitX(p.self) + distance * Cos(angle * bj_DEGTORAD), GetUnitY(p.self) + distance * Sin(angle * bj_DEGTORAD), 0)
if p == null then
call BJDebugMsg("Error: planet p is null")
endif
call SetUnitScale(u, size, size, size)
set moon.self = u
set moon.father = p.self
set moon.distance = distance
set moon.rotationspeed = 14.4 / rotationspeed
set moon.circlingspeed = 14.4 / circlingspeed
set moon.angle = angle
set moon.name = name
set PCOUNT = PCOUNT + 1
set PLANET[PCOUNT - 1] = moon
set u = null
endfunction
function DestroyPlanet takes planet d returns nothing
local planet p
local integer i = 0
loop
exitwhen i > PCOUNT
set p = PLANET[i]
if p.father == d.self then
set PLANET[PCOUNT] = PLANET[PCOUNT-1]
set PCOUNT = PCOUNT -1
call KillUnit(p.self)
call p.destroy()
endif
set i = i + 1
endloop
set PLANET[PCOUNT] = PLANET[PCOUNT-1]
set PCOUNT = PCOUNT -1
call KillUnit(d.self)
call d.destroy()
endfunction
function CometCreate takes real x, real y, real angle, real speed, real size, integer model, integer pnum, integer fnumber, real fdistance returns nothing
local comet c = comet.create()
local unit u = CreateUnit(Player(pnum), model, x, y, angle)
local unit follow
local integer i = 1
loop
exitwhen i > fnumber
set follow = CreateUnit(Player(pnum), model, x - fdistance * i * Cos(angle * bj_DEGTORAD), y - fdistance * i * Sin(angle * bj_DEGTORAD), angle)
call SetUnitVertexColor(follow, 100, 100, 100, 100 * -i)
call SetUnitScale(follow, 100 - 10 * i, 100 - 10 * i, 100 - 10 * i)
set c.follow[c.countfollow] = follow
set c.countfollow = c.countfollow + 1
set c.follow[c.countfollow - 1] = follow
set i = i + 1
endloop
set c.self = u
set c.speed = speed
set c.angle = angle
call SetUnitScale(u, size, size, size)
if CCOUNT == 0 then
call TimerStart(CTIMER, 0.04, true, function MoveComets)
endif
set CCOUNT = CCOUNT + 1
set COMET[CCOUNT - 1] = c
set u = null
endfunction
//===================== Helper functions =======================
function LastCreatedPlanet takes nothing returns planet
return PLANET[PCOUNT - 1]
endfunction
function LastCreatedComet takes nothing returns comet
return COMET[CCOUNT - 1]
endfunction
function GetPlanetByName takes string name returns planet
local planet p
local integer i = 0
loop
exitwhen i > PCOUNT
set p = PLANET[i]
if p.name == name then
exitwhen true
endif
set i = i + 1
endloop
return p
endfunction
//===================== Setting planet properties functions =======================
function SetPlanetName takes planet p, string name, string s returns nothing
local planet pla
if name == "" and p != null then
set p.name = s
elseif p == null and name != "" then
set pla = GetPlanetByName(name)
set pla.name = s
else
call BJDebugMsg("planet value or name not found")
endif
endfunction
function SetPlanetRotationSpeed takes planet p, string name, real rotationspeed returns nothing
local planet pla
if name == "" and p != null then
set p.rotationspeed = rotationspeed
elseif p == null and name != "" then
set pla = GetPlanetByName(name)
set pla.rotationspeed = rotationspeed
else
call BJDebugMsg("planet value or name not found")
endif
endfunction
function SetPlanetDistance takes planet p, string name, real distance returns nothing
local planet pla
if name == "" and p != null then
set p.distance = distance
elseif p == null and name != "" then
set pla = GetPlanetByName(name)
set pla.distance = distance
else
call BJDebugMsg("planet value or name not found")
endif
endfunction
function SetPlanetCirclingSpeed takes planet p, string name, real circlingspeed returns nothing
local planet pla
if name == "" and p != null then
set p.circlingspeed = circlingspeed
elseif p == null and name != "" then
set pla = GetPlanetByName(name)
set pla.circlingspeed = circlingspeed
else
call BJDebugMsg("planet value or name not found")
endif
endfunction
function SetPlanetSize takes planet p, string name, real size returns nothing
local planet pla
if name == "" and p != null then
call SetUnitScale(p.self, size, size, size)
elseif p == null and name != "" then
set pla = GetPlanetByName(name)
call SetUnitScale(pla.self, size, size, size)
else
call BJDebugMsg("planet value or name not found")
endif
endfunction
function SetPlanetOwner takes planet p, string name, integer pnum returns nothing
local planet pla
if name == "" and p != null then
call SetUnitOwner(p.self, Player(pnum), true)
elseif p == null and name != "" then
set pla = GetPlanetByName(name)
call SetUnitOwner(pla.self, Player(pnum), true)
else
call BJDebugMsg("planet value or name not found")
endif
endfunction
//===================== Setting comet properties functions =======================
function SetCometName takes comet c, string s returns nothing
set c.name = s
endfunction
function SetCometSpeed takes comet c, real s returns nothing
set c.speed = s
endfunction
function SetCometSize takes comet c, real size returns nothing
call SetUnitScale(c.self, size, size, size)
endfunction
function SetCometOwner takes comet c, integer pnum returns nothing
call SetUnitOwner(c.self, Player(pnum), true)
endfunction
endlibrary