1 | -- Global Variables |
---|
2 | allOk = true |
---|
3 | cellReached = false |
---|
4 | guidePositionReached = false |
---|
5 | prisonerReachedLock = false |
---|
6 | hangarReached = false |
---|
7 | |
---|
8 | |
---|
9 | -- Returns the distance between (x1,x2,x3) and (y1,y2,y3) |
---|
10 | function dist( x1,x2,x3, y1,y2,y3 ) |
---|
11 | return math.sqrt( (x1-y1)^2 + (x2-y2)^2 + (x3-y3)^2 ) |
---|
12 | end |
---|
13 | |
---|
14 | |
---|
15 | function observeGuard() |
---|
16 | guardX = guard:getAbsCoorX() |
---|
17 | guardY = guard:getAbsCoorY() |
---|
18 | guardZ = guard:getAbsCoorZ() |
---|
19 | |
---|
20 | if dist( guardX,guardY,guardZ,35.48, 29, 191.28 ) < 60 then |
---|
21 | allOk = false |
---|
22 | end |
---|
23 | |
---|
24 | end |
---|
25 | |
---|
26 | function observePrisoner() |
---|
27 | |
---|
28 | prisonerX = Prisoner:getAbsCoorX() |
---|
29 | prisonerY = Prisoner:getAbsCoorY() |
---|
30 | prisonerZ = Prisoner:getAbsCoorZ() |
---|
31 | |
---|
32 | if dist( prisonerX,prisonerY,prisonerZ,161.76,49,358.87 ) < 60 then |
---|
33 | prisonerReachedLock = true |
---|
34 | end |
---|
35 | |
---|
36 | end |
---|
37 | |
---|
38 | cellProgrammed = false |
---|
39 | function goToCell(timestep) |
---|
40 | |
---|
41 | if not cellProgrammed then |
---|
42 | --io.write("Guard called \n") |
---|
43 | secondguard:walkTo(-132, 29, 238.381805) |
---|
44 | secondguard:walkTo(-138.41, 29, 275.25) |
---|
45 | secondguard:walkTo(-143.70, 29, 275.35) |
---|
46 | secondguard:walkTo(-149.10, 29, 226.66) |
---|
47 | secondguard:walkTo(-149.10, 29, 196.83) |
---|
48 | secondguard:walkTo(-145.82, 29, 189.74) |
---|
49 | secondguard:walkTo(-138.48, 29, 184.28) |
---|
50 | secondguard:walkTo(35.48, 29, 191.28) |
---|
51 | secondguard:runTo(102, 29, 203.28) |
---|
52 | secondguard:runTo(164, 29, 245.28) |
---|
53 | |
---|
54 | cellProgrammed = true |
---|
55 | end |
---|
56 | |
---|
57 | if secondguard:finalGoalReached() then |
---|
58 | return true |
---|
59 | end |
---|
60 | |
---|
61 | return false |
---|
62 | end |
---|
63 | |
---|
64 | guideProgrammed = false |
---|
65 | function goToGuidePosition(timestep) |
---|
66 | |
---|
67 | if not guideProgrammed then |
---|
68 | --io.write("Guard called \n") |
---|
69 | secondguard:walkTo(-132, 29, 238.381805) |
---|
70 | secondguard:walkTo(-138.41, 29, 275.25) |
---|
71 | secondguard:walkTo(-143.70, 29, 275.35) |
---|
72 | secondguard:walkTo(-149.10, 29, 226.66) |
---|
73 | secondguard:walkTo(-149.10, 29, 196.83) |
---|
74 | secondguard:walkTo(-145.82, 29, 189.74) |
---|
75 | secondguard:walkTo(-138.48, 29, 184.28) |
---|
76 | secondguard:walkTo(35.48, 29, 191.28) |
---|
77 | secondguard:runTo(102, 29, 203.28) |
---|
78 | secondguard:runTo(164, 29, 245.28) |
---|
79 | |
---|
80 | guideProgrammed = true |
---|
81 | end |
---|
82 | |
---|
83 | if secondguard:finalGoalReached() then |
---|
84 | return true |
---|
85 | end |
---|
86 | |
---|
87 | return false |
---|
88 | end |
---|
89 | |
---|
90 | hangarProgrammed = false |
---|
91 | function goToHangar(timestep) |
---|
92 | |
---|
93 | if not hangarProgrammed then |
---|
94 | --io.write("Guard called \n") |
---|
95 | secondguard:walkTo(-132, 29, 238.381805) |
---|
96 | secondguard:walkTo(-138.41, 29, 275.25) |
---|
97 | secondguard:walkTo(-143.70, 29, 275.35) |
---|
98 | secondguard:walkTo(-149.10, 29, 226.66) |
---|
99 | secondguard:walkTo(-149.10, 29, 196.83) |
---|
100 | secondguard:walkTo(-145.82, 29, 189.74) |
---|
101 | secondguard:walkTo(-138.48, 29, 184.28) |
---|
102 | secondguard:walkTo(35.48, 29, 191.28) |
---|
103 | secondguard:runTo(102, 29, 203.28) |
---|
104 | secondguard:runTo(164, 29, 245.28) |
---|
105 | |
---|
106 | hangarProgrammed = true |
---|
107 | end |
---|
108 | |
---|
109 | if secondguard:finalGoalReached() then |
---|
110 | return true |
---|
111 | end |
---|
112 | |
---|
113 | return false |
---|
114 | |
---|
115 | end |
---|
116 | |
---|
117 | function tick(timestep) |
---|
118 | --io.write("Secondguard called \n") |
---|
119 | |
---|
120 | observePrisoner() |
---|
121 | |
---|
122 | if not allOk then |
---|
123 | cellReached = goToCell(timestep) |
---|
124 | end |
---|
125 | |
---|
126 | if cellReached and not guidePositionReached then |
---|
127 | guidePositionReached = goToGuidePosition(timestep) |
---|
128 | end |
---|
129 | |
---|
130 | if guidePositionReached and prisonerReachedLock then |
---|
131 | hangarReached = goToHangar(timestep) |
---|
132 | end |
---|
133 | |
---|
134 | if hangarReached then |
---|
135 | return true |
---|
136 | end |
---|
137 | |
---|
138 | return false |
---|
139 | end |
---|