forked from tdelc/EmptyEpsilon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
artemis_mission_convert_template.lua
91 lines (81 loc) · 1.81 KB
/
artemis_mission_convert_template.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function init()
timers = {}
fleet = {}
temp_transmission_object = SpaceStation():setTemplate("Small Station"):setPosition(-1000000, -1000000)
###START###
end
function update(delta)
for key, value in pairs(timers) do
timers[key] = timers[key] - delta
end
###EVENTS###
end
--[[
Utility functions
--]]
function vectorFromAngle(angle, length)
return math.cos(angle / 180 * math.pi) * length, math.sin(angle / 180 * math.pi) * length
end
function ifOutsideBox(obj, x1, y1, x2, y2)
if obj == nil or not obj:isValid() then
return false
end
x, y = obj:getPosition()
if x >= x1 and x <= x2 and y >= y1 and y <= y2 then
return false
end
return true
end
function ifInsideBox(obj, x1, y1, x2, y2)
if obj == nil or not obj:isValid() then
return false
end
x, y = obj:getPosition()
if x >= x1 and x <= x2 and y >= y1 and y <= y2 then
return true
end
return false
end
function ifInsideSphere(obj, x1, y1, r)
if obj == nil or not obj:isValid() then
return false
end
x, y = obj:getPosition()
xd, yd = (x1 - x), (y1 - y)
if math.sqrt(xd * xd + yd * yd) < r then
return true
end
return false
end
function ifOutsideSphere(obj, x1, y1, r)
if obj == nil or not obj:isValid() then
return false
end
x, y = obj:getPosition()
xd, yd = (x1 - x), (y1 - y)
if math.sqrt(xd * xd + yd * yd) < r then
return false
end
return true
end
function ifdocked(obj)
-- TODO: Only checks the first player ship.
return getPlayerShip(-1):isDocked(obj)
end
function countFleet(fleetnr)
count = 0
if fleet[fleetnr] ~= nil then
for key, value in pairs(fleet[fleetnr]) do
if value:isValid() then
count = count + 1
end
end
end
return count
end
function distance(obj1, obj2)
x1, y1 = obj1:getPosition()
x2, y2 = obj2:getPosition()
xd, yd = (x1 - x2), (y1 - y2)
return math.sqrt(xd * xd + yd * yd)
end