[3945] | 1 | -- Global Variables |
---|
| 2 | allOk = true |
---|
[3951] | 3 | cellReached = false |
---|
[3945] | 4 | guidePositionReached = false |
---|
| 5 | prisonerReachedLock = false |
---|
| 6 | hangarReached = false |
---|
| 7 | |
---|
[3946] | 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 | |
---|
[3951] | 15 | function observeGuard() |
---|
| 16 | guardX = guard:getAbsCoorX() |
---|
| 17 | guardY = guard:getAbsCoorY() |
---|
| 18 | guardZ = guard:getAbsCoorZ() |
---|
| 19 | |
---|
[3954] | 20 | if dist( guardX,guardY,guardZ,35.48, 29, 191.28 ) < 60 then |
---|
[3945] | 21 | allOk = false |
---|
| 22 | end |
---|
| 23 | |
---|
[3951] | 24 | end |
---|
| 25 | |
---|
[3946] | 26 | function observePrisoner() |
---|
[3945] | 27 | |
---|
[3951] | 28 | prisonerX = Prisoner:getAbsCoorX() |
---|
| 29 | prisonerY = Prisoner:getAbsCoorY() |
---|
| 30 | prisonerZ = Prisoner:getAbsCoorZ() |
---|
[3946] | 31 | |
---|
[3951] | 32 | if dist( prisonerX,prisonerY,prisonerZ,161.76,49,358.87 ) < 60 then |
---|
| 33 | prisonerReachedLock = true |
---|
[3945] | 34 | end |
---|
| 35 | |
---|
[3951] | 36 | end |
---|
[3945] | 37 | |
---|
[3954] | 38 | cellProgrammed = false |
---|
[3951] | 39 | function goToCell(timestep) |
---|
| 40 | |
---|
[3954] | 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 | |
---|
[3945] | 61 | return false |
---|
| 62 | end |
---|
| 63 | |
---|
[3954] | 64 | guideProgrammed = false |
---|
[3945] | 65 | function goToGuidePosition(timestep) |
---|
| 66 | |
---|
[3954] | 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 | |
---|
[3945] | 87 | return false |
---|
| 88 | end |
---|
| 89 | |
---|
[3954] | 90 | hangarProgrammed = false |
---|
[3945] | 91 | function goToHangar(timestep) |
---|
| 92 | |
---|
[3954] | 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 | |
---|
[3945] | 113 | return false |
---|
[3954] | 114 | |
---|
[3945] | 115 | end |
---|
| 116 | |
---|
| 117 | function tick(timestep) |
---|
[3946] | 118 | --io.write("Secondguard called \n") |
---|
| 119 | |
---|
| 120 | observePrisoner() |
---|
[3945] | 121 | |
---|
| 122 | if not allOk then |
---|
[3951] | 123 | cellReached = goToCell(timestep) |
---|
[3945] | 124 | end |
---|
| 125 | |
---|
[3951] | 126 | if cellReached and not guidePositionReached then |
---|
[3945] | 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 |
---|