Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

continued implementation

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