-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfueler.ks
131 lines (116 loc) · 3.66 KB
/
fueler.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Fuel storage management
// Fuel transfer standard jobs
//
// From fuel shuttle to storage
// from storage to some consumer ship
if not exists("1:/lib_list_dialog.ks") {
copypath("0:/lib/lib_list_dialog.ks", "1:").
}
if not exists("1:/lib_menu.ks") {
copypath("0:/lib/lib_menu.ks", "1:").
}
if not exists("1:/lib_gui_box.ks") {
copypath("0:/lib/lib_gui_box.ks", "1:").
}
if not exists("1:/spec_char.ksm") {
copypath("0:/lib/spec_char.ksm", "1:").
}
function fuel_transfer {
parameter from_tanks, to_tanks, limit is 0.
set job_lf_tick to transferall("liquidfuel", from_tanks, to_tanks).
set job_lf_tick:active to true.
set job_lf_tick to transferall("oxidizer", from_tanks, to_tanks).
set job_lf_tick:active to true.
set job_mp_tick to transferall("monopropellant", from_tanks, to_tanks).
set job_mp_tick:active to true.
return.
wait 10.
if limit > 0 {
set job_lf_tock to transfer("liquidfuel", to_tanks, from_tanks, limit).
set job_lf_tock:active to true.
set job_mp_tock to transfer("monopropellant", to_tanks, from_tanks, 50).
set job_mp_tock:active to true.
}
}
runoncepath("lib_list_dialog.ks").
// List of storage tanks. Always the same.
set storageTanks to SHIP:PARTSTAGGED("storageTank").
set remainingFuel to 0.
set modeList to list("Refuel UT","Restock","Load shuttle","General refueling").
if body:name = "Kerbin" { modeList:remove(2). set shuttleName to "Shuttle". set remainingFuel to 400. }
if body:name = "Mun" { set shuttleName to "Fueler". }
list elements in eList.
set dockedShips to list().
set dockedShipNames to list().
clearscreen.
set choice to open_menu("Select mode", modeList).
if choice = "Refuel UT" {
for elem in eList {
if elem:name:startswith("UT") {
dockedShipNames:add(elem:name).
dockedShips:add(elem).
}
}
set choice to open_list_dialog("Select UT to refuel", dockedShipNames).
set targetShip to dockedShips[choice].
set receiverTanks to list().
FOR item IN targetShip:PARTS {
IF item:TAG = "receiverTank" {
receiverTanks:ADD(item).
}
}
fuel_transfer(storageTanks, receiverTanks, 0).
}
if choice = "Restock" {
for elem in eList {
if elem:name:contains(shuttleName) {
dockedShips:add(elem).
dockedShipNames:add(elem:name).
}
}
set choice to open_list_dialog("Select ship to restock from", dockedShipNames).
clearscreen.
set refuelerShip to dockedShips[choice].
set shuttleTanks to list().
for item in refuelerShip:parts {
if item:tag = "shuttleTank" {
shuttleTanks:add(item).
}
}
print "Initiating fuel transfer.".
fuel_transfer(shuttleTanks, storageTanks, 0).
if remainingFuel > 0 {
fuel_transfer(storageTanks, shuttleTanks, remainingFuel).
}
}
if choice = "Load shuttle" {
for elem in eList {
// are we at mine on Mun?
if ship:status = "LANDED" {
if elem:name:contains("Fueler") {
dockedShips:add(elem).
dockedShipNames:add(elem:name).
}
} else {
if elem:name:startswith("Fuel Shuttle") {
dockedShips:add(elem).
dockedShipNames:add(elem:name).
}
}
}
set choice to open_list_dialog("Select oiler to refuel", dockedShipNames).
set shuttleShip to dockedShips[choice].
set shuttleTanks to list().
for item in shuttleShip:parts {
if item:tag = "shuttleTank" {
shuttleTanks:add(item).
}
if item:tag = "privateTank" {
shuttleTanks:add(item).
}
if item:tag = "receiverTank" {
shuttleTanks:add(item).
}
}
fuel_transfer(storageTanks, shuttleTanks, 0).
}