1 | -- Create the trigger |
---|
2 | trigger = ScriptTrigger() |
---|
3 | trigger:setName("hangartrigger") |
---|
4 | trigger:setScript("hangar.lua") |
---|
5 | trigger:setFunction("tick") |
---|
6 | trigger:setAbsCoor(678.946838, -11.959779, -920.512634) |
---|
7 | trigger:setTarget("Player") |
---|
8 | trigger:setRadius(100) |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | -- Get objects from orxonox |
---|
13 | thisscript:addObject("Claw", "spaceshipclaw") |
---|
14 | thisscript:addObject("RepairStation", "repair") |
---|
15 | thisscript:addObject("FPSPlayer", "Player") |
---|
16 | thisscript:addObject("SpaceShip", "spaceship") |
---|
17 | thisscript:addObject("GenericNPC", "mechanic") |
---|
18 | thisscript:addObject("GenericNPC", "mechanic2") |
---|
19 | |
---|
20 | -- Global Variables |
---|
21 | playerEnteredSpaceShip = false |
---|
22 | playerReachedTrigger = false |
---|
23 | spaceshipOnPad = false |
---|
24 | spaceshipLaunchReady = false |
---|
25 | |
---|
26 | |
---|
27 | -- Returns the distance between (x1,x2,x3) and (y1,y2,y3) |
---|
28 | function dist( x1,x2,x3, y1,y2,y3 ) |
---|
29 | |
---|
30 | return math.sqrt( (x1-y1)^2 + (x2-y2)^2 + (x3-y3)^2 ) |
---|
31 | |
---|
32 | end |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | function observePlayer() |
---|
37 | |
---|
38 | --playerEnteredSpaceShip = spaceship:hasPlayer() |
---|
39 | |
---|
40 | playerX = Player:getAbsCoorX() |
---|
41 | playerY = Player:getAbsCoorY() |
---|
42 | playerZ = Player:getAbsCoorZ() |
---|
43 | |
---|
44 | if dist( playerX,playerY,playerZ,678.946838, -11.959779, -920.512634 ) < 200 then |
---|
45 | playerReachedTrigger = true |
---|
46 | end |
---|
47 | |
---|
48 | end |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | mprogramRoute = true |
---|
55 | mheight = 5 |
---|
56 | function mechanicMove(timestep) |
---|
57 | if mprogramRoute then |
---|
58 | |
---|
59 | mechanic:walkTo( 991.192261, mheight, -1878.394287) |
---|
60 | mechanic:walkTo( 976.976685, mheight, -1879.182129) |
---|
61 | mechanic:walkTo( 963.752625, mheight, -1880.202881) |
---|
62 | mechanic:walkTo( 948.094543, mheight, -1880.980713) |
---|
63 | mechanic:walkTo( 931.008606, mheight, -1880.974854) |
---|
64 | mechanic:walkTo( 917.888428, mheight, -1880.832764) |
---|
65 | mechanic:walkTo( 901.552368, mheight, -1880.655762) |
---|
66 | mechanic:walkTo( 886.475220, mheight, -1880.522949) |
---|
67 | mechanic:walkTo( 872.041504, mheight, -1880.545410) |
---|
68 | mechanic:walkTo( 851.380249, mheight, -1880.577637) |
---|
69 | mechanic:walkTo( 840.637512, mheight, -1880.594238) |
---|
70 | mechanic:walkTo( 828.564941, mheight, -1880.489868) |
---|
71 | mechanic:walkTo( 811.580322, mheight, -1880.085205) |
---|
72 | mechanic:walkTo( 801.953003, mheight, -1880.036377) |
---|
73 | mechanic:walkTo( 784.801086, mheight, -1880.280762) |
---|
74 | mechanic:walkTo( 774.514343, mheight, -1880.380005) |
---|
75 | mechanic:walkTo( 762.351746, mheight, -1880.248779) |
---|
76 | mechanic:walkTo( 750.737549, mheight, -1880.123413) |
---|
77 | mechanic:walkTo( 739.186890, mheight, -1879.999023) |
---|
78 | mechanic:walkTo( 728.210022, mheight, -1879.880371) |
---|
79 | mechanic:walkTo( 717.243835, mheight, -1879.761719) |
---|
80 | mechanic:walkTo( 708.253235, mheight, -1879.649048) |
---|
81 | mechanic:walkTo( 695.825867, mheight, -1877.611938) |
---|
82 | mechanic:walkTo( 687.077820, mheight, -1869.800659) |
---|
83 | mechanic:walkTo( 683.886963, mheight, -1859.888062) |
---|
84 | mechanic:walkTo( 685.589905, mheight, -1844.102051) |
---|
85 | mechanic:walkTo( 686.333069, mheight, -1837.212524) |
---|
86 | mechanic:walkTo( 687.256042, mheight, -1828.656860) |
---|
87 | mechanic:walkTo( 688.759583, mheight, -1820.024048) |
---|
88 | mechanic:walkTo( 690.621216, mheight, -1809.834595) |
---|
89 | mechanic:walkTo( 692.045593, mheight, -1803.566772) |
---|
90 | mechanic:walkTo( 695.021851, mheight, -1795.320923) |
---|
91 | mechanic:walkTo( 703.956360, mheight, -1789.028931) |
---|
92 | mechanic:walkTo( 711.400574, mheight, -1785.378418) |
---|
93 | mechanic:walkTo( 720.236267, mheight, -1782.750977) |
---|
94 | mechanic:walkTo( 741.346130, mheight, -1786.131836) |
---|
95 | mechanic:walkTo( 744.505798, mheight, -1788.214111) |
---|
96 | mechanic:walkTo( 753.788513, mheight, -1796.320557) |
---|
97 | mechanic:walkTo( 760.480408, mheight, -1804.107788) |
---|
98 | mechanic:walkTo( 765.918274, mheight, -1811.952393) |
---|
99 | mechanic:walkTo( 772.114990, mheight, -1823.565674) |
---|
100 | mechanic:walkTo( 776.130737, mheight, -1830.713989) |
---|
101 | mechanic:walkTo( 781.833313, mheight, -1836.770996) |
---|
102 | mechanic:walkTo( 796.051880, mheight, -1843.499512) |
---|
103 | mechanic:walkTo( 805.178101, mheight, -1844.844116) |
---|
104 | mechanic:walkTo( 816.733154, mheight, -1846.198608) |
---|
105 | mechanic:walkTo( 830.296326, mheight, -1844.374146) |
---|
106 | mechanic:walkTo( 841.234680, mheight, -1841.184814) |
---|
107 | mechanic:walkTo( 853.356201, mheight, -1837.650391) |
---|
108 | mechanic:walkTo( 866.242981, mheight, -1833.892944) |
---|
109 | mechanic:walkTo( 877.006836, mheight, -1830.820923) |
---|
110 | mechanic:walkTo( 889.236816, mheight, -1828.092773) |
---|
111 | mechanic:walkTo( 897.856689, mheight, -1826.204346) |
---|
112 | mechanic:walkTo( 909.685486, mheight, -1823.613037) |
---|
113 | mechanic:walkTo( 922.058777, mheight, -1819.907227) |
---|
114 | mechanic:walkTo( 933.861328, mheight, -1814.044800) |
---|
115 | mechanic:walkTo( 943.290588, mheight, -1809.960205) |
---|
116 | mechanic:walkTo( 952.188293, mheight, -1806.317261) |
---|
117 | mechanic:walkTo( 985.450745, mheight, -1800.297729) |
---|
118 | mechanic:walkTo( 1000.339722, mheight, -1800.916626) |
---|
119 | mechanic:walkTo( 1013.447937, mheight, -1802.642090) |
---|
120 | mechanic:walkTo( 1022.703430, mheight, -1808.694946) |
---|
121 | mechanic:walkTo( 1030.242554, mheight, -1821.859253) |
---|
122 | mechanic:walkTo( 1030.063354, mheight, -1839.935547) |
---|
123 | mechanic:walkTo( 1025.804932, mheight, -1864.135986) |
---|
124 | mechanic:walkTo( 1019.079651, mheight, -1878.196777) |
---|
125 | |
---|
126 | mprogramRoute = false |
---|
127 | end |
---|
128 | |
---|
129 | if mechanic:finalGoalReached() then |
---|
130 | mprogramRoute = true |
---|
131 | end |
---|
132 | |
---|
133 | end |
---|
134 | |
---|
135 | mtprogramRoute = true |
---|
136 | mtheight = 5 |
---|
137 | waittime = 0 |
---|
138 | waiting = false |
---|
139 | function mechanictMove(timestep) |
---|
140 | if mtprogramRoute then |
---|
141 | mechanic2:walkTo( 1564.473999, mtheight, -1923.821533) |
---|
142 | mechanic2:walkTo( 1556.049927, mtheight, -1916.359009) |
---|
143 | mechanic2:walkTo( 1550.970581, mtheight, -1913.087524) |
---|
144 | mechanic2:walkTo( 1542.345459, mtheight, -1912.611938) |
---|
145 | mechanic2:walkTo( 1534.643677, mtheight, -1912.361816) |
---|
146 | mechanic2:walkTo( 1524.490845, mtheight, -1912.074097) |
---|
147 | mechanic2:walkTo( 1516.120605, mtheight, -1912.511475) |
---|
148 | mechanic2:walkTo( 1508.607788, mtheight, -1912.904175) |
---|
149 | mechanic2:walkTo( 1498.452759, mtheight, -1913.434814) |
---|
150 | mechanic2:walkTo( 1492.513916, mtheight, -1913.744995) |
---|
151 | mechanic2:walkTo( 1483.056274, mtheight, -1914.239136) |
---|
152 | mechanic2:walkTo( 1471.428711, mtheight, -1916.435303) |
---|
153 | mechanic2:walkTo( 1460.068359, mtheight, -1916.473022) |
---|
154 | mechanic2:walkTo( 1451.006592, mtheight, -1913.691772) |
---|
155 | mechanic2:walkTo( 1444.585938, mtheight, -1911.533691) |
---|
156 | mechanic2:walkTo( 1439.008423, mtheight, -1909.659058) |
---|
157 | mechanic2:walkTo( 1421.636230, mtheight, -1915.466553) |
---|
158 | mechanic2:walkTo( 1420.582275, mtheight, -1926.693970) |
---|
159 | mechanic2:walkTo( 1422.506714, mtheight, -1934.938232) |
---|
160 | mechanic2:walkTo( 1430.749023, mtheight, -1942.431519) |
---|
161 | mechanic2:walkTo( 1440.773315, mtheight, -1948.152832) |
---|
162 | mechanic2:walkTo( 1452.532227, mtheight, -1950.169800) |
---|
163 | mechanic2:walkTo( 1465.584961, mtheight, -1949.407959) |
---|
164 | mechanic2:walkTo( 1475.635254, mtheight, -1948.756226) |
---|
165 | mechanic2:walkTo( 1481.961548, mtheight, -1948.346069) |
---|
166 | mechanic2:walkTo( 1495.564575, mtheight, -1947.588257) |
---|
167 | mechanic2:walkTo( 1505.660156, mtheight, -1947.679077) |
---|
168 | mechanic2:walkTo( 1514.055542, mtheight, -1947.901245) |
---|
169 | mechanic2:walkTo( 1523.532959, mtheight, -1948.351440) |
---|
170 | mechanic2:walkTo( 1537.855347, mtheight, -1949.461914) |
---|
171 | mechanic2:walkTo( 1545.510498, mtheight, -1950.162720) |
---|
172 | mechanic2:walkTo( 1553.132935, mtheight, -1950.860718) |
---|
173 | mechanic2:walkTo( 1556.371460, mtheight, -1951.157104) |
---|
174 | mechanic2:walkTo( 1563.450806, mtheight, -1951.804932) |
---|
175 | mechanic2:walkTo( 1572.594116, mtheight, -1952.320679) |
---|
176 | mechanic2:walkTo( 1582.691772, mtheight, -1950.470459) |
---|
177 | mechanic2:walkTo( 1589.872681, mtheight, -1929.683105) |
---|
178 | mechanic2:walkTo( 1587.794922, mtheight, -1922.749756) |
---|
179 | mechanic2:walkTo( 1582.800171, mtheight, -1917.671021) |
---|
180 | mechanic2:walkTo( 1573.449951, mtheight, -1915.750854) |
---|
181 | mechanic2:walkTo( 1564.055908, mtheight, -1914.986328) |
---|
182 | mtprogramRoute = false |
---|
183 | end |
---|
184 | |
---|
185 | mechanic2X = mechanic2:getAbsCoorX() |
---|
186 | mechanic2Y = mechanic2:getAbsCoorY() |
---|
187 | mechanic2Z = mechanic2:getAbsCoorZ() |
---|
188 | |
---|
189 | if dist(mechanic2X,mechanic2Y,mechanic2Z,1435.444824, mtheight, -1916.463013) < 10 and not waiting then |
---|
190 | mechanic2:stop() |
---|
191 | waittime = 5 |
---|
192 | --io.write("mechanic2 stoped \n") |
---|
193 | waiting = true |
---|
194 | end |
---|
195 | |
---|
196 | if waittime >= 0 and waiting then |
---|
197 | waittime = waittime - timestep |
---|
198 | --io.write(waittime,"\n") |
---|
199 | if waittime < 0 then |
---|
200 | --io.write("mechanic2 finished waiting\n") |
---|
201 | mechanic2:resume() |
---|
202 | end |
---|
203 | end |
---|
204 | |
---|
205 | if dist(mechanic2X,mechanic2Y,mechanic2Z,1564.473999, mtheight, -1923.821533) < 10 and waiting then |
---|
206 | waiting = false |
---|
207 | end |
---|
208 | |
---|
209 | |
---|
210 | if mechanic2:finalGoalReached() then |
---|
211 | mtprogramRoute = true |
---|
212 | end |
---|
213 | |
---|
214 | end |
---|
215 | |
---|
216 | |
---|
217 | |
---|
218 | |
---|
219 | |
---|
220 | |
---|
221 | |
---|
222 | |
---|
223 | positionReached = false |
---|
224 | spaceShipReleased = false |
---|
225 | function moveToLaunchSite(timestep) |
---|
226 | |
---|
227 | if not positionReached then |
---|
228 | dx = 10 * timestep |
---|
229 | dy = 0 * timestep |
---|
230 | dz = 0* timestep |
---|
231 | end |
---|
232 | |
---|
233 | if not spaceShipReleased and positionReached then |
---|
234 | dx = 0 * timestep |
---|
235 | dy = 10 * timestep |
---|
236 | dz = 0 * timestep |
---|
237 | end |
---|
238 | |
---|
239 | if positionReached and spaceShipReleased then |
---|
240 | dx = 0 * timestep |
---|
241 | dy = 1 * timestep |
---|
242 | dz = 0 * timestep |
---|
243 | end |
---|
244 | |
---|
245 | |
---|
246 | if spaceshipOnPad then |
---|
247 | |
---|
248 | if not spaceShipReleased then |
---|
249 | --spaceshipclaw:playAnimation(1,1) |
---|
250 | --io.write("release spaceship\n") |
---|
251 | spaceShipReleased = true |
---|
252 | playerEnteredSpaceShip = true |
---|
253 | end |
---|
254 | |
---|
255 | --if clawY > 100 then |
---|
256 | spaceshipLaunchReady = true |
---|
257 | --end |
---|
258 | |
---|
259 | end |
---|
260 | |
---|
261 | |
---|
262 | -- set new coordinates |
---|
263 | --clawX = claw:getAbsCoorX() |
---|
264 | --clawY = claw:getAbsCoorY() |
---|
265 | --clawZ = claw:getAbsCoorZ() |
---|
266 | |
---|
267 | --claw:setAbsCoor(clawX + dx, clawY + dy, clawZ + dz) |
---|
268 | spaceshipX = spaceship:getAbsCoorX() |
---|
269 | spaceshipY = spaceship:getAbsCoorY() |
---|
270 | spaceshipZ = spaceship:getAbsCoorZ() |
---|
271 | |
---|
272 | spaceship:setAbsCoor(spaceshipX + dx, spaceshipY + dy, spaceshipZ + dz) |
---|
273 | |
---|
274 | |
---|
275 | |
---|
276 | --if dist( clawX,clawY,clawZ,1020.025024, -11.959781, -1721.614380 ) < 60 then |
---|
277 | if dist( spaceshipX,spaceshipY,spaceshipZ,1020.025024, -11.959781, -1721.614380 ) < 60 then |
---|
278 | positionReached = true |
---|
279 | end |
---|
280 | |
---|
281 | |
---|
282 | --if dist( clawX,clawY,clawZ,167.361526,29,483.163818 ) < 60 then |
---|
283 | if spaceshipY > 10 then |
---|
284 | spaceshipOnPad = true |
---|
285 | end |
---|
286 | |
---|
287 | |
---|
288 | end |
---|
289 | |
---|
290 | hoverPosReached = false |
---|
291 | function launchSpaceShip(timestep) |
---|
292 | |
---|
293 | if not hoverPosReached then |
---|
294 | dx = 0 * timestep |
---|
295 | dy = 1 * timestep |
---|
296 | dz = 0 * timestep |
---|
297 | else |
---|
298 | dx = 200 * timestep |
---|
299 | dy = 0 * timestep |
---|
300 | dz = 0 * timestep |
---|
301 | end |
---|
302 | |
---|
303 | spaceshipX = spaceship:getAbsCoorX() |
---|
304 | spaceshipY = spaceship:getAbsCoorY() |
---|
305 | spaceshipZ = spaceship:getAbsCoorZ() |
---|
306 | |
---|
307 | spaceship:setAbsCoor(spaceshipX + dx, spaceshipY + dy, spaceshipZ + dz) |
---|
308 | |
---|
309 | if spaceshipY > 15 then |
---|
310 | hoverPosReached = true |
---|
311 | end |
---|
312 | |
---|
313 | end |
---|
314 | |
---|
315 | |
---|
316 | function tick(timestep) |
---|
317 | |
---|
318 | observePlayer() |
---|
319 | mechanicMove(timestep) |
---|
320 | mechanictMove(timestep) |
---|
321 | |
---|
322 | --if playerReachedTrigger and not spaceshipLaunchReady then |
---|
323 | --moveToLaunchSite(timestep) |
---|
324 | --end |
---|
325 | |
---|
326 | --if spaceshipLaunchReady then |
---|
327 | --launchSpaceShip(timestep) |
---|
328 | --end |
---|
329 | |
---|
330 | |
---|
331 | return false |
---|
332 | end |
---|