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.
 
 
 

516 line
12 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": 1,
  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. return this;
  212. }
  213. function Person(count = 1) {
  214. this.name = "Person";
  215. copy_defaults(this,new DefaultEntity());
  216. this.count = count;
  217. this.contents = {};
  218. this.describeOne = function (verbose=true) {
  219. sex = random_desc(["male", "female"], (verbose ? 1 : 0));
  220. body = random_desc(["skinny","fat","tall","short","stocky","spindly"], (verbose ? 0.6 : 0));
  221. species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]);
  222. return "a " + merge_desc([sex,body,species]);
  223. }
  224. this.describe = function() {
  225. if (count <= 3) {
  226. list = [];
  227. for (var i = 0; i < count; i++) {
  228. list.push(this.describeOne(this.count <= 2));
  229. }
  230. return merge_things(list);
  231. } else {
  232. return this.count + " people"
  233. }
  234. }
  235. return this;
  236. }
  237. function EmptyCar(count = 1) {
  238. this.name = "Car";
  239. copy_defaults(this,new DefaultEntity());
  240. this.count = count;
  241. this.contents = {};
  242. this.describeOne = function() {
  243. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"]);
  244. adjective = random_desc(["rusty","brand-new"],0.3);
  245. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  246. return "a parked " + merge_desc([adjective,color,type]);
  247. }
  248. this.describe = function() {
  249. if (this.count <= 3) {
  250. list = [];
  251. for (var i = 0; i < this.count; i++) {
  252. list.push(this.describeOne());
  253. }
  254. return merge_things(list);
  255. } else {
  256. return this.count + " parked cars";
  257. }
  258. }
  259. }
  260. function Car(count = 1) {
  261. this.name = "Car";
  262. copy_defaults(this,new DefaultEntity());
  263. this.count = count;
  264. this.contents = {};
  265. var amount = distribution(2,5,count);
  266. this.contents.person = new Person(amount);
  267. this.describeOne = function(verbose=true) {
  268. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"], (verbose ? 1 : 0));
  269. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  270. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  271. return "a " + merge_desc([adjective,color,type]);
  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 + " cars with " + this.contents.person.describe() + " inside";
  282. }
  283. }
  284. }
  285. function Bus(count = 1) {
  286. this.name = "Bus";
  287. copy_defaults(this,new DefaultEntity());
  288. this.count = count;
  289. this.contents = {};
  290. var amount = distribution(10,35,count);
  291. this.contents.person = new Person(amount);
  292. this.describeOne = function(verbose=true) {
  293. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  294. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  295. type = random_desc(["bus","double-decker bus","articulating bus"]);
  296. return "a " + merge_desc([adjective,color,type]);
  297. }
  298. this.describe = function() {
  299. if (this.count <= 3) {
  300. list = [];
  301. for (var i = 0; i < this.count; i++) {
  302. list.push(this.describeOne(this.count < 2));
  303. }
  304. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  305. } else {
  306. return this.count + " buses with " + this.contents.person.describe() + " inside";
  307. }
  308. }
  309. }
  310. function Motorcycle(count = 1) {
  311. this.name = "Motorcycle";
  312. copy_defaults(this,new DefaultEntity());
  313. this.count = count;
  314. this.contents = {};
  315. var amount = distribution(1,2,count);
  316. this.contents.person = new Person(amount);
  317. }
  318. function Train(count = 1) {
  319. this.name = "Train";
  320. copy_defaults(this,new DefaultEntity());
  321. this.count = count;
  322. this.contents = {};
  323. var amount = distribution(50,250,count);
  324. this.contents.person = new Person(amount);
  325. amount = distribution(10,50,count);
  326. this.contents.emptycar = new EmptyCar(amount);
  327. this.describeOne = function(verbose=true) {
  328. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  329. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  330. type = random_desc(["train","passenger train","freight train"]);
  331. return "a " + merge_desc([adjective,color,type]);
  332. }
  333. this.describe = function() {
  334. if (this.count <= 3) {
  335. list = [];
  336. for (var i = 0; i < this.count; i++) {
  337. list.push(this.describeOne(this.count < 2));
  338. }
  339. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  340. } else {
  341. return this.count + " trains with " + describe_all(this.contents) + " inside";
  342. }
  343. }
  344. }
  345. function House(count = 1) {
  346. this.name = "House";
  347. copy_defaults(this,new DefaultEntity());
  348. this.count = count;
  349. this.contents = {};
  350. var amount = distribution(0,8,count);
  351. this.contents.person = new Person(amount);
  352. amount = distribution(0,2,count);
  353. this.contents.emptycar = new EmptyCar(amount);
  354. this.describeOne = function(verbose=true) {
  355. size = random_desc(["little","two-story","large"], (verbose ? 0.5 : 0));
  356. color = random_desc(["blue","white","gray","tan","green"], (verbose ? 0.5 : 0));
  357. name = random_desc(["house","house","house","house","house","trailer"], 1);
  358. return "a " + merge_desc([size,color,name]);
  359. }
  360. this.describe = function() {
  361. if (this.count <= 3) {
  362. list = [];
  363. for (var i = 0; i < this.count; i++) {
  364. list.push(this.describeOne(this.count < 2));
  365. }
  366. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  367. } else {
  368. return this.count + " homes with " + this.contents.person.describe() + " inside";
  369. }
  370. }
  371. }
  372. function ParkingGarage(count = 1) {
  373. this.name = "Parking Garage";
  374. copy_defaults(this,new DefaultEntity());
  375. this.count = count;
  376. this.contents = {};
  377. var amount = distribution(10,200,count);
  378. this.contents.person = new Person(amount);
  379. amount = distribution(30,100,count);
  380. this.contents.emptycar = new EmptyCar(amount);
  381. amount = distribution(5,20,count);
  382. this.contents.car = new Car(amount);
  383. this.describeOne = function(verbose=true) {
  384. return "a parking garage";
  385. }
  386. this.describe = function() {
  387. if (this.count <= 3) {
  388. list = [];
  389. for (var i = 0; i < this.count; i++) {
  390. list.push(this.describeOne(this.count < 2));
  391. }
  392. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  393. } else {
  394. return this.count + " parking garages with " + describe_all(this.contents) + " inside";
  395. }
  396. }
  397. }
  398. function Overpass(count = 1) {
  399. this.name = "Overpass";
  400. copy_defaults(this,new DefaultEntity());
  401. this.count = count;
  402. this.contents = {};
  403. var amount = distribution(0,20,count);
  404. this.contents.person = new Person(amount);
  405. amount = distribution(25,100,count);
  406. this.contents.car = new Car(amount);
  407. }