Copyright | Brent Yorgey |
---|---|
License | BSD-3-Clause |
Maintainer | byorgey@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A recipe represents some kind of process for transforming some input entities into some output entities.
Synopsis
- type IngredientList e = [(Count, e)]
- data Recipe e = Recipe {}
- recipeInputs :: Lens' (Recipe e) (IngredientList e)
- recipeOutputs :: Lens' (Recipe e) (IngredientList e)
- recipeRequirements :: Lens' (Recipe e) (IngredientList e)
- recipeTime :: Lens' (Recipe e) Integer
- recipeWeight :: Lens' (Recipe e) Integer
- loadRecipes :: Has (Lift IO) sig m => EntityMap -> m (Either Text [Recipe Entity])
- outRecipeMap :: [Recipe Entity] -> IntMap [Recipe Entity]
- inRecipeMap :: [Recipe Entity] -> IntMap [Recipe Entity]
- reqRecipeMap :: [Recipe Entity] -> IntMap [Recipe Entity]
- data MissingIngredient = MissingIngredient MissingType Count Entity
- data MissingType
- knowsIngredientsFor :: (Inventory, Inventory) -> Recipe Entity -> Bool
- recipesFor :: IntMap [Recipe Entity] -> Entity -> [Recipe Entity]
- make :: (Inventory, Inventory) -> Recipe Entity -> Either [MissingIngredient] (Inventory, IngredientList Entity, Recipe Entity)
- make' :: (Inventory, Inventory) -> Recipe Entity -> Either [MissingIngredient] (Inventory, IngredientList Entity)
Ingredient lists and recipes
type IngredientList e = [(Count, e)] Source #
An ingredient list is a list of entities with multiplicity. It is polymorphic in the entity type so that we can use either entity names when serializing, or actual entity objects while the game is running.
A recipe is just a list of input entities and a list of output entities (both with multiplicity). The idea is that it represents some kind of process where the inputs are transformed into the outputs.
Instances
recipeInputs :: Lens' (Recipe e) (IngredientList e) Source #
The inputs to a recipe.
recipeOutputs :: Lens' (Recipe e) (IngredientList e) Source #
The outputs from a recipe.
recipeRequirements :: Lens' (Recipe e) (IngredientList e) Source #
Other entities which the recipe requires you to have, but which are not consumed by the recipe (e.g. a furnace).
recipeWeight :: Lens' (Recipe e) Integer Source #
How this recipe is weighted against other recipes. Any time there are multiple valid recipes that fit certain criteria, one of the recipes will be randomly chosen with probability proportional to its weight.
Loading recipes
loadRecipes :: Has (Lift IO) sig m => EntityMap -> m (Either Text [Recipe Entity]) Source #
Given an already loaded EntityMap
, try to load a list of
recipes from the data file recipes.yaml
.
outRecipeMap :: [Recipe Entity] -> IntMap [Recipe Entity] Source #
Build a map of recipes indexed by output ingredients.
inRecipeMap :: [Recipe Entity] -> IntMap [Recipe Entity] Source #
Build a map of recipes indexed by input ingredients.
reqRecipeMap :: [Recipe Entity] -> IntMap [Recipe Entity] Source #
Build a map of recipes indexed by requirements.
Looking up recipes
data MissingIngredient Source #
Instances
Show MissingIngredient Source # | |
Defined in Swarm.Game.Recipe showsPrec :: Int -> MissingIngredient -> ShowS # show :: MissingIngredient -> String # showList :: [MissingIngredient] -> ShowS # | |
Eq MissingIngredient Source # | |
Defined in Swarm.Game.Recipe (==) :: MissingIngredient -> MissingIngredient -> Bool # (/=) :: MissingIngredient -> MissingIngredient -> Bool # |
data MissingType Source #
Instances
Show MissingType Source # | |
Defined in Swarm.Game.Recipe showsPrec :: Int -> MissingType -> ShowS # show :: MissingType -> String # showList :: [MissingType] -> ShowS # | |
Eq MissingType Source # | |
Defined in Swarm.Game.Recipe (==) :: MissingType -> MissingType -> Bool # (/=) :: MissingType -> MissingType -> Bool # |
knowsIngredientsFor :: (Inventory, Inventory) -> Recipe Entity -> Bool Source #
Figure out if a recipe is available, but it can be lacking items.
recipesFor :: IntMap [Recipe Entity] -> Entity -> [Recipe Entity] Source #
Get a list of all the recipes for the given entity. Look up an
entity in either an inRecipeMap
or outRecipeMap
depending on
whether you want to know recipes that consume or produce the
given entity, respectively.
make :: (Inventory, Inventory) -> Recipe Entity -> Either [MissingIngredient] (Inventory, IngredientList Entity, Recipe Entity) Source #
Try to make a recipe, deleting the recipe's inputs from the inventory. Return either a description of which items are lacking, if the inventory does not contain sufficient inputs, or an inventory without inputs and function adding outputs if it was successful.