From 798f634dc7d9c2d7238e0a18bdeb5b3184bfea08 Mon Sep 17 00:00:00 2001 From: Karl Ostmo Date: Mon, 17 Jul 2023 23:09:00 -0700 Subject: [PATCH] Use robotMap directly instead of addRobot --- src/Swarm/Game/Step.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Swarm/Game/Step.hs b/src/Swarm/Game/Step.hs index d8fd9f431..666a7f925 100644 --- a/src/Swarm/Game/Step.hs +++ b/src/Swarm/Game/Step.hs @@ -1584,12 +1584,16 @@ execConst c vs s k = do | otherwise -> es |> e let addToRobotLog :: Has (State GameState) sgn m => Robot -> m () addToRobotLog r = do - r' <- execState r $ do + maybeRidLoc <- evalState r $ do hasLog <- hasCapability CLog hasListen <- hasCapability CListen loc' <- use robotLocation - when (hasLog && hasListen) (robotLog %= addLatestClosest loc') - addRobot r' + rid <- use robotID + return $ do + guard $ hasLog && hasListen + Just (rid, loc') + forM_ maybeRidLoc $ \(rid, loc') -> + robotMap . at rid . _Just . robotLog %= addLatestClosest loc' robotsAround <- if isPrivileged then use $ robotMap . to IM.elems