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.
 
 
 

727 line
18 KiB

  1. var things =
  2. {
  3. "Container": Container,
  4. "Person": Person,
  5. "Empty Car": EmptyCar,
  6. "Car": Car,
  7. "Bus": Bus,
  8. "Tram": Tram,
  9. "Motorcycle": Motorcycle,
  10. "House": House,
  11. "Train": Train,
  12. "Train Car": TrainCar,
  13. "Parking Garage": ParkingGarage,
  14. "Overpass": Overpass,
  15. };
  16. var areas =
  17. {
  18. "Container": 0,
  19. "Person": 1,
  20. "Car": 4,
  21. "Bus": 12,
  22. "Tram": 20,
  23. "Motorcycle": 2,
  24. "House": 1000,
  25. "Train": 500,
  26. "TrainCar": 500,
  27. "Parking Garage": 20000,
  28. "Overpass": 10000,
  29. };
  30. // general logic: each step fills in a fraction of the remaining space
  31. function fill_area2(area, weights = {"Person": 0.1, "Car": 0.05, "House": 0.1})
  32. {
  33. result = [];
  34. candidates = [];
  35. for (var key in weights) {
  36. if (weights.hasOwnProperty(key)) {
  37. candidates.push({"name": key, "area": areas[key], "weight": weights[key]});
  38. }
  39. }
  40. candidates = candidates.sort(function (x,y) {
  41. return x.area > y.area
  42. });
  43. while(candidates.length > 0) {
  44. var candidate = candidates.pop();
  45. if (candidate.area > area)
  46. continue;
  47. var max = Math.floor(area / candidate.area);
  48. var limit = Math.min(max, 100);
  49. var count = 0;
  50. // for small amounts, actually do the randomness
  51. // the first few ones get a better shot
  52. while (limit > 0) {
  53. if (limit <= 3)
  54. count += Math.random() < (1 - Math.pow((1 - candidate.weight),2)) ? 1 : 0;
  55. else
  56. count += Math.random() < candidate.weight ? 1 : 0;
  57. --limit;
  58. }
  59. if (limit < max) {
  60. count += Math.round((max-limit) * candidate.weight);
  61. }
  62. area -= count * candidate.area;
  63. if (count > 0)
  64. result.push(new things[candidate.name](count));
  65. }
  66. if (result.length > 1) {
  67. return new Container(result);
  68. } else if (result.length == 1) {
  69. return result[0];
  70. } else {
  71. return new Person(1);
  72. }
  73. }
  74. function fill_area(area, weights = {"Person": 0.1})
  75. {
  76. var testRadius = Math.sqrt(area / Math.PI);
  77. result = []
  78. for (var key in weights) {
  79. if (weights.hasOwnProperty(key)) {
  80. var objArea = areas[key];
  81. var objRadius = Math.sqrt(objArea / Math.PI);
  82. var newRadius = testRadius - objRadius;
  83. if (newRadius > 0) {
  84. var newArea = newRadius * newRadius * Math.PI;
  85. var numObjs = weights[key] * newArea;
  86. if (numObjs < 1) {
  87. numObjs = Math.random() > numObjs ? 0 : 1;
  88. }
  89. else {
  90. numObjs = Math.round(numObjs);
  91. }
  92. if (numObjs > 0)
  93. result.push(new things[key](numObjs));
  94. else {
  95. // try again with a better chance for just one
  96. }
  97. }
  98. }
  99. }
  100. if (result.length > 1)
  101. return new Container(result);
  102. else if (result.length == 1)
  103. return result[0];
  104. else
  105. return new Person();
  106. }
  107. var masses =
  108. {
  109. "Container": 0,
  110. "Person": 80,
  111. "Car": 1000,
  112. "Bus": 5000,
  113. "Tram": 10000,
  114. "Motorcycle": 200,
  115. "House": 10000,
  116. "Train": 5000,
  117. "Train Car": 5000,
  118. "Parking Garage": 100000,
  119. "Overpass": 100000,
  120. };
  121. // describes everything in the container
  122. function describe_all(contents,verbose=true) {
  123. var things = [];
  124. for (var key in contents) {
  125. if (contents.hasOwnProperty(key)) {
  126. things.push(contents[key].describe(verbose));
  127. }
  128. }
  129. return merge_things(things);
  130. }
  131. function random_desc(list, odds=1) {
  132. if (Math.random() < odds)
  133. return list[Math.floor(Math.random() * list.length)];
  134. else
  135. return "";
  136. }
  137. // combine strings into a list with proper grammar
  138. function merge_things(list,semicolons=false) {
  139. if (list.length == 0) {
  140. return "";
  141. } else if (list.length == 1) {
  142. return list[0];
  143. } else if (list.length == 2) {
  144. return list[0] + " and " + list[1];
  145. } else {
  146. result = "";
  147. list.slice(0,list.length-1).forEach(function(term) {
  148. result += term + ", ";
  149. })
  150. result += "and " + list[list.length-1]
  151. return result;
  152. }
  153. }
  154. // combine the adjectives for something into a single string
  155. function merge_desc(list) {
  156. result = ""
  157. list.forEach(function(term) {
  158. if (term != "")
  159. result += term + " ";
  160. });
  161. // knock off the last space
  162. if (result.length > 0) {
  163. result = result.substring(0, result.length - 1);
  164. }
  165. return result;
  166. }
  167. // maybe make this something that approximates a
  168. // normal distribution; doing this 15,000,000 times is bad...
  169. // solution: only a few are random lul
  170. function distribution(min, max, samples) {
  171. var result = 0;
  172. var limit = Math.min(100,samples)
  173. for (var i = 0; i < limit; i++) {
  174. result += Math.floor(Math.random() * (max - min + 1) + min);
  175. }
  176. if (limit < samples) {
  177. result += Math.round((max - min) * (samples - limit));
  178. }
  179. return result;
  180. }
  181. /* default actions */
  182. function defaultStomp(thing) {
  183. return function () { return "You crush " + thing.describe() + " underfoot."};
  184. }
  185. function defaultKick(thing) {
  186. return function() { return "You punt " + thing.describe() + ", destroying " + (thing.count > 1 ? "them" : "it") + "."; }
  187. }
  188. function defaultEat(thing) {
  189. return function() { return "You scoop up " + thing.describe() + " and swallow " + (thing.count > 1 ? "them" : "it") + " whole."; }
  190. }
  191. function defaultAnalVore(thing) {
  192. return function() { return "You sit yourself down on " + thing.describe() + ". " + (thing.count > 1 ? "They slide" : "It slides") + " inside with ease."; }
  193. }
  194. function defaultButtcrush(thing) {
  195. return function() { return "Your heavy ass obliterates " + thing.describe() + ". "; }
  196. }
  197. function defaultArea(thing) {
  198. return areas[thing.name];
  199. }
  200. function defaultMass(thing) {
  201. return masses[thing.name];
  202. }
  203. function defaultMerge(thing) {
  204. return function(container) {
  205. var newCount = this.count + container.count;
  206. var newThing = new things[thing.name](newCount);
  207. newThing.contents = {};
  208. for (var key in this.contents) {
  209. if (this.contents.hasOwnProperty(key)) {
  210. newThing.contents[key] = this.contents[key];
  211. }
  212. }
  213. for (var key in container.contents) {
  214. if (container.contents.hasOwnProperty(key)) {
  215. if (this.contents.hasOwnProperty(key)) {
  216. newThing.contents[key] = this.contents[key].merge(container.contents[key]);
  217. } else {;
  218. newThing.contents[key] = container.contents[key];
  219. }
  220. }
  221. }
  222. return newThing;
  223. }
  224. }
  225. function defaultSum(thing) {
  226. return function() {
  227. var counts = {}
  228. if (thing.name != "Container")
  229. counts[thing.name] = thing.count;
  230. for (var key in thing.contents) {
  231. if (thing.contents.hasOwnProperty(key)) {
  232. subcount = thing.contents[key].sum();
  233. for (var subkey in subcount) {
  234. if (!counts.hasOwnProperty(subkey)) {
  235. counts[subkey] = 0;
  236. }
  237. counts[subkey] += subcount[subkey];
  238. }
  239. }
  240. }
  241. return counts;
  242. }
  243. }
  244. function defaultSumProperty(thing) {
  245. return function(prop) {
  246. var total = 0;
  247. total += thing[prop] * thing.count;
  248. for (var key in thing.contents) {
  249. if (thing.contents.hasOwnProperty(key)) {
  250. total += thing.contents[key].sum_property(prop);
  251. }
  252. }
  253. return total;
  254. }
  255. }
  256. function DefaultEntity() {
  257. this.stomp = defaultStomp;
  258. this.eat = defaultEat;
  259. this.kick = defaultKick;
  260. this.anal_vore = defaultAnalVore;
  261. this.buttcrush = defaultButtcrush;
  262. this.sum = defaultSum;
  263. this.area = defaultArea;
  264. this.mass = defaultMass;
  265. this.sum_property = defaultSumProperty;
  266. this.merge = defaultMerge;
  267. return this;
  268. }
  269. // god I love reinventing the wheel
  270. function copy_defaults(self,proto) {
  271. for (var key in proto) {
  272. if (proto.hasOwnProperty(key)) {
  273. self[key] = proto[key](self)
  274. }
  275. }
  276. }
  277. function Container(contents = []) {
  278. this.name = "Container";
  279. copy_defaults(this,new DefaultEntity());
  280. this.count = 0;
  281. this.contents = {}
  282. for (var i=0; i < contents.length; i++) {
  283. this.contents[contents[i].name] = contents[i];
  284. }
  285. for (var key in this.contents) {
  286. if (this.contents.hasOwnProperty(key)) {
  287. this.count += this.contents[key].count;
  288. }
  289. }
  290. this.describe = function(verbose = true) {
  291. return describe_all(this.contents,false)
  292. }
  293. this.eat = function() {
  294. var line = containerEat(this);
  295. if (line == "")
  296. return defaultEat(this)();
  297. else
  298. return line;
  299. };
  300. return this;
  301. }
  302. function Person(count = 1) {
  303. this.name = "Person";
  304. copy_defaults(this,new DefaultEntity());
  305. this.count = count;
  306. this.contents = {};
  307. this.describeOne = function (verbose=true) {
  308. body = random_desc(["skinny","fat","tall","short","stocky","spindly"], (verbose ? 0.6 : 0));
  309. sex = random_desc(["male", "female"], (verbose ? 1 : 0));
  310. species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]);
  311. return "a " + merge_desc([body,sex,species]);
  312. }
  313. this.describe = function(verbose=true) {
  314. if (verbose) {
  315. if (count <= 3) {
  316. list = [];
  317. for (var i = 0; i < count; i++) {
  318. list.push(this.describeOne(this.count <= 2));
  319. }
  320. return merge_things(list);
  321. } else {
  322. return this.count + " people"
  323. }
  324. } else {
  325. return this.count + " " + (this.count > 1 ? "people" : "person");
  326. }
  327. }
  328. this.stomp = function() {
  329. var line = personStomp(this);
  330. if (line == "")
  331. return defaultStomp(this)();
  332. else
  333. return line;
  334. };
  335. this.eat = function() {
  336. var line = personEat(this);
  337. if (line == "")
  338. return defaultEat(this)();
  339. else
  340. return line;
  341. };
  342. return this;
  343. }
  344. function EmptyCar(count = 1) {
  345. this.name = "Car";
  346. copy_defaults(this,new DefaultEntity());
  347. this.count = count;
  348. this.contents = {};
  349. this.describeOne = function(verbose=true) {
  350. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"]);
  351. adjective = random_desc(["rusty","brand-new"],0.3);
  352. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  353. return "a parked " + merge_desc([adjective,color,type]);
  354. }
  355. this.describe = function(verbose = true) {
  356. if (verbose) {
  357. if (this.count <= 3) {
  358. list = [];
  359. for (var i = 0; i < this.count; i++) {
  360. list.push(this.describeOne());
  361. }
  362. return merge_things(list);
  363. } else {
  364. return this.count + " parked cars";
  365. }
  366. } else {
  367. return this.count + " parked " + (this.count > 1 ? "cars" : "car");
  368. }
  369. }
  370. }
  371. function Car(count = 1) {
  372. this.name = "Car";
  373. copy_defaults(this,new DefaultEntity());
  374. this.count = count;
  375. this.contents = {};
  376. var amount = distribution(2,5,count);
  377. this.contents.person = new Person(amount);
  378. this.describeOne = function(verbose=true) {
  379. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"], (verbose ? 1 : 0));
  380. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  381. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  382. return "a " + merge_desc([adjective,color,type]);
  383. }
  384. this.describe = function(verbose = true) {
  385. if (verbose) {
  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(false) + " inside";
  392. } else {
  393. return this.count + " cars with " + this.contents.person.describe(false) + " inside";
  394. }
  395. } else {
  396. return this.count + " " + (this.count > 1 ? "cars" : "car");
  397. }
  398. }
  399. }
  400. function Bus(count = 1) {
  401. this.name = "Bus";
  402. copy_defaults(this,new DefaultEntity());
  403. this.count = count;
  404. this.contents = {};
  405. var amount = distribution(10,35,count);
  406. this.contents.person = new Person(amount);
  407. this.describeOne = function(verbose=true) {
  408. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  409. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  410. type = random_desc(["bus","double-decker bus","articulating bus"]);
  411. return "a " + merge_desc([adjective,color,type]);
  412. }
  413. this.describe = function(verbose = true) {
  414. if (this.count <= 3) {
  415. list = [];
  416. for (var i = 0; i < this.count; i++) {
  417. list.push(this.describeOne(this.count < 2));
  418. }
  419. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  420. } else {
  421. return this.count + " buses with " + this.contents.person.describe() + " inside";
  422. }
  423. }
  424. }
  425. function Tram(count = 1) {
  426. this.name = "Tram";
  427. copy_defaults(this,new DefaultEntity());
  428. this.count = count;
  429. this.contents = {};
  430. var amount = distribution(40,60,count);
  431. this.contents.person = new Person(amount);
  432. this.describeOne = function(verbose=true) {
  433. adjective = random_desc(["rusty","weathered"], (verbose ? 0.3 : 0));
  434. color = random_desc(["blue","brown","gray"], (verbose ? 1 : 0));
  435. type = random_desc(["tram"]);
  436. return "a " + merge_desc([adjective,color,type]);
  437. }
  438. this.describe = function(verbose = true) {
  439. if (this.count <= 3) {
  440. list = [];
  441. for (var i = 0; i < this.count; i++) {
  442. list.push(this.describeOne(this.count < 2));
  443. }
  444. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  445. } else {
  446. return this.count + " trams with " + this.contents.person.describe() + " inside";
  447. }
  448. }
  449. this.anal_vore = function() {
  450. return "You slide " + this.describe() + " up your tight ass";
  451. }
  452. }
  453. function Motorcycle(count = 1) {
  454. this.name = "Motorcycle";
  455. copy_defaults(this,new DefaultEntity());
  456. this.count = count;
  457. this.contents = {};
  458. var amount = distribution(1,2,count);
  459. this.contents.person = new Person(amount);
  460. }
  461. function Train(count = 1) {
  462. this.name = "Train";
  463. copy_defaults(this,new DefaultEntity());
  464. this.count = count;
  465. this.contents = {};
  466. var amount = distribution(1,4,count);
  467. this.contents.person = new Person(amount);
  468. amount = distribution(1,10,count);
  469. this.contents.traincar = new TrainCar(amount);
  470. this.describeOne = function(verbose=true) {
  471. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  472. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  473. type = random_desc(["train","passenger train","freight train"]);
  474. return "a " + merge_desc([adjective,color,type]);
  475. }
  476. this.describe = function(verbose = true) {
  477. if (this.count <= 3) {
  478. list = [];
  479. for (var i = 0; i < this.count; i++) {
  480. list.push(this.describeOne(this.count < 2));
  481. }
  482. return merge_things(list) + " with " + this.contents.person.describe() + " in the engine and " + this.contents.traincar.describe() + " attached";
  483. } else {
  484. return this.count + " trains with " + this.contents.person.describe() + " in the engine and " + this.contents.traincar.describe() + " attached";
  485. }
  486. }
  487. this.anal_vore = function() {
  488. var cars = (this.contents.traincar.count == 1 ? this.contents.traincar.describe() + " follows it inside" : this.contents.traincar.describe() + " are pulled slowly inside");
  489. return "You snatch up " + this.describeOne() + " and stuff it into your pucker, moaning as " + cars;
  490. }
  491. }
  492. function TrainCar(count = 1) {
  493. this.name = "Train Car";
  494. copy_defaults(this,new DefaultEntity());
  495. this.count = count;
  496. this.contents = {};
  497. var amount = distribution(10,40,count);
  498. this.contents.person = new Person(amount);
  499. this.describeOne = function(verbose=true) {
  500. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  501. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  502. type = random_desc(["train car","passenger train car","freight train car"]);
  503. return "a " + merge_desc([adjective,color,type]);
  504. }
  505. this.describe = function(verbose = true) {
  506. if (this.count <= 3) {
  507. list = [];
  508. for (var i = 0; i < this.count; i++) {
  509. list.push(this.describeOne(this.count < 2));
  510. }
  511. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  512. } else {
  513. return this.count + " train cars with " + describe_all(this.contents) + " inside";
  514. }
  515. }
  516. }
  517. function House(count = 1) {
  518. this.name = "House";
  519. copy_defaults(this,new DefaultEntity());
  520. this.count = count;
  521. this.contents = {};
  522. var amount = distribution(0,8,count);
  523. this.contents.person = new Person(amount);
  524. amount = distribution(0,2,count);
  525. this.contents.emptycar = new EmptyCar(amount);
  526. this.describeOne = function(verbose=true) {
  527. size = random_desc(["little","two-story","large"], (verbose ? 0.5 : 0));
  528. color = random_desc(["blue","white","gray","tan","green"], (verbose ? 0.5 : 0));
  529. name = random_desc(["house","house","house","house","house","trailer"], 1);
  530. return "a " + merge_desc([size,color,name]);
  531. }
  532. this.describe = function(verbose = true) {
  533. if (this.count <= 3) {
  534. list = [];
  535. for (var i = 0; i < this.count; i++) {
  536. list.push(this.describeOne(this.count < 2));
  537. }
  538. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  539. } else {
  540. return this.count + " homes with " + this.contents.person.describe() + " inside";
  541. }
  542. }
  543. }
  544. function ParkingGarage(count = 1) {
  545. this.name = "Parking Garage";
  546. copy_defaults(this,new DefaultEntity());
  547. this.count = count;
  548. this.contents = {};
  549. var amount = distribution(10,200,count);
  550. this.contents.person = new Person(amount);
  551. amount = distribution(30,100,count);
  552. this.contents.emptycar = new EmptyCar(amount);
  553. amount = distribution(5,20,count);
  554. this.contents.car = new Car(amount);
  555. this.describeOne = function(verbose=true) {
  556. return "a parking garage";
  557. }
  558. this.describe = function(verbose = true) {
  559. if (this.count <= 3) {
  560. list = [];
  561. for (var i = 0; i < this.count; i++) {
  562. list.push(this.describeOne(this.count < 2));
  563. }
  564. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  565. } else {
  566. return this.count + " parking garages with " + describe_all(this.contents) + " inside";
  567. }
  568. }
  569. }
  570. function Overpass(count = 1) {
  571. this.name = "Overpass";
  572. copy_defaults(this,new DefaultEntity());
  573. this.count = count;
  574. this.contents = {};
  575. var amount = distribution(0,20,count);
  576. this.contents.person = new Person(amount);
  577. amount = distribution(25,100,count);
  578. this.contents.car = new Car(amount);
  579. }