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.
 
 
 

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