Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/single_player_map/scripts/guard.lua @ 4068

Last change on this file since 4068 was 4067, checked in by snellen, 19 years ago

continued

File size: 8.3 KB
Line 
1-- Get objects from orxonox
2thisscript:addObject("GenericNPC","guard")
3thisscript:addObject("FPSPlayer", "Player")
4
5-- Global Variables
6walkingRouteOne = true   -- True if thestranger is walking route one
7exitPositionReached = false
8playerInLock = false
9hangarReached = false
10guardStopped = false
11
12height = 29
13
14-- Returns the distance between (x1,x2,x3) and (y1,y2,y3)
15function dist( x1,x2,x3, y1,y2,y3 )
16return math.sqrt( (x1-y1)^2 + (x2-y2)^2 + (x3-y3)^2 )
17end
18
19
20function observePlayer()
21
22guardX = guard:getAbsCoorX()
23guardY = guard:getAbsCoorY()
24guardZ = guard:getAbsCoorZ()
25
26playerX = Player:getAbsCoorX()
27playerY = Player:getAbsCoorY()
28playerZ = Player:getAbsCoorZ()
29
30
31distance = dist( guardX,guardY,guardZ,playerX, playerY, playerZ)
32
33--io.write(distance, " \n")
34
35if dist( guardX,guardY,guardZ,playerX, playerY, playerZ) > 150 and hangarRouteProgrammed and not guardStopped then
36 io.write("guard stopped\n")
37 guard:stop()
38 guardStopped = true
39end
40
41if dist( guardX,guardY,guardZ,playerX, playerY, playerZ) < 150 and hangarRouteProgrammed and guardStopped then
42io.write("guard resumed\n")
43 guard:resume()
44 guardStopped = false
45end
46
47if dist( playerX,playerY,playerZ,167.361526,29,483.163818 ) < 60 then
48playerInLock = true
49end
50
51end
52
53routeOneProgrammed = false
54function walkRouteOne(timestep)
55
56if not routeOneProgrammed then
57guard:walkTo( 266.396362, height, 241.398544)
58guard:walkTo( 254.577255, height, 241.159897)
59guard:walkTo( 221.120651, height, 240.484360)
60guard:walkTo( 187.732651, height, 239.810196)
61guard:walkTo( 165.661865, height, 239.364563)
62guard:walkTo( 148.642044, height, 239.020889)
63guard:walkTo( 128.012802, height, 238.604340)
64guard:walkTo( 65.664688, height, 237.345383)
65guard:walkTo( 30.099592, height, 236.627243)
66guard:walkTo( -14.031926, height, 236.483414)
67guard:walkTo( -52.224205, height, 241.776978)
68guard:walkTo( -83.528168, height, 245.757629)
69guard:walkTo( -98.730980, height, 247.394043)
70guard:walkTo( -111.666504, height, 246.585648)
71guard:walkTo( -111.666504, height, 246.585648)
72guard:walkTo( -114.805542, height, 246.144440)
73guard:walkTo( -119.267967, height, 245.360168)
74guard:walkTo( -138.284515, height, 239.281021)
75guard:walkTo( -146.166840, height, 234.512054)
76guard:walkTo( -157.210480, height, 222.620941)
77guard:walkTo( -158.519867, height, 219.674301)
78guard:walkTo( -158.519867, height, 219.674301)
79guard:walkTo( -158.478958, height, 213.490570)
80guard:walkTo( -158.478958, height, 213.490570)
81guard:walkTo( -155.965332, height, 210.303101)
82guard:walkTo( -150.804489, height, 203.959869)
83guard:walkTo( -148.853012, height, 201.561295)
84guard:walkTo( -145.451157, height, 197.554382)
85guard:walkTo( -143.694107, height, 196.373535)
86guard:walkTo( -139.281479, height, 193.407990)
87guard:walkTo( -137.526047, height, 192.228226)
88guard:walkTo( -103.046753, height, 182.510071)
89guard:runTo( -14.992087, height, 181.910767)
90guard:runTo( 46.347664, height, 181.493317)
91guard:runTo( 86.343376, height, 181.221130)
92guard:runTo( 124.465179, height, 194.251617)
93guard:runTo( 136.548996, height, 219.682953)
94guard:runTo( 145.162140, height, 244.268982)
95guard:runTo( 149.328720, height, 256.993256)
96guard:runTo( 162.649582, height, 268.181732)
97
98routeOneProgrammed = true
99end
100
101if guard:finalGoalReached() then
102return false
103end
104
105return true
106end
107
108
109exitRouteProgrammed = false
110function goToExitPosition(timestep)
111
112if not exitRouteProgrammed then
113guard:runTo( 162.096558, height, 274.944366)
114guard:runTo( 161.519516, height, 286.673370)
115guard:runTo( 161.098618, height, 295.228699)
116guard:runTo( 160.568466, height, 306.004486)
117guard:runTo( 160.151169, height, 314.486572)
118guard:runTo( 159.416641, height, 324.925232)
119guard:walkTo( 158.700073, height, 335.108154)
120guard:walkTo( 157.943298, height, 345.862610)
121guard:walkTo( 157.418381, height, 356.131256)
122guard:walkTo( 156.908035, height, 366.115417)
123guard:walkTo( 156.940308, height, 377.467712)
124guard:walkTo( 156.965408, height, 386.287933)
125guard:walkTo( 156.924698, height, 394.296417)
126guard:walkTo( 156.816116, height, 401.564911)
127guard:walkTo( 156.147583, height, 446.314850)
128guard:walkTo( 155.145660, height, 515.473877)
129guard:walkTo( 148.450058, height, 524.572571)
130guard:walkTo( 135.599609, height, 533.407166)
131guard:walkTo( 119.772217, height, 539.609192)
132guard:walkTo( 108.926720, height, 537.174927)
133guard:walkTo( 100.885788, height, 524.737793)
134guard:walkTo( 99.870834, height, 512.540100)
135guard:walkTo( 108.219215, height, 502.064178)
136
137exitRouteProgrammed = true
138end
139
140if guard:finalGoalReached() and playerInLock then
141return true
142end
143
144return false
145end
146
147
148hangarRouteProgrammed = false
149function goToHangar(timestep)
150
151if not hangarRouteProgrammed and playerInLock then
152guard:walkTo( 120.981117, height, 503.008972)
153guard:walkTo( 133.354797, height, 504.669128)
154guard:walkTo( 147.490158, height, 507.034393)
155guard:walkTo( 157.640610, height, 508.901001)
156guard:walkTo( 168.830688, height, 510.958710)
157guard:walkTo( 185.020630, height, 512.736206)
158guard:walkTo( 201.232452, height, 513.413818)
159guard:walkTo( 265.666138, height, 513.736023)
160guard:walkTo( 362.377960, height, 515.575806)
161guard:walkTo( 426.176392, height, 515.666748)
162guard:walkTo( 500.031677, height, 515.197266)
163guard:walkTo( 551.294250, height, 514.430237)
164guard:walkTo( 604.974731, height, 515.106323)
165guard:walkTo( 651.117920, height, 516.026550)
166guard:walkTo( 664.581909, height, 516.295227)
167guard:walkTo( 683.122803, height, 516.665100)
168guard:walkTo( 694.547485, height, 516.892944)
169guard:walkTo( 704.408569, height, 517.089539)
170guard:walkTo( 714.413208, height, 517.289185)
171guard:walkTo( 739.045288, height, 515.581970)
172guard:walkTo( 763.904541, height, 497.281738)
173guard:walkTo( 767.672791, height, 481.974457)
174guard:walkTo( 769.436951, height, 468.704559)
175guard:walkTo( 770.490967, height, 453.283386)
176guard:walkTo( 771.185303, height, 435.960114)
177guard:walkTo( 771.952820, height, 379.502045)
178guard:walkTo( 771.938293, height, 310.049042)
179guard:walkTo( 772.514526, height, 231.579498)
180guard:walkTo( 773.601074, height, 135.177933)
181guard:walkTo( 773.790771, height, 50.675163)
182guard:walkTo( 773.316162, height, -36.961666)
183guard:walkTo( 772.885986, height, -116.407944)
184guard:walkTo( 772.841309, height, -124.651726)
185guard:walkTo( 772.491333, height, -137.742279)
186guard:walkTo( 770.644775, height, -153.245926)
187guard:walkTo( 768.774414, height, -163.767120)
188guard:walkTo( 766.336426, height, -174.224228)
189guard:walkTo( 762.794128, height, -187.312271)
190guard:walkTo( 733.548279, height, -274.004791)
191guard:walkTo( 713.113647, height, -329.657959)
192guard:walkTo( 694.801819, height, -379.530243)
193guard:walkTo( 681.276062, height, -422.047028)
194guard:walkTo( 672.579102, height, -458.540985)
195guard:walkTo( 670.843384, height, -465.824615)
196guard:walkTo( 669.948364, height, -480.910645)
197guard:walkTo( 669.361511, height, -493.648529)
198guard:walkTo( 669.686829, height, -501.598572)
199guard:walkTo( 674.055664, height, -582.077637)
200guard:walkTo( 676.046387, height, -630.403809)
201guard:walkTo( 677.839050, height, -674.209534)
202guard:walkTo( 680.754944, height, -765.965515)
203guard:walkTo( 681.034180, height, -803.351135)
204guard:walkTo( 680.088806, height, -844.069031)
205guard:walkTo( 677.801514, height, -899.952148)
206guard:walkTo( 675.205627, height, -950.496460)
207guard:walkTo( 672.847778, height, -996.413574)
208guard:walkTo( 676.204041, height, -1043.556274)
209guard:walkTo( 691.304382, height, -1088.596558)
210guard:walkTo( 705.101318, height, -1128.320312)
211guard:walkTo( 720.476013, height, -1164.364380)
212guard:walkTo( 729.216797, height, -1183.948364)
213guard:walkTo( 740.145203, height, -1212.598267)
214guard:walkTo( 746.547363, height, -1238.340576)
215guard:walkTo( 756.866211, height, -1280.605347)
216guard:walkTo( 763.380554, height, -1314.622314)
217guard:walkTo( 768.731506, height, -1347.977539)
218guard:walkTo( 772.446655, height, -1381.641479)
219guard:walkTo( 772.721069, height, -1421.184937)
220guard:walkTo( 772.414734, height, -1457.349121)
221guard:walkTo( 772.803284, height, -1489.560913)
222
223hangarRouteProgrammed  = true
224end
225
226if guard:finalGoalReached() then
227return true
228end
229
230return false
231end
232
233
234function waveToSpaceship(timestep)
235
236end
237
238
239function tick(timestep)
240--io.write("Guard called \n")
241observePlayer()
242
243if walkingRouteOne then
244walkingRouteOne = walkRouteOne(timestep)
245end
246
247if not walkingRouteOne and not exitPositionReached then
248exitPositionReached = goToExitPosition(timestep)
249end
250
251if not hangarReached and exitPositionReached then
252hangarReached = goToHangar(timestep)
253end
254
255if hangarReached then
256waveToSpaceship(timestep)
257end
258
259return false
260end
261 
Note: See TracBrowser for help on using the repository browser.