Skip to content

Commit

Permalink
make it impossible to destroy base (#318)
Browse files Browse the repository at this point in the history
It is now impossible to destroy `base`. In `Step.hs` we now always check whether the current robot is `base` (by checking whether its `robotID` is 0) before the `selfDestruct` flag is set. If it is `base` a `CmdFailed` exception is thrown instead.

This resolves #297 .
  • Loading branch information
Alexander-Block authored Mar 22, 2022
1 parent b1e2c59 commit 7d2339f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Swarm/Game/Step.hs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ execConst c vs s k = do
return $ Waiting (time + d) (Out VUnit s k)
_ -> badConst
Selfdestruct -> do
selfDestruct .= True
destroyIfNotBase
flagRedraw
return $ Out VUnit s k
Move -> do
Expand All @@ -647,8 +647,9 @@ execConst c vs s k = do

-- Robots drown if they walk over liquid
caps <- use robotCapabilities
when (e `hasProperty` Liquid && CFloat `S.notMember` caps) $
selfDestruct .= True
when
(e `hasProperty` Liquid && CFloat `S.notMember` caps)
destroyIfNotBase

robotLocation .= nextLoc
flagRedraw
Expand Down Expand Up @@ -1358,6 +1359,13 @@ execConst c vs s k = do
[de] -> Right $ Just $ snd de
_ -> Left $ Fatal "Bad recipe:\n more than one unmovable entity produced."

destroyIfNotBase :: (Has (State Robot) sig m, Has (Error Exn) sig m) => m ()
destroyIfNotBase = do
rid <- use robotID
if rid == 0
then throwError $ cmdExn c ["You consider destroying your base, but decide not to do it after all."]
else selfDestruct .= True

-- update some tile in the world setting it to entity or making it empty
updateLoc w loc res = W.update (W.locToCoords loc) (const res) w

Expand Down

0 comments on commit 7d2339f

Please sign in to comment.