| @@ -6,7 +6,7 @@ function random_desc(list, odds=1) { | |||||
| return ""; | return ""; | ||||
| } | } | ||||
| function merge_things(list) { | |||||
| function merge_things(list,semicolons=false) { | |||||
| if (list.length == 0) { | if (list.length == 0) { | ||||
| return ""; | return ""; | ||||
| } else if (list.length == 1) { | } else if (list.length == 1) { | ||||
| @@ -53,14 +53,34 @@ function distribution(min, max, samples) { | |||||
| return result; | return result; | ||||
| } | } | ||||
| /* default actions */ | |||||
| function defaultStomp(thing) { | |||||
| return "You crush " + thing.describe() + " underfoot."; | |||||
| } | |||||
| function defaultKick(thing) { | |||||
| return "You punt " + thing.describe() + ", destroying " + (thing.count > 1 ? "them" : "it") + "."; | |||||
| } | |||||
| function defaultEat(thing) { | |||||
| return "You scoop up " + thing.describe() + " and swallow " + (thing.count > 1 ? "them" : "it") + " whole."; | |||||
| } | |||||
| function DefaultEntity() { | |||||
| this.stomp = defaultStomp; | |||||
| this.eat = defaultEat; | |||||
| this.kick = defaultKick; | |||||
| return this; | |||||
| } | |||||
| function Person(count = 1) { | function Person(count = 1) { | ||||
| this.name = "Person"; | this.name = "Person"; | ||||
| this.count = count; | this.count = count; | ||||
| this.contents = []; | |||||
| this.describeOne = function () { | |||||
| sex = random_desc(["male", "female"]); | |||||
| body = random_desc(["skinny","fat","tall","short","stocky","spindly"],0.6); | |||||
| this.contents = {}; | |||||
| this.describeOne = function (verbose=true) { | |||||
| sex = random_desc(["male", "female"], (verbose ? 1 : 0)); | |||||
| body = random_desc(["skinny","fat","tall","short","stocky","spindly"], (verbose ? 0.6 : 0)); | |||||
| species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]); | species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]); | ||||
| return "a " + merge_desc([sex,body,species]); | return "a " + merge_desc([sex,body,species]); | ||||
| } | } | ||||
| @@ -69,11 +89,11 @@ function Person(count = 1) { | |||||
| if (count <= 3) { | if (count <= 3) { | ||||
| list = []; | list = []; | ||||
| for (var i = 0; i < count; i++) { | for (var i = 0; i < count; i++) { | ||||
| list.push(this.describeOne()); | |||||
| list.push(this.describeOne(this.count <= 2)); | |||||
| } | } | ||||
| return merge_things(list); | return merge_things(list); | ||||
| } else { | } else { | ||||
| return this.count + " people." | |||||
| return this.count + " people" | |||||
| } | } | ||||
| } | } | ||||
| @@ -83,72 +103,161 @@ function Person(count = 1) { | |||||
| function EmptyCar(count = 1) { | function EmptyCar(count = 1) { | ||||
| this.name = "Car"; | this.name = "Car"; | ||||
| this.count = count; | this.count = count; | ||||
| this.contents = []; | |||||
| this.contents = {}; | |||||
| this.describeOne | |||||
| this.describeOne = function() { | |||||
| color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"]); | |||||
| adjective = random_desc(["rusty","brand-new"],0.3); | |||||
| type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]); | |||||
| return "a parked " + merge_desc([adjective,color,type]); | |||||
| } | |||||
| this.describe = function() { | |||||
| if (this.count <= 3) { | |||||
| list = []; | |||||
| for (var i = 0; i < this.count; i++) { | |||||
| list.push(this.describeOne()); | |||||
| } | |||||
| return merge_things(list); | |||||
| } else { | |||||
| return this.count + " parked cars" | |||||
| } | |||||
| } | |||||
| } | } | ||||
| function Car(count = 1) { | function Car(count = 1) { | ||||
| this.name = "Car"; | this.name = "Car"; | ||||
| this.count = count; | this.count = count; | ||||
| this.contents = []; | |||||
| this.contents = {}; | |||||
| var amount = distribution(2,5,count); | var amount = distribution(2,5,count); | ||||
| this.contents.push(new Person(amount)); | |||||
| this.contents.person = new Person(amount); | |||||
| this.describeOne = function(verbose=true) { | |||||
| color = random_desc(["black","black","gray","gray","blue","red","tan","white","white"], (verbose ? 1 : 0)); | |||||
| adjective = random_desc(["rusty","brand-new"], (verbose ? 0.3 : 0)); | |||||
| type = random_desc(["SUV","coupe","sedan","truck","van","convertible"]); | |||||
| return "a " + merge_desc([adjective,color,type]); | |||||
| } | |||||
| this.describe = function() { | |||||
| if (this.count <= 3) { | |||||
| list = []; | |||||
| for (var i = 0; i < this.count; i++) { | |||||
| list.push(this.describeOne(this.count < 2)); | |||||
| } | |||||
| return merge_things(list) + " with " + this.contents.person.describe() + " inside"; | |||||
| } else { | |||||
| return this.count + " cars with " + this.contents.person.describe() + " inside"; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| function Bus(count = 1) { | function Bus(count = 1) { | ||||
| this.name = "Bus"; | this.name = "Bus"; | ||||
| this.count = count; | this.count = count; | ||||
| this.contents = []; | |||||
| this.contents = {}; | |||||
| this.resolved = false; | this.resolved = false; | ||||
| var amount = distribution(10,35,count); | var amount = distribution(10,35,count); | ||||
| this.contents.push(new Person(amount)); | |||||
| this.contents.person = new Person(amount); | |||||
| this.describeOne = function(verbose=true) { | |||||
| color = random_desc(["black","tan","gray"], (verbose ? 1 : 0)); | |||||
| type = random_desc(["bus","double-decker bus","articulating bus"]); | |||||
| return "a " + merge_desc([adjective,color,type]); | |||||
| } | |||||
| this.describe = function() { | |||||
| if (this.count <= 3) { | |||||
| list = []; | |||||
| for (var i = 0; i < this.count; i++) { | |||||
| list.push(this.describeOne(this.count < 2)); | |||||
| } | |||||
| return merge_things(list) + " with " + this.contents.person.describe() + " inside"; | |||||
| } else { | |||||
| return this.count + " buses with " + this.contents.person.describe() + " inside"; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| function Motorcycle(count = 1) { | function Motorcycle(count = 1) { | ||||
| this.name = "Motorcycle"; | this.name = "Motorcycle"; | ||||
| this.count = count; | this.count = count; | ||||
| this.contents = []; | |||||
| this.contents = {}; | |||||
| var amount = distribution(1,2,count); | var amount = distribution(1,2,count); | ||||
| this.contents.push(new Person(amount)); | |||||
| this.contents.person = new Person(amount); | |||||
| } | } | ||||
| function Train(count = 1) { | function Train(count = 1) { | ||||
| this.name = "Train"; | this.name = "Train"; | ||||
| this.count = count; | this.count = count; | ||||
| this.contents = []; | |||||
| this.contents = {}; | |||||
| var amount = distribution(20,60,count); | var amount = distribution(20,60,count); | ||||
| this.contents.push(new Person(amount)); | |||||
| this.contents.person = new Person(amount); | |||||
| } | } | ||||
| function House(count = 1) { | function House(count = 1) { | ||||
| this.name = "House"; | this.name = "House"; | ||||
| this.count = count; | this.count = count; | ||||
| this.contents = []; | |||||
| this.contents = {}; | |||||
| var amount = distribution(0,8,count); | var amount = distribution(0,8,count); | ||||
| this.contents.push(new Person(amount)); | |||||
| this.contents.person = new Person(amount); | |||||
| amount = distribution(0,2,count); | amount = distribution(0,2,count); | ||||
| this.contents.push(new Car(amount)); | |||||
| this.contents.emptycar = new EmptyCar(amount); | |||||
| this.describeOne = function(verbose=true) { | |||||
| size = random_desc(["little","two-story","large"], (verbose ? 0.5 : 0)); | |||||
| color = random_desc(["blue","white","gray","tan","green"], (verbose ? 0.5 : 0)); | |||||
| name = random_desc(["house","house","house","house","house","trailer"], 1); | |||||
| return "a " + merge_desc([size,color,name]); | |||||
| } | |||||
| this.describe = function() { | |||||
| if (this.count <= 3) { | |||||
| list = []; | |||||
| for (var i = 0; i < this.count; i++) { | |||||
| list.push(this.describeOne(this.count < 2)); | |||||
| } | |||||
| return merge_things(list) + " with " + this.contents.person.describe() + " inside"; | |||||
| } else { | |||||
| return this.count + " homes with " + this.contents.person.describe() + " inside"; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| function ParkingGarage(count = 1) { | function ParkingGarage(count = 1) { | ||||
| this.name = "Parking Garage"; | this.name = "Parking Garage"; | ||||
| this.count = count; | this.count = count; | ||||
| this.contents = []; | |||||
| this.contents = {}; | |||||
| var amount = distribution(10,200,count); | var amount = distribution(10,200,count); | ||||
| this.contents.push(new Person(amount)); | |||||
| this.contents.person = new Person(amount); | |||||
| amount = distribution(30,100,count); | amount = distribution(30,100,count); | ||||
| this.contents.push(new EmptyCar(amount)); | |||||
| this.contents.emptycar = new EmptyCar(amount); | |||||
| amount = distribution(5,20,count); | amount = distribution(5,20,count); | ||||
| this.contents.push(new Car(amount)); | |||||
| this.contents.car = new Car(amount); | |||||
| this.describeOne = function(verbose=true) { | |||||
| return "a parking garage"; | |||||
| } | |||||
| this.describe = function() { | |||||
| if (this.count <= 3) { | |||||
| list = []; | |||||
| for (var i = 0; i < this.count; i++) { | |||||
| list.push(this.describeOne(this.count < 2)); | |||||
| } | |||||
| return merge_things(list) + " with " + merge_things([this.contents.person.describe(),this.contents.emptycar.describe(),this.contents.car.describe()]) + " inside"; | |||||
| } else { | |||||
| return this.count + " parking garages with " + this.contents.person.describe() + " inside"; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| function Overpass(count = 1) { | function Overpass(count = 1) { | ||||
| this.name = "Overpass"; | this.name = "Overpass"; | ||||
| this.count = count; | this.count = count; | ||||
| this.contents = []; | |||||
| this.contents = {}; | |||||
| var amount = distribution(0,20,count); | var amount = distribution(0,20,count); | ||||
| this.contents.push(new Person(amount)); | |||||
| this.contents.person = new Person(amount); | |||||
| amount = distribution(25,100,count); | amount = distribution(25,100,count); | ||||
| this.contents.push(new Car(amount)); | |||||
| this.contents.car = new Car(amount); | |||||
| } | } | ||||