Просмотр исходного кода

Show how far away two characters can see each other

Only happens if both 'show ratios' and 'show horizon' are enabled
master
Fen Dweller 4 лет назад
Родитель
Сommit
173e3d96e6
1 измененных файлов: 26 добавлений и 2 удалений
  1. +26
    -2
      macrovision.js

+ 26
- 2
macrovision.js Просмотреть файл

@@ -566,6 +566,7 @@ function updateEntityElement(entity, element) {
} else {
topName.classList.remove("top-name-needed");
}
updateRatios();
}

let ratioInfo
@@ -607,15 +608,35 @@ function updateRatios() {

if (config.showHorizon) {
if (selectedEntity !== null) {
const y = document.querySelector("#entity-" + selectedEntity.index).dataset.y;
const R = math.unit(1.27560e+7, "meters")
const h = selectedEntity.currentView.height
const h = math.add(selectedEntity.currentView.height, math.unit(y, "meters"))

const first = math.multiply(2, math.multiply(R, h))
const second = math.multiply(h, h)

const sightline = math.sqrt(math.add(first, second)).to(config.height.units[0].unit.name)

text += selectedEntity.name + " could see for " + math.format(sightline, { precision: 3 })
text += selectedEntity.name + " could see for " + math.format(sightline, { precision: 3 }) + "\n"
}
}

if (config.showRatios && config.showHorizon) {
if (selectedEntity !== null && prevSelectedEntity !== null && selectedEntity !== prevSelectedEntity) {
const y1 = document.querySelector("#entity-" + selectedEntity.index).dataset.y;
const y2 = document.querySelector("#entity-" + prevSelectedEntity.index).dataset.y;
const R = math.unit(1.27560e+7, "meters")
const R2 = math.subtract(math.subtract(R, prevSelectedEntity.currentView.height), math.unit(y2, "meters"))
const h = math.add(selectedEntity.currentView.height, math.unit(y1, "meters"))

console.log(R, R2, h)

const first = math.pow(math.add(R, h), 2)
const second = math.pow(R2, 2)

const sightline = math.sqrt(math.subtract(first, second)).to(config.height.units[0].unit.name)

text += selectedEntity.name + " could see " + prevSelectedEntity.name + " from " + math.format(sightline, { precision: 3 }) + " away\n"
}
}

@@ -2219,6 +2240,9 @@ function removeEntity(element) {
topName.parentElement.removeChild(topName);
element.parentElement.removeChild(element);

selectedEntity = null;
prevSelectedEntity = null;
updateRatios();
}

function checkEntity(entity) {


Загрузка…
Отмена
Сохранить