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.
 
 
 

563 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. // put another container into this one
  215. this.merge = function(container) {
  216. for (var key in container.contents) {
  217. if (container.contents.hasOwnProperty(key)) {
  218. if (this.contents.hasOwnProperty(key)) {
  219. this.count += container.contents[key].count;
  220. this.contents[key] = new things[container.contents[key].name](container.contents[key].count + this.contents[key].count);
  221. } else {
  222. this.count += container.contents[key].count;
  223. this.contents[key] = new things[container.contents[key].name](container.contents[key].count);
  224. }
  225. }
  226. }
  227. }
  228. return this;
  229. }
  230. function Person(count = 1) {
  231. this.name = "Person";
  232. copy_defaults(this,new DefaultEntity());
  233. this.count = count;
  234. this.contents = {};
  235. this.describeOne = function (verbose=true) {
  236. sex = random_desc(["male", "female"], (verbose ? 1 : 0));
  237. body = random_desc(["skinny","fat","tall","short","stocky","spindly"], (verbose ? 0.6 : 0));
  238. species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]);
  239. return "a " + merge_desc([sex,body,species]);
  240. }
  241. this.describe = function() {
  242. if (count <= 3) {
  243. list = [];
  244. for (var i = 0; i < count; i++) {
  245. list.push(this.describeOne(this.count <= 2));
  246. }
  247. return merge_things(list);
  248. } else {
  249. return this.count + " people"
  250. }
  251. }
  252. return this;
  253. }
  254. function TidePod(count = 1) {
  255. this.name = "Tide Pod";
  256. copy_defaults(this,new DefaultEntity());
  257. this.count = count;
  258. this.contents = {};
  259. this.describeOne = function (verbose=true) {
  260. species = random_desc(["delicious","scrumptious","savory"]);
  261. return "a " + merge_desc([species,"tide pod"]);
  262. }
  263. this.describe = function() {
  264. if (count <= 3) {
  265. list = [];
  266. for (var i = 0; i < count; i++) {
  267. list.push(this.describeOne(this.count <= 2));
  268. }
  269. return merge_things(list);
  270. } else {
  271. return this.count + " tide pods"
  272. }
  273. }
  274. return this;
  275. }
  276. function EmptyCar(count = 1) {
  277. this.name = "Car";
  278. copy_defaults(this,new DefaultEntity());
  279. this.count = count;
  280. this.contents = {};
  281. this.describeOne = function() {
  282. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"]);
  283. adjective = random_desc(["rusty","brand-new"],0.3);
  284. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  285. return "a parked " + merge_desc([adjective,color,type]);
  286. }
  287. this.describe = function() {
  288. if (this.count <= 3) {
  289. list = [];
  290. for (var i = 0; i < this.count; i++) {
  291. list.push(this.describeOne());
  292. }
  293. return merge_things(list);
  294. } else {
  295. return this.count + " parked cars";
  296. }
  297. }
  298. }
  299. function Car(count = 1) {
  300. this.name = "Car";
  301. copy_defaults(this,new DefaultEntity());
  302. this.count = count;
  303. this.contents = {};
  304. var amount = distribution(2,5,count);
  305. this.contents.person = new Person(amount);
  306. this.describeOne = function(verbose=true) {
  307. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"], (verbose ? 1 : 0));
  308. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  309. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  310. return "a " + merge_desc([adjective,color,type]);
  311. }
  312. this.describe = function() {
  313. if (this.count <= 3) {
  314. list = [];
  315. for (var i = 0; i < this.count; i++) {
  316. list.push(this.describeOne(this.count < 2));
  317. }
  318. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  319. } else {
  320. return this.count + " cars with " + this.contents.person.describe() + " inside";
  321. }
  322. }
  323. }
  324. function Bus(count = 1) {
  325. this.name = "Bus";
  326. copy_defaults(this,new DefaultEntity());
  327. this.count = count;
  328. this.contents = {};
  329. var amount = distribution(10,35,count);
  330. this.contents.person = new Person(amount);
  331. this.describeOne = function(verbose=true) {
  332. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  333. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  334. type = random_desc(["bus","double-decker bus","articulating bus"]);
  335. return "a " + merge_desc([adjective,color,type]);
  336. }
  337. this.describe = function() {
  338. if (this.count <= 3) {
  339. list = [];
  340. for (var i = 0; i < this.count; i++) {
  341. list.push(this.describeOne(this.count < 2));
  342. }
  343. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  344. } else {
  345. return this.count + " buses with " + this.contents.person.describe() + " inside";
  346. }
  347. }
  348. }
  349. function Motorcycle(count = 1) {
  350. this.name = "Motorcycle";
  351. copy_defaults(this,new DefaultEntity());
  352. this.count = count;
  353. this.contents = {};
  354. var amount = distribution(1,2,count);
  355. this.contents.person = new Person(amount);
  356. }
  357. function Train(count = 1) {
  358. this.name = "Train";
  359. copy_defaults(this,new DefaultEntity());
  360. this.count = count;
  361. this.contents = {};
  362. var amount = distribution(50,250,count);
  363. this.contents.person = new Person(amount);
  364. amount = distribution(10,50,count);
  365. this.contents.emptycar = new EmptyCar(amount);
  366. this.describeOne = function(verbose=true) {
  367. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  368. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  369. type = random_desc(["train","passenger train","freight train"]);
  370. return "a " + merge_desc([adjective,color,type]);
  371. }
  372. this.describe = function() {
  373. if (this.count <= 3) {
  374. list = [];
  375. for (var i = 0; i < this.count; i++) {
  376. list.push(this.describeOne(this.count < 2));
  377. }
  378. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  379. } else {
  380. return this.count + " trains with " + describe_all(this.contents) + " inside";
  381. }
  382. }
  383. }
  384. function House(count = 1) {
  385. this.name = "House";
  386. copy_defaults(this,new DefaultEntity());
  387. this.count = count;
  388. this.contents = {};
  389. var amount = distribution(0,8,count);
  390. this.contents.person = new Person(amount);
  391. amount = distribution(0,2,count);
  392. this.contents.emptycar = new EmptyCar(amount);
  393. this.describeOne = function(verbose=true) {
  394. size = random_desc(["little","two-story","large"], (verbose ? 0.5 : 0));
  395. color = random_desc(["blue","white","gray","tan","green"], (verbose ? 0.5 : 0));
  396. name = random_desc(["house","house","house","house","house","trailer"], 1);
  397. return "a " + merge_desc([size,color,name]);
  398. }
  399. this.describe = function() {
  400. if (this.count <= 3) {
  401. list = [];
  402. for (var i = 0; i < this.count; i++) {
  403. list.push(this.describeOne(this.count < 2));
  404. }
  405. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  406. } else {
  407. return this.count + " homes with " + this.contents.person.describe() + " inside";
  408. }
  409. }
  410. }
  411. function ParkingGarage(count = 1) {
  412. this.name = "Parking Garage";
  413. copy_defaults(this,new DefaultEntity());
  414. this.count = count;
  415. this.contents = {};
  416. var amount = distribution(10,200,count);
  417. this.contents.person = new Person(amount);
  418. amount = distribution(30,100,count);
  419. this.contents.emptycar = new EmptyCar(amount);
  420. amount = distribution(5,20,count);
  421. this.contents.car = new Car(amount);
  422. this.describeOne = function(verbose=true) {
  423. return "a parking garage";
  424. }
  425. this.describe = function() {
  426. if (this.count <= 3) {
  427. list = [];
  428. for (var i = 0; i < this.count; i++) {
  429. list.push(this.describeOne(this.count < 2));
  430. }
  431. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  432. } else {
  433. return this.count + " parking garages with " + describe_all(this.contents) + " inside";
  434. }
  435. }
  436. }
  437. function Overpass(count = 1) {
  438. this.name = "Overpass";
  439. copy_defaults(this,new DefaultEntity());
  440. this.count = count;
  441. this.contents = {};
  442. var amount = distribution(0,20,count);
  443. this.contents.person = new Person(amount);
  444. amount = distribution(25,100,count);
  445. this.contents.car = new Car(amount);
  446. }