License | BSD-3-Clause |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Swarm.Game.State.Robot
Description
Robot-specific subrecords and utilities used by GameState
Synopsis
- data ViewCenterRule
- = VCLocation (Cosmic Location)
- | VCRobot RID
- data Robots
- data RobotNaming
- nameGenerator :: Getter RobotNaming NameGenerator
- gensym :: Lens' RobotNaming Int
- robotNaming :: Lens' Robots RobotNaming
- initRobots :: GameStateConfig -> Robots
- setRobotInfo :: RID -> [Robot] -> Robots -> Robots
- robotMap :: Lens' Robots (IntMap Robot)
- robotsByLocation :: Lens' Robots (MonoidMap SubworldName (MonoidMap Location IntSet))
- robotsWatching :: Lens' Robots (MonoidMap (Cosmic Location) IntSet)
- activeRobots :: Getter Robots IntSet
- waitingRobots :: Getter Robots (MonoidMap TickNumber [RID])
- currentTickWakeableBots :: Lens' Robots [RID]
- viewCenterRule :: Lens' Robots ViewCenterRule
- viewCenter :: Getter Robots (Cosmic Location)
- focusedRobotID :: Getter Robots RID
- wakeWatchingRobots :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => RID -> TickNumber -> Cosmic Location -> m ()
- sleepUntil :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => RID -> TickNumber -> m ()
- sleepForever :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => RID -> m ()
- wakeUpRobotsDoneSleeping :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => TickNumber -> m ()
- deleteRobot :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => RID -> m ()
- removeRobotFromLocationMap :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => Cosmic Location -> RID -> m ()
- activateRobot :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => RID -> m ()
- addRobot :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => Robot -> m ()
- addRobotToLocation :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => RID -> Cosmic Location -> m ()
- addTRobot :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => CESK -> TRobot -> m ()
- addTRobot' :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => CESK -> TRobot -> m Robot
- modifyViewCenter :: (Cosmic Location -> Cosmic Location) -> Robots -> Robots
- unfocus :: Robots -> Robots
- recalcViewCenter :: Robots -> Robots
Types
data ViewCenterRule Source #
The ViewCenterRule
specifies how to determine the center of the
world viewport.
Constructors
VCLocation (Cosmic Location) | The view should be centered on an absolute position. |
VCRobot RID | The view should be centered on a certain robot. |
Instances
Robot naming
data RobotNaming Source #
nameGenerator :: Getter RobotNaming NameGenerator Source #
robotNaming :: Lens' Robots RobotNaming Source #
State and data for assigning identifiers to robots
Initialization
initRobots :: GameStateConfig -> Robots Source #
Accessors
robotMap :: Lens' Robots (IntMap Robot) Source #
All the robots that currently exist in the game, indexed by ID.
robotsByLocation :: Lens' Robots (MonoidMap SubworldName (MonoidMap Location IntSet)) Source #
The names of all robots that currently exist in the game, indexed by
location (which we need both for e.g. the salvage
command as
well as for actually drawing the world). Unfortunately there is
no good way to automatically keep this up to date, since we don't
just want to completely rebuild it every time the robotMap
changes. Instead, we just make sure to update it every time the
location of a robot changes, or a robot is created or destroyed.
Fortunately, there are relatively few ways for these things to
happen.
robotsWatching :: Lens' Robots (MonoidMap (Cosmic Location) IntSet) Source #
Get a list of all the robots that are "watching" by location.
activeRobots :: Getter Robots IntSet Source #
The names of the robots that are currently not sleeping.
waitingRobots :: Getter Robots (MonoidMap TickNumber [RID]) Source #
The names of the robots that are currently sleeping, indexed by wake up
time. Note that this may not include all sleeping robots, particularly
those that are only taking a short nap (e.g. wait 1
).
currentTickWakeableBots :: Lens' Robots [RID] Source #
Get a list of all the robots that are "watching" by location.
viewCenterRule :: Lens' Robots ViewCenterRule Source #
The current rule for determining the center of the world view.
It updates also, viewCenter
and focusedRobot
to keep
everything synchronized.
viewCenter :: Getter Robots (Cosmic Location) Source #
The current center of the world view. Note that this cannot be
modified directly, since it is calculated automatically from the
viewCenterRule
. To modify the view center, either set the
viewCenterRule
, or use modifyViewCenter
.
focusedRobotID :: Getter Robots RID Source #
The current robot in focus.
It is only a Getter
because this value should be updated only when
the viewCenterRule
is specified to be a robot.
Technically it's the last robot ID specified by viewCenterRule
,
but that robot may not be alive anymore - to be safe use focusedRobot
.
Utilities
wakeWatchingRobots :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => RID -> TickNumber -> Cosmic Location -> m () Source #
Iterates through all of the currently wait
-ing robots,
and moves forward the wake time of the ones that are watch
-ing this location.
NOTE: Clearing TickNumber
map entries from internalWaitingRobots
upon wakeup is handled by wakeUpRobotsDoneSleeping
sleepUntil :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => RID -> TickNumber -> m () Source #
Takes a robot out of the activeRobots
set and puts it in the waitingRobots
queue.
sleepForever :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => RID -> m () Source #
Takes a robot out of the activeRobots
set.
wakeUpRobotsDoneSleeping :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => TickNumber -> m () Source #
Removes robots whose wake up time matches the current game ticks count
from the waitingRobots
queue and put them back in the activeRobots
set
if they still exist in the keys of robotMap
.
Mutations
This function modifies:
wakeLog
robotsWatching
internalWaitingRobots
internalActiveRobots
(akaactiveRobots
)
deleteRobot :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => RID -> m () Source #
removeRobotFromLocationMap :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => Cosmic Location -> RID -> m () Source #
Makes sure empty sets don't hang around in the
robotsByLocation
map. We don't want a key with an
empty set at every location any robot has ever
visited!
activateRobot :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => RID -> m () Source #
Adds a robot to the activeRobots
set.
addRobot :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => Robot -> m () Source #
Add a robot to the game state, adding it to the main robot map, the active robot set, and to to the index of robots by location.
addRobotToLocation :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => RID -> Cosmic Location -> m () Source #
Helper function for updating the "robotsByLocation" bookkeeping
addTRobot :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => CESK -> TRobot -> m () Source #
Add a concrete instance of a robot template to the game state: First, generate a unique ID number for it. Then, add it to the main robot map, the active robot set, and to to the index of robots by location.
addTRobot' :: forall (sig :: (Type -> Type) -> Type -> Type) m. Has (State Robots) sig m => CESK -> TRobot -> m Robot Source #
Like addTRobot, but return the newly instantiated robot.
View
modifyViewCenter :: (Cosmic Location -> Cosmic Location) -> Robots -> Robots Source #
Modify the viewCenter
by applying an arbitrary function to the
current value. Note that this also modifies the viewCenterRule
to match. After calling this function the viewCenterRule
will
specify a particular location, not a robot.
unfocus :: Robots -> Robots Source #
Unfocus by modifying the view center rule to look at the current location instead of a specific robot, and also set the focused robot ID to an invalid value. In classic mode this causes the map view to become nothing but static.
recalcViewCenter :: Robots -> Robots Source #
Recalculate the view center (and cache the result in the
viewCenter
field) based on the current viewCenterRule
. If
the viewCenterRule
specifies a robot which does not exist,
simply leave the current viewCenter
as it is.