Commit graph

29 commits

Author SHA1 Message Date
Griffin Smith
db6ea02581 Begin a broken-out NestedMap type
Begin breaking out a NestedMap data structure, which existed in both the
variables for the new template system and the structure that stored
messages.
2020-05-25 11:21:19 -04:00
Griffin Smith
2c86856ca7 Add a new template system
Add a parser, pretty-printer, and renderer for a new template system,
which should eventually be a drop-in replacement for the current
mustache-based template system, but also supports text filters (which
will be used for things like pluralization and noun casing). Nothing
currently uses it yet, though.
2020-05-24 11:14:02 -04:00
Griffin Smith
34cabba896 Add a very basic, naive auto-move command
Add a very basic, naive auto-move command, which just steps the player
in a direction until they collide with something, regardless of any
surrounding beasties who might want to eat them.

There's a lot of other stuff going on here - in order to get this
working the way I wanted with a slight (I settled on 50ms) delay between
every step in these autocommands while still redrawing in between I had
to do all the extra machinery for custom Brick events with a channel,
and then at the same time adding the bits for actually executing
autocommands in a general fashion (because there will definitely be
more!) hit my threshold for size for App.hs which sent me on a big
journey to break it up into smaller files -- which seems actually like
it was quite successful. Hopefully this will help with compile times
too, though App.hs is still pretty slow (maybe more to do here).
2020-05-11 23:03:21 -04:00
Griffin Smith
25a1c5ade3 Factor out an EntityAttributes type
Factor out a new EntityAttributes type from some of the methods of the
Entity class, to avoid the proliferation of 1-argument boolean methods
on the entity class that always have to be forwarded through the Entity
instance for SomeEntity if they have defaults (forgetting to do which
has wasted tons of my time up to this point). Currently blocksVision,
blocksObject, and collision are all in there.
2020-02-08 17:24:27 -05:00
Griffin Smith
6b0bab0e85 Add support for multiple levels
Add a data structure, based on the zipper comonad, which provides
support for multiple levels, each of which is its own entity map. The
current level is provided by coreturn, which the `entities` lens has
been updated to use. Nothing currently supports going up or down levels
yet - that's coming next.
2020-01-04 23:48:51 -05:00
Griffin Smith
1b88921bc3 Decouple Gormlak AI from creatures
Decouple the definition of the Gormlak AI from the creature type itself
using generic lenses and a "HasVisionRadius" typeclass, to begin to
untangle the hs-boot web of circular dependencies. This
actually *increases* the number of hs-boot files from 1 to 2, but both
of the source imports that use them are single-instance (unlike gormlak
AI which I would expect to grow linearly with the growth of the game),
plus at least one should be able to go away once we remove collision
from the game lenses module and move it into something defined in the
entity class itself.
2020-01-03 12:41:48 -05:00
Griffin Smith
ffc8e793d5 Prompt before overwriting files when saving
When saving the game to a file that already exists, prompt for whether
or not to overwrite the file.

Since this was the first instance of a prompt triggered by another
prompt, this also had to do a minor fix to swap the order of completing
the prompt and clearing it, so that we don't submit the prompt and then
immediately clear it.
2019-12-31 11:09:18 -05:00
Griffin Smith
e76567b9e7 Add dungeon level generation
Add a dungeon level generator, which:

1. generates an infinite sequence of rectangular rooms within the
   dimensions of the level
2. removes any duplicates from that sequence
3. Generates a graph from the delaunay triangulation of the centerpoints
   of those rooms
4. Generates the minimum-spanning-tree of that delaunay triangulation,
   with weights given by line length in points
5. Adds back a subset (default 10-15%) of edges from the delaunay
   triangulation to the graph
6. Uses the resulting graph to draw corridors between the rooms, using a
   random point on the near edge of each room to pick the points of the
   corridors
