Flight time calculator

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Flight time calculator

      Has anyone ever made a flight time calculator for 1.8 or 2.0? We did but it doesn't calculate properly.




      This is the code used in the calculation
      ------------------------------------------------------

      JavaScript Source Code

      1. <script type="text/javascript">
      2. function CalculateDistance(x1, y1, z1, x2, y2, z2) {
      3. if (x1 == x2) {
      4. if (y1 == y2) {
      5. if (z1 == z2) {
      6. return 5;
      7. } else {
      8. return 1000 + Math.abs(z1 - z2) * 5;
      9. }
      10. } else {
      11. return 2700 + Math.abs(y1 - y2) * 95;
      12. }
      13. } else {
      14. return Math.abs(x1 - x2) * 20000;
      15. }
      16. }
      17. function CalculateCargoCapacity(shipType, cargoSpace, cargoTechLevel, cargoTalentLevel) {
      18. if (shipType == 202 || shipType == 203 || shipType == 209 || shipType == 217 || shipType == 219) {
      19. return cargoSpace * (1 + (cargoTechLevel * 0.5 + cargoTalentLevel * 0.05));
      20. } else {
      21. return cargoSpace * (1 + (cargoTechLevel * 0.05 + cargoTalentLevel * 0.05));
      22. }
      23. }
      24. function CalculateShipSpeed(shipType, baseSpeed, combustionLevel, impulseLevel, hyperSpaceLevel) {
      25. if (shipType == 202 || shipType == 203 || shipType == 209 || shipType == 217 || shipType == 219) {
      26. if (hyperSpaceLevel >= 22) {
      27. return parseInt(baseSpeed * (1 + hyperSpaceLevel * 0.3));
      28. } else if (impulseLevel >= 22) {
      29. return parseInt(baseSpeed * (1 + impulseLevel * 0.2));
      30. } else {
      31. return parseInt(baseSpeed * (1 + combustionLevel * 0.1));
      32. }
      33. } else {
      34. if (shipType == 204 || shipType == 210) {
      35. return parseInt(baseSpeed * (1 + combustionLevel * 0.1));
      36. } else if (shipType == 205 || shipType == 206 || shipType == 208 || shipType == 220) {
      37. return parseInt(baseSpeed * (1 + impulseLevel * 0.2));
      38. } else {
      39. return parseInt(baseSpeed * (1 + hyperSpaceLevel * 0.3));
      40. }
      41. }
      42. }
      43. function CalculateSpeedFactor(navigatorLevel, speedTalentLevel, speedBoosterItem) {
      44. var factor = 1;
      45. var navigatorFactor = 0;
      46. var speedTalentFactor = 0;
      47. var speedBoosterFactor = 0;
      48. if (navigatorLevel > 0) {
      49. navigatorFactor = navigatorLevel * 0.02;
      50. }
      51. if (speedTalentLevel > 0) {
      52. speedTalentFactor = speedTalentLevel * 0.02;
      53. }
      54. if (speedBoosterItem > 0) {
      55. speedBoosterFactor = speedBoosterItem / 100;
      56. }
      57. console.log("booster : " + speedBoosterFactor);
      58. return 1 + navigatorFactor + speedTalentFactor + speedBoosterFactor;
      59. }
      60. function CalculateFleetTime(distance, speedPerc, fleetSpeed) {
      61. speedPerc = speedPerc / 10;
      62. if (distance > 1000) distance += 1000;
      63. return Math.max(Math.round(((35000 / speedPerc) * Math.sqrt((distance * 10) / fleetSpeed) + 10) / 3), 5);
      64. }
      65. function CalculateFlight() {
      66. var result_distance = 0;
      67. var result_fuel_cons = 0;
      68. var result_cargo_capacity = 0;
      69. var result_speed_of_fleet = 999999999999999999999999999999;
      70. var sourceX = $("#source_coords_x").val();
      71. var sourceY = $("#source_coords_y").val();
      72. var sourceZ = $("#source_coords_z").val();
      73. var targetX = $("#target_coords_x").val();
      74. var targetY = $("#target_coords_y").val();
      75. var targetZ = $("#target_coords_z").val();
      76. var speedPercentage = parseInt($(".x-speed-choice.active").first().attr("data-speed-percent"));
      77. if (isNaN(speedPercentage)) speedPercentage = 100;
      78. var speedBooster = parseInt($(".x-fuel-booster-item.active").first().attr("data-boost-value"));
      79. if (isNaN(speedBooster)) speedBooster = 0;
      80. var classSelection = $(".x-class-selection.active").first().attr("data-class-type");
      81. if (classSelection == undefined) classSelection = null;
      82. console.log(speedPercentage);
      83. var combustionEngineLevel = parseInt($("#combustion_engine_level").val());
      84. var impulseEngineLevel = parseInt($("#impulse_engine_level").val());
      85. var hyperspaceEngineLevel = parseInt($("#hyperspace_engine_level").val());
      86. var cargoTechLevel = parseInt($("#cargo_tech_level").val());
      87. var cargoTalentLevel = parseInt($("#ship_cargo_talent_level").val());
      88. var fuelConsTalentLevel = parseInt($("#ship_fuel_cons_talent_level").val());
      89. var shipSpeedTalentLevel = parseInt($("#ship_speed_talent_level").val());
      90. var navigatorLevel = parseInt($("#navigator_level").val());
      91. if (isNaN(combustionEngineLevel)) combustionEngineLevel = 0;
      92. if (isNaN(impulseEngineLevel)) impulseEngineLevel = 0;
      93. if (isNaN(hyperspaceEngineLevel)) hyperspaceEngineLevel = 0;
      94. if (isNaN(cargoTechLevel)) cargoTechLevel = 0;
      95. if (isNaN(cargoTalentLevel)) cargoTalentLevel = 0;
      96. if (isNaN(fuelConsTalentLevel)) fuelConsTalentLevel = 0;
      97. if (isNaN(shipSpeedTalentLevel)) shipSpeedTalentLevel = 0;
      98. if (isNaN(navigatorLevel)) navigatorLevel = 0;
      99. result_distance = CalculateDistance(sourceX, sourceY, sourceZ, targetX, targetY, targetZ);
      100. var isCargoShipsOnly = true;
      101. var isWarShipsOnly = true;
      102. $("#simulator-container .x-ship-input").each(function () {
      103. var thisShipCount = parseInt($(this).val().replace(/\D/g, ""));
      104. if (isNaN(thisShipCount)) thisShipCount = 0;
      105. if (thisShipCount > 0) {
      106. var shipType = $(this).attr("data-ship-type");
      107. if (shipType != 202 && shipType != 203 && shipType != 217) {
      108. isCargoShipsOnly = false;
      109. }
      110. if (
      111. shipType != 202 &&
      112. shipType != 203 &&
      113. shipType != 204 &&
      114. shipType != 205 &&
      115. shipType != 206 &&
      116. shipType != 207 &&
      117. shipType != 208 &&
      118. shipType != 209 &&
      119. shipType != 210 &&
      120. shipType != 211 &&
      121. shipType != 213 &&
      122. shipType != 214 &&
      123. shipType != 215 &&
      124. shipType != 217 &&
      125. shipType != 219 &&
      126. shipType != 220
      127. ) {
      128. isWarShipsOnly = false;
      129. }
      130. var shipCargoCapacity = parseInt($(this).attr("data-cargo-space"));
      131. if (isNaN(shipCargoCapacity)) shipCargoCapacity = 0;
      132. if (shipCargoCapacity > 0) shipCargoCapacity = CalculateCargoCapacity(shipType, shipCargoCapacity, cargoTechLevel, cargoTalentLevel);
      133. result_cargo_capacity += thisShipCount * parseInt(shipCargoCapacity);
      134. var shipFuelCons = parseInt($(this).attr("data-fuel-cons"));
      135. if (isNaN(shipFuelCons)) shipFuelCons = 0;
      136. if (shipFuelCons > 0) {
      137. shipFuelCons = shipFuelCons * (1 - fuelConsTalentLevel * 0.02);
      138. }
      139. result_fuel_cons += thisShipCount * shipFuelCons;
      140. var shipSpeed = parseInt($(this).attr("data-speed"));
      141. shipSpeed = parseInt(CalculateShipSpeed(shipType, shipSpeed, combustionEngineLevel, impulseEngineLevel, hyperspaceEngineLevel) * CalculateSpeedFactor(navigatorLevel, shipSpeedTalentLevel, speedBooster));
      142. if (shipSpeed < result_speed_of_fleet) result_speed_of_fleet = shipSpeed;
      143. }
      144. });
      145. console.log("isCargoShipsOnly : " + isCargoShipsOnly);
      146. console.log("isWarShipsOnly : " + isWarShipsOnly);
      147. var oneWayFlightTime = CalculateFleetTime(result_distance, speedPercentage, result_speed_of_fleet);
      148. if (result_fuel_cons > 0) {
      149. result_fuel_cons = 1 + Math.round((result_fuel_cons / 35000) * result_distance * Math.pow(speedPercentage / 100 + 1, 2));
      150. }
      151. if (classSelection != null) {
      152. if (classSelection == "MINER") {
      153. if (isCargoShipsOnly) {
      154. oneWayFlightTime = Math.ceil(oneWayFlightTime / 2);
      155. }
      156. } else if (classSelection == "COMMANDER") {
      157. if (isWarShipsOnly) {
      158. oneWayFlightTime = Math.ceil(oneWayFlightTime / 1.5);
      159. }
      160. result_fuel_cons = Math.ceil(result_fuel_cons * 0.75);
      161. }
      162. }
      163. if (speedPercentage < 100) {
      164. result_speed_of_fleet = parseInt(result_speed_of_fleet * (speedPercentage / 100));
      165. }
      166. if (result_speed_of_fleet == 999999999999999999999999999999) result_speed_of_fleet = 0;
      167. $("#result_flight_time_one_way").html(ConvertToTimeString(oneWayFlightTime));
      168. $("#result_distance").html(numberWithCommas(result_distance));
      169. $("#result_fuel_cons").html(numberWithCommas(result_fuel_cons));
      170. $("#result_cargo_capacity").html(numberWithCommas(result_cargo_capacity));
      171. $("#result_fleet_speed").html(numberWithCommas(result_speed_of_fleet));
      172. }
      173. $(function () {
      174. $("#simulator-container input")
      175. .off()
      176. .focusin(function () {
      177. var val = $(this).val();
      178. var min_value = parseInt($(this).attr("min-value"));
      179. if (val === "0" || val === 0 || val == "0" || val == 0 || val == min_value) {
      180. $(this).val("");
      181. } else {
      182. if (/\D/g.test(this.value)) {
      183. // Filter non-digits from input value.
      184. this.value = this.value.replace(/\D/g, "");
      185. }
      186. }
      187. this.value = numberWithCommas(this.value);
      188. })
      189. .focusout(function () {
      190. var val = $(this).val();
      191. var min_value = parseInt($(this).attr("min-value"));
      192. if (val === "" || val === " " || val == "" || val == " ") {
      193. $(this).val(min_value);
      194. } else {
      195. if (/\D/g.test(this.value)) {
      196. // Filter non-digits from input value.
      197. this.value = this.value.replace(/\D/g, "");
      198. }
      199. }
      200. this.value = numberWithCommas(this.value);
      201. })
      202. .on("input", function (e) {
      203. if (e.keyCode === 37 || e.keyCode === 38 || e.keyCode === 39 || e.keyCode === 40) return;
      204. if (/\D/g.test(this.value)) {
      205. // Filter non-digits from input value.
      206. this.value = this.value.replace(/\D/g, "");
      207. }
      208. var min_value = parseInt($(this).attr("min-value"));
      209. if (min_value == undefined || min_value == null || isNaN(min_value)) min_value = 0;
      210. var max_value = parseInt($(this).attr("max-value"));
      211. if (max_value == undefined || max_value == null || isNaN(max_value)) max_value = 999999999999999999999999999999;
      212. var intVal = parseInt(this.value);
      213. if (!isNaN(intVal)) {
      214. if (intVal < min_value) {
      215. this.value = min_value;
      216. } else if (intVal > max_value) {
      217. this.value = max_value;
      218. }
      219. }
      220. this.value = numberWithCommas(this.value);
      221. CalculateFlight();
      222. });
      223. $("#simulator-container .x-speed-choice").click(function () {
      224. $("#simulator-container .x-speed-choice").removeClass("active");
      225. $(this).addClass("active");
      226. CalculateFlight();
      227. return false;
      228. });
      229. $("#simulator-container .x-fuel-booster-item").click(function () {
      230. $("#simulator-container .x-fuel-booster-item").removeClass("active");
      231. $(this).addClass("active");
      232. CalculateFlight();
      233. return false;
      234. });
      235. $("#simulator-container .x-class-selection").click(function () {
      236. $("#simulator-container .x-class-selection").removeClass("active");
      237. $(this).addClass("active");
      238. CalculateFlight();
      239. return false;
      240. });
      241. CalculateFlight();
      242. });
      243. </script>
      Display All

      The post was edited 1 time, last by Danter14: Proof that it is possible to put it in the code tags ().