Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/presentation/scripts/guard.lua @ 4151

Last change on this file since 4151 was 4151, checked in by snellen, 18 years ago

added attractor.lua

File size: 10.7 KB
RevLine 
[4080]1-- Get objects from orxonox
2thisscript:addObject("GenericNPC","guard")
3thisscript:addObject("FPSPlayer", "Player")
4
[3945]5-- Global Variables
[3947]6walkingRouteOne = true   -- True if thestranger is walking route one
[3945]7exitPositionReached = false
8playerInLock = false
9hangarReached = false
[4080]10guardStopped = false
[4151]11gotoSpaceship = false
[3945]12
[4080]13height = 34
[3962]14
[3946]15-- Returns the distance between (x1,x2,x3) and (y1,y2,y3)
16function dist( x1,x2,x3, y1,y2,y3 )
17return math.sqrt( (x1-y1)^2 + (x2-y2)^2 + (x3-y3)^2 )
18end
19
[3945]20
[3946]21function observePlayer()
[4080]22
23guardX = guard:getAbsCoorX()
24guardY = guard:getAbsCoorY()
25guardZ = guard:getAbsCoorZ()
26
[3946]27playerX = Player:getAbsCoorX()
28playerY = Player:getAbsCoorY()
29playerZ = Player:getAbsCoorZ()
30
[4080]31
32distance = dist( guardX,guardY,guardZ,playerX, playerY, playerZ)
33
[4151]34if distance > 250 and hangarRouteProgrammed and not guardStopped and not gotoSpaceship then
[4080]35 guard:stop()
36 guardStopped = true
37end
38
[4151]39if distance < 250 and hangarRouteProgrammed and guardStopped and not gotoSpaceship then
[4080]40 guard:resume()
41 guardStopped = false
42end
43
44if dist( playerX,playerY,playerZ,167.361526,29,483.163818 ) < 200 then
[3947]45playerInLock = true
[3945]46end
47
[4151]48if dist( guardX,guardY,guardZ,772.325012, height, -1500.850708) < 200 then
49gotoSpaceship = true
[3947]50end
51
[4151]52
53end
54
[3947]55routeOneProgrammed = false
[3945]56function walkRouteOne(timestep)
[3947]57if not routeOneProgrammed then
[3964]58guard:walkTo( 266.396362, height, 241.398544)
59guard:walkTo( 254.577255, height, 241.159897)
60guard:walkTo( 221.120651, height, 240.484360)
61guard:walkTo( 187.732651, height, 239.810196)
62guard:walkTo( 165.661865, height, 239.364563)
63guard:walkTo( 148.642044, height, 239.020889)
64guard:walkTo( 128.012802, height, 238.604340)
65guard:walkTo( 65.664688, height, 237.345383)
66guard:walkTo( 30.099592, height, 236.627243)
67guard:walkTo( -14.031926, height, 236.483414)
68guard:walkTo( -52.224205, height, 241.776978)
69guard:walkTo( -83.528168, height, 245.757629)
70guard:walkTo( -98.730980, height, 247.394043)
71guard:walkTo( -111.666504, height, 246.585648)
72guard:walkTo( -111.666504, height, 246.585648)
73guard:walkTo( -114.805542, height, 246.144440)
74guard:walkTo( -119.267967, height, 245.360168)
75guard:walkTo( -138.284515, height, 239.281021)
76guard:walkTo( -146.166840, height, 234.512054)
77guard:walkTo( -157.210480, height, 222.620941)
78guard:walkTo( -158.519867, height, 219.674301)
79guard:walkTo( -158.519867, height, 219.674301)
80guard:walkTo( -158.478958, height, 213.490570)
81guard:walkTo( -158.478958, height, 213.490570)
82guard:walkTo( -155.965332, height, 210.303101)
83guard:walkTo( -150.804489, height, 203.959869)
84guard:walkTo( -148.853012, height, 201.561295)
85guard:walkTo( -145.451157, height, 197.554382)
86guard:walkTo( -143.694107, height, 196.373535)
87guard:walkTo( -139.281479, height, 193.407990)
88guard:walkTo( -137.526047, height, 192.228226)
89guard:walkTo( -103.046753, height, 182.510071)
[3965]90guard:runTo( -14.992087, height, 181.910767)
91guard:runTo( 46.347664, height, 181.493317)
92guard:runTo( 86.343376, height, 181.221130)
93guard:runTo( 124.465179, height, 194.251617)
94guard:runTo( 136.548996, height, 219.682953)
95guard:runTo( 145.162140, height, 244.268982)
96guard:runTo( 149.328720, height, 256.993256)
97guard:runTo( 162.649582, height, 268.181732)
[3951]98
[3947]99routeOneProgrammed = true
100end
[3945]101
[3951]102if guard:finalGoalReached() then
103return false
[3945]104end
105
[3951]106return true
107end
108
109
110exitRouteProgrammed = false
[3945]111function goToExitPosition(timestep)
112
[3951]113if not exitRouteProgrammed then
[4080]114--guard:runTo( 162.096558, height, 274.944366)
115--guard:runTo( 161.519516, height, 286.673370)
116--guard:runTo( 161.098618, height, 295.228699)
117--guard:runTo( 160.568466, height, 306.004486)
118guard:runTo( 160.151169, height, 314.486572)
119guard:runTo( 159.416641, height, 324.925232)
[3962]120guard:walkTo( 158.700073, height, 335.108154)
121guard:walkTo( 157.943298, height, 345.862610)
122guard:walkTo( 157.418381, height, 356.131256)
123guard:walkTo( 156.908035, height, 366.115417)
124guard:walkTo( 156.940308, height, 377.467712)
125guard:walkTo( 156.965408, height, 386.287933)
126guard:walkTo( 156.924698, height, 394.296417)
127guard:walkTo( 156.816116, height, 401.564911)
128guard:walkTo( 156.147583, height, 446.314850)
129guard:walkTo( 155.145660, height, 515.473877)
130guard:walkTo( 148.450058, height, 524.572571)
131guard:walkTo( 135.599609, height, 533.407166)
132guard:walkTo( 119.772217, height, 539.609192)
133guard:walkTo( 108.926720, height, 537.174927)
134guard:walkTo( 100.885788, height, 524.737793)
135guard:walkTo( 99.870834, height, 512.540100)
136guard:walkTo( 108.219215, height, 502.064178)
137
[3951]138exitRouteProgrammed = true
139end
140
141if guard:finalGoalReached() and playerInLock then
142return true
143end
144
[3945]145return false
146end
147
148
[3951]149hangarRouteProgrammed = false
[3945]150function goToHangar(timestep)
151
[3964]152if not hangarRouteProgrammed and playerInLock then
[4080]153
154guard:walkTo( 133.354797, height, 504.669128)
155guard:walkTo( 147.490158, height, 507.034393)
156guard:walkTo( 157.640610, height, 508.901001)
157guard:walkTo( 168.830688, height, 510.958710)
158guard:walkTo( 185.020630, height, 512.736206)
159guard:walkTo( 201.232452, height, 513.413818)
160guard:walkTo( 265.666138, height, 513.736023)
161guard:walkTo( 362.377960, height, 515.575806)
162guard:walkTo( 426.176392, height, 515.666748)
163guard:walkTo( 500.031677, height, 515.197266)
164guard:walkTo( 551.294250, height, 514.430237)
165guard:walkTo( 604.974731, height, 515.106323)
166guard:walkTo( 651.117920, height, 516.026550)
167guard:walkTo( 664.581909, height, 516.295227)
168guard:walkTo( 683.122803, height, 516.665100)
169guard:walkTo( 694.547485, height, 516.892944)
170guard:walkTo( 704.408569, height, 517.089539)
171guard:walkTo( 714.413208, height, 517.289185)
172guard:walkTo( 739.045288, height, 515.581970)
173guard:walkTo( 763.904541, height, 497.281738)
174guard:walkTo( 767.672791, height, 481.974457)
175guard:walkTo( 769.436951, height, 468.704559)
176guard:walkTo( 770.490967, height, 453.283386)
177guard:walkTo( 771.185303, height, 435.960114)
178guard:walkTo( 771.952820, height, 379.502045)
179guard:walkTo( 771.938293, height, 310.049042)
180guard:walkTo( 772.514526, height, 231.579498)
181guard:walkTo( 773.601074, height, 135.177933)
182guard:walkTo( 773.790771, height, 50.675163)
183guard:walkTo( 773.316162, height, -36.961666)
184guard:walkTo( 772.885986, height, -116.407944)
185guard:walkTo( 772.841309, height, -124.651726)
186guard:walkTo( 772.491333, height, -137.742279)
187guard:walkTo( 770.644775, height, -153.245926)
188guard:walkTo( 768.774414, height, -163.767120)
189guard:walkTo( 766.336426, height, -174.224228)
190guard:walkTo( 762.794128, height, -187.312271)
191guard:walkTo( 733.548279, height, -274.004791)
192guard:walkTo( 713.113647, height, -329.657959)
193guard:walkTo( 694.801819, height, -379.530243)
194guard:walkTo( 681.276062, height, -422.047028)
195guard:walkTo( 672.579102, height, -458.540985)
196guard:walkTo( 670.843384, height, -465.824615)
197guard:walkTo( 669.948364, height, -480.910645)
198guard:walkTo( 669.361511, height, -493.648529)
199guard:walkTo( 669.686829, height, -501.598572)
200guard:walkTo( 674.055664, height, -582.077637)
201guard:walkTo( 676.046387, height, -630.403809)
202guard:walkTo( 677.839050, height, -674.209534)
203guard:walkTo( 680.754944, height, -765.965515)
204guard:walkTo( 681.034180, height, -803.351135)
205guard:walkTo( 680.088806, height, -844.069031)
206guard:walkTo( 677.801514, height, -899.952148)
207guard:walkTo( 675.205627, height, -950.496460)
208guard:walkTo( 672.847778, height, -996.413574)
209guard:walkTo( 676.204041, height, -1043.556274)
210guard:walkTo( 691.304382, height, -1088.596558)
211guard:walkTo( 705.101318, height, -1128.320312)
212guard:walkTo( 720.476013, height, -1164.364380)
213guard:walkTo( 729.216797, height, -1183.948364)
214guard:walkTo( 740.145203, height, -1212.598267)
215guard:walkTo( 746.547363, height, -1238.340576)
216guard:walkTo( 756.866211, height, -1280.605347)
217guard:walkTo( 763.380554, height, -1314.622314)
218guard:walkTo( 768.731506, height, -1347.977539)
219guard:walkTo( 772.446655, height, -1381.641479)
220guard:walkTo( 772.721069, height, -1421.184937)
221guard:walkTo( 772.414734, height, -1457.349121)
222guard:walkTo( 772.803284, height, -1489.560913)
223
[4100]224guard:walkTo( 772.325012, height, -1500.850708)
225guard:walkTo( 772.325012, height, -1500.850708)
226guard:walkTo( 772.487854, height, -1508.028809)
227guard:walkTo( 774.761047, height, -1519.442139)
228guard:walkTo( 778.809204, height, -1525.292847)
229guard:walkTo( 783.482666, height, -1530.000610)
230guard:walkTo( 790.163269, height, -1536.350708)
231guard:walkTo( 797.713745, height, -1542.968018)
232guard:walkTo( 804.024475, height, -1548.390503)
233guard:walkTo( 810.316406, height, -1553.796875)
234guard:walkTo( 819.849731, height, -1561.323242)
235guard:walkTo( 826.676819, height, -1566.627197)
236guard:walkTo( 833.950928, height, -1572.278442)
237guard:walkTo( 840.587036, height, -1577.434082)
238guard:walkTo( 847.261230, height, -1582.458252)
239guard:walkTo( 852.104797, height, -1586.104370)
240guard:walkTo( 857.504944, height, -1590.169556)
241guard:walkTo( 861.696411, height, -1593.324829)
242guard:walkTo( 867.690613, height, -1597.837036)
243guard:walkTo( 874.808105, height, -1604.437378)
244guard:walkTo( 878.302429, height, -1608.333252)
245guard:walkTo( 884.001892, height, -1614.366211)
246guard:walkTo( 890.699646, height, -1621.398315)
247guard:walkTo( 895.391052, height, -1626.179688)
248guard:walkTo( 902.171509, height, -1633.090332)
249guard:walkTo( 906.807495, height, -1637.957764)
250guard:walkTo( 910.438599, height, -1641.770142)
251guard:walkTo( 915.626160, height, -1647.216797)
252guard:walkTo( 921.844727, height, -1653.745972)
253guard:walkTo( 928.565125, height, -1660.801636)
254guard:walkTo( 933.742004, height, -1666.236694)
255guard:walkTo( 938.956543, height, -1671.711182)
256guard:walkTo( 942.160706, height, -1675.745972)
257guard:walkTo( 947.547302, height, -1681.952881)
258guard:walkTo( 951.732483, height, -1687.077759)
259guard:walkTo( 957.284851, height, -1693.876709)
260guard:walkTo( 962.786438, height, -1700.614990)
261guard:walkTo( 966.177246, height, -1705.151245)
262guard:walkTo( 970.221619, height, -1710.886230)
263guard:walkTo( 974.503113, height, -1717.243896)
264guard:walkTo( 977.332153, height, -1722.064087)
265guard:walkTo( 981.496887, height, -1729.391357)
266guard:walkTo( 986.814148, height, -1738.394165)
267guard:walkTo( 991.428650, height, -1745.393799)
268guard:walkTo( 998.958069, height, -1755.184326)
269guard:walkTo( 1003.995300, height, -1761.734131)
270guard:walkTo( 1009.006226, height, -1768.234375)
271guard:walkTo( 1013.550842, height, -1773.405029)
272guard:walkTo( 1019.371277, height, -1778.674072)
273guard:walkTo( 1024.703491, height, -1782.708618)
274guard:walkTo( 1030.605469, height, -1787.173950)
275guard:walkTo( 1036.072876, height, -1790.982056)
276guard:walkTo( 1043.746094, height, -1795.485474)
277guard:walkTo( 1050.884644, height, -1799.663574)
[3951]278hangarRouteProgrammed  = true
279end
280
[4106]281if guard:finalGoalReached() and not guardStopped then
[3951]282return true
283end
284
[3945]285return false
286end
287
288
[4151]289
[3945]290function tick(timestep)
[3946]291--io.write("Guard called \n")
292observePlayer()
[3945]293
[4151]294
[3945]295if walkingRouteOne then
[3951]296walkingRouteOne = walkRouteOne(timestep)
[3945]297end
298
299if not walkingRouteOne and not exitPositionReached then
300exitPositionReached = goToExitPosition(timestep)
301end
302
[3964]303if not hangarReached and exitPositionReached then
[3945]304hangarReached = goToHangar(timestep)
305end
306
[4100]307return hangarReached
[3945]308end
309 
Note: See TracBrowser for help on using the repository browser.