2019-12-30 11:31:56 -05:00
Griffin Smith
32421916e0 Update the vision every time we step the game
Recalculate the character's lines of sight every time we step the game,
rather than just every time the character *moves*. I had originally
thought this was a non-contiguous lines-of-sight bug - which there's a
test disproving - but it actually turned out to be that actions like
eating or attacking would step the game forward (thus moving gormlaks)
without re-calculating the positions visible to the character.
2019-12-23 17:55:28 -05:00
Griffin Smith
052bc8455a Add a drop command
Add a drop command, bound to 'd', which prompts the character for an
item in their inventory, removes it from the inventory, and places it on
the ground. Along the way I had to fix a bug in the
`EntityMap.atPosition` lens, which was always appending to the existing
entities at the position on set, without removing the entities that were
already there - the rabbit hole of quickchecking the lens laws here also
lead to replacing the target of this lens with a newtype called
`VectorBag`, which ignores order (since the entitymap makes no
guarantees about order of entities at a given position).
2019-12-23 17:22:56 -05:00
Griffin Smith
97a5c61f28 Fix an injectivity issue with saving the game
Fix an injectivity issue with JSON-encoding the entity map that was
causing the game saving to not properly round-trip. As part of this,
there's a refactor to the internals of the entity map to use sets
instead of vectors, which should also get us a nice perf boost.
2019-11-30 15:00:39 -05:00
Griffin Smith
8a1235c3dc Use menus for combat and picking up items
Refactor a bunch of stuff around to allow for polymorphically surfacing
an EntityChar for all entities, and use this to write a generic
`entityMenu` function, which generates a menu from the chars of a list
of entities - and use that to fully implement (removing `undefined`)
menus for both attacking and picking things up when there are multiple
entities on the relevant tile.
2019-11-29 22:59:15 -05:00
Griffin Smith
f37d0f75c0 Implement saving+loading the game
Implement ToJSON and FromJSON for all of the various pieces of the game
state, and add a pair of functions saveGame/loadGame implementing a
prism to save the game as zlib-compressed JSON. To test this, there's
now Arbitrary, CoArbitrary, and Function instances for all the parts of
the game state - to get around circular imports with the concrete
entities this unfortunately is happening via orphan instances, plus an
hs-boot file to break a circular import that was just a little too hard
to remove by moving things around. Ugh.
2019-11-29 14:33:52 -05:00
Griffin Smith
de8052cef8 Allow eating edible items
Add menu support to the prompt system, and an "Eat" command that prompts
for an item to eat and eats the item the character specifies, restoring
an amount of hitpoints configurable via the item raw type.
2019-10-06 12:50:29 -04:00
Griffin Smith
ec39dc0a5b Tweak gormlak movement slightly
- Don't let gormlaks run into things like walls or each other
- Add a small element of randomness to gormlaks' motion
- Increase gormlaks' vision by a large amount
2019-09-28 15:03:36 -04:00
Griffin Smith
1a0f618a82 Implement the start of creature AI
Add a Brain class, which determines for an entity the set of moves it
makes every step of the game, and begin to implement that for gormlaks.
The idea here is that every step of the game, a gormlak will move
towards the furthest-away wall it can see.
2019-09-28 15:03:36 -04:00
Griffin Smith
dd16166665 Describe what you see when you walk over items
Every step the character takes, describe the entities at that position
excluding the character.
2019-09-20 19:38:46 -04:00
Griffin Smith
7770ed0548 Add the beginnings of a prompt system
Add the beginnings of a generic prompt system, with exclusive support
atm for string prompts, and test it out by asking the character for
their name at startup
2019-09-20 12:03:30 -04:00
Griffin Smith
62a2e05ef2 Add items and inventory
Add a new "Item" entity, which pulls from the previously-existent
ItemType raw, and add a "PickUp" command which takes the (currently
*only*) item off the ground and puts it into the inventory.
2019-09-19 13:56:14 -04:00
Griffin Smith
58fce2ec19 Progressively reveal the map to the player
As the character walks around the map, progressively reveal the entities
on the map to them, using an algorithm based on well known
circle-rasterizing and line-rasterizing algorithms to calculate lines of
sight that are potentially obscured by walls.
2019-09-15 17:30:57 -04:00
Griffin Smith
c06edf3cc6 Place the chacracter in the level at startup time
Randomly select a position in the largest contiguous region of the
generated level in which to place the character at startup time.
2019-09-13 15:24:05 -04:00
Griffin Smith
9ebdc6fbb4 Convert generated levels to walls
Add support for converting generated levels to walls, and merge one into
the entity map at the beginning of the game.

There's nothing here that guarantees the character ends up *inside* the
level though (they almost always don't) so that'll have to be slotted
into the level generation process.
2019-09-09 20:54:33 -04:00
Griffin Smith
f03ad6bbd6 Add cellular-automata cave generator
Add a cellular-automata-based cave level generator, plus an
optparse-applicative-based CLI for invoking level generators in general.
2019-09-07 14:52:37 -04:00
Griffin Smith
73a52e531d Put a test gormlak on the screen
Implement a concrete "Creature" entity, and place one on the screen at
the game startup for testing.

This revealed a bug with drawing when getting the maximum entity
position, but that appears to be fixed now (yay)
2019-09-02 14:45:36 -04:00
Griffin Smith
4d270712ae Add raws, loaded statically from a folder
Add raw types with support for both creatures and items, loaded
statically from a "raws" folder just like in the Rust version.
2019-09-02 13:59:28 -04:00
Griffin Smith
adb3b74c0c Link up messages to the overall game
Add a "say" function for saying messages within an app monad to the
user, and link everything up to display them and track their history
2019-09-02 10:52:01 -04:00
Griffin Smith
2fd3e4c9ad Implement messages
Implement messages almost the same as in the Rust version, only with
YAML instead of TOML this time, and a regular old mustache template
instead of something handrolled. Besides that, pretty much everything
here is the same.
2019-09-01 13:54:27 -04:00
Griffin Smith
4ef19aa35a Add entities, and allow walking around
Add support for entities via a port of the EntityMap type, and implement
command support starting at basic hjkl.
2019-08-31 13:18:51 -04:00
Griffin Smith
d3f3890dc5 An @-sign in a box, in haskell
Initial commit of a Haskell version of Xanthous, written using Brick and
built with Nix.

This is so much nicer and so much easier
2019-08-25 13:28:10 -04:00