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
------------------------------------------------------
Display All
This is the code used in the calculation
------------------------------------------------------
JavaScript Source Code
- <script type="text/javascript">
- function CalculateDistance(x1, y1, z1, x2, y2, z2) {
- if (x1 == x2) {
- if (y1 == y2) {
- if (z1 == z2) {
- return 5;
- } else {
- return 1000 + Math.abs(z1 - z2) * 5;
- }
- } else {
- return 2700 + Math.abs(y1 - y2) * 95;
- }
- } else {
- return Math.abs(x1 - x2) * 20000;
- }
- }
- function CalculateCargoCapacity(shipType, cargoSpace, cargoTechLevel, cargoTalentLevel) {
- if (shipType == 202 || shipType == 203 || shipType == 209 || shipType == 217 || shipType == 219) {
- return cargoSpace * (1 + (cargoTechLevel * 0.5 + cargoTalentLevel * 0.05));
- } else {
- return cargoSpace * (1 + (cargoTechLevel * 0.05 + cargoTalentLevel * 0.05));
- }
- }
- function CalculateShipSpeed(shipType, baseSpeed, combustionLevel, impulseLevel, hyperSpaceLevel) {
- if (shipType == 202 || shipType == 203 || shipType == 209 || shipType == 217 || shipType == 219) {
- if (hyperSpaceLevel >= 22) {
- return parseInt(baseSpeed * (1 + hyperSpaceLevel * 0.3));
- } else if (impulseLevel >= 22) {
- return parseInt(baseSpeed * (1 + impulseLevel * 0.2));
- } else {
- return parseInt(baseSpeed * (1 + combustionLevel * 0.1));
- }
- } else {
- if (shipType == 204 || shipType == 210) {
- return parseInt(baseSpeed * (1 + combustionLevel * 0.1));
- } else if (shipType == 205 || shipType == 206 || shipType == 208 || shipType == 220) {
- return parseInt(baseSpeed * (1 + impulseLevel * 0.2));
- } else {
- return parseInt(baseSpeed * (1 + hyperSpaceLevel * 0.3));
- }
- }
- }
- function CalculateSpeedFactor(navigatorLevel, speedTalentLevel, speedBoosterItem) {
- var factor = 1;
- var navigatorFactor = 0;
- var speedTalentFactor = 0;
- var speedBoosterFactor = 0;
- if (navigatorLevel > 0) {
- navigatorFactor = navigatorLevel * 0.02;
- }
- if (speedTalentLevel > 0) {
- speedTalentFactor = speedTalentLevel * 0.02;
- }
- if (speedBoosterItem > 0) {
- speedBoosterFactor = speedBoosterItem / 100;
- }
- console.log("booster : " + speedBoosterFactor);
- return 1 + navigatorFactor + speedTalentFactor + speedBoosterFactor;
- }
- function CalculateFleetTime(distance, speedPerc, fleetSpeed) {
- speedPerc = speedPerc / 10;
- if (distance > 1000) distance += 1000;
- return Math.max(Math.round(((35000 / speedPerc) * Math.sqrt((distance * 10) / fleetSpeed) + 10) / 3), 5);
- }
- function CalculateFlight() {
- var result_distance = 0;
- var result_fuel_cons = 0;
- var result_cargo_capacity = 0;
- var result_speed_of_fleet = 999999999999999999999999999999;
- var sourceX = $("#source_coords_x").val();
- var sourceY = $("#source_coords_y").val();
- var sourceZ = $("#source_coords_z").val();
- var targetX = $("#target_coords_x").val();
- var targetY = $("#target_coords_y").val();
- var targetZ = $("#target_coords_z").val();
- var speedPercentage = parseInt($(".x-speed-choice.active").first().attr("data-speed-percent"));
- if (isNaN(speedPercentage)) speedPercentage = 100;
- var speedBooster = parseInt($(".x-fuel-booster-item.active").first().attr("data-boost-value"));
- if (isNaN(speedBooster)) speedBooster = 0;
- var classSelection = $(".x-class-selection.active").first().attr("data-class-type");
- if (classSelection == undefined) classSelection = null;
- console.log(speedPercentage);
- var combustionEngineLevel = parseInt($("#combustion_engine_level").val());
- var impulseEngineLevel = parseInt($("#impulse_engine_level").val());
- var hyperspaceEngineLevel = parseInt($("#hyperspace_engine_level").val());
- var cargoTechLevel = parseInt($("#cargo_tech_level").val());
- var cargoTalentLevel = parseInt($("#ship_cargo_talent_level").val());
- var fuelConsTalentLevel = parseInt($("#ship_fuel_cons_talent_level").val());
- var shipSpeedTalentLevel = parseInt($("#ship_speed_talent_level").val());
- var navigatorLevel = parseInt($("#navigator_level").val());
- if (isNaN(combustionEngineLevel)) combustionEngineLevel = 0;
- if (isNaN(impulseEngineLevel)) impulseEngineLevel = 0;
- if (isNaN(hyperspaceEngineLevel)) hyperspaceEngineLevel = 0;
- if (isNaN(cargoTechLevel)) cargoTechLevel = 0;
- if (isNaN(cargoTalentLevel)) cargoTalentLevel = 0;
- if (isNaN(fuelConsTalentLevel)) fuelConsTalentLevel = 0;
- if (isNaN(shipSpeedTalentLevel)) shipSpeedTalentLevel = 0;
- if (isNaN(navigatorLevel)) navigatorLevel = 0;
- result_distance = CalculateDistance(sourceX, sourceY, sourceZ, targetX, targetY, targetZ);
- var isCargoShipsOnly = true;
- var isWarShipsOnly = true;
- $("#simulator-container .x-ship-input").each(function () {
- var thisShipCount = parseInt($(this).val().replace(/\D/g, ""));
- if (isNaN(thisShipCount)) thisShipCount = 0;
- if (thisShipCount > 0) {
- var shipType = $(this).attr("data-ship-type");
- if (shipType != 202 && shipType != 203 && shipType != 217) {
- isCargoShipsOnly = false;
- }
- if (
- shipType != 202 &&
- shipType != 203 &&
- shipType != 204 &&
- shipType != 205 &&
- shipType != 206 &&
- shipType != 207 &&
- shipType != 208 &&
- shipType != 209 &&
- shipType != 210 &&
- shipType != 211 &&
- shipType != 213 &&
- shipType != 214 &&
- shipType != 215 &&
- shipType != 217 &&
- shipType != 219 &&
- shipType != 220
- ) {
- isWarShipsOnly = false;
- }
- var shipCargoCapacity = parseInt($(this).attr("data-cargo-space"));
- if (isNaN(shipCargoCapacity)) shipCargoCapacity = 0;
- if (shipCargoCapacity > 0) shipCargoCapacity = CalculateCargoCapacity(shipType, shipCargoCapacity, cargoTechLevel, cargoTalentLevel);
- result_cargo_capacity += thisShipCount * parseInt(shipCargoCapacity);
- var shipFuelCons = parseInt($(this).attr("data-fuel-cons"));
- if (isNaN(shipFuelCons)) shipFuelCons = 0;
- if (shipFuelCons > 0) {
- shipFuelCons = shipFuelCons * (1 - fuelConsTalentLevel * 0.02);
- }
- result_fuel_cons += thisShipCount * shipFuelCons;
- var shipSpeed = parseInt($(this).attr("data-speed"));
- shipSpeed = parseInt(CalculateShipSpeed(shipType, shipSpeed, combustionEngineLevel, impulseEngineLevel, hyperspaceEngineLevel) * CalculateSpeedFactor(navigatorLevel, shipSpeedTalentLevel, speedBooster));
- if (shipSpeed < result_speed_of_fleet) result_speed_of_fleet = shipSpeed;
- }
- });
- console.log("isCargoShipsOnly : " + isCargoShipsOnly);
- console.log("isWarShipsOnly : " + isWarShipsOnly);
- var oneWayFlightTime = CalculateFleetTime(result_distance, speedPercentage, result_speed_of_fleet);
- if (result_fuel_cons > 0) {
- result_fuel_cons = 1 + Math.round((result_fuel_cons / 35000) * result_distance * Math.pow(speedPercentage / 100 + 1, 2));
- }
- if (classSelection != null) {
- if (classSelection == "MINER") {
- if (isCargoShipsOnly) {
- oneWayFlightTime = Math.ceil(oneWayFlightTime / 2);
- }
- } else if (classSelection == "COMMANDER") {
- if (isWarShipsOnly) {
- oneWayFlightTime = Math.ceil(oneWayFlightTime / 1.5);
- }
- result_fuel_cons = Math.ceil(result_fuel_cons * 0.75);
- }
- }
- if (speedPercentage < 100) {
- result_speed_of_fleet = parseInt(result_speed_of_fleet * (speedPercentage / 100));
- }
- if (result_speed_of_fleet == 999999999999999999999999999999) result_speed_of_fleet = 0;
- $("#result_flight_time_one_way").html(ConvertToTimeString(oneWayFlightTime));
- $("#result_distance").html(numberWithCommas(result_distance));
- $("#result_fuel_cons").html(numberWithCommas(result_fuel_cons));
- $("#result_cargo_capacity").html(numberWithCommas(result_cargo_capacity));
- $("#result_fleet_speed").html(numberWithCommas(result_speed_of_fleet));
- }
- $(function () {
- $("#simulator-container input")
- .off()
- .focusin(function () {
- var val = $(this).val();
- var min_value = parseInt($(this).attr("min-value"));
- if (val === "0" || val === 0 || val == "0" || val == 0 || val == min_value) {
- $(this).val("");
- } else {
- if (/\D/g.test(this.value)) {
- // Filter non-digits from input value.
- this.value = this.value.replace(/\D/g, "");
- }
- }
- this.value = numberWithCommas(this.value);
- })
- .focusout(function () {
- var val = $(this).val();
- var min_value = parseInt($(this).attr("min-value"));
- if (val === "" || val === " " || val == "" || val == " ") {
- $(this).val(min_value);
- } else {
- if (/\D/g.test(this.value)) {
- // Filter non-digits from input value.
- this.value = this.value.replace(/\D/g, "");
- }
- }
- this.value = numberWithCommas(this.value);
- })
- .on("input", function (e) {
- if (e.keyCode === 37 || e.keyCode === 38 || e.keyCode === 39 || e.keyCode === 40) return;
- if (/\D/g.test(this.value)) {
- // Filter non-digits from input value.
- this.value = this.value.replace(/\D/g, "");
- }
- var min_value = parseInt($(this).attr("min-value"));
- if (min_value == undefined || min_value == null || isNaN(min_value)) min_value = 0;
- var max_value = parseInt($(this).attr("max-value"));
- if (max_value == undefined || max_value == null || isNaN(max_value)) max_value = 999999999999999999999999999999;
- var intVal = parseInt(this.value);
- if (!isNaN(intVal)) {
- if (intVal < min_value) {
- this.value = min_value;
- } else if (intVal > max_value) {
- this.value = max_value;
- }
- }
- this.value = numberWithCommas(this.value);
- CalculateFlight();
- });
- $("#simulator-container .x-speed-choice").click(function () {
- $("#simulator-container .x-speed-choice").removeClass("active");
- $(this).addClass("active");
- CalculateFlight();
- return false;
- });
- $("#simulator-container .x-fuel-booster-item").click(function () {
- $("#simulator-container .x-fuel-booster-item").removeClass("active");
- $(this).addClass("active");
- CalculateFlight();
- return false;
- });
- $("#simulator-container .x-class-selection").click(function () {
- $("#simulator-container .x-class-selection").removeClass("active");
- $(this).addClass("active");
- CalculateFlight();
- return false;
- });
- CalculateFlight();
- });
- </script>
The post was edited 1 time, last by Danter14: Proof that it is possible to put it in the code tags ().