License | BSD-3-Clause |
---|---|
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A recipe represents some kind of process for transforming some input entities into some output entities.
Recipes support a number of different game mechanics, including:
- crafting
- mining
- randomized "loot boxes"
- unlocking doors
Synchronous vs Async
Recipes can be completed either within the same tick as execution is started, or execution may span multiple ticks. It is possible for the execution of multi-tick recipes to be interrupted in one way or another, in which case the recipe fails without producing the "outputs".
Synopsis
- type IngredientList e = [(Count, e)]
- data Recipe e = Recipe {}
- recipeInputs :: Lens' (Recipe e) (IngredientList e)
- recipeOutputs :: Lens' (Recipe e) (IngredientList e)
- recipeCatalysts :: Lens' (Recipe e) (IngredientList e)
- recipeTime :: Lens' (Recipe e) Integer
- recipeWeight :: Lens' (Recipe e) Integer
- loadRecipes :: (Has (Throw SystemFailure) sig m, Has (Lift IO) sig m) => EntityMap -> m [Recipe Entity]
- outRecipeMap :: [Recipe Entity] -> IntMap [Recipe Entity]
- inRecipeMap :: [Recipe Entity] -> IntMap [Recipe Entity]
- catRecipeMap :: [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 represents some kind of process where inputs are transformed into outputs.
Instances
Fields
recipeInputs :: Lens' (Recipe e) (IngredientList e) Source #
The inputs to a recipe.
recipeOutputs :: Lens' (Recipe e) (IngredientList e) Source #
The outputs from a recipe.
recipeCatalysts :: 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 (Throw SystemFailure) sig m, Has (Lift IO) sig m) => EntityMap -> m [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.
catRecipeMap :: [Recipe Entity] -> IntMap [Recipe Entity] Source #
Build a map of recipes indexed by catalysts.
Looking up recipes
data MissingIngredient Source #
Record information about something missing from a recipe.
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 #
What kind of thing is missing?
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, i.e. if we at least know about all the ingredients. Note it does not matter whether we have enough of the ingredients.
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.
:: (Inventory, Inventory) | The robot's inventory and equipped devices |
-> Recipe Entity | The recipe we are trying to make |
-> Either [MissingIngredient] (Inventory, IngredientList Entity, Recipe Entity) |
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.