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.
 
 
 

541 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. };
  14. var areas =
  15. {
  16. "Container": 0,
  17. "Person": 3,
  18. "Car": 4,
  19. "Bus": 12,
  20. "Motorcycle": 2,
  21. "House": 1000,
  22. "Train": 10000,
  23. "Parking Garage": 20000,
  24. "Overpass": 10000,
  25. };
  26. function fill_area(area, weights = {"Person": 0.1})
  27. {
  28. var testRadius = Math.sqrt(area / Math.PI);
  29. result = []
  30. for (var key in weights) {
  31. if (weights.hasOwnProperty(key)) {
  32. var objArea = areas[key];
  33. var objRadius = Math.sqrt(objArea / Math.PI);
  34. var newRadius = testRadius - objRadius;
  35. if (newRadius > 0) {
  36. var newArea = newRadius * newRadius * Math.PI;
  37. var numObjs = weights[key] * newArea;
  38. if (numObjs < 1) {
  39. numObjs = Math.random() > numObjs ? 0 : 1;
  40. }
  41. else {
  42. numObjs = Math.round(numObjs);
  43. }
  44. if (numObjs > 0)
  45. result.push(new things[key](numObjs));
  46. else {
  47. // try again with a better chance for just one
  48. }
  49. }
  50. }
  51. }
  52. if (result.length > 1)
  53. return new Container(result);
  54. else if (result.length == 1)
  55. return result[0];
  56. else
  57. return new Person();
  58. }
  59. var masses =
  60. {
  61. "Container": 0,
  62. "Person": 80,
  63. "Car": 1000,
  64. "Bus": 5000,
  65. "Motorcycle": 200,
  66. "House": 10000,
  67. "Train": 50000,
  68. "Parking Garage": 100000,
  69. "Overpass": 100000,
  70. };
  71. // describes everything in the container
  72. function describe_all(contents) {
  73. var things = [];
  74. for (var key in contents) {
  75. if (contents.hasOwnProperty(key)) {
  76. things.push(contents[key].describe());
  77. }
  78. }
  79. return merge_things(things);
  80. }
  81. function random_desc(list, odds=1) {
  82. if (Math.random() < odds)
  83. return list[Math.floor(Math.random() * list.length)];
  84. else
  85. return "";
  86. }
  87. // combine strings into a list with proper grammar
  88. function merge_things(list,semicolons=false) {
  89. if (list.length == 0) {
  90. return "";
  91. } else if (list.length == 1) {
  92. return list[0];
  93. } else if (list.length == 2) {
  94. return list[0] + " and " + list[1];
  95. } else {
  96. result = "";
  97. list.slice(0,list.length-1).forEach(function(term) {
  98. result += term + ", ";
  99. })
  100. result += "and " + list[list.length-1]
  101. return result;
  102. }
  103. }
  104. // combine the adjectives for something into a single string
  105. function merge_desc(list) {
  106. result = ""
  107. list.forEach(function(term) {
  108. if (term != "")
  109. result += term + " ";
  110. });
  111. // knock off the last space
  112. if (result.length > 0) {
  113. result = result.substring(0, result.length - 1);
  114. }
  115. return result;
  116. }
  117. // maybe make this something that approximates a
  118. // normal distribution; doing this 15,000,000 times is bad...
  119. function distribution(min, max, samples) {
  120. var result = 0;
  121. for (var i = 0; i < samples; i++) {
  122. result += Math.floor(Math.random() * (max - min + 1) + min);
  123. }
  124. return result;
  125. }
  126. /* default actions */
  127. function defaultStomp(thing) {
  128. return function () { return "You crush " + thing.describe() + " underfoot."};
  129. }
  130. function defaultKick(thing) {
  131. return function() { return "You punt " + thing.describe() + ", destroying " + (thing.count > 1 ? "them" : "it") + "."; }
  132. }
  133. function defaultEat(thing) {
  134. return function() { return "You scoop up " + thing.describe() + " and swallow " + (thing.count > 1 ? "them" : "it") + " whole."; }
  135. }
  136. function defaultAnalVore(thing) {
  137. return function() { return "Your ass slams down on " + thing.describe() + ". " + (thing.count > 1 ? "They slide" : "It slides") + " inside with ease."; }
  138. }
  139. function defaultArea(thing) {
  140. return areas[thing.name];
  141. }
  142. function defaultMass(thing) {
  143. return masses[thing.name];
  144. }
  145. function defaultMerge(thing) {
  146. return function(container) {
  147. var newCount = this.count + container.count;
  148. var newThing = new things[thing.name](newCount);
  149. newThing.contents = {};
  150. for (var key in this.contents) {
  151. if (this.contents.hasOwnProperty(key)) {
  152. newThing.contents[key] = this.contents[key];
  153. }
  154. }
  155. for (var key in container.contents) {
  156. if (container.contents.hasOwnProperty(key)) {
  157. if (this.contents.hasOwnProperty(key)) {
  158. newThing.contents[key] = this.contents[key].merge(container.contents[key]);
  159. } else {;
  160. newThing.contents[key] = container.contents[key];
  161. }
  162. }
  163. }
  164. return newThing;
  165. }
  166. }
  167. function defaultSum(thing) {
  168. return function() {
  169. var counts = {}
  170. if (thing.name != "Container")
  171. counts[thing.name] = thing.count;
  172. for (var key in thing.contents) {
  173. if (thing.contents.hasOwnProperty(key)) {
  174. subcount = thing.contents[key].sum();
  175. for (var subkey in subcount) {
  176. if (!counts.hasOwnProperty(subkey)) {
  177. counts[subkey] = 0;
  178. }
  179. counts[subkey] += subcount[subkey];
  180. }
  181. }
  182. }
  183. return counts;
  184. }
  185. }
  186. function defaultSumProperty(thing) {
  187. return function(prop) {
  188. var total = 0;
  189. total += thing[prop] * thing.count;
  190. for (var key in thing.contents) {
  191. if (thing.contents.hasOwnProperty(key)) {
  192. total += thing.contents[key].sum_property(prop);
  193. }
  194. }
  195. return total;
  196. }
  197. }
  198. function DefaultEntity() {
  199. this.stomp = defaultStomp;
  200. this.eat = defaultEat;
  201. this.kick = defaultKick;
  202. this.anal_vore = defaultAnalVore;
  203. this.sum = defaultSum;
  204. this.area = defaultArea;
  205. this.mass = defaultMass;
  206. this.sum_property = defaultSumProperty;
  207. this.merge = defaultMerge;
  208. return this;
  209. }
  210. // god I love reinventing the wheel
  211. function copy_defaults(self,proto) {
  212. for (var key in proto) {
  213. if (proto.hasOwnProperty(key)) {
  214. self[key] = proto[key](self)
  215. }
  216. }
  217. }
  218. function Container(contents = []) {
  219. this.name = "Container";
  220. copy_defaults(this,new DefaultEntity());
  221. this.count = 0;
  222. this.contents = {}
  223. for (var i=0; i < contents.length; i++) {
  224. this.contents[contents[i].name] = contents[i];
  225. }
  226. for (var key in this.contents) {
  227. if (this.contents.hasOwnProperty(key)) {
  228. this.count += this.contents[key].count;
  229. }
  230. }
  231. this.describe = function() {
  232. return describe_all(this.contents)
  233. }
  234. return this;
  235. }
  236. function Person(count = 1) {
  237. this.name = "Person";
  238. copy_defaults(this,new DefaultEntity());
  239. this.count = count;
  240. this.contents = {};
  241. this.describeOne = function (verbose=true) {
  242. sex = random_desc(["male", "female"], (verbose ? 1 : 0));
  243. body = random_desc(["skinny","fat","tall","short","stocky","spindly"], (verbose ? 0.6 : 0));
  244. species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]);
  245. return "a " + merge_desc([sex,body,species]);
  246. }
  247. this.describe = function() {
  248. if (count <= 3) {
  249. list = [];
  250. for (var i = 0; i < count; i++) {
  251. list.push(this.describeOne(this.count <= 2));
  252. }
  253. return merge_things(list);
  254. } else {
  255. return this.count + " people"
  256. }
  257. }
  258. return this;
  259. }
  260. function EmptyCar(count = 1) {
  261. this.name = "Car";
  262. copy_defaults(this,new DefaultEntity());
  263. this.count = count;
  264. this.contents = {};
  265. this.describeOne = function() {
  266. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"]);
  267. adjective = random_desc(["rusty","brand-new"],0.3);
  268. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  269. return "a parked " + merge_desc([adjective,color,type]);
  270. }
  271. this.describe = function() {
  272. if (this.count <= 3) {
  273. list = [];
  274. for (var i = 0; i < this.count; i++) {
  275. list.push(this.describeOne());
  276. }
  277. return merge_things(list);
  278. } else {
  279. return this.count + " parked cars";
  280. }
  281. }
  282. }
  283. function Car(count = 1) {
  284. this.name = "Car";
  285. copy_defaults(this,new DefaultEntity());
  286. this.count = count;
  287. this.contents = {};
  288. var amount = distribution(2,5,count);
  289. this.contents.person = new Person(amount);
  290. this.describeOne = function(verbose=true) {
  291. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"], (verbose ? 1 : 0));
  292. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  293. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  294. return "a " + merge_desc([adjective,color,type]);
  295. }
  296. this.describe = function() {
  297. if (this.count <= 3) {
  298. list = [];
  299. for (var i = 0; i < this.count; i++) {
  300. list.push(this.describeOne(this.count < 2));
  301. }
  302. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  303. } else {
  304. return this.count + " cars with " + this.contents.person.describe() + " inside";
  305. }
  306. }
  307. }
  308. function Bus(count = 1) {
  309. this.name = "Bus";
  310. copy_defaults(this,new DefaultEntity());
  311. this.count = count;
  312. this.contents = {};
  313. var amount = distribution(10,35,count);
  314. this.contents.person = new Person(amount);
  315. this.describeOne = function(verbose=true) {
  316. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  317. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  318. type = random_desc(["bus","double-decker bus","articulating bus"]);
  319. return "a " + merge_desc([adjective,color,type]);
  320. }
  321. this.describe = function() {
  322. if (this.count <= 3) {
  323. list = [];
  324. for (var i = 0; i < this.count; i++) {
  325. list.push(this.describeOne(this.count < 2));
  326. }
  327. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  328. } else {
  329. return this.count + " buses with " + this.contents.person.describe() + " inside";
  330. }
  331. }
  332. }
  333. function Motorcycle(count = 1) {
  334. this.name = "Motorcycle";
  335. copy_defaults(this,new DefaultEntity());
  336. this.count = count;
  337. this.contents = {};
  338. var amount = distribution(1,2,count);
  339. this.contents.person = new Person(amount);
  340. }
  341. function Train(count = 1) {
  342. this.name = "Train";
  343. copy_defaults(this,new DefaultEntity());
  344. this.count = count;
  345. this.contents = {};
  346. var amount = distribution(50,250,count);
  347. this.contents.person = new Person(amount);
  348. amount = distribution(10,50,count);
  349. this.contents.emptycar = new EmptyCar(amount);
  350. this.describeOne = function(verbose=true) {
  351. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  352. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  353. type = random_desc(["train","passenger train","freight train"]);
  354. return "a " + merge_desc([adjective,color,type]);
  355. }
  356. this.describe = function() {
  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 " + describe_all(this.contents) + " inside";
  363. } else {
  364. return this.count + " trains with " + describe_all(this.contents) + " inside";
  365. }
  366. }
  367. }
  368. function House(count = 1) {
  369. this.name = "House";
  370. copy_defaults(this,new DefaultEntity());
  371. this.count = count;
  372. this.contents = {};
  373. var amount = distribution(0,8,count);
  374. this.contents.person = new Person(amount);
  375. amount = distribution(0,2,count);
  376. this.contents.emptycar = new EmptyCar(amount);
  377. this.describeOne = function(verbose=true) {
  378. size = random_desc(["little","two-story","large"], (verbose ? 0.5 : 0));
  379. color = random_desc(["blue","white","gray","tan","green"], (verbose ? 0.5 : 0));
  380. name = random_desc(["house","house","house","house","house","trailer"], 1);
  381. return "a " + merge_desc([size,color,name]);
  382. }
  383. this.describe = function() {
  384. if (this.count <= 3) {
  385. list = [];
  386. for (var i = 0; i < this.count; i++) {
  387. list.push(this.describeOne(this.count < 2));
  388. }
  389. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  390. } else {
  391. return this.count + " homes with " + this.contents.person.describe() + " inside";
  392. }
  393. }
  394. }
  395. function ParkingGarage(count = 1) {
  396. this.name = "Parking Garage";
  397. copy_defaults(this,new DefaultEntity());
  398. this.count = count;
  399. this.contents = {};
  400. var amount = distribution(10,200,count);
  401. this.contents.person = new Person(amount);
  402. amount = distribution(30,100,count);
  403. this.contents.emptycar = new EmptyCar(amount);
  404. amount = distribution(5,20,count);
  405. this.contents.car = new Car(amount);
  406. this.describeOne = function(verbose=true) {
  407. return "a parking garage";
  408. }
  409. this.describe = function() {
  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 " + describe_all(this.contents) + " inside";
  416. } else {
  417. return this.count + " parking garages with " + describe_all(this.contents) + " inside";
  418. }
  419. }
  420. }
  421. function Overpass(count = 1) {
  422. this.name = "Overpass";
  423. copy_defaults(this,new DefaultEntity());
  424. this.count = count;
  425. this.contents = {};
  426. var amount = distribution(0,20,count);
  427. this.contents.person = new Person(amount);
  428. amount = distribution(25,100,count);
  429. this.contents.car = new Car(amount);
  430. }