555 lines
16 KiB
JavaScript
555 lines
16 KiB
JavaScript
var landmarks = [
|
|
{
|
|
"name": "Nauvoo",
|
|
"distainst": 0,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "Sugar Creek",
|
|
"distainst": 7,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "Richardson's Point",
|
|
"distainst": 35,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Chariton River Crossing",
|
|
"distainst": 80,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "Locust Creek",
|
|
"distainst": 103,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "Garden Grove",
|
|
"distainst": 128,
|
|
"type": "settlement",
|
|
"active": true
|
|
}, {
|
|
"name": "Mount Pisgah",
|
|
"distainst": 153,
|
|
"type": "settlement",
|
|
"active": true
|
|
}, {
|
|
"name": "Nishnabotna River Crossing",
|
|
"distainst": 232,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "Grand Encampment", // Mormon Battalion Leaves
|
|
"distainst": 255,
|
|
"type": "camp",
|
|
"active": true
|
|
}, {
|
|
"name": "Kanesville",
|
|
"distainst": 265,
|
|
"type": "settlement",
|
|
"active": true
|
|
}, {
|
|
"name": "Winter Quarters",
|
|
"distainst": 266,
|
|
"type": "settlement",
|
|
"active": true
|
|
}, {
|
|
"name": "Elkhorn River",
|
|
"distainst": 293,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "Platte River",
|
|
"distainst": 305,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "Loup Fork",
|
|
"distainst": 352,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "Fort Kearny",
|
|
"distainst": 469,
|
|
"type": "fort",
|
|
"active": true
|
|
}, {
|
|
"name": "Confluence Point",
|
|
"distainst": 563,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Ash Hollow",
|
|
"distainst": 646,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Chimney Rock",
|
|
"distainst": 718,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Scotts Bluff",
|
|
"distainst": 738,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Fort Laramie",
|
|
"distainst": 788,
|
|
"type": "fort",
|
|
"active": true
|
|
}, {
|
|
"name": "Upper Platte",
|
|
"distainst": 914,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "Red Butte",
|
|
"distainst": 940,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Sweetwater River",
|
|
"distainst": 964,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "Independence Rock",
|
|
"distainst": 965,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Devil's Gate",
|
|
"distainst": 970,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Martin's Cove",
|
|
"distainst": 993,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Rocky Ridge",
|
|
"distainst": 1038,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Rock Creek",
|
|
"distainst": 1048,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "South Pass",
|
|
"distainst": 1065,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Green River",
|
|
"distainst": 1128,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "Ft. Bridger",
|
|
"distainst": 1183,
|
|
"type": "fort",
|
|
"active": true
|
|
}, {
|
|
"name": "Bear River",
|
|
"distainst": 1216,
|
|
"type": "river",
|
|
"active": true
|
|
}, {
|
|
"name": "The Needles",
|
|
"distainst": 1236,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Echo Canyon",
|
|
"distainst": 1246,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Big Mountain",
|
|
"distainst": 1279,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Golden Pass Road",
|
|
"distainst": 1281,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Emigration Canyon",
|
|
"distainst": 1283,
|
|
"type": "landmark",
|
|
"active": true
|
|
}, {
|
|
"name": "Salt Lake Valley",
|
|
"distainst": 1297,
|
|
"type": "seattlement",
|
|
"active": true
|
|
}
|
|
]
|
|
var train = {
|
|
dis: 0,
|
|
paused: false,
|
|
stopped: false,
|
|
river: false,
|
|
delayed: false,
|
|
resting: false,
|
|
tavelingTo: 0
|
|
}
|
|
var date = {
|
|
days: Math.floor(Math.random() * 90) + 60, // Days from January 1, 1846 (0 == January 1, 1846) (63553 == January 1, 2020)
|
|
months: ["Maytember",
|
|
"January",
|
|
"Febuary",
|
|
"March",
|
|
"April",
|
|
"May",
|
|
"June",
|
|
"July",
|
|
"August",
|
|
"September",
|
|
"October",
|
|
"November",
|
|
"December"],
|
|
weekdays: ["Sunday",
|
|
"Monday",
|
|
"Tuesday",
|
|
"Wednesday",
|
|
"Thursday",
|
|
"Friday",
|
|
"Saturday"],
|
|
year: function (d) {
|
|
var y = 2;
|
|
while ((d >= 365 && (y) % 4 != 0) || d >= 366) {
|
|
if (y++ % 4 == 0)
|
|
d -= 366;
|
|
else
|
|
d -= 365;
|
|
}
|
|
y += 1844;
|
|
return y;
|
|
},
|
|
dayOfYear: function (d) {
|
|
var y = 2;
|
|
while ((d >= 365 && (y) % 4 != 0) || d >= 366) {
|
|
if (y++ % 4 == 0)
|
|
d -= 366;
|
|
else
|
|
d -= 365;
|
|
}
|
|
return d;
|
|
},
|
|
month: function (day) {
|
|
var m = 0;
|
|
var d = this.dayOfYear(day) + 1;
|
|
if (this.year(day) % 4 == 0) {
|
|
if (d <= 31)
|
|
m = 1;
|
|
else if (d <= 60)
|
|
m = 2;
|
|
else if (d <= 91)
|
|
m = 3;
|
|
else if (d <= 121)
|
|
m = 4;
|
|
else if (d <= 152)
|
|
m = 5;
|
|
else if (d <= 182)
|
|
m = 6;
|
|
else if (d <= 213)
|
|
m = 7;
|
|
else if (d <= 244)
|
|
m = 8;
|
|
else if (d <= 274)
|
|
m = 9;
|
|
else if (d <= 305)
|
|
m = 10;
|
|
else if (d <= 335)
|
|
m = 11;
|
|
else if (d <= 366)
|
|
m = 12;
|
|
} else {
|
|
if (d <= 31)
|
|
m = 1;
|
|
else if (d <= 59)
|
|
m = 2;
|
|
else if (d <= 90)
|
|
m = 3;
|
|
else if (d <= 120)
|
|
m = 4;
|
|
else if (d <= 151)
|
|
m = 5;
|
|
else if (d <= 181)
|
|
m = 6;
|
|
else if (d <= 212)
|
|
m = 7;
|
|
else if (d <= 243)
|
|
m = 8;
|
|
else if (d <= 273)
|
|
m = 9;
|
|
else if (d <= 304)
|
|
m = 10;
|
|
else if (d <= 334)
|
|
m = 11;
|
|
else if (d <= 365)
|
|
m = 12;
|
|
}
|
|
return m;
|
|
},
|
|
dayOfMonth: function (day) {
|
|
var d = (this.dayOfYear(day)) + 1;
|
|
if (this.year(day) % 4 == 0) {
|
|
if (d <= 31);
|
|
else if (d <= 60)
|
|
d -= 31;
|
|
else if (d <= 91)
|
|
d -= 60;
|
|
else if (d <= 121)
|
|
d -= 91;
|
|
else if (d <= 152)
|
|
d -= 121;
|
|
else if (d <= 182)
|
|
d -= 152;
|
|
else if (d <= 213)
|
|
d -= 182;
|
|
else if (d <= 244)
|
|
d -= 213;
|
|
else if (d <= 274)
|
|
d -= 244;
|
|
else if (d <= 305)
|
|
d -= 274;
|
|
else if (d <= 335)
|
|
d -= 305;
|
|
else if (d <= 366)
|
|
d -= 335;
|
|
} else {
|
|
if (d <= 31);
|
|
else if (d <= 59)
|
|
d -= 31;
|
|
else if (d <= 90)
|
|
d -= 59;
|
|
else if (d <= 120)
|
|
d -= 90;
|
|
else if (d <= 151)
|
|
d -= 120;
|
|
else if (d <= 181)
|
|
d -= 151;
|
|
else if (d <= 212)
|
|
d -= 181;
|
|
else if (d <= 243)
|
|
d -= 212;
|
|
else if (d <= 273)
|
|
d -= 243;
|
|
else if (d <= 304)
|
|
d -= 273;
|
|
else if (d <= 334)
|
|
d -= 304;
|
|
else if (d <= 365)
|
|
d -= 334;
|
|
}
|
|
return d;
|
|
},
|
|
dayOfWeek: function (day) {
|
|
var y = this.year(day);
|
|
var leap = 0;
|
|
if (y % 4 == 0)
|
|
leap = 1
|
|
return ((2 + y + Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400) - 2 - leap) + this.dayOfYear(day)) % 7;
|
|
},
|
|
printedDate: function (day) {
|
|
return this.weekdays[this.dayOfWeek(day)] + ", " + this.months[this.month(day)] + " " + String(this.dayOfMonth(day)) + ", " + String(this.year(day));
|
|
}
|
|
}
|
|
var weather = {
|
|
seeds: [Math.random() / 1,
|
|
Math.random() / 1,
|
|
Math.random() / 1,
|
|
Math.random() / 1,
|
|
Math.random() / 1,
|
|
Math.random() / 1],
|
|
tempeture: function (day) {
|
|
var month = date.month(day);
|
|
var temp = [-10, 30, 40, 50, 60, 70, 80, 90, 80, 70, 60, 50, 40];
|
|
//var add = 0;
|
|
return ((Math.sin(day * this.seeds[0] + this.seeds[1]) * Math.cos(day * this.seeds[2] + this.seeds[3]) * -10) + (Math.sin(day * this.seeds[4] + this.seeds[5]) * 1)) + temp[month];
|
|
},
|
|
clouds: function (day) {
|
|
return ((Math.sin(day * this.seeds[0] + this.seeds[1]) * Math.cos(day * this.seeds[2] + this.seeds[3])) + 1) / 2;
|
|
},
|
|
printWeather: function (day) {
|
|
if (this.clouds(day) > 0.98)
|
|
return "Hail";
|
|
else if (this.clouds(day) > 0.95)
|
|
if (this.tempeture(day) >= 40)
|
|
return "Heavy Rain";
|
|
else
|
|
return "Blizzard";
|
|
else if (this.clouds(day) > 0.85)
|
|
if (this.tempeture(day) >= 40)
|
|
return "Rain";
|
|
else
|
|
return "Snow";
|
|
else if (this.clouds(day) > 0.75)
|
|
return "Partly Cloudy";
|
|
else if (this.clouds(day) > 0.50)
|
|
return "Mostly Sunny";
|
|
else
|
|
return "Sunny";
|
|
},
|
|
printTempeture: function (day) {
|
|
if (this.tempeture(day) > 100)
|
|
return "Extreamly Hot";
|
|
else if (this.tempeture(day) > 85)
|
|
return "Hot";
|
|
else if (this.tempeture(day) > 55)
|
|
return "Warm";
|
|
else if (this.tempeture(day) > 20)
|
|
return "Cold";
|
|
else
|
|
return "Extreamly Cold";
|
|
}
|
|
}
|
|
var funcs = {
|
|
nextLandmarkIndex: function () {
|
|
for (var i = 0; i < landmarks.length; i++) {
|
|
if (landmarks[i].distainst > train.dis)
|
|
return i;
|
|
}
|
|
if (landmarks[landmarks.length - 1].distainst < train.dis)
|
|
return landmarks.length - 1;
|
|
else
|
|
return 0;
|
|
},
|
|
nextLandmark: function () {
|
|
return landmarks[this.nextLandmarkIndex()];
|
|
},
|
|
pausedText: function () {
|
|
if (train.paused) {
|
|
return "Play";
|
|
} else if (train.stopped || train.river) {
|
|
return "Continue";
|
|
} else {
|
|
return "Pause";
|
|
}
|
|
}
|
|
}
|
|
var log = []
|
|
|
|
function print(str) {
|
|
if (!log.includes(date.printedDate(date.days))) {
|
|
log.push("");
|
|
log.push(date.printedDate(date.days));
|
|
}
|
|
log.push(str);
|
|
|
|
}
|
|
|
|
function visitLandmark(index) {
|
|
train.dis = landmarks[index].distainst;
|
|
if (landmarks[index].type == "river")
|
|
train.river = true;
|
|
else
|
|
train.stopped = true;
|
|
|
|
print("Welcome to: " + landmarks[index].name);
|
|
updateScreen();
|
|
}
|
|
|
|
function crossRiver(index) {
|
|
document.getElementById("game").innerHTML = "<p>" + landmarks[index].name + " - River Crossing</p>";
|
|
date.days++;
|
|
}
|
|
|
|
function updateScreen() {
|
|
document.getElementById("date").innerHTML = "Date: " + date.printedDate(date.days);
|
|
document.getElementById("weather").innerHTML = "Weather: " + weather.printWeather(date.days);
|
|
//document.getElementById("tempature").innerHTML = "Tempature: " + String(weather.tempeture(date.days));
|
|
document.getElementById("tempature").innerHTML = "Tempature: " + weather.printTempeture(date.days);
|
|
document.getElementById("nextLandmark").innerHTML = "Next Landmark: " + funcs.nextLandmark().name;
|
|
document.getElementById("disToLandmark").innerHTML = "To Landmark: " + String(Math.abs(train.dis - funcs.nextLandmark().distainst)) + " mi";
|
|
document.getElementById("disTraveled").innerHTML = "Traveled: " + String(train.dis) + " mi";
|
|
document.getElementById("percentage").innerHTML = String(Math.floor(train.dis / landmarks[landmarks.length - 1].distainst * 1000) / 10) + " %";
|
|
document.getElementById("pause").innerHTML = funcs.pausedText();
|
|
|
|
var logText = "";
|
|
|
|
for (var i = 0; i < log.length; i++)
|
|
logText = log[i] + "<br>" + logText;
|
|
|
|
document.getElementById("log").innerHTML = logText;
|
|
}
|
|
|
|
updateScreen();
|
|
visitLandmark(train.tavelingTo++);
|
|
|
|
document.getElementById("pause").addEventListener("click", function () {
|
|
if (train.stopped)
|
|
train.stopped = false;
|
|
else if (train.river) {
|
|
//crossRiver(train.tavelingTo - 1);
|
|
train.river = false;
|
|
} else
|
|
train.paused = !train.paused;
|
|
updateScreen();
|
|
});
|
|
document.getElementById("map").addEventListener("click", function () {
|
|
document.getElementById("game").innerHTML = ""
|
|
});
|
|
document.getElementById("status").addEventListener("click", function () {
|
|
document.getElementById("game").innerHTML = "<p>status</p>"
|
|
});
|
|
document.getElementById("trade").addEventListener("click", function () {
|
|
document.getElementById("game").innerHTML = "<p>WIP</p>"
|
|
});
|
|
document.getElementById("buy").addEventListener("click", function () {
|
|
document.getElementById("game").innerHTML = "<p>WIP</p>"
|
|
});
|
|
document.getElementById("pace").addEventListener("click", function () {
|
|
document.getElementById("game").innerHTML = "<p>WIP</p>"
|
|
});
|
|
document.getElementById("rations").addEventListener("click", function () {
|
|
document.getElementById("game").innerHTML = "<p>WIP</p>"
|
|
});
|
|
document.getElementById("rest").addEventListener("click", function () {
|
|
document.getElementById("game").innerHTML = "<p>WIP</p>"
|
|
});
|
|
document.getElementById("downloadLog").addEventListener("click", function () {
|
|
var logText = "";
|
|
for (var i = 0; i < log.length; i++)
|
|
logText += log[i] + "\n";
|
|
//console.log(logText);
|
|
|
|
var filename = "log.txt";
|
|
var file = new Blob([logText], {
|
|
type: typeof (logText)
|
|
});
|
|
var a = document.createElement("a"),
|
|
url = URL.createObjectURL(file);
|
|
a.href = url;
|
|
a.download = filename;
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
setTimeout(function () {
|
|
document.body.removeChild(a);
|
|
window.URL.revokeObjectURL(url);
|
|
}, 0);
|
|
|
|
});
|
|
|
|
setInterval(function mainLoop() {
|
|
if (!train.paused && !train.stopped && !train.river) {
|
|
date.days++;
|
|
if (date.dayOfWeek(date.days) != 0 && !train.delayed && !train.resting && weather.clouds(date.days) < 0.95)
|
|
train.dis += Math.floor(Math.random() * 30);
|
|
else if (weather.clouds(date.days) > 0.95)
|
|
print("Severe Weather!");
|
|
}
|
|
if (landmarks[train.tavelingTo].distainst <= train.dis) {
|
|
visitLandmark(train.tavelingTo++);
|
|
}
|
|
updateScreen();
|
|
}, 500);
|