diff --git a/main.ms b/main.ms index b9af46c..cddbce0 100644 --- a/main.ms +++ b/main.ms @@ -65,6 +65,7 @@ ensureImport "shields" ensureImport "tiles" ensureImport "weapons" ensureImport "names" +ensureImport "phrases" ensureImport "arenaGenerator" ensureImport "randomDungeonGenerator" @@ -260,3 +261,5 @@ main = function() end function main() +clear +print "All done!" diff --git a/src/entity.ms b/src/entity.ms index 92ae273..19e4480 100644 --- a/src/entity.ms +++ b/src/entity.ms @@ -39,6 +39,11 @@ Entity.str = function() return self.name end function +// This function will return true if the examine functionality has been overridden. +Entity.examineOverride = function() + return false +end function + Entity.describe = function(display, bounds) ui.drawText(display, "HP: {0}/{1}".fill([self.currentHP, self.maxHP]), bounds, Color.orange.str()) bounds.height -= 1 diff --git a/src/factories/actions.ms b/src/factories/actions.ms index 0c9e00d..dd821db 100644 --- a/src/factories/actions.ms +++ b/src/factories/actions.ms @@ -185,13 +185,24 @@ examine = function(position) action.apply = function(entity, map) entities = map.getEntitiesAt(position) - if entities.len == 0 then tile = map.tiles[position.y][position.x] Service.messages.report("You see a {0} here.".fill([ tile.name ])) - else + return + end if + + foundEntity = false + for e in entities + if e.examineOverride() then + foundEntity = true + break + end if + end for + + if not foundEntity then ui.examine(entities) end if end function + return action end function diff --git a/src/factories/behaviors.ms b/src/factories/behaviors.ms index 912d1b8..02537f0 100644 --- a/src/factories/behaviors.ms +++ b/src/factories/behaviors.ms @@ -56,23 +56,30 @@ makeAttackOnCollision = function() return b end function -makeWander = function() +makeWander = function(changeDirectionChance = 0.5, pauseChance = 0.5) b = makeHealWhileResting() + b.pauseChance = pauseChance + b.changeDirectionChance = changeDirectionChance b.currentDirection = point.zero b.chooseNewDirection = function(entity) - dx = math.random(-1, 1) - dy = 0 - if dx == 0 then - dy = math.random(-1, 1) - end if + if rnd() < pauseChance then + dx = 0 + dy = 0 + else + dx = math.random(-1, 1) + dy = 0 + if dx == 0 then + dy = math.random(-1, 1) + end if - axis = math.random(0, 1) - if axis == 1 then - // Randomly choose which axis gets priority on changing. - a = dx - dx = dy - dy = a + axis = math.random(0, 1) + if axis == 1 then + // Randomly choose which axis gets priority on changing. + a = dx + dx = dy + dy = a + end if end if self.currentDirection.x = dx @@ -80,7 +87,7 @@ makeWander = function() end function b.shouldChooseNewDirection = function() - return rnd() > 0.5 + return rnd() < self.changeDirectionChance end function b.wanderAround = function(entity, map) diff --git a/src/factories/entities.ms b/src/factories/entities.ms index 3023ea6..c7086c5 100644 --- a/src/factories/entities.ms +++ b/src/factories/entities.ms @@ -73,7 +73,7 @@ makeSign = function(map, pnt, msg) end function // Let's start with a villager that is basically a walking signpost. -makeSimpleVillager = function(map, pnt, msg) +makeSimpleVillager = function(map, pnt) if math.random(0, 100) < 50 then name = names.boy t = tile.make(268, Color.blue.lighter, true, false) @@ -84,13 +84,18 @@ makeSimpleVillager = function(map, pnt, msg) e = (new entity.Entity).init(t, races.npc, classes.classless, pnt) e.name = name.str() e.fullName = name - e.description = "{0}: ""{1}""".fill([e.name, msg]) + e.description = "A simple villager leading a simple life." e.canBeAttacked = false e.describe = function(display, bounds) end function - e.behaviors.push(behaviors.makeWander()) + e.examineOverride = function() + ui.showMessage(phrases.getRandom(), e.name) + return true + end function + + e.behaviors.push(behaviors.makeWander(0.1, 0.7)) return e end function diff --git a/src/factories/phrases.ms b/src/factories/phrases.ms new file mode 100644 index 0000000..45dad7c --- /dev/null +++ b/src/factories/phrases.ms @@ -0,0 +1,53 @@ +data = [ + "Welcome to Village!", + "Heard tell of strange things happening by the old quarry...", + "May the light of the Sun God guide your path, traveler.", + "Don't forget to pay the merchant at the market, their prices are sharp as an axe!", + "Quiet you! The mushrooms won't reveal their secrets if you talk so loud.", + "Have you seen my lucky charm? A silver horseshoe, lost near the well.", + "Beware the shadows after dusk, whispers say things stalk the moonlit lanes.", + "Remember, a smile is worth more than gold in these uncertain times.", + "May your pockets be heavy and your burdens light.", + "The bakery's got fresh bread this morning, warm and crusty, just like the baker!", + "Seen a hooded figure skulking around the abandoned mill? Best not stay out late.", + "Tell the old herbalist I need more herbs for my poultices, they know where to find them.", + "Remember, courage isn't the absence of fear, it's taking action despite it.", + "Have you heard the latest gossip? Someone swears they saw a dragon in the clouds!", + "Don't forget to water the moonflowers tonight, they bloom best under the silver light.", + "Keep an eye out for lost souls, the Whispering Woods can be a tricky place.", + "May the winds of fortune blow in your favor today, brave adventurer.", + "Heard a booming sound from the north last night, like a giant hammering the earth.", + "If you need a weapon sharpened, the young blacksmith has a steady hand.", + "Have you seen my pet owl? He flew off after a plump field mouse this morning.", + "Keep your wits sharp and your blade sharper, you never know what lurks around the bend.", + "Don't forget to make an offering to the River Spirit, a pebble is enough, but respect is key.", + "Don't believe everything you hear in the tavern, some folks like to embellish their tales.", + "Be wary of strangers, not everyone who smiles has good intentions.", + "Have you tried the stews at the tavern? Hearty and flavorful, they'll warm you from the inside out.", + "Remember, kindness is a weapon too, sometimes the gentlest words can break the strongest chains.", + "Seen a flash of blue light streaking across the night sky? Shooting star, or something more?", + "If you're looking for work, the old farmer might need help clearing their fields before winter.", + "Don't judge a book by its cover, some of the wisest folks here live in the humblest cottages.", + "Keep your eyes peeled for hidden treasures, the village is older than anyone remembers.", + "May the stars guide your path and the sun warm your face.", + "Don't forget to thank the bees for their honeyed gift, a little respect goes a long way.", + "Heard a mournful howl from the hills last night, hope it wasn't a lone wolf on the prowl.", + "Remember, every step is a journey, savor the small moments along the way.", + "Have you seen the giant oak at the edge of the forest? Some say it whispers secrets in the wind.", + "May your adventures be grand and your stories be worth telling by the fireside.", + "Don't underestimate the power of a helping hand, kindness can change the world, one deed at a time.", + "Seen a flash of green eyes in the bushes? Could be a fox, or something far more cunning...", + "Remember, even the smallest light can pierce the darkest night.", + "May the forest spirits watch over you as you venture into the unknown.", + "Don't forget to water the village well, fresh water is a precious gift.", + "Heard a rhythmic drumming from the south, wonder what those strange folks are up to now...", + "Remember, laughter is the best medicine, even in the toughest times.", + "Keep your chin up, brave adventurer, even the darkest clouds eventually pass.", + "May the warmth of the hearth fire fill your heart and guide you on your way.", + "Don't judge a creature by its scales or feathers, some of the kindest souls have the fiercest forms.", + "Remember, silence can be just as powerful as words, sometimes listening is the greatest gift.", +] + +getRandom = function() + return math.randomChoice(data) +end function diff --git a/src/townGenerator.ms b/src/townGenerator.ms index 9f05670..dd48ad9 100644 --- a/src/townGenerator.ms +++ b/src/townGenerator.ms @@ -323,7 +323,7 @@ generateCavernLevel = function(mapgen, map) for n in range(10) pnt = findSpawnPointInRadius(map, map.stairsDown, 20) - e = entities.makeSimpleVillager(map, pnt, "Welcome to Village!") + e = entities.makeSimpleVillager(map, pnt) map.entities.push(e) end for diff --git a/src/ui.ms b/src/ui.ms index 4ad9a11..a93b25a 100644 --- a/src/ui.ms +++ b/src/ui.ms @@ -119,6 +119,7 @@ InventorySelectListItem = require("InventorySelectListItem") InventorySelectWindow = require("InventorySelectWindow") ExamineSelectListItem = require("ExamineSelectListItem") ExamineWindow = require("ExamineWindow") +MessageWindow = require("MessageWindow") HeadsUpDisplay = require("HeadsUpDisplay") selectItem = function(entity, title) @@ -128,3 +129,7 @@ end function examine = function(entities) return (new ui.ExamineWindow).examine(entities) end function + +showMessage = function(message, title="Message") + ui.MessageWindow.make(message, title).show() +end function diff --git a/src/ui/MessageWindow.ms b/src/ui/MessageWindow.ms new file mode 100644 index 0000000..2faa528 --- /dev/null +++ b/src/ui/MessageWindow.ms @@ -0,0 +1,36 @@ +MessageWindow = {} + +MessageWindow.make = function(message, title) + wnd = (new MessageWindow) + wnd.bounds = rect.make(4, 4, constants.UI_DISPLAY_WIDTH - 4 * 2, constants.UI_DISPLAY_HEIGHT - 4 * 2) + wnd.title = title + wnd.message = message + return wnd +end function + +MessageWindow.draw = function() + ui.drawWindow(Display.hud, self.bounds, self.title) + lineCount = ui.drawText(Display.hud, self.message, self.messageBounds) +end function + +// Returns the index of the selected item. +MessageWindow.show = function() + self.draw + + result = null + while true + delta = 0 + k = key.get.code + if keybindings.exit.contains(k) then + break + else if keybindings.select.contains(k) then + break + end if + end while +end function + +MessageWindow.messageBounds = function() + return rect.make(self.bounds.left + 2, self.bounds.top + 2, self.bounds.width - 4, self.bounds.height - 4) +end function + +return MessageWindow