License | BSD-3-Clause |
---|---|
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Swarm.Game.Scenario
Description
Scenarios are standalone worlds with specific starting and winning conditions, which can be used both for building interactive tutorials and for standalone puzzles and scenarios.
Synopsis
- data PCell e = Cell {
- cellTerrain :: TerrainType
- cellEntity :: Erasable e
- cellRobots :: [IndexedTRobot]
- type Cell = PCell Entity
- data PWorldDescription e = WorldDescription {
- offsetOrigin :: Bool
- scrollable :: Bool
- palette :: WorldPalette e
- ul :: Location
- area :: PositionedGrid (Maybe (PCell e))
- navigation :: Navigation Identity WaypointName
- placedStructures :: [LocatedStructure]
- worldName :: SubworldName
- worldProg :: Maybe (TTerm '[] (World CellVal))
- type WorldDescription = PWorldDescription Entity
- type IndexedTRobot = (Int, TRobot)
- type StructureCells = NamedGrid (Maybe Cell)
- data Scenario = Scenario {
- _scenarioMetadata :: ScenarioMetadata
- _scenarioOperation :: ScenarioOperation
- _scenarioLandscape :: ScenarioLandscape
- data ScenarioLandscape = ScenarioLandscape {
- _scenarioSeed :: Maybe Int
- _scenarioAttrs :: [CustomAttr]
- _scenarioTerrainAndEntities :: TerrainEntityMaps
- _scenarioCosmetics :: Map WorldAttr PreservableColor
- _scenarioKnown :: Set EntityName
- _scenarioWorlds :: NonEmpty WorldDescription
- _scenarioNavigation :: Navigation (Map SubworldName) Location
- _scenarioStructures :: StaticStructureInfo
- _scenarioRobots :: [TRobot]
- data StaticStructureInfo = StaticStructureInfo {
- _structureDefs :: [SymmetryAnnotatedGrid StructureCells]
- _staticPlacements :: Map SubworldName [LocatedStructure]
- data ScenarioMetadata = ScenarioMetadata Int Text (Maybe Text)
- staticPlacements :: Lens' StaticStructureInfo (Map SubworldName [LocatedStructure])
- structureDefs :: Lens' StaticStructureInfo [SymmetryAnnotatedGrid StructureCells]
- scenarioMetadata :: Lens' Scenario ScenarioMetadata
- scenarioOperation :: Lens' Scenario ScenarioOperation
- scenarioLandscape :: Lens' Scenario ScenarioLandscape
- scenarioVersion :: Lens' ScenarioMetadata Int
- scenarioName :: Lens' ScenarioMetadata Text
- scenarioAuthor :: Lens' ScenarioMetadata (Maybe Text)
- scenarioDescription :: Lens' ScenarioOperation (Document Syntax)
- scenarioCreative :: Lens' ScenarioOperation Bool
- scenarioSeed :: Lens' ScenarioLandscape (Maybe Int)
- scenarioAttrs :: Lens' ScenarioLandscape [CustomAttr]
- scenarioTerrainAndEntities :: Lens' ScenarioLandscape TerrainEntityMaps
- scenarioCosmetics :: Lens' ScenarioLandscape (Map WorldAttr PreservableColor)
- scenarioRecipes :: Lens' ScenarioOperation [Recipe Entity]
- scenarioKnown :: Lens' ScenarioLandscape (Set EntityName)
- scenarioWorlds :: Lens' ScenarioLandscape (NonEmpty WorldDescription)
- scenarioNavigation :: Lens' ScenarioLandscape (Navigation (Map SubworldName) Location)
- scenarioStructures :: Lens' ScenarioLandscape StaticStructureInfo
- scenarioRobots :: Lens' ScenarioLandscape [TRobot]
- scenarioObjectives :: Lens' ScenarioOperation [Objective]
- scenarioSolution :: Lens' ScenarioOperation (Maybe TSyntax)
- scenarioStepsPerTick :: Lens' ScenarioOperation (Maybe Int)
- loadScenario :: (Has (Throw SystemFailure) sig m, Has (Lift IO) sig m) => FilePath -> ScenarioInputs -> m (Scenario, FilePath)
- loadScenarioFile :: (Has (Throw SystemFailure) sig m, Has (Lift IO) sig m) => ScenarioInputs -> FilePath -> m Scenario
- getScenarioPath :: Has (Lift IO) sig m => FilePath -> m (Maybe FilePath)
- loadStandaloneScenario :: (Has (Throw SystemFailure) sig m, Has (Lift IO) sig m) => FilePath -> m (Scenario, GameStateInputs)
- data GameStateInputs = GameStateInputs {}
- data ScenarioInputs = ScenarioInputs {}
- arbitrateSeed :: Maybe Seed -> ScenarioLandscape -> IO Seed
WorldDescription
A single cell in a world map, which contains a terrain value,
and optionally an entity and robot.
It is parameterized on the Entity
type to facilitate less
stateful versions of the Entity
type in rendering scenario data.
Constructors
Cell | |
Fields
|
Instances
ToJSON Cell Source # | |
ToJSON CellPaintDisplay Source # | |
Defined in Swarm.Game.Scenario.Topography.Cell Methods toJSON :: CellPaintDisplay -> Value # toEncoding :: CellPaintDisplay -> Encoding # toJSONList :: [CellPaintDisplay] -> Value # toEncodingList :: [CellPaintDisplay] -> Encoding # omitField :: CellPaintDisplay -> Bool # | |
Show e => Show (PCell e) Source # | |
Eq e => Eq (PCell e) Source # | |
FromJSONE (TerrainEntityMaps, RobotMap) Cell Source # | Parse a tuple such as |
Defined in Swarm.Game.Scenario.Topography.Cell Methods parseJSONE :: Value -> ParserE (TerrainEntityMaps, RobotMap) Cell parseJSONE' :: (TerrainEntityMaps, RobotMap) -> Value -> Parser Cell |
type Cell = PCell Entity Source #
A single cell in a world map, which contains a terrain value, and optionally an entity and robot.
data PWorldDescription e Source #
A description of a world parsed from a YAML file. This type is parameterized to accommodate Cells that utilize a less stateful Entity type.
Constructors
WorldDescription | |
Fields
|
Instances
ToJSON WorldDescriptionPaint Source # | |
Defined in Swarm.Game.Scenario.Topography.WorldDescription Methods toJSON :: WorldDescriptionPaint -> Value # toEncoding :: WorldDescriptionPaint -> Encoding # toJSONList :: [WorldDescriptionPaint] -> Value # toEncodingList :: [WorldDescriptionPaint] -> Encoding # omitField :: WorldDescriptionPaint -> Bool # | |
FromJSONE WorldParseDependencies WorldDescription Source # | |
Defined in Swarm.Game.Scenario.Topography.WorldDescription Methods parseJSONE :: Value -> ParserE WorldParseDependencies WorldDescription parseJSONE' :: WorldParseDependencies -> Value -> Parser WorldDescription | |
Show e => Show (PWorldDescription e) Source # | |
Defined in Swarm.Game.Scenario.Topography.WorldDescription Methods showsPrec :: Int -> PWorldDescription e -> ShowS # show :: PWorldDescription e -> String # showList :: [PWorldDescription e] -> ShowS # |
type IndexedTRobot = (Int, TRobot) Source #
A robot template paired with its definition's index within the Scenario file
type StructureCells = NamedGrid (Maybe Cell) Source #
Scenario
A Scenario
contains all the information to describe a
scenario.
Constructors
Scenario | |
Fields
|
Instances
Show Scenario Source # | |
FromJSONE ScenarioInputs Scenario Source # | |
Defined in Swarm.Game.Scenario Methods parseJSONE :: Value -> ParserE ScenarioInputs Scenario parseJSONE' :: ScenarioInputs -> Value -> Parser Scenario |
data ScenarioLandscape Source #
All cosmetic and structural content of the scenario.
Constructors
ScenarioLandscape | |
Fields
|
Instances
Show ScenarioLandscape Source # | |
Defined in Swarm.Game.Scenario Methods showsPrec :: Int -> ScenarioLandscape -> ShowS # show :: ScenarioLandscape -> String # showList :: [ScenarioLandscape] -> ShowS # |
data StaticStructureInfo Source #
Constructors
StaticStructureInfo | |
Fields
|
Instances
Show StaticStructureInfo Source # | |
Defined in Swarm.Game.Scenario Methods showsPrec :: Int -> StaticStructureInfo -> ShowS # show :: StaticStructureInfo -> String # showList :: [StaticStructureInfo] -> ShowS # |
data ScenarioMetadata Source #
Authorship information about scenario not used at play-time
Constructors
ScenarioMetadata Int Text (Maybe Text) |
Instances
staticPlacements :: Lens' StaticStructureInfo (Map SubworldName [LocatedStructure]) Source #
A record of the static placements of structures, so that they can be added to the "recognized" list upon scenario initialization
structureDefs :: Lens' StaticStructureInfo [SymmetryAnnotatedGrid StructureCells] Source #
Structure templates that may be auto-recognized when constructed by a robot
Fields
scenarioMetadata :: Lens' Scenario ScenarioMetadata Source #
Authorship information about scenario not used at play-time
scenarioOperation :: Lens' Scenario ScenarioOperation Source #
Non-structural gameplay content of the scenario; how it is to be played.
scenarioLandscape :: Lens' Scenario ScenarioLandscape Source #
All cosmetic and structural content of the scenario.
scenarioVersion :: Lens' ScenarioMetadata Int Source #
The version number of the scenario schema. Currently, this should always be 1, but it is ignored. In the future, this may be used to convert older formats to newer ones, or simply to print a nice error message when we can't read an older format.
scenarioName :: Lens' ScenarioMetadata Text Source #
The name of the scenario.
scenarioAuthor :: Lens' ScenarioMetadata (Maybe Text) Source #
The author of the scenario.
scenarioDescription :: Lens' ScenarioOperation (Document Syntax) Source #
A high-level description of the scenario, shown e.g. in the menu.
scenarioCreative :: Lens' ScenarioOperation Bool Source #
Whether the scenario should start in creative mode.
scenarioSeed :: Lens' ScenarioLandscape (Maybe Int) Source #
The seed used for the random number generator. If Nothing
, use
a random seed / prompt the user for the seed.
scenarioAttrs :: Lens' ScenarioLandscape [CustomAttr] Source #
Custom attributes defined in the scenario.
scenarioTerrainAndEntities :: Lens' ScenarioLandscape TerrainEntityMaps Source #
Any custom terrain and entities used for this scenario, combined with the default system terrain and entities.
scenarioCosmetics :: Lens' ScenarioLandscape (Map WorldAttr PreservableColor) Source #
High-fidelity color map for entities
scenarioRecipes :: Lens' ScenarioOperation [Recipe Entity] Source #
Any custom recipes used in this scenario.
scenarioKnown :: Lens' ScenarioLandscape (Set EntityName) Source #
List of entities that should be considered "known", so robots do not have to scan them.
scenarioWorlds :: Lens' ScenarioLandscape (NonEmpty WorldDescription) Source #
The subworlds of the scenario. The "root" subworld shall always be at the head of the list, by construction.
scenarioNavigation :: Lens' ScenarioLandscape (Navigation (Map SubworldName) Location) Source #
Waypoints and inter-world portals
scenarioStructures :: Lens' ScenarioLandscape StaticStructureInfo Source #
Information required for structure recognition
scenarioRobots :: Lens' ScenarioLandscape [TRobot] Source #
The starting robots for the scenario. Note this should include the base.
scenarioObjectives :: Lens' ScenarioOperation [Objective] Source #
A sequence of objectives for the scenario (if any).
scenarioSolution :: Lens' ScenarioOperation (Maybe TSyntax) Source #
An optional solution of the scenario, expressed as a
program of type cmd a
. This is useful for automated
testing of the win condition.
scenarioStepsPerTick :: Lens' ScenarioOperation (Maybe Int) Source #
Optionally, specify the maximum number of steps each robot may take during a single tick.
Loading from disk
loadScenario :: (Has (Throw SystemFailure) sig m, Has (Lift IO) sig m) => FilePath -> ScenarioInputs -> m (Scenario, FilePath) Source #
Load a scenario with a given name from disk, given an entity map to use. This function is used if a specific scenario is requested on the command line.
loadScenarioFile :: (Has (Throw SystemFailure) sig m, Has (Lift IO) sig m) => ScenarioInputs -> FilePath -> m Scenario Source #
Load a scenario from a file.
loadStandaloneScenario :: (Has (Throw SystemFailure) sig m, Has (Lift IO) sig m) => FilePath -> m (Scenario, GameStateInputs) Source #
data GameStateInputs Source #
Constructors
GameStateInputs | |
Fields
|
data ScenarioInputs Source #
Constructors
ScenarioInputs | |
Fields
|
Instances
FromJSONE ScenarioInputs Scenario Source # | |
Defined in Swarm.Game.Scenario Methods parseJSONE :: Value -> ParserE ScenarioInputs Scenario parseJSONE' :: ScenarioInputs -> Value -> Parser Scenario |
Utilities
arbitrateSeed :: Maybe Seed -> ScenarioLandscape -> IO Seed Source #
Decide on a seed. In order of preference, we will use: 1. seed value provided by the user 2. seed value specified in the scenario description 3. randomly chosen seed value