[4051] | 1 | -- Get objects from orxonox |
---|
| 2 | thisscript:addObject("Claw", "spaceshipclaw") |
---|
| 3 | thisscript:addObject("RepairStation", "repair") |
---|
| 4 | thisscript:addObject("FPSPlayer", "Player") |
---|
| 5 | thisscript:addObject("SpaceShip", "spaceship") |
---|
[4070] | 6 | thisscript:addObject("GenericNPC", "mechanic") |
---|
[4100] | 7 | thisscript:addObject("GenericNPC", "mechanic2") |
---|
[3947] | 8 | |
---|
[4056] | 9 | -- Global Variables |
---|
| 10 | playerEnteredSpaceShip = false |
---|
| 11 | playerReachedTrigger = false |
---|
| 12 | spaceshipOnPad = false |
---|
| 13 | spaceshipLaunchReady = false |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | -- Returns the distance between (x1,x2,x3) and (y1,y2,y3) |
---|
| 17 | function dist( x1,x2,x3, y1,y2,y3 ) |
---|
| 18 | |
---|
| 19 | return math.sqrt( (x1-y1)^2 + (x2-y2)^2 + (x3-y3)^2 ) |
---|
| 20 | |
---|
| 21 | end |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | function observePlayer() |
---|
| 26 | |
---|
[4070] | 27 | --playerEnteredSpaceShip = spaceship:hasPlayer() |
---|
[4056] | 28 | |
---|
| 29 | playerX = Player:getAbsCoorX() |
---|
| 30 | playerY = Player:getAbsCoorY() |
---|
| 31 | playerZ = Player:getAbsCoorZ() |
---|
| 32 | |
---|
[4070] | 33 | if dist( playerX,playerY,playerZ,678.946838, -11.959779, -920.512634 ) < 200 then |
---|
[4056] | 34 | playerReachedTrigger = true |
---|
| 35 | end |
---|
| 36 | |
---|
| 37 | end |
---|
| 38 | |
---|
| 39 | |
---|
[4070] | 40 | |
---|
| 41 | |
---|
| 42 | |
---|
[4100] | 43 | mprogramRoute = true |
---|
[4070] | 44 | mheight = 5 |
---|
| 45 | function mechanicMove(timestep) |
---|
[4100] | 46 | if mprogramRoute then |
---|
[4070] | 47 | |
---|
| 48 | mechanic:walkTo( 991.192261, mheight, -1878.394287) |
---|
| 49 | mechanic:walkTo( 976.976685, mheight, -1879.182129) |
---|
| 50 | mechanic:walkTo( 963.752625, mheight, -1880.202881) |
---|
| 51 | mechanic:walkTo( 948.094543, mheight, -1880.980713) |
---|
| 52 | mechanic:walkTo( 931.008606, mheight, -1880.974854) |
---|
| 53 | mechanic:walkTo( 917.888428, mheight, -1880.832764) |
---|
| 54 | mechanic:walkTo( 901.552368, mheight, -1880.655762) |
---|
| 55 | mechanic:walkTo( 886.475220, mheight, -1880.522949) |
---|
| 56 | mechanic:walkTo( 872.041504, mheight, -1880.545410) |
---|
| 57 | mechanic:walkTo( 851.380249, mheight, -1880.577637) |
---|
| 58 | mechanic:walkTo( 840.637512, mheight, -1880.594238) |
---|
| 59 | mechanic:walkTo( 828.564941, mheight, -1880.489868) |
---|
| 60 | mechanic:walkTo( 811.580322, mheight, -1880.085205) |
---|
| 61 | mechanic:walkTo( 801.953003, mheight, -1880.036377) |
---|
| 62 | mechanic:walkTo( 784.801086, mheight, -1880.280762) |
---|
| 63 | mechanic:walkTo( 774.514343, mheight, -1880.380005) |
---|
| 64 | mechanic:walkTo( 762.351746, mheight, -1880.248779) |
---|
| 65 | mechanic:walkTo( 750.737549, mheight, -1880.123413) |
---|
| 66 | mechanic:walkTo( 739.186890, mheight, -1879.999023) |
---|
| 67 | mechanic:walkTo( 728.210022, mheight, -1879.880371) |
---|
| 68 | mechanic:walkTo( 717.243835, mheight, -1879.761719) |
---|
| 69 | mechanic:walkTo( 708.253235, mheight, -1879.649048) |
---|
| 70 | mechanic:walkTo( 695.825867, mheight, -1877.611938) |
---|
| 71 | mechanic:walkTo( 687.077820, mheight, -1869.800659) |
---|
| 72 | mechanic:walkTo( 683.886963, mheight, -1859.888062) |
---|
| 73 | mechanic:walkTo( 685.589905, mheight, -1844.102051) |
---|
| 74 | mechanic:walkTo( 686.333069, mheight, -1837.212524) |
---|
| 75 | mechanic:walkTo( 687.256042, mheight, -1828.656860) |
---|
| 76 | mechanic:walkTo( 688.759583, mheight, -1820.024048) |
---|
| 77 | mechanic:walkTo( 690.621216, mheight, -1809.834595) |
---|
| 78 | mechanic:walkTo( 692.045593, mheight, -1803.566772) |
---|
| 79 | mechanic:walkTo( 695.021851, mheight, -1795.320923) |
---|
| 80 | mechanic:walkTo( 703.956360, mheight, -1789.028931) |
---|
| 81 | mechanic:walkTo( 711.400574, mheight, -1785.378418) |
---|
| 82 | mechanic:walkTo( 720.236267, mheight, -1782.750977) |
---|
| 83 | mechanic:walkTo( 741.346130, mheight, -1786.131836) |
---|
| 84 | mechanic:walkTo( 744.505798, mheight, -1788.214111) |
---|
| 85 | mechanic:walkTo( 753.788513, mheight, -1796.320557) |
---|
| 86 | mechanic:walkTo( 760.480408, mheight, -1804.107788) |
---|
| 87 | mechanic:walkTo( 765.918274, mheight, -1811.952393) |
---|
| 88 | mechanic:walkTo( 772.114990, mheight, -1823.565674) |
---|
| 89 | mechanic:walkTo( 776.130737, mheight, -1830.713989) |
---|
| 90 | mechanic:walkTo( 781.833313, mheight, -1836.770996) |
---|
| 91 | mechanic:walkTo( 796.051880, mheight, -1843.499512) |
---|
| 92 | mechanic:walkTo( 805.178101, mheight, -1844.844116) |
---|
| 93 | mechanic:walkTo( 816.733154, mheight, -1846.198608) |
---|
| 94 | mechanic:walkTo( 830.296326, mheight, -1844.374146) |
---|
| 95 | mechanic:walkTo( 841.234680, mheight, -1841.184814) |
---|
| 96 | mechanic:walkTo( 853.356201, mheight, -1837.650391) |
---|
| 97 | mechanic:walkTo( 866.242981, mheight, -1833.892944) |
---|
| 98 | mechanic:walkTo( 877.006836, mheight, -1830.820923) |
---|
| 99 | mechanic:walkTo( 889.236816, mheight, -1828.092773) |
---|
| 100 | mechanic:walkTo( 897.856689, mheight, -1826.204346) |
---|
| 101 | mechanic:walkTo( 909.685486, mheight, -1823.613037) |
---|
| 102 | mechanic:walkTo( 922.058777, mheight, -1819.907227) |
---|
| 103 | mechanic:walkTo( 933.861328, mheight, -1814.044800) |
---|
| 104 | mechanic:walkTo( 943.290588, mheight, -1809.960205) |
---|
| 105 | mechanic:walkTo( 952.188293, mheight, -1806.317261) |
---|
| 106 | mechanic:walkTo( 985.450745, mheight, -1800.297729) |
---|
| 107 | mechanic:walkTo( 1000.339722, mheight, -1800.916626) |
---|
| 108 | mechanic:walkTo( 1013.447937, mheight, -1802.642090) |
---|
| 109 | mechanic:walkTo( 1022.703430, mheight, -1808.694946) |
---|
| 110 | mechanic:walkTo( 1030.242554, mheight, -1821.859253) |
---|
| 111 | mechanic:walkTo( 1030.063354, mheight, -1839.935547) |
---|
| 112 | mechanic:walkTo( 1025.804932, mheight, -1864.135986) |
---|
| 113 | mechanic:walkTo( 1019.079651, mheight, -1878.196777) |
---|
| 114 | |
---|
[4100] | 115 | mprogramRoute = false |
---|
[4070] | 116 | end |
---|
| 117 | |
---|
| 118 | if mechanic:finalGoalReached() then |
---|
[4100] | 119 | mprogramRoute = true |
---|
[4070] | 120 | end |
---|
| 121 | |
---|
| 122 | end |
---|
| 123 | |
---|
[4100] | 124 | mtprogramRoute = true |
---|
| 125 | mtheight = 5 |
---|
| 126 | waittime = 0 |
---|
| 127 | waiting = false |
---|
| 128 | function mechanictMove(timestep) |
---|
| 129 | if mtprogramRoute then |
---|
| 130 | mechanic2:walkTo( 1564.473999, mtheight, -1923.821533) |
---|
| 131 | mechanic2:walkTo( 1556.049927, mtheight, -1916.359009) |
---|
| 132 | mechanic2:walkTo( 1550.970581, mtheight, -1913.087524) |
---|
| 133 | mechanic2:walkTo( 1542.345459, mtheight, -1912.611938) |
---|
| 134 | mechanic2:walkTo( 1534.643677, mtheight, -1912.361816) |
---|
| 135 | mechanic2:walkTo( 1524.490845, mtheight, -1912.074097) |
---|
| 136 | mechanic2:walkTo( 1516.120605, mtheight, -1912.511475) |
---|
| 137 | mechanic2:walkTo( 1508.607788, mtheight, -1912.904175) |
---|
| 138 | mechanic2:walkTo( 1498.452759, mtheight, -1913.434814) |
---|
| 139 | mechanic2:walkTo( 1492.513916, mtheight, -1913.744995) |
---|
| 140 | mechanic2:walkTo( 1483.056274, mtheight, -1914.239136) |
---|
| 141 | mechanic2:walkTo( 1471.428711, mtheight, -1916.435303) |
---|
| 142 | mechanic2:walkTo( 1460.068359, mtheight, -1916.473022) |
---|
| 143 | mechanic2:walkTo( 1451.006592, mtheight, -1913.691772) |
---|
| 144 | mechanic2:walkTo( 1444.585938, mtheight, -1911.533691) |
---|
| 145 | mechanic2:walkTo( 1439.008423, mtheight, -1909.659058) |
---|
| 146 | mechanic2:walkTo( 1421.636230, mtheight, -1915.466553) |
---|
| 147 | mechanic2:walkTo( 1420.582275, mtheight, -1926.693970) |
---|
| 148 | mechanic2:walkTo( 1422.506714, mtheight, -1934.938232) |
---|
| 149 | mechanic2:walkTo( 1430.749023, mtheight, -1942.431519) |
---|
| 150 | mechanic2:walkTo( 1440.773315, mtheight, -1948.152832) |
---|
| 151 | mechanic2:walkTo( 1452.532227, mtheight, -1950.169800) |
---|
| 152 | mechanic2:walkTo( 1465.584961, mtheight, -1949.407959) |
---|
| 153 | mechanic2:walkTo( 1475.635254, mtheight, -1948.756226) |
---|
| 154 | mechanic2:walkTo( 1481.961548, mtheight, -1948.346069) |
---|
| 155 | mechanic2:walkTo( 1495.564575, mtheight, -1947.588257) |
---|
| 156 | mechanic2:walkTo( 1505.660156, mtheight, -1947.679077) |
---|
| 157 | mechanic2:walkTo( 1514.055542, mtheight, -1947.901245) |
---|
| 158 | mechanic2:walkTo( 1523.532959, mtheight, -1948.351440) |
---|
| 159 | mechanic2:walkTo( 1537.855347, mtheight, -1949.461914) |
---|
| 160 | mechanic2:walkTo( 1545.510498, mtheight, -1950.162720) |
---|
| 161 | mechanic2:walkTo( 1553.132935, mtheight, -1950.860718) |
---|
| 162 | mechanic2:walkTo( 1556.371460, mtheight, -1951.157104) |
---|
| 163 | mechanic2:walkTo( 1563.450806, mtheight, -1951.804932) |
---|
| 164 | mechanic2:walkTo( 1572.594116, mtheight, -1952.320679) |
---|
| 165 | mechanic2:walkTo( 1582.691772, mtheight, -1950.470459) |
---|
| 166 | mechanic2:walkTo( 1589.872681, mtheight, -1929.683105) |
---|
| 167 | mechanic2:walkTo( 1587.794922, mtheight, -1922.749756) |
---|
| 168 | mechanic2:walkTo( 1582.800171, mtheight, -1917.671021) |
---|
| 169 | mechanic2:walkTo( 1573.449951, mtheight, -1915.750854) |
---|
| 170 | mechanic2:walkTo( 1564.055908, mtheight, -1914.986328) |
---|
| 171 | mtprogramRoute = false |
---|
| 172 | end |
---|
[4070] | 173 | |
---|
[4100] | 174 | mechanic2X = mechanic2:getAbsCoorX() |
---|
| 175 | mechanic2Y = mechanic2:getAbsCoorY() |
---|
| 176 | mechanic2Z = mechanic2:getAbsCoorZ() |
---|
[4070] | 177 | |
---|
[4100] | 178 | if dist(mechanic2X,mechanic2Y,mechanic2Z,1435.444824, mtheight, -1916.463013) < 10 and not waiting then |
---|
| 179 | mechanic2:stop() |
---|
| 180 | waittime = 5 |
---|
| 181 | --io.write("mechanic2 stoped \n") |
---|
| 182 | waiting = true |
---|
| 183 | end |
---|
[4070] | 184 | |
---|
[4100] | 185 | if waittime >= 0 and waiting then |
---|
| 186 | waittime = waittime - timestep |
---|
| 187 | --io.write(waittime,"\n") |
---|
| 188 | if waittime < 0 then |
---|
| 189 | --io.write("mechanic2 finished waiting\n") |
---|
| 190 | mechanic2:resume() |
---|
| 191 | end |
---|
| 192 | end |
---|
[4070] | 193 | |
---|
[4100] | 194 | if dist(mechanic2X,mechanic2Y,mechanic2Z,1564.473999, mtheight, -1923.821533) < 10 and waiting then |
---|
| 195 | waiting = false |
---|
| 196 | end |
---|
[4070] | 197 | |
---|
| 198 | |
---|
[4100] | 199 | if mechanic2:finalGoalReached() then |
---|
| 200 | mtprogramRoute = true |
---|
| 201 | end |
---|
[4070] | 202 | |
---|
[4100] | 203 | end |
---|
[4070] | 204 | |
---|
[4100] | 205 | |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | |
---|
| 211 | |
---|
[4056] | 212 | positionReached = false |
---|
| 213 | spaceShipReleased = false |
---|
| 214 | function moveToLaunchSite(timestep) |
---|
| 215 | |
---|
| 216 | if not positionReached then |
---|
[4070] | 217 | dx = 10 * timestep |
---|
[4056] | 218 | dy = 0 * timestep |
---|
[4070] | 219 | dz = 0* timestep |
---|
[4056] | 220 | end |
---|
| 221 | |
---|
| 222 | if not spaceShipReleased and positionReached then |
---|
| 223 | dx = 0 * timestep |
---|
[4070] | 224 | dy = 10 * timestep |
---|
[4056] | 225 | dz = 0 * timestep |
---|
| 226 | end |
---|
| 227 | |
---|
| 228 | if positionReached and spaceShipReleased then |
---|
| 229 | dx = 0 * timestep |
---|
| 230 | dy = 1 * timestep |
---|
| 231 | dz = 0 * timestep |
---|
| 232 | end |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | if spaceshipOnPad then |
---|
| 236 | |
---|
| 237 | if not spaceShipReleased then |
---|
[4070] | 238 | --spaceshipclaw:playAnimation(1,1) |
---|
[4100] | 239 | --io.write("release spaceship\n") |
---|
[4056] | 240 | spaceShipReleased = true |
---|
[4070] | 241 | playerEnteredSpaceShip = true |
---|
[4056] | 242 | end |
---|
| 243 | |
---|
[4070] | 244 | --if clawY > 100 then |
---|
[4056] | 245 | spaceshipLaunchReady = true |
---|
[4070] | 246 | --end |
---|
[4056] | 247 | |
---|
| 248 | end |
---|
| 249 | |
---|
| 250 | |
---|
| 251 | -- set new coordinates |
---|
[4070] | 252 | --clawX = claw:getAbsCoorX() |
---|
| 253 | --clawY = claw:getAbsCoorY() |
---|
| 254 | --clawZ = claw:getAbsCoorZ() |
---|
[4056] | 255 | |
---|
[4070] | 256 | --claw:setAbsCoor(clawX + dx, clawY + dy, clawZ + dz) |
---|
| 257 | spaceshipX = spaceship:getAbsCoorX() |
---|
| 258 | spaceshipY = spaceship:getAbsCoorY() |
---|
| 259 | spaceshipZ = spaceship:getAbsCoorZ() |
---|
[4056] | 260 | |
---|
[4070] | 261 | spaceship:setAbsCoor(spaceshipX + dx, spaceshipY + dy, spaceshipZ + dz) |
---|
[4056] | 262 | |
---|
| 263 | |
---|
[4070] | 264 | |
---|
| 265 | --if dist( clawX,clawY,clawZ,1020.025024, -11.959781, -1721.614380 ) < 60 then |
---|
| 266 | if dist( spaceshipX,spaceshipY,spaceshipZ,1020.025024, -11.959781, -1721.614380 ) < 60 then |
---|
[4056] | 267 | positionReached = true |
---|
| 268 | end |
---|
| 269 | |
---|
| 270 | |
---|
[4070] | 271 | --if dist( clawX,clawY,clawZ,167.361526,29,483.163818 ) < 60 then |
---|
| 272 | if spaceshipY > 10 then |
---|
[4056] | 273 | spaceshipOnPad = true |
---|
| 274 | end |
---|
| 275 | |
---|
| 276 | |
---|
[4070] | 277 | end |
---|
[4056] | 278 | |
---|
| 279 | hoverPosReached = false |
---|
| 280 | function launchSpaceShip(timestep) |
---|
| 281 | |
---|
| 282 | if not hoverPosReached then |
---|
| 283 | dx = 0 * timestep |
---|
| 284 | dy = 1 * timestep |
---|
| 285 | dz = 0 * timestep |
---|
| 286 | else |
---|
[4070] | 287 | dx = 200 * timestep |
---|
[4056] | 288 | dy = 0 * timestep |
---|
[4070] | 289 | dz = 0 * timestep |
---|
[4056] | 290 | end |
---|
| 291 | |
---|
| 292 | spaceshipX = spaceship:getAbsCoorX() |
---|
| 293 | spaceshipY = spaceship:getAbsCoorY() |
---|
| 294 | spaceshipZ = spaceship:getAbsCoorZ() |
---|
| 295 | |
---|
| 296 | spaceship:setAbsCoor(spaceshipX + dx, spaceshipY + dy, spaceshipZ + dz) |
---|
| 297 | |
---|
[4070] | 298 | if spaceshipY > 15 then |
---|
[4056] | 299 | hoverPosReached = true |
---|
| 300 | end |
---|
| 301 | |
---|
| 302 | end |
---|
| 303 | |
---|
| 304 | |
---|
[3947] | 305 | function tick(timestep) |
---|
[4070] | 306 | |
---|
[4056] | 307 | observePlayer() |
---|
[4070] | 308 | mechanicMove(timestep) |
---|
[4100] | 309 | mechanictMove(timestep) |
---|
[4056] | 310 | |
---|
[4070] | 311 | if playerReachedTrigger and not spaceshipLaunchReady then |
---|
| 312 | moveToLaunchSite(timestep) |
---|
[4056] | 313 | end |
---|
| 314 | |
---|
| 315 | if spaceshipLaunchReady then |
---|
[4070] | 316 | launchSpaceShip(timestep) |
---|
[4056] | 317 | end |
---|
| 318 | |
---|
| 319 | |
---|
[3947] | 320 | return false |
---|
| 321 | end |
---|