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.
 
 
 

418 lines
9.7 KiB

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