Skip to content

Commit

Permalink
Villagers say random stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Tomes committed Dec 21, 2023
1 parent 6158349 commit bffa019
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 19 deletions.
3 changes: 3 additions & 0 deletions main.ms
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ensureImport "shields"
ensureImport "tiles"
ensureImport "weapons"
ensureImport "names"
ensureImport "phrases"

ensureImport "arenaGenerator"
ensureImport "randomDungeonGenerator"
Expand Down Expand Up @@ -260,3 +261,5 @@ main = function()
end function

main()
clear
print "All done!"
5 changes: 5 additions & 0 deletions src/entity.ms
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions src/factories/actions.ms
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 20 additions & 13 deletions src/factories/behaviors.ms
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,38 @@ 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
self.currentDirection.y = dy
end function
b.shouldChooseNewDirection = function()
return rnd() > 0.5
return rnd() < self.changeDirectionChance
end function
b.wanderAround = function(entity, map)
Expand Down
11 changes: 8 additions & 3 deletions src/factories/entities.ms
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
53 changes: 53 additions & 0 deletions src/factories/phrases.ms
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/townGenerator.ms
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/ui.ms
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
36 changes: 36 additions & 0 deletions src/ui/MessageWindow.ms
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bffa019

Please sign in to comment.