big steppy
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

585 行
14 KiB

  1. var things =
  2. {
  3. "Container": Container,
  4. "Person": Person,
  5. "Empty Car": EmptyCar,
  6. "Car": Car,
  7. "Bus": Bus,
  8. "Tram": Tram,
  9. "Motorcycle": Motorcycle,
  10. "House": House,
  11. "Train": Train,
  12. "Parking Garage": ParkingGarage,
  13. "Overpass": Overpass,
  14. };
  15. var areas =
  16. {
  17. "Container": 0,
  18. "Person": 3,
  19. "Car": 4,
  20. "Bus": 12,
  21. "Tram": 20,
  22. "Motorcycle": 2,
  23. "House": 1000,
  24. "Train": 10000,
  25. "Parking Garage": 20000,
  26. "Overpass": 10000,
  27. };
  28. function fill_area(area, weights = {"Person": 0.1})
  29. {
  30. var testRadius = Math.sqrt(area / Math.PI);
  31. result = []
  32. for (var key in weights) {
  33. if (weights.hasOwnProperty(key)) {
  34. var objArea = areas[key];
  35. var objRadius = Math.sqrt(objArea / Math.PI);
  36. var newRadius = testRadius - objRadius;
  37. if (newRadius > 0) {
  38. var newArea = newRadius * newRadius * Math.PI;
  39. var numObjs = weights[key] * newArea;
  40. if (numObjs < 1) {
  41. numObjs = Math.random() > numObjs ? 0 : 1;
  42. }
  43. else {
  44. numObjs = Math.round(numObjs);
  45. }
  46. if (numObjs > 0)
  47. result.push(new things[key](numObjs));
  48. else {
  49. // try again with a better chance for just one
  50. }
  51. }
  52. }
  53. }
  54. if (result.length > 1)
  55. return new Container(result);
  56. else if (result.length == 1)
  57. return result[0];
  58. else
  59. return new Person();
  60. }
  61. var masses =
  62. {
  63. "Container": 0,
  64. "Person": 80,
  65. "Car": 1000,
  66. "Bus": 5000,
  67. "Motorcycle": 200,
  68. "House": 10000,
  69. "Train": 50000,
  70. "Parking Garage": 100000,
  71. "Overpass": 100000,
  72. };
  73. // describes everything in the container
  74. function describe_all(contents) {
  75. var things = [];
  76. for (var key in contents) {
  77. if (contents.hasOwnProperty(key)) {
  78. things.push(contents[key].describe());
  79. }
  80. }
  81. return merge_things(things);
  82. }
  83. function random_desc(list, odds=1) {
  84. if (Math.random() < odds)
  85. return list[Math.floor(Math.random() * list.length)];
  86. else
  87. return "";
  88. }
  89. // combine strings into a list with proper grammar
  90. function merge_things(list,semicolons=false) {
  91. if (list.length == 0) {
  92. return "";
  93. } else if (list.length == 1) {
  94. return list[0];
  95. } else if (list.length == 2) {
  96. return list[0] + " and " + list[1];
  97. } else {
  98. result = "";
  99. list.slice(0,list.length-1).forEach(function(term) {
  100. result += term + ", ";
  101. })
  102. result += "and " + list[list.length-1]
  103. return result;
  104. }
  105. }
  106. // combine the adjectives for something into a single string
  107. function merge_desc(list) {
  108. result = ""
  109. list.forEach(function(term) {
  110. if (term != "")
  111. result += term + " ";
  112. });
  113. // knock off the last space
  114. if (result.length > 0) {
  115. result = result.substring(0, result.length - 1);
  116. }
  117. return result;
  118. }
  119. // maybe make this something that approximates a
  120. // normal distribution; doing this 15,000,000 times is bad...
  121. // solution: only a few are random lul
  122. function distribution(min, max, samples) {
  123. var result = 0;
  124. var limit = Math.min(100,samples)
  125. for (var i = 0; i < limit; i++) {
  126. result += Math.floor(Math.random() * (max - min + 1) + min);
  127. }
  128. if (limit < samples) {
  129. result += Math.round((max - min) * (samples - limit));
  130. }
  131. return result;
  132. }
  133. /* default actions */
  134. function defaultStomp(thing) {
  135. return function () { return "You crush " + thing.describe() + " underfoot."};
  136. }
  137. function defaultKick(thing) {
  138. return function() { return "You punt " + thing.describe() + ", destroying " + (thing.count > 1 ? "them" : "it") + "."; }
  139. }
  140. function defaultEat(thing) {
  141. return function() { return "You scoop up " + thing.describe() + " and swallow " + (thing.count > 1 ? "them" : "it") + " whole."; }
  142. }
  143. function defaultAnalVore(thing) {
  144. return function() { return "Your ass slams down on " + thing.describe() + ". " + (thing.count > 1 ? "They slide" : "It slides") + " inside with ease."; }
  145. }
  146. function defaultArea(thing) {
  147. return areas[thing.name];
  148. }
  149. function defaultMass(thing) {
  150. return masses[thing.name];
  151. }
  152. function defaultMerge(thing) {
  153. return function(container) {
  154. var newCount = this.count + container.count;
  155. var newThing = new things[thing.name](newCount);
  156. newThing.contents = {};
  157. for (var key in this.contents) {
  158. if (this.contents.hasOwnProperty(key)) {
  159. newThing.contents[key] = this.contents[key];
  160. }
  161. }
  162. for (var key in container.contents) {
  163. if (container.contents.hasOwnProperty(key)) {
  164. if (this.contents.hasOwnProperty(key)) {
  165. newThing.contents[key] = this.contents[key].merge(container.contents[key]);
  166. } else {;
  167. newThing.contents[key] = container.contents[key];
  168. }
  169. }
  170. }
  171. return newThing;
  172. }
  173. }
  174. function defaultSum(thing) {
  175. return function() {
  176. var counts = {}
  177. if (thing.name != "Container")
  178. counts[thing.name] = thing.count;
  179. for (var key in thing.contents) {
  180. if (thing.contents.hasOwnProperty(key)) {
  181. subcount = thing.contents[key].sum();
  182. for (var subkey in subcount) {
  183. if (!counts.hasOwnProperty(subkey)) {
  184. counts[subkey] = 0;
  185. }
  186. counts[subkey] += subcount[subkey];
  187. }
  188. }
  189. }
  190. return counts;
  191. }
  192. }
  193. function defaultSumProperty(thing) {
  194. return function(prop) {
  195. var total = 0;
  196. total += thing[prop] * thing.count;
  197. for (var key in thing.contents) {
  198. if (thing.contents.hasOwnProperty(key)) {
  199. total += thing.contents[key].sum_property(prop);
  200. }
  201. }
  202. return total;
  203. }
  204. }
  205. function DefaultEntity() {
  206. this.stomp = defaultStomp;
  207. this.eat = defaultEat;
  208. this.kick = defaultKick;
  209. this.anal_vore = defaultAnalVore;
  210. this.sum = defaultSum;
  211. this.area = defaultArea;
  212. this.mass = defaultMass;
  213. this.sum_property = defaultSumProperty;
  214. this.merge = defaultMerge;
  215. return this;
  216. }
  217. // god I love reinventing the wheel
  218. function copy_defaults(self,proto) {
  219. for (var key in proto) {
  220. if (proto.hasOwnProperty(key)) {
  221. self[key] = proto[key](self)
  222. }
  223. }
  224. }
  225. function Container(contents = []) {
  226. this.name = "Container";
  227. copy_defaults(this,new DefaultEntity());
  228. this.count = 0;
  229. this.contents = {}
  230. for (var i=0; i < contents.length; i++) {
  231. this.contents[contents[i].name] = contents[i];
  232. }
  233. for (var key in this.contents) {
  234. if (this.contents.hasOwnProperty(key)) {
  235. this.count += this.contents[key].count;
  236. }
  237. }
  238. this.describe = function() {
  239. return describe_all(this.contents)
  240. }
  241. return this;
  242. }
  243. function Person(count = 1) {
  244. this.name = "Person";
  245. copy_defaults(this,new DefaultEntity());
  246. this.count = count;
  247. this.contents = {};
  248. this.describeOne = function (verbose=true) {
  249. sex = random_desc(["male", "female"], (verbose ? 1 : 0));
  250. body = random_desc(["skinny","fat","tall","short","stocky","spindly"], (verbose ? 0.6 : 0));
  251. species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]);
  252. return "a " + merge_desc([sex,body,species]);
  253. }
  254. this.describe = function() {
  255. if (count <= 3) {
  256. list = [];
  257. for (var i = 0; i < count; i++) {
  258. list.push(this.describeOne(this.count <= 2));
  259. }
  260. return merge_things(list);
  261. } else {
  262. return this.count + " people"
  263. }
  264. }
  265. return this;
  266. }
  267. function EmptyCar(count = 1) {
  268. this.name = "Car";
  269. copy_defaults(this,new DefaultEntity());
  270. this.count = count;
  271. this.contents = {};
  272. this.describeOne = function() {
  273. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"]);
  274. adjective = random_desc(["rusty","brand-new"],0.3);
  275. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  276. return "a parked " + merge_desc([adjective,color,type]);
  277. }
  278. this.describe = function() {
  279. if (this.count <= 3) {
  280. list = [];
  281. for (var i = 0; i < this.count; i++) {
  282. list.push(this.describeOne());
  283. }
  284. return merge_things(list);
  285. } else {
  286. return this.count + " parked cars";
  287. }
  288. }
  289. }
  290. function Car(count = 1) {
  291. this.name = "Car";
  292. copy_defaults(this,new DefaultEntity());
  293. this.count = count;
  294. this.contents = {};
  295. var amount = distribution(2,5,count);
  296. this.contents.person = new Person(amount);
  297. this.describeOne = function(verbose=true) {
  298. color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"], (verbose ? 1 : 0));
  299. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  300. type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]);
  301. return "a " + merge_desc([adjective,color,type]);
  302. }
  303. this.describe = function() {
  304. if (this.count <= 3) {
  305. list = [];
  306. for (var i = 0; i < this.count; i++) {
  307. list.push(this.describeOne(this.count < 2));
  308. }
  309. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  310. } else {
  311. return this.count + " cars with " + this.contents.person.describe() + " inside";
  312. }
  313. }
  314. }
  315. function Bus(count = 1) {
  316. this.name = "Bus";
  317. copy_defaults(this,new DefaultEntity());
  318. this.count = count;
  319. this.contents = {};
  320. var amount = distribution(10,35,count);
  321. this.contents.person = new Person(amount);
  322. this.describeOne = function(verbose=true) {
  323. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  324. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  325. type = random_desc(["bus","double-decker bus","articulating bus"]);
  326. return "a " + merge_desc([adjective,color,type]);
  327. }
  328. this.describe = function() {
  329. if (this.count <= 3) {
  330. list = [];
  331. for (var i = 0; i < this.count; i++) {
  332. list.push(this.describeOne(this.count < 2));
  333. }
  334. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  335. } else {
  336. return this.count + " buses with " + this.contents.person.describe() + " inside";
  337. }
  338. }
  339. }
  340. function Tram(count = 1) {
  341. this.name = "Bus";
  342. copy_defaults(this,new DefaultEntity());
  343. this.count = count;
  344. this.contents = {};
  345. var amount = distribution(40,60,count);
  346. this.contents.person = new Person(amount);
  347. this.describeOne = function(verbose=true) {
  348. adjective = random_desc(["rusty","weathered"], (verbose ? 0.3 : 0));
  349. color = random_desc(["blue","brown","gray"], (verbose ? 1 : 0));
  350. type = random_desc(["tram"]);
  351. return "a " + merge_desc([adjective,color,type]);
  352. }
  353. this.describe = function() {
  354. if (this.count <= 3) {
  355. list = [];
  356. for (var i = 0; i < this.count; i++) {
  357. list.push(this.describeOne(this.count < 2));
  358. }
  359. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  360. } else {
  361. return this.count + " trams with " + this.contents.person.describe() + " inside";
  362. }
  363. }
  364. this.anal_vore = function() {
  365. return "You slide " + this.describe() + " up your tight ass";
  366. }
  367. }
  368. function Motorcycle(count = 1) {
  369. this.name = "Motorcycle";
  370. copy_defaults(this,new DefaultEntity());
  371. this.count = count;
  372. this.contents = {};
  373. var amount = distribution(1,2,count);
  374. this.contents.person = new Person(amount);
  375. }
  376. function Train(count = 1) {
  377. this.name = "Train";
  378. copy_defaults(this,new DefaultEntity());
  379. this.count = count;
  380. this.contents = {};
  381. var amount = distribution(50,250,count);
  382. this.contents.person = new Person(amount);
  383. amount = distribution(10,50,count);
  384. this.contents.emptycar = new EmptyCar(amount);
  385. this.describeOne = function(verbose=true) {
  386. adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0));
  387. color = random_desc(["black","tan","gray"], (verbose ? 1 : 0));
  388. type = random_desc(["train","passenger train","freight train"]);
  389. return "a " + merge_desc([adjective,color,type]);
  390. }
  391. this.describe = function() {
  392. if (this.count <= 3) {
  393. list = [];
  394. for (var i = 0; i < this.count; i++) {
  395. list.push(this.describeOne(this.count < 2));
  396. }
  397. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  398. } else {
  399. return this.count + " trains with " + describe_all(this.contents) + " inside";
  400. }
  401. }
  402. }
  403. function House(count = 1) {
  404. this.name = "House";
  405. copy_defaults(this,new DefaultEntity());
  406. this.count = count;
  407. this.contents = {};
  408. var amount = distribution(0,8,count);
  409. this.contents.person = new Person(amount);
  410. amount = distribution(0,2,count);
  411. this.contents.emptycar = new EmptyCar(amount);
  412. this.describeOne = function(verbose=true) {
  413. size = random_desc(["little","two-story","large"], (verbose ? 0.5 : 0));
  414. color = random_desc(["blue","white","gray","tan","green"], (verbose ? 0.5 : 0));
  415. name = random_desc(["house","house","house","house","house","trailer"], 1);
  416. return "a " + merge_desc([size,color,name]);
  417. }
  418. this.describe = function() {
  419. if (this.count <= 3) {
  420. list = [];
  421. for (var i = 0; i < this.count; i++) {
  422. list.push(this.describeOne(this.count < 2));
  423. }
  424. return merge_things(list) + " with " + this.contents.person.describe() + " inside";
  425. } else {
  426. return this.count + " homes with " + this.contents.person.describe() + " inside";
  427. }
  428. }
  429. }
  430. function ParkingGarage(count = 1) {
  431. this.name = "Parking Garage";
  432. copy_defaults(this,new DefaultEntity());
  433. this.count = count;
  434. this.contents = {};
  435. var amount = distribution(10,200,count);
  436. this.contents.person = new Person(amount);
  437. amount = distribution(30,100,count);
  438. this.contents.emptycar = new EmptyCar(amount);
  439. amount = distribution(5,20,count);
  440. this.contents.car = new Car(amount);
  441. this.describeOne = function(verbose=true) {
  442. return "a parking garage";
  443. }
  444. this.describe = function() {
  445. if (this.count <= 3) {
  446. list = [];
  447. for (var i = 0; i < this.count; i++) {
  448. list.push(this.describeOne(this.count < 2));
  449. }
  450. return merge_things(list) + " with " + describe_all(this.contents) + " inside";
  451. } else {
  452. return this.count + " parking garages with " + describe_all(this.contents) + " inside";
  453. }
  454. }
  455. }
  456. function Overpass(count = 1) {
  457. this.name = "Overpass";
  458. copy_defaults(this,new DefaultEntity());
  459. this.count = count;
  460. this.contents = {};
  461. var amount = distribution(0,20,count);
  462. this.contents.person = new Person(amount);
  463. amount = distribution(25,100,count);
  464. this.contents.car = new Car(amount);
  465. }