swarm-0.5.0.0: 2D resource gathering game with programmable robots
LicenseBSD-3-Clause
Safe HaskellSafe-Inferred
LanguageHaskell2010

Swarm.Game.Step.Util

Description

 
Synopsis

Documentation

type HasRobotStepState sig m = (Has (State GameState) sig m, Has (State Robot) sig m, Has (Throw Exn) sig m) Source #

All functions that are used for robot step can access GameState and the current Robot.

They can also throw exception of our custom type, which is handled elsewhere. Because of that the constraint is only Throw, but not Catch/Error.

updateEntityAt :: Has (State GameState) sig m => Cosmic Location -> (Maybe Entity -> Maybe Entity) -> m () Source #

Modify the entity (if any) at a given location.

Capabilities

isPrivilegedBot :: (Has (State GameState) sig m, Has (State Robot) sig m) => m Bool Source #

Exempts the robot from various command constraints when it is either a system robot or playing in creative mode

hasCapability :: (Has (State Robot) sig m, Has (State GameState) sig m) => Capability -> m Bool Source #

Test whether the current robot has a given capability (either because it has a device which gives it that capability, or it is a system robot, or we are in creative mode).

hasCapabilityFor :: (Has (State Robot) sig m, Has (State GameState) sig m, Has (Throw Exn) sig m) => Capability -> Term -> m () Source #

Ensure that either a robot has a given capability, OR we are in creative mode.

Exceptions

holdsOrFail' :: Has (Throw Exn) sig m => Const -> Bool -> [Text] -> m () Source #

isJustOrFail' :: Has (Throw Exn) sig m => Const -> Maybe a -> [Text] -> m a Source #

cmdExn :: Const -> [Text] -> Exn Source #

Create an exception about a command failing.

Some utility functions

getNow :: Has (Lift IO) sig m => m TimeSpec Source #

flagRedraw :: Has (State GameState) sig m => m () Source #

Set a flag telling the UI that the world needs to be redrawn.

World queries

zoomWorld :: Has (State GameState) sig m => SubworldName -> StateC (World Int Entity) Identity b -> m (Maybe b) Source #

Perform an action requiring a World state component in a larger context with a GameState.

entityAt :: Has (State GameState) sig m => Cosmic Location -> m (Maybe Entity) Source #

Get the entity (if any) at a given location.

robotWithID :: Has (State GameState) sig m => RID -> m (Maybe Robot) Source #

Get the robot with a given ID.

robotWithName :: Has (State GameState) sig m => Text -> m (Maybe Robot) Source #

Get the robot with a given name.

Randomness

uniform :: (Has (State GameState) sig m, UniformRange a) => (a, a) -> m a Source #

Generate a uniformly random number using the random generator in the game state.

weightedChoice :: Has (State GameState) sig m => (a -> Integer) -> [a] -> m (Maybe a) Source #

Given a weighting function and a list of values, choose one of the values randomly (using the random generator in the game state), with the probability of each being proportional to its weight. Return Nothing if the list is empty.

randomName :: Has (State GameState) sig m => m Text Source #

Generate a random robot name in the form adjective_name.

Moving

checkMoveFailureUnprivileged :: HasRobotStepState sig m => Cosmic Location -> m (Maybe MoveFailureDetails) Source #

Make sure nothing is in the way. No exception for system robots

checkMoveFailure :: HasRobotStepState sig m => Cosmic Location -> m (Maybe MoveFailureDetails) Source #

Make sure nothing is in the way. Note that system robots implicitly ignore and base throws on failure.