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.
 
 
 

548 lines
13 KiB

  1. var things =
  2. {
  3. "Container": Container,
  4. "Person": Person,
  5. "Empty Car": EmptyCar,
  6. "Car": Car,
  7. "Bus": Bus,
  8. "Motorcycle": Motorcycle,
  9. "House": House,
  10. "Train": Train,
  11. "Parking Garage": ParkingGarage,
  12. "Overpass": Overpass,
  13. "Tide Pod": TidePod
  14. };
  15. var areas =
  16. {
  17. "Container": 0,
  18. "Person": 3,
  19. "Car": 4,
  20. "Bus": 12,
  21. "Motorcycle": 2,
  22. "House": 1000,
  23. "Train": 10000,
  24. "Parking Garage": 20000,
  25. "Overpass": 10000,
  26. "Tide Pod": 0.01,
  27. };
  28. function fill_area(area, weights = {"Person": 0.1})
  29. {
  30. var testRadius = Math.sqrt(area / Math.PI);
  31. result = []
  32. for (var key in weights) {
  33. if (weights.hasOwnProperty(key)) {
  34. var objArea = areas[key];
  35. var objRadius = Math.sqrt(objArea / Math.PI);
  36. var newRadius = testRadius - objRadius;
  37. if (newRadius > 0) {
  38. var newArea = newRadius * newRadius * Math.PI;
  39. var numObjs = weights[key] * newArea;
  40. if (numObjs < 1) {
  41. numObjs = Math.random() > numObjs ? 0 : 1;
  42. }
  43. else {
  44. numObjs = Math.round(numObjs);
  45. }
  46. if (numObjs > 0)
  47. result.push(new things[key](numObjs));
  48. else {
  49. // try again with a better chance for just one
  50. }
  51. }
  52. }
  53. }
  54. if (result.length > 1)
  55. return new Container(result);
  56. else if (result.length == 1)
  57. return result[0];
  58. else
  59. return new Person();
  60. }
  61. var masses =
  62. {
  63. "Container": 0,
  64. "Person": 80,
  65. "Car": 1000,
  66. "Bus": 5000,
  67. "Motorcycle": 200,
  68. "House": 10000,
  69. "Train": 50000,
  70. "Parking Garage": 100000,
  71. "Overpass": 100000,
  72. "Tide Pod": 1
  73. };
  74. // describes everything in the container
  75. function describe_all(contents) {
  76. var things = [];
  77. for (var key in contents) {
  78. if (contents.hasOwnProperty(key)) {
  79. things.push(contents[key].describe());
  80. }
  81. }
  82. return merge_things(things);
  83. }
  84. function random_desc(list, odds=1) {
  85. if (Math.random() < odds)
  86. return list[Math.floor(Math.random() * list.length)];
  87. else
  88. return "";
  89. }
  90. // combine strings into a list with proper grammar
  91. function merge_things(list,semicolons=false) {
  92. if (list.length == 0) {
  93. return "";
  94. } else if (list.length == 1) {
  95. return list[0];
  96. } else if (list.length == 2) {
  97. return list[0] + " and " + list[1];
  98. } else {
  99. result = "";
  100. list.slice(0,list.length-1).forEach(function(term) {
  101. result += term + ", ";
  102. })
  103. result += "and " + list[list.length-1]
  104. return result;
  105. }
  106. }
  107. // combine the adjectives for something into a single string
  108. function merge_desc(list) {
  109. result = ""
  110. list.forEach(function(term) {
  111. if (term != "")
  112. result += term + " ";
  113. });
  114. // knock off the last space
  115. if (result.length > 0) {
  116. result = result.substring(0, result.length - 1);
  117. }
  118. return result;
  119. }
  120. // maybe make this something that approximates a
  121. // normal distribution; doing this 15,000,000 times is bad...
  122. function distribution(min, max, samples) {
  123. var result = 0;
  124. for (var i = 0; i < samples; i++) {
  125. result += Math.floor(Math.random() * (max - min + 1) + min);
  126. }
  127. return result;
  128. }
  129. /* default actions */
  130. function defaultStomp(thing) {
  131. return function () { return "You crush " + thing.describe() + " underfoot."};
  132. }
  133. function defaultKick(thing) {
  134. return function() { return "You punt " + thing.describe() + ", destroying " + (thing.count > 1 ? "them" : "it") + "."; }
  135. }
  136. function defaultEat(thing) {
  137. return function() { return "You scoop up " + thing.describe() + " and swallow " + (thing.count > 1 ? "them" : "it") + " whole."; }
  138. }
  139. function defaultAnalVore(thing) {
  140. return function() { return "Your ass slams down on " + thing.describe() + ". " + (thing.count > 1 ? "They slide" : "It slides") + " inside with ease."; }
  141. }
  142. function defaultArea(thing) {
  143. return areas[thing.name];
  144. }
  145. function defaultMass(thing) {
  146. return masses[thing.name];
  147. }
  148. function defaultSum(thing) {
  149. return function() {
  150. var counts = {}
  151. if (thing.name != "Container")
  152. counts[thing.name] = thing.count;
  153. for (var key in thing.contents) {
  154. if (thing.contents.hasOwnProperty(key)) {
  155. subcount = thing.contents[key].sum();
  156. for (var subkey in subcount) {
  157. if (!counts.hasOwnProperty(subkey)) {
  158. counts[subkey] = 0;
  159. }
  160. counts[subkey] += subcount[subkey];
  161. }
  162. }
  163. }
  164. return counts;
  165. }
  166. }
  167. function defaultSumProperty(thing) {
  168. return function(prop) {
  169. var total = 0;
  170. total += thing[prop] * thing.count;
  171. for (var key in thing.contents) {
  172. if (thing.contents.hasOwnProperty(key)) {
  173. total += thing.contents[key].sum_property(prop);
  174. }
  175. }
  176. return total;
  177. }
  178. }
  179. function DefaultEntity() {
  180. this.stomp = defaultStomp;
  181. this.eat = defaultEat;
  182. this.kick = defaultKick;
  183. this.anal_vore = defaultAnalVore;
  184. this.sum = defaultSum;
  185. this.area = defaultArea;
  186. this.mass = defaultMass;
  187. this.sum_property = defaultSumProperty;
  188. return this;
  189. }
  190. // god I love reinventing the wheel
  191. function copy_defaults(self,proto) {
  192. for (var key in proto) {
  193. if (proto.hasOwnProperty(key)) {
  194. self[key] = proto[key](self)
  195. }
  196. }
  197. }
  198. function Container(contents = []) {
  199. this.name = "Container";
  200. copy_defaults(this,new DefaultEntity());
  201. this.count = 0;
  202. this.contents = {}
  203. for (var i=0; i < contents.length; i++) {
  204. this.contents[contents[i].name] = contents[i];
  205. }
  206. for (var key in this.contents) {
  207. if (this.contents.hasOwnProperty(key)) {
  208. this.count += this.contents[key].count;
  209. }
  210. }
  211. this.describe = function() {
  212. return describe_all(this.contents)
  213. }
  214. return this;
  215. }
  216. function Person(count = 1) {
  217. this.name = "Person";
  218. copy_defaults(this,new DefaultEntity());
  219. this.count = count;
  220. this.contents = {};
  221. this.describeOne = function (verbose=true) {
  222. sex = random_desc(["male", "female"], (verbose ? 1 : 0));
  223. body = random_desc(["skinny","fat","tall","short","stocky","spindly"], (verbose ? 0.6 : 0));
  224. species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]);
  225. return "a " + merge_desc([sex,body,species]);
  226. }
  227. this.describe = function() {
  228. if (count <= 3) {
  229. list = [];
  230. for (var i = 0; i < count; i++) {
  231. list.push(this.describeOne(this.count <= 2));
  232. }
  233. return merge_things(list);
  234. } else {
  235. return this.count + " people"
  236. }
  237. }
  238. return this;
  239. }
  240. function TidePod(count = 1) {
  241. this.name = "Tide Pod";
  242. copy_defaults(this,new DefaultEntity());
  243. this.count = count;
  244. this.contents = {};
  245. this.describeOne = function (verbose=true) {
  246. species = random_desc(["delicious","scrumptious","savory"]);
  247. return "a " + merge_desc([species,"tide pod"]);
  248. }
  249. this.describe = function() {
  250. if (count <= 3) {
  251. list = [];
  252. for (var i = 0; i < count; i++) {
  253. list.push(this.describeOne(this.count <= 2));
  254. }
  255. return merge_things(list);
  256. } else {
  257. return this.count + " tide pods"
  258. }
  259. }
  260. return this;
  261. }
  262. function EmptyCar(count = 1) {
  263. this.name = "Car";
  264. copy_defaults(this,new DefaultEntity());
  265. this.count = count;
  266. this.contents = {};
  267. this.describeOne = function() {
  268. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"]);
  269. adjective = random_desc(["rusty","brand-new"],0.3);
  270. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  271. return "a parked " + merge_desc([adjective,color,type]);
  272. }
  273. this.describe = function() {
  274. if (this.count <= 3) {
  275. list = [];
  276. for (var i = 0; i < this.count; i++) {
  277. list.push(this.describeOne());
  278. }
  279. return merge_things(list);
  280. } else {
  281. return this.count + " parked cars";
  282. }
  283. }
  284. }
  285. function Car(count = 1) {
  286. this.name = "Car";
  287. copy_defaults(this,new DefaultEntity());
  288. this.count = count;
  289. this.contents = {};
  290. var amount = distribution(2,5,count);
  291. this.contents.person = new Person(amount);
  292. this.describeOne = function(verbose=true) {
  293. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"], (verbose ? 1 : 0));
  294. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  295. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  296. return "a " + merge_desc([adjective,color,type]);
  297. }
  298. this.describe = function() {
  299. if (this.count <= 3) {
  300. list = [];
  301. for (var i = 0; i < this.count; i++) {
  302. list.push(this.describeOne(this.count < 2));
  303. }
  304. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  305. } else {
  306. return this.count + " cars with " + this.contents.person.describe() + " inside";
  307. }
  308. }
  309. }
  310. function Bus(count = 1) {
  311. this.name = "Bus";
  312. copy_defaults(this,new DefaultEntity());
  313. this.count = count;
  314. this.contents = {};
  315. var amount = distribution(10,35,count);
  316. this.contents.person = new Person(amount);
  317. this.describeOne = function(verbose=true) {
  318. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  319. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  320. type = random_desc(["bus","double-decker bus","articulating bus"]);
  321. return "a " + merge_desc([adjective,color,type]);
  322. }
  323. this.describe = function() {
  324. if (this.count <= 3) {
  325. list = [];
  326. for (var i = 0; i < this.count; i++) {
  327. list.push(this.describeOne(this.count < 2));
  328. }
  329. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  330. } else {
  331. return this.count + " buses with " + this.contents.person.describe() + " inside";
  332. }
  333. }
  334. }
  335. function Motorcycle(count = 1) {
  336. this.name = "Motorcycle";
  337. copy_defaults(this,new DefaultEntity());
  338. this.count = count;
  339. this.contents = {};
  340. var amount = distribution(1,2,count);
  341. this.contents.person = new Person(amount);
  342. }
  343. function Train(count = 1) {
  344. this.name = "Train";
  345. copy_defaults(this,new DefaultEntity());
  346. this.count = count;
  347. this.contents = {};
  348. var amount = distribution(50,250,count);
  349. this.contents.person = new Person(amount);
  350. amount = distribution(10,50,count);
  351. this.contents.emptycar = new EmptyCar(amount);
  352. this.describeOne = function(verbose=true) {
  353. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  354. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  355. type = random_desc(["train","passenger train","freight train"]);
  356. return "a " + merge_desc([adjective,color,type]);
  357. }
  358. this.describe = function() {
  359. if (this.count <= 3) {
  360. list = [];
  361. for (var i = 0; i < this.count; i++) {
  362. list.push(this.describeOne(this.count < 2));
  363. }
  364. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  365. } else {
  366. return this.count + " trains with " + describe_all(this.contents) + " inside";
  367. }
  368. }
  369. }
  370. function House(count = 1) {
  371. this.name = "House";
  372. copy_defaults(this,new DefaultEntity());
  373. this.count = count;
  374. this.contents = {};
  375. var amount = distribution(0,8,count);
  376. this.contents.person = new Person(amount);
  377. amount = distribution(0,2,count);
  378. this.contents.emptycar = new EmptyCar(amount);
  379. this.describeOne = function(verbose=true) {
  380. size = random_desc(["little","two-story","large"], (verbose ? 0.5 : 0));
  381. color = random_desc(["blue","white","gray","tan","green"], (verbose ? 0.5 : 0));
  382. name = random_desc(["house","house","house","house","house","trailer"], 1);
  383. return "a " + merge_desc([size,color,name]);
  384. }
  385. this.describe = function() {
  386. if (this.count <= 3) {
  387. list = [];
  388. for (var i = 0; i < this.count; i++) {
  389. list.push(this.describeOne(this.count < 2));
  390. }
  391. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  392. } else {
  393. return this.count + " homes with " + this.contents.person.describe() + " inside";
  394. }
  395. }
  396. }
  397. function ParkingGarage(count = 1) {
  398. this.name = "Parking Garage";
  399. copy_defaults(this,new DefaultEntity());
  400. this.count = count;
  401. this.contents = {};
  402. var amount = distribution(10,200,count);
  403. this.contents.person = new Person(amount);
  404. amount = distribution(30,100,count);
  405. this.contents.emptycar = new EmptyCar(amount);
  406. amount = distribution(5,20,count);
  407. this.contents.car = new Car(amount);
  408. this.describeOne = function(verbose=true) {
  409. return "a parking garage";
  410. }
  411. this.describe = function() {
  412. if (this.count <= 3) {
  413. list = [];
  414. for (var i = 0; i < this.count; i++) {
  415. list.push(this.describeOne(this.count < 2));
  416. }
  417. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  418. } else {
  419. return this.count + " parking garages with " + describe_all(this.contents) + " inside";
  420. }
  421. }
  422. }
  423. function Overpass(count = 1) {
  424. this.name = "Overpass";
  425. copy_defaults(this,new DefaultEntity());
  426. this.count = count;
  427. this.contents = {};
  428. var amount = distribution(0,20,count);
  429. this.contents.person = new Person(amount);
  430. amount = distribution(25,100,count);
  431. this.contents.car = new Car(amount);
  432. }