Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function runSurvivalSimulation() {
- // Initial values
- var food = 100;
- var shelter = 100;
- var security = 100;
- var comms = 100;
- var daysLeft = 90;
- var daysIn = 0;
- var survive = true;
- var daysWithoutFood = 0;
- var maxDaysWithoutFood = 7;
- var failureReason = "";
- var initialFailureDay = 0;
- var initialFailureCause = "";
- // Reset variables at the start of each run
- player.SetVar("Survive", true);
- player.SetVar("DaysWithoutFood", 0);
- player.SetVar("DaysIn", 0);
- player.SetVar("FailureReason", "");
- // Team composition
- var teamA = player.GetVar("Person_A");
- var teamB = player.GetVar("Person_B");
- var teamC = player.GetVar("Person_C");
- // Calculate daily resource changes
- var foodChange = -1.3;
- var shelterChange = -0.2;
- var securityChange = -0.5;
- var commsChange = -0.3;
- if (teamA) {
- foodChange += 1.2;
- shelterChange -= 0.05;
- securityChange -= 0.3;
- commsChange -= 0.1;
- }
- if (teamB) {
- foodChange -= 0.2;
- shelterChange -= 0.05;
- securityChange -= 0.3;
- commsChange += 0.3;
- }
- if (teamC) {
- foodChange -= 0.2;
- shelterChange += 0.05;
- securityChange += 0.5;
- commsChange += 0.3;
- }
- // Additional security penalty for A+B combination
- if (teamA && teamB && !teamC) {
- securityChange -= 0.2; // Increase security depletion rate for A+B
- }
- function getRandomPenalty(min, max) {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- function updateResources() {
- // Update resources
- food = Math.max(0, Math.min(100, food + foodChange));
- shelter = Math.max(0, Math.min(100, shelter + shelterChange));
- security = Math.max(0, Math.min(100, security + securityChange));
- comms = Math.max(0, Math.min(100, comms + commsChange));
- daysLeft--;
- daysIn++;
- console.log(`Day ${daysIn} (${daysLeft} left): Food=${food.toFixed(2)}, Shelter=${shelter.toFixed(2)}, Security=${security.toFixed(2)}, Comms=${comms.toFixed(2)}, DaysWithoutFood=${daysWithoutFood}`);
- // Apply cascading effects
- if (security < 40) {
- var severeFoodPenalty = getRandomPenalty(10, 20);
- var severeShelterPenalty = getRandomPenalty(5, 15);
- var severeCommsPenalty = getRandomPenalty(15, 25);
- food -= severeFoodPenalty;
- shelter -= severeShelterPenalty;
- comms -= severeCommsPenalty;
- console.log(`Day ${daysIn}: Security breach! Lost ${severeFoodPenalty} Food and Water, ${severeShelterPenalty} Shelter, and ${severeCommsPenalty} Comms.`);
- if (initialFailureCause === "") {
- initialFailureDay = daysIn;
- initialFailureCause = "Security";
- }
- }
- if (shelter < 50) {
- var criticalFoodPenalty = getRandomPenalty(5, 10);
- food -= criticalFoodPenalty;
- console.log(`Day ${daysIn}: Critical shelter condition! Lost ${criticalFoodPenalty} Food and Water due to exposure.`);
- }
- // Ensure resources don't go below 0
- food = Math.max(0, food);
- shelter = Math.max(0, shelter);
- security = Math.max(0, security);
- comms = Math.max(0, Math.min(100, comms));
- // Check for food depletion
- if (food <= 0) {
- daysWithoutFood++;
- player.SetVar("DaysWithoutFood", daysWithoutFood);
- console.log(`Day ${daysIn}: No food and water! Days without sustenance: ${daysWithoutFood}`);
- if (initialFailureCause === "") {
- initialFailureDay = daysIn;
- initialFailureCause = "Food";
- }
- } else {
- daysWithoutFood = 0;
- player.SetVar("DaysWithoutFood", 0);
- }
- // Update Storyline variables
- player.SetVar("Food", Math.round(food));
- player.SetVar("Shelter", Math.round(shelter));
- player.SetVar("Security", Math.round(security));
- player.SetVar("Comms", Math.round(comms));
- player.SetVar("DaysLeft", daysLeft);
- player.SetVar("DaysIn", daysIn);
- // Continue simulation if there are still days left and haven't exceeded max days without food
- if (daysLeft > 0 && daysWithoutFood < maxDaysWithoutFood) {
- setTimeout(updateResources, 400); // Run every 0.4 seconds
- } else {
- endSimulation();
- }
- }
- function endSimulation() {
- // Determine survival and failure reason
- if (daysWithoutFood >= maxDaysWithoutFood) {
- survive = false;
- if (initialFailureCause === "Security") {
- failureReason = `On day ${initialFailureDay}, the security shields dropped below 40%, allowing hostile local wildlife to destroy the homing beacon, damage your shelter, and consume your food and water stores. This led to complete depletion of sustenance on day ${daysIn - daysWithoutFood} and severe damage to your communications system. You lasted ${daysWithoutFood} more days without food and water before perishing from starvation, dehydration, and exposure to the elements.`;
- } else {
- if (comms >= 90) {
- failureReason = `On day ${initialFailureDay}, you ran out of food and drinking water. You lasted ${daysWithoutFood} more days without sustenance before perishing from starvation, dehydration, and exposure to the elements. Ironically, your communication system continued to broadcast a strong signal, though the camp fell eerily silent. The rescue team will find a fully functioning beacon, but no survivors.`;
- } else {
- failureReason = `On day ${initialFailureDay}, you ran out of food and drinking water. You lasted ${daysWithoutFood} more days without sustenance before perishing from starvation, dehydration, and exposure to the elements.`;
- }
- }
- } else if (daysLeft === 0) {
- if (comms < 90 || comms > 100) {
- survive = false;
- failureReason = `On the final day, your homing beacon failed to maintain the required signal strength (${comms.toFixed(2)}%), leaving you stranded on the planet despite surviving for 90 days.`;
- } else {
- survive = true;
- failureReason = "Congratulations! Your crew successfully survived the full 90 days until rescue arrived. Through careful resource management and strategic decision-making, you maintained your food and water supplies, kept your shelter intact, defended against wildlife, and maintained a strong communication signal.";
- }
- }
- // Round down all values at the end of the simulation
- food = Math.floor(food);
- shelter = Math.floor(shelter);
- security = Math.floor(security);
- comms = Math.floor(comms);
- // Update Storyline variables with final values
- player.SetVar("Food", food);
- player.SetVar("Shelter", shelter);
- player.SetVar("Security", security);
- player.SetVar("Comms", comms);
- player.SetVar("DaysLeft", daysLeft);
- player.SetVar("DaysIn", daysIn);
- player.SetVar("Survive", survive);
- player.SetVar("FailureReason", failureReason);
- console.log(`Simulation ended. ${failureReason}`);
- }
- // Start the simulation
- updateResources();
- }
- // Run the simulation
- runSurvivalSimulation();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement