-- Get objects from orxonox thisscript:addObject("Claw", "spaceshipclaw") thisscript:addObject("RepairStation", "repair") thisscript:addObject("FPSPlayer", "Player") thisscript:addObject("SpaceShip", "spaceship") thisscript:addObject("GenericNPC", "mechanic") thisscript:addObject("GenericNPC", "mechanic2") -- Global Variables playerEnteredSpaceShip = false playerReachedTrigger = false spaceshipOnPad = false spaceshipLaunchReady = false -- Returns the distance between (x1,x2,x3) and (y1,y2,y3) function dist( x1,x2,x3, y1,y2,y3 ) return math.sqrt( (x1-y1)^2 + (x2-y2)^2 + (x3-y3)^2 ) end function observePlayer() --playerEnteredSpaceShip = spaceship:hasPlayer() playerX = Player:getAbsCoorX() playerY = Player:getAbsCoorY() playerZ = Player:getAbsCoorZ() if dist( playerX,playerY,playerZ,678.946838, -11.959779, -920.512634 ) < 200 then playerReachedTrigger = true end end mprogramRoute = true mheight = 5 function mechanicMove(timestep) if mprogramRoute then mechanic:walkTo( 991.192261, mheight, -1878.394287) mechanic:walkTo( 976.976685, mheight, -1879.182129) mechanic:walkTo( 963.752625, mheight, -1880.202881) mechanic:walkTo( 948.094543, mheight, -1880.980713) mechanic:walkTo( 931.008606, mheight, -1880.974854) mechanic:walkTo( 917.888428, mheight, -1880.832764) mechanic:walkTo( 901.552368, mheight, -1880.655762) mechanic:walkTo( 886.475220, mheight, -1880.522949) mechanic:walkTo( 872.041504, mheight, -1880.545410) mechanic:walkTo( 851.380249, mheight, -1880.577637) mechanic:walkTo( 840.637512, mheight, -1880.594238) mechanic:walkTo( 828.564941, mheight, -1880.489868) mechanic:walkTo( 811.580322, mheight, -1880.085205) mechanic:walkTo( 801.953003, mheight, -1880.036377) mechanic:walkTo( 784.801086, mheight, -1880.280762) mechanic:walkTo( 774.514343, mheight, -1880.380005) mechanic:walkTo( 762.351746, mheight, -1880.248779) mechanic:walkTo( 750.737549, mheight, -1880.123413) mechanic:walkTo( 739.186890, mheight, -1879.999023) mechanic:walkTo( 728.210022, mheight, -1879.880371) mechanic:walkTo( 717.243835, mheight, -1879.761719) mechanic:walkTo( 708.253235, mheight, -1879.649048) mechanic:walkTo( 695.825867, mheight, -1877.611938) mechanic:walkTo( 687.077820, mheight, -1869.800659) mechanic:walkTo( 683.886963, mheight, -1859.888062) mechanic:walkTo( 685.589905, mheight, -1844.102051) mechanic:walkTo( 686.333069, mheight, -1837.212524) mechanic:walkTo( 687.256042, mheight, -1828.656860) mechanic:walkTo( 688.759583, mheight, -1820.024048) mechanic:walkTo( 690.621216, mheight, -1809.834595) mechanic:walkTo( 692.045593, mheight, -1803.566772) mechanic:walkTo( 695.021851, mheight, -1795.320923) mechanic:walkTo( 703.956360, mheight, -1789.028931) mechanic:walkTo( 711.400574, mheight, -1785.378418) mechanic:walkTo( 720.236267, mheight, -1782.750977) mechanic:walkTo( 741.346130, mheight, -1786.131836) mechanic:walkTo( 744.505798, mheight, -1788.214111) mechanic:walkTo( 753.788513, mheight, -1796.320557) mechanic:walkTo( 760.480408, mheight, -1804.107788) mechanic:walkTo( 765.918274, mheight, -1811.952393) mechanic:walkTo( 772.114990, mheight, -1823.565674) mechanic:walkTo( 776.130737, mheight, -1830.713989) mechanic:walkTo( 781.833313, mheight, -1836.770996) mechanic:walkTo( 796.051880, mheight, -1843.499512) mechanic:walkTo( 805.178101, mheight, -1844.844116) mechanic:walkTo( 816.733154, mheight, -1846.198608) mechanic:walkTo( 830.296326, mheight, -1844.374146) mechanic:walkTo( 841.234680, mheight, -1841.184814) mechanic:walkTo( 853.356201, mheight, -1837.650391) mechanic:walkTo( 866.242981, mheight, -1833.892944) mechanic:walkTo( 877.006836, mheight, -1830.820923) mechanic:walkTo( 889.236816, mheight, -1828.092773) mechanic:walkTo( 897.856689, mheight, -1826.204346) mechanic:walkTo( 909.685486, mheight, -1823.613037) mechanic:walkTo( 922.058777, mheight, -1819.907227) mechanic:walkTo( 933.861328, mheight, -1814.044800) mechanic:walkTo( 943.290588, mheight, -1809.960205) mechanic:walkTo( 952.188293, mheight, -1806.317261) mechanic:walkTo( 985.450745, mheight, -1800.297729) mechanic:walkTo( 1000.339722, mheight, -1800.916626) mechanic:walkTo( 1013.447937, mheight, -1802.642090) mechanic:walkTo( 1022.703430, mheight, -1808.694946) mechanic:walkTo( 1030.242554, mheight, -1821.859253) mechanic:walkTo( 1030.063354, mheight, -1839.935547) mechanic:walkTo( 1025.804932, mheight, -1864.135986) mechanic:walkTo( 1019.079651, mheight, -1878.196777) mprogramRoute = false end if mechanic:finalGoalReached() then mprogramRoute = true end end mtprogramRoute = true mtheight = 5 waittime = 0 waiting = false function mechanictMove(timestep) if mtprogramRoute then mechanic2:walkTo( 1564.473999, mtheight, -1923.821533) mechanic2:walkTo( 1556.049927, mtheight, -1916.359009) mechanic2:walkTo( 1550.970581, mtheight, -1913.087524) mechanic2:walkTo( 1542.345459, mtheight, -1912.611938) mechanic2:walkTo( 1534.643677, mtheight, -1912.361816) mechanic2:walkTo( 1524.490845, mtheight, -1912.074097) mechanic2:walkTo( 1516.120605, mtheight, -1912.511475) mechanic2:walkTo( 1508.607788, mtheight, -1912.904175) mechanic2:walkTo( 1498.452759, mtheight, -1913.434814) mechanic2:walkTo( 1492.513916, mtheight, -1913.744995) mechanic2:walkTo( 1483.056274, mtheight, -1914.239136) mechanic2:walkTo( 1471.428711, mtheight, -1916.435303) mechanic2:walkTo( 1460.068359, mtheight, -1916.473022) mechanic2:walkTo( 1451.006592, mtheight, -1913.691772) mechanic2:walkTo( 1444.585938, mtheight, -1911.533691) mechanic2:walkTo( 1439.008423, mtheight, -1909.659058) mechanic2:walkTo( 1421.636230, mtheight, -1915.466553) mechanic2:walkTo( 1420.582275, mtheight, -1926.693970) mechanic2:walkTo( 1422.506714, mtheight, -1934.938232) mechanic2:walkTo( 1430.749023, mtheight, -1942.431519) mechanic2:walkTo( 1440.773315, mtheight, -1948.152832) mechanic2:walkTo( 1452.532227, mtheight, -1950.169800) mechanic2:walkTo( 1465.584961, mtheight, -1949.407959) mechanic2:walkTo( 1475.635254, mtheight, -1948.756226) mechanic2:walkTo( 1481.961548, mtheight, -1948.346069) mechanic2:walkTo( 1495.564575, mtheight, -1947.588257) mechanic2:walkTo( 1505.660156, mtheight, -1947.679077) mechanic2:walkTo( 1514.055542, mtheight, -1947.901245) mechanic2:walkTo( 1523.532959, mtheight, -1948.351440) mechanic2:walkTo( 1537.855347, mtheight, -1949.461914) mechanic2:walkTo( 1545.510498, mtheight, -1950.162720) mechanic2:walkTo( 1553.132935, mtheight, -1950.860718) mechanic2:walkTo( 1556.371460, mtheight, -1951.157104) mechanic2:walkTo( 1563.450806, mtheight, -1951.804932) mechanic2:walkTo( 1572.594116, mtheight, -1952.320679) mechanic2:walkTo( 1582.691772, mtheight, -1950.470459) mechanic2:walkTo( 1589.872681, mtheight, -1929.683105) mechanic2:walkTo( 1587.794922, mtheight, -1922.749756) mechanic2:walkTo( 1582.800171, mtheight, -1917.671021) mechanic2:walkTo( 1573.449951, mtheight, -1915.750854) mechanic2:walkTo( 1564.055908, mtheight, -1914.986328) mtprogramRoute = false end mechanic2X = mechanic2:getAbsCoorX() mechanic2Y = mechanic2:getAbsCoorY() mechanic2Z = mechanic2:getAbsCoorZ() if dist(mechanic2X,mechanic2Y,mechanic2Z,1435.444824, mtheight, -1916.463013) < 10 and not waiting then mechanic2:stop() waittime = 5 --io.write("mechanic2 stoped \n") waiting = true end if waittime >= 0 and waiting then waittime = waittime - timestep --io.write(waittime,"\n") if waittime < 0 then --io.write("mechanic2 finished waiting\n") mechanic2:resume() end end if dist(mechanic2X,mechanic2Y,mechanic2Z,1564.473999, mtheight, -1923.821533) < 10 and waiting then waiting = false end if mechanic2:finalGoalReached() then mtprogramRoute = true end end positionReached = false spaceShipReleased = false function moveToLaunchSite(timestep) if not positionReached then dx = 10 * timestep dy = 0 * timestep dz = 0* timestep end if not spaceShipReleased and positionReached then dx = 0 * timestep dy = 10 * timestep dz = 0 * timestep end if positionReached and spaceShipReleased then dx = 0 * timestep dy = 1 * timestep dz = 0 * timestep end if spaceshipOnPad then if not spaceShipReleased then --spaceshipclaw:playAnimation(1,1) --io.write("release spaceship\n") spaceShipReleased = true playerEnteredSpaceShip = true end --if clawY > 100 then spaceshipLaunchReady = true --end end -- set new coordinates --clawX = claw:getAbsCoorX() --clawY = claw:getAbsCoorY() --clawZ = claw:getAbsCoorZ() --claw:setAbsCoor(clawX + dx, clawY + dy, clawZ + dz) spaceshipX = spaceship:getAbsCoorX() spaceshipY = spaceship:getAbsCoorY() spaceshipZ = spaceship:getAbsCoorZ() spaceship:setAbsCoor(spaceshipX + dx, spaceshipY + dy, spaceshipZ + dz) --if dist( clawX,clawY,clawZ,1020.025024, -11.959781, -1721.614380 ) < 60 then if dist( spaceshipX,spaceshipY,spaceshipZ,1020.025024, -11.959781, -1721.614380 ) < 60 then positionReached = true end --if dist( clawX,clawY,clawZ,167.361526,29,483.163818 ) < 60 then if spaceshipY > 10 then spaceshipOnPad = true end end hoverPosReached = false function launchSpaceShip(timestep) if not hoverPosReached then dx = 0 * timestep dy = 1 * timestep dz = 0 * timestep else dx = 200 * timestep dy = 0 * timestep dz = 0 * timestep end spaceshipX = spaceship:getAbsCoorX() spaceshipY = spaceship:getAbsCoorY() spaceshipZ = spaceship:getAbsCoorZ() spaceship:setAbsCoor(spaceshipX + dx, spaceshipY + dy, spaceshipZ + dz) if spaceshipY > 15 then hoverPosReached = true end end function tick(timestep) observePlayer() mechanicMove(timestep) mechanictMove(timestep) --if playerReachedTrigger and not spaceshipLaunchReady then --moveToLaunchSite(timestep) --end --if spaceshipLaunchReady then --launchSpaceShip(timestep) --end return false end