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.
 
 
 

530 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 defaultSum(thing) {
  146. return function() {
  147. var counts = {}
  148. if (thing.name != "Container")
  149. counts[thing.name] = thing.count;
  150. for (var key in thing.contents) {
  151. if (thing.contents.hasOwnProperty(key)) {
  152. subcount = thing.contents[key].sum();
  153. for (var subkey in subcount) {
  154. if (!counts.hasOwnProperty(subkey)) {
  155. counts[subkey] = 0;
  156. }
  157. counts[subkey] += subcount[subkey];
  158. }
  159. }
  160. }
  161. return counts;
  162. }
  163. }
  164. function defaultSumProperty(thing) {
  165. return function(prop) {
  166. var total = 0;
  167. total += thing[prop] * thing.count;
  168. for (var key in thing.contents) {
  169. if (thing.contents.hasOwnProperty(key)) {
  170. total += thing.contents[key].sum_property(prop);
  171. }
  172. }
  173. return total;
  174. }
  175. }
  176. function DefaultEntity() {
  177. this.stomp = defaultStomp;
  178. this.eat = defaultEat;
  179. this.kick = defaultKick;
  180. this.anal_vore = defaultAnalVore;
  181. this.sum = defaultSum;
  182. this.area = defaultArea;
  183. this.mass = defaultMass;
  184. this.sum_property = defaultSumProperty;
  185. return this;
  186. }
  187. // god I love reinventing the wheel
  188. function copy_defaults(self,proto) {
  189. for (var key in proto) {
  190. if (proto.hasOwnProperty(key)) {
  191. self[key] = proto[key](self)
  192. }
  193. }
  194. }
  195. function Container(contents = []) {
  196. this.name = "Container";
  197. copy_defaults(this,new DefaultEntity());
  198. this.count = 0;
  199. this.contents = {}
  200. for (var i=0; i < contents.length; i++) {
  201. this.contents[contents[i].name] = contents[i];
  202. }
  203. for (var key in this.contents) {
  204. if (this.contents.hasOwnProperty(key)) {
  205. this.count += this.contents[key].count;
  206. }
  207. }
  208. this.describe = function() {
  209. return describe_all(this.contents)
  210. }
  211. // put another container into this one
  212. this.merge = function(container) {
  213. for (var key in container.contents) {
  214. if (container.contents.hasOwnProperty(key)) {
  215. if (this.contents.hasOwnProperty(key)) {
  216. this.count += container.contents[key].count;
  217. this.contents[key] = new things[container.contents[key].name](container.contents[key].count + this.contents[key].count);
  218. } else {
  219. this.count += container.contents[key].count;
  220. this.contents[key] = new things[container.contents[key].name](container.contents[key].count);
  221. }
  222. }
  223. }
  224. }
  225. return this;
  226. }
  227. function Person(count = 1) {
  228. this.name = "Person";
  229. copy_defaults(this,new DefaultEntity());
  230. this.count = count;
  231. this.contents = {};
  232. this.describeOne = function (verbose=true) {
  233. sex = random_desc(["male", "female"], (verbose ? 1 : 0));
  234. body = random_desc(["skinny","fat","tall","short","stocky","spindly"], (verbose ? 0.6 : 0));
  235. species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]);
  236. return "a " + merge_desc([sex,body,species]);
  237. }
  238. this.describe = function() {
  239. if (count <= 3) {
  240. list = [];
  241. for (var i = 0; i < count; i++) {
  242. list.push(this.describeOne(this.count <= 2));
  243. }
  244. return merge_things(list);
  245. } else {
  246. return this.count + " people"
  247. }
  248. }
  249. return this;
  250. }
  251. function EmptyCar(count = 1) {
  252. this.name = "Car";
  253. copy_defaults(this,new DefaultEntity());
  254. this.count = count;
  255. this.contents = {};
  256. this.describeOne = function() {
  257. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"]);
  258. adjective = random_desc(["rusty","brand-new"],0.3);
  259. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  260. return "a parked " + merge_desc([adjective,color,type]);
  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());
  267. }
  268. return merge_things(list);
  269. } else {
  270. return this.count + " parked cars";
  271. }
  272. }
  273. }
  274. function Car(count = 1) {
  275. this.name = "Car";
  276. copy_defaults(this,new DefaultEntity());
  277. this.count = count;
  278. this.contents = {};
  279. var amount = distribution(2,5,count);
  280. this.contents.person = new Person(amount);
  281. this.describeOne = function(verbose=true) {
  282. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"], (verbose ? 1 : 0));
  283. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  284. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  285. return "a " + merge_desc([adjective,color,type]);
  286. }
  287. this.describe = function() {
  288. if (this.count <= 3) {
  289. list = [];
  290. for (var i = 0; i < this.count; i++) {
  291. list.push(this.describeOne(this.count < 2));
  292. }
  293. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  294. } else {
  295. return this.count + " cars with " + this.contents.person.describe() + " inside";
  296. }
  297. }
  298. }
  299. function Bus(count = 1) {
  300. this.name = "Bus";
  301. copy_defaults(this,new DefaultEntity());
  302. this.count = count;
  303. this.contents = {};
  304. var amount = distribution(10,35,count);
  305. this.contents.person = new Person(amount);
  306. this.describeOne = function(verbose=true) {
  307. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  308. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  309. type = random_desc(["bus","double-decker bus","articulating bus"]);
  310. return "a " + merge_desc([adjective,color,type]);
  311. }
  312. this.describe = function() {
  313. if (this.count <= 3) {
  314. list = [];
  315. for (var i = 0; i < this.count; i++) {
  316. list.push(this.describeOne(this.count < 2));
  317. }
  318. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  319. } else {
  320. return this.count + " buses with " + this.contents.person.describe() + " inside";
  321. }
  322. }
  323. }
  324. function Motorcycle(count = 1) {
  325. this.name = "Motorcycle";
  326. copy_defaults(this,new DefaultEntity());
  327. this.count = count;
  328. this.contents = {};
  329. var amount = distribution(1,2,count);
  330. this.contents.person = new Person(amount);
  331. }
  332. function Train(count = 1) {
  333. this.name = "Train";
  334. copy_defaults(this,new DefaultEntity());
  335. this.count = count;
  336. this.contents = {};
  337. var amount = distribution(50,250,count);
  338. this.contents.person = new Person(amount);
  339. amount = distribution(10,50,count);
  340. this.contents.emptycar = new EmptyCar(amount);
  341. this.describeOne = function(verbose=true) {
  342. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  343. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  344. type = random_desc(["train","passenger train","freight train"]);
  345. return "a " + merge_desc([adjective,color,type]);
  346. }
  347. this.describe = function() {
  348. if (this.count <= 3) {
  349. list = [];
  350. for (var i = 0; i < this.count; i++) {
  351. list.push(this.describeOne(this.count < 2));
  352. }
  353. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  354. } else {
  355. return this.count + " trains with " + describe_all(this.contents) + " inside";
  356. }
  357. }
  358. }
  359. function House(count = 1) {
  360. this.name = "House";
  361. copy_defaults(this,new DefaultEntity());
  362. this.count = count;
  363. this.contents = {};
  364. var amount = distribution(0,8,count);
  365. this.contents.person = new Person(amount);
  366. amount = distribution(0,2,count);
  367. this.contents.emptycar = new EmptyCar(amount);
  368. this.describeOne = function(verbose=true) {
  369. size = random_desc(["little","two-story","large"], (verbose ? 0.5 : 0));
  370. color = random_desc(["blue","white","gray","tan","green"], (verbose ? 0.5 : 0));
  371. name = random_desc(["house","house","house","house","house","trailer"], 1);
  372. return "a " + merge_desc([size,color,name]);
  373. }
  374. this.describe = function() {
  375. if (this.count <= 3) {
  376. list = [];
  377. for (var i = 0; i < this.count; i++) {
  378. list.push(this.describeOne(this.count < 2));
  379. }
  380. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  381. } else {
  382. return this.count + " homes with " + this.contents.person.describe() + " inside";
  383. }
  384. }
  385. }
  386. function ParkingGarage(count = 1) {
  387. this.name = "Parking Garage";
  388. copy_defaults(this,new DefaultEntity());
  389. this.count = count;
  390. this.contents = {};
  391. var amount = distribution(10,200,count);
  392. this.contents.person = new Person(amount);
  393. amount = distribution(30,100,count);
  394. this.contents.emptycar = new EmptyCar(amount);
  395. amount = distribution(5,20,count);
  396. this.contents.car = new Car(amount);
  397. this.describeOne = function(verbose=true) {
  398. return "a parking garage";
  399. }
  400. this.describe = function() {
  401. if (this.count <= 3) {
  402. list = [];
  403. for (var i = 0; i < this.count; i++) {
  404. list.push(this.describeOne(this.count < 2));
  405. }
  406. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  407. } else {
  408. return this.count + " parking garages with " + describe_all(this.contents) + " inside";
  409. }
  410. }
  411. }
  412. function Overpass(count = 1) {
  413. this.name = "Overpass";
  414. copy_defaults(this,new DefaultEntity());
  415. this.count = count;
  416. this.contents = {};
  417. var amount = distribution(0,20,count);
  418. this.contents.person = new Person(amount);
  419. amount = distribution(25,100,count);
  420. this.contents.car = new Car(amount);
  421. }