From 4491f10764255e3c4cef95a007569588d4aed5e2 Mon Sep 17 00:00:00 2001 From: Karl Ostmo Date: Tue, 18 Jul 2023 09:57:57 -0700 Subject: [PATCH] Use robotMap directly instead of addRobot (#1378) Closes #1372 --- 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