-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib_ship.ks
61 lines (54 loc) · 1.42 KB
/
lib_ship.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
// Vessel utility functions.
// Return lexicon of all vessels..
FUNCTION Ship_Lexicon {
PARAMETER includeSelf IS TRUE. // FALSE = don't include ourself in the lexicon.
LOCAL v IS LIST().
LOCAL rv IS LEXICON().
LIST TARGETS IN v.
IF includeSelf { v:add(ship). }
FOR vessel IN v {
IF rv:haskey(vessel:name) {
rv[vessel:name]:add(vessel).
} ELSE {
SET rv[vessel:name] TO LIST(vessel).
}
}
RETURN rv.
}
FUNCTION Ship_Engines {
// Returns list of engines.
PARAMETER ship.
LOCAL result IS LIST().
//Disabled due to kOS bug #1683 - https://github.com/KSP-KOS/KOS/issues/1683
//LIST engines FROM ship IN result.
LIST engines IN result.
RETURN result.
}
FUNCTION Ship_ActiveEngines {
// Returns list of all active engines
PARAMETER ship IS ship.
PARAMETER includeFlameOut IS FALSE.
LOCAL result IS LIST().
FOR engine IN Ship_Engines(ship) {
IF engine:ignition AND (includeFlameOut OR NOT engine:flameout) {
result:add(engine).
}
}
RETURN result.
}
FUNCTION Ship_AverageISP {
// Returns current average ISP.
PARAMETER ship IS ship.
PARAMETER activeOnly IS TRUE.
PARAMETER includeFlameOut IS FALSE.
LOCAL engines IS 0.
IF activeonly { SET engines TO Ship_ActiveEngines(ship, includeFlameOut). }
ELSE { SET engines TO Ship_Engines(ship). }
LOCAL n IS 0.
LOCAL d IS 0.
FOR engine IN engines {
SET n TO n+engine:availablethrust.
SET d TO d+(engine:availablethrust / engine:isp).
}
RETURN n/d.
}