big steppy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

275 lines
6.3 KiB

  1. var baseHeight = 3.65;
  2. var baseMass = 1360;
  3. var scale = 1;
  4. var strolling = false;
  5. var maxStomachDigest = 10;
  6. var maxBowelsDigest = 10;
  7. victims = {};
  8. function toggle_auto()
  9. {
  10. strolling = !strolling;
  11. }
  12. function initVictims()
  13. {
  14. return {
  15. "Person": 0,
  16. "Car": 0,
  17. "Bus": 0,
  18. "Tram": 0,
  19. "Motorcycle": 0,
  20. "House": 0,
  21. "Train": 0,
  22. "Train Car": 0,
  23. "Parking Garage": 0,
  24. "Overpass": 0,
  25. };
  26. };
  27. // lists out total people
  28. function summarize(sum, fatal = true)
  29. {
  30. return "(" + sum["Person"] + " " + (fatal ? "kills" : "people") + ")";
  31. }
  32. var stomach = []
  33. var bowels = []
  34. function getOnePrey(area)
  35. {
  36. var potential = ["Person", "Car", "Bus", "Tram", "House", "Train", "Parking Garage"];
  37. var potAreas = []
  38. potential.forEach(function (x) {
  39. potAreas.push([x,areas[x]]);
  40. });
  41. potAreas = potAreas.sort(function (x,y) {
  42. return x[1] < y[1];
  43. });
  44. for (var i=0; i<potAreas.length; i++) {
  45. x = potAreas[i];
  46. if (x[1] < area) {
  47. return new things[x[0]](1);
  48. }
  49. };
  50. return new Person(1);
  51. }
  52. function getPrey(region, area)
  53. {
  54. switch(region)
  55. {
  56. case "suburb": return suburbPrey(area);
  57. }
  58. }
  59. function suburbPrey(area)
  60. {
  61. return fill_area2(area, {"Person": 0.5, "House": 0.5, "Car": 0.2, "Tram": 0.1, "Bus": 0.1});
  62. }
  63. function updateVictims(type,prey)
  64. {
  65. var sums = prey.sum();
  66. for (var key in sums) {
  67. if (sums.hasOwnProperty(key)) {
  68. victims[type][key] += sums[key];
  69. }
  70. }
  71. }
  72. function scaleAddMass(scale, baseMass, mass)
  73. {
  74. var startMass = Math.pow(scale, 3) * baseMass;
  75. var newMass = startMass + mass;
  76. return Math.pow(newMass / baseMass, 1/3) ;
  77. }
  78. function feed()
  79. {
  80. var prey = getPrey("suburb", 0.5*scale*scale);
  81. var line = prey.eat() + " " + summarize(prey.sum(), false);
  82. var preyMass = prey.sum_property("mass");
  83. scale = scaleAddMass(scale, baseMass, preyMass);
  84. stomach.push(prey);
  85. if (stomach.length == 1)
  86. setTimeout(function() { doDigest("stomach"); }, 15000);
  87. updateVictims("stomach",prey);
  88. update([line]);
  89. }
  90. function stomp()
  91. {
  92. var prey = getPrey("suburb", 1.5*scale*scale);
  93. var line = prey.stomp() + " " + summarize(prey.sum(), true);
  94. var preyMass = prey.sum_property("mass");
  95. scale = scaleAddMass(scale, baseMass, preyMass);
  96. updateVictims("stomped",prey);
  97. update([line]);
  98. }
  99. function anal_vore()
  100. {
  101. var prey = getOnePrey(scale*scale);
  102. var crushed = getPrey("suburb",3*scale*scale);
  103. var line1 = prey.anal_vore() + " " + summarize(prey.sum(), false);
  104. var line2 = crushed.buttcrush() + " " + summarize(crushed.sum(), false)
  105. var preyMass = prey.sum_property("mass");
  106. var crushedMass = prey.sum_property("mass");
  107. scale = scaleAddMass(scale, baseMass, preyMass);
  108. scale = scaleAddMass(scale, baseMass, crushedMass);
  109. bowels.push(prey);
  110. if (bowels.length == 1)
  111. setTimeout(function() { doDigest("bowels"); }, 15000);
  112. updateVictims("bowels",prey);
  113. updateVictims("stomped",crushed);
  114. update([line1,line2]);
  115. }
  116. function update(lines = [])
  117. {
  118. var log = document.getElementById("log");
  119. lines.forEach(function (x) {
  120. var line = document.createElement('div');
  121. line.innerHTML = x;
  122. log.appendChild(line);
  123. });
  124. log.scrollTop = log.scrollHeight;
  125. var height = baseHeight * scale;
  126. var mass = baseMass * Math.pow(scale, 3);
  127. document.getElementById("height").innerHTML = "Height: " + Math.round(height * 3) + " feet";
  128. document.getElementById("mass").innerHTML = "Mass: " + Math.round(mass * 2.2) + " pounds";
  129. for (var type in victims) {
  130. if (victims.hasOwnProperty(type)) {
  131. for (var key in victims[type]){
  132. if (victims[type].hasOwnProperty(key)) {
  133. if (document.getElementById("stats-" + type + "-" + key) == null) {
  134. if (victims[type][key] == 0)
  135. continue;
  136. child = document.createElement('div');
  137. child.id = "stats-" + type + "-" + key;
  138. child.classList.add("stat-line");
  139. document.getElementById("stats-" + type).appendChild(child);
  140. }
  141. document.getElementById("stats-" + type + "-" + key).innerHTML = key + ": " + victims[type][key];
  142. }
  143. }
  144. }
  145. }
  146. }
  147. function pick_move()
  148. {
  149. if (!strolling) {
  150. setTimeout(pick_move, 2000);
  151. return;
  152. }
  153. var choice = Math.random();
  154. if (choice < 0.2) {
  155. anal_vore();
  156. setTimeout(pick_move, 2000);
  157. } else if (choice < 0.6) {
  158. stomp();
  159. setTimeout(pick_move, 2000);
  160. } else {
  161. feed();
  162. setTimeout(pick_move, 2000);
  163. }
  164. }
  165. function grow()
  166. {
  167. scale *= 1.2;
  168. update();
  169. }
  170. // pop the list and digest that object
  171. function doDigest(containerName)
  172. {
  173. var digestType = containerName == "stomach" ? stomach : bowels;
  174. var count = 0
  175. if (containerName == "stomach") {
  176. count = stomach.length;
  177. count = Math.min(count,maxStomachDigest);
  178. } else if (containerName == "bowels") {
  179. count = bowels.length;
  180. count = Math.min(count,maxBowelsDigest);
  181. }
  182. var container = new Container();
  183. while (count > 0) {
  184. --count;
  185. var toDigest = digestType.shift();
  186. if (toDigest.name != "Container")
  187. toDigest = new Container([toDigest]);
  188. container = container.merge(toDigest);
  189. }
  190. var digested = container.sum();
  191. for (var key in victims[containerName]) {
  192. if (victims[containerName].hasOwnProperty(key) && digested.hasOwnProperty(key) ) {
  193. victims["digested"][key] += digested[key];
  194. victims[containerName][key] -= digested[key];
  195. }
  196. }
  197. if (containerName == "stomach")
  198. update(["Your stomach gurgles as it digests " + container.describe() + " " + summarize(container.sum())]);
  199. else if (containerName == "bowels")
  200. update(["Your bowels churn as they absorb " + container.describe() + " " + summarize(container.sum())]);
  201. if (digestType.length > 0) {
  202. setTimeout(function() {
  203. doDigest(containerName);
  204. }, 15000);
  205. }
  206. }
  207. window.addEventListener('load', function(event) {
  208. victims["stomped"] = initVictims();
  209. victims["digested"] = initVictims();
  210. victims["stomach"] = initVictims();
  211. victims["bowels"] = initVictims();
  212. document.getElementById("button-grow").addEventListener("click",grow);
  213. document.getElementById("button-feed").addEventListener("click",feed);
  214. document.getElementById("button-stomp").addEventListener("click",stomp);
  215. document.getElementById("button-anal_vore").addEventListener("click",anal_vore);
  216. document.getElementById("button-stroll").addEventListener("click",toggle_auto);
  217. setTimeout(pick_move, 2000);
  218. update();
  219. });