Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/single_player_map/scripts/prisoner.lua @ 3959

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

continued implementation…

File size: 4.2 KB
Line 
1cellDoorOpened = false
2walkinCellFinished = false
3cellExitReached = false
4exitReached = false
5hangarReached = false
6spaceShipReached = false
7spaceShipEntered = false
8playerInLock = false
9
10randTime = 0
11
12function observeGuard()
13guardX = guard:getAbsCoorX()
14guardY = guard:getAbsCoorY()
15guardZ = guard:getAbsCoorZ()
16
17if dist( guardX,guardY,guardZ,35.48, 29, 191.28 ) < 60 then
18cellDoorOpened = true
19end
20
21end
22
23function observePlayer()
24playerX = Player:getAbsCoorX()
25playerY = Player:getAbsCoorY()
26playerZ = Player:getAbsCoorZ()
27
28if dist( playerX,playerY,playerZ,161.76,49,358.87 ) < 60 then
29playerInLock = true
30end
31
32walkProgrammed = false
33exitProgrammed = false
34function walkInCell(timestep)
35
36if not walkProgrammed then
37--io.write("Guard called \n")
38prisoner:walkTo(-132, 29, 238.381805)
39prisoner:walkTo(-138.41, 29, 275.25)
40prisoner:walkTo(-143.70, 29, 275.35)
41prisoner:walkTo(-149.10, 29, 226.66)
42prisoner:walkTo(-149.10, 29, 196.83)
43prisoner:walkTo(-145.82, 29, 189.74)
44prisoner:walkTo(-138.48, 29, 184.28)
45prisoner:walkTo(35.48, 29, 191.28)
46prisoner:runTo(102, 29, 203.28)
47prisoner:runTo(164, 29, 245.28)
48
49walkProgrammed = true
50end
51
52if cellDoorOpened then
53
54 if randTime == 0 then
55 randTime = 30 * math.random()
56 else
57 randTime = randTime - timestep
58 end
59
60 if randTime < 0 then
61 -- goto cellexit
62  if not exitProgrammed then
63   prisoner:walkTo(-132, 29, 238.381805)
64   prisoner:walkTo(-138.41, 29, 275.25)
65   prisoner:walkTo(-143.70, 29, 275.35)
66   prisoner:walkTo(-149.10, 29, 226.66)
67   prisoner:walkTo(-149.10, 29, 196.83)
68   prisoner:walkTo(-145.82, 29, 189.74)
69   prisoner:walkTo(-138.48, 29, 184.28)
70   prisoner:walkTo(35.48, 29, 191.28)
71   prisoner:runTo(102, 29, 203.28)
72   prisoner:runTo(164, 29, 245.28)
73
74   exitProgrammed = true
75  end
76
77  if guard:finalGoalReached() then
78   return true
79  end
80
81 end 
82
83return false
84end
85
86
87return false
88
89end
90
91
92gotoExitProgrammed = false
93function goToExit(timestep)
94-- do not forget to make him wait until the player triggeres the trip to the hangar
95if not gotoExitProgrammed and playerInLock then
96prisoner:walkTo(-132, 29, 238.381805)
97prisoner:walkTo(-138.41, 29, 275.25)
98prisoner:walkTo(-143.70, 29, 275.35)
99prisoner:walkTo(-149.10, 29, 226.66)
100prisoner:walkTo(-149.10, 29, 196.83)
101prisoner:walkTo(-145.82, 29, 189.74)
102prisoner:walkTo(-138.48, 29, 184.28)
103prisoner:walkTo(35.48, 29, 191.28)
104prisoner:runTo(102, 29, 203.28)
105prisoner:runTo(164, 29, 245.28)
106
107gotoExitProgrammed = true
108end
109
110if prisoner:finalGoalReached() then
111   return true
112end
113
114return false
115end
116
117hangarRouteProgrammed = false
118function goToHangar(timestep)
119
120if not hangarRouteProgrammed then
121prisoner:walkTo(-132, 29, 238.381805)
122prisoner:walkTo(-138.41, 29, 275.25)
123prisoner:walkTo(-143.70, 29, 275.35)
124prisoner:walkTo(-149.10, 29, 226.66)
125prisoner:walkTo(-149.10, 29, 196.83)
126prisoner:walkTo(-145.82, 29, 189.74)
127prisoner:walkTo(-138.48, 29, 184.28)
128prisoner:walkTo(35.48, 29, 191.28)
129prisoner:runTo(102, 29, 203.28)
130prisoner:runTo(164, 29, 245.28)
131
132hangarRouteProgrammed = true
133end
134
135if prisoner:finalGoalReached() then
136   return true
137end
138
139return false
140
141end
142
143spaceshipRouteProgrammed = false
144function goToSpaceship(timestep)
145
146if not spaceshipRouteProgrammed then
147prisoner:walkTo(-132, 29, 238.381805)
148prisoner:walkTo(-138.41, 29, 275.25)
149prisoner:walkTo(-143.70, 29, 275.35)
150prisoner:walkTo(-149.10, 29, 226.66)
151prisoner:walkTo(-149.10, 29, 196.83)
152prisoner:walkTo(-145.82, 29, 189.74)
153prisoner:walkTo(-138.48, 29, 184.28)
154prisoner:walkTo(35.48, 29, 191.28)
155prisoner:runTo(102, 29, 203.28)
156prisoner:runTo(164, 29, 245.28)
157
158spaceshipRouteProgrammed = true
159end
160
161if prisoner:finalGoalReached() then
162   return true
163end
164
165return false
166
167end
168
169
170function enterSpaceship(timestep)
171
172return false
173end
174
175
176
177function tick(timestep)
178
179--io.write("Prisoner called \n")
180
181 observeGuard()
182 observePlayer()
183
184
185if not cellDoorOpend then
186walkinCellFinished = walkInCell(timestep)
187end
188
189if walkinCellFinished and not exitReached then
190exitReached = goToExit(timestep)
191end
192
193if exitReached and not hangarReached then
194hangarReached = goToHangar(timestep)
195end
196
197if hangarReached and not spaceShipReached then 
198spaceShipReached = goToSpaceship(timestep)
199end
200
201if spaceShipReached and not spaceShipEntered then
202spaceShipEntered = enterSpaceship(timestep)
203end
204
205if spaceShipEntered then
206return true
207end
208
209return false
210end
Note: See TracBrowser for help on using the repository browser.