-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsys.ks
109 lines (89 loc) · 2.65 KB
/
sys.ks
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
global aux is "".
global hib is "".
global lts is "".
global ec is 0.
for res in ship:resources {
if res:name = "ElectricCharge" {
set ec to res.
break.
}
}
on ec:capacity { reboot. }
on ship:partstagged("AUX"):length() { reboot. }
on ship:partstaggedpattern("_[C]\z"):length() { reboot. }
on aux { print "AUX":padleft(6) + aux:padleft(11) at (0,3). preserve. }
on hib { print "HIB":padleft(6) + hib:padleft(11) at (0,4). preserve. }
on lts { print "LTS":padleft(6) + lts:padleft(11) at (0,5). preserve. }
sys_initialize().
// telemetry, maybe?
wait until false.
// Initialize terminal.
function sys_initialize {
clearscreen.
set processor(core:tag):bootfilename to "sys.ks".
processor(core:tag):doaction("open terminal", true).
wait 0.
set terminal:width to 21.
wait 0.
set terminal:height to 7.
print "---------------------".
print " SYS STATE ".
print "---------------------".
set aux to "OFF".
set hib to "OFF".
if ship:sensors:light = 0 {
set lts to "ON".
lights on.
}
else {
set lts to "OFF".
lights off.
}
sys_aux().
sys_hib().
sys_lts().
}
// Switches on fuel cells if power drops below 10%, and switches them back off above 90%.
function sys_aux {
on ceiling(ec:amount / ec:capacity - 0.10) {
set aux to "ON".
for part in ship:partstagged("AUX") {
part:getmodule("ModuleResourceConverter"):doaction("start fuel cell", true).
}
on floor(ec:amount / ec:capacity + 0.10) {
set aux to "OFF".
for part in ship:partstagged("AUX") {
part:getmodule("ModuleResourceConverter"):doaction("stop fuel cell", true).
}
sys_aux().
}
}
}
// Hibernate all probe cores.
function sys_hib {
on kuniverse:timewarp:warp {
wait 1.
if not kuniverse:timewarp:warp = 0 {
set hib to "ON".
for part in ship:partstaggedpattern("_[C]\z") {
part:getmodule("modulecommand"):setfield("hibernation", true).
}
}
else {
set hib to "OFF".
for part in ship:partstaggedpattern("_[C]\z") {
part:getmodule("modulecommand"):setfield("hibernation", false).
}
}
preserve.
}
}
// Cabin lights on at night.
function sys_lts {
on ceiling(min(ship:sensors:light, 1) - 0.10) {
toggle lights.
if lights set lts to "ON".
else set lts to "OFF".
preserve.
}
}