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.
 
 
 

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