SHOW:
|
|
- or go back to the newest paste.
1 | - | // !runscript xSjerGzW |
1 | + | |
2 | - | // racetrack setup script: !runscript FWe0mbFH |
2 | + | |
3 | set pp to p:parent. | |
4 | - | set station to vessel("Space Race"). |
4 | + | if pp:typename = "dockingport" set port to pp. |
5 | - | set racecourse to list("PStart","w1","w2","w3","w4","w5","w6","w7","w8", "w9", "w10","PEnd"). |
5 | + | else findPort(pp). |
6 | } | |
7 | findPort(). | |
8 | - | for i in range(10) { |
8 | + | |
9 | core:part:controlfrom(). | |
10 | port:undock(). | |
11 | - | set g to station:partstagged(str)[0]. |
11 | + | wait 0.2. |
12 | kuniverse:forceactive(ship). | |
13 | wait 0.2. | |
14 | list engines in engs. for e in engs e:activate. | |
15 | sas off. | |
16 | - | set gate to ship:rootpart. |
16 | + | |
17 | wait 1. | |
18 | - | set gateTMax to 1.5. |
18 | + | set target to "Space Race". |
19 | - | set rel_v to velocity:orbit - station:velocity:orbit. |
19 | + | lock rel_v to choose (velocity:orbit - target:velocity:orbit) if hastarget else v(0,0,0). |
20 | set gateFA to v(1,0,0). | |
21 | set gateVel to v(0,0,0). | |
22 | - | set baseSpeed to 12. |
22 | + | set baseSpeed to 0. |
23 | - | set thrustMult to 1.5. |
23 | + | when vessel("space race"):partsdubbedpattern("station")[0]:tag = "stationGo" then set basespeed to 8 + random()*1. |
24 | set docking to false. | |
25 | - | wait until not(brakes). |
25 | + | |
26 | - | set lastIntersect to time:seconds. |
26 | + | set eng:deadband to 0.005. |
27 | } | |
28 | ||
29 | - | set port to ship:rootpart. |
29 | + | set racecourse to list("PStart","w1","w2","w3","w4","w5","w6","w7","w8","PEnd"). |
30 | set gates to list(). | |
31 | set col0 to rgba(0,0,0,0). | |
32 | - | set th to 0. set st to facing:vector. |
32 | + | for i in range(8) { |
33 | set i2 to i + 1. | |
34 | set str to racecourse[i2]. | |
35 | set g to target:partstagged(str)[0]. | |
36 | gates:add(list(g, highlight(g, col0) )). | |
37 | - | if pp:typename = "dockingport" { |
37 | + | |
38 | - | set port to pp. |
38 | + | |
39 | - | } else { |
39 | + | |
40 | - | findPort(pp). |
40 | + | |
41 | ||
42 | function dock { | |
43 | set minAng to 180. | |
44 | for d in target:dockingports { | |
45 | if d:nodetype = port:nodetype and d:state = "ready" and vang(-d:portfacing:vector,d:position) < minAng { | |
46 | set gate to d. | |
47 | - | wait 0. |
47 | + | |
48 | - | set station to vessel("Space Race"). |
48 | + | |
49 | } | |
50 | - | port:getmodule("moduledockingnode"):setfield("docking acquire force", 0). |
50 | + | |
51 | if docking when (gate:nodeposition-port:nodeposition):mag < 0.5 then { exit2(). } | |
52 | ||
53 | - | set undockTime to time:seconds. |
53 | + | |
54 | - | set ship:control:fore to -0.5. |
54 | + | |
55 | lock throttle to 0. rcs off. unlock throttle. set ship:control:neutralize to true. unlock steering. | |
56 | } | |
57 | - | list engines in engs. |
57 | + | |
58 | - | for en in engs { |
58 | + | |
59 | - | en:activate(). |
59 | + | |
60 | if defined tOld set tNew to time:seconds - tOld. | |
61 | set tOld to time:seconds. | |
62 | - | set eng:deadband to 0.000. |
62 | + | |
63 | - | set eng:thrustlimit to 50. |
63 | + | |
64 | } | |
65 | - | for m in ship:modulesnamed("ModuleLight") { |
65 | + | |
66 | - | if m:hasevent("Lights on") m:doevent("Lights on"). |
66 | + | |
67 | set hl:color to col0. | |
68 | set hl to gates[i][1]. | |
69 | ||
70 | set i to i + 1. | |
71 | if i = 8 set i to 0. | |
72 | when abs(vdot(gateFA, gate:position)) < rel_v:mag/20 and vdot(rel_v:normalized, gate:position) < 0 and vxcl(gateFA,gate:position):mag < 2.6 then { | |
73 | print "passed gate " + gate:tag. | |
74 | next(). | |
75 | } | |
76 | set gateVel to rel_v. | |
77 | set gateT to 1. | |
78 | ||
79 | set l to gate:children[0]:getmodule("moduleColoredLensLight"). | |
80 | ||
81 | set hl:color to rgba(l:getfield("light r"),l:getfield("light g"),l:getfield("light b"),0.3). | |
82 | } | |
83 | next(). | |
84 | - | if i = gates:length set i to 0. |
84 | + | |
85 | - | when not(docking) and abs(vdot(gateFA, gate:position)) < rel_v:mag/20 and vdot(rel_v:normalized, gate:position) > 0 and vxcl(gateFA,gate:position):mag < 2.6 then { |
85 | + | rcs on. |
86 | - | print "passed gate " + gate:tag. |
86 | + | set steeringmanager:maxstoppingtime to 2. |
87 | - | set gateT to gateTMax. |
87 | + | set steeringmanager:pitchpid:kp to 2. |
88 | set steeringmanager:yawpid:kp to 2. | |
89 | set steeringmanager:pitchpid:kd to 0.3. | |
90 | set steeringmanager:yawpid:kd to 0.3. | |
91 | - | set lastIntersect to time:seconds. |
91 | + | set tpid to pidloop(0.5,0,0.0,-1,1). |
92 | set spid to pidloop(tpid:kp,tpid:ki,tpid:kd,-1,1). | |
93 | - | //set l to gate:children[0]:getmodule("modulelighteva"). |
93 | + | |
94 | - | //set hl:color to rgba(l:getfield("light r"),l:getfield("light g"),l:getfield("light b"),0.3). |
94 | + | |
95 | set th to 0. set st to facing. | |
96 | lock throttle to th. | |
97 | lock steering to st. | |
98 | ||
99 | ||
100 | - | function go { |
100 | + | |
101 | - | parameter spd is 12. |
101 | + | |
102 | - | set basespeed to spd. |
102 | + | set gateFA to gate:facing:vector. |
103 | - | list targets in tars. for t in tars if t:distance < 500 and t <> station t:connection:sendmessage(list("go", spd)). |
103 | + | set side to vxcl(gateFA, gate:position):mag. |
104 | if docking { | |
105 | set fwdDist to vdot(gateFA, port:nodeposition - gate:nodeposition). | |
106 | - | set ship:control:neutralize to true. rcs off. unlock throttle. unlock steering. |
106 | + | set wantPos to gate:position + gateFA * (min(3, max(fwdDist - 1, -0.1 + 8*side)) + min(15, side / 2)). |
107 | set wanted_v to gateVel * gateT + (1-gateT) * (wantPos:normalized * (wantPos:mag^0.75)). | |
108 | set ve to wanted_v - rel_v. | |
109 | ||
110 | - | for d in station:dockingports { |
110 | + | set st to choose -gateFA if side < 1 and gate:position:mag < 10 else (ve + (rel_v:normalized * (-5/20))). |
111 | - | if d:nodetype = port:nodetype and d:state = "ready" and vang(-d:portfacing:vector,d:position) < minAng and station:elements[0]:parts:contains(d) { |
111 | + | |
112 | else { | |
113 | if vdot(gate:position, gate:facing:vector) < 0 set gateFA to -gateFA. | |
114 | set sl to baseSpeed + max(0.001,side-5)^0.1. | |
115 | - | |
115 | + | set wanted_v to gateVel * gateT + (1-gateT) * ((gate:position + gateFA * max(-12, 5 - side^1.25)):normalized * sl). |
116 | set ve to wanted_v - rel_v. | |
117 | set st to ve + (rel_v:normalized * (-baseSpeed/20)). | |
118 | } | |
119 | - | print "Docking". |
119 | + | |
120 | - | port:getmodule("moduledockingnode"):setfield("docking acquire force", 150). |
120 | + | set gateT to max(0,gateT-0.01). |
121 | - | when (gate:nodeposition-port:nodeposition):mag < 0.5 then { exit2(). } |
121 | + | if vang(facing:vector, ve) < 60 |
122 | - | on ship:parts:length { |
122 | + | set th to vdot(facing:vector,ve) * 3. |
123 | - | set TRANSFERALL("OXIDIZER", ship:elements[0], core:element):active to true. |
123 | + | else set th to 0. |
124 | - | set TRANSFERALL("LIQUIDFUEL", ship:elements[0], core:element):active to true. |
124 | + | |
125 | - | set TRANSFERALL("ELECTRICCHARGE", ship:elements[0], core:element):active to true. |
125 | + | set ship:control:translation to v(-spid:update(time:seconds, vdot(facing:starvector,ve)),-tpid:update(time:seconds,vdot(facing:topvector,ve)),-fpid:update(time:seconds,vdot(facing:vector,ve))). |
126 | - | global dockTime is time:seconds. when time:seconds > dockTime + 3 then { undockandgo(). } |
126 | + | return rcs. |
127 | } | |
128 | - | |
128 | + | |
129 | - | |
129 | + | |
130 | - | } |
130 | + | |
131 | //set camDist to 5. | |
132 | set trackcam to false. | |
133 | - | when not(docking) and ship:resources[0]:amount / ship:resources[0]:capacity < 0.1 and time:seconds > 2 + lastIntersect and gate:position:mag > 10 then { |
133 | + | //set cam to addons:camera:flightcamera. |
134 | - | dock(). return true. |
134 | + | //set gPos to -facing:vector * 80. |
135 | //set camMode to "station". | |
136 | when trackcam then { | |
137 | set gPos to gPos * 0.97 + (rel_v:normalized * 5 + gate:position):normalized * 0.03. | |
138 | - | function vesselSetup { |
138 | + | |
139 | - | rcs on. |
139 | + | |
140 | - | set steeringmanager:maxstoppingtime to 8. |
140 | + | |
141 | - | set steeringmanager:pitchpid:kp to 4. |
141 | + | |
142 | - | set steeringmanager:yawpid:kp to 4. |
142 | + | else if hastarget set cam:position to target:position:normalized * -camDist + vxcl(target:position,gPos:normalized * -camDist/2). |
143 | - | set steeringmanager:pitchpid:kd to 0.3. |
143 | + | |
144 | - | set steeringmanager:yawpid:kd to 0.3. |
144 | + | |
145 | ||
146 | - | vesselSetup(). |
146 | + |