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

Swarm.Game.Step.Util.Command

Description

Helper functions for Swarm.Game.Step.Const commands

Synopsis

Documentation

data GrabbingCmd Source #

Constructors

Grab' 
Harvest' 
Swap' 
Push' 

Instances

Instances details
Show GrabbingCmd Source # 
Instance details

Defined in Swarm.Game.Step.Util.Command

Eq GrabbingCmd Source # 
Instance details

Defined in Swarm.Game.Step.Util.Command

ensureCanExecute :: (Has (State Robot) sig m, Has (State GameState) sig m, Has (Throw Exn) sig m) => Const -> m () Source #

Ensure that a robot is capable of executing a certain constant (either because it has a device which gives it that capability, or it is a system robot, or we are in creative mode).

For certain capabilities that require payment of inventory items in order to be exercised, we pay the toll up front, regardless of other conditions that may preclude the capability from eventually being exercised (e.g. an obstacle that ultimately prevents a "move").

Note that there exist some code paths where the "toll" is bypassed, e.g. see hasCapabilityFor. We should just try to avoid authoring scenarios that include toll-gated devices for those particular capabilities.

Since this function has the side-effect of removing items from the robot's inventory, we must be careful that it is executed exactly once per command.

payExerciseCost :: (Has (State Robot) sig m, Has (State GameState) sig m, Has (Throw Exn) sig m) => Const -> NonEmpty (DeviceUseCost Entity EntityName) -> m () Source #

purgeFarAwayWatches :: HasRobotStepState sig m => m () Source #

Clear watches that are out of range

updateRobotLocation :: HasRobotStepState sig m => Cosmic Location -> Cosmic Location -> m () Source #

Update the location of a robot, and simultaneously update the robotsByLocation map, so we can always look up robots by location. This should be the only way to update the location of a robot. Also implements teleportation by portals.

onTarget :: (HasRobotStepState sig m, Has (Lift IO) sig m) => RID -> (forall sig' m'. (HasRobotStepState sig' m', Has (Lift IO) sig' m') => m' ()) -> m () Source #

Execute a stateful action on a target robot --- whether the current one or another.

grantAchievementForRobot :: (HasRobotStepState sig m, Has (Lift IO) sig m) => GameplayAchievement -> m () Source #

Enforces validity of the robot's privileged status to receive an achievement.

grantAchievement :: (Has (State GameState) sig m, Has (Lift IO) sig m) => GameplayAchievement -> m () Source #

NOTE: When possible, one should use the grantAchievementForRobot function instead of this one.

constCapsFor :: Const -> Robot -> Maybe Capability Source #

Capabilities needed for a specific robot to evaluate or execute a constant. Right now, the only difference is whether the robot is heavy or not when executing the Move command, but there might be other exceptions added in the future.

isNearbyOrExempt :: Bool -> Cosmic Location -> Cosmic Location -> Bool Source #

Requires that the target location is within one cell. Requirement is waived if the bot is privileged.

updateDiscoveredEntities :: HasRobotStepState sig m => Entity -> m () Source #

Update the global list of discovered entities, and check for new recipes.

updateAvailableRecipes :: Has (State GameState) sig m => (Inventory, Inventory) -> Entity -> m () Source #

Update the availableRecipes list. This implementation is not efficient: * Every time we discover a new entity, we iterate through the entire list of recipes to see which ones we can make. Trying to do something more clever seems like it would definitely be a case of premature optimization. One doesn't discover new entities all that often. * For each usable recipe, we do a linear search through the list of known recipes to see if we already know it. This is a little more troubling, since it's quadratic in the number of recipes. But it probably doesn't really make that much difference until we get up to thousands of recipes.

addWatchedLocation :: HasRobotStepState sig m => Cosmic Location -> m () Source #

provisionChild :: HasRobotStepState sig m => RID -> Inventory -> Inventory -> m () Source #

Give some entities from a parent robot (the robot represented by the ambient State Robot effect) to a child robot (represented by the given RID) as part of a Build or Reprogram command. The first Inventory is devices to be equipped, and the second is entities to be transferred.

In classic mode, the entities will be transferred (that is, removed from the parent robot's inventory); in creative mode, the entities will be copied/created, that is, no entities will be removed from the parent robot.

cmdExnWithAchievement :: Const -> [Text] -> GameplayAchievement -> Exn Source #

Create an exception about a command failing, with an achievement

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

Raise an exception about a command failing with a formatted error message.

withExceptions :: Monad m => Store -> Cont -> ThrowC Exn m CESK -> m CESK Source #

Run a subcomputation that might throw an exception in a context where we are returning a CESK machine; any exception will be turned into an Up state.

traceLog :: (Has (State GameState) sig m, Has (State Robot) sig m) => RobotLogSource -> Severity -> Text -> m LogEntry Source #

Print some text via the robot's log.

formatDevices :: Set Entity -> Text Source #

Format a set of suggested devices for use in an error message, in the format device1 or device2 or ... or deviceN.

createLogEntry :: (Has (State GameState) sig m, Has (State Robot) sig m) => RobotLogSource -> Severity -> Text -> m LogEntry Source #

Create a log entry given current robot and game time in ticks noting whether it has been said.

This is the more generic version used both for (recorded) said messages and normal logs.

updateWorld :: HasRobotStepState sig m => Const -> WorldUpdate Entity -> m () Source #

replace some entity in the world with another entity

applyRobotUpdates :: (Has (State GameState) sig m, Has (State Robot) sig m) => [RobotUpdate] -> m () Source #

addSeedBot :: Has (State GameState) sig m => Entity -> (Integer, Integer) -> Integer -> Integer -> Cosmic Location -> TimeSpec -> m () Source #

Construct a "seed robot" from entity, time range and position, and add it to the world. It has low priority and will be covered by placed entities.

seedProgram Source #

Arguments

:: Integer

min time

-> Integer

rand time

-> Integer

seedling count

-> Integer

seedling radius

-> EntityName

entity to place

-> TSyntax 

A system program for a "seed robot", to regrow a growable entity after it is harvested.

NOTE: Seedling propagation delay (spreadable growth) re-uses the growth timing parameters.