[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") |
---|
[3947] | 7 | |
---|
[4056] | 8 | -- Global Variables |
---|
| 9 | playerEnteredSpaceShip = false |
---|
| 10 | playerReachedTrigger = false |
---|
| 11 | spaceshipOnPad = false |
---|
| 12 | spaceshipLaunchReady = false |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | -- Returns the distance between (x1,x2,x3) and (y1,y2,y3) |
---|
| 16 | function dist( x1,x2,x3, y1,y2,y3 ) |
---|
| 17 | |
---|
| 18 | return math.sqrt( (x1-y1)^2 + (x2-y2)^2 + (x3-y3)^2 ) |
---|
| 19 | |
---|
| 20 | end |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | function observePlayer() |
---|
| 25 | |
---|
[4070] | 26 | --playerEnteredSpaceShip = spaceship:hasPlayer() |
---|
[4056] | 27 | |
---|
| 28 | playerX = Player:getAbsCoorX() |
---|
| 29 | playerY = Player:getAbsCoorY() |
---|
| 30 | playerZ = Player:getAbsCoorZ() |
---|
| 31 | |
---|
[4070] | 32 | if dist( playerX,playerY,playerZ,678.946838, -11.959779, -920.512634 ) < 200 then |
---|
[4056] | 33 | playerReachedTrigger = true |
---|
| 34 | end |
---|
| 35 | |
---|
| 36 | end |
---|
| 37 | |
---|
| 38 | |
---|
[4070] | 39 | |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | programRoute = true |
---|
| 43 | mheight = 5 |
---|
| 44 | function mechanicMove(timestep) |
---|
| 45 | if programRoute then |
---|
| 46 | |
---|
| 47 | mechanic:walkTo( 991.192261, mheight, -1878.394287) |
---|
| 48 | mechanic:walkTo( 976.976685, mheight, -1879.182129) |
---|
| 49 | mechanic:walkTo( 963.752625, mheight, -1880.202881) |
---|
| 50 | mechanic:walkTo( 948.094543, mheight, -1880.980713) |
---|
| 51 | mechanic:walkTo( 931.008606, mheight, -1880.974854) |
---|
| 52 | mechanic:walkTo( 917.888428, mheight, -1880.832764) |
---|
| 53 | mechanic:walkTo( 901.552368, mheight, -1880.655762) |
---|
| 54 | mechanic:walkTo( 886.475220, mheight, -1880.522949) |
---|
| 55 | mechanic:walkTo( 872.041504, mheight, -1880.545410) |
---|
| 56 | mechanic:walkTo( 851.380249, mheight, -1880.577637) |
---|
| 57 | mechanic:walkTo( 840.637512, mheight, -1880.594238) |
---|
| 58 | mechanic:walkTo( 828.564941, mheight, -1880.489868) |
---|
| 59 | mechanic:walkTo( 811.580322, mheight, -1880.085205) |
---|
| 60 | mechanic:walkTo( 801.953003, mheight, -1880.036377) |
---|
| 61 | mechanic:walkTo( 784.801086, mheight, -1880.280762) |
---|
| 62 | mechanic:walkTo( 774.514343, mheight, -1880.380005) |
---|
| 63 | mechanic:walkTo( 762.351746, mheight, -1880.248779) |
---|
| 64 | mechanic:walkTo( 750.737549, mheight, -1880.123413) |
---|
| 65 | mechanic:walkTo( 739.186890, mheight, -1879.999023) |
---|
| 66 | mechanic:walkTo( 728.210022, mheight, -1879.880371) |
---|
| 67 | mechanic:walkTo( 717.243835, mheight, -1879.761719) |
---|
| 68 | mechanic:walkTo( 708.253235, mheight, -1879.649048) |
---|
| 69 | mechanic:walkTo( 695.825867, mheight, -1877.611938) |
---|
| 70 | mechanic:walkTo( 687.077820, mheight, -1869.800659) |
---|
| 71 | mechanic:walkTo( 683.886963, mheight, -1859.888062) |
---|
| 72 | mechanic:walkTo( 685.589905, mheight, -1844.102051) |
---|
| 73 | mechanic:walkTo( 686.333069, mheight, -1837.212524) |
---|
| 74 | mechanic:walkTo( 687.256042, mheight, -1828.656860) |
---|
| 75 | mechanic:walkTo( 688.759583, mheight, -1820.024048) |
---|
| 76 | mechanic:walkTo( 690.621216, mheight, -1809.834595) |
---|
| 77 | mechanic:walkTo( 692.045593, mheight, -1803.566772) |
---|
| 78 | mechanic:walkTo( 695.021851, mheight, -1795.320923) |
---|
| 79 | mechanic:walkTo( 703.956360, mheight, -1789.028931) |
---|
| 80 | mechanic:walkTo( 711.400574, mheight, -1785.378418) |
---|
| 81 | mechanic:walkTo( 720.236267, mheight, -1782.750977) |
---|
| 82 | mechanic:walkTo( 741.346130, mheight, -1786.131836) |
---|
| 83 | mechanic:walkTo( 744.505798, mheight, -1788.214111) |
---|
| 84 | mechanic:walkTo( 753.788513, mheight, -1796.320557) |
---|
| 85 | mechanic:walkTo( 760.480408, mheight, -1804.107788) |
---|
| 86 | mechanic:walkTo( 765.918274, mheight, -1811.952393) |
---|
| 87 | mechanic:walkTo( 772.114990, mheight, -1823.565674) |
---|
| 88 | mechanic:walkTo( 776.130737, mheight, -1830.713989) |
---|
| 89 | mechanic:walkTo( 781.833313, mheight, -1836.770996) |
---|
| 90 | mechanic:walkTo( 796.051880, mheight, -1843.499512) |
---|
| 91 | mechanic:walkTo( 805.178101, mheight, -1844.844116) |
---|
| 92 | mechanic:walkTo( 816.733154, mheight, -1846.198608) |
---|
| 93 | mechanic:walkTo( 830.296326, mheight, -1844.374146) |
---|
| 94 | mechanic:walkTo( 841.234680, mheight, -1841.184814) |
---|
| 95 | mechanic:walkTo( 853.356201, mheight, -1837.650391) |
---|
| 96 | mechanic:walkTo( 866.242981, mheight, -1833.892944) |
---|
| 97 | mechanic:walkTo( 877.006836, mheight, -1830.820923) |
---|
| 98 | mechanic:walkTo( 889.236816, mheight, -1828.092773) |
---|
| 99 | mechanic:walkTo( 897.856689, mheight, -1826.204346) |
---|
| 100 | mechanic:walkTo( 909.685486, mheight, -1823.613037) |
---|
| 101 | mechanic:walkTo( 922.058777, mheight, -1819.907227) |
---|
| 102 | mechanic:walkTo( 933.861328, mheight, -1814.044800) |
---|
| 103 | mechanic:walkTo( 943.290588, mheight, -1809.960205) |
---|
| 104 | mechanic:walkTo( 952.188293, mheight, -1806.317261) |
---|
| 105 | mechanic:walkTo( 985.450745, mheight, -1800.297729) |
---|
| 106 | mechanic:walkTo( 1000.339722, mheight, -1800.916626) |
---|
| 107 | mechanic:walkTo( 1013.447937, mheight, -1802.642090) |
---|
| 108 | mechanic:walkTo( 1022.703430, mheight, -1808.694946) |
---|
| 109 | mechanic:walkTo( 1030.242554, mheight, -1821.859253) |
---|
| 110 | mechanic:walkTo( 1030.063354, mheight, -1839.935547) |
---|
| 111 | mechanic:walkTo( 1025.804932, mheight, -1864.135986) |
---|
| 112 | mechanic:walkTo( 1019.079651, mheight, -1878.196777) |
---|
| 113 | |
---|
| 114 | programRoute = false |
---|
| 115 | end |
---|
| 116 | |
---|
| 117 | if mechanic:finalGoalReached() then |
---|
| 118 | programRoute = true |
---|
| 119 | end |
---|
| 120 | |
---|
| 121 | end |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | |
---|
[4056] | 131 | positionReached = false |
---|
| 132 | spaceShipReleased = false |
---|
| 133 | function moveToLaunchSite(timestep) |
---|
| 134 | |
---|
| 135 | if not positionReached then |
---|
[4070] | 136 | dx = 10 * timestep |
---|
[4056] | 137 | dy = 0 * timestep |
---|
[4070] | 138 | dz = 0* timestep |
---|
[4056] | 139 | end |
---|
| 140 | |
---|
| 141 | if not spaceShipReleased and positionReached then |
---|
| 142 | dx = 0 * timestep |
---|
[4070] | 143 | dy = 10 * timestep |
---|
[4056] | 144 | dz = 0 * timestep |
---|
| 145 | end |
---|
| 146 | |
---|
| 147 | if positionReached and spaceShipReleased then |
---|
| 148 | dx = 0 * timestep |
---|
| 149 | dy = 1 * timestep |
---|
| 150 | dz = 0 * timestep |
---|
| 151 | end |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | if spaceshipOnPad then |
---|
| 155 | |
---|
| 156 | if not spaceShipReleased then |
---|
[4070] | 157 | --spaceshipclaw:playAnimation(1,1) |
---|
| 158 | io.write("release spaceship\n") |
---|
[4056] | 159 | spaceShipReleased = true |
---|
[4070] | 160 | playerEnteredSpaceShip = true |
---|
[4056] | 161 | end |
---|
| 162 | |
---|
[4070] | 163 | --if clawY > 100 then |
---|
[4056] | 164 | spaceshipLaunchReady = true |
---|
[4070] | 165 | --end |
---|
[4056] | 166 | |
---|
| 167 | end |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | -- set new coordinates |
---|
[4070] | 171 | --clawX = claw:getAbsCoorX() |
---|
| 172 | --clawY = claw:getAbsCoorY() |
---|
| 173 | --clawZ = claw:getAbsCoorZ() |
---|
[4056] | 174 | |
---|
[4070] | 175 | --claw:setAbsCoor(clawX + dx, clawY + dy, clawZ + dz) |
---|
| 176 | spaceshipX = spaceship:getAbsCoorX() |
---|
| 177 | spaceshipY = spaceship:getAbsCoorY() |
---|
| 178 | spaceshipZ = spaceship:getAbsCoorZ() |
---|
[4056] | 179 | |
---|
[4070] | 180 | spaceship:setAbsCoor(spaceshipX + dx, spaceshipY + dy, spaceshipZ + dz) |
---|
[4056] | 181 | |
---|
| 182 | |
---|
[4070] | 183 | |
---|
| 184 | --if dist( clawX,clawY,clawZ,1020.025024, -11.959781, -1721.614380 ) < 60 then |
---|
| 185 | if dist( spaceshipX,spaceshipY,spaceshipZ,1020.025024, -11.959781, -1721.614380 ) < 60 then |
---|
[4056] | 186 | positionReached = true |
---|
| 187 | end |
---|
| 188 | |
---|
| 189 | |
---|
[4070] | 190 | --if dist( clawX,clawY,clawZ,167.361526,29,483.163818 ) < 60 then |
---|
| 191 | if spaceshipY > 10 then |
---|
[4056] | 192 | spaceshipOnPad = true |
---|
| 193 | end |
---|
| 194 | |
---|
| 195 | |
---|
[4070] | 196 | end |
---|
[4056] | 197 | |
---|
| 198 | hoverPosReached = false |
---|
| 199 | function launchSpaceShip(timestep) |
---|
| 200 | |
---|
| 201 | if not hoverPosReached then |
---|
| 202 | dx = 0 * timestep |
---|
| 203 | dy = 1 * timestep |
---|
| 204 | dz = 0 * timestep |
---|
| 205 | else |
---|
[4070] | 206 | dx = 200 * timestep |
---|
[4056] | 207 | dy = 0 * timestep |
---|
[4070] | 208 | dz = 0 * timestep |
---|
[4056] | 209 | end |
---|
| 210 | |
---|
| 211 | spaceshipX = spaceship:getAbsCoorX() |
---|
| 212 | spaceshipY = spaceship:getAbsCoorY() |
---|
| 213 | spaceshipZ = spaceship:getAbsCoorZ() |
---|
| 214 | |
---|
| 215 | spaceship:setAbsCoor(spaceshipX + dx, spaceshipY + dy, spaceshipZ + dz) |
---|
| 216 | |
---|
[4070] | 217 | if spaceshipY > 15 then |
---|
[4056] | 218 | hoverPosReached = true |
---|
| 219 | end |
---|
| 220 | |
---|
| 221 | end |
---|
| 222 | |
---|
| 223 | |
---|
[3947] | 224 | function tick(timestep) |
---|
[4070] | 225 | |
---|
[4056] | 226 | observePlayer() |
---|
[4070] | 227 | mechanicMove(timestep) |
---|
[4056] | 228 | |
---|
[4070] | 229 | if playerReachedTrigger and not spaceshipLaunchReady then |
---|
| 230 | moveToLaunchSite(timestep) |
---|
[4056] | 231 | end |
---|
| 232 | |
---|
| 233 | if spaceshipLaunchReady then |
---|
[4070] | 234 | launchSpaceShip(timestep) |
---|
[4056] | 235 | end |
---|
| 236 | |
---|
| 237 | |
---|
[3947] | 238 | return false |
---|
| 239 | end |
---|