Преглед изворни кода

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 година
родитељ
комит
173e3d96e6
1 измењених фајлова са 26 додато и 2 уклоњено
  1. +26
    -2
      macrovision.js

+ 26
- 2
macrovision.js Прегледај датотеку

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


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


if (config.showHorizon) { if (config.showHorizon) {
if (selectedEntity !== null) { if (selectedEntity !== null) {
const y = document.querySelector("#entity-" + selectedEntity.index).dataset.y;
const R = math.unit(1.27560e+7, "meters") 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 first = math.multiply(2, math.multiply(R, h))
const second = math.multiply(h, h) const second = math.multiply(h, h)


const sightline = math.sqrt(math.add(first, second)).to(config.height.units[0].unit.name) 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); topName.parentElement.removeChild(topName);
element.parentElement.removeChild(element); element.parentElement.removeChild(element);


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


function checkEntity(entity) { function checkEntity(entity) {


Loading…
Откажи
Сачувај