|
| 1 | +"use strict" |
| 2 | + |
| 3 | +createItem("me", PLAYER(), { |
| 4 | + loc:"lounge", |
| 5 | + synonyms:['me', 'myself'], |
| 6 | + examine: "Just a regular guy.", |
| 7 | +}) |
| 8 | + |
| 9 | +createRoom("lounge", { |
| 10 | + desc:"Welcome, your majesty...", |
| 11 | +}) |
| 12 | + |
| 13 | + |
| 14 | +createItem("home", { |
| 15 | + progress:0, // i.e., turn |
| 16 | + population:100, |
| 17 | + food:100, |
| 18 | + money:100, |
| 19 | + happiness:'contented', |
| 20 | + |
| 21 | + initTurn:function() { |
| 22 | + this.output = [] |
| 23 | + }, |
| 24 | + |
| 25 | + beforeTurn:function() { |
| 26 | + this.progress += 1 |
| 27 | + }, |
| 28 | + |
| 29 | + doTurn:function() { |
| 30 | + // handle discoveries |
| 31 | + for (const key in w) { |
| 32 | + const o = w[key] |
| 33 | + if (!o.discovery) continue |
| 34 | + if (o.discovered) continue |
| 35 | + log(o.name + ' (' + o.discoverAt + ')') |
| 36 | + const owner = w[o.belongsTo] |
| 37 | + log('- ' + owner.name + ' (' + owner.progress + ')') |
| 38 | + if (!owner) { |
| 39 | + return errormsg('The "belongsTo" attribute of ' + o.name + ' is wrong or missing:' + o.belongsTo) |
| 40 | + } |
| 41 | + if (o.discoverAt <= owner.progress) { |
| 42 | + o.discovered = true |
| 43 | + home.output.push(o.discovery) |
| 44 | + } |
| 45 | + } |
| 46 | + }, |
| 47 | +}) |
| 48 | + |
| 49 | +// for convenience |
| 50 | +const home = w.home |
| 51 | + |
| 52 | +// progress tracks how far we have got in each aspect |
| 53 | +// efficiency allows us to tweak how well we do each turn |
| 54 | +// bonus is an in-game modifier |
| 55 | + |
| 56 | + |
| 57 | +createItem("agriculture", { |
| 58 | + foodBySeason:[0, 15, 50, 135], |
| 59 | + foodCommentBySeason:['No food produced in winter', 'Hunters have found limited food across the spring.', 'Hunters have found plenty of food across the summer.', 'Food has been harvested from the fields'], |
| 60 | + foodFactor:0.4, // one person eats this much food each turn |
| 61 | + populationGrowth:0.02, // pop increases by this each turn unless starving |
| 62 | + starvationFactor:2, // how quickly people die when starving |
| 63 | + efficiency:1, // how well farms do |
| 64 | + |
| 65 | + initTurn:function() { |
| 66 | + this.bonus = 0 |
| 67 | + }, |
| 68 | + |
| 69 | + doTurn:function() { |
| 70 | + log("Bonus: " + this.bonus) |
| 71 | + const season = home.progress % 4 |
| 72 | + home.output.push(this.foodCommentBySeason[season]) |
| 73 | + home.food += this.foodBySeason[season] * this.efficiency * (100 + this.bonus) / 100 |
| 74 | + |
| 75 | + const foodConsumption = this.foodFactor * home.population |
| 76 | + if (foodConsumption > home.food) { |
| 77 | + home.population -= Math.floor((foodConsumption - home.food) / this.starvationFactor) |
| 78 | + home.food = 0 |
| 79 | + home.output.push('People are starving!') |
| 80 | + } |
| 81 | + else { |
| 82 | + home.population += Math.floor(home.population * this.populationGrowth) |
| 83 | + home.food -= foodConsumption |
| 84 | + } |
| 85 | + }, |
| 86 | +}) |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +createItem("science", PROGRESSABLE(), { |
| 92 | + alias:'Science Minister', |
| 93 | + dept:true, |
| 94 | + efficiency:1, |
| 95 | + examine:"Science is important to any nation; it can lead to more efficient agriculure, new industries and better weapons. And no good ruler wants anyone to think his kingdom is a technologcal backwater.", |
| 96 | + discovered:true, // known from the start |
| 97 | + |
| 98 | + |
| 99 | +}) |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | +createDiscovery("crop_rotation", { |
| 104 | + discovery:'"Your magesty, our neighbours are getting better yields from the land using a system called crop rotation, whereby a field is used for grain one year, legumes the next and left fallow for livesock the next. Perhaps you might discuss with the miniser for the land."', |
| 105 | + belongsTo:'science', |
| 106 | + discoverAt:2, |
| 107 | + bonusValue:20, |
| 108 | + bonusTo:'agriculture', |
| 109 | + question:"Implement crop rotation?", |
| 110 | +}) |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +createItem("druids", PROGRESSABLE(), { |
| 115 | + alias:'Druid representative', |
| 116 | + dept:true, |
| 117 | + efficiency:1, |
| 118 | + examine:"Druids worship the earth mother, at a sacred grove in the forest.", |
| 119 | + |
| 120 | + belongsTo:'home', |
| 121 | + discoverAt:7, |
| 122 | + discovery:'"Your magesty, a group of druids have found a sacred grove in the forest, and wish to use it in their arcane rituals."', |
| 123 | +}) |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | +createDiscovery("arcane_rituals", { |
| 128 | + discovery:'"Your majesty, the earth goddess has indicated she wishes us to perform certain rituals. I can assure you that if you will permit us to perform these sacred duties properly, crops will be even more bountiful"."', |
| 129 | + alias:'Fertility rituals', |
| 130 | + belongsTo:'druids', |
| 131 | + discoverAt:1, |
| 132 | + bonusValue:20, |
| 133 | + bonusTo:'agriculture', |
| 134 | + question:"Allow the druids to perform arcane rituals?", |
| 135 | +}) |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | +createDiscovery("moonlight_dancing", { |
| 140 | + discovery:'"Your majesty, the earth goddess has indicated she wishes us to perform certain rituals in a more natural form under the light of the full moon, but the yokels object to our naked dancing. I can assure you that if you will permit us to perform these sacred duties properly, crops will be even more bountiful"."', |
| 141 | + alias:'Fertility rituals 2', |
| 142 | + supercedes:"arcane_rituals", |
| 143 | + belongsTo:'druids', |
| 144 | + discoverAt:4, |
| 145 | + bonusValue:20, |
| 146 | + bonusTo:'agriculture', |
| 147 | + beforeTurn:function() { |
| 148 | + if (this.active === 2) w[this.bonusTo].bonus += this.bonusValue |
| 149 | + if (this.active === 1) w[this.bonusTo].bonus += w[this.supercedes].bonusValue |
| 150 | + }, |
| 151 | + question:"Allow the druids to perform naked rituals under the moonlight at the risk of alienating locals?", |
| 152 | + choices:[ |
| 153 | + { |
| 154 | + alias:'Allow naked moonlit rituals', |
| 155 | + properNoun:true, |
| 156 | + script:function() { |
| 157 | + w[options.topic.discoveryName].active = 2 |
| 158 | + msg(options.topic.alias + ": Naked/moonlit") |
| 159 | + } |
| 160 | + }, |
| 161 | + { |
| 162 | + alias:'Allow basic rituals only', |
| 163 | + properNoun:true, |
| 164 | + script:function() { |
| 165 | + w[options.topic.discoveryName].active = 1 |
| 166 | + msg(options.topic.alias + ": Basic") |
| 167 | + } |
| 168 | + }, |
| 169 | + { |
| 170 | + alias:'Forbid rituals', |
| 171 | + properNoun:true, |
| 172 | + script:function() { |
| 173 | + w[options.topic.discoveryName].active = 0 |
| 174 | + msg(options.topic.alias + ": Disabled") |
| 175 | + } |
| 176 | + }, |
| 177 | + ], |
| 178 | + |
| 179 | +}) |
| 180 | + |
| 181 | + |
| 182 | + |
| 183 | + |
0 commit comments