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.
 
 
 

703 lines
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) {
  123. var things = [];
  124. for (var key in contents) {
  125. if (contents.hasOwnProperty(key)) {
  126. things.push(contents[key].describe());
  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)
  292. }
  293. return this;
  294. }
  295. function Person(count = 1) {
  296. this.name = "Person";
  297. copy_defaults(this,new DefaultEntity());
  298. this.count = count;
  299. this.contents = {};
  300. this.describeOne = function (verbose=true) {
  301. body = random_desc(["skinny","fat","tall","short","stocky","spindly"], (verbose ? 0.6 : 0));
  302. sex = random_desc(["male", "female"], (verbose ? 1 : 0));
  303. species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]);
  304. return "a " + merge_desc([body,sex,species]);
  305. }
  306. this.describe = function(verbose=true) {
  307. if (verbose) {
  308. if (count <= 3) {
  309. list = [];
  310. for (var i = 0; i < count; i++) {
  311. list.push(this.describeOne(this.count <= 2));
  312. }
  313. return merge_things(list);
  314. } else {
  315. return this.count + " people"
  316. }
  317. } else {
  318. return this.count + " " + (this.count > 1 ? "people" : "person");
  319. }
  320. }
  321. return this;
  322. }
  323. function EmptyCar(count = 1) {
  324. this.name = "Car";
  325. copy_defaults(this,new DefaultEntity());
  326. this.count = count;
  327. this.contents = {};
  328. this.describeOne = function(verbose=true) {
  329. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"]);
  330. adjective = random_desc(["rusty","brand-new"],0.3);
  331. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  332. return "a parked " + merge_desc([adjective,color,type]);
  333. }
  334. this.describe = function(verbose = true) {
  335. if (verbose) {
  336. if (this.count <= 3) {
  337. list = [];
  338. for (var i = 0; i < this.count; i++) {
  339. list.push(this.describeOne());
  340. }
  341. return merge_things(list);
  342. } else {
  343. return this.count + " parked cars";
  344. }
  345. } else {
  346. return this.count + " parked " + (this.count > 1 ? "cars" : "car");
  347. }
  348. }
  349. }
  350. function Car(count = 1) {
  351. this.name = "Car";
  352. copy_defaults(this,new DefaultEntity());
  353. this.count = count;
  354. this.contents = {};
  355. var amount = distribution(2,5,count);
  356. this.contents.person = new Person(amount);
  357. this.describeOne = function(verbose=true) {
  358. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"], (verbose ? 1 : 0));
  359. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  360. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  361. return "a " + merge_desc([adjective,color,type]);
  362. }
  363. this.describe = function(verbose = true) {
  364. if (verbose) {
  365. if (this.count <= 3) {
  366. list = [];
  367. for (var i = 0; i < this.count; i++) {
  368. list.push(this.describeOne(this.count < 2));
  369. }
  370. return merge_things(list) + " with " + this.contents.person.describe(false) + " inside";
  371. } else {
  372. return this.count + " cars with " + this.contents.person.describe(false) + " inside";
  373. }
  374. } else {
  375. return this.count + " " + (this.count > 1 ? "cars" : "car");
  376. }
  377. }
  378. }
  379. function Bus(count = 1) {
  380. this.name = "Bus";
  381. copy_defaults(this,new DefaultEntity());
  382. this.count = count;
  383. this.contents = {};
  384. var amount = distribution(10,35,count);
  385. this.contents.person = new Person(amount);
  386. this.describeOne = function(verbose=true) {
  387. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  388. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  389. type = random_desc(["bus","double-decker bus","articulating bus"]);
  390. return "a " + merge_desc([adjective,color,type]);
  391. }
  392. this.describe = function(verbose = true) {
  393. if (this.count <= 3) {
  394. list = [];
  395. for (var i = 0; i < this.count; i++) {
  396. list.push(this.describeOne(this.count < 2));
  397. }
  398. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  399. } else {
  400. return this.count + " buses with " + this.contents.person.describe() + " inside";
  401. }
  402. }
  403. }
  404. function Tram(count = 1) {
  405. this.name = "Tram";
  406. copy_defaults(this,new DefaultEntity());
  407. this.count = count;
  408. this.contents = {};
  409. var amount = distribution(40,60,count);
  410. this.contents.person = new Person(amount);
  411. this.describeOne = function(verbose=true) {
  412. adjective = random_desc(["rusty","weathered"], (verbose ? 0.3 : 0));
  413. color = random_desc(["blue","brown","gray"], (verbose ? 1 : 0));
  414. type = random_desc(["tram"]);
  415. return "a " + merge_desc([adjective,color,type]);
  416. }
  417. this.describe = function(verbose = true) {
  418. if (this.count <= 3) {
  419. list = [];
  420. for (var i = 0; i < this.count; i++) {
  421. list.push(this.describeOne(this.count < 2));
  422. }
  423. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  424. } else {
  425. return this.count + " trams with " + this.contents.person.describe() + " inside";
  426. }
  427. }
  428. this.anal_vore = function() {
  429. return "You slide " + this.describe() + " up your tight ass";
  430. }
  431. }
  432. function Motorcycle(count = 1) {
  433. this.name = "Motorcycle";
  434. copy_defaults(this,new DefaultEntity());
  435. this.count = count;
  436. this.contents = {};
  437. var amount = distribution(1,2,count);
  438. this.contents.person = new Person(amount);
  439. }
  440. function Train(count = 1) {
  441. this.name = "Train";
  442. copy_defaults(this,new DefaultEntity());
  443. this.count = count;
  444. this.contents = {};
  445. var amount = distribution(1,4,count);
  446. this.contents.person = new Person(amount);
  447. amount = distribution(1,10,count);
  448. this.contents.traincar = new TrainCar(amount);
  449. this.describeOne = function(verbose=true) {
  450. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  451. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  452. type = random_desc(["train","passenger train","freight train"]);
  453. return "a " + merge_desc([adjective,color,type]);
  454. }
  455. this.describe = function(verbose = true) {
  456. if (this.count <= 3) {
  457. list = [];
  458. for (var i = 0; i < this.count; i++) {
  459. list.push(this.describeOne(this.count < 2));
  460. }
  461. return merge_things(list) + " with " + this.contents.person.describe() + " in the engine and " + this.contents.traincar.describe() + " attached";
  462. } else {
  463. return this.count + " trains with " + this.contents.person.describe() + " in the engine and " + this.contents.traincar.describe() + " attached";
  464. }
  465. }
  466. this.anal_vore = function() {
  467. var cars = (this.contents.traincar.count == 1 ? this.contents.traincar.describe() + " follows it inside" : this.contents.traincar.describe() + " are pulled slowly inside");
  468. return "You snatch up " + this.describeOne() + " and stuff it into your pucker, moaning as " + cars;
  469. }
  470. }
  471. function TrainCar(count = 1) {
  472. this.name = "Train Car";
  473. copy_defaults(this,new DefaultEntity());
  474. this.count = count;
  475. this.contents = {};
  476. var amount = distribution(10,40,count);
  477. this.contents.person = new Person(amount);
  478. this.describeOne = function(verbose=true) {
  479. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  480. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  481. type = random_desc(["train car","passenger train car","freight train car"]);
  482. return "a " + merge_desc([adjective,color,type]);
  483. }
  484. this.describe = function(verbose = true) {
  485. if (this.count <= 3) {
  486. list = [];
  487. for (var i = 0; i < this.count; i++) {
  488. list.push(this.describeOne(this.count < 2));
  489. }
  490. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  491. } else {
  492. return this.count + " train cars with " + describe_all(this.contents) + " inside";
  493. }
  494. }
  495. }
  496. function House(count = 1) {
  497. this.name = "House";
  498. copy_defaults(this,new DefaultEntity());
  499. this.count = count;
  500. this.contents = {};
  501. var amount = distribution(0,8,count);
  502. this.contents.person = new Person(amount);
  503. amount = distribution(0,2,count);
  504. this.contents.emptycar = new EmptyCar(amount);
  505. this.describeOne = function(verbose=true) {
  506. size = random_desc(["little","two-story","large"], (verbose ? 0.5 : 0));
  507. color = random_desc(["blue","white","gray","tan","green"], (verbose ? 0.5 : 0));
  508. name = random_desc(["house","house","house","house","house","trailer"], 1);
  509. return "a " + merge_desc([size,color,name]);
  510. }
  511. this.describe = function(verbose = true) {
  512. if (this.count <= 3) {
  513. list = [];
  514. for (var i = 0; i < this.count; i++) {
  515. list.push(this.describeOne(this.count < 2));
  516. }
  517. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  518. } else {
  519. return this.count + " homes with " + this.contents.person.describe() + " inside";
  520. }
  521. }
  522. }
  523. function ParkingGarage(count = 1) {
  524. this.name = "Parking Garage";
  525. copy_defaults(this,new DefaultEntity());
  526. this.count = count;
  527. this.contents = {};
  528. var amount = distribution(10,200,count);
  529. this.contents.person = new Person(amount);
  530. amount = distribution(30,100,count);
  531. this.contents.emptycar = new EmptyCar(amount);
  532. amount = distribution(5,20,count);
  533. this.contents.car = new Car(amount);
  534. this.describeOne = function(verbose=true) {
  535. return "a parking garage";
  536. }
  537. this.describe = function(verbose = true) {
  538. if (this.count <= 3) {
  539. list = [];
  540. for (var i = 0; i < this.count; i++) {
  541. list.push(this.describeOne(this.count < 2));
  542. }
  543. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  544. } else {
  545. return this.count + " parking garages with " + describe_all(this.contents) + " inside";
  546. }
  547. }
  548. }
  549. function Overpass(count = 1) {
  550. this.name = "Overpass";
  551. copy_defaults(this,new DefaultEntity());
  552. this.count = count;
  553. this.contents = {};
  554. var amount = distribution(0,20,count);
  555. this.contents.person = new Person(amount);
  556. amount = distribution(25,100,count);
  557. this.contents.car = new Car(amount);
  558. }