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.
 
 
 

387 lines
9.6 KiB

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