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.
 
 
 

698 lines
17 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 "Your ass slams down on " + thing.describe() + ". " + (thing.count > 1 ? "They slide" : "It slides") + " inside with ease."; }
  193. }
  194. function defaultArea(thing) {
  195. return areas[thing.name];
  196. }
  197. function defaultMass(thing) {
  198. return masses[thing.name];
  199. }
  200. function defaultMerge(thing) {
  201. return function(container) {
  202. var newCount = this.count + container.count;
  203. var newThing = new things[thing.name](newCount);
  204. newThing.contents = {};
  205. for (var key in this.contents) {
  206. if (this.contents.hasOwnProperty(key)) {
  207. newThing.contents[key] = this.contents[key];
  208. }
  209. }
  210. for (var key in container.contents) {
  211. if (container.contents.hasOwnProperty(key)) {
  212. if (this.contents.hasOwnProperty(key)) {
  213. newThing.contents[key] = this.contents[key].merge(container.contents[key]);
  214. } else {;
  215. newThing.contents[key] = container.contents[key];
  216. }
  217. }
  218. }
  219. return newThing;
  220. }
  221. }
  222. function defaultSum(thing) {
  223. return function() {
  224. var counts = {}
  225. if (thing.name != "Container")
  226. counts[thing.name] = thing.count;
  227. for (var key in thing.contents) {
  228. if (thing.contents.hasOwnProperty(key)) {
  229. subcount = thing.contents[key].sum();
  230. for (var subkey in subcount) {
  231. if (!counts.hasOwnProperty(subkey)) {
  232. counts[subkey] = 0;
  233. }
  234. counts[subkey] += subcount[subkey];
  235. }
  236. }
  237. }
  238. return counts;
  239. }
  240. }
  241. function defaultSumProperty(thing) {
  242. return function(prop) {
  243. var total = 0;
  244. total += thing[prop] * thing.count;
  245. for (var key in thing.contents) {
  246. if (thing.contents.hasOwnProperty(key)) {
  247. total += thing.contents[key].sum_property(prop);
  248. }
  249. }
  250. return total;
  251. }
  252. }
  253. function DefaultEntity() {
  254. this.stomp = defaultStomp;
  255. this.eat = defaultEat;
  256. this.kick = defaultKick;
  257. this.anal_vore = defaultAnalVore;
  258. this.sum = defaultSum;
  259. this.area = defaultArea;
  260. this.mass = defaultMass;
  261. this.sum_property = defaultSumProperty;
  262. this.merge = defaultMerge;
  263. return this;
  264. }
  265. // god I love reinventing the wheel
  266. function copy_defaults(self,proto) {
  267. for (var key in proto) {
  268. if (proto.hasOwnProperty(key)) {
  269. self[key] = proto[key](self)
  270. }
  271. }
  272. }
  273. function Container(contents = []) {
  274. this.name = "Container";
  275. copy_defaults(this,new DefaultEntity());
  276. this.count = 0;
  277. this.contents = {}
  278. for (var i=0; i < contents.length; i++) {
  279. this.contents[contents[i].name] = contents[i];
  280. }
  281. for (var key in this.contents) {
  282. if (this.contents.hasOwnProperty(key)) {
  283. this.count += this.contents[key].count;
  284. }
  285. }
  286. this.describe = function(verbose = true) {
  287. return describe_all(this.contents)
  288. }
  289. return this;
  290. }
  291. function Person(count = 1) {
  292. this.name = "Person";
  293. copy_defaults(this,new DefaultEntity());
  294. this.count = count;
  295. this.contents = {};
  296. this.describeOne = function (verbose=true) {
  297. body = random_desc(["skinny","fat","tall","short","stocky","spindly"], (verbose ? 0.6 : 0));
  298. sex = random_desc(["male", "female"], (verbose ? 1 : 0));
  299. species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]);
  300. return "a " + merge_desc([body,sex,species]);
  301. }
  302. this.describe = function(verbose=true) {
  303. if (verbose) {
  304. if (count <= 3) {
  305. list = [];
  306. for (var i = 0; i < count; i++) {
  307. list.push(this.describeOne(this.count <= 2));
  308. }
  309. return merge_things(list);
  310. } else {
  311. return this.count + " people"
  312. }
  313. } else {
  314. return this.count + " " + (this.count > 1 ? "people" : "person");
  315. }
  316. }
  317. return this;
  318. }
  319. function EmptyCar(count = 1) {
  320. this.name = "Car";
  321. copy_defaults(this,new DefaultEntity());
  322. this.count = count;
  323. this.contents = {};
  324. this.describeOne = function(verbose=true) {
  325. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"]);
  326. adjective = random_desc(["rusty","brand-new"],0.3);
  327. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  328. return "a parked " + merge_desc([adjective,color,type]);
  329. }
  330. this.describe = function(verbose = true) {
  331. if (verbose) {
  332. if (this.count <= 3) {
  333. list = [];
  334. for (var i = 0; i < this.count; i++) {
  335. list.push(this.describeOne());
  336. }
  337. return merge_things(list);
  338. } else {
  339. return this.count + " parked cars";
  340. }
  341. } else {
  342. return this.count + " parked " + (this.count > 1 ? "cars" : "car");
  343. }
  344. }
  345. }
  346. function Car(count = 1) {
  347. this.name = "Car";
  348. copy_defaults(this,new DefaultEntity());
  349. this.count = count;
  350. this.contents = {};
  351. var amount = distribution(2,5,count);
  352. this.contents.person = new Person(amount);
  353. this.describeOne = function(verbose=true) {
  354. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"], (verbose ? 1 : 0));
  355. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  356. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  357. return "a " + merge_desc([adjective,color,type]);
  358. }
  359. this.describe = function(verbose = true) {
  360. if (verbose) {
  361. if (this.count <= 3) {
  362. list = [];
  363. for (var i = 0; i < this.count; i++) {
  364. list.push(this.describeOne(this.count < 2));
  365. }
  366. return merge_things(list) + " with " + this.contents.person.describe(false) + " inside";
  367. } else {
  368. return this.count + " cars with " + this.contents.person.describe(false) + " inside";
  369. }
  370. } else {
  371. return this.count + " " + (this.count > 1 ? "cars" : "car");
  372. }
  373. }
  374. }
  375. function Bus(count = 1) {
  376. this.name = "Bus";
  377. copy_defaults(this,new DefaultEntity());
  378. this.count = count;
  379. this.contents = {};
  380. var amount = distribution(10,35,count);
  381. this.contents.person = new Person(amount);
  382. this.describeOne = function(verbose=true) {
  383. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  384. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  385. type = random_desc(["bus","double-decker bus","articulating bus"]);
  386. return "a " + merge_desc([adjective,color,type]);
  387. }
  388. this.describe = function(verbose = true) {
  389. if (this.count <= 3) {
  390. list = [];
  391. for (var i = 0; i < this.count; i++) {
  392. list.push(this.describeOne(this.count < 2));
  393. }
  394. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  395. } else {
  396. return this.count + " buses with " + this.contents.person.describe() + " inside";
  397. }
  398. }
  399. }
  400. function Tram(count = 1) {
  401. this.name = "Tram";
  402. copy_defaults(this,new DefaultEntity());
  403. this.count = count;
  404. this.contents = {};
  405. var amount = distribution(40,60,count);
  406. this.contents.person = new Person(amount);
  407. this.describeOne = function(verbose=true) {
  408. adjective = random_desc(["rusty","weathered"], (verbose ? 0.3 : 0));
  409. color = random_desc(["blue","brown","gray"], (verbose ? 1 : 0));
  410. type = random_desc(["tram"]);
  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 + " trams with " + this.contents.person.describe() + " inside";
  422. }
  423. }
  424. this.anal_vore = function() {
  425. return "You slide " + this.describe() + " up your tight ass";
  426. }
  427. }
  428. function Motorcycle(count = 1) {
  429. this.name = "Motorcycle";
  430. copy_defaults(this,new DefaultEntity());
  431. this.count = count;
  432. this.contents = {};
  433. var amount = distribution(1,2,count);
  434. this.contents.person = new Person(amount);
  435. }
  436. function Train(count = 1) {
  437. this.name = "Train";
  438. copy_defaults(this,new DefaultEntity());
  439. this.count = count;
  440. this.contents = {};
  441. var amount = distribution(1,4,count);
  442. this.contents.person = new Person(amount);
  443. amount = distribution(1,10,count);
  444. this.contents.traincar = new TrainCar(amount);
  445. this.describeOne = function(verbose=true) {
  446. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  447. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  448. type = random_desc(["train","passenger train","freight train"]);
  449. return "a " + merge_desc([adjective,color,type]);
  450. }
  451. this.describe = function(verbose = true) {
  452. if (this.count <= 3) {
  453. list = [];
  454. for (var i = 0; i < this.count; i++) {
  455. list.push(this.describeOne(this.count < 2));
  456. }
  457. return merge_things(list) + " with " + this.contents.person.describe() + " in the engine and " + this.contents.traincar.describe() + " attached";
  458. } else {
  459. return this.count + " trains with " + this.contents.person.describe() + " in the engine and " + this.contents.traincar.describe() + " attached";
  460. }
  461. }
  462. this.anal_vore = function() {
  463. var cars = (this.contents.traincar.count == 1 ? this.contents.traincar.describe() + " follows it inside" : this.contents.traincar.describe() + " are pulled slowly inside");
  464. return "You snatch up " + this.describeOne() + " and stuff it into your pucker, moaning as " + cars;
  465. }
  466. }
  467. function TrainCar(count = 1) {
  468. this.name = "Train Car";
  469. copy_defaults(this,new DefaultEntity());
  470. this.count = count;
  471. this.contents = {};
  472. var amount = distribution(10,40,count);
  473. this.contents.person = new Person(amount);
  474. this.describeOne = function(verbose=true) {
  475. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  476. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  477. type = random_desc(["train car","passenger train car","freight train car"]);
  478. return "a " + merge_desc([adjective,color,type]);
  479. }
  480. this.describe = function(verbose = true) {
  481. if (this.count <= 3) {
  482. list = [];
  483. for (var i = 0; i < this.count; i++) {
  484. list.push(this.describeOne(this.count < 2));
  485. }
  486. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  487. } else {
  488. return this.count + " train cars with " + describe_all(this.contents) + " inside";
  489. }
  490. }
  491. }
  492. function House(count = 1) {
  493. this.name = "House";
  494. copy_defaults(this,new DefaultEntity());
  495. this.count = count;
  496. this.contents = {};
  497. var amount = distribution(0,8,count);
  498. this.contents.person = new Person(amount);
  499. amount = distribution(0,2,count);
  500. this.contents.emptycar = new EmptyCar(amount);
  501. this.describeOne = function(verbose=true) {
  502. size = random_desc(["little","two-story","large"], (verbose ? 0.5 : 0));
  503. color = random_desc(["blue","white","gray","tan","green"], (verbose ? 0.5 : 0));
  504. name = random_desc(["house","house","house","house","house","trailer"], 1);
  505. return "a " + merge_desc([size,color,name]);
  506. }
  507. this.describe = function(verbose = true) {
  508. if (this.count <= 3) {
  509. list = [];
  510. for (var i = 0; i < this.count; i++) {
  511. list.push(this.describeOne(this.count < 2));
  512. }
  513. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  514. } else {
  515. return this.count + " homes with " + this.contents.person.describe() + " inside";
  516. }
  517. }
  518. }
  519. function ParkingGarage(count = 1) {
  520. this.name = "Parking Garage";
  521. copy_defaults(this,new DefaultEntity());
  522. this.count = count;
  523. this.contents = {};
  524. var amount = distribution(10,200,count);
  525. this.contents.person = new Person(amount);
  526. amount = distribution(30,100,count);
  527. this.contents.emptycar = new EmptyCar(amount);
  528. amount = distribution(5,20,count);
  529. this.contents.car = new Car(amount);
  530. this.describeOne = function(verbose=true) {
  531. return "a parking garage";
  532. }
  533. this.describe = function(verbose = true) {
  534. if (this.count <= 3) {
  535. list = [];
  536. for (var i = 0; i < this.count; i++) {
  537. list.push(this.describeOne(this.count < 2));
  538. }
  539. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  540. } else {
  541. return this.count + " parking garages with " + describe_all(this.contents) + " inside";
  542. }
  543. }
  544. }
  545. function Overpass(count = 1) {
  546. this.name = "Overpass";
  547. copy_defaults(this,new DefaultEntity());
  548. this.count = count;
  549. this.contents = {};
  550. var amount = distribution(0,20,count);
  551. this.contents.person = new Person(amount);
  552. amount = distribution(25,100,count);
  553. this.contents.car = new Car(amount);
  554. }